Change the unparseable query to parse ODBC escape query
dbaccess/qa/connectivity/tools/CRMDatabase.java - remove unparseable query dbaccess/qa/unit/dbtest_base.cxx - Add the ODBC escape query dbacces/qa/unit/CRMDatabase_test.cxx - Add test The unparseable query has been commented out for a number of years in the CRMDatabase.java. At some point, this query has become parseable so this commit removes the old commented out Java query, moves the it to C++ and adds a CPPUNIT test for the queries parseability. Change-Id: Ie4d700458bc6dfd52cd87aec75ec202dd12248ef Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181142 Tested-by: Jenkins Tested-by: Xisco Fauli <xiscofauli@libreoffice.org> Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
This commit is contained in:
committed by
Xisco Fauli
parent
39fcf245d6
commit
c48ebfd863
@@ -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();
|
||||
}
|
||||
}
|
||||
|
@@ -13,11 +13,14 @@
|
||||
#include <com/sun/star/container/XNameAccess.hpp>
|
||||
#include <com/sun/star/frame/XStorable.hpp>
|
||||
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
|
||||
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
||||
#include <com/sun/star/sdb/DatabaseContext.hpp>
|
||||
#include <com/sun/star/sdb/XDocumentDataSource.hpp>
|
||||
#include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
|
||||
#include <com/sun/star/sdb/XQueriesSupplier.hpp>
|
||||
#include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
|
||||
#include <com/sun/star/sdbc/XDataSource.hpp>
|
||||
#include <com/sun/star/sdbc/SQLException.hpp>
|
||||
#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
|
||||
#include <com/sun/star/sdbc/XResultSet.hpp>
|
||||
#include <com/sun/star/sdbc/XRow.hpp>
|
||||
@@ -33,11 +36,13 @@ public:
|
||||
void testRegistrationName();
|
||||
uno::Reference<XConnection> 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> xConnection = setUpDBConnection();
|
||||
createTables(xConnection);
|
||||
|
||||
uno::Reference<lang::XMultiServiceFactory> xFactory(xConnection, UNO_QUERY);
|
||||
CPPUNIT_ASSERT(xFactory.is());
|
||||
|
||||
Reference<XSingleSelectQueryComposer> xComposer(
|
||||
xFactory->createInstance(u"com.sun.star.sdb.SingleSelectQueryComposer"_ustr),
|
||||
UNO_QUERY_THROW);
|
||||
|
||||
uno::Reference<XQueriesSupplier> xQuerySupplier(xConnection, UNO_QUERY_THROW);
|
||||
uno::Reference<container::XNameAccess> xQueryAccess = xQuerySupplier->getQueries();
|
||||
CPPUNIT_ASSERT(xQueryAccess->hasElements());
|
||||
|
||||
Reference<XPropertySet> 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> xStatement = xConnection->createStatement();
|
||||
Reference<XResultSet> xResults = xStatement->executeQuery(xComposer->getQuery());
|
||||
CPPUNIT_ASSERT(xResults.is());
|
||||
|
||||
// Check to make sure the query returns the correct result
|
||||
Reference<XRow> 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();
|
||||
|
@@ -162,6 +162,8 @@ void DBTestBase::createQueries(const Reference<XDataSource>& 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> & xDataSource)
|
||||
|
Reference in New Issue
Block a user