This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 244547 - calling stored procedures does not show the output table
Summary: calling stored procedures does not show the output table
Status: RESOLVED FIXED
Alias: None
Product: db
Classification: Unclassified
Component: Show Data (show other bugs)
Version: 8.0
Hardware: All All
: P3 normal (vote)
Assignee: Libor Fischmeistr
URL:
Keywords: PATCH_AVAILABLE
Depends on:
Blocks:
 
Reported: 2014-05-16 11:47 UTC by max0x7ba
Modified: 2014-07-19 10:15 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
MS SQL editor correctly shows the output table of a stored procedure (6.12 KB, image/png)
2014-05-16 11:47 UTC, max0x7ba
Details
NetBeans does not show the output table of a stored procedure. (40.86 KB, image/png)
2014-05-16 11:48 UTC, max0x7ba
Details
test case MS SQL editor correct output (7.59 KB, image/png)
2014-05-23 12:06 UTC, max0x7ba
Details
test case NetBeans missing output (50.81 KB, image/png)
2014-05-23 12:08 UTC, max0x7ba
Details
proposed patch v1 (7.41 KB, patch)
2014-05-23 20:07 UTC, matthias42
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description max0x7ba 2014-05-16 11:47:20 UTC
Created attachment 147302 [details]
MS SQL editor correctly shows the output table of a stored procedure

When I call a stored procedure that returns a table from the MS SQL Editor it correctly displays the output table of a stored procedure.

When I call the same stored procedure from NetBeans it does not show the output table.
Comment 1 max0x7ba 2014-05-16 11:48:02 UTC
Created attachment 147303 [details]
NetBeans does not show the output table of a stored procedure.
Comment 2 matthias42 2014-05-16 16:53:03 UTC
I checked against my test system - and in this broadness the bug is not correct:

I ran this:

exec sys.sp_help

and got two resultsets (both displayed). I went one step further and ran (t is a table in the db):

exec sys.sp_help 't'

and got five result sets. So there seems to be something different wrong here.

This is:

- SQL Server 2008 (Express)
- Driver: Microsoft JDBC Driver 4.0 for SQL Server
- Version: Microsoft JDBC Driver 4.0 for SQL Server

Could you give some more information please and run the above statements to narrow down the problem?
Comment 3 max0x7ba 2014-05-19 10:05:42 UTC
The stored procedure in question creates and populates a temporary table and then returns it. Is that a supported use case?
Comment 4 max0x7ba 2014-05-19 10:18:54 UTC
Running `exec sys.sp_help` does show results.

Driver: Microsoft SQL Server 2005
Driver class: com.microsoft.sqlserver.jdbc.SQLServerDriver
Driver: Microsoft JDBC Driver 4.0 for SQL Server
Database product name: Microsoft SQL Server
Database product version: 10.50.1600
Comment 5 max0x7ba 2014-05-20 11:12:58 UTC
When I call that stored procedure from C/C++ code through ODBC API (unixODBC + FreeTDS) I can get the result table as expected.

Let me know what kind of information you need to help fix this issue.
Comment 6 matthias42 2014-05-20 19:18:37 UTC
(In reply to max0x7ba from comment #5)
> Let me know what kind of information you need to help fix this issue.

It would be helpful if you could provide a minimal testcase (sample data with a minimal stored procedure, that reproduces your problem).

Please note: I'm not a netbeans developer but have some work in the db module - I'll have a look at the problem, but won't promise a solution.
Comment 7 max0x7ba 2014-05-23 12:05:22 UTC
Test case sql:

    DECLARE @RawData TABLE(Column1 VARCHAR(50),Column2 DATETime)
    
    INSERT INTO @RawData
    (Column1 ,Column2   )
    Select 'abc',GETDATE()
    union all
    Select 'def',GETDATE()
    
    SELECT *
    FROM @Rawdata
Comment 8 max0x7ba 2014-05-23 12:06:48 UTC
Created attachment 147408 [details]
test case MS SQL editor correct output
Comment 9 max0x7ba 2014-05-23 12:08:16 UTC
Created attachment 147409 [details]
test case NetBeans missing output
Comment 10 matthias42 2014-05-23 20:07:00 UTC
Created attachment 147417 [details]
proposed patch v1

Thank you! That helped debugging - This is the culprit is in  SQLExecutionHelper.java around line 140:

                     // Read multiple Resultsets
                     boolean isResultSet = executeSQLStatement(stmt, sql);
 
-                    // @todo: This needs clearing up => in light of request for
-                    // the ability to disable autocommit, this need to go
-                    if (!isResultSet || dataView.getUpdateCount() != -1) {
-                        if (!conn.getAutoCommit()) {
-                            conn.commit();
-                        }
-                        return;
-                    }
                     if (Thread.interrupted()) {
                         return;
                     }


My test worked, because the first return was already a resultset, so the removed code path above is not taken. In the sample case the first return is the update count from the insert and only the second result is the resultset you are interested in.

My reading of SQLStatementExcecutor is, that the above statement is necessary to ensure, that a statement modifying data is committed. This is necessary, because SQLStatementExecutor switches into non-autocommit mode and then executes statements. The other users of that class: INSERT, DELETE, UPDATE and TRUNCATE handling all use this and use commitOrRollback to flush their batch out. For the usecase of the "executeQuery" method this is not sane, as each line of input is executed seperatetly and virtual autocommit mode is established.

My fix pushes this virtual autocommit mode down into the SQLStatementExecutor and uses the "real" Autocommit-Mode. That renders the statement useless and it can be removed.

If this change is not acceptable it might be worth checking whether removing the return is feasible, but would not trust database vendors to do sane things with an open resultset and an intermittend commit.

The colleteral changes I did (introducing final and tightening the access modifiers) should be save, as the classes are not public api.
Comment 11 Libor Fischmeistr 2014-07-09 12:38:56 UTC
Patch applied - http://hg.netbeans.org/core-main/rev/b923cb93fef5

Thank you Matthias for it.
Comment 12 Quality Engineering 2014-07-19 10:15:48 UTC
Integrated into 'main-silver', will be available in build *201407190718* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/b923cb93fef5
User: Libor Fischmeistr <lfischmeistr@netbeans.org>
Log: #244547: calling stored procedures does not show the output table