diff options
author | Release Engineers <releng@openoffice.org> | 2009-07-03 12:24:35 +0000 |
---|---|---|
committer | Release Engineers <releng@openoffice.org> | 2009-07-03 12:24:35 +0000 |
commit | ab3a8d0d5f8d5389cb6c9968ad42fb358e343b10 (patch) | |
tree | 3d39cc192154172a2e781f70d8b6e49a24a517d2 /connectivity/source/drivers/evoab | |
parent | b7975b057e45b141b10747d33325b281146b337e (diff) |
CWS-TOOLING: integrate CWS dbaperf2
2009-06-22 11:04:36 +0200 msc r273202 : #100000# fix to run this test
2009-06-22 09:41:04 +0200 msc r273200 : #100000# correct case
2009-06-22 09:02:42 +0200 msc r273199 : new SRB
2009-06-22 08:53:26 +0200 msc r273198 : #100000
2009-06-15 12:36:32 +0200 oj r272976 : test
2009-06-12 14:23:23 +0200 msc r272918 : #101587# unused feature was removed
2009-06-12 06:45:17 +0200 oj r272903 : use GUI instead of OS
2009-06-11 09:12:30 +0200 oj r272845 : remove unused dep
2009-06-11 09:11:09 +0200 oj r272844 : ColumnAliasInOrderBy not supported
2009-06-11 08:27:00 +0200 oj r272843 : CWS-TOOLING: rebase CWS dbaperf2 to trunk@272827 (milestone: DEV300:m50)
2009-06-10 15:30:17 +0200 msc r272822 : #100000
2009-06-10 15:27:40 +0200 msc r272820 : #102515# new function for the database type list
2009-06-10 15:26:09 +0200 msc r272818 : move file to dbaccess/tools/dbcreatetools.inc
2009-06-10 15:20:10 +0200 msc r272816 : #102515# new function for the database type list
2009-06-10 12:34:46 +0200 oj r272803 : #i101587# check extension
2009-06-10 11:53:45 +0200 oj r272800 : remove unused code
2009-06-09 09:57:25 +0200 oj r272752 : #i101587# EscapeDateTime moved into features section
2009-06-09 09:56:26 +0200 oj r272751 : enable finish
2009-06-08 11:50:37 +0200 oj r272726 : #i102588# move convert tzo saveDataSource
2009-06-05 11:54:20 +0200 jsk r272676 : #i102515# - NEW: Functions to retrieve Database names from API
2009-06-05 10:52:22 +0200 jsk r272671 : NEW: Functions to retrieve Database names from API
2009-06-05 09:36:54 +0200 oj r272666 : handle win and unx differently
2009-06-05 09:36:28 +0200 oj r272665 : handle win and unx differently
2009-06-04 13:41:56 +0200 oj r272625 : #i101268# make use of stringbuffer instead of oustring
2009-06-04 10:18:14 +0200 oj r272612 : add SAL_DLLPUBLIC_EXPORT
2009-05-28 10:56:33 +0200 oj r272381 : #i101587# create langpacks
2009-05-28 10:41:59 +0200 oj r272380 : #i101587# create langpacks
2009-05-28 10:29:30 +0200 oj r272379 : #i101587# create langpacks
2009-05-07 10:11:46 +0200 oj r271635 : fix compile warnings
2009-05-07 07:01:31 +0200 oj r271619 : change type from int32 to PathID
2009-05-07 06:53:19 +0200 oj r271618 : add all
2009-05-06 14:57:02 +0200 oj r271595 : add missing lib
2009-05-06 14:56:54 +0200 oj r271594 : no used anymore
2009-05-06 14:56:08 +0200 oj r271593 : no used anymore
2009-05-06 14:54:25 +0200 oj r271592 : no used anymore
2009-05-06 14:45:59 +0200 oj r271591 : add missing lib
2009-05-06 14:41:54 +0200 oj r271590 : change wnt
2009-05-06 14:22:21 +0200 oj r271589 : #i101587# use config for the drivers
2009-05-06 14:21:39 +0200 oj r271588 : #i101587# add new set for metadata and config data for driver
2009-05-06 14:19:36 +0200 oj r271587 : #i101587# handle metadata and props of driver
2009-05-06 10:11:11 +0200 oj r271570 : #i101587# correct wrong use of reference
2009-05-06 09:24:33 +0200 oj r271567 : #i101587# add new set for metadata
2009-05-06 08:52:06 +0200 oj r271563 : #i101587# add driver configuration
2009-05-06 08:51:04 +0200 oj r271562 : #i101587# add driver configuration
2009-05-04 10:24:41 +0200 oj r271442 : CWS-TOOLING: rebase CWS dbaperf2 to trunk@271427 (milestone: DEV300:m47)
2009-04-28 07:06:22 +0200 oj r271303 : compile error
2009-04-27 14:12:48 +0200 oj r271270 : #i101268# make use of stringbuffer instead of oustring
2009-04-27 14:12:27 +0200 oj r271269 : #i101268# make use of stringbuffer instead of oustring
2009-04-27 09:30:10 +0200 oj r271255 : use string buffer when possible
2009-04-24 11:56:01 +0200 oj r271207 : #i101268# remove end() call from loop
2009-04-23 14:24:03 +0200 oj r271171 : add dep
2009-04-23 13:25:25 +0200 oj r271164 : #i101268# add config entries for database drivers
2009-04-23 13:07:13 +0200 oj r271161 : #i101268# add config entries for database drivers
2009-04-23 13:06:33 +0200 oj r271160 : #i101268# add parent url pattern entry for driver node
2009-04-23 13:05:39 +0200 oj r271159 : #i101268# add config entry for driver node
2009-04-23 13:04:09 +0200 oj r271157 : #i101268# add config entry for driver node
2009-04-23 06:41:32 +0200 oj r271142 : #i101268# add new configuration file Drivers
2009-04-22 13:49:19 +0200 oj r271103 : convert EOL
2009-04-22 13:29:17 +0200 oj r271101 : #i101268# use of driver configuration entries for features and properties
2009-04-22 13:28:08 +0200 oj r271100 : #i101268# use of driver configuration entries for features and properties
2009-04-22 13:15:26 +0200 oj r271098 : #i101268# add new configuration file Drivers
2009-04-22 13:14:43 +0200 oj r271097 : #i101268# use of driver configuration entries for features and properties
Diffstat (limited to 'connectivity/source/drivers/evoab')
35 files changed, 5278 insertions, 0 deletions
diff --git a/connectivity/source/drivers/evoab/LCatalog.cxx b/connectivity/source/drivers/evoab/LCatalog.cxx new file mode 100644 index 000000000000..713af210ac38 --- /dev/null +++ b/connectivity/source/drivers/evoab/LCatalog.cxx @@ -0,0 +1,75 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LCatalog.cxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" + + +#include "LCatalog.hxx" +#include "LConnection.hxx" +#include "LTables.hxx" +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/sdbc/XResultSet.hpp> + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::sdbcx; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::container; + +// ------------------------------------------------------------------------- +using namespace connectivity::evoab; +// ------------------------------------------------------------------------- +OEvoabCatalog::OEvoabCatalog(OEvoabConnection* _pCon) : file::OFileCatalog(_pCon) +{ +} +// ------------------------------------------------------------------------- +void OEvoabCatalog::refreshTables() +{ + TStringVector aVector; + Sequence< ::rtl::OUString > aTypes; + Reference< XResultSet > xResult = m_xMetaData->getTables(Any(), + ::rtl::OUString::createFromAscii("%"),::rtl::OUString::createFromAscii("%"),aTypes); + + if(xResult.is()) + { + Reference< XRow > xRow(xResult,UNO_QUERY); + while(xResult->next()) + aVector.push_back(xRow->getString(3)); + } + if(m_pTables) + m_pTables->reFill(aVector); + else + m_pTables = new OEvoabTables(m_xMetaData,*this,m_aMutex,aVector); +} +// ----------------------------------------------------------------------------- + + + diff --git a/connectivity/source/drivers/evoab/LCatalog.hxx b/connectivity/source/drivers/evoab/LCatalog.hxx new file mode 100644 index 000000000000..e539db3a8fc3 --- /dev/null +++ b/connectivity/source/drivers/evoab/LCatalog.hxx @@ -0,0 +1,52 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LCatalog.hxx,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_EVOAB_LCATALOG_HXX_ +#define _CONNECTIVITY_EVOAB_LCATALOG_HXX_ + +#include "file/FCatalog.hxx" + +namespace connectivity +{ + namespace evoab + { + class OEvoabConnection; + class OEvoabCatalog : public file::OFileCatalog + { + public: + virtual void refreshTables(); + + public: + OEvoabCatalog(OEvoabConnection* _pCon); + }; + } +} +#endif // _CONNECTIVITY_EVOAB_LCATALOG_HXX_ + diff --git a/connectivity/source/drivers/evoab/LColumnAlias.cxx b/connectivity/source/drivers/evoab/LColumnAlias.cxx new file mode 100644 index 000000000000..30b94e2e20c9 --- /dev/null +++ b/connectivity/source/drivers/evoab/LColumnAlias.cxx @@ -0,0 +1,235 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LColumnAlias.cxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "LColumnAlias.hxx" +#include "LDriver.hxx" +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include "LConfigAccess.hxx" + +using namespace ::connectivity; +using namespace ::connectivity::evoab; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::container; + +static const ::rtl::OUString sProgrammaticNames[] = +{ + ::rtl::OUString::createFromAscii("FirstName"), + ::rtl::OUString::createFromAscii("LastName"), + ::rtl::OUString::createFromAscii("DisplayName"), + ::rtl::OUString::createFromAscii("NickName"), + ::rtl::OUString::createFromAscii("PrimaryEmail"), + ::rtl::OUString::createFromAscii("SecondEmail"), + ::rtl::OUString::createFromAscii("PreferMailFormat"), + ::rtl::OUString::createFromAscii("WorkPhone"), + ::rtl::OUString::createFromAscii("HomePhone"), + ::rtl::OUString::createFromAscii("FaxNumber"), + ::rtl::OUString::createFromAscii("PagerNumber"), + ::rtl::OUString::createFromAscii("CellularNumber"), + ::rtl::OUString::createFromAscii("HomeAddress"), + ::rtl::OUString::createFromAscii("HomeAddress2"), + ::rtl::OUString::createFromAscii("HomeCity"), + ::rtl::OUString::createFromAscii("HomeState"), + ::rtl::OUString::createFromAscii("HomeZipCode"), + ::rtl::OUString::createFromAscii("HomeCountry"), + ::rtl::OUString::createFromAscii("WorkAddress"), + ::rtl::OUString::createFromAscii("WorkAddress2"), + ::rtl::OUString::createFromAscii("WorkCity"), + ::rtl::OUString::createFromAscii("WorkState"), + ::rtl::OUString::createFromAscii("WorkZipCode"), + ::rtl::OUString::createFromAscii("WorkCountry"), + ::rtl::OUString::createFromAscii("JobTitle"), + ::rtl::OUString::createFromAscii("Department"), + ::rtl::OUString::createFromAscii("Company"), + ::rtl::OUString::createFromAscii("WebPage1"), + ::rtl::OUString::createFromAscii("WebPage2"), + ::rtl::OUString::createFromAscii("BirthYear"), + ::rtl::OUString::createFromAscii("BirthMonth"), + ::rtl::OUString::createFromAscii("BirthDay"), + ::rtl::OUString::createFromAscii("Notes") +}; +//------------------------------------------------------------------------------ +OColumnAlias::OColumnAlias() +{ + // Initialise m_aAlias with the default values from sProgrammaticNames. + initialise(); + + // Initialise m_aAlias map with the default values from sProgrammaticNames. + setAliasMap(); +} +//------------------------------------------------------------------ +OColumnAlias::~OColumnAlias() +{ +} +//------------------------------------------------------------------ +void OColumnAlias::initialise() +{ + m_aAlias.reserve( END - FIRSTNAME + 1 ); + for (sal_Int32 i(FIRSTNAME); i < END; ++i) + { + m_aAlias.push_back(sProgrammaticNames[i]); + m_aHeadLineNames.push_back(sProgrammaticNames[i]); + } + + return; +} +//------------------------------------------------------------------ +void OColumnAlias::setAlias(const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiServiceFactory >& _rxORB) +{ + OSL_TRACE("OColumnAlias::setAlias()entered"); + + // open our driver settings config node + + // the config path for our own driver's settings + Reference< XPropertySet > xEvoDriverNode = createDriverConfigNode( _rxORB, OEvoabDriver::getImplementationName_Static() ); + //Reference< XPropertySet > xMozDriverNode = createDriverConfigNode( _rxORB, mozab::OConnection::getDriverImplementationName() ); + Reference< XPropertySet > xMozDriverNode = createDriverConfigNode( _rxORB, ::rtl::OUString::createFromAscii ("com.sun.star.comp.sdbc.MozabDriver") ); + if ( xEvoDriverNode.is() && xMozDriverNode.is() ) + { + try + { + //============================================================= + Reference< XNameAccess > xEvoAliasesNode; + Reference< XNameAccess > xMozAliasesNode; + xEvoDriverNode->getPropertyValue( ::rtl::OUString::createFromAscii("ColumnAliases") ) >>= xEvoAliasesNode; + xMozDriverNode->getPropertyValue( ::rtl::OUString::createFromAscii("ColumnAliases") ) >>= xMozAliasesNode; + OSL_ENSURE( xEvoAliasesNode.is(), "OColumnAlias::setAlias: missing the evolution aliases node!" ); + OSL_ENSURE( xMozAliasesNode.is(), "OColumnAlias::setAlias: missing the mozilla aliases node!" ); + + // this is a set of string nodes + Sequence< ::rtl::OUString > aColumnProgrammaticNames; + //OSL_TRACE("OColumnAlias::setAlias()before xAliasesNode->getElementNames()"); + if ( xEvoAliasesNode.is() ) + aColumnProgrammaticNames = xEvoAliasesNode->getElementNames(); + //OSL_TRACE("OColumnAlias::setAlias()after xAliasesNode->getElementNames()"); + + //============================================================= + // travel through all the set elements + const ::rtl::OUString* pProgrammaticNames = aColumnProgrammaticNames.getConstArray(); + const ::rtl::OUString* pProgrammaticNamesEnd = pProgrammaticNames + aColumnProgrammaticNames.getLength(); + ::rtl::OUString sAssignedAlias; + ::rtl::OUString sHeadLineName; + + for ( ; pProgrammaticNames < pProgrammaticNamesEnd; ++pProgrammaticNames ) + { + //OSL_TRACE("OColumnAlias::setAlias()::*pProgrammaticNames = %s\n", ((OUtoCStr(*pProgrammaticNames)) ? (OUtoCStr(*pProgrammaticNames)):("NULL")) ); + OSL_ENSURE( m_aAliasMap.end() != m_aAliasMap.find( *pProgrammaticNames ), + "OColumnAlias::setAlias: found an invalid programmtic name!" ); + // if this asserts, somebody stored a programmatic name in the configuration + // which is not allowed (i.e. not in the list of known programmatics). + //OSL_TRACE("OColumnAlias::setAlias()before xAliasesNode->getByName()"); + +#if OSL_DEBUG_LEVEL > 0 + sal_Bool bExtractionSuccess = +#endif + xMozAliasesNode->getByName( *pProgrammaticNames) >>= sAssignedAlias; + OSL_ENSURE( bExtractionSuccess, "OColumnAlias::setAlias: invalid mozilla config data!" ); +#if OSL_DEBUG_LEVEL > 0 + bExtractionSuccess = +#endif + xEvoAliasesNode->getByName( *pProgrammaticNames) >>= sHeadLineName; + OSL_ENSURE( bExtractionSuccess, "OColumnAlias::setAlias: invalid evolution config data!" ); + //OSL_TRACE("OColumnAlias::setAlias()after xAliasesNode->getByName()"); + + // normalize in case the config data is corrupted + // (what we really don't need is an empty alias ...) + if ( 0 == sAssignedAlias.getLength() ) + sAssignedAlias = *pProgrammaticNames; + if ( 0 == sHeadLineName.getLength() ) + sHeadLineName = *pProgrammaticNames; + //OSL_TRACE("OColumnAlias::setAlias()::sAssignedAlias = %s\n", ((OUtoCStr(sAssignedAlias)) ? (OUtoCStr(sAssignedAlias)):("NULL")) ); + //OSL_TRACE("OColumnAlias::setAlias()::sHeadLineName = %s\n", ((OUtoCStr(sHeadLineName)) ? (OUtoCStr(sHeadLineName)):("NULL")) ); + + //============================================================= + // check the value + // look up the programmatic indicated by pProgrammaticNames in the known programmatics + const ::rtl::OUString* pProgrammatic = sProgrammaticNames + FIRSTNAME; + const ::rtl::OUString* pProgrammaticEnd = sProgrammaticNames + END; + + OSL_ENSURE( (sal_Int32)m_aAlias.size() == pProgrammaticEnd - pProgrammatic, + "OColumnAlias::setAlias: aliases vector not yet initialized!" ); + + // the destination where we want to remember the alias + ::std::vector< ::rtl::OUString >::iterator aAlias = m_aAlias.begin(); + ::std::vector< ::rtl::OUString >::iterator aHeadLineName = m_aHeadLineNames.begin(); + + for ( ; pProgrammatic < pProgrammaticEnd; ++pProgrammatic, ++aAlias, ++aHeadLineName ) + { + //OSL_TRACE("OColumnAlias::setAlias()::*pProgrammatic = %s\n", ((OUtoCStr(*pProgrammatic)) ? (OUtoCStr(*pProgrammatic)):("NULL")) ); + if ( pProgrammaticNames->equals( *pProgrammatic ) ) + { + // add alias to the vector + *aAlias = sAssignedAlias; + *aHeadLineName = sHeadLineName; + break; + } + } + } + } + catch( const Exception& ) + { + OSL_ENSURE( sal_False, "OColumnAlias::setAlias: could not read my driver's configuration data!" ); + } + } + + // Initialise m_aAliasMap. + setAliasMap(); + + return; +} +//------------------------------------------------------------------ +const ::std::vector< ::rtl::OUString> & OColumnAlias::getAlias() const +{ + return m_aAlias; +} +//------------------------------------------------------------------ +const ::std::map< ::rtl::OUString, ::rtl::OUString> & OColumnAlias::getAliasMap() const +{ + return m_aAliasMap; +} +//------------------------------------------------------------------ +void OColumnAlias::setAliasMap() +{ + // Fill the map with the values of m_aAlias + // and the sProgrammaticNames array. + for (sal_Int32 i(FIRSTNAME); i < END; ++i) { + m_aAliasMap[m_aAlias[i]] = m_aHeadLineNames[i]; + //OSL_TRACE("OColumnAlias::setAliasMap()::m_aAlias[i] = %s\n", ((OUtoCStr(m_aAlias[i])) ? (OUtoCStr(m_aAlias[i])):("NULL")) ); + //OSL_TRACE("OColumnAlias::setAliasMap()::m_aAliasMap[m_aAlias[i]] = %s\n", ((OUtoCStr(m_aAliasMap[m_aAlias[i]])) ? (OUtoCStr(m_aAliasMap[m_aAlias[i]])):("NULL")) ); + } + + return; +} +//------------------------------------------------------------------ diff --git a/connectivity/source/drivers/evoab/LColumnAlias.hxx b/connectivity/source/drivers/evoab/LColumnAlias.hxx new file mode 100644 index 000000000000..c91931d121bf --- /dev/null +++ b/connectivity/source/drivers/evoab/LColumnAlias.hxx @@ -0,0 +1,116 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LColumnAlias.hxx,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_EVOAB_LCOLUMNALIAS_HXX_ +#define _CONNECTIVITY_EVOAB_LCOLUMNALIAS_HXX_ + +#include <unotools/confignode.hxx> + +#include <osl/mutex.hxx> +#include <vector> +#include <map> + +namespace connectivity +{ + namespace evoab + { + typedef enum { + FIRSTNAME = 0, + LASTNAME, + DISPLAYNAME, + NICKNAME, + PRIMARYEMAIL, + SECONDEMAIL, + PREFERMAILFORMAT, + WORKPHONE, + HOMEPHONE, + FAXNUMBER, + PAGERNUMBER, + CELLULARNUMBER, + HOMEADDRESS, + HOMEADDRESS2, + HOMECITY, + HOMESTATE, + HOMEZIPCODE, + HOMECOUNTRY, + WORKADDRESS, + WORKADDRESS2, + WORKCITY, + WORKSTATE, + WORKZIPCODE, + WORKCOUNTRY, + JOBTITLE, + DEPARTMENT, + COMPANY, + WEBPAGE1, + WEBPAGE2, + BIRTHYEAR, + BIRTHMONTH, + BIRTHDAY, + NOTES, + END + } ProgrammaticName; + + class OColumnAlias + { + /** + * m_Alias holds aliases for the evolution addressbook + * column names. This member gets initialised during + * creation of the connection to the driver. + * m_aAlias initialises m_aAliasMap which then can be + * used to find the corresponding programmatic name + * when an alias is used as a query attribute. Mozilla + * expects programmatic names from its clients. + * + * m_aAlias: vector of aliases used to initialise m_aAliasMap. + * m_AliasMap: map of {alias, programmaticname} pairs. + * + */ + private: + ::std::vector< ::rtl::OUString> m_aAlias; + ::std::vector< ::rtl::OUString> m_aHeadLineNames; + ::std::map< ::rtl::OUString, ::rtl::OUString> m_aAliasMap; + protected: + ::osl::Mutex m_aMutex; + public: + void initialise(void); + const ::std::vector< ::rtl::OUString> & getAlias(void) const; + const ::std::map< ::rtl::OUString, ::rtl::OUString> & getAliasMap(void) const; + void setAlias(const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiServiceFactory > &); + private: + void setAliasMap(void); + public: + OColumnAlias(void); + ~OColumnAlias(void); + }; + } +} +#endif // _CONNECTIVITY_EVOAB_LCOLUMNALIAS_HXX_ diff --git a/connectivity/source/drivers/evoab/LColumns.cxx b/connectivity/source/drivers/evoab/LColumns.cxx new file mode 100644 index 000000000000..9608c8efd384 --- /dev/null +++ b/connectivity/source/drivers/evoab/LColumns.cxx @@ -0,0 +1,60 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LColumns.cxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" + +#include "LColumns.hxx" +#include "LTable.hxx" +#include "connectivity/sdbcx/VColumn.hxx" + +using namespace connectivity::evoab; +using namespace connectivity; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::sdbcx; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::container; + + +sdbcx::ObjectType OEvoabColumns::createObject(const ::rtl::OUString& _rName) +{ + + OEvoabTable* pTable = (OEvoabTable*)m_pTable; + ::vos::ORef<OSQLColumns> aCols = pTable->getTableColumns(); + OSQLColumns::Vector::const_iterator aIter = find(aCols->get().begin(),aCols->get().end(),_rName,::comphelper::UStringMixEqual(isCaseSensitive())); + sdbcx::ObjectType xRet; + if(aIter != aCols->get().end()) + xRet = sdbcx::ObjectType(*aIter,UNO_QUERY); + return xRet; +} +// ------------------------------------------------------------------------- + + diff --git a/connectivity/source/drivers/evoab/LColumns.hxx b/connectivity/source/drivers/evoab/LColumns.hxx new file mode 100644 index 000000000000..457f319ca7b1 --- /dev/null +++ b/connectivity/source/drivers/evoab/LColumns.hxx @@ -0,0 +1,55 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LColumns.hxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_EVOAB_LCOLUMNS_HXX_ +#define _CONNECTIVITY_EVOAB_LCOLUMNS_HXX_ + +#include "file/FColumns.hxx" + +namespace connectivity +{ + namespace evoab + { + class OEvoabColumns : public file::OColumns + { + protected: + virtual sdbcx::ObjectType createObject(const ::rtl::OUString& _rName); + public: + OEvoabColumns(file::OFileTable* _pTable, + ::osl::Mutex& _rMutex, + const TStringVector &_rVector + ) : file::OColumns(_pTable,_rMutex,_rVector) + {} + + }; + } +} +#endif // _CONNECTIVITY_EVOAB_LCOLUMNS_HXX_ + diff --git a/connectivity/source/drivers/evoab/LConfigAccess.cxx b/connectivity/source/drivers/evoab/LConfigAccess.cxx new file mode 100644 index 000000000000..9df502d35d70 --- /dev/null +++ b/connectivity/source/drivers/evoab/LConfigAccess.cxx @@ -0,0 +1,164 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LConfigAccess.cxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "LConfigAccess.hxx" +#include "LDriver.hxx" +#ifndef CONNECTIVITY_EVOAB_DEBUG_HELPER_HXX +#include "LDebug.hxx" +#endif + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; + +//......................................................................... +namespace connectivity +{ + namespace evoab + { + //----------------------------------------------------------------- + Reference< XPropertySet > createDriverConfigNode( Reference< XMultiServiceFactory > _rxORB, ::rtl::OUString _sDriverImplementationName ) + { + OSL_TRACE("createDriverConfigNode()entered"); + + Reference< XPropertySet > xNode; + try + { + //============================================================= + // create the config provider + Reference< XMultiServiceFactory > xConfigProvider( + _rxORB->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.configuration.ConfigurationProvider" ) ), + UNO_QUERY + ); + OSL_ENSURE( xConfigProvider.is(), "createDriverConfigNode: could not create the config provider!" ); + + if ( xConfigProvider.is() ) + { + ::rtl::OUString sCompleteNodePath = ::rtl::OUString::createFromAscii ("/org.openoffice.Office.DataAccess/DriverSettings/" ); + sCompleteNodePath += _sDriverImplementationName; + //sCompleteNodePath += OEvoabConnection::getDriverImplementationName(); + //sCompleteNodePath += ::rtl::OUString::createFromAscii ("com.sun.star.comp.sdbc.MozabDriver"); + EVO_TRACE_STRING("createDriverConfigNode()::sCompleteNodePath = %s\n", sCompleteNodePath ); + + //========================================================= + // arguments for creating the config access + Sequence< Any > aArguments(2); + // the path to the node to open + aArguments[0] <<= PropertyValue( + ::rtl::OUString::createFromAscii( "nodepath"), + 0, + makeAny( sCompleteNodePath ), + PropertyState_DIRECT_VALUE + ); + // the depth: -1 means unlimited + aArguments[1] <<= PropertyValue( + ::rtl::OUString::createFromAscii( "depth"), + 0, + makeAny( (sal_Int32)-1 ), + PropertyState_DIRECT_VALUE + ); + + //========================================================= + // create the access + Reference< XInterface > xAccess = xConfigProvider->createInstanceWithArguments( + ::rtl::OUString::createFromAscii( "com.sun.star.configuration.ConfigurationAccess" ), + aArguments + ); + OSL_ENSURE( xAccess.is(), "createDriverConfigNode: invalid access returned (should throw an exception instead)!" ); + + xNode = xNode.query( xAccess ); + } + } + catch( const Exception& ) + { + OSL_ENSURE( sal_False, "createDriverConfigNode: caught an exception while accessing the driver's config node!" ); + } + + // outta here + return xNode; + } + + //----------------------------------------------------------------- + namespace + { + // a private helper to accessing the point where we store the reference + // to the factory + Reference< XMultiServiceFactory >& accessFactoryStorage( ) + { + static Reference< XMultiServiceFactory > xEvoabServiceFactory; + return xEvoabServiceFactory; + } + } + + //----------------------------------------------------------------- + void setEvoabServiceFactory( const Reference< XMultiServiceFactory >& _rxFactory ) + { + accessFactoryStorage( ) = _rxFactory; + } + + //----------------------------------------------------------------- + const Reference< XMultiServiceFactory >& getEvoabServiceFactory( ) + { + return accessFactoryStorage( ); + } + + //----------------------------------------------------------------- + ::rtl::OUString getFullPathExportingCommand( Reference< XMultiServiceFactory > _rxORB ) + { + ::rtl::OUString sFullPathExportingCommand; + + //Reference< XMultiServiceFactory > xFactory = getEvoabServiceFactory(); + //OSL_ENSURE( xFactory.is(), "getPreferredProfileName: invalid service factory!" ); + OSL_ENSURE( _rxORB.is(), "getFullPathExportingCommand: invalid service factory!" ); + if ( _rxORB.is() ) + { + try + { + Reference< XPropertySet > xDriverNode = createDriverConfigNode( _rxORB, OEvoabDriver::getImplementationName_Static() ); + Reference< XPropertySet > xEvoPrefsNode; + if ( xDriverNode.is() ) + xDriverNode->getPropertyValue( ::rtl::OUString::createFromAscii( "EvolutionPreferences" ) ) >>= xEvoPrefsNode; + OSL_ENSURE( xEvoPrefsNode.is(), "getFullPathExportingCommand: could not access the node for the evolution preferences!" ); + if ( xEvoPrefsNode.is() ) + xEvoPrefsNode->getPropertyValue( ::rtl::OUString::createFromAscii( "FullPathExportingCommand" ) ) >>= sFullPathExportingCommand; + } + catch( const Exception& ) + { + OSL_ENSURE( sal_False, "getFullPathExportingCommand: caught an exception!" ); + } + } + return sFullPathExportingCommand; + } + } +} + +//......................................................................... diff --git a/connectivity/source/drivers/evoab/LConfigAccess.hxx b/connectivity/source/drivers/evoab/LConfigAccess.hxx new file mode 100644 index 000000000000..9df43ef3226b --- /dev/null +++ b/connectivity/source/drivers/evoab/LConfigAccess.hxx @@ -0,0 +1,49 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LConfigAccess.hxx,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_EVOAB_LCONFIGACCESS_HXX_ +#define _CONNECTIVITY_EVOAB_LCONFIGACCESS_HXX_ + +// This is the extended version (for use on the SO side of the driver) of MConfigAccess +// (which is for use on the mozilla side only) + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +namespace connectivity +{ + namespace evoab + { + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > + createDriverConfigNode( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > _rxORB, ::rtl::OUString _sDriverImplementationName ); + ::rtl::OUString getFullPathExportingCommand( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > _rxORB ); + } +} +#endif // _CONNECTIVITY_EVOAB_LCONFIGACCESS_HXX_ diff --git a/connectivity/source/drivers/evoab/LConnection.cxx b/connectivity/source/drivers/evoab/LConnection.cxx new file mode 100644 index 000000000000..383354d8ff5f --- /dev/null +++ b/connectivity/source/drivers/evoab/LConnection.cxx @@ -0,0 +1,270 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LConnection.cxx,v $ + * $Revision: 1.12.56.1 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "LConnection.hxx" +#include "LDatabaseMetaData.hxx" +#include "LCatalog.hxx" +#include <com/sun/star/lang/DisposedException.hpp> +#include <tools/urlobj.hxx> +#include "LPreparedStatement.hxx" +#include "LStatement.hxx" +#include <comphelper/extract.hxx> +#include <connectivity/dbcharset.hxx> +#include <connectivity/dbexception.hxx> +#include <comphelper/processfactory.hxx> +#include <vos/process.hxx> +#include <tools/debug.hxx> +#include "LDebug.hxx" +#include "diagnose_ex.h" +#include <comphelper/sequence.hxx> +#include <connectivity/dbexception.hxx> +#include "resource/common_res.hrc" + +using namespace connectivity::evoab; +using namespace connectivity::file; +using namespace vos; + +typedef connectivity::file::OConnection OConnection_B; + +//------------------------------------------------------------------------------ +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::sdbcx; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::lang; + +::rtl::OUString implGetExceptionMsg( Exception& e, const ::rtl::OUString& aExceptionType_ ) +{ + ::rtl::OUString aExceptionType = aExceptionType_; + if( aExceptionType.getLength() == 0 ) + aExceptionType = ::rtl::OUString( ::rtl::OUString::createFromAscii("Unknown" ) ); + + ::rtl::OUString aTypeLine( ::rtl::OUString::createFromAscii("\nType: " ) ); + aTypeLine += aExceptionType; + + ::rtl::OUString aMessageLine( ::rtl::OUString::createFromAscii("\nMessage: " ) ); + aMessageLine += ::rtl::OUString( e.Message ); + + ::rtl::OUString aMsg(aTypeLine); + aMsg += aMessageLine; + return aMsg; +} + + // Exception type unknown +::rtl::OUString implGetExceptionMsg( Exception& e ) +{ + ::rtl::OUString aMsg = implGetExceptionMsg( e, ::rtl::OUString() ); + return aMsg; +} + +// -------------------------------------------------------------------------------- +OEvoabConnection::OEvoabConnection(OEvoabDriver* _pDriver) : OConnection(_pDriver) + ,m_bHeaderLine(sal_True) + ,m_cFieldDelimiter(',') + ,m_cStringDelimiter('"') + ,m_cDecimalDelimiter('.') + ,m_cThousandDelimiter(' ') +{ + // Initialise m_aColumnAlias. + m_aColumnAlias.setAlias(_pDriver->getFactory()); +} +//----------------------------------------------------------------------------- +OEvoabConnection::~OEvoabConnection() +{ +} + +// XServiceInfo +// -------------------------------------------------------------------------------- +IMPLEMENT_SERVICE_INFO(OEvoabConnection, "com.sun.star.sdbc.drivers.evoab.Connection", "com.sun.star.sdbc.Connection") + +//----------------------------------------------------------------------------- +void OEvoabConnection::construct(const ::rtl::OUString& url,const Sequence< PropertyValue >& info) throw(SQLException) +{ + osl_incrementInterlockedCount( &m_refCount ); + EVO_TRACE_STRING("OEvoabConnection::construct()::url = %s\n", url ); + + + ::rtl::OUString aCLICommand = getDriver()->getEvoab_CLI_EffectiveCommand(); + ::rtl::OUString aWorkingDirPath = getDriver()->getWorkingDirPath(); + ::rtl::OUString aArg1 = ::rtl::OUString::createFromAscii(OEvoabDriver::getEVOAB_CLI_ARG_LIST_FOLDERS()); + ::rtl::OUString aArg2 = ::rtl::OUString::createFromAscii(OEvoabDriver::getEVOAB_CLI_ARG_OUTPUT_FILE_PREFIX()); + aArg2 += aWorkingDirPath; + aArg2 += getDriver()->getEvoFolderListFileName(); + OArgumentList aArgs(2,&aArg1,&aArg2); + + EVO_TRACE_STRING("OEvoabConnection::construct()::aCLICommand = %s\n", aCLICommand ); + EVO_TRACE_STRING("OEvoabConnection::construct()::aWorkingDirPath = %s\n", aWorkingDirPath ); + EVO_TRACE_STRING("OEvoabConnection::construct()::aArg1 = %s\n", aArg1 ); + EVO_TRACE_STRING("OEvoabConnection::construct()::aArg2 = %s\n", aArg2 ); + OProcess aApp( aCLICommand,aWorkingDirPath); + OSL_VERIFY_EQUALS( + aApp.execute( (OProcess::TProcessOption)(OProcess::TOption_Hidden | OProcess::TOption_Wait | OProcess::TOption_SearchPath),aArgs), + OProcess::E_None, + "Error at execute evolution-addressbook-export to get VCards"); + + + Sequence<PropertyValue> aDriverParam; + ::std::vector<PropertyValue> aParam; + + aParam.push_back(PropertyValue(::rtl::OUString::createFromAscii("EnableSQL92Check"), 0, Any(), PropertyState_DIRECT_VALUE)); + ::dbtools::OCharsetMap aLookupIanaName; + ::dbtools::OCharsetMap::const_iterator aLookup = aLookupIanaName.find(RTL_TEXTENCODING_UTF8); + aParam.push_back(PropertyValue(::rtl::OUString::createFromAscii("CharSet"), 0, + makeAny((*aLookup).getIanaName()), PropertyState_DIRECT_VALUE)); + aParam.push_back(PropertyValue(::rtl::OUString::createFromAscii("Extension"), 0, makeAny(getDriver()->getFileExt()), PropertyState_DIRECT_VALUE)); + aParam.push_back(PropertyValue(::rtl::OUString::createFromAscii("HeaderLine"), 0, makeAny(m_bHeaderLine), PropertyState_DIRECT_VALUE)); + aParam.push_back(PropertyValue(::rtl::OUString::createFromAscii("FieldDelimiter"), 0, makeAny(::rtl::OUString(&m_cFieldDelimiter,1)), PropertyState_DIRECT_VALUE)); + aParam.push_back(PropertyValue(::rtl::OUString::createFromAscii("StringDelimiter"), 0, makeAny(::rtl::OUString(&m_cStringDelimiter,1)), PropertyState_DIRECT_VALUE)); + aParam.push_back(PropertyValue(::rtl::OUString::createFromAscii("DecimalDelimiter"), 0, makeAny(::rtl::OUString(&m_cDecimalDelimiter,1)), PropertyState_DIRECT_VALUE)); + aParam.push_back(PropertyValue(::rtl::OUString::createFromAscii("ThousandDelimiter"), 0, makeAny(::rtl::OUString(&m_cThousandDelimiter,1)), PropertyState_DIRECT_VALUE)); + + // build a new parameter sequence from the original parameters, appended by the new parameters from above + PropertyValue *pParams = aParam.empty() ? 0 : &aParam[0]; + aDriverParam = ::comphelper::concatSequences( + info, + Sequence< PropertyValue >( pParams, aParam.size() ) + ); + + // transform "sdbc:address:evolution" part of URL to "sdbc:flat:file:///..." + // + sal_Int32 nLen = url.indexOf(':'); + nLen = url.indexOf(':',nLen+1); + ::rtl::OUString aAddrbookURI(url.copy(nLen+1)); + // Get Scheme + nLen = aAddrbookURI.indexOf(':'); + ::rtl::OUString aAddrbookScheme; + if ( nLen == -1 ) + { + // There isn't any subschema: - but could be just subschema + if ( aAddrbookURI.getLength() > 0 ) + { + aAddrbookScheme= aAddrbookURI; + } + else + { + OSL_TRACE( "No subschema given!!!\n"); + throwGenericSQLException(STR_URI_SYNTAX_ERROR ,*this); + } + } + else + { + aAddrbookScheme = aAddrbookURI.copy(0, nLen); + } + + EVO_TRACE_STRING("OEvoabConnection::construct()::URI = %s\n", aAddrbookURI ); + EVO_TRACE_STRING("OEvoabConnection::construct()::Scheme = %s\n", aAddrbookScheme ); + + // + // Now we have a URI convert it to a Evolution CLI flat file URI + // + // The Mapping being used is: + // + // * for Evolution + // "sdbc:address:evolution:" -> "sdbc:flat:file:///(file path generated) + + rtl::OUString aEvoFlatURI; + if ( aAddrbookScheme.compareToAscii( OEvoabDriver::getSDBC_SCHEME_EVOLUTION() ) == 0 ) + { + aEvoFlatURI = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "sdbc:flat:" )); + } + + + aEvoFlatURI += getDriver()->getWorkingDirURL(); + EVO_TRACE_STRING("OEvoabConnection::construct()::m_aEvoFlatURI = %s\n", aEvoFlatURI ); + //setURL(aEvoFlatURI); + m_aEvoFlatURI = aEvoFlatURI; + + osl_decrementInterlockedCount( &m_refCount ); + OConnection::construct(aEvoFlatURI,aDriverParam); +} +// -------------------------------------------------------------------------------- +Reference< XDatabaseMetaData > SAL_CALL OEvoabConnection::getMetaData( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OConnection_B::rBHelper.bDisposed); + + + Reference< XDatabaseMetaData > xMetaData = m_xMetaData; + if(!xMetaData.is()) + { + xMetaData = new OEvoabDatabaseMetaData(this); + m_xMetaData = xMetaData; + } + + return xMetaData; +} +//------------------------------------------------------------------------------ +::com::sun::star::uno::Reference< XTablesSupplier > OEvoabConnection::createCatalog() +{ + ::osl::MutexGuard aGuard( m_aMutex ); + Reference< XTablesSupplier > xTab = m_xCatalog; + if(!xTab.is()) + { + OEvoabCatalog *pCat = new OEvoabCatalog(this); + xTab = pCat; + m_xCatalog = xTab; + } + return xTab; +} +// -------------------------------------------------------------------------------- +Reference< XStatement > SAL_CALL OEvoabConnection::createStatement( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OConnection_B::rBHelper.bDisposed); + + OEvoabStatement* pStmt = new OEvoabStatement(this); + + Reference< XStatement > xStmt = pStmt; + m_aStatements.push_back(WeakReferenceHelper(*pStmt)); + return xStmt; +} +// -------------------------------------------------------------------------------- +Reference< XPreparedStatement > SAL_CALL OEvoabConnection::prepareStatement( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OConnection_B::rBHelper.bDisposed); + + + OEvoabPreparedStatement* pStmt = new OEvoabPreparedStatement(this); + Reference< XPreparedStatement > xStmt = pStmt; + pStmt->construct(sql); + + m_aStatements.push_back(WeakReferenceHelper(*pStmt)); + return xStmt; +} +// -------------------------------------------------------------------------------- +Reference< XPreparedStatement > SAL_CALL OEvoabConnection::prepareCall( const ::rtl::OUString& /*sql*/ ) throw(SQLException, RuntimeException) +{ + ::dbtools::throwFeatureNotImplementedException( "XConnection::prepareCall", *this ); + return NULL; +} +// ------------------------------------------------------------------------- diff --git a/connectivity/source/drivers/evoab/LConnection.hxx b/connectivity/source/drivers/evoab/LConnection.hxx new file mode 100644 index 000000000000..e0cd79eb8f78 --- /dev/null +++ b/connectivity/source/drivers/evoab/LConnection.hxx @@ -0,0 +1,81 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LConnection.hxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_EVOAB_LCONNECTION_HXX_ +#define _CONNECTIVITY_EVOAB_LCONNECTION_HXX_ + +#include "LDriver.hxx" +#include "file/FConnection.hxx" +#include "LColumnAlias.hxx" + +namespace connectivity +{ + namespace evoab + { + class OEvoabConnection : public file::OConnection + { + private: + OColumnAlias m_aColumnAlias; + sal_Bool m_bHeaderLine; // column names in first row + sal_Unicode m_cFieldDelimiter; // look at the name + sal_Unicode m_cStringDelimiter; // delimiter for strings m_cStringDelimiter blabla m_cStringDelimiter + sal_Unicode m_cDecimalDelimiter; // Dezimal-delimiter (Dezimalpoint) + sal_Unicode m_cThousandDelimiter; // + rtl::OUString m_aEvoFlatURI; + + public: + OEvoabConnection(OEvoabDriver* _pDriver); + virtual ~OEvoabConnection(); + + virtual void construct(const ::rtl::OUString& _rUrl,const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rInfo ) throw( ::com::sun::star::sdbc::SQLException); + + // own methods + inline const OEvoabDriver* getDriver() const { return static_cast< const OEvoabDriver* >( m_pDriver ); } + inline sal_Bool isHeaderLine() const { return m_bHeaderLine; } + inline sal_Unicode getFieldDelimiter() const { return m_cFieldDelimiter; } + inline sal_Unicode getStringDelimiter() const { return m_cStringDelimiter; } + inline sal_Unicode getDecimalDelimiter() const { return m_cDecimalDelimiter; } + inline sal_Unicode getThousandDelimiter() const { return m_cThousandDelimiter;} + const OColumnAlias& getColumnAlias() const { return m_aColumnAlias; } + + // XServiceInfo + DECLARE_SERVICE_INFO(); + + // XConnection + virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XTablesSupplier > createCatalog(); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement > SAL_CALL createStatement( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareCall( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + + }; + } +} +#endif // _CONNECTIVITY_EVOAB_LCONNECTION_HXX_ diff --git a/connectivity/source/drivers/evoab/LDatabaseMetaData.cxx b/connectivity/source/drivers/evoab/LDatabaseMetaData.cxx new file mode 100644 index 000000000000..5a0f80781d2a --- /dev/null +++ b/connectivity/source/drivers/evoab/LDatabaseMetaData.cxx @@ -0,0 +1,394 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LDatabaseMetaData.cxx,v $ + * $Revision: 1.8 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "LDatabaseMetaData.hxx" +#include "LConnection.hxx" +#include <com/sun/star/sdbc/DataType.hpp> +#include <com/sun/star/sdbc/ResultSetType.hpp> +#include <com/sun/star/sdbc/ColumnValue.hpp> +#include <com/sun/star/beans/XFastPropertySet.hpp> +#include <com/sun/star/sdbc/ResultSetConcurrency.hpp> +#include <com/sun/star/sdbcx/XColumnsSupplier.hpp> +#include <com/sun/star/sdbcx/XIndexesSupplier.hpp> +#include <com/sun/star/ucb/XContentAccess.hpp> +#ifndef _COM_SUN_STAR_SQLC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#include <tools/urlobj.hxx> +#include "FDatabaseMetaDataResultSet.hxx" +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include <comphelper/extract.hxx> +#include <comphelper/types.hxx> +#include "LFolderList.hxx" +#include "connectivity/CommonTools.hxx" +#include <vos/process.hxx> +#include <osl/process.h> +#include <tools/debug.hxx> +#include <map> +#include <vector> + +#ifndef CONNECTIVITY_EVOAB_DEBUG_HELPER_HXX +#include "LDebug.hxx" +#endif +#include "diagnose_ex.h" + +using namespace ::comphelper; +using namespace connectivity; +using namespace connectivity::evoab; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::sdbcx; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::ucb; +using namespace osl; +using namespace vos; + +namespace connectivity +{ + namespace evoab + { + static sal_Int32 const s_nCOLUMN_SIZE = 256; + static sal_Int32 const s_nDECIMAL_DIGITS = 0; + static sal_Int32 const s_nNULLABLE = 1; + static sal_Int32 const s_nCHAR_OCTET_LENGTH = 65535; + } +} + +OEvoabDatabaseMetaData::OEvoabDatabaseMetaData(::connectivity::file::OConnection* _pCon) :ODatabaseMetaData(_pCon) +{ +} +// ------------------------------------------------------------------------- +OEvoabDatabaseMetaData::~OEvoabDatabaseMetaData() +{ +} +// ------------------------------------------------------------------------- +Reference< XResultSet > OEvoabDatabaseMetaData::impl_getTypeInfo_throw( ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo); + Reference< XResultSet > xRef = pResult; + static ODatabaseMetaDataResultSet::ORows aRows; + if(aRows.empty()) + { + ODatabaseMetaDataResultSet::ORow aRow; + + aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); + aRow.push_back(new ORowSetValueDecorator(::rtl::OUString::createFromAscii("CHAR"))); + aRow.push_back(new ORowSetValueDecorator(DataType::CHAR)); + aRow.push_back(new ORowSetValueDecorator((sal_Int32)254)); + aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue()); + aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue()); + aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); + aRow.push_back(new ORowSetValueDecorator((sal_Int32)ColumnValue::NULLABLE)); + aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); + aRow.push_back(new ORowSetValueDecorator((sal_Int32)ColumnSearch::CHAR)); + aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); + aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); + aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); + aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); + aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); + aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); + aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); + aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); + aRow.push_back(new ORowSetValueDecorator((sal_Int32)10)); + + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("VARCHAR")); + aRow[2] = new ORowSetValueDecorator(DataType::VARCHAR); + aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue(); + aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue(); + aRows.push_back(aRow); + + + aRow[1] = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("LONGVARCHAR")); + aRow[2] = new ORowSetValueDecorator(DataType::LONGVARCHAR); + aRow[3] = new ORowSetValueDecorator((sal_Int32)65535); + aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue(); + aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue(); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("DATE")); + aRow[2] = new ORowSetValueDecorator(DataType::DATE); + aRow[3] = new ORowSetValueDecorator((sal_Int32)10); + aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue(); + aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue(); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("TIME")); + aRow[2] = new ORowSetValueDecorator(DataType::TIME); + aRow[3] = new ORowSetValueDecorator((sal_Int32)8); + aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue(); + aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue(); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("TIMESTAMP")); + aRow[2] = new ORowSetValueDecorator(DataType::TIMESTAMP); + aRow[3] = new ORowSetValueDecorator((sal_Int32)19); + aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue(); + aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue(); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("BOOL")); + aRow[2] = new ORowSetValueDecorator(DataType::BIT); + aRow[3] = ODatabaseMetaDataResultSet::get1Value(); + aRow[9] = ODatabaseMetaDataResultSet::getBasicValue(); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("DECIMAL")); + aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL); + aRow[3] = new ORowSetValueDecorator((sal_Int32)20); + aRow[15] = new ORowSetValueDecorator((sal_Int32)15); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("DOUBLE")); + aRow[2] = new ORowSetValueDecorator(DataType::DOUBLE); + aRow[3] = new ORowSetValueDecorator((sal_Int32)20); + aRow[15] = ODatabaseMetaDataResultSet::get0Value(); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("NUMERIC")); + aRow[2] = new ORowSetValueDecorator(DataType::NUMERIC); + aRow[3] = new ORowSetValueDecorator((sal_Int32)20); + aRow[15] = new ORowSetValueDecorator((sal_Int32)20); + aRows.push_back(aRow); + } + + pResult->setRows(aRows); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL OEvoabDatabaseMetaData::getColumns( + const Any& /*catalog*/, const ::rtl::OUString& /*schemaPattern*/, const ::rtl::OUString& tableNamePattern, + const ::rtl::OUString& columnNamePattern ) throw(SQLException, RuntimeException) +{ + OSL_TRACE("OEvoabDatabaseMetaData::getColumns()::Entered\n"); + EVO_TRACE_STRING("OEvoabDatabaseMetaData::getColumns()::schemaPattern = %s\n", schemaPattern ); + EVO_TRACE_STRING("OEvoabDatabaseMetaData::getColumns()::tableNamePattern = %s\n", tableNamePattern ); + EVO_TRACE_STRING("OEvoabDatabaseMetaData::getColumns()::columnNamePattern = %s\n", columnNamePattern ); + + ::osl::MutexGuard aGuard( m_aMutex ); + + Reference< XTablesSupplier > xTables = m_pConnection->createCatalog(); + if(!xTables.is()) + throw SQLException(); + + Reference< XNameAccess> xNames = xTables->getTables(); + if(!xNames.is()) + throw SQLException(); + + ODatabaseMetaDataResultSet::ORows aRows; + ODatabaseMetaDataResultSet::ORow aRow(19); + aRow[10] = new ORowSetValueDecorator((sal_Int32)10); + Sequence< ::rtl::OUString> aTabNames(xNames->getElementNames()); + const ::rtl::OUString* pTabBegin = aTabNames.getConstArray(); + const ::rtl::OUString* pTabEnd = pTabBegin + aTabNames.getLength(); + for(;pTabBegin != pTabEnd;++pTabBegin) + { + if(match(tableNamePattern,*pTabBegin,'\0')) + { + Reference< XColumnsSupplier> xTable; + ::cppu::extractInterface(xTable,xNames->getByName(*pTabBegin)); + aRow[3] = new ORowSetValueDecorator(*pTabBegin); + + Reference< XNameAccess> xColumns = xTable->getColumns(); + if(!xColumns.is()) + throw SQLException(); + + Sequence< ::rtl::OUString> aColNames(xColumns->getElementNames()); + + const ::rtl::OUString* pBegin = aColNames.getConstArray(); + const ::rtl::OUString* pEnd = pBegin + aColNames.getLength(); + Reference< XPropertySet> xColumn; + for(sal_Int32 i=1;pBegin != pEnd;++pBegin,++i) + { + if(match(columnNamePattern,*pBegin,'\0')) + { + aRow[4] = new ORowSetValueDecorator(*pBegin); + + ::cppu::extractInterface(xColumn,xColumns->getByName(*pBegin)); + OSL_ENSURE(xColumn.is(),"Columns contains a column who isn't a fastpropertyset!"); + aRow[5] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)))); + aRow[6] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)))); + aRow[7] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)))); + aRow[9] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)))); + aRow[11] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE)))); + aRow[13] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE)))); + + switch((sal_Int32)aRow[5]->getValue()) + { + case DataType::CHAR: + case DataType::VARCHAR: + aRow[16] = new ORowSetValueDecorator((sal_Int32)254); + break; + case DataType::LONGVARCHAR: + aRow[16] = new ORowSetValueDecorator((sal_Int32)65535); + break; + default: + aRow[16] = new ORowSetValueDecorator((sal_Int32)0); + } + aRow[17] = new ORowSetValueDecorator(i); + switch(sal_Int32(aRow[11]->getValue())) + { + case ColumnValue::NO_NULLS: + aRow[18] = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("NO")); + break; + case ColumnValue::NULLABLE: + aRow[18] = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("YES")); + break; + default: + aRow[18] = new ORowSetValueDecorator(::rtl::OUString()); + } + aRows.push_back(aRow); + } + } + } + } + + ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns); + Reference< XResultSet > xRef = pResult; + pResult->setRows(aRows); + + return xRef; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OEvoabDatabaseMetaData::getURL( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:flat:")) + m_pConnection->getURL(); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL OEvoabDatabaseMetaData::getTables( + const Any& /*catalog*/, const ::rtl::OUString& /*schemaPattern*/, + const ::rtl::OUString& /*tableNamePattern*/, const Sequence< ::rtl::OUString >& types ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTables); + Reference< XResultSet > xRef = pResult; + + // check if any type is given + // when no types are given then we have to return all tables e.g. TABLE + + static const ::rtl::OUString aTable(::rtl::OUString::createFromAscii("TABLE")); + + sal_Bool bTableFound = sal_True; + sal_Int32 nLength = types.getLength(); + if(nLength) + { + bTableFound = sal_False; + + const ::rtl::OUString* pBegin = types.getConstArray(); + const ::rtl::OUString* pEnd = pBegin + nLength; + for(;pBegin != pEnd;++pBegin) + { + if(*pBegin == aTable) + { + bTableFound = sal_True; + break; + } + } + } + if(!bTableFound) + return xRef; + + OEvoabConnection* pOEvoabConnection = (OEvoabConnection*)m_pConnection; + OEvoabFolderList* pFolderList = new OEvoabFolderList( pOEvoabConnection ); + + + ODatabaseMetaDataResultSet::ORows aRows; + sal_Bool bMoreData = sal_True; + ::rtl::OUString aName, aLocation; + sal_Int32 nCardsCount; + + pFolderList->initializeRow(3); + bMoreData = pFolderList->first(); + OSL_TRACE("OEvoabDatabaseMetaData::getTables()::first %d\n",bMoreData ); + do + { + if(bMoreData) + bMoreData = pFolderList->getRow(); + if(bMoreData) + { + aLocation = pFolderList->getString(1); + aName = pFolderList->getString(2); + nCardsCount = pFolderList->getInt(3); + EVO_TRACE_STRING( "OEvoabDatabaseMetaData::getTables()::aLocation = %s\n", aLocation ); + EVO_TRACE_STRING( "OEvoabDatabaseMetaData::getTables()::aName = %s\n", aName ); + OSL_TRACE("OEvoabDatabaseMetaData::getTables()::nCardsCount = %d\n", nCardsCount); + + ODatabaseMetaDataResultSet::ORow aRow(3); + aRow.reserve(6); + aRow.push_back(new ORowSetValueDecorator(aName)); + aRow.push_back(new ORowSetValueDecorator(aTable)); + aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); + aRows.push_back(aRow); + + ::rtl::OUString aWorkingDir = pOEvoabConnection->getDriver()->getWorkingDirPath(); + ::rtl::OUString aCLICommand = pOEvoabConnection->getDriver()->getEvoab_CLI_EffectiveCommand(); + ::rtl::OUString aArg1 = aLocation; + ::rtl::OUString aArg2 = ::rtl::OUString::createFromAscii(pOEvoabConnection->getDriver()->getEVOAB_CLI_ARG_OUTPUT_FILE_PREFIX()); + aArg2 += aWorkingDir; + aArg2 += aName; + aArg2 += ::rtl::OUString::createFromAscii("."); + aArg2 += ::rtl::OUString(pOEvoabConnection->getExtension()); + ::rtl::OUString aArg3 = ::rtl::OUString::createFromAscii(pOEvoabConnection->getDriver()->getEVOAB_CLI_ARG_OUTPUT_FORMAT()); + + OArgumentList aArgs(3,&aArg1,&aArg2,&aArg3); + + EVO_TRACE_STRING( "OEvoabDatabaseMetaData::getTables()::aCLICommand = %s\n", aCLICommand ); + EVO_TRACE_STRING( "OEvoabDatabaseMetaData::getTables()::aWorkingDir = %s\n", aWorkingDir ); + EVO_TRACE_STRING( "OEvoabDatabaseMetaData::getTables()::aArg1 = %s\n", aArg1 ); + EVO_TRACE_STRING( "OEvoabDatabaseMetaData::getTables()::aArg2 = %s\n", aArg2 ); + EVO_TRACE_STRING( "OEvoabDatabaseMetaData::getTables()::aArg3 = %s\n", aArg3 ); + + OProcess aApp( aCLICommand,aWorkingDir); + OSL_VERIFY_EQUALS( + aApp.execute( (OProcess::TProcessOption)(OProcess::TOption_Hidden | OProcess::TOption_Wait | OProcess::TOption_SearchPath),aArgs), + OProcess::E_None, + "Error at execute evolution-addressbook-exporter to get VCards" ); + + bMoreData = pFolderList->next(); + } + } + while ( bMoreData ); + + delete pFolderList; + pFolderList = NULL; + + pResult->setRows(aRows); + + return xRef; +} diff --git a/connectivity/source/drivers/evoab/LDatabaseMetaData.hxx b/connectivity/source/drivers/evoab/LDatabaseMetaData.hxx new file mode 100644 index 000000000000..bad565d68e54 --- /dev/null +++ b/connectivity/source/drivers/evoab/LDatabaseMetaData.hxx @@ -0,0 +1,59 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LDatabaseMetaData.hxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_EVOAB_LDATABASEMETADATA_HXX_ +#define _CONNECTIVITY_EVOAB_LDATABASEMETADATA_HXX_ + +#include "file/FDatabaseMetaData.hxx" +#include "FDatabaseMetaDataResultSet.hxx" + +namespace connectivity +{ + namespace evoab + { + //************************************************************** + //************ Class: java.sql.DatabaseMetaDataDate + //************************************************************** + + class OEvoabDatabaseMetaData : public file::ODatabaseMetaData + { + virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > impl_getTypeInfo_throw(); + virtual ::rtl::OUString SAL_CALL getURL( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getColumns( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& tableNamePattern, const ::rtl::OUString& columnNamePattern ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getTables( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& tableNamePattern, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& types ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + protected: + virtual ~OEvoabDatabaseMetaData(); + public: + OEvoabDatabaseMetaData(file::OConnection* _pCon); + }; + } +} +#endif // _CONNECTIVITY_EVOAB_LDATABASEMETADATA_HXX_ + diff --git a/connectivity/source/drivers/evoab/LDebug.cxx b/connectivity/source/drivers/evoab/LDebug.cxx new file mode 100644 index 000000000000..64b39f7cea03 --- /dev/null +++ b/connectivity/source/drivers/evoab/LDebug.cxx @@ -0,0 +1,45 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LDebug.cxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" + +#ifndef CONNECTIVITY_EVOAB_DEBUG_HELPER_HXX +#include "LDebug.hxx" +#endif +#include <osl/diagnose.h> + +void evo_traceStringMessage( const sal_Char* _pFormat, const ::rtl::OUString& _rAsciiString ) +{ + ::rtl::OString sByteStringMessage( _rAsciiString.getStr(), _rAsciiString.getLength(), RTL_TEXTENCODING_ASCII_US ); + if ( !sByteStringMessage.getLength() ) + sByteStringMessage = "<empty>"; + OSL_TRACE( _pFormat, sByteStringMessage.getStr() ); +} diff --git a/connectivity/source/drivers/evoab/LDebug.hxx b/connectivity/source/drivers/evoab/LDebug.hxx new file mode 100644 index 000000000000..dc8a64ef796c --- /dev/null +++ b/connectivity/source/drivers/evoab/LDebug.hxx @@ -0,0 +1,45 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LDebug.hxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CONNECTIVITY_EVOAB_DEBUG_HELPER_HXX +#define CONNECTIVITY_EVOAB_DEBUG_HELPER_HXX + +#include <rtl/ustring.hxx> + +#ifdef _DEBUG + void evo_traceStringMessage( const sal_Char* _pFormat, const ::rtl::OUString& _rAsciiString ); + + #define EVO_TRACE_STRING( pFormat, rAsciiString ) evo_traceStringMessage( pFormat, rAsciiString ) +#else + #define EVO_TRACE_STRING( pFormat, rAsciiString ) (void)(0) +#endif + + +#endif // CONNECTIVITY_EVOAB_DEBUG_HELPER_HXX diff --git a/connectivity/source/drivers/evoab/LDriver.cxx b/connectivity/source/drivers/evoab/LDriver.cxx new file mode 100644 index 000000000000..379dfba4b21e --- /dev/null +++ b/connectivity/source/drivers/evoab/LDriver.cxx @@ -0,0 +1,508 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LDriver.cxx,v $ + * $Revision: 1.10.42.1 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "LDriver.hxx" +#include "LConnection.hxx" +#include <com/sun/star/lang/DisposedException.hpp> +#include "connectivity/dbexception.hxx" +#include "LConfigAccess.hxx" +#include <osl/file.hxx> +#include "osl/security.hxx" +#include <comphelper/processfactory.hxx> +#include <com/sun/star/ucb/XCommandEnvironment.hpp> +#include <ucbhelper/content.hxx> +#include <tools/debug.hxx> +#include "resource/common_res.hrc" +#include "resource/sharedresources.hxx" +#include "LDebug.hxx" + +using namespace osl; +using namespace connectivity::evoab; +using namespace connectivity::file; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::sdbcx; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::ucb; + +// -------------------------------------------------------------------------------- +OEvoabDriver::OEvoabDriver(const Reference< XMultiServiceFactory >& _rxFactory) : OFileDriver(_rxFactory) + ,m_aTempDir(NULL, sal_True) + ,m_aFolderListName(::rtl::OUString::createFromAscii(getEVOAB_FOLDERLIST_FILE_NAME())) + ,m_aVersionName(::rtl::OUString::createFromAscii(getEVOAB_VERSION_FILE_NAME())) + ,m_aFileExt(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(getEVOAB_META_FILE_EXT()))) + ,m_bWorkingDirCreated(sal_False) + ,m_eSupportedEvoVersion( eUnknown ) +{ + m_aEvoab_CLI_FullPathCommand = getFullPathExportingCommand(_rxFactory); + + if ( m_aEvoab_CLI_FullPathCommand.getLength() == 0 ) + m_aEvoab_CLI_FullPathCommand = ::rtl::OUString::createFromAscii(getEVOAB_CLI_FULLPATHCOMMAND()); + if ( m_aEvoab_CLI_FullPathCommand.copy(0,7) != ::rtl::OUString::createFromAscii("file://") && m_aEvoab_CLI_FullPathCommand.copy(0,1) == ::rtl::OUString::createFromAscii("/")) + m_aEvoab_CLI_FullPathCommand = ::rtl::OUString::createFromAscii("file://") + m_aEvoab_CLI_FullPathCommand; + m_aEvoab_CLI_EffectiveCommand = m_aEvoab_CLI_FullPathCommand; + m_aTempDir.EnableKillingFile(); + + EVO_TRACE_STRING("OEvoabDriver::OEvoabDriver()::m_aEvoab_CLI_FullPathCommand = %s", m_aEvoab_CLI_FullPathCommand ); +} +// static ServiceInfo +//------------------------------------------------------------------------------ +rtl::OUString OEvoabDriver::getImplementationName_Static( ) throw(RuntimeException) +{ + return rtl::OUString::createFromAscii(EVOAB_DRIVER_IMPL_NAME); +} + +//------------------------------------------------------------------ +::rtl::OUString SAL_CALL OEvoabDriver::getImplementationName( ) throw(RuntimeException) +{ + return getImplementationName_Static(); +} + +//------------------------------------------------------------------ +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL connectivity::evoab::OEvoabDriver_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception ) +{ + return *(new OEvoabDriver(_rxFactory)); +} +// -------------------------------------------------------------------------------- +Reference< XConnection > SAL_CALL OEvoabDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODriver_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if ( ! acceptsURL(url) ) + return NULL; + + OEvoabConnection* pCon = new OEvoabConnection(this); + pCon->construct(url,info); + Reference< XConnection > xCon = pCon; + m_xConnections.push_back(WeakReferenceHelper(*pCon)); + + return xCon; +} +// -------------------------------------------------------------------------------- +namespace +{ + ::rtl::OUString lcl_translateProcessErrorMessage( oslProcessError nProcErr) + { + ::rtl::OUString sProcErr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" not executed!.")); + switch (nProcErr) + { + case osl_Process_E_None: + sProcErr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" executed sucessful!")); + break; + case osl_Process_E_NotFound: + sProcErr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" executed failed: not found!")); + break; + case osl_Process_E_NoPermission: + sProcErr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" executed failed: has no permission!")); + break; + case osl_Process_E_TimedOut: + sProcErr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" executed failed: time out!")); + break; + case osl_Process_E_Unknown: + sProcErr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" executed failed: unkown reason!")); + break; + case osl_Process_E_InvalidError: + sProcErr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" executed failed: invalid error!")); + break; + default: + sProcErr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" executed failed: other reason!")); + } + return sProcErr; + } + oslProcessError lcl_execute( const ::rtl::OUString& _rCommand, ::rtl::OUString& _rArgument, + const ::rtl::OUString& _rWorkingDir, oslProcessOption _nOptions, oslFileHandle& /*[out]*/ _hStdOut ) + { + oslProcessError nError = osl_Process_E_None; + + EVO_TRACE_STRING("LDriver.cxx::lcl_execute: command : %s", _rCommand ); + EVO_TRACE_STRING("LDriver.cxx::lcl_execute: argument : %s", _rArgument ); + EVO_TRACE_STRING("LDriver.cxx::lcl_execute: working dir: %s", _rWorkingDir ); + + oslProcess hProcess( 0 ); + + nError = osl_executeProcess_WithRedirectedIO( + _rCommand.pData, + &_rArgument.pData, + 1, + _nOptions, + 0, + _rWorkingDir.pData, + 0, + 0, + &hProcess, + NULL, + &_hStdOut, + NULL + ); + ::rtl::OUString sError = _rCommand + lcl_translateProcessErrorMessage( nError); + EVO_TRACE_STRING( "%s", sError ); + + if ( nError == osl_Process_E_None ) + { + TimeValue aFiveSeconds; + aFiveSeconds.Seconds = 5; + aFiveSeconds.Nanosec = 0; + oslProcessError nWaitForProcessError = osl_joinProcessWithTimeout( hProcess, &aFiveSeconds ); + if ( osl_Process_E_None != nWaitForProcessError ) + { + nError = nWaitForProcessError; + // TODO: kill the running process? + } + osl_freeProcessHandle( hProcess ); + } + return nError; + } +} + +// -------------------------------------------------------------------------------- +sal_Bool SAL_CALL OEvoabDriver::acceptsURL( const ::rtl::OUString& url ) + throw(SQLException, RuntimeException) +{ + sal_Bool bRet; + bRet = sal_False; + // here we have to look if we support this url format + if(acceptsURL_Stat(url)) + { + if ( m_eSupportedEvoVersion != eUnknown ) + return m_eSupportedEvoVersion == eTrue ? sal_True : sal_False; + + if(!m_bWorkingDirCreated) + { + String sTempDirURL = getTempDirURL(); + //EVO_TRACE_STRING("OEvoabDriver::acceptsURL()::sTempDirURL = %s", sTempDirURL ); + + ::rtl::OUString aTempDirURL(sTempDirURL); + m_aWorkingDirURL = aTempDirURL; + m_bWorkingDirCreated = sal_True; + } + + ::rtl::OUString aCLICommand = getEvoab_CLI_EffectiveCommand(); + ::rtl::OUString aWorkingDirURL = getWorkingDirURL(); + ::rtl::OUString aArgVersion = ::rtl::OUString::createFromAscii(getEVOAB_CLI_ARG_VERSION()); + + oslFileHandle hStdout = NULL; + oslProcessError nProcErr = lcl_execute( aCLICommand, aArgVersion, aWorkingDirURL, 0, hStdout ); + if(nProcErr != osl_Process_E_None) + { + if(doesEvoab_CLI_HavePath()) + aCLICommand = getEvoab_CLI_Command(); + else + aCLICommand = getEvoab_CLI_Path() + getEvoab_CLI_Command(); + nProcErr = lcl_execute( aCLICommand, aArgVersion, aWorkingDirURL, osl_Process_SEARCHPATH | osl_Process_HIDDEN, hStdout ); + if ( nProcErr == osl_Process_E_None ) + m_aEvoab_CLI_EffectiveCommand = aCLICommand; + } + + if ( hStdout != NULL ) + { + OSL_ASSERT( hStdout ); + sal_Char pBuffer[256]; + sal_uInt64 nBytesRead; + oslFileError nFileErr = osl_File_E_None; + nFileErr = osl_readFile( hStdout, pBuffer, 256, &nBytesRead); + if ( nFileErr != osl_File_E_None ) + { + ::rtl::OUString sErr = translateFileErrorMessage( nFileErr); + OSL_ENSURE(false, ::rtl::OUStringToOString( sErr, RTL_TEXTENCODING_ASCII_US ).getStr()); + } + ::rtl::OUString aVersionInfo; + if ( nFileErr == osl_File_E_None && nBytesRead > 0 && nBytesRead <= 256) + { + OSL_TRACE("OEvoabDriver::acceptsURL()::osl_readFile(),nBytesRead = %u",nBytesRead); + aVersionInfo = + ::rtl::OUString( ( const sal_Char * )pBuffer, + (sal_Int32)nBytesRead, + RTL_TEXTENCODING_UTF8 ); + EVO_TRACE_STRING("OEvoabDriver::acceptsURL()::aVersionInfo = %s", aVersionInfo ); + sal_Int32 nIndex = 0; + sal_Bool bNumRetrieved = sal_False; + ::rtl::OUString aToken; + sal_Int32 aVer[4]; + sal_Int32 i; + for ( i = 0; i < 4; i++ ) + aVer[i] = 0; + do + { + aToken = aVersionInfo.getToken( 0, ' ', nIndex ); + //OSL_TRACE("OEvoabDriver::acceptsURL()::Token:%d", nIndex ); + //EVO_TRACE_STRING("OEvoabDriver::acceptsURL()::aToken = %s", aToken ); + if( aToken.toChar() >= '0' && aToken.toChar() <= '9' ) + { + bNumRetrieved = sal_True; + sal_Int32 nIndex1 = 0; + ::rtl::OUString aNum; + for(i = 0; i < 4 ; i++) + { + if( nIndex1 >= 0 ) + { + aNum = aToken.getToken( 0, '.', nIndex1); + aVer[i] = aNum.toInt32(); + OSL_TRACE("OEvoabDriver::acceptsURL()::Ver[%u]=%u", i, aVer[i] ); + } + } + } + } + while ( nIndex >= 0 && !bNumRetrieved ); + + if((aVer[0]>1)||(aVer[0]==1 && aVer[1]>3)||(aVer[0]==1 && aVer[1]==3 && aVer[2]>2)||(aVer[0]==1 && aVer[1]==3 && aVer[2]==2 && aVer[3]>=99)) + bRet = sal_True; + else + bRet = sal_False; + } + else + bRet = sal_False; + + osl_closeFile( hStdout ); + } + m_eSupportedEvoVersion = bRet ? eTrue : eFalse; + } + EVO_TRACE_STRING("OEvoabDriver::acceptsURL()::return, return value = %s", ::rtl::OUString::valueOf(bRet) ); + return bRet; +} + + +// -------------------------------------------------------------------------------- +sal_Bool OEvoabDriver::acceptsURL_Stat( const ::rtl::OUString& url ) +{ + + EVO_TRACE_STRING("OEvoabDriver::acceptsURL_Stat()::Scheme = %s", url ); + // Skip 'sdbc:address: part of URL + // + sal_Int32 nLen = url.indexOf(':'); + nLen = url.indexOf(':',nLen+1); + ::rtl::OUString aAddrbookURI(url.copy(nLen+1)); + + // Get Scheme + nLen = aAddrbookURI.indexOf(':'); + ::rtl::OUString aAddrbookScheme; + if ( nLen == -1 ) + { + // There isn't any subschema: - but could be just subschema + if ( aAddrbookURI.getLength() > 0 ) + aAddrbookScheme= aAddrbookURI; + else if(url == ::rtl::OUString::createFromAscii("sdbc:address:") ) + return sal_True; // special case here + else + return sal_False; + } + else + aAddrbookScheme = aAddrbookURI.copy(0, nLen); + + + EVO_TRACE_STRING("OEvoabDriver::acceptsURL_Stat()::URI = %s", aAddrbookURI ); + EVO_TRACE_STRING("OEvoabDriver::acceptsURL_Stat()::Scheme = %s", aAddrbookScheme ); + + return aAddrbookScheme.compareToAscii( getSDBC_SCHEME_EVOLUTION() ) == 0 ; +} +// ------------------------------------------------------------------------- +const rtl::OUString OEvoabDriver::getEvoab_CLI_Command() const +{ + rtl::OUString aEvoab_CLI_Command; + sal_Int32 nLen = m_aEvoab_CLI_FullPathCommand.lastIndexOf('/'); + + if ( nLen == -1 ) + aEvoab_CLI_Command = m_aEvoab_CLI_FullPathCommand; + else + aEvoab_CLI_Command = m_aEvoab_CLI_FullPathCommand.copy(nLen+1); + + EVO_TRACE_STRING( "OEvoabDriver::getEvoab_CLI_Command()::aEvoab_CLI_Command = %s", aEvoab_CLI_Command ); + + return aEvoab_CLI_Command; +} +// ------------------------------------------------------------------------- +const rtl::OUString OEvoabDriver::getEvoab_CLI_Path() const +{ + rtl::OUString aEvoab_CLI_Path; + sal_Int32 nLen = m_aEvoab_CLI_FullPathCommand.lastIndexOf('/'); + + if ( nLen == -1 ) + { + rtl::OUString aDefault_CLI_FullPathCommand; + aDefault_CLI_FullPathCommand = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(OEvoabDriver::getEVOAB_CLI_FULLPATHCOMMAND())); + sal_Int32 nLength = aDefault_CLI_FullPathCommand.lastIndexOf('/'); + aEvoab_CLI_Path = aDefault_CLI_FullPathCommand.copy(0, nLength+1); + } + else + aEvoab_CLI_Path = m_aEvoab_CLI_FullPathCommand.copy(0, nLen+1); + EVO_TRACE_STRING( "OEvoabDriver::getEvoab_CLI_Path()::aEvoab_CLI_Path = %s", aEvoab_CLI_Path ); + + return aEvoab_CLI_Path; +} +// ------------------------------------------------------------------------- +const rtl::OUString OEvoabDriver::getWorkingDirPath() const +{ + ::rtl::OUString aWorkingDirPath; + if(m_bWorkingDirCreated) + osl::File::getSystemPathFromFileURL( m_aWorkingDirURL, aWorkingDirPath ); + return aWorkingDirPath; +} +// ------------------------------------------------------------------------- +const String OEvoabDriver::getEvoFolderListFileURL() const +{ + + ::rtl::OUString aEvoFolderListFileURL; + aEvoFolderListFileURL = getWorkingDirURL() + getEvoFolderListFileName(); + + EVO_TRACE_STRING("OEvoabDriver::getEvoFolderListFileURL(): aEvoFolderListFileURL = %s", aEvoFolderListFileURL ); + return aEvoFolderListFileURL.getStr(); +} + +// ------------------------------------------------------------------------- +String OEvoabDriver::getTempDirURL() const +{ + ::rtl::OUString aTempDirURL; + aTempDirURL = m_aTempDir.GetURL(); + if((aTempDirURL.lastIndexOf( '/')) != (aTempDirURL.getLength( ) - 1)) + aTempDirURL += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")); + + EVO_TRACE_STRING("OEvoabDriver::getTempDirURL(): aTempDirURL = %s", aTempDirURL ); + return aTempDirURL.getStr(); +} +//------------------------------------------------------------------------- +sal_Bool OEvoabDriver::fileExists(const ::rtl::OUString& _rURL, sal_Bool _bIsDir) const +{ + ::ucbhelper::Content aCheckExistence; + sal_Bool bExists = sal_False; + try + { + aCheckExistence = ::ucbhelper::Content(_rURL, Reference< XCommandEnvironment >()); + if(_bIsDir) + bExists = aCheckExistence.isFolder(); + else + bExists = aCheckExistence.isDocument(); + } + catch(const Exception&) { } + return bExists; +} + +// ----------------------------------------------------------------------------- +const sal_Char* OEvoabDriver::getSDBC_SCHEME_EVOLUTION() +{ + static const sal_Char* SDBC_SCHEME_EVOLUTION = EVOAB_EVOLUTION_SCHEMA; + return SDBC_SCHEME_EVOLUTION; +} +const sal_Char* OEvoabDriver::getEVOAB_FOLDERLIST_FILE_NAME() +{ + static const sal_Char* EVOAB_FOLDERLIST_FILE_NAME = "FolderList"; + return EVOAB_FOLDERLIST_FILE_NAME; +} +const sal_Char* OEvoabDriver::getEVOAB_VERSION_FILE_NAME() +{ + static const sal_Char* EVOAB_VERSION_FILE_NAME = "EvoVersion"; + return EVOAB_VERSION_FILE_NAME; +} +const sal_Char* OEvoabDriver::getEVOAB_META_FILE_EXT() +{ + static const sal_Char* EVOAB_META_FILE_EXT = "csv"; + return EVOAB_META_FILE_EXT; +} +const sal_Char* OEvoabDriver::getEVOAB_CLI_FULLPATHCOMMAND() +{ + static const sal_Char* EVOAB_CLI_FULLPATHCOMMAND = "file:///home/evoab/extra/share/evolution/*/tools/evolution-addressbook-export"; + return EVOAB_CLI_FULLPATHCOMMAND; +} +const sal_Char* OEvoabDriver::getEVOAB_CLI_ARG_LIST_FOLDERS() +{ + static const sal_Char* EVOAB_CLI_ARG_LIST_FOLDERS = "-l"; + return EVOAB_CLI_ARG_LIST_FOLDERS; +} +const sal_Char* OEvoabDriver::getEVOAB_CLI_ARG_OUTPUT_FILE_PREFIX() +{ + static const sal_Char* EVOAB_CLI_ARG_OUTPUT_FILE_PREFIX = "--output="; + return EVOAB_CLI_ARG_OUTPUT_FILE_PREFIX; +} +const sal_Char* OEvoabDriver::getEVOAB_CLI_ARG_OUTPUT_FORMAT() +{ + static const sal_Char* EVOAB_CLI_ARG_OUTPUT_FORMAT = "--format=csv"; + return EVOAB_CLI_ARG_OUTPUT_FORMAT; +} +const sal_Char* OEvoabDriver::getEVOAB_CLI_ARG_VERSION() +{ + static const sal_Char* EVOAB_CLI_ARG_VERSION = "--version"; + return EVOAB_CLI_ARG_VERSION; +} +const sal_Char* OEvoabDriver::getEVOAB_CLI_ARG_OUTPUT_REDIRECT() +{ + static const sal_Char* EVOAB_CLI_ARG_OUTPUT_REDIRECT = ">"; + return EVOAB_CLI_ARG_OUTPUT_REDIRECT; +} +rtl::OUString OEvoabDriver::translateFileErrorMessage( oslFileError nFileErr) +{ + ::rtl::OUString sFileErr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" no file operation!.")); + switch (nFileErr) + { + case osl_File_E_None: + sFileErr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" File operation succeeded!")); + break; + case osl_File_E_INVAL: + sFileErr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" File operation failed: the format of the parameters was not valid!")); + break; + case osl_File_E_INTR: + sFileErr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" File operation failed: function call was interrupted!")); + break; + case osl_File_E_IO: + sFileErr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" File operation failed: I/O errors!")); + break; + case osl_File_E_ISDIR: + sFileErr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" File operation failed: is a directory!")); + break; + case osl_File_E_BADF: + sFileErr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" File operation failed: bad file!")); + break; + case osl_File_E_FAULT: + sFileErr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" File operation failed: bad address!")); + break; + case osl_File_E_AGAIN: + sFileErr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" File operation failed: operation would block!")); + break; + case osl_File_E_NOLINK: + sFileErr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" File operation failed: link has been severed!")); + break; + default: + sFileErr = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" File operation failed: other reason!")); + } + return sFileErr; +} +// ----------------------------------------------------------------------------- +Sequence< DriverPropertyInfo > SAL_CALL OEvoabDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException) +{ + if ( !acceptsURL(url) ) + { + ::connectivity::SharedResources aResources; + const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR); + ::dbtools::throwGenericSQLException(sMessage ,*this); + } // if ( !acceptsURL(url) ) + return Sequence< DriverPropertyInfo >(); +} diff --git a/connectivity/source/drivers/evoab/LDriver.hxx b/connectivity/source/drivers/evoab/LDriver.hxx new file mode 100644 index 000000000000..bf45c93d9531 --- /dev/null +++ b/connectivity/source/drivers/evoab/LDriver.hxx @@ -0,0 +1,118 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LDriver.hxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_EVOAB_LDRIVER_HXX_ +#define _CONNECTIVITY_EVOAB_LDRIVER_HXX_ + +#include <cppuhelper/compbase2.hxx> +#include "connectivity/CommonTools.hxx" +#include "file/FDriver.hxx" +#include <unotools/tempfile.hxx> +#include <osl/file.h> +#include <osl/process.h> + +#define EVOAB_EVOLUTION_SCHEMA "evolution" +#define EVOAB_LDAP_SCHEMA "ldap" +#define EVOAB_DRIVER_IMPL_NAME "com.sun.star.comp.sdbc.evoab.OEvoabDriver" + +namespace connectivity +{ + namespace evoab + { + + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL OEvoabDriver_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception ); + + class OEvoabDriver : public file::OFileDriver + { + private: + enum MaybeVoidBool + { + eUnknown, + eTrue, + eFalse + }; + ::utl::TempFile m_aTempDir; + rtl::OUString m_aFolderListName; + rtl::OUString m_aVersionName; + rtl::OUString m_aFileExt; + rtl::OUString m_aWorkingDirURL; + rtl::OUString m_aEvoab_CLI_EffectiveCommand; + rtl::OUString m_aEvoab_CLI_FullPathCommand; + sal_Bool m_bWorkingDirCreated; + MaybeVoidBool m_eSupportedEvoVersion; + + sal_Bool fileExists(const ::rtl::OUString& _rURL, sal_Bool _bIsDir=sal_False) const; + + public: + OEvoabDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory); + + inline rtl::OUString getEvoFolderListName() const { return m_aFolderListName;} + inline rtl::OUString getFileExt() const { return m_aFileExt;} + inline rtl::OUString getEvoFolderListFileName() const { return m_aFolderListName + ::rtl::OUString::createFromAscii(".") + m_aFileExt;} + inline rtl::OUString getEvoVersionFileName() const { return m_aVersionName + ::rtl::OUString::createFromAscii(".") + m_aFileExt;} + inline rtl::OUString getWorkingDirURL() const { return m_aWorkingDirURL;} + inline rtl::OUString getEvoab_CLI_FullPathCommand() const { return m_aEvoab_CLI_FullPathCommand;} + inline rtl::OUString getEvoab_CLI_EffectiveCommand() const { return m_aEvoab_CLI_EffectiveCommand;} + inline sal_Bool doesEvoab_CLI_HavePath() const { return m_aEvoab_CLI_FullPathCommand.lastIndexOf('/')!=-1;} + const rtl::OUString getEvoab_CLI_Command() const; + const rtl::OUString getEvoab_CLI_Path() const; + const rtl::OUString getWorkingDirPath() const; + const String getEvoFolderListFileURL() const; + String getTempDirURL() const; + + // XInterface + ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); + // XDriver + virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL connect( const ::rtl::OUString& url, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL acceptsURL( const ::rtl::OUString& url ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo( const ::rtl::OUString& url, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + + + // static methods + static ::rtl::OUString getImplementationName_Static( ) throw(::com::sun::star::uno::RuntimeException); + static sal_Bool acceptsURL_Stat( const ::rtl::OUString& url ); + static ::rtl::OUString translateProcessErrorMessage( oslProcessError nProcErr); + static ::rtl::OUString translateFileErrorMessage( oslFileError nFileErr); + static const sal_Char* getSDBC_SCHEME_EVOLUTION(); + static const sal_Char* getEVOAB_FOLDERLIST_FILE_NAME(); + static const sal_Char* getEVOAB_VERSION_FILE_NAME(); + static const sal_Char* getEVOAB_META_FILE_EXT(); + static const sal_Char* getEVOAB_CLI_FULLPATHCOMMAND(); + static const sal_Char* getEVOAB_CLI_ARG_LIST_FOLDERS(); + static const sal_Char* getEVOAB_CLI_ARG_OUTPUT_FILE_PREFIX(); + static const sal_Char* getEVOAB_CLI_ARG_OUTPUT_FORMAT(); + static const sal_Char* getEVOAB_CLI_ARG_VERSION(); + static const sal_Char* getEVOAB_CLI_ARG_OUTPUT_REDIRECT(); + + }; + } + +} +#endif //_CONNECTIVITY_EVOAB_LDRIVER_HXX_ diff --git a/connectivity/source/drivers/evoab/LFolderList.cxx b/connectivity/source/drivers/evoab/LFolderList.cxx new file mode 100644 index 000000000000..a3c031c05c05 --- /dev/null +++ b/connectivity/source/drivers/evoab/LFolderList.cxx @@ -0,0 +1,566 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LFolderList.cxx,v $ + * $Revision: 1.15 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" + +#include <ctype.h> +#include <algorithm> +#include "LFolderList.hxx" +#include <com/sun/star/sdbc/ColumnValue.hpp> +#include <com/sun/star/sdbc/DataType.hpp> +#include <svtools/converter.hxx> +#include "LConnection.hxx" +#include "LColumns.hxx" +#include <osl/thread.h> +#include <tools/config.hxx> +#include <comphelper/sequence.hxx> +#include <svtools/zforlist.hxx> +#include <rtl/math.hxx> +#include <stdio.h> //sprintf +#include <comphelper/extract.hxx> +#include <comphelper/numbers.hxx> +#include "LDriver.hxx" +#include <com/sun/star/util/NumberFormat.hpp> +#include <unotools/configmgr.hxx> +#include <i18npool/mslangid.hxx> +#include "connectivity/dbconversion.hxx" +#include <comphelper/types.hxx> +#include <unotools/ucbstreamhelper.hxx> +#include <tools/debug.hxx> +#include "connectivity/dbexception.hxx" +#ifndef CONNECTIVITY_EVOAB_DEBUG_HELPER_HXX +#include "LDebug.hxx" +#endif +#include <svtools/syslocale.hxx> + +using namespace ::comphelper; +using namespace connectivity; +using namespace connectivity::evoab; +using namespace connectivity::file; +using namespace ::cppu; +using namespace utl; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::sdbcx; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; + +// ------------------------------------------------------------------------- +void OEvoabFolderList::fillColumns(const ::com::sun::star::lang::Locale& _aLocale) +{ + BOOL bRead = TRUE; + + QuotedTokenizedString aHeaderLine; + OEvoabConnection* pConnection = (OEvoabConnection*)m_pConnection; + + // read first row + QuotedTokenizedString aFirstLine; + bRead = m_pFileStream->ReadByteStringLine(aFirstLine,pConnection->getTextEncoding()); + + while(bRead && !aFirstLine.Len()) + { + bRead = m_pFileStream->ReadByteStringLine(aFirstLine,pConnection->getTextEncoding()); + } + // use first row as headerline because we need the number of columns + aHeaderLine = aFirstLine; + + // column count + xub_StrLen nFieldCount = aHeaderLine.GetTokenCount(pConnection->getFieldDelimiter(),pConnection->getStringDelimiter()); + + if(!m_aColumns.isValid()) + m_aColumns = new OSQLColumns(); + else + m_aColumns->get().clear(); + + m_aTypes.clear(); + m_aPrecisions.clear(); + m_aScales.clear(); + // reserve some space + m_aColumns->get().reserve(nFieldCount); + m_aTypes.reserve(nFieldCount); + m_aPrecisions.reserve(nFieldCount); + m_aScales.reserve(nFieldCount); + + sal_Bool bCase = getConnection()->getMetaData()->storesMixedCaseQuotedIdentifiers(); + CharClass aCharClass(pConnection->getDriver()->getFactory(),_aLocale); + // read description + sal_Unicode cDecimalDelimiter = pConnection->getDecimalDelimiter(); + sal_Unicode cThousandDelimiter = pConnection->getThousandDelimiter(); + String aColumnName; + ::rtl::OUString aTypeName; + ::comphelper::UStringMixEqual aCase(bCase); + xub_StrLen nStartPosFirstLine = 0; // use for eficient way to get the tokens + xub_StrLen nStartPosFirstLine2 = 0; + for (xub_StrLen i = 0; i < nFieldCount; i++) + { + + // no column name so ... + aColumnName = 'C'; + aColumnName += String::CreateFromInt32(i+1); + + sal_Int32 eType; + UINT16 nPrecision = 0; + UINT16 nScale = 0; + + BOOL bNumeric = FALSE; + ULONG nIndex = 0; + + // first without fielddelimiter + String aField; + aFirstLine.GetTokenSpecial(aField,nStartPosFirstLine,pConnection->getFieldDelimiter(),'\0'); + if (aField.Len() == 0 || + (pConnection->getStringDelimiter() && pConnection->getStringDelimiter() == aField.GetChar(0))) + { + bNumeric = FALSE; + } + else + { + String aField2; + if ( pConnection->getStringDelimiter() != '\0' ) + aFirstLine.GetTokenSpecial(aField2,nStartPosFirstLine2,pConnection->getFieldDelimiter(),pConnection->getStringDelimiter()); + else + aField2 = aField; + + if (aField2.Len() == 0) + { + bNumeric = FALSE; + } + else + { + bNumeric = TRUE; + xub_StrLen nDot = 0; + for (xub_StrLen j = 0; j < aField2.Len(); j++) + { + sal_Unicode c = aField2.GetChar(j); + // nur Ziffern und Dezimalpunkt und Tausender-Trennzeichen? + if ((!cDecimalDelimiter || c != cDecimalDelimiter) && + (!cThousandDelimiter || c != cThousandDelimiter) && + !aCharClass.isDigit(aField2,j)) + { + bNumeric = FALSE; + break; + } + if (cDecimalDelimiter && c == cDecimalDelimiter) + { + nPrecision = 15; // we have an decimal value + nScale = 2; + nDot++; + } + } + + if (nDot > 1) // if there is more than one dot it isn't a number + bNumeric = FALSE; + if (bNumeric && cThousandDelimiter) + { + // Ist der Trenner richtig angegeben? + String aValue = aField2.GetToken(0,cDecimalDelimiter); + for (sal_Int32 j = aValue.Len() - 4; j >= 0; j -= 4) + { + sal_Unicode c = aValue.GetChar(j); + // nur Ziffern und Dezimalpunkt und Tausender-Trennzeichen? + if (c == cThousandDelimiter && j) + continue; + else + { + bNumeric = FALSE; + break; + } + } + } + + // jetzt koennte es noch ein Datumsfeld sein + if (!bNumeric) + { + try + { + nIndex = m_xNumberFormatter->detectNumberFormat(::com::sun::star::util::NumberFormat::ALL,aField2); + } + catch(Exception&) + { + } + } + } + } + + sal_Int32 nFlags = 0; + if (bNumeric) + { + if (cDecimalDelimiter) + { + if(nPrecision) + { + eType = DataType::DECIMAL; + aTypeName = ::rtl::OUString::createFromAscii("DECIMAL"); + } + else + { + eType = DataType::DOUBLE; + aTypeName = ::rtl::OUString::createFromAscii("DOUBLE"); + } + } + else + eType = DataType::INTEGER; + nFlags = ColumnSearch::BASIC; + } + else + { + + switch (comphelper::getNumberFormatType(m_xNumberFormatter,nIndex)) + { + case NUMBERFORMAT_DATE: + eType = DataType::DATE; + aTypeName = ::rtl::OUString::createFromAscii("DATE"); + break; + case NUMBERFORMAT_DATETIME: + eType = DataType::TIMESTAMP; + aTypeName = ::rtl::OUString::createFromAscii("TIMESTAMP"); + break; + case NUMBERFORMAT_TIME: + eType = DataType::TIME; + aTypeName = ::rtl::OUString::createFromAscii("TIME"); + break; + default: + eType = DataType::VARCHAR; + nPrecision = 0; // nyi: Daten koennen aber laenger sein! + nScale = 0; + aTypeName = ::rtl::OUString::createFromAscii("VARCHAR"); + }; + nFlags |= ColumnSearch::CHAR; + } + + // check if the columname already exists + String aAlias(aColumnName); + OSQLColumns::Vector::const_iterator aFind = connectivity::find(m_aColumns->get().begin(),m_aColumns->get().end(),aAlias,aCase); + sal_Int32 nExprCnt = 0; + while(aFind != m_aColumns->get().end()) + { + (aAlias = aColumnName) += String::CreateFromInt32(++nExprCnt); + aFind = connectivity::find(m_aColumns->get().begin(),m_aColumns->get().end(),aAlias,aCase); + } + + sdbcx::OColumn* pColumn = new sdbcx::OColumn(aAlias,aTypeName,::rtl::OUString(), + ColumnValue::NULLABLE, + nPrecision, + nScale, + eType, + sal_False, + sal_False, + sal_False, + bCase); + Reference< XPropertySet> xCol = pColumn; + m_aColumns->get().push_back(xCol); + m_aTypes.push_back(eType); + m_aPrecisions.push_back(nPrecision); + m_aScales.push_back(nScale); + } + m_pFileStream->Seek(STREAM_SEEK_TO_BEGIN); +} +// ------------------------------------------------------------------------- +DBG_NAME( OEvoabFolderList ); +OEvoabFolderList::OEvoabFolderList(OEvoabConnection* _pConnection) + :m_nFilePos(0) + ,m_pFileStream(NULL) + ,m_pConnection(_pConnection) + ,m_bIsNull(sal_False) +{ + DBG_CTOR( OEvoabFolderList, NULL ); + m_aColumns = new OSQLColumns(); + + construct(); +} +// ----------------------------------------------------------------------------- +void OEvoabFolderList::construct() +{ + SvtSysLocale aLocale; + ::com::sun::star::lang::Locale aAppLocale(aLocale.GetLocaleDataPtr()->getLocale()); + Sequence< ::com::sun::star::uno::Any > aArg(1); + aArg[0] <<= aAppLocale; + + Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier(m_pConnection->getDriver()->getFactory()->createInstanceWithArguments(::rtl::OUString::createFromAscii("com.sun.star.util.NumberFormatsSupplier"),aArg),UNO_QUERY); + m_xNumberFormatter = Reference< ::com::sun::star::util::XNumberFormatter >(m_pConnection->getDriver()->getFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.util.NumberFormatter")),UNO_QUERY); + m_xNumberFormatter->attachNumberFormatsSupplier(xSupplier); + + INetURLObject aURL; + aURL.SetURL(m_pConnection->getDriver()->getEvoFolderListFileURL()); + + String aFileName = aURL.GetMainURL(INetURLObject::NO_DECODE); + + EVO_TRACE_STRING("OJ::construct()::aFileName = %s\n", aFileName ); + m_pFileStream = createStream_simpleError( aFileName,STREAM_READWRITE | STREAM_NOCREATE | STREAM_SHARE_DENYWRITE); + + if(!m_pFileStream) + m_pFileStream = createStream_simpleError( aFileName,STREAM_READ | STREAM_NOCREATE | STREAM_SHARE_DENYNONE); + + if(m_pFileStream) + { + m_pFileStream->Seek(STREAM_SEEK_TO_END); + sal_Int32 nSize = m_pFileStream->Tell(); + m_pFileStream->Seek(STREAM_SEEK_TO_BEGIN); + + // Buffersize abhaengig von der Filegroesse + m_pFileStream->SetBufferSize(nSize > 1000000 ? 32768 : + nSize > 100000 ? 16384 : + nSize > 10000 ? 4096 : 1024); + OSL_TRACE("OEvoabFolderList::construct()::m_pFileStream->Tell() = %d\n", nSize ); + + fillColumns(aAppLocale); + } +} + + +//------------------------------------------------------------------ +sal_Bool OEvoabFolderList::fetchRow(OValueRow _rRow,const OSQLColumns & _rCols) +{ + (_rRow->get())[0] = m_nFilePos; // the "bookmark" + + OEvoabConnection* pConnection = (OEvoabConnection*)m_pConnection; + // Felder: + xub_StrLen nStartPos = 0; + String aStr; + OSQLColumns::Vector::const_iterator aIter = _rCols.get().begin(); + for (sal_Int32 i = 0; aIter != _rCols.get().end();++aIter, ++i) + { + m_aCurrentLine.GetTokenSpecial(aStr,nStartPos,pConnection->getFieldDelimiter(),pConnection->getStringDelimiter()); + //OSL_TRACE("OEvoabFolderList::fetchRow()::aStr = %s\n", ((OUtoCStr(::rtl::OUString(aStr))) ? (OUtoCStr(::rtl::OUString(aStr))):("NULL")) ); + + if (aStr.Len() == 0) + (_rRow->get())[i+1].setNull(); + else + { + // length depending on the data type + sal_Int32 nType = m_aTypes[i]; + switch(nType) + { + case DataType::TIMESTAMP: + case DataType::DATE: + case DataType::TIME: + { + double nRes = 0.0; + try + { + nRes = m_xNumberFormatter->convertStringToNumber(::com::sun::star::util::NumberFormat::ALL,aStr); + Reference<XPropertySet> xProp(m_xNumberFormatter->getNumberFormatsSupplier()->getNumberFormatSettings(),UNO_QUERY); + com::sun::star::util::Date aDate; + xProp->getPropertyValue(::rtl::OUString::createFromAscii("NullDate")) >>= aDate; + + switch(nType) + { + case DataType::DATE: + (_rRow->get())[i+1] = ::dbtools::DBTypeConversion::toDouble(::dbtools::DBTypeConversion::toDate(nRes,aDate)); + break; + case DataType::TIMESTAMP: + (_rRow->get())[i+1] = ::dbtools::DBTypeConversion::toDouble(::dbtools::DBTypeConversion::toDateTime(nRes,aDate)); + break; + default: + (_rRow->get())[i+1] = ::dbtools::DBTypeConversion::toDouble(::dbtools::DBTypeConversion::toTime(nRes)); + } + } + catch(Exception&) + { + (_rRow->get())[i+1].setNull(); + } + } break; + case DataType::DOUBLE: + case DataType::INTEGER: + case DataType::DECIMAL: // #99178# OJ + case DataType::NUMERIC: + { + sal_Unicode cDecimalDelimiter = pConnection->getDecimalDelimiter(); + sal_Unicode cThousandDelimiter = pConnection->getThousandDelimiter(); + String aStrConverted; + + OSL_ENSURE(cDecimalDelimiter && nType != DataType::INTEGER || + !cDecimalDelimiter && nType == DataType::INTEGER, + "FalscherTyp"); + + // In Standard-Notation (DezimalPUNKT ohne Tausender-Komma) umwandeln: + for (xub_StrLen j = 0; j < aStr.Len(); ++j) + { + if (cDecimalDelimiter && aStr.GetChar(j) == cDecimalDelimiter) + aStrConverted += '.'; + else if ( aStr.GetChar(j) == '.' ) // special case, if decimal seperator isn't '.' we have to vut the string after it + break; // #99189# OJ + else if (cThousandDelimiter && aStr.GetChar(j) == cThousandDelimiter) + { + // weglassen + } + else + aStrConverted += aStr.GetChar(j) ; + } + double nVal = ::rtl::math::stringToDouble(aStrConverted.GetBuffer(),',','.',NULL,NULL); + + // #99178# OJ + if ( DataType::DECIMAL == nType || DataType::NUMERIC == nType ) + (_rRow->get())[i+1] = String::CreateFromDouble(nVal); + else + (_rRow->get())[i+1] = nVal; + } break; + + default: + { + // Wert als String in Variable der Row uebernehmen + (_rRow->get())[i+1] = aStr; + } + break; + } + } + } + return sal_True; +} + + +//------------------------------------------------------------------ +sal_Bool OEvoabFolderList::seekRow(IResultSetHelper::Movement eCursorPosition) +{ + //OSL_TRACE("OEvoabFolderList::seekRow()::(before SeekRow)m_aCurrentLine = %d\n", ((OUtoCStr(::rtl::OUString(m_aCurrentLine))) ? (OUtoCStr(::rtl::OUString(m_aCurrentLine))):("NULL")) ); + + if ( !m_pFileStream ) + return sal_False; + OEvoabConnection* pConnection = (OEvoabConnection*)m_pConnection; + // ---------------------------------------------------------- + // Positionierung vorbereiten: + //OSL_TRACE("OEvoabFolderList::seekRow()::(before SeekRow,m_pFileStriam Exist)m_aCurrentLine = %d\n", ((OUtoCStr(::rtl::OUString(m_aCurrentLine))) ? (OUtoCStr(::rtl::OUString(m_aCurrentLine))):("NULL")) ); + + switch(eCursorPosition) + { + case IResultSetHelper::FIRST: + m_nFilePos = 0; + // run through + + case IResultSetHelper::NEXT: + m_pFileStream->Seek(m_nFilePos); + + if (m_pFileStream->IsEof()) + { + OSL_TRACE( "OEvoabFolderList::seekRow: EOF /before/ reading the line." ); + return sal_False; + } + + m_pFileStream->ReadByteStringLine(m_aCurrentLine,pConnection->getTextEncoding()); + if (m_pFileStream->IsEof()) + { + OSL_TRACE( "OEvoabFolderList::seekRow: EOF /after/ reading the line." ); + if ( !m_aCurrentLine.Len() ) + { + OSL_TRACE( "OEvoabFolderList::seekRow: empty line read." ); + return sal_False; + } + } + m_nFilePos = m_pFileStream->Tell(); + break; + + default: + OSL_ENSURE( sal_False, "OEvoabFolderList::seekRow: unsupported positioning!" ); + break; + } + + //OSL_TRACE("OEvoabFolderList::seekRow()::(after SeekRow)m_aCurrentLine = %d\n", ((OUtoCStr(::rtl::OUString(m_aCurrentLine))) ? (OUtoCStr(::rtl::OUString(m_aCurrentLine))):("NULL")) ); + + return sal_True; +} +// ----------------------------------------------------------------------------- +SvStream* OEvoabFolderList::createStream_simpleError( const String& _rFileName, StreamMode _eOpenMode) +{ + utl::UcbLockBytesHandler* p_null_dummy=NULL; + SvStream* pReturn = ::utl::UcbStreamHelper::CreateStream( _rFileName, _eOpenMode, p_null_dummy); + if (pReturn && (ERRCODE_NONE != pReturn->GetErrorCode())) + { + delete pReturn; + pReturn = NULL; + } + return pReturn; +} +// ----------------------------------------------------------------------------- +const ORowSetValue& OEvoabFolderList::getValue(sal_Int32 _nColumnIndex ) throw(::com::sun::star::sdbc::SQLException) +{ + checkIndex( _nColumnIndex ); + + m_bIsNull = (m_aRow->get())[_nColumnIndex].isNull(); + return (m_aRow->get())[_nColumnIndex]; +} +// ----------------------------------------------------------------------------- +void OEvoabFolderList::checkIndex(sal_Int32 _nColumnIndex ) throw(::com::sun::star::sdbc::SQLException) +{ + if ( _nColumnIndex <= 0 || _nColumnIndex >= (sal_Int32)m_aRow->get().size() ) { +// ::dbtools::throwInvalidIndexException(); + ; + } +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OEvoabFolderList::getString( sal_Int32 _nColumnIndex ) throw(SQLException, RuntimeException) +{ + return getValue(_nColumnIndex); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OEvoabFolderList::getInt( sal_Int32 _nColumnIndex ) throw(SQLException, RuntimeException) +{ + return getValue( _nColumnIndex ); +} +// ----------------------------------------------------------------------------- +void OEvoabFolderList::initializeRow(sal_Int32 _nColumnCount) +{ + if(!m_aRow.isValid()) + { + m_aRow = new OValueVector(_nColumnCount); + (m_aRow->get())[0].setBound(sal_True); + ::std::for_each(m_aRow->get().begin()+1,m_aRow->get().end(),TSetBound(sal_False)); + } + //OSL_TRACE("OEvoabFolderList::initializeRow()::_nColumnCount = %d\n", _nColumnCount); + +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OEvoabFolderList::first( ) throw(SQLException, RuntimeException) +{ + sal_Bool bSuccess = seekRow(IResultSetHelper::FIRST); + + EVO_TRACE_STRING("OEvoabFolderList::first(): returning %s\n", ::rtl::OUString::valueOf(bSuccess) ); + return bSuccess; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OEvoabFolderList::next( ) throw(SQLException, RuntimeException) +{ + sal_Bool bSuccess = seekRow(IResultSetHelper::NEXT); + + EVO_TRACE_STRING("OEvoabFolderList::next(): returning %s\n", ::rtl::OUString::valueOf(bSuccess) ); + return bSuccess; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OEvoabFolderList::getRow( ) throw(SQLException, RuntimeException) +{ + sal_Bool bRet = fetchRow(m_aRow,getTableColumns().getBody()); + EVO_TRACE_STRING("OEvoabFolderList::getRow()::fetchRow() = %s\n", ::rtl::OUString::valueOf(bRet) ); + + return bRet; +} diff --git a/connectivity/source/drivers/evoab/LFolderList.hxx b/connectivity/source/drivers/evoab/LFolderList.hxx new file mode 100644 index 000000000000..baa2a3b05e86 --- /dev/null +++ b/connectivity/source/drivers/evoab/LFolderList.hxx @@ -0,0 +1,95 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LFolderList.hxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_EVOAB_LEVOABFOLDERLIST_HXX_ +#define _CONNECTIVITY_EVOAB_LEVOABFOLDERLIST_HXX_ + +#include "connectivity/sdbcx/VColumn.hxx" +#include "connectivity/CommonTools.hxx" +#include <tools/urlobj.hxx> +#include "LTable.hxx" +#include "TResultSetHelper.hxx" + + +namespace connectivity +{ + namespace evoab + { + //================================================================== + // Ableitung von String mit ueberladenen GetToken/GetTokenCount-Methoden + // Speziell fuer FLAT FILE-Format: Strings koennen gequotet sein + //================================================================== + + class OEvoabConnection; + + class OEvoabFolderList + { + // maps a row postion to a file position + ::std::vector<sal_Int32> m_aTypes; // holds all type for columns just to avoid to ask the propertyset + ::std::vector<sal_Int32> m_aPrecisions; // same as aboth + ::std::vector<sal_Int32> m_aScales; + QuotedTokenizedString m_aCurrentLine; + ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > m_xNumberFormatter; + sal_Int32 m_nFilePos; // aktuelle IResultSetHelper::Movement + SvStream* m_pFileStream; + OEvoabConnection* m_pConnection; + ::vos::ORef<OSQLColumns> m_aColumns; + OValueRow m_aRow; + sal_Bool m_bIsNull; + + private: + void fillColumns(const ::com::sun::star::lang::Locale& _aLocale); + BOOL CreateFile(const INetURLObject& aFile, BOOL& bCreateMemo); + + sal_Bool fetchRow(OValueRow _rRow,const OSQLColumns& _rCols); + sal_Bool seekRow(IResultSetHelper::Movement eCursorPosition); + + public: + + OEvoabFolderList( OEvoabConnection* _pConnection); + + OEvoabConnection* getConnection() const { return m_pConnection;} + ::vos::ORef<OSQLColumns> getTableColumns() const {return m_aColumns;} + void construct(); // can throw any exception + static SvStream* createStream_simpleError( const String& _rFileName, StreamMode _eOpenMode); + void initializeRow(sal_Int32 _nColumnCount); + void checkIndex(sal_Int32 _nColumnIndex ) throw(::com::sun::star::sdbc::SQLException); + const ORowSetValue& getValue(sal_Int32 _nColumnIndex ) throw(::com::sun::star::sdbc::SQLException); + ::rtl::OUString SAL_CALL getString( sal_Int32 _nColumnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + sal_Int32 SAL_CALL getInt( sal_Int32 _nColumnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + sal_Bool SAL_CALL first( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + sal_Bool SAL_CALL next( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + sal_Int32 SAL_CALL getRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + + }; + } +} +#endif // _CONNECTIVITY_EVOAB_LEVOABFOLDERLIST_HXX_ + diff --git a/connectivity/source/drivers/evoab/LNoException.cxx b/connectivity/source/drivers/evoab/LNoException.cxx new file mode 100644 index 000000000000..183ab75559f4 --- /dev/null +++ b/connectivity/source/drivers/evoab/LNoException.cxx @@ -0,0 +1,327 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LNoException.cxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "LTable.hxx" +#include "LConnection.hxx" + +using namespace connectivity; +using namespace connectivity::evoab; + +//------------------------------------------------------------------ +xub_StrLen OEvoabString::GetTokenCount( sal_Unicode cTok, sal_Unicode cStrDel ) const +{ + if ( !Len() ) + return 0; + + xub_StrLen nTokCount = 1; + BOOL bStart = TRUE; // Stehen wir auf dem ersten Zeichen im Token? + BOOL bInString = FALSE; // Befinden wir uns INNERHALB eines (cStrDel delimited) String? + + // Suche bis Stringende nach dem ersten nicht uebereinstimmenden Zeichen + for( xub_StrLen i = 0; i < Len(); i++ ) + { + if (bStart) + { + bStart = FALSE; + // Erstes Zeichen ein String-Delimiter? + if ((*this).GetChar(i) == cStrDel) + { + bInString = TRUE; // dann sind wir jetzt INNERHALB des Strings! + continue; // dieses Zeichen ueberlesen! + } + } + + if (bInString) { + // Wenn jetzt das String-Delimiter-Zeichen auftritt ... + if ( (*this).GetChar(i) == cStrDel ) + { + if ((i+1 < Len()) && ((*this).GetChar(i+1) == cStrDel)) + { + // Verdoppeltes String-Delimiter-Zeichen: + i++; // kein String-Ende, naechstes Zeichen ueberlesen. + } + else + { + // String-Ende + bInString = FALSE; + } + } + } else { + // Stimmt das Tokenzeichen ueberein, dann erhoehe TokCount + if ( (*this).GetChar(i) == cTok ) + { + nTokCount++; + bStart = TRUE; + } + } + } + //OSL_TRACE("OEvoabString::nTokCount = %d\n", ((OUtoCStr(::rtl::OUString(nTokCount))) ? (OUtoCStr(::rtl::OUString(nTokCount))):("NULL")) ); + + return nTokCount; +} + +//------------------------------------------------------------------ +void OEvoabString::GetTokenSpecial( String& _rStr,xub_StrLen& nStartPos, sal_Unicode cTok, sal_Unicode cStrDel ) const +{ + _rStr.Erase(); + xub_StrLen nLen = Len(); + if ( nLen ) + { + BOOL bInString = (nStartPos < nLen) && ((*this).GetChar(nStartPos) == cStrDel); // Befinden wir uns INNERHALB eines (cStrDel delimited) String? + + // Erstes Zeichen ein String-Delimiter? + if (bInString ) + ++nStartPos; // dieses Zeichen ueberlesen! + // Suche bis Stringende nach dem ersten nicht uebereinstimmenden Zeichen + for( xub_StrLen i = nStartPos; i < nLen; ++i ) + { + if (bInString) + { + // Wenn jetzt das String-Delimiter-Zeichen auftritt ... + if ( (*this).GetChar(i) == cStrDel ) + { + if ((i+1 < nLen) && ((*this).GetChar(i+1) == cStrDel)) + { + // Verdoppeltes String-Delimiter-Zeichen: + ++i; // kein String-Ende, naechstes Zeichen ueberlesen. + + _rStr += (*this).GetChar(i); // Zeichen gehoert zum Resultat-String + } + else + { + // String-Ende + bInString = FALSE; + } + } + else + { + _rStr += (*this).GetChar(i); // Zeichen gehoert zum Resultat-String + } + + } + else + { + // Stimmt das Tokenzeichen ueberein, dann erhoehe nTok + if ( (*this).GetChar(i) == cTok ) + { + // Vorzeitiger Abbruch der Schleife moeglich, denn + // wir haben, was wir wollten. + nStartPos = i+1; + break; + } + else + { + _rStr += (*this).GetChar(i); // Zeichen gehoert zum Resultat-String + } + } + } + } +} +// ----------------------------------------------------------------------------- +void OEvoabTable::refreshIndexes() +{ +} +// ----------------------------------------------------------------------------- +sal_Bool OEvoabTable::checkHeaderLine() +{ + if (m_nFilePos == 0 && ((OEvoabConnection*)m_pConnection)->isHeaderLine()) + { + BOOL bRead2; + do + { + bRead2 = m_pFileStream->ReadByteStringLine(m_aCurrentLine,m_pConnection->getTextEncoding()); + } + while(bRead2 && !m_aCurrentLine.Len()); + + m_nFilePos = m_pFileStream->Tell(); + if (m_pFileStream->IsEof()) + return sal_False; + } + return sal_True; +} +//------------------------------------------------------------------ +sal_Bool OEvoabTable::seekRow(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOffset, sal_Int32& nCurPos) +{ + //OSL_TRACE("OEvoabTable::(before SeekRow)m_aCurrentLine = %d\n", ((OUtoCStr(::rtl::OUString(m_aCurrentLine))) ? (OUtoCStr(::rtl::OUString(m_aCurrentLine))):("NULL")) ); + + if ( !m_pFileStream ) + return sal_False; + OEvoabConnection* pConnection = (OEvoabConnection*)m_pConnection; + // ---------------------------------------------------------- + // Positionierung vorbereiten: + //OSL_TRACE("OEvoabTable::(before SeekRow,m_pFileStriam Exist)m_aCurrentLine = %d\n", ((OUtoCStr(::rtl::OUString(m_aCurrentLine))) ? (OUtoCStr(::rtl::OUString(m_aCurrentLine))):("NULL")) ); + + m_nFilePos = nCurPos; + + switch(eCursorPosition) + { + case IResultSetHelper::FIRST: + m_nFilePos = 0; + m_nRowPos = 1; + // run through + case IResultSetHelper::NEXT: + if(eCursorPosition != IResultSetHelper::FIRST) + ++m_nRowPos; + m_pFileStream->Seek(m_nFilePos); + if (m_pFileStream->IsEof() || !checkHeaderLine()) + { + m_nMaxRowCount = m_nRowPos; + return sal_False; + } + + m_aRowToFilePos.insert(::std::map<sal_Int32,sal_Int32>::value_type(m_nRowPos,m_nFilePos)); + + m_pFileStream->ReadByteStringLine(m_aCurrentLine,pConnection->getTextEncoding()); + if (m_pFileStream->IsEof()) + { + m_nMaxRowCount = m_nRowPos; + return sal_False; + } + nCurPos = m_pFileStream->Tell(); + break; + case IResultSetHelper::PRIOR: + --m_nRowPos; + if(m_nRowPos > 0) + { + m_nFilePos = m_aRowToFilePos.find(m_nRowPos)->second; + m_pFileStream->Seek(m_nFilePos); + if (m_pFileStream->IsEof() || !checkHeaderLine()) + return sal_False; + m_pFileStream->ReadByteStringLine(m_aCurrentLine,pConnection->getTextEncoding()); + if (m_pFileStream->IsEof()) + return sal_False; + nCurPos = m_pFileStream->Tell(); + } + else + m_nRowPos = 0; + + break; + + break; + case IResultSetHelper::LAST: + if(m_nMaxRowCount) + { + m_nFilePos = m_aRowToFilePos.rbegin()->second; + m_nRowPos = m_aRowToFilePos.rbegin()->first; + m_pFileStream->Seek(m_nFilePos); + if (m_pFileStream->IsEof() || !checkHeaderLine()) + return sal_False; + m_pFileStream->ReadByteStringLine(m_aCurrentLine,pConnection->getTextEncoding()); + if (m_pFileStream->IsEof()) + return sal_False; + nCurPos = m_pFileStream->Tell(); + } + else + { + while(seekRow(IResultSetHelper::NEXT,1,nCurPos)) ; // run through after last row + // now I know all + seekRow(IResultSetHelper::PRIOR,1,nCurPos); + } + break; + case IResultSetHelper::RELATIVE: + if(nOffset > 0) + { + for(sal_Int32 i = 0;i<nOffset;++i) + seekRow(IResultSetHelper::NEXT,1,nCurPos); + } + else if(nOffset < 0) + { + for(sal_Int32 i = nOffset;i;++i) + seekRow(IResultSetHelper::PRIOR,1,nCurPos); + } + break; + case IResultSetHelper::ABSOLUTE: + { + if(nOffset < 0) + nOffset = m_nRowPos + nOffset; + ::std::map<sal_Int32,sal_Int32>::const_iterator aIter = m_aRowToFilePos.find(nOffset); + if(aIter != m_aRowToFilePos.end()) + { + m_nFilePos = aIter->second; + m_pFileStream->Seek(m_nFilePos); + if (m_pFileStream->IsEof() || !checkHeaderLine()) + return sal_False; + m_pFileStream->ReadByteStringLine(m_aCurrentLine,pConnection->getTextEncoding()); + if (m_pFileStream->IsEof()) + return sal_False; + nCurPos = m_pFileStream->Tell(); + } + else if(m_nMaxRowCount && nOffset > m_nMaxRowCount) // offset is outside the table + { + m_nRowPos = m_nMaxRowCount; + return sal_False; + } + else + { + aIter = m_aRowToFilePos.upper_bound(nOffset); + if(aIter == m_aRowToFilePos.end()) + { + m_nRowPos = m_aRowToFilePos.rbegin()->first; + nCurPos = m_nFilePos = m_aRowToFilePos.rbegin()->second; + while(m_nRowPos != nOffset) + seekRow(IResultSetHelper::NEXT,1,nCurPos); + } + else + { + --aIter; + m_nRowPos = aIter->first; + m_nFilePos = aIter->second; + m_pFileStream->Seek(m_nFilePos); + if (m_pFileStream->IsEof() || !checkHeaderLine()) + return sal_False; + m_pFileStream->ReadByteStringLine(m_aCurrentLine,pConnection->getTextEncoding()); + if (m_pFileStream->IsEof()) + return sal_False; + nCurPos = m_pFileStream->Tell(); + } + } + } + + break; + case IResultSetHelper::BOOKMARK: + m_pFileStream->Seek(nOffset); + if (m_pFileStream->IsEof()) + return sal_False; + + m_nFilePos = m_pFileStream->Tell(); // Byte-Position in der Datei merken (am ZeilenANFANG) + m_pFileStream->ReadByteStringLine(m_aCurrentLine,pConnection->getTextEncoding()); + if (m_pFileStream->IsEof()) + return sal_False; + nCurPos = m_pFileStream->Tell(); + break; + } + + //OSL_TRACE("OEvoabTable::(after SeekRow)m_aCurrentLine = %d\n", ((OUtoCStr(::rtl::OUString(m_aCurrentLine))) ? (OUtoCStr(::rtl::OUString(m_aCurrentLine))):("NULL")) ); + + return sal_True; +} +// ----------------------------------------------------------------------------- diff --git a/connectivity/source/drivers/evoab/LPreparedStatement.cxx b/connectivity/source/drivers/evoab/LPreparedStatement.cxx new file mode 100644 index 000000000000..fa4269fdce4d --- /dev/null +++ b/connectivity/source/drivers/evoab/LPreparedStatement.cxx @@ -0,0 +1,46 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LPreparedStatement.cxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "LPreparedStatement.hxx" +#include "LResultSet.hxx" + +using namespace connectivity::evoab; +using namespace connectivity::file; +using namespace ::com::sun::star::uno; +// ------------------------------------------------------------------------- +OResultSet* OEvoabPreparedStatement::createResultSet() +{ + return new OEvoabResultSet(this,m_aSQLIterator); +} +// ------------------------------------------------------------------------- +IMPLEMENT_SERVICE_INFO(OEvoabPreparedStatement,"com.sun.star.sdbc.driver.evoab.PreparedStatement","com.sun.star.sdbc.PreparedStatement"); + diff --git a/connectivity/source/drivers/evoab/LPreparedStatement.hxx b/connectivity/source/drivers/evoab/LPreparedStatement.hxx new file mode 100644 index 000000000000..e4260ef3a994 --- /dev/null +++ b/connectivity/source/drivers/evoab/LPreparedStatement.hxx @@ -0,0 +1,53 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LPreparedStatement.hxx,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_EVOAB_LPREPAREDSTATEMENT_HXX_ +#define _CONNECTIVITY_EVOAB_LPREPAREDSTATEMENT_HXX_ + +#include "file/FPreparedStatement.hxx" + +namespace connectivity +{ + namespace evoab + { + class OConnection; + class OEvoabPreparedStatement : public file::OPreparedStatement + { + protected: + virtual file::OResultSet* createResultSet(); + public: + OEvoabPreparedStatement( file::OConnection* _pConnection) : file::OPreparedStatement( _pConnection){}; + DECLARE_SERVICE_INFO(); + }; + } +} + +#endif //_CONNECTIVITY_EVOAB_LPREPAREDSTATEMENT_HXX_ + diff --git a/connectivity/source/drivers/evoab/LResultSet.cxx b/connectivity/source/drivers/evoab/LResultSet.cxx new file mode 100644 index 000000000000..fd4959465710 --- /dev/null +++ b/connectivity/source/drivers/evoab/LResultSet.cxx @@ -0,0 +1,193 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LResultSet.cxx,v $ + * $Revision: 1.8 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include <com/sun/star/sdbcx/CompareBookmark.hpp> +#include <com/sun/star/sdbcx/XDeleteRows.hpp> +#include "LResultSet.hxx" +#include <com/sun/star/lang/DisposedException.hpp> +#include <comphelper/sequence.hxx> +#include <comphelper/types.hxx> + +using namespace ::comphelper; + +using namespace connectivity::evoab; +using namespace connectivity::file; +using namespace ::cppu; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::sdbcx; +// using namespace com::sun::star::container; +// using namespace com::sun::star::util; +//------------------------------------------------------------------------------ +OEvoabResultSet::OEvoabResultSet( OStatement_Base* pStmt,connectivity::OSQLParseTreeIterator& _aSQLIterator) + : file::OResultSet(pStmt,_aSQLIterator) + ,m_bBookmarkable(sal_True) +{ + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISBOOKMARKABLE), PROPERTY_ID_ISBOOKMARKABLE, PropertyAttribute::READONLY,&m_bBookmarkable, ::getBooleanCppuType()); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OEvoabResultSet::getImplementationName( ) throw ( RuntimeException) +{ + return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.evoab.ResultSet"); +} +// ------------------------------------------------------------------------- +Sequence< ::rtl::OUString > SAL_CALL OEvoabResultSet::getSupportedServiceNames( ) throw( RuntimeException) +{ + Sequence< ::rtl::OUString > aSupported(2); + aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.ResultSet"); + aSupported[1] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.ResultSet"); + return aSupported; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OEvoabResultSet::supportsService( const ::rtl::OUString& _rServiceName ) throw( RuntimeException) +{ + Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); + const ::rtl::OUString* pSupported = aSupported.getConstArray(); + const ::rtl::OUString* pEnd = pSupported + aSupported.getLength(); + for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) + ; + + return pSupported != pEnd; +} +// ------------------------------------------------------------------------- +Any SAL_CALL OEvoabResultSet::queryInterface( const Type & rType ) throw(RuntimeException) +{ + if(rType == ::getCppuType((const Reference<XDeleteRows>*)0) || rType == ::getCppuType((const Reference<XResultSetUpdate>*)0) + || rType == ::getCppuType((const Reference<XRowUpdate>*)0)) + return Any(); + + Any aRet = OResultSet::queryInterface(rType); + return aRet.hasValue() ? aRet : OEvoabResultSet_BASE::queryInterface(rType); +} +// ------------------------------------------------------------------------- +Sequence< Type > SAL_CALL OEvoabResultSet::getTypes( ) throw( RuntimeException) +{ + Sequence< Type > aTypes = OResultSet::getTypes(); + ::std::vector<Type> aOwnTypes; + aOwnTypes.reserve(aTypes.getLength()); + const Type* pBegin = aTypes.getConstArray(); + const Type* pEnd = pBegin + aTypes.getLength(); + for(;pBegin != pEnd;++pBegin) + { + if(!(*pBegin == ::getCppuType((const Reference<XDeleteRows>*)0) || + *pBegin == ::getCppuType((const Reference<XResultSetUpdate>*)0) || + *pBegin == ::getCppuType((const Reference<XRowUpdate>*)0))) + { + aOwnTypes.push_back(*pBegin); + } + } + Type *pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0]; + Sequence< Type > aRet(pTypes, aOwnTypes.size()); + return ::comphelper::concatSequences(aRet,OEvoabResultSet_BASE::getTypes()); +} + +// ------------------------------------------------------------------------- +// XRowLocate +Any SAL_CALL OEvoabResultSet::getBookmark( ) throw( SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + + return makeAny((sal_Int32)(m_aRow->get())[0]->getValue()); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OEvoabResultSet::moveToBookmark( const Any& bookmark ) throw( SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + + m_bRowDeleted = m_bRowInserted = m_bRowUpdated = sal_False; + + return Move(IResultSetHelper::BOOKMARK,comphelper::getINT32(bookmark),sal_True); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OEvoabResultSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw( SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + + + m_bRowDeleted = m_bRowInserted = m_bRowUpdated = sal_False; + + Move(IResultSetHelper::BOOKMARK,comphelper::getINT32(bookmark),sal_False); + + return relative(rows); +} + +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OEvoabResultSet::compareBookmarks( const Any& lhs, const Any& rhs ) throw( SQLException, RuntimeException) +{ + return (lhs == rhs) ? 0 : 2; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OEvoabResultSet::hasOrderedBookmarks( ) throw( SQLException, RuntimeException) +{ + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OEvoabResultSet::hashBookmark( const Any& bookmark ) throw( SQLException, RuntimeException) +{ + return comphelper::getINT32(bookmark); +} +// ------------------------------------------------------------------------- +IPropertyArrayHelper* OEvoabResultSet::createArrayHelper( ) const +{ + Sequence< Property > aProps; + describeProperties(aProps); + return new ::cppu::OPropertyArrayHelper(aProps); +} +// ------------------------------------------------------------------------- +IPropertyArrayHelper & OEvoabResultSet::getInfoHelper() +{ + return *OEvoabResultSet_BASE3::getArrayHelper(); +} +// ----------------------------------------------------------------------------- +void SAL_CALL OEvoabResultSet::acquire() throw() +{ + OEvoabResultSet_BASE2::acquire(); +} +// ----------------------------------------------------------------------------- +void SAL_CALL OEvoabResultSet::release() throw() +{ + OEvoabResultSet_BASE2::release(); +} +// ----------------------------------------------------------------------------- +::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OEvoabResultSet::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException) +{ + return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); +} +// ----------------------------------------------------------------------------- + diff --git a/connectivity/source/drivers/evoab/LResultSet.hxx b/connectivity/source/drivers/evoab/LResultSet.hxx new file mode 100644 index 000000000000..f93ba9364e5a --- /dev/null +++ b/connectivity/source/drivers/evoab/LResultSet.hxx @@ -0,0 +1,84 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LResultSet.hxx,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_EVOAB_LRESULTSET_HXX_ +#define _CONNECTIVITY_EVOAB_LRESULTSET_HXX_ + +#include "file/FResultSet.hxx" +#include <com/sun/star/sdbcx/XRowLocate.hpp> +#include <cppuhelper/implbase1.hxx> + +namespace connectivity +{ + namespace evoab + { + class OEvoabResultSet; + // these typedef's are only necessary for the compiler + typedef ::cppu::ImplHelper1< ::com::sun::star::sdbcx::XRowLocate> OEvoabResultSet_BASE; + typedef file::OResultSet OEvoabResultSet_BASE2; + typedef ::comphelper::OPropertyArrayUsageHelper<OEvoabResultSet> OEvoabResultSet_BASE3; + + + class OEvoabResultSet : public OEvoabResultSet_BASE2, + public OEvoabResultSet_BASE, + public OEvoabResultSet_BASE3 + { + sal_Bool m_bBookmarkable; + protected: + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const; + // OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); + public: + DECLARE_SERVICE_INFO(); + + OEvoabResultSet( file::OStatement_Base* pStmt,connectivity::OSQLParseTreeIterator& _aSQLIterator); + + // XInterface + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL acquire() throw(); + virtual void SAL_CALL release() throw(); + //XTypeProvider + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw(::com::sun::star::uno::RuntimeException); + // XPropertySet + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException); + + // XRowLocate + virtual ::com::sun::star::uno::Any SAL_CALL getBookmark( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL moveToBookmark( const ::com::sun::star::uno::Any& bookmark ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL moveRelativeToBookmark( const ::com::sun::star::uno::Any& bookmark, sal_Int32 rows ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL compareBookmarks( const ::com::sun::star::uno::Any& first, const ::com::sun::star::uno::Any& second ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasOrderedBookmarks( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL hashBookmark( const ::com::sun::star::uno::Any& bookmark ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + }; + } +} +#endif //_CONNECTIVITY_EVOAB_LRESULTSET_HXX_ + diff --git a/connectivity/source/drivers/evoab/LServices.cxx b/connectivity/source/drivers/evoab/LServices.cxx new file mode 100644 index 000000000000..bab5ae8cfce9 --- /dev/null +++ b/connectivity/source/drivers/evoab/LServices.cxx @@ -0,0 +1,178 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LServices.cxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "LDriver.hxx" +#include <cppuhelper/factory.hxx> +#include <osl/diagnose.h> + +using namespace connectivity::evoab; +using ::rtl::OUString; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::registry::XRegistryKey; +using ::com::sun::star::lang::XSingleServiceFactory; +using ::com::sun::star::lang::XMultiServiceFactory; + +typedef Reference< XSingleServiceFactory > (SAL_CALL *createFactoryFunc) + ( + const Reference< XMultiServiceFactory > & rServiceManager, + const OUString & rComponentName, + ::cppu::ComponentInstantiation pCreateFunction, + const Sequence< OUString > & rServiceNames, + rtl_ModuleCount* _pT + ); + +//*************************************************************************************** +// +// Die vorgeschriebene C-Api muss erfuellt werden! +// Sie besteht aus drei Funktionen, die von dem Modul exportiert werden muessen. +// + +//--------------------------------------------------------------------------------------- +void REGISTER_PROVIDER( + const OUString& aServiceImplName, + const Sequence< OUString>& Services, + const Reference< ::com::sun::star::registry::XRegistryKey > & xKey) +{ + OUString aMainKeyName; + aMainKeyName = OUString::createFromAscii("/"); + aMainKeyName += aServiceImplName; + aMainKeyName += OUString::createFromAscii("/UNO/SERVICES"); + + Reference< ::com::sun::star::registry::XRegistryKey > xNewKey( xKey->createKey(aMainKeyName) ); + OSL_ENSURE(xNewKey.is(), "FILE::component_writeInfo : could not create a registry key !"); + + for (sal_Int32 i=0; i<Services.getLength(); ++i) + xNewKey->createKey(Services[i]); +} + + +//--------------------------------------------------------------------------------------- +struct ProviderRequest +{ + Reference< XSingleServiceFactory > xRet; + Reference< XMultiServiceFactory > const xServiceManager; + OUString const sImplementationName; + + ProviderRequest( + void* pServiceManager, + sal_Char const* pImplementationName + ) + : xServiceManager(reinterpret_cast<XMultiServiceFactory*>(pServiceManager)) + , sImplementationName(OUString::createFromAscii(pImplementationName)) + { + } + + inline + sal_Bool CREATE_PROVIDER( + const OUString& Implname, + const Sequence< OUString > & Services, + ::cppu::ComponentInstantiation Factory, + createFactoryFunc creator + ) + { + if (!xRet.is() && (Implname == sImplementationName)) + try + { + xRet = creator( xServiceManager, sImplementationName,Factory, Services,0); + } + catch(...) + { + } + return xRet.is(); + } + + void* getProvider() const { return xRet.get(); } +}; + +//--------------------------------------------------------------------------------------- + +extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL +component_getImplementationEnvironment( + const sal_Char **ppEnvTypeName, + uno_Environment ** /*ppEnv*/ + ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +//--------------------------------------------------------------------------------------- +extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo( + void* /*pServiceManager*/, + void* pRegistryKey + ) +{ + if (pRegistryKey) + try + { + Reference< ::com::sun::star::registry::XRegistryKey > xKey(reinterpret_cast< ::com::sun::star::registry::XRegistryKey*>(pRegistryKey)); + + REGISTER_PROVIDER( + OEvoabDriver::getImplementationName_Static(), + OEvoabDriver::getSupportedServiceNames_Static(), xKey); + + return sal_True; + } + catch (::com::sun::star::registry::InvalidRegistryException& ) + { + OSL_ENSURE(sal_False, "FILE::component_writeInfo : could not create a registry key ! ## InvalidRegistryException !"); + } + + return sal_False; +} + +//--------------------------------------------------------------------------------------- +extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory( + const sal_Char* pImplementationName, + void* pServiceManager, + void* /*pRegistryKey*/) +{ + void* pRet = 0; + if (pServiceManager) + { + ProviderRequest aReq(pServiceManager,pImplementationName); + + aReq.CREATE_PROVIDER( + OEvoabDriver::getImplementationName_Static(), + OEvoabDriver::getSupportedServiceNames_Static(), + OEvoabDriver_CreateInstance, ::cppu::createSingleFactory) + ; + + if(aReq.xRet.is()) + aReq.xRet->acquire(); + + pRet = aReq.getProvider(); + } + + return pRet; +}; + diff --git a/connectivity/source/drivers/evoab/LStatement.cxx b/connectivity/source/drivers/evoab/LStatement.cxx new file mode 100644 index 000000000000..9ef945b1ccd4 --- /dev/null +++ b/connectivity/source/drivers/evoab/LStatement.cxx @@ -0,0 +1,46 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LStatement.cxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "LStatement.hxx" +#include "LResultSet.hxx" + +using namespace connectivity::evoab; +using namespace connectivity::file; +using namespace com::sun::star::uno; +// ------------------------------------------------------------------------- +OResultSet* OEvoabStatement::createResultSet() +{ + return new OEvoabResultSet(this,m_aSQLIterator); +} +// ------------------------------------------------------------------------- +IMPLEMENT_SERVICE_INFO(OEvoabStatement,"com.sun.star.sdbc.driver.evoab.Statement","com.sun.star.sdbc.Statement"); + diff --git a/connectivity/source/drivers/evoab/LStatement.hxx b/connectivity/source/drivers/evoab/LStatement.hxx new file mode 100644 index 000000000000..9e8af7f7b273 --- /dev/null +++ b/connectivity/source/drivers/evoab/LStatement.hxx @@ -0,0 +1,52 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LStatement.hxx,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_EVOAB_LSTATEMENT_HXX_ +#define _CONNECTIVITY_EVOAB_LSTATEMENT_HXX_ + +#include "file/FStatement.hxx" + +namespace connectivity +{ + namespace evoab + { + class OConnection; + class OEvoabStatement : public file::OStatement + { + protected: + virtual file::OResultSet* createResultSet(); + public: + OEvoabStatement( file::OConnection* _pConnection) : file::OStatement( _pConnection){} + DECLARE_SERVICE_INFO(); + }; + } +} + +#endif //_CONNECTIVITY_EVOAB_LSTATEMENT_HXX_ diff --git a/connectivity/source/drivers/evoab/LTable.cxx b/connectivity/source/drivers/evoab/LTable.cxx new file mode 100644 index 000000000000..cbb4bc53e9f4 --- /dev/null +++ b/connectivity/source/drivers/evoab/LTable.cxx @@ -0,0 +1,873 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LTable.cxx,v $ + * $Revision: 1.18 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" + +#include <ctype.h> +#include "LTable.hxx" +#include <com/sun/star/sdbc/ColumnValue.hpp> +#include <com/sun/star/sdbc/DataType.hpp> +#include <com/sun/star/ucb/XContentAccess.hpp> +#ifndef _COM_SUN_STAR_SQLC_XROW_HPP_ +//#include <com/sun/star/sdbc/XRow.hpp> +#endif +#include <svtools/converter.hxx> +#include "LConnection.hxx" +#include "LColumns.hxx" +#include <osl/thread.h> +#include <tools/config.hxx> +#include <comphelper/sequence.hxx> +#include <svtools/zforlist.hxx> +#include <rtl/math.hxx> +#include <stdio.h> //sprintf +#include <comphelper/extract.hxx> +#include <comphelper/numbers.hxx> +#include "LDriver.hxx" +#include <com/sun/star/util/NumberFormat.hpp> +#include <unotools/configmgr.hxx> +#include <i18npool/mslangid.hxx> +#include "connectivity/dbconversion.hxx" +#include <comphelper/types.hxx> +#include <svtools/syslocale.hxx> +#ifndef CONNECTIVITY_EVOAB_DEBUG_HELPER_HXX +#include "LDebug.hxx" +#endif +#include <map> + +using namespace ::comphelper; +using namespace connectivity; +using namespace connectivity::evoab; +using namespace connectivity::file; +using namespace ::cppu; +using namespace utl; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::ucb; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::sdbcx; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; + +// ------------------------------------------------------------------------- +void OEvoabTable::fillColumns(const ::com::sun::star::lang::Locale& _aLocale) +{ + BOOL bRead = TRUE; + + QuotedTokenizedString aHeaderLine; + OEvoabConnection* pConnection = (OEvoabConnection*)m_pConnection; + if (pConnection->isHeaderLine()) + { + while(bRead && !aHeaderLine.Len()) + { + bRead = m_pFileStream->ReadByteStringLine(aHeaderLine,pConnection->getTextEncoding()); + } + } + + // read first row + QuotedTokenizedString aFirstLine; + bRead = m_pFileStream->ReadByteStringLine(aFirstLine,pConnection->getTextEncoding()); + + if (!pConnection->isHeaderLine() || !aHeaderLine.Len()) + { + while(bRead && !aFirstLine.Len()) + { + bRead = m_pFileStream->ReadByteStringLine(aFirstLine,pConnection->getTextEncoding()); + } + // use first row as headerline because we need the number of columns + aHeaderLine = aFirstLine; + } + // column count + xub_StrLen nFieldCount = aHeaderLine.GetTokenCount(pConnection->getFieldDelimiter(),pConnection->getStringDelimiter()); + + if(!m_aColumns.isValid()) + m_aColumns = new OSQLColumns(); + else + m_aColumns->get().clear(); + + m_aTypes.clear(); + m_aPrecisions.clear(); + m_aScales.clear(); + // reserve some space + m_aColumnRawNames.reserve(nFieldCount); + m_aColumns->get().reserve(nFieldCount); + m_aTypes.reserve(nFieldCount); + m_aPrecisions.reserve(nFieldCount); + m_aScales.reserve(nFieldCount); + + sal_Bool bCase = getConnection()->getMetaData()->storesMixedCaseQuotedIdentifiers(); + CharClass aCharClass(pConnection->getDriver()->getFactory(),_aLocale); + // read description + sal_Unicode cDecimalDelimiter = pConnection->getDecimalDelimiter(); + sal_Unicode cThousandDelimiter = pConnection->getThousandDelimiter(); + String aColumnName; + ::rtl::OUString aTypeName; + ::comphelper::UStringMixEqual aCase(bCase); + xub_StrLen nStartPosHeaderLine = 0; // use for eficient way to get the tokens + xub_StrLen nStartPosFirstLine = 0; // use for eficient way to get the tokens + xub_StrLen nStartPosFirstLine2 = 0; + for (xub_StrLen i = 0; i < nFieldCount; i++) + { + if (pConnection->isHeaderLine()) + { + aHeaderLine.GetTokenSpecial(aColumnName,nStartPosHeaderLine,pConnection->getFieldDelimiter(),pConnection->getStringDelimiter()); + } + else + { + // no column name so ... + aColumnName = 'C'; + aColumnName += String::CreateFromInt32(i+1); + } + //OSL_TRACE("OEvoabTable::aColumnName = %s\n", ((OUtoCStr(::rtl::OUString(aColumnName))) ? (OUtoCStr(::rtl::OUString(aColumnName))):("NULL")) ); + + sal_Int32 eType; + UINT16 nPrecision = 0; + UINT16 nScale = 0; + + BOOL bNumeric = FALSE; + ULONG nIndex = 0; + + // first without fielddelimiter + String aField; + aFirstLine.GetTokenSpecial(aField,nStartPosFirstLine,pConnection->getFieldDelimiter(),'\0'); + //OSL_TRACE("OEvoabTable::aField = %s\n", ((OUtoCStr(::rtl::OUString(aField))) ? (OUtoCStr(::rtl::OUString(aField))):("NULL")) ); + + if (aField.Len() == 0 || + (pConnection->getStringDelimiter() && pConnection->getStringDelimiter() == aField.GetChar(0))) + { + bNumeric = FALSE; + } + else + { + String aField2; + if ( pConnection->getStringDelimiter() != '\0' ) + aFirstLine.GetTokenSpecial(aField2,nStartPosFirstLine2,pConnection->getFieldDelimiter(),pConnection->getStringDelimiter()); + else + aField2 = aField; + + //OSL_TRACE("OEvoabTable::aField2 = %s\n", ((OUtoCStr(::rtl::OUString(aField2))) ? (OUtoCStr(::rtl::OUString(aField2))):("NULL")) ); + + if (aField2.Len() == 0) + { + bNumeric = FALSE; + } + else + { + bNumeric = TRUE; + xub_StrLen nDot = 0; + for (xub_StrLen j = 0; j < aField2.Len(); j++) + { + sal_Unicode c = aField2.GetChar(j); + // nur Ziffern und Dezimalpunkt und Tausender-Trennzeichen? + if ((!cDecimalDelimiter || c != cDecimalDelimiter) && + (!cThousandDelimiter || c != cThousandDelimiter) && + !aCharClass.isDigit(aField2,j)) + { + bNumeric = FALSE; + break; + } + if (cDecimalDelimiter && c == cDecimalDelimiter) + { + nPrecision = 15; // we have an decimal value + nScale = 2; + nDot++; + } + } + + if (nDot > 1) // if there is more than one dot it isn't a number + bNumeric = FALSE; + if (bNumeric && cThousandDelimiter) + { + // Ist der Trenner richtig angegeben? + String aValue = aField2.GetToken(0,cDecimalDelimiter); + for (sal_Int32 j = aValue.Len() - 4; j >= 0; j -= 4) + { + sal_Unicode c = aValue.GetChar(j); + // nur Ziffern und Dezimalpunkt und Tausender-Trennzeichen? + if (c == cThousandDelimiter && j) + continue; + else + { + bNumeric = FALSE; + break; + } + } + } + + // jetzt koennte es noch ein Datumsfeld sein + if (!bNumeric) + { + try + { + nIndex = m_xNumberFormatter->detectNumberFormat(::com::sun::star::util::NumberFormat::ALL,aField2); + } + catch(Exception&) + { + } + } + } + } + + sal_Int32 nFlags = 0; + if (bNumeric) + { + if (cDecimalDelimiter) + { + if(nPrecision) + { + eType = DataType::DECIMAL; + aTypeName = ::rtl::OUString::createFromAscii("DECIMAL"); + } + else + { + eType = DataType::DOUBLE; + aTypeName = ::rtl::OUString::createFromAscii("DOUBLE"); + } + } + else + eType = DataType::INTEGER; + nFlags = ColumnSearch::BASIC; + } + else + { + + switch (comphelper::getNumberFormatType(m_xNumberFormatter,nIndex)) + { + case NUMBERFORMAT_DATE: + eType = DataType::DATE; + aTypeName = ::rtl::OUString::createFromAscii("DATE"); + break; + case NUMBERFORMAT_DATETIME: + eType = DataType::TIMESTAMP; + aTypeName = ::rtl::OUString::createFromAscii("TIMESTAMP"); + break; + case NUMBERFORMAT_TIME: + eType = DataType::TIME; + aTypeName = ::rtl::OUString::createFromAscii("TIME"); + break; + default: + eType = DataType::VARCHAR; + nPrecision = 0; // nyi: Daten koennen aber laenger sein! + nScale = 0; + aTypeName = ::rtl::OUString::createFromAscii("VARCHAR"); + }; + nFlags |= ColumnSearch::CHAR; + } + + // check if the columname already exists + String aAlias(aColumnName); + OSQLColumns::Vector::const_iterator aFind = connectivity::find(m_aColumns->get().begin(),m_aColumns->get().end(),aAlias,aCase); + sal_Int32 nExprCnt = 0; + while(aFind != m_aColumns->get().end()) + { + (aAlias = aColumnName) += String::CreateFromInt32(++nExprCnt); + aFind = connectivity::find(m_aColumns->get().begin(),m_aColumns->get().end(),aAlias,aCase); + } + + m_aColumnRawNames.push_back(::rtl::OUString(aAlias)); + + //~ sdbcx::OColumn* pColumn = new sdbcx::OColumn(aAlias,aTypeName,::rtl::OUString(), + //~ ColumnValue::NULLABLE, + //~ nPrecision, + //~ nScale, + //~ eType, + //~ sal_False, + //~ sal_False, + //~ sal_False, + //~ bCase); + //~ Reference< XPropertySet> xCol = pColumn; + //~ m_aColumns->push_back(xCol); + m_aTypes.push_back(eType); + m_aPrecisions.push_back(nPrecision); + m_aScales.push_back(nScale); + } + setColumnAliases(); + m_pFileStream->Seek(STREAM_SEEK_TO_BEGIN); +} +// ------------------------------------------------------------------------- +OEvoabTable::OEvoabTable(sdbcx::OCollection* _pTables,OEvoabConnection* _pConnection) : OEvoabTable_BASE(_pTables,_pConnection) +{ + +} +// ------------------------------------------------------------------------- +OEvoabTable::OEvoabTable(sdbcx::OCollection* _pTables,OEvoabConnection* _pConnection, + const ::rtl::OUString& _Name, + const ::rtl::OUString& _Type, + const ::rtl::OUString& _Description , + const ::rtl::OUString& _SchemaName, + const ::rtl::OUString& _CatalogName + ) : OEvoabTable_BASE(_pTables,_pConnection,_Name, + _Type, + _Description, + _SchemaName, + _CatalogName) + ,m_nRowPos(0) + ,m_nMaxRowCount(0) +{ + //~ OSL_TRACE("OEvoabTable::(in constructor)_Name = %s\n", ((OUtoCStr(_Name)) ? (OUtoCStr(_Name)):("NULL")) ); + //~ OSL_TRACE("OEvoabTable::(in constructor)_Type = %s\n", ((OUtoCStr(_Type)) ? (OUtoCStr(_Type)):("NULL")) ); + //~ OSL_TRACE("OEvoabTable::(in constructor)_Description = %s\n", ((OUtoCStr(_Description)) ? (OUtoCStr(_Description)):("NULL")) ); + //~ OSL_TRACE("OEvoabTable::(in constructor)_SchemaName = %s\n", ((OUtoCStr(_SchemaName)) ? (OUtoCStr(_SchemaName)):("NULL")) ); + //~ OSL_TRACE("OEvoabTable::(in constructor)_CatalogName = %s\n", ((OUtoCStr(_CatalogName)) ? (OUtoCStr(_CatalogName)):("NULL")) ); +} +// ----------------------------------------------------------------------------- +void OEvoabTable::construct() +{ + SvtSysLocale aLocale; + ::com::sun::star::lang::Locale aAppLocale(aLocale.GetLocaleDataPtr()->getLocale()); + Sequence< ::com::sun::star::uno::Any > aArg(1); + aArg[0] <<= aAppLocale; + + Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier(m_pConnection->getDriver()->getFactory()->createInstanceWithArguments(::rtl::OUString::createFromAscii("com.sun.star.util.NumberFormatsSupplier"),aArg),UNO_QUERY); + m_xNumberFormatter = Reference< ::com::sun::star::util::XNumberFormatter >(m_pConnection->getDriver()->getFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.util.NumberFormatter")),UNO_QUERY); + m_xNumberFormatter->attachNumberFormatsSupplier(xSupplier); + + INetURLObject aURL; + aURL.SetURL(getEntry()); + + if(aURL.getExtension() != rtl::OUString(m_pConnection->getExtension())) + aURL.setExtension(m_pConnection->getExtension()); + + String aFileName = aURL.GetMainURL(INetURLObject::NO_DECODE); + + m_pFileStream = createStream_simpleError( aFileName,STREAM_READWRITE | STREAM_NOCREATE | STREAM_SHARE_DENYWRITE); + + if(!m_pFileStream) + m_pFileStream = createStream_simpleError( aFileName,STREAM_READ | STREAM_NOCREATE | STREAM_SHARE_DENYNONE); + + if(m_pFileStream) + { + OSL_TRACE("OEvoabTable::construct()::m_pFileStream created\n" ); + m_pFileStream->Seek(STREAM_SEEK_TO_END); + sal_Int32 nSize = m_pFileStream->Tell(); + m_pFileStream->Seek(STREAM_SEEK_TO_BEGIN); + + // Buffersize abhaengig von der Filegroesse + m_pFileStream->SetBufferSize(nSize > 1000000 ? 32768 : + nSize > 100000 ? 16384 : + nSize > 10000 ? 4096 : 1024); + OSL_TRACE("OEvoabTable::construct()::m_pFileStream->Tell() = %d\n", nSize ); + + fillColumns(aAppLocale); + + refreshColumns(); + } +} +// ------------------------------------------------------------------------- +String OEvoabTable::getEntry() +{ + ::rtl::OUString sURL; + try + { + Reference< XResultSet > xDir = m_pConnection->getDir()->getStaticResultSet(); + Reference< XRow> xRow(xDir,UNO_QUERY); + ::rtl::OUString sName; + ::rtl::OUString sExt; + + INetURLObject aURL; + xDir->beforeFirst(); + static const ::rtl::OUString s_sSeparator(RTL_CONSTASCII_USTRINGPARAM("/")); + while(xDir->next()) + { + sName = xRow->getString(1); + aURL.SetSmartProtocol(INET_PROT_FILE); + String sUrl = m_pConnection->getURL() + s_sSeparator + sName; + aURL.SetSmartURL( sUrl ); + + // cut the extension + sExt = aURL.getExtension(); + + // name and extension have to coincide + if ( m_pConnection->matchesExtension( sExt ) ) + { + sName = sName.replaceAt(sName.getLength()-(sExt.getLength()+1),sExt.getLength()+1,::rtl::OUString()); + if ( sName == m_Name ) + { + Reference< XContentAccess > xContentAccess( xDir, UNO_QUERY ); + sURL = xContentAccess->queryContentIdentifierString(); + break; + } + } + } + xDir->beforeFirst(); // move back to before first record + } + catch(Exception&) + { + OSL_ASSERT(0); + } + return sURL.getStr(); +} +// ------------------------------------------------------------------------- +void OEvoabTable::refreshColumns() +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + TStringVector aVector; + aVector.reserve(m_aColumns->get().size()); + + for(OSQLColumns::Vector::const_iterator aIter = m_aColumns->get().begin();aIter != m_aColumns->get().end();++aIter) + aVector.push_back(Reference< XNamed>(*aIter,UNO_QUERY)->getName()); + + if(m_pColumns) + m_pColumns->reFill(aVector); + else + m_pColumns = new OEvoabColumns(this,m_aMutex,aVector); + + OSL_TRACE("OEvoabTable::refreshColumns()::end\n" ); +} + +// ------------------------------------------------------------------------- +void SAL_CALL OEvoabTable::disposing(void) +{ + OFileTable::disposing(); + ::osl::MutexGuard aGuard(m_aMutex); + m_aColumns = NULL; +} +// ------------------------------------------------------------------------- +Sequence< Type > SAL_CALL OEvoabTable::getTypes( ) throw(RuntimeException) +{ + Sequence< Type > aTypes = OTable_TYPEDEF::getTypes(); + ::std::vector<Type> aOwnTypes; + aOwnTypes.reserve(aTypes.getLength()); + const Type* pBegin = aTypes.getConstArray(); + const Type* pEnd = pBegin + aTypes.getLength(); + for(;pBegin != pEnd;++pBegin) + { + if(!(*pBegin == ::getCppuType((const Reference<XKeysSupplier>*)0) || + *pBegin == ::getCppuType((const Reference<XRename>*)0) || + *pBegin == ::getCppuType((const Reference<XIndexesSupplier>*)0) || + *pBegin == ::getCppuType((const Reference<XAlterTable>*)0) || + *pBegin == ::getCppuType((const Reference<XDataDescriptorFactory>*)0))) + { + aOwnTypes.push_back(*pBegin); + } + } + Type *pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0]; + return Sequence< Type >(pTypes, aOwnTypes.size()); +} + +// ------------------------------------------------------------------------- +Any SAL_CALL OEvoabTable::queryInterface( const Type & rType ) throw(RuntimeException) +{ + if( rType == ::getCppuType((const Reference<XKeysSupplier>*)0) || + rType == ::getCppuType((const Reference<XIndexesSupplier>*)0) || + rType == ::getCppuType((const Reference<XRename>*)0) || + rType == ::getCppuType((const Reference<XAlterTable>*)0) || + rType == ::getCppuType((const Reference<XDataDescriptorFactory>*)0)) + return Any(); + + Any aRet = OTable_TYPEDEF::queryInterface(rType); + return aRet.hasValue() ? aRet : ::cppu::queryInterface(rType,static_cast< ::com::sun::star::lang::XUnoTunnel*> (this)); +} + +//-------------------------------------------------------------------------- +Sequence< sal_Int8 > OEvoabTable::getUnoTunnelImplementationId() +{ + static ::cppu::OImplementationId * pId = 0; + if (! pId) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if (! pId) + { + static ::cppu::OImplementationId aId; + pId = &aId; + } + } + return pId->getImplementationId(); +} + +// com::sun::star::lang::XUnoTunnel +//------------------------------------------------------------------ +sal_Int64 OEvoabTable::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException) +{ + return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) + ? reinterpret_cast< sal_Int64 >( this ) + : OEvoabTable_BASE::getSomething(rId); +} +//------------------------------------------------------------------ +sal_Bool OEvoabTable::fetchRow(OValueRefRow& _rRow,const OSQLColumns & _rCols,sal_Bool bIsTable,sal_Bool bRetrieveData) +{ + *(_rRow->get())[0] = m_nFilePos; + + if (!bRetrieveData) + return TRUE; + + OEvoabConnection* pConnection = (OEvoabConnection*)m_pConnection; + // Felder: + xub_StrLen nStartPos = 0; + String aStr; + OSQLColumns::Vector::const_iterator aIter = _rCols.get().begin(); + for (sal_Int32 i = 0; aIter != _rCols.get().end();++aIter, ++i) + { + m_aCurrentLine.GetTokenSpecial(aStr,nStartPos,pConnection->getFieldDelimiter(),pConnection->getStringDelimiter()); + //OSL_TRACE("OEvoabTable::fetchRow()::aStr = %s\n", ((OUtoCStr(::rtl::OUString(aStr))) ? (OUtoCStr(::rtl::OUString(aStr))):("NULL")) ); + + if (aStr.Len() == 0) + (_rRow->get())[i+1]->setNull(); + else + { + // Laengen je nach Datentyp: + sal_Int32 nLen, + nType = 0; + if(bIsTable) + { + nLen = m_aPrecisions[i]; + nType = m_aTypes[i]; + } + else + { + Reference< XPropertySet> xColumn = *aIter; + xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)) >>= nLen; + xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)) >>= nType; + } + switch(nType) + { + case DataType::TIMESTAMP: + case DataType::DATE: + case DataType::TIME: + { + double nRes = 0.0; + try + { + nRes = m_xNumberFormatter->convertStringToNumber(::com::sun::star::util::NumberFormat::ALL,aStr); + Reference<XPropertySet> xProp(m_xNumberFormatter->getNumberFormatsSupplier()->getNumberFormatSettings(),UNO_QUERY); + com::sun::star::util::Date aDate; + xProp->getPropertyValue(::rtl::OUString::createFromAscii("NullDate")) >>= aDate; + + switch(nType) + { + case DataType::DATE: + *(_rRow->get())[i+1] = ::dbtools::DBTypeConversion::toDouble(::dbtools::DBTypeConversion::toDate(nRes,aDate)); + break; + case DataType::TIMESTAMP: + *(_rRow->get())[i+1] = ::dbtools::DBTypeConversion::toDouble(::dbtools::DBTypeConversion::toDateTime(nRes,aDate)); + break; + default: + *(_rRow->get())[i+1] = ::dbtools::DBTypeConversion::toDouble(::dbtools::DBTypeConversion::toTime(nRes)); + } + } + catch(Exception&) + { + (_rRow->get())[i+1]->setNull(); + } + } break; + case DataType::DOUBLE: + case DataType::INTEGER: + case DataType::DECIMAL: // #99178# OJ + case DataType::NUMERIC: + { + sal_Unicode cDecimalDelimiter = pConnection->getDecimalDelimiter(); + sal_Unicode cThousandDelimiter = pConnection->getThousandDelimiter(); + String aStrConverted; + + OSL_ENSURE(cDecimalDelimiter && nType != DataType::INTEGER || + !cDecimalDelimiter && nType == DataType::INTEGER, + "FalscherTyp"); + + // In Standard-Notation (DezimalPUNKT ohne Tausender-Komma) umwandeln: + for (xub_StrLen j = 0; j < aStr.Len(); ++j) + { + if (cDecimalDelimiter && aStr.GetChar(j) == cDecimalDelimiter) + aStrConverted += '.'; + else if ( aStr.GetChar(j) == '.' ) // special case, if decimal seperator isn't '.' we have to vut the string after it + break; // #99189# OJ + else if (cThousandDelimiter && aStr.GetChar(j) == cThousandDelimiter) + { + // weglassen + } + else + aStrConverted += aStr.GetChar(j) ; + } + double nVal = ::rtl::math::stringToDouble(aStrConverted.GetBuffer(),',','.',NULL,NULL); + + // #99178# OJ + if ( DataType::DECIMAL == nType || DataType::NUMERIC == nType ) + *(_rRow->get())[i+1] = ORowSetValue(String::CreateFromDouble(nVal)); + else + *(_rRow->get())[i+1] = nVal; + } break; + + default: + { + // Wert als String in Variable der Row uebernehmen + *(_rRow->get())[i+1] = ORowSetValue(aStr); + } + break; + } + } + } + return sal_True; +} +// ----------------------------------------------------------------------------- +sal_Bool OEvoabTable::setColumnAliases() +{ + + size_t nSize = m_aColumnRawNames.size(); + if(nSize == 0 || m_aPrecisions.size() != nSize || m_aScales.size() != nSize || m_aTypes.size() != nSize) + return sal_False; + m_aColumns->get().clear(); + m_aColumns->get().reserve(nSize); + ::rtl::OUString aColumnReadName; + ::rtl::OUString aColumnHeadlineName; + ::rtl::OUString aColumnDisplayName; + ::rtl::OUString aColumnFinalName; + String sColumnFinalName; + + const TStringVector& colAliasNames = ((OEvoabConnection*)m_pConnection)->getColumnAlias().getAlias(); + const ::std::map< ::rtl::OUString, ::rtl::OUString > & colMap = ((OEvoabConnection*)m_pConnection)->getColumnAlias().getAliasMap(); + ::osl::MutexGuard aGuard( m_aMutex ); + + for(size_t i = 0;i < nSize; ++i) + { + aColumnReadName = m_aColumnRawNames[i]; + //OSL_TRACE("OEvoabTable::getColumnRows()::aColumnReadName = %s\n", ((OUtoCStr(aColumnReadName)) ? (OUtoCStr(aColumnReadName)):("NULL")) ); + sal_Bool bFound = sal_False; + for ( size_t j = 0; j < colAliasNames.size(); ++j ) + { + aColumnDisplayName = colAliasNames[j]; + + ::std::map< ::rtl::OUString, ::rtl::OUString >::const_iterator aPos = colMap.find( aColumnDisplayName ); + if ( colMap.end() != aPos ) + { + aColumnHeadlineName = aPos->second; + EVO_TRACE_STRING( "OEvoabTable::getColumnRows()::aColumnDisplayName = %s\n", aColumnDisplayName ); + EVO_TRACE_STRING( "OEvoabTable::getColumnRows()::aColumnHeadlineName= %s\n", aColumnHeadlineName ); + if(aColumnReadName == aColumnHeadlineName) + { + //OSL_TRACE("OEvoabTable::getColumnRows()::aColumnHeadlineName = %s\n", ((OUtoCStr(aColumnHeadlineName)) ? (OUtoCStr(aColumnHeadlineName)):("NULL")) ); + //OSL_TRACE("OEvoabTable::getColumnRows()::aColumnDisplayName = %s\n", ((OUtoCStr(aColumnDisplayName)) ? (OUtoCStr(aColumnDisplayName)):("NULL")) ); + aColumnFinalName = aColumnDisplayName; + bFound = sal_True; + //OSL_TRACE("OEvoabTable::getColumnRows()::j = %d\n", j ); + + break; + } + } + else + OSL_ENSURE( sal_False, "OEvoabTable::setColumnAliases: did not find one of the aliases!" ); + } + if(!bFound) + aColumnFinalName = aColumnReadName; + sColumnFinalName = aColumnFinalName; + + sal_Bool bCase = getConnection()->getMetaData()->storesMixedCaseQuotedIdentifiers(); + ::rtl::OUString aTypeName; + aTypeName = ::rtl::OUString::createFromAscii("VARCHAR"); + sdbcx::OColumn* pColumn = new sdbcx::OColumn(sColumnFinalName,aTypeName,::rtl::OUString(), + ColumnValue::NULLABLE, + m_aPrecisions[i], + m_aScales[i], + m_aTypes[i], + sal_False, + sal_False, + sal_False, + bCase); + Reference< XPropertySet> xCol = pColumn; + m_aColumns->get().push_back(xCol); + } + return sal_True; +} +// ----------------------------------------------------------------------------- +void OEvoabTable::refreshIndexes() +{ +} +// ----------------------------------------------------------------------------- +sal_Bool OEvoabTable::checkHeaderLine() +{ + if (m_nFilePos == 0 && ((OEvoabConnection*)m_pConnection)->isHeaderLine()) + { + BOOL bRead2; + do + { + bRead2 = m_pFileStream->ReadByteStringLine(m_aCurrentLine,m_pConnection->getTextEncoding()); + } + while(bRead2 && !m_aCurrentLine.Len()); + + m_nFilePos = m_pFileStream->Tell(); + if (m_pFileStream->IsEof()) + return sal_False; + } + return sal_True; +} +//------------------------------------------------------------------ +sal_Bool OEvoabTable::seekRow(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOffset, sal_Int32& nCurPos) +{ + //OSL_TRACE("OEvoabTable::(before SeekRow)m_aCurrentLine = %d\n", ((OUtoCStr(::rtl::OUString(m_aCurrentLine))) ? (OUtoCStr(::rtl::OUString(m_aCurrentLine))):("NULL")) ); + + if ( !m_pFileStream ) + return sal_False; + OEvoabConnection* pConnection = (OEvoabConnection*)m_pConnection; + // ---------------------------------------------------------- + // Positionierung vorbereiten: + //OSL_TRACE("OEvoabTable::(before SeekRow,m_pFileStriam Exist)m_aCurrentLine = %d\n", ((OUtoCStr(::rtl::OUString(m_aCurrentLine))) ? (OUtoCStr(::rtl::OUString(m_aCurrentLine))):("NULL")) ); + + m_nFilePos = nCurPos; + + switch(eCursorPosition) + { + case IResultSetHelper::FIRST: + m_nFilePos = 0; + m_nRowPos = 1; + // run through + case IResultSetHelper::NEXT: + if(eCursorPosition != IResultSetHelper::FIRST) + ++m_nRowPos; + m_pFileStream->Seek(m_nFilePos); + if (m_pFileStream->IsEof() || !checkHeaderLine()) + { + m_nMaxRowCount = m_nRowPos; + return sal_False; + } + + m_aRowToFilePos.insert(::std::map<sal_Int32,sal_Int32>::value_type(m_nRowPos,m_nFilePos)); + + m_pFileStream->ReadByteStringLine(m_aCurrentLine,pConnection->getTextEncoding()); + if (m_pFileStream->IsEof()) + { + m_nMaxRowCount = m_nRowPos; + return sal_False; + } + nCurPos = m_pFileStream->Tell(); + break; + case IResultSetHelper::PRIOR: + --m_nRowPos; + if(m_nRowPos > 0) + { + m_nFilePos = m_aRowToFilePos.find(m_nRowPos)->second; + m_pFileStream->Seek(m_nFilePos); + if (m_pFileStream->IsEof() || !checkHeaderLine()) + return sal_False; + m_pFileStream->ReadByteStringLine(m_aCurrentLine,pConnection->getTextEncoding()); + if (m_pFileStream->IsEof()) + return sal_False; + nCurPos = m_pFileStream->Tell(); + } + else + m_nRowPos = 0; + + break; + case IResultSetHelper::LAST: + if(m_nMaxRowCount) + { + m_nFilePos = m_aRowToFilePos.rbegin()->second; + m_nRowPos = m_aRowToFilePos.rbegin()->first; + m_pFileStream->Seek(m_nFilePos); + if (m_pFileStream->IsEof() || !checkHeaderLine()) + return sal_False; + m_pFileStream->ReadByteStringLine(m_aCurrentLine,pConnection->getTextEncoding()); + if (m_pFileStream->IsEof()) + return sal_False; + nCurPos = m_pFileStream->Tell(); + } + else + { + while(seekRow(IResultSetHelper::NEXT,1,nCurPos)) ; // run through after last row + // now I know all + seekRow(IResultSetHelper::PRIOR,1,nCurPos); + } + break; + case IResultSetHelper::RELATIVE: + if(nOffset > 0) + { + for(sal_Int32 i = 0;i<nOffset;++i) + seekRow(IResultSetHelper::NEXT,1,nCurPos); + } + else if(nOffset < 0) + { + for(sal_Int32 i = nOffset;i;++i) + seekRow(IResultSetHelper::PRIOR,1,nCurPos); + } + break; + case IResultSetHelper::ABSOLUTE: + { + if(nOffset < 0) + nOffset = m_nRowPos + nOffset; + ::std::map<sal_Int32,sal_Int32>::const_iterator aIter = m_aRowToFilePos.find(nOffset); + if(aIter != m_aRowToFilePos.end()) + { + m_nFilePos = aIter->second; + m_pFileStream->Seek(m_nFilePos); + if (m_pFileStream->IsEof() || !checkHeaderLine()) + return sal_False; + m_pFileStream->ReadByteStringLine(m_aCurrentLine,pConnection->getTextEncoding()); + if (m_pFileStream->IsEof()) + return sal_False; + nCurPos = m_pFileStream->Tell(); + } + else if(m_nMaxRowCount && nOffset > m_nMaxRowCount) // offset is outside the table + { + m_nRowPos = m_nMaxRowCount; + return sal_False; + } + else + { + aIter = m_aRowToFilePos.upper_bound(nOffset); + if(aIter == m_aRowToFilePos.end()) + { + m_nRowPos = m_aRowToFilePos.rbegin()->first; + nCurPos = m_nFilePos = m_aRowToFilePos.rbegin()->second; + while(m_nRowPos != nOffset) + seekRow(IResultSetHelper::NEXT,1,nCurPos); + } + else + { + --aIter; + m_nRowPos = aIter->first; + m_nFilePos = aIter->second; + m_pFileStream->Seek(m_nFilePos); + if (m_pFileStream->IsEof() || !checkHeaderLine()) + return sal_False; + m_pFileStream->ReadByteStringLine(m_aCurrentLine,pConnection->getTextEncoding()); + if (m_pFileStream->IsEof()) + return sal_False; + nCurPos = m_pFileStream->Tell(); + } + } + } + + break; + case IResultSetHelper::BOOKMARK: + m_pFileStream->Seek(nOffset); + if (m_pFileStream->IsEof()) + return sal_False; + + m_nFilePos = m_pFileStream->Tell(); // Byte-Position in der Datei merken (am ZeilenANFANG) + m_pFileStream->ReadByteStringLine(m_aCurrentLine,pConnection->getTextEncoding()); + if (m_pFileStream->IsEof()) + return sal_False; + nCurPos = m_pFileStream->Tell(); + break; + } + + //OSL_TRACE("OEvoabTable::(after SeekRow)m_aCurrentLine = %d\n", ((OUtoCStr(::rtl::OUString(m_aCurrentLine))) ? (OUtoCStr(::rtl::OUString(m_aCurrentLine))):("NULL")) ); + + return sal_True; +} +// ----------------------------------------------------------------------------- diff --git a/connectivity/source/drivers/evoab/LTable.hxx b/connectivity/source/drivers/evoab/LTable.hxx new file mode 100644 index 000000000000..360e4487cf09 --- /dev/null +++ b/connectivity/source/drivers/evoab/LTable.hxx @@ -0,0 +1,103 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LTable.hxx,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_EVOAB_LTABLE_HXX_ +#define _CONNECTIVITY_EVOAB_LTABLE_HXX_ + +#include "file/FTable.hxx" +#include "connectivity/sdbcx/VColumn.hxx" +#include "connectivity/CommonTools.hxx" +#include <tools/urlobj.hxx> +#include "file/quotedstring.hxx" +#include <vector> + +namespace connectivity +{ + namespace evoab + { + typedef file::OFileTable OEvoabTable_BASE; + class OEvoabConnection; + + typedef ::std::map< ::rtl::OUString, + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNamed>, comphelper::UStringMixLess > OContainer; + + class OEvoabTable : public OEvoabTable_BASE + { + private: + // maps a row postion to a file position + ::std::map<sal_Int32,sal_Int32> m_aRowToFilePos; + ::std::vector<sal_Int32> m_aTypes; // holds all type for columns just to avoid to ask the propertyset + ::std::vector<sal_Int32> m_aPrecisions; // same as aboth + ::std::vector<sal_Int32> m_aScales; + QuotedTokenizedString m_aCurrentLine; + ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > m_xNumberFormatter; + sal_Int32 m_nRowPos; + sal_Int32 m_nMaxRowCount; // will be set if stream is once eof + ::std::vector< ::rtl::OUString> m_aColumnRawNames; + sal_Bool setColumnAliases(); + void fillColumns(const ::com::sun::star::lang::Locale& _aLocale); + sal_Bool checkHeaderLine(); + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet> isUniqueByColumnName(const ::rtl::OUString& _rColName); + + public: + virtual void refreshColumns(); + virtual void refreshIndexes(); + + public: + // DECLARE_CTY_DEFAULTS( OFlatTable_BASE); + OEvoabTable( sdbcx::OCollection* _pTables,OEvoabConnection* _pConnection); + OEvoabTable( sdbcx::OCollection* _pTables,OEvoabConnection* _pConnection, + const ::rtl::OUString& _Name, + const ::rtl::OUString& _Type, + const ::rtl::OUString& _Description = ::rtl::OUString(), + const ::rtl::OUString& _SchemaName = ::rtl::OUString(), + const ::rtl::OUString& _CatalogName = ::rtl::OUString() + ); + + void construct(); // can throw any exception + + virtual sal_Bool seekRow(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOffset, sal_Int32& nCurPos); + virtual sal_Bool fetchRow(OValueRefRow& _rRow,const OSQLColumns& _rCols, sal_Bool bIsTable,sal_Bool bRetrieveData); + + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); + //XTypeProvider + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL disposing(void); + + // com::sun::star::lang::XUnoTunnel + virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException); + static ::com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId(); + + String getEntry(); + }; + } +} +#endif // _CONNECTIVITY_EVOAB_LTABLE_HXX_ + diff --git a/connectivity/source/drivers/evoab/LTables.cxx b/connectivity/source/drivers/evoab/LTables.cxx new file mode 100644 index 000000000000..7465c890f240 --- /dev/null +++ b/connectivity/source/drivers/evoab/LTables.cxx @@ -0,0 +1,65 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LTables.cxx,v $ + * $Revision: 1.6 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "LTables.hxx" +#include "LTable.hxx" +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/sdbc/XResultSet.hpp> +#include <com/sun/star/sdbc/ColumnValue.hpp> +#include <com/sun/star/sdbc/KeyRule.hpp> +#include <com/sun/star/sdbcx/KeyType.hpp> +#include "file/FCatalog.hxx" +#include "file/FConnection.hxx" +#include <comphelper/types.hxx> + +using namespace connectivity; +using namespace ::comphelper; +using namespace connectivity::evoab; +using namespace connectivity::file; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::sdbcx; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::container; +namespace starutil = ::com::sun::star::util; + +sdbcx::ObjectType OEvoabTables::createObject(const ::rtl::OUString& _rName) +{ + OEvoabTable* pRet = new OEvoabTable(this,(OEvoabConnection*)static_cast<OFileCatalog&>(m_rParent).getConnection(), + _rName,::rtl::OUString::createFromAscii("TABLE")); + sdbcx::ObjectType xRet = pRet; + pRet->construct(); + return xRet; +} +// ------------------------------------------------------------------------- + diff --git a/connectivity/source/drivers/evoab/LTables.hxx b/connectivity/source/drivers/evoab/LTables.hxx new file mode 100644 index 000000000000..3fcaaa7d8e58 --- /dev/null +++ b/connectivity/source/drivers/evoab/LTables.hxx @@ -0,0 +1,55 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: LTables.hxx,v $ + * $Revision: 1.5 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_EVOAB_LTABLES_HXX_ +#define _CONNECTIVITY_EVOAB_LTABLES_HXX_ + +#include "file/FTables.hxx" + +namespace connectivity +{ + namespace evoab + { + // namespace ::com::sun::star::sdbcx = ::com::sun::star::sdbcx; + typedef file::OTables OEvoabTables_BASE; + + class OEvoabTables : public OEvoabTables_BASE + { + protected: + virtual sdbcx::ObjectType createObject(const ::rtl::OUString& _rName); + public: + OEvoabTables(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >& _rMetaData,::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, + const TStringVector &_rVector) : OEvoabTables_BASE(_rMetaData,_rParent,_rMutex,_rVector) + {} + }; + } +} +#endif // _CONNECTIVITY_EVOAB_LTABLES_HXX_ + diff --git a/connectivity/source/drivers/evoab/evoab.map b/connectivity/source/drivers/evoab/evoab.map new file mode 100644 index 000000000000..00cf7191f143 --- /dev/null +++ b/connectivity/source/drivers/evoab/evoab.map @@ -0,0 +1,8 @@ +EVOAB_1_0 { + global: + component_getImplementationEnvironment; + component_writeInfo; + component_getFactory; + local: + *; +}; diff --git a/connectivity/source/drivers/evoab/evoab.xcu b/connectivity/source/drivers/evoab/evoab.xcu new file mode 100755 index 000000000000..4c5c4894e0ab --- /dev/null +++ b/connectivity/source/drivers/evoab/evoab.xcu @@ -0,0 +1,64 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!--*********************************************************************** + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: DataAccess.xcu,v $ + * $Revision: 1.27 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************ --> +<oor:component-data oor:name="Drivers" oor:package="org.openoffice.Office.DataAccess" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema"> + <node oor:name="Installed"> + <node oor:name="sdbc:address:evolution:ldap" oor:op="replace"> + <prop oor:name="Driver"> + <value>com.sun.star.comp.sdbc.evoab.OEvoabDriver</value> + </prop> + <prop oor:name="DriverTypeDisplayName" oor:type="xs:string"> + <value xml:lang="en-US">Evolution LDAP</value> + </prop> + <node oor:name="Features"> + <node oor:name="EscapeDateTime" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + </node> + </node> + <node oor:name="sdbc:address:evolution:groupwise" oor:op="replace"> + <prop oor:name="Driver"> + <value>com.sun.star.comp.sdbc.evoab.OEvoabDriver</value> + </prop> + <prop oor:name="DriverTypeDisplayName" oor:type="xs:string"> + <value xml:lang="en-US">Groupwise</value> + </prop> + <node oor:name="Features"> + <node oor:name="EscapeDateTime" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + </node> + </node> + </node> +</oor:component-data> diff --git a/connectivity/source/drivers/evoab/evoab.xml b/connectivity/source/drivers/evoab/evoab.xml new file mode 100644 index 000000000000..8ed16719ae0e --- /dev/null +++ b/connectivity/source/drivers/evoab/evoab.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE module-description PUBLIC "-//W3C//DTD HTML 3.2//EN" "module-description.dtd"> +<module-description> + <module-name>file</module-name> + <component-description> + <author>Xibei(Berry) Jia</author> + <name>com.sun.star.comp.sdbc.evoab.OEvoabDriver</name> + <description>This library implements the database driver for evolution address book formats. +</description> + <loader-name>com.sun.star.loader.SharedLibrary</loader-name> + <language>c++</language> + <status value="final"/> + <supported-service>com.sun.star.sdbc.Driver</supported-service> + <supported-service>com.sun.star.sdbcx.Driver</supported-service> + <service-dependency> ... </service-dependency> + </component-description> + <project-build-dependency>cppuhelper</project-build-dependency> + <project-build-dependency>cppu</project-build-dependency> + <project-build-dependency>sal</project-build-dependency> + <project-build-dependency>vos</project-build-dependency> + <runtime-module-dependency>file</runtime-module-dependency> + <runtime-module-dependency>cppuhelper</runtime-module-dependency> + <runtime-module-dependency>cppu</runtime-module-dependency> + <runtime-module-dependency>sal</runtime-module-dependency> + <runtime-module-dependency>vos</runtime-module-dependency> + <runtime-module-dependency>osl</runtime-module-dependency> + <runtime-module-dependency>svtools-light1</runtime-module-dependency> + <runtime-module-dependency>svtools</runtime-module-dependency> + <runtime-module-dependency>ucbhelper</runtime-module-dependency> + <runtime-module-dependency>dbtools</runtime-module-dependency> + <runtime-module-dependency>unotools</runtime-module-dependency> + <runtime-module-dependency>comphelper</runtime-module-dependency> +</module-description> diff --git a/connectivity/source/drivers/evoab/exports.dxp b/connectivity/source/drivers/evoab/exports.dxp new file mode 100644 index 000000000000..9630d7e06768 --- /dev/null +++ b/connectivity/source/drivers/evoab/exports.dxp @@ -0,0 +1,3 @@ +component_getImplementationEnvironment +component_writeInfo +component_getFactory diff --git a/connectivity/source/drivers/evoab/makefile.mk b/connectivity/source/drivers/evoab/makefile.mk new file mode 100644 index 000000000000..8982322513de --- /dev/null +++ b/connectivity/source/drivers/evoab/makefile.mk @@ -0,0 +1,108 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.9 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. +PRJINC=..$/.. +PRJNAME=connectivity +TARGET=evoab + +VISIBILITY_HIDDEN=TRUE + +# --- Settings ---------------------------------- +.IF "$(DBGUTIL_OJ)"!="" +ENVCFLAGS+=/FR$(SLO)$/ +.ENDIF + +.INCLUDE : $(PRJ)$/version.mk +.INCLUDE : $(PRJ)$/makefile.pmk + +.IF "$(GUI)"=="UNX" + +# --- Files ------------------------------------- + +EXCEPTIONSFILES=\ + $(SLO)$/LResultSet.obj \ + $(SLO)$/LStatement.obj \ + $(SLO)$/LPreparedStatement.obj \ + $(SLO)$/LFolderList.obj \ + $(SLO)$/LConfigAccess.obj \ + $(SLO)$/LColumnAlias.obj \ + $(SLO)$/LTable.obj \ + $(SLO)$/LDatabaseMetaData.obj \ + $(SLO)$/LCatalog.obj \ + $(SLO)$/LColumns.obj \ + $(SLO)$/LTables.obj \ + $(SLO)$/LConnection.obj \ + $(SLO)$/LServices.obj \ + $(SLO)$/LDriver.obj + +SLOFILES=\ + $(EXCEPTIONSFILES) \ + $(SLO)$/LDebug.obj + + +SHL1VERSIONMAP=$(TARGET).map + + +# --- Library ----------------------------------- +#SHL1TARGET=$(TARGET)$(DLLPOSTFIX) +SHL1TARGET= $(EVOAB_TARGET)$(DLLPOSTFIX) +SHL1OBJS=$(SLOFILES) +SHL1STDLIBS=\ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(VOSLIB) \ + $(TOOLSLIB) \ + $(SVTOOLLIB) \ + $(UNOTOOLSLIB) \ + $(UCBHELPERLIB) \ + $(SALLIB) \ + $(DBTOOLSLIB) \ + $(DBFILELIB) \ + $(COMPHELPERLIB) + +.IF "$(DBFILELIB)" == "" +SHL1STDLIBS+= ifile.lib +.ENDIF + +SHL1DEPN= +SHL1IMPLIB= i$(TARGET) + +SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME= $(SHL1TARGET) + +.ELSE +dummy: + @echo "Nothing to build for GUI $(GUI)" +.ENDIF +# --- Targets ---------------------------------- +.INCLUDE : $(PRJ)$/target.pmk |