// test selection
Reference<XStatement> xStatement = xConnection->createStatement();
Reference<XResultSet> xResults
= xStatement->executeQuery(u"SELECT \"NAME\" FROM \"CATEGORIES\" ORDER BY \"ID\""_ustr);
CPPUNIT_ASSERT(xResults.is());
// test if the queries have been created and can be used
uno::Reference<XQueriesSupplier> xQuerySupplier(xConnection, UNO_QUERY_THROW);
uno::Reference<container::XNameAccess> xQueryAccess = xQuerySupplier->getQueries();
CPPUNIT_ASSERT(xQueryAccess->hasElements());
// the unshipped orders query depends on the all orders query, so we'll test // to see if both work
uno::Reference<sdbcx::XColumnsSupplier> xColumns(
xQueryAccess->getByName(u"unshipped orders"_ustr), UNO_QUERY);
uno::Reference<container::XNameAccess> xColumnAccess(xColumns->getColumns());
CPPUNIT_ASSERT(xColumnAccess->hasElements());
Sequence<OUString> ColumnNames = xColumnAccess->getElementNames();
CPPUNIT_ASSERT(ColumnNames.hasElements()); // first column returned should be from the all orders query
CPPUNIT_ASSERT_EQUAL(ColumnNames[0], u"Order No."_ustr);
}
void CRMDBTest::testRegistrationName()
{ // 1. check the existing "Bibliography" data source whether it has the proper name
Reference<container::XNameAccess> xNameAccess(
getMultiServiceFactory()->createInstance(u"com.sun.star.sdb.DatabaseContext"_ustr),
UNO_QUERY);
Reference<sdbc::XDataSource> xBiblioDataSource(xNameAccess->getByName(u"Bibliography"_ustr),
UNO_QUERY);
CPPUNIT_ASSERT(xBiblioDataSource.is());
// 2. register a newly created data source, and verify it has the proper name // Setup the CRMDatabase
createDBDocument(u"sdbc:embedded:hsqldb"_ustr);
uno::Reference<sdb::XOfficeDatabaseDocument> xDocument(mxComponent, UNO_QUERY_THROW);
uno::Reference<XConnection> xConnection = getConnectionForDocument(xDocument);
createTables(xConnection);
// Get a XDatabaseContext from XSingleService factory in order to register the DataSource
Reference<sdb::XDatabaseContext> xDatabaseContext(xNameAccess, UNO_QUERY_THROW);
CPPUNIT_ASSERT(xDatabaseContext.is());
// Register the datasource
xDatabaseContext->registerObject(u"SomeNewHsqlDataSource"_ustr, xDataSource);
// Check the newly created data source to see if it has the proper name
Reference<beans::XPropertySet> xProp(xDataSource, UNO_QUERY);
OUString sDataSourceName;
xProp->getPropertyValue(u"Name"_ustr) >>= sDataSourceName;
// Test to make sure the query is parseable // If it is unparseable, catch the SQLException and fail with the SQL error message try
{
xComposer->setQuery(sQuery);
} catch (const SQLException& e)
{
OString oMessage = OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US);
CPPUNIT_ASSERT_MESSAGE(oMessage.getStr(), false);
}
// 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);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.