Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getMoreResults Skips resultsets[BUG] #969

Closed
michaeldenkmal opened this issue Feb 25, 2019 · 15 comments
Closed

getMoreResults Skips resultsets[BUG] #969

michaeldenkmal opened this issue Feb 25, 2019 · 15 comments
Assignees
Labels
Bug A bug in the driver. A high priority item that one can expect to be addressed quickly.

Comments

@michaeldenkmal
Copy link

Driver version

SQL Server version

Client Operating System

JAVA/JVM version

Table schema

Problem description

  1. Expected behaviour:
  2. Actual behaviour:
  3. Error message/stack trace:
  4. Any other details that can be helpful:

JDBC trace logs

Reproduction code

@michaeldenkmal michaeldenkmal added the Bug A bug in the driver. A high priority item that one can expect to be addressed quickly. label Feb 25, 2019
@michaeldenkmal
Copy link
Author

the following test function skips every secound Result set with gradle:testCompile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '7.2.1.jre8'
but i doest it right with testCompile 'com.microsoft.sqlserver:mssql-jdbc:6.1.0.jre8'

` public static void testMoreResults(Connection con) {
try (Statement stmt = con.createStatement();) {
String SQL = "exec sp_help 'dbo.docs'";

        boolean results = stmt.execute(SQL);
        int rsCount = 0;

        // Loop through the available result sets.
        do {
            if (results) {
                ResultSet rs = stmt.getResultSet();
                String firstColumnName = rs.getMetaData().getColumnName(1);
                rsCount++;

                // Show data from the result set.
                System.out.println(String.format("result #%d: firstColumnName:%s", rsCount, firstColumnName));
                while (rs.next()) {
                    System.out.println(rs.getString(1));
                }
            }
            System.out.println();
            results = stmt.getMoreResults();
        } while (results);
    }
    // Handle any errors that may have occurred.
    catch (SQLException e) {
        e.printStackTrace();
    }
}

`

expected result:
` result #1: firstColumnName:Name
DOCS

result #2: firstColumnName:Column_name
ID
DOC_ART
DOKUMENTPFAD
FIRMA1
SUCHBEGRIFF
PNAME
ERSTELLT_AM
LEG_NR
F_NR
P_NR
LU
ERSTELLT_VON
DATEIGROESSE
NOTIZEN
VORLAGE
GZ_ID
EXTENSION
LEGTR_NR
LEGUTR_NR
GR_ID
login_name
BPRIVATE
betreff
ohintid
AD_ID
WrkFlwStat_Id
ABSSB
ABSFirma1
ABS_F_NR
ABS_P_NR
ABS_PNAME
ABS_AD_ID
dFileCreation
dFileLastAccess
dFileLastWrite
wm_id
bm_id
szrevnr
maBm_Id
szDocRecJson
dLastViewed
xmlInfo
ohintRefTabName_C
ft_idxed_b
archived_b
text_inhalt_m

result #3: firstColumnName:Identity
No identity column defined.

result #4: firstColumnName:RowGuidCol
No rowguidcol column defined.

result #5: firstColumnName:Data_located_on_filegroup
PRIMARY

result #6: firstColumnName:index_name
idxDocsFnrPnr
ix_doc_dokumentpfad
ix_docs_ohintid
PK__DOCS__0425A276
UQ__DOCS__0519C6AF

result #7: firstColumnName:constraint_type
CHECK on column BPRIVATE
DEFAULT on column archived_b
DEFAULT on column betreff
DEFAULT on column BPRIVATE
DEFAULT on column ft_idxed_b
FOREIGN KEY

FOREIGN KEY

FOREIGN KEY

FOREIGN KEY

FOREIGN KEY

FOREIGN KEY

PRIMARY KEY (clustered)
UNIQUE (non-clustered)
FOREIGN KEY

result #8: firstColumnName:Table is referenced by foreign key
ohemm.dbo.docs_locks: docs_locks_fk_docs
ohemm.dbo.docs_viewed: docs_viewed_Fk_docs
ohemm.dbo.docs_webacc: docs_webacc_Fk_docs
ohemm.dbo.docs_webTmplXml: docs_webTmplXml_Fk_Docs
ohemm.dbo.DocsLog: DocsLog_Fk_docs
ohemm.dbo.emmdoczus: FK__emmdoczus__DO_ID__297722B6
ohemm.dbo.EmmDoZuBtrWh: FK__EmmDoZuBt__Do_ID__2E3BD7D3
ohemm.dbo.emmDoZuPers: FK__emmDoZuPe__Do_ID__34E8D562
ohemm.dbo.ga_protokoll: ga_protokoll_fk_docs
ohemm.dbo.ohdocsversand: ohdocsversand_fk_docs
ohemm.dbo.ohProtokoll: ohProtokoll_fk_docs
ohemm.dbo.ohStdDoc: FK__ohStdDoc__DO_ID__3F6663D5
ohemm.dbo.ohzudocdoc: ohzudocdoc_fk_chld
ohemm.dbo.ohzudocdoc: ohzudocdoc_fk_prnt
ohemm.dbo.WrkFlwHis: wrkFlwHis_Fk_DO
ohemm.dbo.ZU_D_BRCODE: FkZUDODO
ohemm.dbo.zu_doablstru: zudoablstr_FK_do
ohemm.dbo.zu_docDoc: zu_DocDoc_Fk_Do1
ohemm.dbo.zu_docDoc: zu_DocDoc_Fk_Do2
ohemm.dbo.ZU_DOPAG: FK__ZU_DOPAG__DOC_ID__2FCF1A8A
ohemm.dbo.ZU_FERFAX_DOCS: FK__ZU_FERFAX__DOC_I__339FAB6E`

