diff --git a/connectivity/qa/connectivity/tools/CRMDatabase.java b/connectivity/qa/connectivity/tools/CRMDatabase.java index 3d33926280c3..204b90fa9def 100644 --- a/connectivity/qa/connectivity/tools/CRMDatabase.java +++ b/connectivity/qa/connectivity/tools/CRMDatabase.java @@ -203,43 +203,6 @@ public class CRMDatabase m_connection.refreshTables(); } - - private void validateUnparseable() - { - /* - // The "unparseable" query should be indeed be unparseable by OOo (though a valid HSQL query) - XSingleSelectQueryComposer composer; - QueryDefinition unparseableQuery; - try - { - final XMultiServiceFactory factory = UnoRuntime.queryInterface( - XMultiServiceFactory.class, m_database.defaultConnection().getXConnection() ); - composer = UnoRuntime.queryInterface( - XSingleSelectQueryComposer.class, factory.createInstance( "com.sun.star.sdb.SingleSelectQueryComposer" ) ); - unparseableQuery = m_dataSource.getQueryDefinition( "unparseable" ); - } - catch( Exception e ) - { - throw new RuntimeException( "caught an unexpected exception: " + e.getMessage() ); - } - - boolean caughtExpected = false; - try - { - composer.setQuery( unparseableQuery.getCommand() ); - } - catch (WrappedTargetException e) { } - catch( SQLException e ) - { - caughtExpected = true; - } - - if ( !caughtExpected ) - throw new RuntimeException( "Somebody improved the parser! This is bad :), since we need an unparsable query here!" ); - */ - } - - private void createQueries() throws ElementExistException, WrappedTargetException, com.sun.star.lang.IllegalArgumentException { m_database.getDataSource().createQuery( @@ -268,10 +231,5 @@ public class CRMDatabase m_database.getDataSource().createQuery( "parseable", "SELECT * FROM \"customers\"" ); m_database.getDataSource().createQuery( "parseable native", "SELECT * FROM INFORMATION_SCHEMA.SYSTEM_VIEWS", false ); -/* - m_database.getDataSource().createQuery( "unparseable", - "SELECT {fn DAYOFMONTH ('2001-01-01')} AS \"ID_VARCHAR\" FROM \"products\"", false ); -*/ - validateUnparseable(); } } diff --git a/dbaccess/qa/unit/CRMDatabase_test.cxx b/dbaccess/qa/unit/CRMDatabase_test.cxx index adb9a9af479b..557be6f0f35d 100644 --- a/dbaccess/qa/unit/CRMDatabase_test.cxx +++ b/dbaccess/qa/unit/CRMDatabase_test.cxx @@ -13,11 +13,14 @@ #include #include #include +#include #include #include #include #include +#include #include +#include #include #include #include @@ -33,11 +36,13 @@ public: void testRegistrationName(); uno::Reference setUpDBConnection(); void testQueryColumns(); + void testODBCEscapeQuery(); CPPUNIT_TEST_SUITE(CRMDBTest); CPPUNIT_TEST(testCRMDatabase); CPPUNIT_TEST(testRegistrationName); CPPUNIT_TEST(testQueryColumns); + CPPUNIT_TEST(testODBCEscapeQuery); CPPUNIT_TEST_SUITE_END(); }; @@ -180,6 +185,47 @@ void CRMDBTest::testQueryColumns() } } +void CRMDBTest::testODBCEscapeQuery() +{ + uno::Reference xConnection = setUpDBConnection(); + createTables(xConnection); + + uno::Reference xFactory(xConnection, UNO_QUERY); + CPPUNIT_ASSERT(xFactory.is()); + + Reference xComposer( + xFactory->createInstance(u"com.sun.star.sdb.SingleSelectQueryComposer"_ustr), + UNO_QUERY_THROW); + + uno::Reference xQuerySupplier(xConnection, UNO_QUERY_THROW); + uno::Reference xQueryAccess = xQuerySupplier->getQueries(); + CPPUNIT_ASSERT(xQueryAccess->hasElements()); + + Reference xQuery(xQueryAccess->getByName(u"parse odbc escape"_ustr), UNO_QUERY); + OUString sQuery; + xQuery->getPropertyValue(u"Command"_ustr) >>= sQuery; + + // Test to make sure the query is parseable + // If it is unparseable, catch the SQLException and fail with the SQL error mesage + try + { + xComposer->setQuery(sQuery); + } + catch (const SQLException& e) + { + OString oMessage = OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US); + CPPUNIT_ASSERT_MESSAGE(oMessage.getStr(), false); + } + + Reference xStatement = xConnection->createStatement(); + Reference xResults = xStatement->executeQuery(xComposer->getQuery()); + CPPUNIT_ASSERT(xResults.is()); + + // Check to make sure the query returns the correct result + Reference xRow(xResults, UNO_QUERY_THROW); + CPPUNIT_ASSERT(xResults->next()); + CPPUNIT_ASSERT_EQUAL(u"1"_ustr, xRow->getString(1)); +} CPPUNIT_TEST_SUITE_REGISTRATION(CRMDBTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/dbaccess/qa/unit/dbtest_base.cxx b/dbaccess/qa/unit/dbtest_base.cxx index f33a29958ee2..bec6e6817ca1 100644 --- a/dbaccess/qa/unit/dbtest_base.cxx +++ b/dbaccess/qa/unit/dbtest_base.cxx @@ -162,6 +162,8 @@ void DBTestBase::createQueries(const Reference& xDataSource) createQuery(u"SELECT * FROM \"CUSTOMERS\""_ustr, true, u"parseable"_ustr, xDataSource); createQuery(u"SELECT * FROM INFORMATION_SCHEMA.SYSTEM_VIEWS"_ustr, false, u"parseable native"_ustr, xDataSource); + createQuery(u"SELECT {fn DAYOFMONTH ('2001-01-01')} AS \"ID_VARCHAR\" FROM \"PRODUCTS\""_ustr, + false, u"parse odbc escape"_ustr, xDataSource); } void DBTestBase::createQuery(const OUString& sQuery, bool bEscapeProcessing, const OUString& sQueryName, const Reference & xDataSource)