MS SQL issues

After using 0xDBE for a while there are a few things I have noticed with MSSQL - these may or may not be known issues, I don't have time to check right now.

RAISERROR (@Msg, 0, 1) WITH NOWAIT

...does not print immediately, but only when execution of the full script block ends.

Scripts that should be executed as a whole, such as Ola Hallengren's maintenance script, or Adam Machanic's WhoIsActive:

https://ola.hallengren.com/scripts/MaintenanceSolution.sql
http://sqlblog.com/files/folders/beta/entry42453.aspx

...throw errors when executed in 0xDBE. This appears to be an issue with 0xDBE not properly supporting the GO for separation of batches. A quicker example:

DECLARE @Test INT;
SET @Test = 1;
PRINT @Test;
GO
DECLARE @Test VARCHAR(1);
SET @Test = '1';
PRINT @Test;
GO

In SSMS it prints as expected, in 0xDBE you get:

[2014-11-13 10:16:45] [S1000][134] The variable name '@Test' has already been declared. Variable names must be unique within a query batch or stored procedure.

This makes 0xDBE fairly limited for writing and executing more complex scripts.

There also appears to be some sort of issue with temporary tables and modifying them between executions of a block like IF OBJECT_ID...IS NULL DROP TABLE #Temp / CREATE TABLE. I've often run into situtations where if I add or modify a column in that temp table it will throw an error instead of executing the DROP the next time I run it. It won't work until I specifially drop the table outside of the code block manually, and then it will execute fine without any other changes. I haven't been able to isolate this behaviour enough to re-create it though.

1
5 comments

Thank you. Created:
https://youtrack.jetbrains.com/issue/DBE-969
https://youtrack.jetbrains.com/issue/DBE-970

The last issue requires a bit of play around, will do it later. If you can provide a sample script to demonstrate the problem, please do.

Regards,
Alexander.

0

I wrote a stored procedure in Azure SQL Database. Throughout the stored procedure I added many lines like:
RAISERROR('Reached point X.', 10, 7) WITH NOWAIT;

I thought this might help me with debugging. But yeah, on the “Output” tab, DataGrip doesn't seem to display these informational “error” messages until the stored procedure execution completes. So, it doesn't help. (Because I am debugging a stored procedure that never completes!)

I read through DBE-969, where it says “we shall add [have now added, I assume] async getWarnings() polling for a running statement.” What does this mean? I've searched, but I cannot figure it out. Is there some way for me to fetch these informational “error” messages that have been raised, during the execution of the stored procedure? (Or, ideally, have DataGrip display them in real time?)

Many thanks!

0
The original raise error statement from DBE-969 works as expected, namely, displays the message while the statement is executed. Please provide an example of your procedure with raise error and specify your current IDE version.
0

DataGrip 2024.3.3
Build #DB-243.23654.19, built on December 17, 2024
Runtime version: 21.0.5+8-b631.30 amd64 (JCEF 122.1.9)
Windows 11.0

The stored procedure is defined like below. I'm not sure if I should expect it to show the messages that are within the TRANSACTION, before that transaction is COMMITted? But when I start executing the procedure, it doesn't even show the first message ('Started execution!'), which is before the transaction begins.

CREATE PROCEDURE table_x_sync (
    @p1_drop_and_recreate BIT
    ,@p2_incremental_refresh BIT
) AS BEGIN

RAISERROR('Started execution!', 10, 1) WITH NOWAIT;

    BEGIN TRANSACTION;

RAISERROR('Started transaction!', 10, 2) WITH NOWAIT;

        IF @p1_drop_and_recreate = 1 AND @p2_incremental_refresh = 1 BEGIN
            RAISERROR('Both @p1_drop_and_recreate and @p2_incremental_refresh cannot be 1 simultaneously.', 16, 199);
            RETURN;
        END;

RAISERROR('Reached point 3!', 10, 3) WITH NOWAIT;

        IF @p1_drop_and_recreate = 1 BEGIN

            DROP TABLE IF EXISTS table_x;

            CREATE TABLE table_x (
                id INTEGER
                ,[...more columns...]
                ,_adf_synced_at_pacific_brnz DATETIME2(0)
                ,_adf_synced_at_pacific DATETIME2(0)
            );

        END

RAISERROR('Reached point 4!', 10, 4) WITH NOWAIT;

        IF @p1_drop_and_recreate = 0 AND @p2_incremental_refresh = 0 BEGIN TRUNCATE TABLE table_x END

RAISERROR('Reached point 5!', 10, 5) WITH NOWAIT;

        DECLARE @now DATETIME2(0) = CAST((SYSDATETIMEOFFSET() AT TIME ZONE 'Pacific Standard Time') AS DATETIME2(0));

        SELECT ...
        INTO stg_table
        FROM ...

RAISERROR('Reached point 6!', 10, 6) WITH NOWAIT;

        IF @p2_incremental_refresh = 1 BEGIN

RAISERROR('Reached point 7 !', 10, 7) WITH NOWAIT;

            DELETE ...
            FROM table_x
            WHERE...;
        END

RAISERROR('Reached point 8!', 10, 8) WITH NOWAIT;

        INSERT INTO table_x...

RAISERROR('Inserted rows into table_x!', 10, 9) WITH NOWAIT;

    COMMIT TRANSACTION;

RAISERROR('Committed transaction!', 10, 10) WITH NOWAIT;

END;
0
Thanks for the example.

I was able to reproduce it and have reported this issue omn our tracker:

RAISERROR messages are not written into the output

https://youtrack.jetbrains.com/issue/DBE-23406 

Please follow this issue to stay updated on the progress.
0

Please sign in to leave a comment.