result with 7.2.1.jre8:

`result:

resulest #1: firstColumnName:Name
DOCS

resulest #2: firstColumnName:Identity
No identity column defined.

resulest #3: firstColumnName:Data_located_on_filegroup
PRIMARY

resulest #4: firstColumnName:constraint_type
CHECK on column BPRIVATE
DEFAULT on column archived_b
DEFAULT on column betreff
DEFAULT on column BPRIVATE
DEFAULT on column ft_idxed_b
FOREIGN KEY

FOREIGN KEY

FOREIGN KEY

FOREIGN KEY

FOREIGN KEY

FOREIGN KEY

PRIMARY KEY (clustered)
UNIQUE (non-clustered)
FOREIGN KEY
`

@peterbae
Copy link
Contributor

Hi @michaeldenkmal, thanks for reporting this issue. We've confirmed the behavior has started from 7.1.0 release, and we're looking into it.

@michaeldenkmal
Copy link
Author

Thank you ;)

@biasb
Copy link

biasb commented Feb 27, 2019

Can confirm this bug as well, unit tests started failing with "invalid column" for a routine that collects metadata from sp_help after updating to 7.2.1.jre8 from 7.0.0.jre8.

It seems the ResultSet pointer is advanced automatically when (all?) rows are read. If no rows where read (i.e rs.next() not called) then getMoreResults() worked as expected (rs.getMetaData().getColumn(1) returned correct first column name).

@cheenamalhotra cheenamalhotra self-assigned this Feb 27, 2019
@martinm1000
Copy link

This one sound scary, as I use multiple rs returned from some stored procedures, but I haven't seen this problem (I think).

Is this a general problem or something that can happen with calls of MetaData() ?

@biasb
Copy link

biasb commented Feb 28, 2019

With the latest driver this always happens (for me) even if getMetaData() is not used. I had code that used sp_help and iterated through all result sets from it that started failing after updating to the latest driver.

@martinm1000
Copy link

@biasb So is it specific (more or less) to sp_help ?
Can this happen with a simple

select * from tableA;
select * from tableB; 
select * from tableC;

where B would be skipped ?

@cheenamalhotra
Copy link
Member

Hi @martinm1000 @biasb

This issue occurs only in cases where SQL Warnings are recieved with ResultSets. If no SQL Warnings are recieved, the driver does not attempt parsing them and the resultsets are available as expected. We have found out the warning parsing is parsing additional information which is leading in missing next ResultSet from stream.

Work is in progress to fix this behavior, will let you know soon.

@cheenamalhotra
Copy link
Member

Hi @michaeldenkmal @martinm1000 @biasb

I just created PR #991 to fix the reported issue. Request you to test and confirm if everything works as desired.

@free2bcreative
Copy link

I found the same issue while converting our project over to using mssql-jdbc. I was about to open an issue...but found that it was already created.

I did a quick test with the code changes and it seems to have fixed the issue.

Any estimate as to when PR 991 will come out with the next release?

@cheenamalhotra
Copy link
Member

Hi @free2bcreative

Thanks for confirming. The team will be reviewing the PR soon sometime, so far it hasn't been milestoned for a specific release. Stay tuned for further updates!

@softboy99
Copy link

I also encountered this problem

@cheenamalhotra
Copy link
Member

Hi @michaeldenkmal @free2bcreative @softboy99

PR #991 was merged today, hence closing the issue. The fix will be available in next preview release.

Thank you!

@upadas
Copy link

upadas commented Apr 12, 2024

Same issue with Sybase. Using the jconnect-7.0.7.jar. Will appreciate a solution.

@Jeffery-Wasty
Copy link
Contributor

Hi @upadas,

If you are still having issues with our driver, please create a new issue and we can help you from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in the driver. A high priority item that one can expect to be addressed quickly.
Projects
None yet
Development

No branches or pull requests

9 participants