Issue Details (XML | Word | Printable)

Key: JDBC-464
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Mark Rotteveel
Reporter: Mark Rotteveel
Votes: 0
Watchers: 0

If you were logged in you would be able to see more operations.
Jaybird JCA/JDBC Driver

ResultSetMetaData.getPrecision of a numeric column when no transaction is active throws an SQLException

Created: 08/Dec/16 07:13 PM   Updated: 18/Dec/16 02:58 PM
Component/s: JDBC driver
Affects Version/s: Jaybird 2.2.7, Jaybird 2.2.8, Jaybird 2.2.9, Jaybird 2.2.10, Jaybird 2.2.11, Jaybird 3.0.0-beta-1
Fix Version/s: Jaybird 2.2.12, Jaybird 3.0.0-beta-2, Jaybird 3.0.0

Issue Links:

 Description  « Hide
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.jdbc.FBStatement.prepareFixedStatement(
at org.firebirdsql.jdbc.AbstractPreparedStatement.prepareFixedStatement(
at org.firebirdsql.jdbc.AbstractPreparedStatement.<init>(
at org.firebirdsql.jdbc.FBPreparedStatement.<init>(
at org.firebirdsql.jdbc.FBDatabaseMetaData.getStatement(
at org.firebirdsql.jdbc.FBDatabaseMetaData.doQuery(
at org.firebirdsql.jdbc.FBResultSetMetaData.getExtendedFieldInfo(
at org.firebirdsql.jdbc.AbstractFieldMetaData.getExtFieldInfo(
at org.firebirdsql.jdbc.AbstractFieldMetaData.getPrecisionInternal(
at org.firebirdsql.jdbc.FBResultSetMetaData.getPrecision(
at org.firebirdsql.jdbc.TestFBResultSetMetaData.getPrecisionOfNumericColumnWithoutActiveTransaction(

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>(
at org.firebirdsql.jdbc.FBPreparedStatement.<init>(
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
at java.lang.reflect.Constructor.newInstance(
at org.firebirdsql.jdbc.FBStatementFactory.createPreparedStatement(
at org.firebirdsql.jdbc.AbstractDatabaseMetaData.getStatement(
at org.firebirdsql.jdbc.AbstractDatabaseMetaData.doQuery(
at org.firebirdsql.jdbc.FBResultSetMetaData.getExtendedFieldInfo(
at org.firebirdsql.jdbc.FBResultSetMetaData.getExtFieldInfo(
at org.firebirdsql.jdbc.FBResultSetMetaData.getPrecision(
at org.firebirdsql.jdbc.TestFBResultSetMetaData.getPrecisionOfNumericColumnWithoutActiveTransaction(
at ...
Caused by: org.firebirdsql.gds.GDSException: invalid transaction handle (expecting explicit transaction start)
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.validateHandle(
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.iscDsqlPrepare(
at org.firebirdsql.gds.impl.GDSHelper.prepareStatement(
at org.firebirdsql.jdbc.AbstractStatement.prepareFixedStatement(
at org.firebirdsql.jdbc.AbstractPreparedStatement.prepareFixedStatement(
at org.firebirdsql.jdbc.AbstractPreparedStatement.<init>(
... 41 more

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Mark Rotteveel added a comment - 17/Dec/16 09:52 AM
Changed implementation so it now will start a transaction if none is present. As part of this change, FBDatabaseMetaData statements are now kept prepared for reuse. This might provide a small performance benefit for applications that use the metadata a lot at the cost of a little more resources (open statement handles).

I have exposed a close method in the FirebirdDatabaseMetaData interface. This close method will close all statements in the database metadata, but keep the database metadata object itself usable. It should not be necessary to call this normally (it is called on connection close), but it is provided just in case.