diff options
author | Lionel Elie Mamane <lionel@mamane.lu> | 2018-09-15 07:19:28 +0200 |
---|---|---|
committer | Lionel Elie Mamane <lionel@mamane.lu> | 2018-09-22 22:10:34 +0200 |
commit | 6bebb05bd4b338e1ed3dac2c02b8b4186dc79675 (patch) | |
tree | a03ffea05b1e9b14b0523816cfab8e1dae5ff902 /dbaccess | |
parent | 3e17cdbca0738eeecbda7ed8f60f1e988c68d7bc (diff) |
tdf#119569 try most likely to succeed method to get column metadata _before_
We first try to prepare the statement and get metadata
information. That's fine. Some DB engines/drivers will not give column
information on an unexectured prepared statement. In that case, first
try to execute the statement with all parameters set to NULL, which is
likely to succeed. If not, keep "execute the raw SQL indiscriminately"
as a last resort. I'm not sure it will ever be useful, though.
Change-Id: I76b5fd6b2059e96fabe9a611c8e3ed115acfc964
Reviewed-on: https://gerrit.libreoffice.org/60884
Tested-by: Jenkins
Reviewed-by: Lionel Elie Mamane <lionel@mamane.lu>
Diffstat (limited to 'dbaccess')
-rw-r--r-- | dbaccess/source/core/api/SingleSelectQueryComposer.cxx | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx index 4892df42be23..cfac370ca6b0 100644 --- a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx +++ b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx @@ -788,29 +788,36 @@ Reference< XNameAccess > SAL_CALL OSingleSelectQueryComposer::getColumns( ) } catch( const Exception& ) { } - try + if ( !xResultSetMeta.is() && xPreparedStatement.is() ) { - if ( !xResultSetMeta.is() ) + try { - xStatement.reset( Reference< XStatement >( m_xConnection->createStatement(), UNO_QUERY_THROW ) ); - Reference< XPropertySet > xStatementProps( xStatement, UNO_QUERY_THROW ); - try { xStatementProps->setPropertyValue( PROPERTY_ESCAPE_PROCESSING, makeAny( false ) ); } - catch ( const Exception& ) { DBG_UNHANDLED_EXCEPTION("dbaccess"); } - xResMetaDataSup.set( xStatement->executeQuery( sSQL ), UNO_QUERY_THROW ); + //@see issue http://qa.openoffice.org/issues/show_bug.cgi?id=110111 + // access returns a different order of column names when executing select * from + // and asking the columns from the metadata. + Reference< XParameters > xParameters( xPreparedStatement, UNO_QUERY_THROW ); + Reference< XIndexAccess > xPara = getParameters(); + for(sal_Int32 i = 1;i <= xPara->getCount();++i) + xParameters->setNull(i,DataType::VARCHAR); + xResMetaDataSup.set(xPreparedStatement->executeQuery(), UNO_QUERY_THROW ); xResultSetMeta.set( xResMetaDataSup->getMetaData(), UNO_QUERY_THROW ); } + catch( const Exception& ) { } } - catch( const Exception& ) + + if ( !xResultSetMeta.is() ) { - //@see issue http://qa.openoffice.org/issues/show_bug.cgi?id=110111 - // access returns a different order of column names when executing select * from - // and asking the columns from the metadata. - Reference< XParameters > xParameters( xPreparedStatement, UNO_QUERY_THROW ); - Reference< XIndexAccess > xPara = getParameters(); - for(sal_Int32 i = 1;i <= xPara->getCount();++i) - xParameters->setNull(i,DataType::VARCHAR); - xResMetaDataSup.set(xPreparedStatement->executeQuery(), UNO_QUERY_THROW ); + xStatement.reset( Reference< XStatement >( m_xConnection->createStatement(), UNO_QUERY_THROW ) ); + Reference< XPropertySet > xStatementProps( xStatement, UNO_QUERY_THROW ); + try { xStatementProps->setPropertyValue( PROPERTY_ESCAPE_PROCESSING, makeAny( false ) ); } + catch ( const Exception& ) { DBG_UNHANDLED_EXCEPTION("dbaccess"); } + xResMetaDataSup.set( xStatement->executeQuery( sSQL ), UNO_QUERY_THROW ); xResultSetMeta.set( xResMetaDataSup->getMetaData(), UNO_QUERY_THROW ); + + if (xResultSetMeta.is()) + { + SAL_WARN("dbaccess", "OSingleSelectQueryComposer::getColumns failed to get xResultSetMeta from executed PreparedStatement, but got it from 'no escape processing' statement. SQL command:\n\t" << sSQL ); + } } if ( aSelectColumns->get().empty() ) |