Kaydet (Commit) 36026a6a authored tarafından David Ostrovsky's avatar David Ostrovsky Kaydeden (comit) Muthu Subramanian

mork driver: add list tables and unit test

Change-Id: I594b24341eb38c05523f578c1dc2e43d90544f30
üst f6739073
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
$(eval $(call gb_CppunitTest_CppunitTest,connectivity_mork))
$(eval $(call gb_CppunitTest_set_include,connectivity_mork,\
-I$(SRCDIR)/connectivity/source/inc \
-I$(SRCDIR)/connectivity/source/drivers/mork \
$$(INCLUDE) \
))
$(eval $(call gb_CppunitTest_use_api,connectivity_mork,\
udkapi \
offapi \
))
$(eval $(call gb_CppunitTest_use_ure,connectivity_mork))
$(eval $(call gb_CppunitTest_use_sdk_api,connectivity_mork))
$(eval $(call gb_CppunitTest_add_exception_objects,connectivity_mork, \
connectivity/qa/connectivity/mork/DriverTest \
))
$(eval $(call gb_CppunitTest_use_libraries,connectivity_mork, \
comphelper \
cppu \
cppuhelper \
i18nisolang1 \
mork \
sal \
salhelper \
sb \
test \
unotest \
ucbhelper \
utl \
$(gb_UWINAPI) \
))
$(eval $(call gb_CppunitTest_use_components,connectivity_mork,\
configmgr/source/configmgr \
i18npool/util/i18npool \
connectivity/source/drivers/mork/mork \
ucb/source/core/ucb1 \
ucb/source/ucp/file/ucpfile1 \
))
$(eval $(call gb_CppunitTest_use_configuration,connectivity_mork))
# vim: set noet sw=4 ts=4:
......@@ -145,10 +145,14 @@ $(eval $(call gb_Module_add_subsequentcheck_targets,connectivity,\
Jar_ConnectivityTools \
))
# FIXME: Does not work. Convert to JUnit.
# JunitTest_complex \
# JunitTest_complex \
endif
$(eval $(call gb_Module_add_check_targets,connectivity,\
CppunitTest_connectivity_mork \
))
endif
# vim: set noet sw=4 ts=4:
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <test/bootstrapfixture.hxx>
#include "MColumnAlias.hxx"
#include "MQueryHelper.hxx"
#include "MConnection.hxx"
#include <com/sun/star/sdbc/XDriver.hpp>
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::uno;
namespace connectivity { namespace mork {
class MorkDriverTest: public test::BootstrapFixture
{
public:
MorkDriverTest() : test::BootstrapFixture(false, false) {};
void test_metadata();
void test_select_default_all();
void test_select_list_table_joe_doe_5();
virtual void setUp();
virtual void tearDown();
CPPUNIT_TEST_SUITE(MorkDriverTest);
CPPUNIT_TEST(test_metadata);
CPPUNIT_TEST(test_select_default_all);
CPPUNIT_TEST(test_select_list_table_joe_doe_5);
CPPUNIT_TEST_SUITE_END();
private:
Reference<XInterface> m_xMorkComponent;
Reference<XConnection> m_xConnection;
};
void MorkDriverTest::setUp()
{
test::BootstrapFixture::setUp();
m_xMorkComponent = getMultiServiceFactory()->createInstance("com.sun.star.comp.sdbc.MorkDriver");
CPPUNIT_ASSERT_MESSAGE("no mork component!", m_xMorkComponent.is());
// is this the best way to pass test file through URL?
// may be take a custom Sequence< PropertyValue > route?
OUString url = OUString("sdbc:address:thunderbird:unittest:") +
getPathFromSrc("/connectivity/qa/connectivity/mork/abook_10_john_does.mab");
Sequence< PropertyValue > info;
Reference< XDriver> xDriver(m_xMorkComponent, UNO_QUERY);
if (!xDriver.is())
{
CPPUNIT_ASSERT_MESSAGE("cannot connect to mork driver!", xDriver.is());
}
m_xConnection = xDriver->connect(url, info);
if (!m_xConnection.is())
{
CPPUNIT_ASSERT_MESSAGE("cannot connect to address book data soure!", m_xConnection.is());
}
}
void MorkDriverTest::tearDown()
{
// how to make dispose() work?
// Reference< com::sun::star::lang::XComponent >( m_xMorkComponent, UNO_QUERY_THROW )->dispose();
test::BootstrapFixture::tearDown();
}
void MorkDriverTest::test_metadata()
{
Reference< XDatabaseMetaData > xDatabaseMetaData = m_xConnection->getMetaData();
if (!xDatabaseMetaData.is())
{
CPPUNIT_ASSERT_MESSAGE("cannot retrieve meta data!", xDatabaseMetaData.is());
}
const Any catalog;
const OUString schemaPattern = "%";
const OUString tableNamePattern = "%";
const Sequence< OUString > types;
Reference< XResultSet > xResultSet =
xDatabaseMetaData->getTables(catalog, schemaPattern, tableNamePattern, types);
if (!xResultSet.is())
{
CPPUNIT_ASSERT_MESSAGE("cannot retrieve tables!", xResultSet.is());
}
// TODO: how to access that result set and check the tables?
// it should be 3 tables inside: AddressBook, does_5 and does_10
}
void MorkDriverTest::test_select_default_all()
{
const OUString sql = "select \"E-mail\" from \"AddressBook\" ORDER BY \"E-mail\"";
Reference< XPreparedStatement > xStatement = m_xConnection->prepareStatement(sql);
if (!xStatement.is())
{
CPPUNIT_ASSERT_MESSAGE("cannot create prepared statement!", xStatement.is());
}
Reference< XResultSet > xResultSet = xStatement->executeQuery();
if (!xResultSet.is())
{
CPPUNIT_ASSERT_MESSAGE("cannot execure sql statement!", xResultSet.is());
}
Reference< XRow > xDelegatorRow(xResultSet, UNO_QUERY);
if (!xDelegatorRow.is())
{
CPPUNIT_ASSERT_MESSAGE("cannot extract row from result set!", xDelegatorRow.is());
}
sal_Bool result = xResultSet->first();
CPPUNIT_ASSERT_MESSAGE("fetch first row failed!", result);
OUString mail = xDelegatorRow->getString(1);
CPPUNIT_ASSERT_MESSAGE("first row is not john@doe.org!", mail.equalsAscii("john@doe.org"));
result = xResultSet->next();
CPPUNIT_ASSERT_MESSAGE("fetch second row failed!", result);
mail = xDelegatorRow->getString(1);
CPPUNIT_ASSERT_MESSAGE("second row is not john@doe10.org!", mail.equalsAscii("john@doe10.org"));
result = xResultSet->last();
CPPUNIT_ASSERT_MESSAGE("fetch last row failed!", result);
mail = xDelegatorRow->getString(1);
CPPUNIT_ASSERT_MESSAGE("last row is not john@doe9.org!", mail.equalsAscii("john@doe9.org"));
}
void MorkDriverTest::test_select_list_table_joe_doe_5()
{
const OUString sql = "select \"E-mail\" from \"does_5\" where \"E-mail\" LIKE '%doe5.org' ";
Reference< XPreparedStatement > xStatement = m_xConnection->prepareStatement(sql);
if (!xStatement.is())
{
CPPUNIT_ASSERT_MESSAGE("cannot create prepared statement!", xStatement.is());
}
Reference< XResultSet > xResultSet = xStatement->executeQuery();
if (!xResultSet.is())
{
CPPUNIT_ASSERT_MESSAGE("cannot execure sql statement!", xResultSet.is());
}
Reference< XRow > xDelegatorRow(xResultSet, UNO_QUERY);
if (!xDelegatorRow.is())
{
CPPUNIT_ASSERT_MESSAGE("cannot extract row from result set!", xDelegatorRow.is());
}
sal_Bool result = xResultSet->first();
CPPUNIT_ASSERT_MESSAGE("fetch first row failed!", result);
OUString mail = xDelegatorRow->getString(1);
CPPUNIT_ASSERT_MESSAGE("last row is not john@doe5.org!", mail.equalsAscii("john@doe5.org"));
}
CPPUNIT_TEST_SUITE_REGISTRATION(MorkDriverTest);
}}
CPPUNIT_PLUGIN_IMPLEMENT();
// <!-- <mdb:mork:z v="1.4"/> -->
< <(a=c)> // (f=iso-8859-1)
(B8=LastModifiedDate)(B9=RecordKey)(BA=AddrCharSet)(BB=LastRecordKey)
(BC=ns:addrbk:db:table:kind:pab)(BD=ListName)(BE=ListNickName)
(BF=ListDescription)(C0=ListTotalAddresses)(C1=LowercaseListName)
(C2=ns:addrbk:db:table:kind:deleted)(C3=_Yahoo)(C4=_MSN)
(C5=_GoogleTalk)(C6=_Skype)(C7=_JabberId)(C8=PreferDisplayName)
(C9=PhotoURI)(CA=PhotoType)(CB=PhotoName)(CC=DbRowID)(CD=_QQ)(CE=_ICQ)
(80=ns:addrbk:db:row:scope:card:all)
(81=ns:addrbk:db:row:scope:list:all)
(82=ns:addrbk:db:row:scope:data:all)(83=FirstName)(84=LastName)
(85=PhoneticFirstName)(86=PhoneticLastName)(87=DisplayName)
(88=NickName)(89=PrimaryEmail)(8A=LowercasePrimaryEmail)
(8B=SecondEmail)(8C=PreferMailFormat)(8D=PopularityIndex)
(8E=AllowRemoteContent)(8F=WorkPhone)(90=HomePhone)(91=FaxNumber)
(92=PagerNumber)(93=CellularNumber)(94=WorkPhoneType)(95=HomePhoneType)
(96=FaxNumberType)(97=PagerNumberType)(98=CellularNumberType)
(99=HomeAddress)(9A=HomeAddress2)(9B=HomeCity)(9C=HomeState)
(9D=HomeZipCode)(9E=HomeCountry)(9F=WorkAddress)(A0=WorkAddress2)
(A1=WorkCity)(A2=WorkState)(A3=WorkZipCode)(A4=WorkCountry)
(A5=JobTitle)(A6=Department)(A7=Company)(A8=_AimScreenName)
(A9=AnniversaryYear)(AA=AnniversaryMonth)(AB=AnniversaryDay)
(AC=SpouseName)(AD=FamilyName)(AE=WebPage1)(AF=WebPage2)(B0=BirthYear)
(B1=BirthMonth)(B2=BirthDay)(B3=Custom1)(B4=Custom2)(B5=Custom3)
(B6=Custom4)(B7=Notes)>
<(AF=b)(81=John Doe)(82=)(80=0)(83=John)(84=1)(85=Doe)(86=john@doe.org)
(87=generic)(88=John Doe2)(89=Doe2)(8A=john@doe2.org)(8B=2)(8C=John Doe3)
(8D=Doe3)(8E=john@doe3.org)(8F=3)(90=John Doe4)(91=Doe4)(92
=john@doe4.org)(93=4)(94=John Doe5)(95=Doe5)(96=john@doe5.org)(97=5)
(98=John Doe6)(99=Doe6)(9A=john@doe6.org)(9B=6)(9C=John Doe7)(9D=Doe7)
(9E=john@doe7.org)(9F=7)(A0=John Doe8)(A1=Doe8)(A2=john@doe8.org)
(A3=8)(A4=John Doe9)(A5=Doe9)(A6=john@doe9.org)(A7=9)(A8=John Doe10)
(A9=Doe10)(AA=john@doe10.org)(AB=10)(AC=a)(AD=Does_5)(AE=does_5)>
{1:^80 {(k^BC:c)(s=9)}
[1:^82(^BB=b)]
[1(^87^81)(^86=)(^C3=)(^A1=)(^AE=)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0=4)(^B9=b)(^CF=1)(^D0=2)(^D1=3)
(^D2=4)]
@$$}D}@
@$${E{@
< <(a=c)> // (f=iso-8859-1)
(D3=Address5)>
[-1:^81(^BD^AD)(^C1^AE)(^BE=)(^BF=)(^C0=5)(^B9=b)(^CF=1)(^D0=2)(^D1=3)
(^D2=4)(^D3=5)]
@$$}E}@
@$${F{@
[-2:^81(^BD^B0)(^C1^B1)(^BE=)(^BF=)(^C0=1)(^B9=c)(^CF=a)]
@$$}F}@
@$${10{@
[-2:^81(^BD^B0)(^C1^B1)(^BE=)(^BF=)(^C0=2)(^B9=c)(^CF=a)(^D0=6)]
@$$}10}@
@$${11{@
[-2:^81(^BD^B0)(^C1^B1)(^BE=)(^BF=)(^C0=3)(^B9=c)(^CF=a)(^D0=6)(^D1=7)]
@$$}11}@
@$${12{@
[-2:^81(^BD^B0)(^C1^B1)(^BE=)(^BF=)(^C0=4)(^B9=c)(^CF=a)(^D0=6)(^D1=7)
(^D2=8)]
@$$}12}@
@$${13{@
[-2:^81(^BD^B0)(^C1^B1)(^BE=)(^BF=)(^C0=5)(^B9=c)(^CF=a)(^D0=6)(^D1=7)
(^D2=8)(^D3=9)]
@$$}13}@
......@@ -87,6 +87,10 @@ OColumnAlias::OColumnAlias( const ::com::sun::star::uno::Reference< ::com::sun::
initialize( _rxORB );
}
OColumnAlias::OColumnAlias()
{
}
//------------------------------------------------------------------------------
void OColumnAlias::initialize( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB )
{
......
......@@ -31,7 +31,7 @@ namespace connectivity
{
namespace mork
{
class OColumnAlias
class SAL_DLLPUBLIC_EXPORT OColumnAlias
{
public:
struct AliasEntry
......@@ -57,6 +57,7 @@ namespace connectivity
public:
OColumnAlias( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & );
OColumnAlias();
inline bool hasAlias( const ::rtl::OUString& _rAlias ) const
{
......
......@@ -85,11 +85,11 @@ void OConnection::construct(const ::rtl::OUString& url,const Sequence< PropertyV
nLen = url.indexOf(':',nLen+1);
OSL_ENSURE( url.copy( 0, nLen ) == "sdbc:address", "OConnection::construct: invalid start of the URI - should never have survived XDriver::acceptsURL!" );
::rtl::OUString aAddrbookURI(url.copy(nLen+1));
OUString aAddrbookURI(url.copy(nLen+1));
// Get Scheme
nLen = aAddrbookURI.indexOf(':');
::rtl::OUString aAddrbookScheme;
::rtl::OUString sAdditionalInfo;
OUString aAddrbookScheme;
OUString sAdditionalInfo;
if ( nLen == -1 )
{
// There isn't any subschema: - but could be just subschema
......@@ -112,13 +112,23 @@ void OConnection::construct(const ::rtl::OUString& url,const Sequence< PropertyV
SAL_INFO("connectivity.mork", "URI = " << aAddrbookURI );
SAL_INFO("connectivity.mork", "Scheme = " << aAddrbookScheme );
::rtl::OUString defaultProfile = m_pProfileAccess->getDefaultProfile(::com::sun::star::mozilla::MozillaProductType_Thunderbird);
SAL_INFO("connectivity.mork", "DefaultProfile: " << defaultProfile);
OUString path;
const OUString UNITTEST_URL = "thunderbird:unittest:";
sal_Int32 unittestIndex = url.indexOf(UNITTEST_URL);
::rtl::OUString path = m_pProfileAccess->getProfilePath(::com::sun::star::mozilla::MozillaProductType_Thunderbird, defaultProfile);
SAL_INFO("connectivity.mork", "ProfilePath: " << path);
path += rtl::OUString( "/abook.mab" );
// production?
if (unittestIndex == -1)
{
OUString defaultProfile = m_pProfileAccess->getDefaultProfile(::com::sun::star::mozilla::MozillaProductType_Thunderbird);
path = m_pProfileAccess->getProfilePath(::com::sun::star::mozilla::MozillaProductType_Thunderbird, defaultProfile);
SAL_INFO("connectivity.mork", "DefaultProfile: " << defaultProfile);
SAL_INFO("connectivity.mork", "ProfilePath: " << path);
path += rtl::OUString( "/abook.mab" );
}
else
{
path = aAddrbookURI.replaceFirst(UNITTEST_URL, "");
}
SAL_INFO("connectivity.mork", "AdressbookPath: " << path);
......
......@@ -31,6 +31,8 @@ static ::osl::Mutex m_aMetaMutex;
#include <com/sun/star/sdb/ErrorCondition.hpp>
#include <comphelper/processfactory.hxx>
#include "MorkParser.hxx"
using namespace connectivity;
using namespace connectivity::mork;
......@@ -52,11 +54,21 @@ sal_Bool MDatabaseMetaDataHelper::getTableStrings( OConnection*
::rtl::OString sAbURIString;
SAL_INFO("connectivity.mork", "=> MDatabaseMetaDataHelper::getTableStrings()");
_pCon->getMorkParser();
// TODO: retrieve Tables from MorkParser
// only put for now the private adress book
rtl::OUString table = rtl::OUString::createFromAscii( "AddressBook");
/* add default table */
OUString table = "AddressBook";
_rStrings.push_back(table);
/* retrieve list table names */
std::set<std::string> lists;
_pCon->getMorkParser()->retrieveLists(lists);
for (::std::set<std::string>::iterator iter = lists.begin(); iter != lists.end(); ++iter) {
OUString groupTableName = OStringToOUString((*iter).c_str(), RTL_TEXTENCODING_UTF8);
SAL_INFO("connectivity.mork", "add Table " << groupTableName);
_rStrings.push_back(groupTableName);
}
return( sal_True );
}
......@@ -70,14 +82,14 @@ sal_Bool MDatabaseMetaDataHelper::getTables( OConnection* _pCon,
static ODatabaseMetaDataResultSet::ORows aRows;
SAL_INFO("connectivity.mork", "=> MDatabaseMetaDataHelper::getTables()" );
SAL_INFO("connectivity.mork", "tableNamePattern : " << tableNamePattern);
::osl::MutexGuard aGuard( m_aMetaMutex );
ODatabaseMetaDataResultSet::ORows().swap(aRows); // this makes real clear where memory is freed as well
aRows.clear();
::std::vector< ::rtl::OUString > tables;
// ::std::vector< ::rtl::OUString > tabletypes;
::rtl::OUString matchAny = rtl::OUString::createFromAscii("%");
OUString matchAny = "%";
if ( !getTableStrings( _pCon, tables ) )
return sal_False;
......@@ -86,21 +98,20 @@ sal_Bool MDatabaseMetaDataHelper::getTables( OConnection* _pCon,
ODatabaseMetaDataResultSet::ORow aRow(3);
::rtl::OUString aTableName = tables[i];
//::rtl::OUString aTableType = tabletypes[i];
SAL_INFO("connectivity.mork", "TableName: " << aTableName );
// return tables to caller
if (match( tableNamePattern, aTableName, '\0' ))
{
{
if ( aTableName.isEmpty() ) {
aTableName = rtl::OUString::createFromAscii("AddressBook");
aTableName = "AddressBook";
}
SAL_INFO("connectivity.mork", "TableName: " << aTableName);
aRow.push_back( new ORowSetValueDecorator( aTableName ) ); // Table name
aRow.push_back( new ORowSetValueDecorator( rtl::OUString::createFromAscii("TABLE") ) ); // Table type
aRow.push_back( new ORowSetValueDecorator( OUString::createFromAscii("TABLE") ) ); // Table type
aRow.push_back( ODatabaseMetaDataResultSet::getEmptyValue() ); // Remarks
aRows.push_back(aRow);
}
......
......@@ -26,6 +26,8 @@
#include <stdlib.h>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <string.h>
#include "resource/mork_res.hrc"
......@@ -239,7 +241,18 @@ sal_Int32 MQueryHelper::executeQuery(OConnection* xConnection)
SAL_INFO("connectivity.mork", "MQueryHelper::executeQuery()" );
reset();
//dumpExpression(this, &m_aExpr);
rtl::OString oStringTable = OUStringToOString( m_aAddressbook, RTL_TEXTENCODING_UTF8 );
std::set<int> listRecords;
bool handleListTable = false;
// check if we are retrieving the default table
if (oStringTable != "AddressBook")
{
handleListTable = true;
// retrieve row ids for that list table
std::string listTable = oStringTable.getStr();
xConnection->getMorkParser()->getRecordKeysForListTable(listTable, listRecords);
}
MorkTableMap::iterator tableIter;
MorkTableMap *Tables = xConnection->getMorkParser()->getTables( 0x80 );
MorkRowMap *Rows = 0;
......@@ -249,38 +262,53 @@ sal_Int32 MQueryHelper::executeQuery(OConnection* xConnection)
for ( tableIter = Tables->begin(); tableIter != Tables->end(); ++tableIter )
{
if (tableIter->first != 1) break;
Rows = xConnection->getMorkParser()->getRows( 0x80, &tableIter->second );
Rows = xConnection->getMorkParser()->getRows( 0x80, &tableIter->second );
if ( Rows )
{
// Iterate all rows
for ( rowIter = Rows->begin(); rowIter != Rows->end(); ++rowIter )
{
// list specific table
// only retrieve rowIds that belong to that list table.
if (handleListTable)
{
int rowId = rowIter->first;
// belongs this row id to the list table?
if (listRecords.end() == std::find(listRecords.begin(), listRecords.end(), rowId))
{
// no, skip it
continue;
}
}
MQueryHelperResultEntry* entry = new MQueryHelperResultEntry();
for (MorkCells::iterator CellsIter = rowIter->second.begin();
CellsIter != rowIter->second.end(); ++CellsIter )
{
std::string column = xConnection->getMorkParser()->getColumn(CellsIter->first);
std::string value = xConnection->getMorkParser()->getValue(CellsIter->second);
//SAL_INFO("connectivity.mork", "key: " << column << " value: " << value);
OString key(column.c_str(), static_cast<sal_Int32>(column.size()));
OString valueOString(value.c_str(), static_cast<sal_Int32>(value.size()));
rtl::OUString valueOUString = ::rtl::OStringToOUString( valueOString, RTL_TEXTENCODING_UTF8 );
rtl::OUString valueOUString = OStringToOUString( valueOString, RTL_TEXTENCODING_UTF8 );
entry->setValue(key, valueOUString);
}
::std::vector< sal_Bool > vector = entryMatchedByExpression(this, &m_aExpr, entry);
sal_Bool result = sal_True;
for (::std::vector<sal_Bool>::iterator iter = vector.begin(); iter != vector.end(); ++iter) {
for (::std::vector<sal_Bool>::iterator iter = vector.begin(); iter != vector.end(); ++iter)
{
result = result && *iter;
}
if (result) {
if (result)
{
append(entry);
}
else
{
delete entry;
}
}
}
}
return 0;
}
......
......@@ -185,6 +185,9 @@ namespace connectivity
void getCardValues(nsIAbCard *card,sal_uInt32 rowIndex=0);
*/
sal_Int32 doQueryDefaultTable(OConnection* xConnection);
sal_Int32 doQueryListTable(OConnection* xConnection, rtl::OString& ouStringTable);
public:
MQueryHelper(const OColumnAlias& _ca);
virtual ~MQueryHelper();
......
......@@ -70,8 +70,8 @@ using namespace com::sun::star::util;
Sequence< ::rtl::OUString > SAL_CALL OResultSet::getSupportedServiceNames( ) throw( RuntimeException)
{
::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(2);
aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdbc.ResultSet"));
aSupported[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdbcx.ResultSet"));
aSupported[0] = OUString("com.sun.star.sdbc.ResultSet");
aSupported[1] = OUString("com.sun.star.sdbcx.ResultSet");
return aSupported;
}
// -------------------------------------------------------------------------
......
......@@ -39,6 +39,7 @@
#include <stdexcept>
#include <fstream>
#include <iostream>
#include <algorithm>
std::string g_Empty = "";
......@@ -598,6 +599,138 @@ std::string &MorkParser::getColumn( int oid )
return foundIter->second;
}
void MorkParser::retrieveLists(std::set<std::string>& lists)
{
MorkTableMap* tables = getTables(defaultScope_);
if (!tables) return;
for (MorkTableMap::iterator TableIter = tables->begin();
TableIter != tables->end(); TableIter++ )
{
#ifdef VERBOSE
std::cout << "\t Table:"
<< ( ( int ) TableIter->first < 0 ? "-" : " " )
<< std::hex << std::uppercase << TableIter->first << std::endl;
#endif
MorkRowMap* rows = getRows( defaultListScope_, &TableIter->second );
if (!rows) return;
for ( MorkRowMap::iterator RowIter = rows->begin();
RowIter != rows->end(); RowIter++ )
{
#ifdef VERBOSE
std::cout << "\t\t\t Row Id:"
<< ( ( int ) RowIter->first < 0 ? "-" : " ")
<< std::hex << std::uppercase << RowIter->first << std::endl;
std::cout << "\t\t\t\t Cells:\r\n";
#endif
// Get cells
for ( MorkCells::iterator cellsIter = RowIter->second.begin();
cellsIter != RowIter->second.end(); cellsIter++ )
{
if (cellsIter->first == 0xC1)
{
lists.insert(getValue( cellsIter->second ));
break;
}
}
}
}
}
void MorkParser::getRecordKeys4List(std::string& listName, std::vector<std::string>& records)
{
MorkTableMap* tables = getTables(defaultScope_);
if (!tables) return;
for (MorkTableMap::iterator TableIter = tables->begin();
TableIter != tables->end(); TableIter++ )
{
#ifdef VERBOSE
std::cout << "\t Table:"
<< ( ( int ) TableIter->first < 0 ? "-" : " " )
<< std::hex << std::uppercase << TableIter->first << std::endl;
#endif
MorkRowMap* rows = getRows( 0x81, &TableIter->second );
if (!rows) return;
for ( MorkRowMap::iterator RowIter = rows->begin();
RowIter != rows->end(); RowIter++ )
{
#ifdef VERBOSE
std::cout << "\t\t\t Row Id:"
<< ( ( int ) RowIter->first < 0 ? "-" : " ")
<< std::hex << std::uppercase << RowIter->first << std::endl;
std::cout << "\t\t\t\t Cells:\r\n";
#endif
// Get cells
bool listFound = false;
for ( MorkCells::iterator cellsIter = RowIter->second.begin();
cellsIter != RowIter->second.end(); cellsIter++ )
{
if (listFound)
{
if (cellsIter->first >= 0xC7)
{
std::string value = getValue(cellsIter->second);
records.push_back(value);
}
}
else if ((cellsIter->first == 0xC1) &&
listName == getValue( cellsIter->second ))
{
listFound = true;
}
}
}
}
}
void MorkParser::getRecordKeysForListTable(std::string& listName, std::set<int>& records)
{
MorkTableMap* tables = getTables(defaultScope_);
if (!tables) return;
for (MorkTableMap::iterator TableIter = tables->begin();
TableIter != tables->end(); TableIter++ )
{
#ifdef VERBOSE
std::cout << "\t Table:"
<< ( ( int ) TableIter->first < 0 ? "-" : " " )
<< std::hex << std::uppercase << TableIter->first << std::endl;
#endif
MorkRowMap* rows = getRows( 0x81, &TableIter->second );
if (!rows) return;
for ( MorkRowMap::iterator RowIter = rows->begin();
RowIter != rows->end(); RowIter++ )
{
#ifdef VERBOSE
std::cout << "\t\t\t Row Id:"
<< ( ( int ) RowIter->first < 0 ? "-" : " ")
<< std::hex << std::uppercase << RowIter->first << std::endl;
std::cout << "\t\t\t\t Cells:\r\n";
#endif
// Get cells
bool listFound = false;
for ( MorkCells::iterator cellsIter = RowIter->second.begin();
cellsIter != RowIter->second.end(); cellsIter++ )
{
if (listFound)
{
if (cellsIter->first >= 0xC7)
{
std::string value = getValue(cellsIter->second);
int id = strtoul(value.c_str(), 0, 16);
records.insert(id);
}
}
else if ((cellsIter->first == 0xC1) &&
listName == getValue( cellsIter->second ))
{
listFound = true;
}
}
}
}
}
void MorkParser::dump()
{
std::cout << "Column Dict:\r\n";
......
......@@ -38,6 +38,8 @@
#include <string>
#include <map>
#include <set>
#include <vector>
#include "dllapi.h"
......@@ -111,6 +113,10 @@ public:
std::string &getColumn( int oid );
void retrieveLists(std::set<std::string>& lists);
void getRecordKeys4List(std::string& listName, std::vector<std::string>& records);
void getRecordKeysForListTable(std::string& listName, std::set<int>& records);
void dump();
protected: // Members
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment