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

CLONE -ResultSetMetaData.getPrecision of a numeric column when no transaction is active throws an SQLException [JDBC470] #509

Closed
firebird-issue-importer opened this issue Dec 24, 2016 · 7 comments

Comments

@firebird-issue-importer

Submitted by: @mrotteveel

Relate to JDBC465

The fix of JDBC464 didn't fix all cases.

If ResultSetMetaData.getPrecision is called for a numeric or decimal column while no transaction is active (and the method wasn't called earlier when a transaction was active for the same RSMD), then this will fail with an exception.

The cause is that RSMD will execute the query, but as the FBConnection is not accessible in the context, it can only piggyback on an existing transaction instead of starting a new one. We should change this so it can either start a new normal transaction, or start a separate transaction for this metadata query (and commit that asap).

Also investigate if similar problems occur elsewhere (prime candidates are where the constructor FBDatabaseMetaData(GDSHelper gdsHelper) is used instead of FBDatabaseMetaData(AbstractConnection c).

Exception in 3.0 beta 1:

java.sql.SQLNonTransientException: No transaction or transaction not ACTIVE

at org\.firebirdsql\.gds\.ng\.TransactionHelper\.checkTransactionActive\(TransactionHelper\.java:49\)
at org\.firebirdsql\.gds\.ng\.wire\.version11\.V11Statement\.prepare\(V11Statement\.java:57\)
at org\.firebirdsql\.jdbc\.FBStatement\.prepareFixedStatement\(FBStatement\.java:1399\)
at org\.firebirdsql\.jdbc\.AbstractPreparedStatement\.prepareFixedStatement\(AbstractPreparedStatement\.java:1229\)
at org\.firebirdsql\.jdbc\.AbstractPreparedStatement\.<init\>\(AbstractPreparedStatement\.java:147\)
at org\.firebirdsql\.jdbc\.FBPreparedStatement\.<init\>\(FBPreparedStatement\.java:50\)
at org\.firebirdsql\.jdbc\.FBDatabaseMetaData\.getStatement\(FBDatabaseMetaData\.java:5035\)
at org\.firebirdsql\.jdbc\.FBDatabaseMetaData\.doQuery\(FBDatabaseMetaData\.java:5061\)
at org\.firebirdsql\.jdbc\.FBResultSetMetaData\.getExtendedFieldInfo\(FBResultSetMetaData\.java:506\)
at org\.firebirdsql\.jdbc\.AbstractFieldMetaData\.getExtFieldInfo\(AbstractFieldMetaData\.java:342\)
at org\.firebirdsql\.jdbc\.AbstractFieldMetaData\.getPrecisionInternal\(AbstractFieldMetaData\.java:280\)
at org\.firebirdsql\.jdbc\.FBResultSetMetaData\.getPrecision\(FBResultSetMetaData\.java:281\)
at org\.firebirdsql\.jdbc\.TestFBResultSetMetaData\.getPrecisionOfNumericColumnWithoutActiveTransaction\(TestFBResultSetMetaData\.java:305\)

Exception in Jaybird 2.2.x:

org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544332. invalid transaction handle (expecting explicit transaction start)

at org\.firebirdsql\.jdbc\.AbstractPreparedStatement\.<init\>\(AbstractPreparedStatement\.java:137\)
at org\.firebirdsql\.jdbc\.FBPreparedStatement\.<init\>\(FBPreparedStatement\.java:45\)
at sun\.reflect\.NativeConstructorAccessorImpl\.newInstance0\(Native Method\)
at sun\.reflect\.NativeConstructorAccessorImpl\.newInstance\(NativeConstructorAccessorImpl\.java:62\)
at sun\.reflect\.DelegatingConstructorAccessorImpl\.newInstance\(DelegatingConstructorAccessorImpl\.java:45\)
at java\.lang\.reflect\.Constructor\.newInstance\(Constructor\.java:423\)
at org\.firebirdsql\.jdbc\.FBStatementFactory\.createPreparedStatement\(FBStatementFactory\.java:89\)
at org\.firebirdsql\.jdbc\.AbstractDatabaseMetaData\.getStatement\(AbstractDatabaseMetaData\.java:6175\)
at org\.firebirdsql\.jdbc\.AbstractDatabaseMetaData\.doQuery\(AbstractDatabaseMetaData\.java:6203\)
at org\.firebirdsql\.jdbc\.FBResultSetMetaData\.getExtendedFieldInfo\(FBResultSetMetaData\.java:833\)
at org\.firebirdsql\.jdbc\.FBResultSetMetaData\.getExtFieldInfo\(FBResultSetMetaData\.java:682\)
at org\.firebirdsql\.jdbc\.FBResultSetMetaData\.getPrecision\(FBResultSetMetaData\.java:305\)
at org\.firebirdsql\.jdbc\.TestFBResultSetMetaData\.getPrecisionOfNumericColumnWithoutActiveTransaction\(TestFBResultSetMetaData\.java:361\)
at \.\.\.

Caused by: org.firebirdsql.gds.GDSException: invalid transaction handle (expecting explicit transaction start)
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.validateHandle(AbstractJavaGDSImpl.java:3246)
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.iscDsqlPrepare(AbstractJavaGDSImpl.java:1454)
at org.firebirdsql.gds.impl.GDSHelper.prepareStatement(GDSHelper.java:214)
at org.firebirdsql.jdbc.AbstractStatement.prepareFixedStatement(AbstractStatement.java:1388)
at org.firebirdsql.jdbc.AbstractPreparedStatement.prepareFixedStatement(AbstractPreparedStatement.java:1269)
at org.firebirdsql.jdbc.AbstractPreparedStatement.<init>(AbstractPreparedStatement.java:134)
... 41 more

Commits: 6ae0926 5f3cffa

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Dec 24, 2016

Modified by: @mrotteveel

Link: This issue relate to JDBC465 [ JDBC465 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Dec 24, 2016

Modified by: @mrotteveel

Version: Jaybird 3.0.0-beta-2 [ 10802 ]

Fix Version: Jaybird 2.2.13 [ 10805 ]

description: If ResultSetMetaData.getPrecision is called for a numeric or decimal column while no transaction is active (and the method wasn't called earlier when a transaction was active for the same RSMD), then this will fail with an exception.

The cause is that RSMD will execute the query, but as the FBConnection is not accessible in the context, it can only piggyback on an existing transaction instead of starting a new one. We should change this so it can either start a new normal transaction, or start a separate transaction for this metadata query (and commit that asap).

Also investigate if similar problems occur elsewhere (prime candidates are where the constructor FBDatabaseMetaData(GDSHelper gdsHelper) is used instead of FBDatabaseMetaData(AbstractConnection c).

Exception in 3.0 beta 1:

java.sql.SQLNonTransientException: No transaction or transaction not ACTIVE

at org\.firebirdsql\.gds\.ng\.TransactionHelper\.checkTransactionActive\(TransactionHelper\.java:49\)
at org\.firebirdsql\.gds\.ng\.wire\.version11\.V11Statement\.prepare\(V11Statement\.java:57\)
at org\.firebirdsql\.jdbc\.FBStatement\.prepareFixedStatement\(FBStatement\.java:1399\)
at org\.firebirdsql\.jdbc\.AbstractPreparedStatement\.prepareFixedStatement\(AbstractPreparedStatement\.java:1229\)
at org\.firebirdsql\.jdbc\.AbstractPreparedStatement\.<init\>\(AbstractPreparedStatement\.java:147\)
at org\.firebirdsql\.jdbc\.FBPreparedStatement\.<init\>\(FBPreparedStatement\.java:50\)
at org\.firebirdsql\.jdbc\.FBDatabaseMetaData\.getStatement\(FBDatabaseMetaData\.java:5035\)
at org\.firebirdsql\.jdbc\.FBDatabaseMetaData\.doQuery\(FBDatabaseMetaData\.java:5061\)
at org\.firebirdsql\.jdbc\.FBResultSetMetaData\.getExtendedFieldInfo\(FBResultSetMetaData\.java:506\)
at org\.firebirdsql\.jdbc\.AbstractFieldMetaData\.getExtFieldInfo\(AbstractFieldMetaData\.java:342\)
at org\.firebirdsql\.jdbc\.AbstractFieldMetaData\.getPrecisionInternal\(AbstractFieldMetaData\.java:280\)
at org\.firebirdsql\.jdbc\.FBResultSetMetaData\.getPrecision\(FBResultSetMetaData\.java:281\)
at org\.firebirdsql\.jdbc\.TestFBResultSetMetaData\.getPrecisionOfNumericColumnWithoutActiveTransaction\(TestFBResultSetMetaData\.java:305\)

Exception in Jaybird 2.2.x:

org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544332. invalid transaction handle (expecting explicit transaction start)

at org\.firebirdsql\.jdbc\.AbstractPreparedStatement\.<init\>\(AbstractPreparedStatement\.java:137\)
at org\.firebirdsql\.jdbc\.FBPreparedStatement\.<init\>\(FBPreparedStatement\.java:45\)
at sun\.reflect\.NativeConstructorAccessorImpl\.newInstance0\(Native Method\)
at sun\.reflect\.NativeConstructorAccessorImpl\.newInstance\(NativeConstructorAccessorImpl\.java:62\)
at sun\.reflect\.DelegatingConstructorAccessorImpl\.newInstance\(DelegatingConstructorAccessorImpl\.java:45\)
at java\.lang\.reflect\.Constructor\.newInstance\(Constructor\.java:423\)
at org\.firebirdsql\.jdbc\.FBStatementFactory\.createPreparedStatement\(FBStatementFactory\.java:89\)
at org\.firebirdsql\.jdbc\.AbstractDatabaseMetaData\.getStatement\(AbstractDatabaseMetaData\.java:6175\)
at org\.firebirdsql\.jdbc\.AbstractDatabaseMetaData\.doQuery\(AbstractDatabaseMetaData\.java:6203\)
at org\.firebirdsql\.jdbc\.FBResultSetMetaData\.getExtendedFieldInfo\(FBResultSetMetaData\.java:833\)
at org\.firebirdsql\.jdbc\.FBResultSetMetaData\.getExtFieldInfo\(FBResultSetMetaData\.java:682\)
at org\.firebirdsql\.jdbc\.FBResultSetMetaData\.getPrecision\(FBResultSetMetaData\.java:305\)
at org\.firebirdsql\.jdbc\.TestFBResultSetMetaData\.getPrecisionOfNumericColumnWithoutActiveTransaction\(TestFBResultSetMetaData\.java:361\)
at \.\.\.

Caused by: org.firebirdsql.gds.GDSException: invalid transaction handle (expecting explicit transaction start)
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.validateHandle(AbstractJavaGDSImpl.java:3246)
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.iscDsqlPrepare(AbstractJavaGDSImpl.java:1454)
at org.firebirdsql.gds.impl.GDSHelper.prepareStatement(GDSHelper.java:214)
at org.firebirdsql.jdbc.AbstractStatement.prepareFixedStatement(AbstractStatement.java:1388)
at org.firebirdsql.jdbc.AbstractPreparedStatement.prepareFixedStatement(AbstractPreparedStatement.java:1269)
at org.firebirdsql.jdbc.AbstractPreparedStatement.<init>(AbstractPreparedStatement.java:134)
... 41 more

=>

The fix of JDBC464 didn't fix all cases.

If ResultSetMetaData.getPrecision is called for a numeric or decimal column while no transaction is active (and the method wasn't called earlier when a transaction was active for the same RSMD), then this will fail with an exception.

The cause is that RSMD will execute the query, but as the FBConnection is not accessible in the context, it can only piggyback on an existing transaction instead of starting a new one. We should change this so it can either start a new normal transaction, or start a separate transaction for this metadata query (and commit that asap).

Also investigate if similar problems occur elsewhere (prime candidates are where the constructor FBDatabaseMetaData(GDSHelper gdsHelper) is used instead of FBDatabaseMetaData(AbstractConnection c).

Exception in 3.0 beta 1:

java.sql.SQLNonTransientException: No transaction or transaction not ACTIVE

at org\.firebirdsql\.gds\.ng\.TransactionHelper\.checkTransactionActive\(TransactionHelper\.java:49\)
at org\.firebirdsql\.gds\.ng\.wire\.version11\.V11Statement\.prepare\(V11Statement\.java:57\)
at org\.firebirdsql\.jdbc\.FBStatement\.prepareFixedStatement\(FBStatement\.java:1399\)
at org\.firebirdsql\.jdbc\.AbstractPreparedStatement\.prepareFixedStatement\(AbstractPreparedStatement\.java:1229\)
at org\.firebirdsql\.jdbc\.AbstractPreparedStatement\.<init\>\(AbstractPreparedStatement\.java:147\)
at org\.firebirdsql\.jdbc\.FBPreparedStatement\.<init\>\(FBPreparedStatement\.java:50\)
at org\.firebirdsql\.jdbc\.FBDatabaseMetaData\.getStatement\(FBDatabaseMetaData\.java:5035\)
at org\.firebirdsql\.jdbc\.FBDatabaseMetaData\.doQuery\(FBDatabaseMetaData\.java:5061\)
at org\.firebirdsql\.jdbc\.FBResultSetMetaData\.getExtendedFieldInfo\(FBResultSetMetaData\.java:506\)
at org\.firebirdsql\.jdbc\.AbstractFieldMetaData\.getExtFieldInfo\(AbstractFieldMetaData\.java:342\)
at org\.firebirdsql\.jdbc\.AbstractFieldMetaData\.getPrecisionInternal\(AbstractFieldMetaData\.java:280\)
at org\.firebirdsql\.jdbc\.FBResultSetMetaData\.getPrecision\(FBResultSetMetaData\.java:281\)
at org\.firebirdsql\.jdbc\.TestFBResultSetMetaData\.getPrecisionOfNumericColumnWithoutActiveTransaction\(TestFBResultSetMetaData\.java:305\)

Exception in Jaybird 2.2.x:

org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544332. invalid transaction handle (expecting explicit transaction start)

at org\.firebirdsql\.jdbc\.AbstractPreparedStatement\.<init\>\(AbstractPreparedStatement\.java:137\)
at org\.firebirdsql\.jdbc\.FBPreparedStatement\.<init\>\(FBPreparedStatement\.java:45\)
at sun\.reflect\.NativeConstructorAccessorImpl\.newInstance0\(Native Method\)
at sun\.reflect\.NativeConstructorAccessorImpl\.newInstance\(NativeConstructorAccessorImpl\.java:62\)
at sun\.reflect\.DelegatingConstructorAccessorImpl\.newInstance\(DelegatingConstructorAccessorImpl\.java:45\)
at java\.lang\.reflect\.Constructor\.newInstance\(Constructor\.java:423\)
at org\.firebirdsql\.jdbc\.FBStatementFactory\.createPreparedStatement\(FBStatementFactory\.java:89\)
at org\.firebirdsql\.jdbc\.AbstractDatabaseMetaData\.getStatement\(AbstractDatabaseMetaData\.java:6175\)
at org\.firebirdsql\.jdbc\.AbstractDatabaseMetaData\.doQuery\(AbstractDatabaseMetaData\.java:6203\)
at org\.firebirdsql\.jdbc\.FBResultSetMetaData\.getExtendedFieldInfo\(FBResultSetMetaData\.java:833\)
at org\.firebirdsql\.jdbc\.FBResultSetMetaData\.getExtFieldInfo\(FBResultSetMetaData\.java:682\)
at org\.firebirdsql\.jdbc\.FBResultSetMetaData\.getPrecision\(FBResultSetMetaData\.java:305\)
at org\.firebirdsql\.jdbc\.TestFBResultSetMetaData\.getPrecisionOfNumericColumnWithoutActiveTransaction\(TestFBResultSetMetaData\.java:361\)
at \.\.\.

Caused by: org.firebirdsql.gds.GDSException: invalid transaction handle (expecting explicit transaction start)
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.validateHandle(AbstractJavaGDSImpl.java:3246)
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.iscDsqlPrepare(AbstractJavaGDSImpl.java:1454)
at org.firebirdsql.gds.impl.GDSHelper.prepareStatement(GDSHelper.java:214)
at org.firebirdsql.jdbc.AbstractStatement.prepareFixedStatement(AbstractStatement.java:1388)
at org.firebirdsql.jdbc.AbstractPreparedStatement.prepareFixedStatement(AbstractPreparedStatement.java:1269)
at org.firebirdsql.jdbc.AbstractPreparedStatement.<init>(AbstractPreparedStatement.java:134)
... 41 more

Fix Version: Jaybird 2.2.12 [ 10781 ] =>

Fix Version: Jaybird 3.0.0-beta-2 [ 10802 ] =>

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Dec 24, 2016

Commented by: @mrotteveel

The exception could still occur when a connection was in use by another thread when the meta data statement was prepared.

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Dec 31, 2016

Modified by: @mrotteveel

Fix Version: Jaybird 3.0.0-beta-3 [ 10806 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Dec 31, 2016

Commented by: @mrotteveel

Fixed thread safety issue caused by insufficient synchronization

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Dec 31, 2016

Modified by: @mrotteveel

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Mar 5, 2017

Modified by: @mrotteveel

status: Resolved [ 5 ] => Closed [ 6 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment