diff options
author | David Ostrovsky <david@ostrovsky.org> | 2012-09-30 19:53:40 +0200 |
---|---|---|
committer | Muthu Subramanian <sumuthu@suse.com> | 2012-10-10 13:35:13 +0530 |
commit | 36026a6ae5d2f42db5fa262a358a3bc8e33e036c (patch) | |
tree | b27b7da466dde7e719f1c4db0fb50516470021dc /connectivity/source/drivers/mork | |
parent | f6739073edc1b593035f25becbd0e9d6d536ef0c (diff) |
mork driver: add list tables and unit test
Change-Id: I594b24341eb38c05523f578c1dc2e43d90544f30
Diffstat (limited to 'connectivity/source/drivers/mork')
-rw-r--r-- | connectivity/source/drivers/mork/MColumnAlias.cxx | 4 | ||||
-rw-r--r-- | connectivity/source/drivers/mork/MColumnAlias.hxx | 3 | ||||
-rw-r--r-- | connectivity/source/drivers/mork/MConnection.cxx | 28 | ||||
-rw-r--r-- | connectivity/source/drivers/mork/MDatabaseMetaDataHelper.cxx | 31 | ||||
-rw-r--r-- | connectivity/source/drivers/mork/MQueryHelper.cxx | 46 | ||||
-rw-r--r-- | connectivity/source/drivers/mork/MQueryHelper.hxx | 3 | ||||
-rw-r--r-- | connectivity/source/drivers/mork/MResultSet.cxx | 4 | ||||
-rw-r--r-- | connectivity/source/drivers/mork/MorkParser.cxx | 133 | ||||
-rw-r--r-- | connectivity/source/drivers/mork/MorkParser.hxx | 6 |
9 files changed, 227 insertions, 31 deletions
diff --git a/connectivity/source/drivers/mork/MColumnAlias.cxx b/connectivity/source/drivers/mork/MColumnAlias.cxx index 624b5ab88e43..ba653c3e9009 100644 --- a/connectivity/source/drivers/mork/MColumnAlias.cxx +++ b/connectivity/source/drivers/mork/MColumnAlias.cxx @@ -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 ) { diff --git a/connectivity/source/drivers/mork/MColumnAlias.hxx b/connectivity/source/drivers/mork/MColumnAlias.hxx index 45f6f780c966..21f21963fc81 100644 --- a/connectivity/source/drivers/mork/MColumnAlias.hxx +++ b/connectivity/source/drivers/mork/MColumnAlias.hxx @@ -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 { diff --git a/connectivity/source/drivers/mork/MConnection.cxx b/connectivity/source/drivers/mork/MConnection.cxx index a35badddc2c8..47525d2f946b 100644 --- a/connectivity/source/drivers/mork/MConnection.cxx +++ b/connectivity/source/drivers/mork/MConnection.cxx @@ -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); diff --git a/connectivity/source/drivers/mork/MDatabaseMetaDataHelper.cxx b/connectivity/source/drivers/mork/MDatabaseMetaDataHelper.cxx index a22b660650a8..1507b8b6ec2e 100644 --- a/connectivity/source/drivers/mork/MDatabaseMetaDataHelper.cxx +++ b/connectivity/source/drivers/mork/MDatabaseMetaDataHelper.cxx @@ -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); } diff --git a/connectivity/source/drivers/mork/MQueryHelper.cxx b/connectivity/source/drivers/mork/MQueryHelper.cxx index 9091d108e0ae..efd56f42b49a 100644 --- a/connectivity/source/drivers/mork/MQueryHelper.cxx +++ b/connectivity/source/drivers/mork/MQueryHelper.cxx @@ -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; } diff --git a/connectivity/source/drivers/mork/MQueryHelper.hxx b/connectivity/source/drivers/mork/MQueryHelper.hxx index 28b1e0739e9e..de1fff09d8cf 100644 --- a/connectivity/source/drivers/mork/MQueryHelper.hxx +++ b/connectivity/source/drivers/mork/MQueryHelper.hxx @@ -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(); diff --git a/connectivity/source/drivers/mork/MResultSet.cxx b/connectivity/source/drivers/mork/MResultSet.cxx index 49ee90a0f387..03f1c1bfba49 100644 --- a/connectivity/source/drivers/mork/MResultSet.cxx +++ b/connectivity/source/drivers/mork/MResultSet.cxx @@ -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; } // ------------------------------------------------------------------------- diff --git a/connectivity/source/drivers/mork/MorkParser.cxx b/connectivity/source/drivers/mork/MorkParser.cxx index da772a101f49..06373310e3d5 100644 --- a/connectivity/source/drivers/mork/MorkParser.cxx +++ b/connectivity/source/drivers/mork/MorkParser.cxx @@ -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"; diff --git a/connectivity/source/drivers/mork/MorkParser.hxx b/connectivity/source/drivers/mork/MorkParser.hxx index 76544411264a..8ac7584a3d66 100644 --- a/connectivity/source/drivers/mork/MorkParser.hxx +++ b/connectivity/source/drivers/mork/MorkParser.hxx @@ -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 |