diff options
Diffstat (limited to 'connectivity/source/drivers')
123 files changed, 47301 insertions, 0 deletions
diff --git a/connectivity/source/drivers/adabas/BCatalog.cxx b/connectivity/source/drivers/adabas/BCatalog.cxx new file mode 100644 index 000000000000..b9c73fdc4aa3 --- /dev/null +++ b/connectivity/source/drivers/adabas/BCatalog.cxx @@ -0,0 +1,195 @@ +/************************************************************************* + * + * $RCSfile: BCatalog.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:19 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADABAS_CATALOG_HXX_ +#include "adabas/BCatalog.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_BCONNECTION_HXX_ +#include "adabas/BConnection.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_GROUPS_HXX_ +#include "adabas/BGroups.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_USERS_HXX_ +#include "adabas/BUsers.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_TABLES_HXX_ +#include "adabas/BTables.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif + + +// ------------------------------------------------------------------------- +using namespace connectivity::adabas; +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; +// ------------------------------------------------------------------------- +OAdabasCatalog::OAdabasCatalog(SQLHANDLE _aConnectionHdl, OAdabasConnection* _pCon) : connectivity::sdbcx::OCatalog(_pCon) + ,m_pConnection(_pCon) + ,m_aConnectionHdl(_aConnectionHdl) + ,m_xMetaData(m_pConnection->getMetaData( )) +{ + osl_incrementInterlockedCount( &m_refCount ); + refreshTables(); + refreshViews(); + refreshGroups(); + refreshUsers(); + osl_decrementInterlockedCount( &m_refCount ); +} +// ------------------------------------------------------------------------- +void OAdabasCatalog::refreshTables() +{ + ::std::vector< ::rtl::OUString> aVector; + Sequence< ::rtl::OUString > aTypes(1); + aTypes[0] = ::rtl::OUString::createFromAscii("%"); + Reference< XResultSet > xResult = m_xMetaData->getTables(Any(), + ::rtl::OUString::createFromAscii("%"),::rtl::OUString::createFromAscii("%"),aTypes); + + if(xResult.is()) + { + Reference< XRow > xRow(xResult,UNO_QUERY); + ::rtl::OUString aName,aDot = ::rtl::OUString::createFromAscii("."),aView = ::rtl::OUString::createFromAscii("VIEW"); + while(xResult->next()) + { + if(xRow->getString(4) != aView) + { + aName = xRow->getString(2); + aName += aDot; + aName += xRow->getString(3); + aVector.push_back(aName); + } + } + } + if(m_pTables) + delete m_pTables; + m_pTables = new OTables(m_xMetaData,*this,m_aMutex,aVector); +} +// ------------------------------------------------------------------------- +void OAdabasCatalog::refreshViews() +{ + ::std::vector< ::rtl::OUString> aVector; + Sequence< ::rtl::OUString > aTypes(1); + aTypes[0] = ::rtl::OUString::createFromAscii("VIEW"); + Reference< XResultSet > xResult = m_xMetaData->getTables(Any(), + ::rtl::OUString::createFromAscii("%"),::rtl::OUString::createFromAscii("%"),aTypes); + + if(xResult.is()) + { + Reference< XRow > xRow(xResult,UNO_QUERY); + ::rtl::OUString aName,aDot = ::rtl::OUString::createFromAscii("."); + while(xResult->next()) + { + aName = xRow->getString(2); + aName += aDot; + aName += xRow->getString(3); + aVector.push_back(aName); + } + } + if(m_pViews) + delete m_pViews; + m_pViews = new OTables(m_xMetaData,*this,m_aMutex,aVector); +} +// ------------------------------------------------------------------------- +void OAdabasCatalog::refreshGroups() +{ + ::std::vector< ::rtl::OUString> aVector; + Reference< XStatement > xStmt = m_pConnection->createStatement( ); + Reference< XResultSet > xResult = xStmt->executeQuery( + ::rtl::OUString::createFromAscii("SELECT DISTINCT GROUPNAME FROM DOMAIN.USERS WHERE GROUPNAME IS NOT NULL AND GROUPNAME <> ' '")); + if(xResult.is()) + { + Reference< XRow > xRow(xResult,UNO_QUERY); + while(xResult->next()) + aVector.push_back(xRow->getString(1)); + } + if(m_pGroups) + delete m_pGroups; + m_pGroups = new OGroups(*this,m_aMutex,aVector,m_pConnection,this); +} +// ------------------------------------------------------------------------- +void OAdabasCatalog::refreshUsers() +{ + ::std::vector< ::rtl::OUString> aVector; + Reference< XStatement > xStmt = m_pConnection->createStatement( ); + Reference< XResultSet > xResult = xStmt->executeQuery( + ::rtl::OUString::createFromAscii("SELECT DISTINCT USERNAME FROM DOMAIN.USERS WHERE USERNAME IS NOT NULL AND USERNAME <> ' ' AND USERNAME <> 'CONTROL'")); + if(xResult.is()) + { + Reference< XRow > xRow(xResult,UNO_QUERY); + while(xResult->next()) + aVector.push_back(xRow->getString(1)); + } + if(m_pUsers) + delete m_pUsers; + m_pUsers = new OUsers(*this,m_aMutex,aVector,m_pConnection,this); +} +// ------------------------------------------------------------------------- + + diff --git a/connectivity/source/drivers/adabas/BColumns.cxx b/connectivity/source/drivers/adabas/BColumns.cxx new file mode 100644 index 000000000000..cfebf615d6f2 --- /dev/null +++ b/connectivity/source/drivers/adabas/BColumns.cxx @@ -0,0 +1,241 @@ +/************************************************************************* + * + * $RCSfile: BColumns.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:19 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADABAS_COLUMNS_HXX_ +#include "adabas/BColumns.hxx" +#endif +#ifndef _CONNECTIVITY_SDBCX_COLUMN_HXX_ +#include "connectivity/sdbcx/VColumn.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ +#include <com/sun/star/sdbc/ColumnValue.hpp> +#endif +#ifndef _CONNECTIVITY_ADABAS_TABLE_HXX_ +#include "adabas/BTable.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +using namespace connectivity::adabas; +using namespace connectivity::sdbcx; +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; +using namespace ::com::sun::star::lang; +typedef connectivity::sdbcx::OCollection OCollection_TYPE; + +Reference< XNamed > OColumns::createObject(const ::rtl::OUString& _rName) +{ + + Reference< XResultSet > xResult = m_pTable->getConnection()->getMetaData()->getColumns(Any(), + m_pTable->getSchema(),m_pTable->getName(),_rName); + + Reference< XNamed > xRet = NULL; + if(xResult.is()) + { + Reference< XRow > xRow(xResult,UNO_QUERY); + while(xResult->next()) + { + if(xRow->getString(4) == _rName) + { + OColumn* pRet = new OColumn(_rName, + xRow->getString(6), + xRow->getString(13), + xRow->getInt(11), + xRow->getInt(7), + xRow->getInt(9), + xRow->getInt(5), + sal_False,sal_False,sal_False,sal_True); + xRet = pRet; + break; + } + } + } + + return xRet; +} + +// ------------------------------------------------------------------------- +void OColumns::impl_refresh() throw(RuntimeException) +{ + m_pTable->refreshColumns(); +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > OColumns::createEmptyObject() +{ + OColumn* pNew = new OColumn(sal_True); + Reference< XPropertySet > xRet = pNew; + return xRet; +} +// ------------------------------------------------------------------------- +// XAppend +void SAL_CALL OColumns::appendByDescriptor( const Reference< XPropertySet >& descriptor ) throw(SQLException, ElementExistException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + if(!m_pTable->isNew()) + { + ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("ALTER TABLE "); + ::rtl::OUString aQuote = m_pTable->getConnection()->getMetaData()->getIdentifierQuoteString( ); + ::rtl::OUString aDot = ::rtl::OUString::createFromAscii("."); + + aSql = aSql + aQuote + m_pTable->getSchema() + aQuote + aDot + aQuote + m_pTable->getName() + aQuote; + aSql = aSql + ::rtl::OUString::createFromAscii(" ADD "); + aSql = aSql + aQuote + getString(descriptor->getPropertyValue(PROPERTY_NAME)) + aQuote; + aSql = aSql + ::rtl::OUString::createFromAscii(" "); + + Any aTypeName = descriptor->getPropertyValue(PROPERTY_TYPENAME); + if(aTypeName.hasValue() && getString(aTypeName).getLength()) + aSql = aSql + getString(aTypeName); + else + aSql = aSql + getTypeString(descriptor) + ::rtl::OUString::createFromAscii(" "); + + // aSql = aSql + getString(descriptor->getPropertyValue(PROPERTY_TYPENAME)); + + switch(getINT32(descriptor->getPropertyValue(PROPERTY_TYPE))) + { + case DataType::CHAR: + case DataType::VARCHAR: + aSql = aSql + ::rtl::OUString::createFromAscii("(") + + ::rtl::OUString::valueOf(getINT32(descriptor->getPropertyValue(PROPERTY_PRECISION))) + + ::rtl::OUString::createFromAscii(")"); + break; + + case DataType::DECIMAL: + case DataType::NUMERIC: + aSql = aSql + ::rtl::OUString::createFromAscii("(") + + ::rtl::OUString::valueOf(getINT32(descriptor->getPropertyValue(PROPERTY_PRECISION))) + + ::rtl::OUString::createFromAscii(",") + + ::rtl::OUString::valueOf(getINT32(descriptor->getPropertyValue(PROPERTY_SCALE))) + + ::rtl::OUString::createFromAscii(")"); + break; + } + ::rtl::OUString aDefault = getString(descriptor->getPropertyValue(PROPERTY_DEFAULTVALUE)); + if(getINT32(descriptor->getPropertyValue(PROPERTY_ISNULLABLE)) == ColumnValue::NO_NULLS) + { + aSql = aSql + ::rtl::OUString::createFromAscii(" NOT NULL"); + if(aDefault.getLength()) + aSql = aSql + ::rtl::OUString::createFromAscii(" WITH DEFAULT"); + } + else if(aDefault.getLength()) + aSql = aSql + ::rtl::OUString::createFromAscii(" DEFAULT ") + aDefault; + + Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); + xStmt->execute(aSql); + } + OCollection_TYPE::appendByDescriptor(descriptor); +} +// ------------------------------------------------------------------------- +// XDrop +void SAL_CALL OColumns::dropByName( const ::rtl::OUString& elementName ) throw(SQLException, NoSuchElementException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + if(!m_pTable->isNew()) + { + ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("ALTER TABLE "); + ::rtl::OUString aQuote = m_pTable->getConnection()->getMetaData()->getIdentifierQuoteString( ); + ::rtl::OUString aDot = ::rtl::OUString::createFromAscii("."); + + aSql = aSql + aQuote + m_pTable->getSchema() + aQuote + aDot + aQuote + m_pTable->getName() + aQuote; + aSql = aSql + ::rtl::OUString::createFromAscii(" DROP "); + aSql = aSql + aQuote + elementName + aQuote; + + Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); + xStmt->execute(aSql); + } + + OCollection_TYPE::dropByName(elementName); +} +// ------------------------------------------------------------------------- +void SAL_CALL OColumns::dropByIndex( sal_Int32 index ) throw(SQLException, IndexOutOfBoundsException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + if (index < 0 || index >= getCount()) + throw IndexOutOfBoundsException(); + + if(!m_pTable->isNew()) + { + ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("ALTER TABLE "); + ::rtl::OUString aQuote = m_pTable->getConnection()->getMetaData()->getIdentifierQuoteString( ); + ::rtl::OUString aDot = ::rtl::OUString::createFromAscii("."); + + aSql = aSql + aQuote + m_pTable->getSchema() + aQuote + aDot + aQuote + m_pTable->getName() + aQuote; + aSql = aSql + ::rtl::OUString::createFromAscii(" DROP "); + aSql = aSql + aQuote + m_aElements[index]->first + aQuote; + + Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); + xStmt->execute(aSql); + } + OCollection_TYPE::dropByIndex(index); +} + + diff --git a/connectivity/source/drivers/adabas/BConnection.cxx b/connectivity/source/drivers/adabas/BConnection.cxx new file mode 100644 index 000000000000..0b7dbea58955 --- /dev/null +++ b/connectivity/source/drivers/adabas/BConnection.cxx @@ -0,0 +1,233 @@ +/************************************************************************* + * + * $RCSfile: BConnection.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:19 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_ADABAS_BCONNECTION_HXX_ +#include "adabas/BConnection.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_BDRIVER_HXX_ +#include "adabas/BDriver.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_CATALOG_HXX_ +#include "adabas/BCatalog.hxx" +#endif +#ifndef _CONNECTIVITY_ODBC_OFUNCTIONS_HXX_ +#include "odbc/OFunctions.hxx" +#endif +#ifndef _CONNECTIVITY_OTOOLS_HXX_ +#include "odbc/OTools.hxx" +#endif +#ifndef _CONNECTIVITY_ODBC_ODATABASEMETADATA_HXX_ +#include "adabas/BDatabaseMetaData.hxx" +#endif + +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif + +using namespace connectivity::adabas; +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; +using namespace ::com::sun::star::lang; + + +//------------------------------------------------------------------------------ +namespace starlang = ::com::sun::star::lang; +// -------------------------------------------------------------------------------- +OAdabasConnection::OAdabasConnection(const SQLHANDLE _pDriverHandle, connectivity::odbc::ODBCDriver* _pDriver) + : OConnection_BASE2(_pDriverHandle,_pDriver) +{ +} +//----------------------------------------------------------------------------- +SQLRETURN OAdabasConnection::Construct( const ::rtl::OUString& url,const Sequence< PropertyValue >& info) throw(SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + osl_incrementInterlockedCount( &m_refCount ); + + m_aConnectionHandle = SQL_NULL_HANDLE; + + // Connection allozieren + N3SQLAllocHandle(SQL_HANDLE_DBC,m_pDriverHandleCopy,&m_aConnectionHandle); + if(m_aConnectionHandle == SQL_NULL_HANDLE) + throw SQLException(); + + const PropertyValue *pBegin = info.getConstArray(); + const PropertyValue *pEnd = pBegin + info.getLength(); + ::rtl::OUString aAdminUid,aAdminPwd; + + sal_Int32 nLen = url.indexOf(':'); + nLen = url.indexOf(':',nLen+1); + ::rtl::OUString aDSN(url.copy(nLen+1)),aUID,aPWD; + sal_Int32 nTimeout = 20; + for(;pBegin != pEnd;++pBegin) + { + if(!pBegin->Name.compareToAscii("CTRLUSER")) + pBegin->Value >>= aAdminUid; + else if(!pBegin->Name.compareToAscii("CTRLPWD")) + pBegin->Value >>= aAdminPwd; + else if(!pBegin->Name.compareToAscii("Timeout")) + pBegin->Value >>= nTimeout; + else if(!pBegin->Name.compareToAscii("user")) + pBegin->Value >>= aUID; + else if(!pBegin->Name.compareToAscii("password")) + pBegin->Value >>= aPWD; + } + + SQLRETURN nSQLRETURN = OpenConnection(aDSN,nTimeout, aUID,aPWD); + + osl_decrementInterlockedCount( &m_refCount ); + return nSQLRETURN; +} +//----------------------------------------------------------------------------- +SQLRETURN OAdabasConnection::OpenConnection(const ::rtl::OUString& aConnectStr,sal_Int32 nTimeOut, const ::rtl::OUString& _uid,const ::rtl::OUString& _pwd) +{ + if (m_aConnectionHandle == SQL_NULL_HANDLE) + return -1; + + SQLRETURN nSQLRETURN = 0; + SDB_ODBC_CHAR szDSN[4096]; + SDB_ODBC_CHAR szUID[20]; + SDB_ODBC_CHAR szPWD[20]; + + memset(szDSN,'\0',4096); + memset(szUID,'\0',20); + memset(szPWD,'\0',20); + + ::rtl::OString aConStr(::rtl::OUStringToOString(aConnectStr,osl_getThreadTextEncoding())); + ::rtl::OString aUID(::rtl::OUStringToOString(_uid,osl_getThreadTextEncoding())); + ::rtl::OString aPWD(::rtl::OUStringToOString(_pwd,osl_getThreadTextEncoding())); + memcpy(szDSN, (SDB_ODBC_CHAR*) aConStr.getStr(), ::std::min<sal_Int32>((sal_Int32)2048,aConStr.getLength())); + memcpy(szUID, (SDB_ODBC_CHAR*) aUID.getStr(), ::std::min<sal_Int32>((sal_Int32)20,aUID.getLength())); + memcpy(szPWD, (SDB_ODBC_CHAR*) aPWD.getStr(), ::std::min<sal_Int32>((sal_Int32)20,aPWD.getLength())); + + + + N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_LOGIN_TIMEOUT,(SQLPOINTER)nTimeOut,SQL_IS_INTEGER); + // Verbindung aufbauen + + nSQLRETURN = N3SQLConnect(m_aConnectionHandle, + szDSN, + (SQLSMALLINT) ::std::min<sal_Int32>((sal_Int32)2048,aConStr.getLength()), + szUID, + (SQLSMALLINT) ::std::min<sal_Int32>((sal_Int32)20,aUID.getLength()), + szPWD, + (SQLSMALLINT) ::std::min<sal_Int32>((sal_Int32)20,aPWD.getLength())); + if (nSQLRETURN == SQL_ERROR || nSQLRETURN == SQL_NO_DATA) + return nSQLRETURN; + +#ifndef MAC + // autocoomit ist immer default + + N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_AUTOCOMMIT,(SQLPOINTER)SQL_AUTOCOMMIT_ON,SQL_IS_INTEGER); +#endif + buildTypeInfo(); + + return nSQLRETURN; +} + +//------------------------------------------------------------------------------ +void OAdabasConnection::disposing() +{ + ::osl::MutexGuard aGuard(m_aMutex); + + Reference< XComponent > xComp2(m_xCatalog.get(), UNO_QUERY); + if(xComp2.is()) + xComp2->dispose(); + + m_xCatalog = Reference< XTablesSupplier >(); + + OConnection_BASE2::disposing(); +} +//------------------------------------------------------------------------------ +::com::sun::star::uno::Reference< XTablesSupplier > OAdabasConnection::createCatalog() +{ + ::osl::MutexGuard aGuard( m_aMutex ); + Reference< XTablesSupplier > xTab = m_xCatalog; + if(!m_xCatalog.get().is()) + { + OAdabasCatalog *pCat = new OAdabasCatalog(m_aConnectionHandle,this); + xTab = pCat; + m_xCatalog = xTab; + } + return xTab; +} +// -------------------------------------------------------------------------------- +Reference< XDatabaseMetaData > SAL_CALL OAdabasConnection::getMetaData( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE2::rBHelper.bDisposed) + throw DisposedException(); + + if(!m_xMetaData.is()) + m_xMetaData = new OAdabasDatabaseMetaData(m_aConnectionHandle,this); + + return m_xMetaData; +} +//------------------------------------------------------------------------------ +sal_Bool OAdabasConnection::isStarted() +{ + return sal_True; + +} + diff --git a/connectivity/source/drivers/adabas/BDatabaseMetaData.cxx b/connectivity/source/drivers/adabas/BDatabaseMetaData.cxx new file mode 100644 index 000000000000..00edcb7e9971 --- /dev/null +++ b/connectivity/source/drivers/adabas/BDatabaseMetaData.cxx @@ -0,0 +1,80 @@ +/************************************************************************* + * + * $RCSfile: BDatabaseMetaData.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:19 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADABAS_BDATABASEMETADATA_HXX_ +#include "adabas/BDatabaseMetaData.hxx" +#endif + +using namespace connectivity::adabas; +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; + +::rtl::OUString SAL_CALL OAdabasDatabaseMetaData::getURL( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aRet = ::rtl::OUString::createFromAscii("sdbc:adabas:") + OAdabasDatabaseMetaData_BASE::getURL(); + return aRet; +} + + diff --git a/connectivity/source/drivers/adabas/BDriver.cxx b/connectivity/source/drivers/adabas/BDriver.cxx new file mode 100644 index 000000000000..3bbf1c42bd83 --- /dev/null +++ b/connectivity/source/drivers/adabas/BDriver.cxx @@ -0,0 +1,252 @@ +/************************************************************************* + * + * $RCSfile: BDriver.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:19 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADABAS_BDRIVER_HXX_ +#include "adabas/BDriver.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_BCONNECTION_HXX_ +#include "adabas/BConnection.hxx" +#endif +#ifndef _CONNECTIVITY_ODBC_OFUNCTIONS_HXX_ +#include "odbc/OFunctions.hxx" +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif +#ifndef _CONNECTIVITY_OTOOLS_HXX_ +#include "odbc/OTools.hxx" +#endif + +using namespace connectivity::adabas; +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; +// -------------------------------------------------------------------------------- +ODriver::ODriver() +{ +} +//------------------------------------------------------------------------------ +void ODriver::disposing() +{ + ::osl::MutexGuard aGuard(m_aMutex); + ODriver_BASE::disposing(); +} + +// static ServiceInfo +//------------------------------------------------------------------------------ +rtl::OUString ODriver::getImplementationName_Static( ) throw(RuntimeException) +{ + return rtl::OUString::createFromAscii("com.sun.star.sdbc.BDriver"); +} +//------------------------------------------------------------------------------ +Sequence< ::rtl::OUString > ODriver::getSupportedServiceNames_Static( ) throw (RuntimeException) +{ + Sequence< ::rtl::OUString > aSNS( 2 ); + aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver"); + aSNS[1] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Driver"); + return aSNS; +} +//------------------------------------------------------------------ +::rtl::OUString SAL_CALL ODriver::getImplementationName( ) throw(RuntimeException) +{ + return getImplementationName_Static(); +} + +//------------------------------------------------------------------ +sal_Bool SAL_CALL ODriver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException) +{ + Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); + const ::rtl::OUString* pSupported = aSupported.getConstArray(); + for (sal_Int32 i=0; i<aSupported.getLength(); ++i, ++pSupported) + if (pSupported->equals(_rServiceName)) + return sal_True; + + return sal_False; +} +//------------------------------------------------------------------ +Sequence< ::rtl::OUString > SAL_CALL ODriver::getSupportedServiceNames( ) throw(RuntimeException) +{ + return getSupportedServiceNames_Static(); +} +//------------------------------------------------------------------ +Any SAL_CALL ODriver::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = ::cppu::queryInterface(rType, static_cast<XDataDefinitionSupplier*>(this)); + if(aRet.hasValue()) + return aRet; + return ODriver_BASE::queryInterface(rType); +} +//------------------------------------------------------------------ +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL connectivity::adabas::ODriver_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& ) throw( ::com::sun::star::uno::Exception ) +{ + return *(new ODriver()); +} +// -------------------------------------------------------------------------------- +Reference< XConnection > SAL_CALL ODriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException) +{ + if(!m_pDriverHandle) + { + ::rtl::OUString aPath; + if(!EnvironmentHandle(aPath)) + throw SQLException(aPath,*this,::rtl::OUString(),1000,Any()); + } + OAdabasConnection* pCon = new OAdabasConnection(m_pDriverHandle,this); + SQLRETURN nSQLRETURN = pCon->Construct(url,info); + + if (nSQLRETURN == SQL_ERROR || nSQLRETURN == SQL_NO_DATA) + { + connectivity::odbc::OTools::ThrowException(nSQLRETURN,pCon->getConnection(),SQL_HANDLE_DBC,*this); + } + else if(SQL_SUCCESS_WITH_INFO == nSQLRETURN) // this driver does not support odbc3 + { + } + Reference< XConnection > xCon = pCon; + m_xConnections.push_back(WeakReferenceHelper(*pCon)); + + return xCon; +} + +// -------------------------------------------------------------------------------- +sal_Bool SAL_CALL ODriver::acceptsURL( const ::rtl::OUString& url ) + throw(SQLException, RuntimeException) +{ + if(!url.compareTo(::rtl::OUString::createFromAscii("sdbc:adabas:"),12)) + { + return sal_True; + } + return sal_False; +} +// -------------------------------------------------------------------------------- +Sequence< DriverPropertyInfo > SAL_CALL ODriver::getPropertyInfo( const ::rtl::OUString& , const Sequence< PropertyValue >& ) throw(SQLException, RuntimeException) +{ + return Sequence< DriverPropertyInfo >(); +} +// -------------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODriver::getMajorVersion( ) throw(RuntimeException) +{ + return 1; +} +// -------------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODriver::getMinorVersion( ) throw(RuntimeException) +{ + return 0; +} +// -------------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// ODBC Environment (gemeinsam fuer alle Connections): +SQLHANDLE ODriver::EnvironmentHandle(::rtl::OUString &_rPath) +{ + // Ist (fuer diese Instanz) bereits ein Environment erzeugt worden? + if (!m_pDriverHandle) + { + SQLHANDLE h = SQL_NULL_HANDLE; + // Environment allozieren + + // ODBC-DLL jetzt laden: + if (! connectivity::LoadLibrary_ADABAS(_rPath)) + return SQL_NULL_HANDLE; + + if (N3SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&h) != SQL_SUCCESS) + return SQL_NULL_HANDLE; + + // In globaler Struktur merken ... + m_pDriverHandle = (void *) h; + SQLRETURN nError = N3SQLSetEnvAttr(h, SQL_ATTR_ODBC_VERSION,(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_INTEGER); + //N3SQLSetEnvAttr(h, SQL_ATTR_CONNECTION_POOLING,(SQLPOINTER) SQL_CP_ONE_PER_HENV, SQL_IS_INTEGER); + } + + return m_pDriverHandle; +} +// -------------------------------------------------------------------------------- +// XDataDefinitionSupplier +Reference< XTablesSupplier > SAL_CALL ODriver::getDataDefinitionByConnection( const Reference< ::com::sun::star::sdbc::XConnection >& connection ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODriver_BASE::rBHelper.bDisposed) + throw DisposedException(); + + + OAdabasConnection* pConnection = NULL; + for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i) + { + if ((OAdabasConnection*) Reference< XConnection >::query(i->get().get()).get() == (OAdabasConnection*)connection.get()) + { + pConnection = (OAdabasConnection*)connection.get(); + break; + } + } + + Reference< XTablesSupplier > xTab = NULL; + if(pConnection) + xTab = pConnection->createCatalog(); + return xTab; +} + +// -------------------------------------------------------------------------------- +Reference< XTablesSupplier > SAL_CALL ODriver::getDataDefinitionByURL( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) +{ + return getDataDefinitionByConnection(connect(url,info)); +} + + diff --git a/connectivity/source/drivers/adabas/BGroup.cxx b/connectivity/source/drivers/adabas/BGroup.cxx new file mode 100644 index 000000000000..8423bf7d3384 --- /dev/null +++ b/connectivity/source/drivers/adabas/BGroup.cxx @@ -0,0 +1,131 @@ +/************************************************************************* + * + * $RCSfile: BGroup.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:19 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADABAS_GROUP_HXX_ +#include "adabas/BGroup.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_USERS_HXX_ +#include "adabas/BUsers.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _CONNECTIVITY_ADABAS_BCONNECTION_HXX_ +#include "adabas/BConnection.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif + +using namespace connectivity::adabas; +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; + +// ------------------------------------------------------------------------- +OAdabasGroup::OAdabasGroup( OAdabasConnection* _pConnection) : connectivity::sdbcx::OGroup(sal_True) + ,m_pConnection(_pConnection) +{ + construct(); + ::std::vector< ::rtl::OUString> aVector; + m_pUsers = new OUsers(*this,m_aMutex,aVector,m_pConnection,this); +} +// ------------------------------------------------------------------------- +OAdabasGroup::OAdabasGroup( OAdabasConnection* _pConnection, + const ::rtl::OUString& _Name + ) : connectivity::sdbcx::OGroup(_Name,sal_True) + ,m_pConnection(_pConnection) +{ + construct(); + refreshUsers(); +} +// ------------------------------------------------------------------------- +void OAdabasGroup::refreshUsers() +{ + if(!m_pConnection) + return; + + ::std::vector< ::rtl::OUString> aVector; + Reference< XStatement > xStmt = m_pConnection->createStatement( ); + + ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("SELECT DISTINCT USERNAME FROM DOMAIN.USERS WHERE USERNAME IS NOT NULL AND USERNAME <> ' ' AND USERNAME <> 'CONTROL' AND GROUPNAME = '"); + aSql += getName( ); + aSql += ::rtl::OUString::createFromAscii("'"); + + Reference< XResultSet > xResult = xStmt->executeQuery(aSql); + if(xResult.is()) + { + Reference< XRow > xRow(xResult,UNO_QUERY); + while(xResult->next()) + aVector.push_back(xRow->getString(1)); + } + if(m_pUsers) + delete m_pUsers; + m_pUsers = new OUsers(*this,m_aMutex,aVector,m_pConnection,this); +} + + diff --git a/connectivity/source/drivers/adabas/BGroups.cxx b/connectivity/source/drivers/adabas/BGroups.cxx new file mode 100644 index 000000000000..f9a3c6b8adb7 --- /dev/null +++ b/connectivity/source/drivers/adabas/BGroups.cxx @@ -0,0 +1,161 @@ +/************************************************************************* + * + * $RCSfile: BGroups.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:19 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADABAS_GROUPS_HXX_ +#include "adabas/BGroups.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_GROUP_HXX_ +#include "adabas/BGroup.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_TABLE_HXX_ +#include "adabas/BTable.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _CONNECTIVITY_SDBCX_IREFRESHABLE_HXX_ +#include "sdbcx/IRefreshable.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif + +using namespace connectivity::adabas; +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; +typedef connectivity::sdbcx::OCollection OCollection_TYPE; +// ------------------------------------------------------------------------- +Reference< XNamed > OGroups::createObject(const ::rtl::OUString& _rName) +{ + Reference< XNamed > xRet = NULL; + OAdabasGroup* pRet = new OAdabasGroup(m_pConnection,_rName); + xRet = pRet; + return xRet; +} +// ------------------------------------------------------------------------- +void OGroups::impl_refresh() throw(RuntimeException) +{ + m_pParent->refreshGroups(); +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > OGroups::createEmptyObject() +{ + OAdabasGroup* pNew = new OAdabasGroup(m_pConnection); + return pNew; +} +// ------------------------------------------------------------------------- +// XAppend +void SAL_CALL OGroups::appendByDescriptor( const Reference< XPropertySet >& descriptor ) throw(SQLException, ElementExistException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + ::rtl::OUString aName = getString(descriptor->getPropertyValue(PROPERTY_NAME)); + ObjectMap::iterator aIter = m_aNameMap.find(aName); + if( aIter != m_aNameMap.end()) + throw ElementExistException(aName,*this); + + + ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("CREATE USERGROUP "); + ::rtl::OUString aQuote = m_pConnection->getMetaData()->getIdentifierQuoteString( ); + + aSql = aSql + aQuote + getString(descriptor->getPropertyValue(PROPERTY_NAME)) + aQuote; + + Reference< XStatement > xStmt = m_pConnection->createStatement( ); + xStmt->execute(aSql); + + OCollection_TYPE::appendByDescriptor(descriptor); +} +// ------------------------------------------------------------------------- +// XDrop +void SAL_CALL OGroups::dropByName( const ::rtl::OUString& elementName ) throw(SQLException, NoSuchElementException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + ObjectMap::iterator aIter = m_aNameMap.find(elementName); + if( aIter == m_aNameMap.end()) + throw NoSuchElementException(elementName,*this); + + ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("DROP USERGROUP "); + ::rtl::OUString aQuote = m_pConnection->getMetaData()->getIdentifierQuoteString( ); + + aSql = aSql + aQuote + elementName + aQuote; + + Reference< XStatement > xStmt = m_pConnection->createStatement( ); + xStmt->execute(aSql); + + OCollection_TYPE::dropByName(elementName); +} +// ------------------------------------------------------------------------- +void SAL_CALL OGroups::dropByIndex( sal_Int32 index ) throw(SQLException, IndexOutOfBoundsException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + if (index < 0 || index >= getCount()) + throw IndexOutOfBoundsException(); + + dropByName(m_aElements[index]->first); +} + + diff --git a/connectivity/source/drivers/adabas/BIndex.cxx b/connectivity/source/drivers/adabas/BIndex.cxx new file mode 100644 index 000000000000..6d8276f9b791 --- /dev/null +++ b/connectivity/source/drivers/adabas/BIndex.cxx @@ -0,0 +1,139 @@ +/************************************************************************* + * + * $RCSfile: BIndex.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:19 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADABAS_INDEX_HXX_ +#include "adabas/BIndex.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_INDEXCOLUMNS_HXX_ +#include "adabas/BIndexColumns.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _CONNECTIVITY_ADABAS_TABLE_HXX_ +#include "adabas/BTable.hxx" +#endif + +using namespace connectivity::adabas; +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; +// ------------------------------------------------------------------------- +OAdabasIndex::OAdabasIndex( OAdabasTable* _pTable) : connectivity::sdbcx::OIndex(sal_True) + , m_pTable(_pTable) +{ + construct(); + ::std::vector< ::rtl::OUString> aVector; + m_pColumns = new OIndexColumns(this,m_aMutex,aVector); +} +// ------------------------------------------------------------------------- +OAdabasIndex::OAdabasIndex( OAdabasTable* _pTable, + const ::rtl::OUString& _Name, + const ::rtl::OUString& _Catalog, + sal_Bool _isUnique, + sal_Bool _isPrimaryKeyIndex, + sal_Bool _isClustered + ) : connectivity::sdbcx::OIndex(_Name, + _Catalog, + _isUnique, + _isPrimaryKeyIndex, + _isClustered,sal_True) + ,m_pTable(_pTable) +{ + construct(); + refreshColumns(); +} +// ------------------------------------------------------------------------- + +void OAdabasIndex::refreshColumns() +{ + if(!m_pTable) + return; + + ::std::vector< ::rtl::OUString> aVector; + Reference< XResultSet > xResult = m_pTable->getConnection()->getMetaData()->getIndexInfo(Any(), + m_pTable->getSchema(),m_pTable->getName(),sal_False,sal_False); + + if(xResult.is()) + { + Reference< XRow > xRow(xResult,UNO_QUERY); + ::rtl::OUString aColName; + while(xResult->next()) + { + if(xRow->getString(9) == m_Name) + { + aColName = xRow->getString(9); + if(!xRow->wasNull()) + aVector.push_back(aColName); + } + } + } + if(m_pColumns) + delete m_pColumns; + m_pColumns = new OIndexColumns(this,m_aMutex,aVector); +} + diff --git a/connectivity/source/drivers/adabas/BIndexColumns.cxx b/connectivity/source/drivers/adabas/BIndexColumns.cxx new file mode 100644 index 000000000000..8f7582a621d2 --- /dev/null +++ b/connectivity/source/drivers/adabas/BIndexColumns.cxx @@ -0,0 +1,146 @@ +/************************************************************************* + * + * $RCSfile: BIndexColumns.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:19 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADABAS_INDEXCOLUMNS_HXX_ +#include "adabas/BIndexColumns.hxx" +#endif +#ifndef _CONNECTIVITY_SDBCX_INDEXCOLUMN_HXX_ +#include "connectivity/sdbcx/VIndexColumn.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ +#include <com/sun/star/sdbc/ColumnValue.hpp> +#endif +#ifndef _CONNECTIVITY_ADABAS_TABLE_HXX_ +#include "adabas/BTable.hxx" +#endif + +using namespace connectivity::adabas; +using namespace connectivity::sdbcx; +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; +// ------------------------------------------------------------------------- +Reference< XNamed > OIndexColumns::createObject(const ::rtl::OUString& _rName) +{ + + Reference< XResultSet > xResult = m_pIndex->getTable()->getConnection()->getMetaData()->getIndexInfo(Any(), + m_pIndex->getTable()->getSchema(),m_pIndex->getTable()->getName(),sal_False,sal_False); + + sal_Bool bAsc = sal_True; + if(xResult.is()) + { + Reference< XRow > xRow(xResult,UNO_QUERY); + ::rtl::OUString aD(::rtl::OUString::createFromAscii("D")); + while(xResult->next()) + { + if(xRow->getString(9) == _rName) + bAsc = xRow->getString(10) != aD; + } + } + + xResult = m_pIndex->getTable()->getConnection()->getMetaData()->getColumns(Any(), + m_pIndex->getTable()->getSchema(),m_pIndex->getTable()->getName(),_rName); + + Reference< XNamed > xRet = NULL; + if(xResult.is()) + { + Reference< XRow > xRow(xResult,UNO_QUERY); + while(xResult->next()) + { + if(xRow->getString(4) == _rName) + { + OIndexColumn* pRet = new OIndexColumn(bAsc, + _rName, + xRow->getString(6), + xRow->getString(13), + xRow->getInt(11), + xRow->getInt(7), + xRow->getInt(9), + xRow->getInt(5), + sal_False,sal_False,sal_False,sal_True); + xRet = pRet; + break; + } + } + } + + return xRet; +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > OIndexColumns::createEmptyObject() +{ + OIndexColumn* pNew = new OIndexColumn(sal_True); + return pNew; +} +// ------------------------------------------------------------------------- + diff --git a/connectivity/source/drivers/adabas/BIndexes.cxx b/connectivity/source/drivers/adabas/BIndexes.cxx new file mode 100644 index 000000000000..82361e74977c --- /dev/null +++ b/connectivity/source/drivers/adabas/BIndexes.cxx @@ -0,0 +1,241 @@ +/************************************************************************* + * + * $RCSfile: BIndexes.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_ADABAS_INDEXES_HXX_ +#include "adabas/BIndexes.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_INDEX_HXX_ +#include "adabas/BIndex.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_TABLE_HXX_ +#include "adabas/BTable.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_INDEXTYPE_HPP_ +#include <com/sun/star/sdbc/IndexType.hpp> +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +using namespace connectivity::adabas; +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; +typedef connectivity::sdbcx::OCollection OCollection_TYPE; + +Reference< XNamed > OIndexes::createObject(const ::rtl::OUString& _rName) +{ + ::rtl::OUString aName,aQualifier; + sal_Int32 nLen = _rName.indexOf('.'); + if(nLen != -1) + { + aQualifier = _rName.copy(0,nLen); + aName = _rName.copy(nLen+1); + } + else + aName = _rName; + + + Reference< XResultSet > xResult = m_pTable->getConnection()->getMetaData()->getIndexInfo(Any(), + m_pTable->getSchema(),m_pTable->getName(),sal_False,sal_False); + + Reference< XNamed > xRet = NULL; + if(xResult.is()) + { + Reference< XRow > xRow(xResult,UNO_QUERY); + while(xResult->next()) + { + if(xRow->getString(6) == aName && (!aQualifier.getLength() || xRow->getString(5) == aQualifier )) + { + OAdabasIndex* pRet = new OAdabasIndex(m_pTable,aName,aQualifier,!xRow->getBoolean(4), + aName == ::rtl::OUString::createFromAscii("SYSPRIMARYKEYINDEX"), + xRow->getShort(7) == IndexType::CLUSTERED); + xRet = pRet; + } + } + } + + return xRet; +} +// ------------------------------------------------------------------------- +void OIndexes::impl_refresh() throw(RuntimeException) +{ + m_pTable->refreshIndexes(); +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > OIndexes::createEmptyObject() +{ + OAdabasIndex* pNew = new OAdabasIndex(m_pTable); + return pNew; +} +// ------------------------------------------------------------------------- +// XAppend +void SAL_CALL OIndexes::appendByDescriptor( const Reference< XPropertySet >& descriptor ) throw(SQLException, ElementExistException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + ::rtl::OUString aName = getString(descriptor->getPropertyValue(PROPERTY_NAME)); + ObjectMap::iterator aIter = m_aNameMap.find(aName); + if( aIter != m_aNameMap.end()) + throw ElementExistException(aName,*this); + + if(!m_pTable->isNew()) + { + ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("CREATE "); + ::rtl::OUString aQuote = m_pTable->getConnection()->getMetaData()->getIdentifierQuoteString( ); + ::rtl::OUString aDot = ::rtl::OUString::createFromAscii("."); + + if(getINT32(descriptor->getPropertyValue(PROPERTY_ISUNIQUE))) + aSql = aSql + ::rtl::OUString::createFromAscii("UNIQUE "); + aSql = aSql + ::rtl::OUString::createFromAscii("INDEX "); + + + if(aName.getLength()) + { + aSql = aSql + aQuote + aName + aQuote + + ::rtl::OUString::createFromAscii(" ON ") + + aQuote + m_pTable->getSchema() + aQuote + aDot + + aQuote + m_pTable->getName() + aQuote + + ::rtl::OUString::createFromAscii(" ( "); + + Reference<XColumnsSupplier> xColumnSup(descriptor,UNO_QUERY); + Reference<XIndexAccess> xColumns(xColumnSup->getColumns(),UNO_QUERY); + Reference< XPropertySet > xColProp; + for(sal_Int32 i=0;i<xColumns->getCount();++i) + { + xColumns->getByIndex(i) >>= xColProp; + aSql = aSql + aQuote + getString(xColProp->getPropertyValue(PROPERTY_NAME)) + aQuote; + aSql = aSql + (getBOOL(xColProp->getPropertyValue(PROPERTY_ISASCENDING)) + ? + ::rtl::OUString::createFromAscii(" ASC") + : + ::rtl::OUString::createFromAscii(" DESC")) + + ::rtl::OUString::createFromAscii(","); + } + aSql = aSql.replaceAt(aSql.getLength()-1,1,::rtl::OUString::createFromAscii(")")); + } + else + { + aSql = aSql + aQuote + m_pTable->getSchema() + aQuote + aDot + aQuote + m_pTable->getName() + aQuote; + + Reference<XColumnsSupplier> xColumnSup(descriptor,UNO_QUERY); + Reference<XIndexAccess> xColumns(xColumnSup->getColumns(),UNO_QUERY); + Reference< XPropertySet > xColProp; + if(xColumns->getCount() != 1) + throw SQLException(); + + xColumns->getByIndex(0) >>= xColProp; + + aSql = aSql + aDot + aQuote + getString(xColProp->getPropertyValue(PROPERTY_NAME)) + aQuote; + } + + Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); + xStmt->execute(aSql); + } + OCollection_TYPE::appendByDescriptor(descriptor); +} +// ------------------------------------------------------------------------- +// XDrop +void SAL_CALL OIndexes::dropByName( const ::rtl::OUString& elementName ) throw(SQLException, NoSuchElementException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + ObjectMap::iterator aIter = m_aNameMap.find(elementName); + if( aIter == m_aNameMap.end()) + throw NoSuchElementException(elementName,*this); + + if(!m_pTable->isNew()) + { + ::rtl::OUString aName,aSchema; + sal_Int32 nLen = elementName.indexOf('.'); + aSchema = elementName.copy(0,nLen); + aName = elementName.copy(nLen+1); + + ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("DROP INDEX "); + ::rtl::OUString aQuote = m_pTable->getConnection()->getMetaData()->getIdentifierQuoteString( ); + ::rtl::OUString aDot = ::rtl::OUString::createFromAscii("."); + + aSql = aSql + aQuote + aSchema + aQuote + aDot + aQuote + aName + ::rtl::OUString::createFromAscii(" ON ") + + aQuote + m_pTable->getSchema() + aQuote + m_pTable->getName() + aQuote; + + Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); + xStmt->execute(aSql); + } + OCollection_TYPE::dropByName(elementName); +} +// ------------------------------------------------------------------------- +void SAL_CALL OIndexes::dropByIndex( sal_Int32 index ) throw(SQLException, IndexOutOfBoundsException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + if (index < 0 || index >= getCount()) + throw IndexOutOfBoundsException(); + + dropByName(m_aElements[index]->first); +} +// ------------------------------------------------------------------------- + + diff --git a/connectivity/source/drivers/adabas/BKeys.cxx b/connectivity/source/drivers/adabas/BKeys.cxx new file mode 100644 index 000000000000..e3227f467b0e --- /dev/null +++ b/connectivity/source/drivers/adabas/BKeys.cxx @@ -0,0 +1,285 @@ +/************************************************************************* + * + * $RCSfile: BKeys.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADABAS_KEYS_HXX_ +#include "adabas/BKeys.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_INDEX_HXX_ +#include "adabas/BKey.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_TABLE_HXX_ +#include "adabas/BTable.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBCX_KEYTYPE_HPP_ +#include <com/sun/star/sdbcx/KeyType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_KEYRULE_HPP_ +#include <com/sun/star/sdbc/KeyRule.hpp> +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +using namespace connectivity::adabas; +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; +typedef connectivity::sdbcx::OCollection OCollection_TYPE; + +Any SAL_CALL OKeys::queryInterface( const Type & rType ) throw(RuntimeException) +{ + if(rType == ::getCppuType(static_cast< Reference<XNameAccess> *>(NULL))) + return Any(); + + return OCollection_TYPE::queryInterface(rType); +} +// ------------------------------------------------------------------------- +Sequence< Type > SAL_CALL OKeys::getTypes( ) throw(RuntimeException) +{ + Sequence< Type > aTypes(OCollection_TYPE::getTypes()); + Type* pBegin = aTypes.getArray(); + Type* pEnd = pBegin + aTypes.getLength(); + + Sequence< Type > aRetType(aTypes.getLength()-1); + sal_Int32 i=0; + for(;pBegin != pEnd; ++pBegin) + { + if(*pBegin != ::getCppuType(static_cast< Reference<XNameAccess> *>(NULL))) + { + aRetType.getArray()[i++] = *pBegin; + } + } + + return aRetType; +} +// ------------------------------------------------------------------------- +Reference< XNamed > OKeys::createObject(const ::rtl::OUString& _rName) +{ + Reference< XNamed > xRet = NULL; + + if(_rName.getLength()) + { + Reference< XResultSet > xResult = m_pTable->getConnection()->getMetaData()->getExportedKeys(Any(), + m_pTable->getSchema(),m_pTable->getName()); + + if(xResult.is()) + { + Reference< XRow > xRow(xResult,UNO_QUERY); + ::rtl::OUString aName,aDot = ::rtl::OUString::createFromAscii("."); + while(xResult->next()) + { + if(xRow->getString(13) == _rName) + { + aName = xRow->getString(6); + if(aName.getLength()) + aName += aDot; + aName += xRow->getString(7); + + OAdabasKey* pRet = new OAdabasKey(m_pTable,_rName,aName,KeyType::FOREIGN,xRow->getInt(10),xRow->getInt(11)); + xRet = pRet; + break; + } + } + } + } + else + { + OAdabasKey* pRet = new OAdabasKey(m_pTable,_rName,::rtl::OUString(),KeyType::PRIMARY,KeyRule::NO_ACTION,KeyRule::NO_ACTION); + xRet = pRet; + } + + return xRet; +} +// ------------------------------------------------------------------------- +void OKeys::impl_refresh() throw(RuntimeException) +{ + m_pTable->refreshKeys(); +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > OKeys::createEmptyObject() +{ + OAdabasKey* pNew = new OAdabasKey(m_pTable); + return pNew; +} +// ------------------------------------------------------------------------- +// XAppend +void SAL_CALL OKeys::appendByDescriptor( const Reference< XPropertySet >& descriptor ) throw(SQLException, ElementExistException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + ::rtl::OUString aName = getString(descriptor->getPropertyValue(PROPERTY_NAME)); + ObjectMap::iterator aIter = m_aNameMap.find(aName); + if( aIter != m_aNameMap.end()) + throw ElementExistException(aName,*this); + if(!m_pTable->isNew()) + { + sal_Int32 nKeyType = getINT32(descriptor->getPropertyValue(PROPERTY_TYPE)); + + ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("ALTER TABLE "); + ::rtl::OUString aQuote = m_pTable->getConnection()->getMetaData()->getIdentifierQuoteString( ); + ::rtl::OUString aDot = ::rtl::OUString::createFromAscii("."); + + aSql = aSql + aQuote + m_pTable->getSchema() + aQuote + aDot + aQuote + m_pTable->getName() + aQuote; + if(nKeyType == KeyType::PRIMARY) + { + aSql = aSql + ::rtl::OUString::createFromAscii(" ALTER PRIMARY KEY ("); + } + else if(nKeyType == KeyType::FOREIGN) + { + aSql = aSql + ::rtl::OUString::createFromAscii(" FOREIGN KEY ("); + } + else + throw SQLException(); + + Reference<XColumnsSupplier> xColumnSup(descriptor,UNO_QUERY); + Reference<XIndexAccess> xColumns(xColumnSup->getColumns(),UNO_QUERY); + Reference< XPropertySet > xColProp; + for(sal_Int32 i=0;i<xColumns->getCount();++i) + { + xColumns->getByIndex(i) >>= xColProp; + aSql = aSql + aQuote + getString(xColProp->getPropertyValue(PROPERTY_NAME)) + aQuote + + ::rtl::OUString::createFromAscii(","); + } + aSql = aSql.replaceAt(aSql.getLength()-1,1,::rtl::OUString::createFromAscii(")")); + + if(nKeyType == KeyType::FOREIGN) + { + sal_Int32 nDeleteRule = getINT32(xColProp->getPropertyValue(PROPERTY_DELETERULE)); + + ::rtl::OUString aName,aSchema,aRefTable = getString(xColProp->getPropertyValue(PROPERTY_REFERENCEDTABLE)); + sal_Int32 nLen = aRefTable.indexOf('.'); + aSchema = aRefTable.copy(0,nLen); + aName = aRefTable.copy(nLen+1); + aSql = aSql + ::rtl::OUString::createFromAscii(" REFERENCES ") + + aQuote + aSchema + aQuote + aDot + aQuote + aName + aQuote; + + for(sal_Int32 i=0;i<xColumns->getCount();++i) + { + xColumns->getByIndex(i) >>= xColProp; + aSql = aSql + aQuote + getString(xColProp->getPropertyValue(PROPERTY_REFERENCEDCOLUMN)) + aQuote + + ::rtl::OUString::createFromAscii(","); + } + aSql = aSql.replaceAt(aSql.getLength()-1,1,::rtl::OUString::createFromAscii(")")); + + switch(nDeleteRule) + { + case KeyRule::CASCADE: + aSql = aSql + ::rtl::OUString::createFromAscii(" ON DELETE CASCADE "); + break; + case KeyRule::RESTRICT: + aSql = aSql + ::rtl::OUString::createFromAscii(" ON DELETE RESTRICT "); + break; + case KeyRule::SET_NULL: + aSql = aSql + ::rtl::OUString::createFromAscii(" ON DELETE SET NULL "); + break; + case KeyRule::SET_DEFAULT: + aSql = aSql + ::rtl::OUString::createFromAscii(" ON DELETE SET DEFAULT "); + break; + default: + ; + } + } + + Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); + xStmt->execute(aSql); + } + OCollection_TYPE::appendByDescriptor(descriptor); +} +// ------------------------------------------------------------------------- +// XDrop +void SAL_CALL OKeys::dropByName( const ::rtl::OUString& elementName ) throw(SQLException, NoSuchElementException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + ObjectMap::iterator aIter = m_aNameMap.find(elementName); + if( aIter == m_aNameMap.end()) + throw NoSuchElementException(elementName,*this); + + if(!m_pTable->isNew()) + { + ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("ALTER TABLE "); + ::rtl::OUString aQuote = m_pTable->getConnection()->getMetaData()->getIdentifierQuoteString( ); + ::rtl::OUString aDot = ::rtl::OUString::createFromAscii("."); + + aSql = aSql + aQuote + m_pTable->getSchema() + aQuote + m_pTable->getName() + aQuote + + ::rtl::OUString::createFromAscii(" DROP PRIMARY KEY"); + + Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); + xStmt->execute(aSql); + } + OCollection_TYPE::dropByName(elementName); +} +// ------------------------------------------------------------------------- +void SAL_CALL OKeys::dropByIndex( sal_Int32 index ) throw(SQLException, IndexOutOfBoundsException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + if (index < 0 || index >= getCount()) + throw IndexOutOfBoundsException(); + + dropByName(m_aElements[index]->first); +} + diff --git a/connectivity/source/drivers/adabas/BResultSetMetaData.cxx b/connectivity/source/drivers/adabas/BResultSetMetaData.cxx new file mode 100644 index 000000000000..df70ad5de067 --- /dev/null +++ b/connectivity/source/drivers/adabas/BResultSetMetaData.cxx @@ -0,0 +1,249 @@ +/************************************************************************* + * + * $RCSfile: BResultSetMetaData.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADABAS_BRESULTSETMETADATA_HXX_ +#include "adabas/BResultSetMetaData.hxx" +#endif +#ifndef _CONNECTIVITY_OTOOLS_HXX_ +#include "adabas/BTools.hxx" +#endif + +using namespace connectivity::adabas; +// ------------------------------------------------------------------------- +OResultSetMetaData::~OResultSetMetaData() +{ +} +// ------------------------------------------------------------------------- +::rtl::OUString OResultSetMetaData::getCharColAttrib(sal_Int32 _column,sal_Int32 ident) throw(starsdbc::SQLException, staruno::RuntimeException) +{ + sal_Int32 column = _column; + if(_column < m_vMapping.size()) // use mapping + column = m_vMapping[_column]; + + sal_Int32 BUFFER_LEN = 128; + char *pName = new char[BUFFER_LEN]; + SQLSMALLINT nRealLen=0; + OTools::ThrowException(N3SQLColAttribute(m_aStatementHandle, + column, + ident, + (SQLPOINTER)pName, + BUFFER_LEN, + &nRealLen, + NULL + ),m_aStatementHandle,SQL_HANDLE_STMT,*this); + if(nRealLen > BUFFER_LEN) + { + delete pName; + pName = new char[nRealLen]; + OTools::ThrowException(N3SQLColAttribute(m_aStatementHandle, + column, + ident, + (SQLPOINTER)pName, + nRealLen, + &nRealLen, + NULL + ),m_aStatementHandle,SQL_HANDLE_STMT,*this); + } + + return ::rtl::OUString::createFromAscii(pName); +} +// ------------------------------------------------------------------------- +sal_Int32 OResultSetMetaData::getNumColAttrib(sal_Int32 _column,sal_Int32 ident) throw(starsdbc::SQLException, staruno::RuntimeException) +{ + sal_Int32 column = _column; + if(_column < m_vMapping.size()) // use mapping + column = m_vMapping[_column]; + + sal_Int32 nValue; + OTools::ThrowException(N3SQLColAttribute(m_aStatementHandle, + column, + ident, + NULL, + 0, + NULL, + &nValue),m_aStatementHandle,SQL_HANDLE_STMT,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(starsdbc::SQLException, staruno::RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_DISPLAY_SIZE); +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSetMetaData::getColumnType( sal_Int32 column ) throw(starsdbc::SQLException, staruno::RuntimeException) +{ + return OTools::MapOdbcType2Jdbc(getNumColAttrib(column,SQL_DESC_TYPE)); +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount( ) throw(starsdbc::SQLException, staruno::RuntimeException) +{ + if(m_nColCount != -1) + return m_nColCount; + sal_Int16 nNumResultCols=0; + OTools::ThrowException(N3SQLNumResultCols(m_aStatementHandle,&nNumResultCols),m_aStatementHandle,SQL_HANDLE_STMT,*this); + return m_nColCount = nNumResultCols; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive( sal_Int32 column ) throw(starsdbc::SQLException, staruno::RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_CASE_SENSITIVE) == SQL_TRUE; +} +// ------------------------------------------------------------------------- + +::rtl::OUString SAL_CALL OResultSetMetaData::getSchemaName( sal_Int32 column ) throw(starsdbc::SQLException, staruno::RuntimeException) +{ + return getCharColAttrib(column,SQL_DESC_SCHEMA_NAME); +} +// ------------------------------------------------------------------------- + +::rtl::OUString SAL_CALL OResultSetMetaData::getColumnName( sal_Int32 column ) throw(starsdbc::SQLException, staruno::RuntimeException) +{ + return getCharColAttrib(column,SQL_DESC_NAME); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getTableName( sal_Int32 column ) throw(starsdbc::SQLException, staruno::RuntimeException) +{ + return getCharColAttrib(column,SQL_DESC_TABLE_NAME); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getCatalogName( sal_Int32 column ) throw(starsdbc::SQLException, staruno::RuntimeException) +{ + return getCharColAttrib(column,SQL_DESC_CATALOG_NAME); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getColumnTypeName( sal_Int32 column ) throw(starsdbc::SQLException, staruno::RuntimeException) +{ + return getCharColAttrib(column,SQL_DESC_TYPE_NAME +); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getColumnLabel( sal_Int32 column ) throw(starsdbc::SQLException, staruno::RuntimeException) +{ + return getCharColAttrib(column,SQL_DESC_LABEL); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getColumnServiceName( sal_Int32 column ) throw(starsdbc::SQLException, staruno::RuntimeException) +{ + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isCurrency( sal_Int32 column ) throw(starsdbc::SQLException, staruno::RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_FIXED_PREC_SCALE) == SQL_TRUE; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement( sal_Int32 column ) throw(starsdbc::SQLException, staruno::RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_AUTO_UNIQUE_VALUE) == SQL_TRUE; +} +// ------------------------------------------------------------------------- + + +sal_Bool SAL_CALL OResultSetMetaData::isSigned( sal_Int32 column ) throw(starsdbc::SQLException, staruno::RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_UNSIGNED) == SQL_FALSE; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OResultSetMetaData::getPrecision( sal_Int32 column ) throw(starsdbc::SQLException, staruno::RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_PRECISION); +} +sal_Int32 SAL_CALL OResultSetMetaData::getScale( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_SCALE); +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSetMetaData::isNullable( sal_Int32 column ) throw(starsdbc::SQLException, staruno::RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_NULLABLE) == SQL_NULLABLE; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isSearchable( sal_Int32 column ) throw(starsdbc::SQLException, staruno::RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_SEARCHABLE) != SQL_PRED_NONE; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isReadOnly( sal_Int32 column ) throw(starsdbc::SQLException, staruno::RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_UPDATABLE) == SQL_ATTR_READONLY; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) throw(starsdbc::SQLException, staruno::RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_UPDATABLE) == SQL_ATTR_WRITE; +; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 column ) throw(starsdbc::SQLException, staruno::RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_UPDATABLE) == SQL_ATTR_WRITE; +} +// ------------------------------------------------------------------------- + diff --git a/connectivity/source/drivers/adabas/BTable.cxx b/connectivity/source/drivers/adabas/BTable.cxx new file mode 100644 index 000000000000..3452ed9b80df --- /dev/null +++ b/connectivity/source/drivers/adabas/BTable.cxx @@ -0,0 +1,590 @@ +/************************************************************************* + * + * $RCSfile: BTable.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADABAS_TABLE_HXX_ +#include "adabas/BTable.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_INDEXES_HXX_ +#include "adabas/BIndexes.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_COLUMNS_HXX_ +#include "adabas/BColumns.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_KEYS_HXX_ +#include "adabas/BKeys.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBCX_KEYTYPE_HPP_ +#include <com/sun/star/sdbcx/KeyType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_KEYRULE_HPP_ +#include <com/sun/star/sdbc/KeyRule.hpp> +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ +#include <com/sun/star/sdbc/ColumnValue.hpp> +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +using namespace connectivity::adabas; +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; + +OAdabasTable::OAdabasTable(OAdabasConnection* _pConnection) : OTable_TYPEDEF(sal_True) + ,m_pConnection(_pConnection) +{ + construct(); + ::std::vector< ::rtl::OUString> aVector; + m_pColumns = new OColumns(this,m_aMutex,aVector); + m_pKeys = new OKeys(this,m_aMutex,aVector); + m_pIndexes = new OIndexes(this,m_aMutex,aVector); +} +// ------------------------------------------------------------------------- +OAdabasTable::OAdabasTable( OAdabasConnection* _pConnection, + const ::rtl::OUString& _Name, + const ::rtl::OUString& _Type, + const ::rtl::OUString& _Description , + const ::rtl::OUString& _SchemaName, + const ::rtl::OUString& _CatalogName + ) : OTable_TYPEDEF(sal_True,_Name, + _Type, + _Description, + _SchemaName, + _CatalogName) + ,m_pConnection(_pConnection) +{ + construct(); + refreshColumns(); + refreshKeys(); + refreshIndexes(); +} +// ------------------------------------------------------------------------- +void OAdabasTable::refreshColumns() +{ + ::std::vector< ::rtl::OUString> aVector; + Reference< XResultSet > xResult = m_pConnection->getMetaData()->getColumns(Any(), + m_SchemaName,m_Name,::rtl::OUString::createFromAscii("%")); + + if(xResult.is()) + { + Reference< XRow > xRow(xResult,UNO_QUERY); + while(xResult->next()) + aVector.push_back(xRow->getString(4)); + } + + if(m_pColumns) + delete m_pColumns; + m_pColumns = new OColumns(this,m_aMutex,aVector); +} +// ------------------------------------------------------------------------- +void OAdabasTable::refreshPrimaryKeys(std::vector< ::rtl::OUString>& _rKeys) +{ + Reference< XResultSet > xResult = m_pConnection->getMetaData()->getPrimaryKeys(Any(),m_SchemaName,m_Name); + + if(xResult.is()) + { + Reference< XRow > xRow(xResult,UNO_QUERY); + if(xResult->next()) // there can be only one primary key + { + ::rtl::OUString aPkName = xRow->getString(6); + _rKeys.push_back(aPkName); + } + } +} +// ------------------------------------------------------------------------- +void OAdabasTable::refreshForgeinKeys(std::vector< ::rtl::OUString>& _rKeys) +{ + Reference< XResultSet > xResult = m_pConnection->getMetaData()->getExportedKeys(Any(),m_SchemaName,m_Name); + + if(xResult.is()) + { + Reference< XRow > xRow(xResult,UNO_QUERY); + while(xResult->next()) + _rKeys.push_back(xRow->getString(12)); + } +} +// ------------------------------------------------------------------------- +void OAdabasTable::refreshKeys() +{ + ::std::vector< ::rtl::OUString> aVector; + + refreshPrimaryKeys(aVector); + refreshForgeinKeys(aVector); + if(m_pKeys) + delete m_pKeys; + m_pKeys = new OKeys(this,m_aMutex,aVector); +} +// ------------------------------------------------------------------------- +void OAdabasTable::refreshIndexes() +{ + ::std::vector< ::rtl::OUString> aVector; + // fill indexes + Reference< XResultSet > xResult = m_pConnection->getMetaData()->getIndexInfo(Any(), + m_SchemaName,m_Name,sal_False,sal_False); + + if(xResult.is()) + { + Reference< XRow > xRow(xResult,UNO_QUERY); + ::rtl::OUString aName,aDot = ::rtl::OUString::createFromAscii("."); + while(xResult->next()) + { + aName = xRow->getString(5); + if(aName.getLength()) + aName += aDot; + aName += xRow->getString(6); + if(aName.getLength()) + aVector.push_back(aName); + } + } + + if(m_pIndexes) + delete m_pIndexes; + m_pIndexes = new OIndexes(this,m_aMutex,aVector); +} +// ------------------------------------------------------------------------- +Any SAL_CALL OAdabasTable::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = ::cppu::queryInterface(rType,static_cast< ::com::sun::star::lang::XUnoTunnel*> (this)); + if(aRet.hasValue()) + return aRet; + return OTable_TYPEDEF::queryInterface(rType); +} + +//-------------------------------------------------------------------------- +Sequence< sal_Int8 > OAdabasTable::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 OAdabasTable::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException) +{ + if (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) + return (sal_Int64)this; + + return 0; +} +// ------------------------------------------------------------------------- +sal_Bool OAdabasTable::create() throw(SQLException, RuntimeException) +{ + ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("CREATE TABLE "); + ::rtl::OUString aQuote = m_pConnection->getMetaData()->getIdentifierQuoteString( ); + ::rtl::OUString aDot = ::rtl::OUString::createFromAscii("."); + ::rtl::OUString aComma = ::rtl::OUString::createFromAscii(", "); + + aSql += aQuote + m_SchemaName + aQuote + aDot + aQuote + m_Name + aQuote; + aSql += ::rtl::OUString::createFromAscii(" ( "); + + sal_Int32 nCount = m_pColumns->getCount(); + Reference< XPropertySet > xProp; + for(sal_Int32 i=0;i<nCount;++i) + { + m_pColumns->getByIndex(i) >>= xProp; + aSql += aQuote + getString(xProp->getPropertyValue(PROPERTY_NAME)) + aQuote + + getString(xProp->getPropertyValue(PROPERTY_TYPENAME)); + + // add type definition + switch(getINT32(xProp->getPropertyValue(PROPERTY_TYPE))) + { + case DataType::CHAR: + case DataType::VARCHAR: + aSql += ::rtl::OUString::createFromAscii("(") + + ::rtl::OUString::valueOf(getINT32(xProp->getPropertyValue(PROPERTY_TYPE))) + + ::rtl::OUString::createFromAscii(")"); + break; + + case DataType::DECIMAL: + case DataType::NUMERIC: + aSql += ::rtl::OUString::createFromAscii("(") + + ::rtl::OUString::valueOf(getINT32(xProp->getPropertyValue(PROPERTY_TYPE))) + + ::rtl::OUString::createFromAscii(",") + + ::rtl::OUString::valueOf(getINT32(xProp->getPropertyValue(PROPERTY_SCALE))) + + ::rtl::OUString::createFromAscii(")"); + break; + } + + ::rtl::OUString aDefault = getString(xProp->getPropertyValue(PROPERTY_DEFAULTVALUE)); + if(getINT32(xProp->getPropertyValue(PROPERTY_ISNULLABLE)) == ColumnValue::NO_NULLS) + { + aSql += ::rtl::OUString::createFromAscii(" NOT NULL"); + if(aDefault.getLength()) + aSql += ::rtl::OUString::createFromAscii(" WITH DEFAULT"); + } + else if(aDefault.getLength()) + aSql += ::rtl::OUString::createFromAscii(" DEFAULT ") + aDefault; + + aSql += aComma; + } + + // create the key columns ( only the string ) + nCount = m_pKeys->getCount(); + + for(i=0;i<nCount;++i) + { + m_pKeys->getByIndex(i) >>= xProp; + Reference< XColumnsSupplier > xKey(xProp,UNO_QUERY); + Reference< ::com::sun::star::container::XIndexAccess > xCols(xKey->getColumns(),UNO_QUERY); + switch(getINT32(xProp->getPropertyValue(PROPERTY_TYPE))) + { + case KeyType::PRIMARY: + { + sal_Int32 nCols = xCols->getCount(); + if(nCols) + aSql += ::rtl::OUString::createFromAscii(" PRIMARY KEY( "); + for(sal_Int32 i=0;i<nCols;++i) + { + xCols->getByIndex(i) >>= xProp; + aSql += aQuote + getString(xProp->getPropertyValue(PROPERTY_NAME)) + aQuote; + aSql += aComma; + } + if(nCols) + aSql = aSql.replaceAt(aSql.getLength()-1,1,::rtl::OUString::createFromAscii(")")); + } + case KeyType::UNIQUE: + { + sal_Int32 nCols = xCols->getCount(); + if(nCols) + aSql += ::rtl::OUString::createFromAscii(" UNIQUE( "); + for(sal_Int32 i=0;i<nCols;++i) + { + xCols->getByIndex(i) >>= xProp; + aSql += aQuote + getString(xProp->getPropertyValue(PROPERTY_NAME)) + aQuote; + aSql += aComma; + } + if(nCols) + aSql = aSql.replaceAt(aSql.getLength()-1,1,::rtl::OUString::createFromAscii(")")); + } + case KeyType::FOREIGN: + { + sal_Int32 nCols = xCols->getCount(); + if(nCols) + { + aSql += ::rtl::OUString::createFromAscii(" FOREIGN KEY( "); + ::rtl::OUString aKeyName = getString(xProp->getPropertyValue(PROPERTY_NAME)); + ::rtl::OUString aRefTableName = getString(xProp->getPropertyValue(PROPERTY_REFERENCEDTABLE)); + sal_Int32 nDeleteRule = getINT32(xProp->getPropertyValue(PROPERTY_DELETERULE)); + if(aKeyName.getLength()) + { + aSql += aQuote + aKeyName + aQuote; + aSql += ::rtl::OUString::createFromAscii(" "); + } + + for(sal_Int32 i=0;i<nCols;++i) + { + xCols->getByIndex(i) >>= xProp; + aSql += aQuote + getString(xProp->getPropertyValue(PROPERTY_NAME)) + aQuote; + aSql += aComma; + } + aSql = aSql.replaceAt(aSql.getLength()-1,1,::rtl::OUString::createFromAscii(")")); + aSql += ::rtl::OUString::createFromAscii(" REFERENCES ") + + aQuote + aRefTableName + aQuote; + switch(nDeleteRule) + { + case KeyRule::CASCADE: + aSql += ::rtl::OUString::createFromAscii(" ON DELETE CASCADE "); + break; + case KeyRule::RESTRICT: + aSql += ::rtl::OUString::createFromAscii(" ON DELETE RESTRICT "); + break; + case KeyRule::SET_NULL: + aSql += ::rtl::OUString::createFromAscii(" ON DELETE SET NULL "); + break; + case KeyRule::NO_ACTION: + break; + case KeyRule::SET_DEFAULT: + aSql += ::rtl::OUString::createFromAscii(" ON DELETE SET DEFAULT "); + break; + } + } + + } + } + } + Reference< XStatement > xStmt = m_pConnection->createStatement( ); + xStmt->execute(aSql); + return sal_True; +} +// ------------------------------------------------------------------------- +// XRename +void SAL_CALL OAdabasTable::rename( const ::rtl::OUString& newName ) throw(SQLException, ElementExistException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_aMutex); + if ( +#ifdef GCC + sdbcx::OTable_BASE::rBHelper.bDisposed +#else + rBHelper.bDisposed +#endif + ) + throw DisposedException(); + + if(!isNew()) + { + ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("RENAME TABLE "); + ::rtl::OUString aQuote = m_pConnection->getMetaData()->getIdentifierQuoteString( ); + ::rtl::OUString aDot = ::rtl::OUString::createFromAscii("."); + + ::rtl::OUString aName,aSchema; + sal_Int32 nLen = newName.indexOf('.'); + aSchema = newName.copy(0,nLen); + aName = newName.copy(nLen+1); + + aSql += aQuote + m_SchemaName + aQuote + aDot + aQuote + m_Name + aQuote + + ::rtl::OUString::createFromAscii(" TO ") + + aQuote + aSchema + aQuote + aDot + aQuote + aName + aQuote; + + Reference< XStatement > xStmt = m_pConnection->createStatement( ); + xStmt->execute(aSql); + } + else + m_Name = newName; +} +// ------------------------------------------------------------------------- +// XAlterTable +void SAL_CALL OAdabasTable::alterColumnByName( const ::rtl::OUString& colName, const Reference< XPropertySet >& descriptor ) throw(SQLException, NoSuchElementException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_aMutex); + if ( +#ifdef GCC + sdbcx::OTable_BASE::rBHelper.bDisposed +#else + rBHelper.bDisposed +#endif + ) + throw DisposedException(); + + if(!isNew()) + { + ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("ALTER TABLE "); + ::rtl::OUString aQuote = m_pConnection->getMetaData()->getIdentifierQuoteString( ); + ::rtl::OUString aDot = ::rtl::OUString::createFromAscii("."); + + aSql += aQuote + m_SchemaName + aQuote + aDot + aQuote + m_Name + aQuote + + ::rtl::OUString::createFromAscii(" COLUMN ") + + aQuote + colName + aQuote + + ::rtl::OUString::createFromAscii(" ALTER "); + + aSql += aQuote + getString(descriptor->getPropertyValue(PROPERTY_NAME)) + aQuote + + getString(descriptor->getPropertyValue(PROPERTY_TYPENAME)); + + switch(getINT32(descriptor->getPropertyValue(PROPERTY_TYPE))) + { + case DataType::CHAR: + case DataType::VARCHAR: + aSql += ::rtl::OUString::createFromAscii("(") + + ::rtl::OUString::valueOf(getINT32(descriptor->getPropertyValue(PROPERTY_TYPE))) + + ::rtl::OUString::createFromAscii(")"); + break; + + case DataType::DECIMAL: + case DataType::NUMERIC: + aSql += ::rtl::OUString::createFromAscii("(") + + ::rtl::OUString::valueOf(getINT32(descriptor->getPropertyValue(PROPERTY_TYPE))) + + ::rtl::OUString::createFromAscii(",") + + ::rtl::OUString::valueOf(getINT32(descriptor->getPropertyValue(PROPERTY_SCALE))) + + ::rtl::OUString::createFromAscii(")"); + break; + } + ::rtl::OUString aDefault = getString(descriptor->getPropertyValue(PROPERTY_DEFAULTVALUE)); + if(getINT32(descriptor->getPropertyValue(PROPERTY_ISNULLABLE)) == ColumnValue::NO_NULLS) + { + aSql += ::rtl::OUString::createFromAscii(" NOT NULL"); + if(aDefault.getLength()) + aSql += ::rtl::OUString::createFromAscii(" WITH DEFAULT"); + } + else if(aDefault.getLength()) + aSql += ::rtl::OUString::createFromAscii(" DEFAULT ") + aDefault; + + Reference< XStatement > xStmt = m_pConnection->createStatement( ); + xStmt->execute(aSql); + + refreshColumns(); + } + else + { + if(m_pColumns) + { + m_pColumns->dropByName(colName); + m_pColumns->appendByDescriptor(descriptor); + } + } + +} +// ------------------------------------------------------------------------- +void SAL_CALL OAdabasTable::alterColumnByIndex( sal_Int32 index, const Reference< XPropertySet >& descriptor ) throw(SQLException, ::com::sun::star::lang::IndexOutOfBoundsException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_aMutex); + if ( +#ifdef GCC + sdbcx::OTable_BASE::rBHelper.bDisposed +#else + rBHelper.bDisposed +#endif + ) + throw DisposedException(); + + Reference< XPropertySet > xOld; + if(m_pColumns->getByIndex(index) >>= xOld) + alterColumnByName(getString(xOld->getPropertyValue(PROPERTY_NAME)),descriptor); +} + +// ------------------------------------------------------------------------- +::rtl::OUString connectivity::adabas::getTypeString(const Reference< ::com::sun::star::beans::XPropertySet >& xColProp) +{ + ::rtl::OUString aValue; + switch(getINT32(xColProp->getPropertyValue(PROPERTY_TYPE))) + { + case DataType::BIT: + aValue = ::rtl::OUString::createFromAscii("BOOLEAN"); + break; + case DataType::TINYINT: + aValue = ::rtl::OUString::createFromAscii("SMALLINT"); + break; + case DataType::SMALLINT: + aValue = ::rtl::OUString::createFromAscii("SMALLINT"); + break; + case DataType::INTEGER: + aValue = ::rtl::OUString::createFromAscii("INT"); + break; + case DataType::FLOAT: + aValue = ::rtl::OUString::createFromAscii("FLOAT"); + break; + case DataType::REAL: + aValue = ::rtl::OUString::createFromAscii("REAL"); + break; + case DataType::DOUBLE: + aValue = ::rtl::OUString::createFromAscii("DOUBLE"); + break; + case DataType::NUMERIC: + aValue = ::rtl::OUString::createFromAscii("DECIMAL"); + break; + case DataType::DECIMAL: + aValue = ::rtl::OUString::createFromAscii("DECIMAL"); + break; + case DataType::CHAR: + aValue = ::rtl::OUString::createFromAscii("CHAR"); + break; + case DataType::VARCHAR: + aValue = ::rtl::OUString::createFromAscii("VARCHAR"); + break; + case DataType::LONGVARCHAR: + aValue = ::rtl::OUString::createFromAscii("LONG VARCHAR"); + break; + case DataType::DATE: + aValue = ::rtl::OUString::createFromAscii("DATE"); + break; + case DataType::TIME: + aValue = ::rtl::OUString::createFromAscii("TIME"); + break; + case DataType::TIMESTAMP: + aValue = ::rtl::OUString::createFromAscii("TIMESTAMP"); + break; + case DataType::BINARY: + aValue = ::rtl::OUString::createFromAscii("BOOLEAN"); + break; + case DataType::VARBINARY: + aValue = ::rtl::OUString::createFromAscii("VARCHAR BYTE"); + break; + case DataType::LONGVARBINARY: + aValue = ::rtl::OUString::createFromAscii("LONG BYTE"); + break; + } + return aValue; +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OAdabasTable::getTypes( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > *)0 )); + + return ::utl::concatSequences(aTypes.getTypes(),OTable_TYPEDEF::getTypes()); +} + + + diff --git a/connectivity/source/drivers/adabas/BTables.cxx b/connectivity/source/drivers/adabas/BTables.cxx new file mode 100644 index 000000000000..93c4e3961715 --- /dev/null +++ b/connectivity/source/drivers/adabas/BTables.cxx @@ -0,0 +1,419 @@ +/************************************************************************* + * + * $RCSfile: BTables.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADABAS_TABLES_HXX_ +#include "adabas/BTables.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_TABLE_HXX_ +#include "adabas/BTable.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ +#include <com/sun/star/sdbc/ColumnValue.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_KEYRULE_HPP_ +#include <com/sun/star/sdbc/KeyRule.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBCX_KEYTYPE_HPP_ +#include <com/sun/star/sdbcx/KeyType.hpp> +#endif +#ifndef _CONNECTIVITY_ADABAS_CATALOG_HXX_ +#include "adabas/BCatalog.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_BCONNECTION_HXX_ +#include "adabas/BConnection.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +using namespace connectivity::adabas; +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; +typedef connectivity::sdbcx::OCollection OCollection_TYPE; + +Reference< XNamed > OTables::createObject(const ::rtl::OUString& _rName) +{ + ::rtl::OUString aName,aSchema; + sal_Int32 nLen = _rName.indexOf('.'); + aSchema = _rName.copy(0,nLen); + aName = _rName.copy(nLen+1); + + Sequence< ::rtl::OUString > aTypes(1); + aTypes[0] = ::rtl::OUString::createFromAscii("%"); + // aTypes[0] = ::rtl::OUString::createFromAscii("TABLE"); + // aTypes[1] = ::rtl::OUString::createFromAscii("SYSTEMTABLE"); + + Reference< XResultSet > xResult = m_xMetaData->getTables(Any(), + aSchema,aName,aTypes); + + Reference< XNamed > xRet = NULL; + if(xResult.is()) + { + Reference< XRow > xRow(xResult,UNO_QUERY); + if(xResult->next()) // there can be only one table with this name + { + OAdabasTable* pRet = new OAdabasTable( static_cast<OAdabasCatalog&>(m_rParent).getConnection(), + aName,xRow->getString(4),xRow->getString(5),aSchema); + xRet = pRet; + } + } + + return xRet; +} +// ------------------------------------------------------------------------- +void OTables::impl_refresh( ) throw(RuntimeException) +{ + static_cast<OAdabasCatalog&>(m_rParent).refreshTables(); +} +// ------------------------------------------------------------------------- +void OTables::disposing(void) +{ + m_xMetaData = NULL; + OCollection::disposing(); +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > OTables::createEmptyObject() +{ + OAdabasTable* pNew = new OAdabasTable(static_cast<OAdabasCatalog&>(m_rParent).getConnection()); + return pNew; +} +// ------------------------------------------------------------------------- +// XAppend +void SAL_CALL OTables::appendByDescriptor( const Reference< XPropertySet >& descriptor ) throw(SQLException, ElementExistException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + ::rtl::OUString aName = getString(descriptor->getPropertyValue(PROPERTY_NAME)); + ObjectMap::iterator aIter = m_aNameMap.find(aName); + if( aIter != m_aNameMap.end()) + throw ElementExistException(aName,*this); + + ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("CREATE TABLE "); + ::rtl::OUString aQuote = static_cast<OAdabasCatalog&>(m_rParent).getConnection()->getMetaData()->getIdentifierQuoteString( ); + ::rtl::OUString aDot = ::rtl::OUString::createFromAscii("."); + + aSql = aSql + aQuote + getString(descriptor->getPropertyValue(PROPERTY_SCHEMANAME)) + aQuote + aDot + + aQuote + getString(descriptor->getPropertyValue(PROPERTY_NAME)) + aQuote + + ::rtl::OUString::createFromAscii(" ("); + + // columns + Reference<XColumnsSupplier> xColumnSup(descriptor,UNO_QUERY); + Reference<XIndexAccess> xColumns(xColumnSup->getColumns(),UNO_QUERY); + Reference< XPropertySet > xColProp; + + Any aTypeName; + for(sal_Int32 i=0;i<xColumns->getCount();++i) + { + if(xColumns->getByIndex(i) >>= xColProp) + { + + aSql = aSql + aQuote + getString(xColProp->getPropertyValue(PROPERTY_NAME)) + aQuote; + + aSql = aSql + ::rtl::OUString::createFromAscii(" "); + + aTypeName = xColProp->getPropertyValue(PROPERTY_TYPENAME); + + if(aTypeName.hasValue() && getString(aTypeName).getLength()) + aSql = aSql + getString(aTypeName); + else + aSql = aSql + getTypeString(xColProp) + ::rtl::OUString::createFromAscii(" "); + + switch(getINT32(xColProp->getPropertyValue(PROPERTY_TYPE))) + { + case DataType::CHAR: + case DataType::VARCHAR: + aSql = aSql + ::rtl::OUString::createFromAscii("(") + + ::rtl::OUString::valueOf(getINT32(xColProp->getPropertyValue(PROPERTY_PRECISION))) + + ::rtl::OUString::createFromAscii(")"); + break; + + case DataType::DECIMAL: + case DataType::NUMERIC: + aSql = aSql + ::rtl::OUString::createFromAscii("(") + + ::rtl::OUString::valueOf(getINT32(xColProp->getPropertyValue(PROPERTY_PRECISION))) + + ::rtl::OUString::createFromAscii(",") + + ::rtl::OUString::valueOf(getINT32(xColProp->getPropertyValue(PROPERTY_SCALE))) + + ::rtl::OUString::createFromAscii(")"); + break; + } + ::rtl::OUString aDefault = getString(xColProp->getPropertyValue(PROPERTY_DEFAULTVALUE)); + if(getINT32(xColProp->getPropertyValue(PROPERTY_ISNULLABLE)) == ColumnValue::NO_NULLS) + { + aSql = aSql + ::rtl::OUString::createFromAscii(" NOT NULL"); + if(aDefault.getLength()) + aSql = aSql + ::rtl::OUString::createFromAscii(" WITH DEFAULT"); + } + else if(aDefault.getLength()) + aSql = aSql + ::rtl::OUString::createFromAscii(" DEFAULT ") + aDefault; + + aSql = aSql + ::rtl::OUString::createFromAscii(","); + } + } + aSql = aSql.replaceAt(aSql.getLength()-1,1,::rtl::OUString::createFromAscii(")")); + + // keys + + Reference<XKeysSupplier> xKeySup(descriptor,UNO_QUERY); + + Reference<XIndexAccess> xKeys = xKeySup->getKeys(); + if(xKeys.is()) + { + sal_Bool bPKey = sal_False; + for(sal_Int32 i=0;i<xKeys->getCount();++i) + { + if(xColumns->getByIndex(i) >>= xColProp) + { + + sal_Int32 nKeyType = getINT32(xColProp->getPropertyValue(PROPERTY_TYPE)); + + if(nKeyType == KeyType::PRIMARY) + { + if(!bPKey) + throw SQLException(); + + bPKey = sal_True; + xColumnSup = Reference<XColumnsSupplier>(xColProp,UNO_QUERY); + xColumns = Reference<XIndexAccess>(xColumnSup->getColumns(),UNO_QUERY); + if(!xColumns->getCount()) + throw SQLException(); + + aSql = aSql + ::rtl::OUString::createFromAscii(" PRIMARY KEY ("); + for(sal_Int32 i=0;i<xColumns->getCount();++i) + { + if(xColumns->getByIndex(i) >>= xColProp) + aSql = aSql + aQuote + getString(xColProp->getPropertyValue(PROPERTY_NAME)) + aQuote + + ::rtl::OUString::createFromAscii(","); + } + + aSql = aSql.replaceAt(aSql.getLength()-1,1,::rtl::OUString::createFromAscii(")")); + } + else if(nKeyType == KeyType::UNIQUE) + { + xColumnSup = Reference<XColumnsSupplier>(xColProp,UNO_QUERY); + xColumns = Reference<XIndexAccess>(xColumnSup->getColumns(),UNO_QUERY); + if(!xColumns->getCount()) + throw SQLException(); + + aSql = aSql + ::rtl::OUString::createFromAscii(" UNIQUE ("); + for(sal_Int32 i=0;i<xColumns->getCount();++i) + { + if(xColumns->getByIndex(i) >>= xColProp) + aSql = aSql + aQuote + getString(xColProp->getPropertyValue(PROPERTY_NAME)) + aQuote + + ::rtl::OUString::createFromAscii(","); + } + + aSql = aSql.replaceAt(aSql.getLength()-1,1,::rtl::OUString::createFromAscii(")")); + } + else if(nKeyType == KeyType::FOREIGN) + { + sal_Int32 nDeleteRule = getINT32(xColProp->getPropertyValue(PROPERTY_DELETERULE)); + + xColumnSup = Reference<XColumnsSupplier>(xColProp,UNO_QUERY); + xColumns = Reference<XIndexAccess>(xColumnSup->getColumns(),UNO_QUERY); + if(!xColumns->getCount()) + throw SQLException(); + + aSql = aSql + ::rtl::OUString::createFromAscii(" FOREIGN KEY "); + ::rtl::OUString aName,aSchema,aRefTable = getString(xColProp->getPropertyValue(PROPERTY_REFERENCEDTABLE)); + sal_Int32 nLen = aRefTable.indexOf('.'); + aSchema = aRefTable.copy(0,nLen); + aName = aRefTable.copy(nLen+1); + + aSql = aSql + aQuote + aSchema + aQuote + aDot + + aQuote + aName + aQuote + + ::rtl::OUString::createFromAscii(" ("); + + for(sal_Int32 i=0;i<xColumns->getCount();++i) + { + if(xColumns->getByIndex(i) >>= xColProp) + aSql = aSql + aQuote + getString(xColProp->getPropertyValue(PROPERTY_NAME)) + aQuote + + ::rtl::OUString::createFromAscii(","); + } + + aSql = aSql.replaceAt(aSql.getLength()-1,1,::rtl::OUString::createFromAscii(")")); + + switch(nDeleteRule) + { + case KeyRule::CASCADE: + aSql = aSql + ::rtl::OUString::createFromAscii(" ON DELETE CASCADE "); + break; + case KeyRule::RESTRICT: + aSql = aSql + ::rtl::OUString::createFromAscii(" ON DELETE RESTRICT "); + break; + case KeyRule::SET_NULL: + aSql = aSql + ::rtl::OUString::createFromAscii(" ON DELETE SET NULL "); + break; + case KeyRule::SET_DEFAULT: + aSql = aSql + ::rtl::OUString::createFromAscii(" ON DELETE SET DEFAULT "); + break; + default: + ; + } + } + } + } + } + + OAdabasConnection* pConnection = static_cast<OAdabasCatalog&>(m_rParent).getConnection(); + Reference< XStatement > xStmt = pConnection->createStatement( ); + xStmt->execute(aSql); + + if(getString(descriptor->getPropertyValue(PROPERTY_DESCRIPTION)).getLength()) + setComments(descriptor); + + + OCollection_TYPE::appendByDescriptor(descriptor); +} +// ------------------------------------------------------------------------- +void OTables::setComments(const Reference< XPropertySet >& descriptor ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("CREATE TABLE "); + ::rtl::OUString aQuote = static_cast<OAdabasCatalog&>(m_rParent).getConnection()->getMetaData()->getIdentifierQuoteString( ); + ::rtl::OUString aDot = ::rtl::OUString::createFromAscii("."); + + OAdabasConnection* pConnection = static_cast<OAdabasCatalog&>(m_rParent).getConnection(); + Reference< XStatement > xStmt = pConnection->createStatement( ); + aSql = ::rtl::OUString::createFromAscii("COMMENT ON TABLE ") + + aQuote + getString(descriptor->getPropertyValue(PROPERTY_SCHEMANAME)) + aQuote + aDot + + aQuote + getString(descriptor->getPropertyValue(PROPERTY_NAME)) + aQuote + + ::rtl::OUString::createFromAscii(" '") + + getString(descriptor->getPropertyValue(PROPERTY_DESCRIPTION)) + + ::rtl::OUString::createFromAscii("'"); + xStmt->execute(aSql); + + // columns + Reference<XColumnsSupplier> xColumnSup(descriptor,UNO_QUERY); + Reference<XIndexAccess> xColumns(xColumnSup->getColumns(),UNO_QUERY); + Reference< XPropertySet > xColProp; + + aSql = ::rtl::OUString::createFromAscii("COMMENT ON COLUMN ") + + aQuote + getString(descriptor->getPropertyValue(PROPERTY_SCHEMANAME)) + aQuote + aDot + + aQuote + getString(descriptor->getPropertyValue(PROPERTY_NAME)) + aQuote + aDot + + aQuote; + + for(sal_Int32 i=0;i<xColumns->getCount();++i) + { + xColumns->getByIndex(i) >>= xColProp; + ::rtl::OUString aDescription = getString(xColProp->getPropertyValue(PROPERTY_DESCRIPTION)); + if(aDescription.getLength()) + { + ::rtl::OUString aCom = aSql + getString(xColProp->getPropertyValue(PROPERTY_NAME)) + aQuote + + ::rtl::OUString::createFromAscii(" '") + + aDescription + + ::rtl::OUString::createFromAscii("'"); + xStmt->execute(aSql); + } + } +} +// ------------------------------------------------------------------------- +// XDrop +void SAL_CALL OTables::dropByName( const ::rtl::OUString& elementName ) throw(SQLException, NoSuchElementException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + ObjectMap::iterator aIter = m_aNameMap.find(elementName); + if( aIter == m_aNameMap.end()) + throw NoSuchElementException(elementName,*this); + + Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(aIter->second.get(),UNO_QUERY); + if(xTunnel.is()) + { + OAdabasTable* pTable = (OAdabasTable*)xTunnel->getSomething(OAdabasTable:: getUnoTunnelImplementationId()); + + if(!pTable->isNew()) + { + OAdabasConnection* pConnection = static_cast<OAdabasCatalog&>(m_rParent).getConnection(); + Reference< XStatement > xStmt = pConnection->createStatement( ); + + ::rtl::OUString aName,aSchema; + sal_Int32 nLen = elementName.indexOf('.'); + aSchema = elementName.copy(0,nLen); + aName = elementName.copy(nLen+1); + ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("DROP TABLE "); + aSql = aSql + m_xMetaData->getIdentifierQuoteString( ) + aSchema + m_xMetaData->getIdentifierQuoteString( ); + aSql = aSql + ::rtl::OUString::createFromAscii("."); + aSql = aSql + m_xMetaData->getIdentifierQuoteString( ) + aName + m_xMetaData->getIdentifierQuoteString( ); + xStmt->execute(aSql); + } + } + + OCollection_TYPE::dropByName(elementName); +} +// ------------------------------------------------------------------------- +void SAL_CALL OTables::dropByIndex( sal_Int32 index ) throw(SQLException, IndexOutOfBoundsException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + if (index < 0 || index >= getCount()) + throw IndexOutOfBoundsException(); + + dropByName((*m_aElements[index]).first); +} +// ------------------------------------------------------------------------- + + diff --git a/connectivity/source/drivers/adabas/BUser.cxx b/connectivity/source/drivers/adabas/BUser.cxx new file mode 100644 index 000000000000..b017fc2d1f18 --- /dev/null +++ b/connectivity/source/drivers/adabas/BUser.cxx @@ -0,0 +1,151 @@ +/************************************************************************* + * + * $RCSfile: BUser.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADABAS_USER_HXX_ +#include "adabas/BUser.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_GROUPS_HXX_ +#include "adabas/BGroups.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _CONNECTIVITY_ADABAS_BCONNECTION_HXX_ +#include "adabas/BConnection.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif + +using namespace connectivity::adabas; +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; +// ------------------------------------------------------------------------- +OAdabasUser::OAdabasUser( OAdabasConnection* _pConnection) : connectivity::sdbcx::OUser(sal_True) + ,m_pConnection(_pConnection) +{ + construct(); +} +// ------------------------------------------------------------------------- +OAdabasUser::OAdabasUser( OAdabasConnection* _pConnection, + const ::rtl::OUString& _Name + ) : connectivity::sdbcx::OUser(_Name,sal_True) + ,m_pConnection(_pConnection) +{ + construct(); +} +// ------------------------------------------------------------------------- +Any SAL_CALL OAdabasUser::queryInterface( const Type & rType ) throw(RuntimeException) +{ +// if(rType == ::getCppuType((const ::com::sun::star::uno::Reference< XGroupsSupplier>*)0)) +// return Any(); + + return OUser_TYPEDEF::queryInterface(rType); +} +// ------------------------------------------------------------------------- +void OAdabasUser::refreshGroups() +{ + if(!m_pConnection) + return; + + ::std::vector< ::rtl::OUString> aVector; + Reference< XStatement > xStmt = m_pConnection->createStatement( ); + ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("SELECT DISTINCT GROUPNAME FROM DOMAIN.USERS WHERE GROUPNAME IS NOT NULL AND GROUPNAME <> ' ' AND USERNAME = '"); + aSql += getName( ); + aSql += ::rtl::OUString::createFromAscii("'"); + + Reference< XResultSet > xResult = xStmt->executeQuery(aSql); + if(xResult.is()) + { + Reference< XRow > xRow(xResult,UNO_QUERY); + while(xResult->next()) + aVector.push_back(xRow->getString(1)); + } + + if(m_pGroups) + delete m_pGroups; + m_pGroups = new OGroups(*this,m_aMutex,aVector,m_pConnection,this); +} +// ------------------------------------------------------------------------- +OUserExtend::OUserExtend( OAdabasConnection* _pConnection) : OAdabasUser(_pConnection) +{ + construct(); +} +// ------------------------------------------------------------------------- +OUserExtend::OUserExtend( OAdabasConnection* _pConnection,const ::rtl::OUString& _Name) : OAdabasUser(_pConnection,_Name) +{ + construct(); +} +// ------------------------------------------------------------------------- +typedef connectivity::sdbcx::OUser OUser_TYPEDEF; +void OUserExtend::construct() +{ + OUser_TYPEDEF::construct(); + registerProperty(PROPERTY_PASSWORD, PROPERTY_ID_PASSWORD,0,&m_Password,::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); +} + diff --git a/connectivity/source/drivers/adabas/BUsers.cxx b/connectivity/source/drivers/adabas/BUsers.cxx new file mode 100644 index 000000000000..50d896c0b05a --- /dev/null +++ b/connectivity/source/drivers/adabas/BUsers.cxx @@ -0,0 +1,160 @@ +/************************************************************************* + * + * $RCSfile: BUsers.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADABAS_USERS_HXX_ +#include "adabas/BUsers.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_USER_HXX_ +#include "adabas/BUser.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_TABLE_HXX_ +#include "adabas/BTable.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _CONNECTIVITY_SDBCX_IREFRESHABLE_HXX_ +#include "connectivity/sdbcx/IRefreshable.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +using namespace connectivity::adabas; +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; +typedef connectivity::sdbcx::OCollection OCollection_TYPE; + +Reference< XNamed > OUsers::createObject(const ::rtl::OUString& _rName) +{ + OAdabasUser* pRet = new OAdabasUser(m_pConnection,_rName); + Reference< XNamed > xRet = pRet; + return xRet; +} +// ------------------------------------------------------------------------- +void OUsers::impl_refresh() throw(RuntimeException) +{ + m_pParent->refreshUsers(); +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > OUsers::createEmptyObject() +{ + OUserExtend* pNew = new OUserExtend(m_pConnection); + return pNew; +} +// ------------------------------------------------------------------------- +// XAppend +void SAL_CALL OUsers::appendByDescriptor( const Reference< XPropertySet >& descriptor ) throw(SQLException, ElementExistException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + ::rtl::OUString aName = getString(descriptor->getPropertyValue(PROPERTY_NAME)); + ObjectMap::iterator aIter = m_aNameMap.find(aName); + if( aIter != m_aNameMap.end()) + throw ElementExistException(aName,*this); + + ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("CREATE USER "); + ::rtl::OUString aQuote = m_pConnection->getMetaData()->getIdentifierQuoteString( ); + + aSql = aSql + aQuote + getString(descriptor->getPropertyValue(PROPERTY_NAME)) + aQuote + + ::rtl::OUString::createFromAscii(" PASSWORD ") + + getString(descriptor->getPropertyValue(PROPERTY_PASSWORD)); + + Reference< XStatement > xStmt = m_pConnection->createStatement( ); + xStmt->execute(aSql); + + OCollection_TYPE::appendByDescriptor(descriptor); +} +// ------------------------------------------------------------------------- +// XDrop +void SAL_CALL OUsers::dropByName( const ::rtl::OUString& elementName ) throw(SQLException, NoSuchElementException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + ObjectMap::iterator aIter = m_aNameMap.find(elementName); + if( aIter == m_aNameMap.end()) + throw NoSuchElementException(elementName,*this); + + ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("DROP USER "); + ::rtl::OUString aQuote = m_pConnection->getMetaData()->getIdentifierQuoteString( ); + + aSql = aSql + aQuote + elementName + aQuote; + + Reference< XStatement > xStmt = m_pConnection->createStatement( ); + xStmt->execute(aSql); + + OCollection_TYPE::dropByName(elementName); +} + +// ------------------------------------------------------------------------- +void SAL_CALL OUsers::dropByIndex( sal_Int32 index ) throw(SQLException, IndexOutOfBoundsException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + if (index < 0 || index >= getCount()) + throw IndexOutOfBoundsException(); + + dropByName(m_aElements[index]->first); +} + diff --git a/connectivity/source/drivers/adabas/Bservices.cxx b/connectivity/source/drivers/adabas/Bservices.cxx new file mode 100644 index 000000000000..7485587dc4b8 --- /dev/null +++ b/connectivity/source/drivers/adabas/Bservices.cxx @@ -0,0 +1,212 @@ +/************************************************************************* + * + * $RCSfile: Bservices.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADABAS_BDRIVER_HXX_ +#include "adabas/BDriver.hxx" +#endif +#ifndef _CPPUHELPER_FACTORY_HXX_ +#include <cppuhelper/factory.hxx> +#endif +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +using namespace connectivity::adabas; +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 + ); + +//*************************************************************************************** +// +// 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_ENSHURE(xNewKey.is(), "ADABAS::component_writeInfo : could not create a registry key !"); + + for (sal_uInt32 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); + } + catch(...) + { + } + return xRet.is(); + } + + void* getProvider() const { return xRet.get(); } +}; + +//--------------------------------------------------------------------------------------- + +extern "C" void SAL_CALL component_getImplementationEnvironment( + const sal_Char **ppEnvTypeName, + uno_Environment **ppEnv + ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +//--------------------------------------------------------------------------------------- +extern "C" 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( + ODriver::getImplementationName_Static(), + ODriver::getSupportedServiceNames_Static(), xKey); + + return sal_True; + } + catch (::com::sun::star::registry::InvalidRegistryException& ) + { + OSL_ENSHURE(sal_False, "ODBC::component_writeInfo : could not create a registry key ! ## InvalidRegistryException !"); + } + + return sal_False; +} + +//--------------------------------------------------------------------------------------- +extern "C" 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( + ODriver::getImplementationName_Static(), + ODriver::getSupportedServiceNames_Static(), + ODriver_CreateInstance, ::cppu::createSingleFactory) + ; + + if(aReq.xRet.is()) + aReq.xRet->acquire(); + + pRet = aReq.getProvider(); + } + + return pRet; +}; + + diff --git a/connectivity/source/drivers/adabas/adabas.map b/connectivity/source/drivers/adabas/adabas.map new file mode 100644 index 000000000000..7ce4c703e6b3 --- /dev/null +++ b/connectivity/source/drivers/adabas/adabas.map @@ -0,0 +1,8 @@ +ADABAS_2_0 { + global: + component_getImplementationEnvironment; + component_writeInfo; + component_getFactory; + local: + *; +}; diff --git a/connectivity/source/drivers/adabas/adabas.xml b/connectivity/source/drivers/adabas/adabas.xml new file mode 100644 index 000000000000..40070e191e75 --- /dev/null +++ b/connectivity/source/drivers/adabas/adabas.xml @@ -0,0 +1,70 @@ +<?xml version='1.0' encoding="UTF-8"?> +<!DOCTYPE COMPONENTDESCRIPTION PUBLIC "-//W3C//DTD HTML 3.2//EN" "componentdependencies.dtd"> +<COMPONENTDESCRIPTION> + +<Name> com.sun.star.sdbc.BDriver </Name> + +<Description> + This is the implementation of the sdbc-odbc bridge. +</Description> + +<ModuleName> odbc </ModuleName> + +<LoaderName> com.sun.star.loader.SharedLibrary </LoaderName> + +<SupportedService> com.sun.star.sdbc.Driver </SupportedService> + +<ServiceDependency> ... </ServiceDependency> + +<ProjectBuildDependency> cppuhelper </ProjectBuildDependency> +<ProjectBuildDependency> cppu </ProjectBuildDependency> +<ProjectBuildDependency> sal </ProjectBuildDependency> +<ProjectBuildDependency> vos </ProjectBuildDependency> + +<RuntimeModuleDependency> cppuhelper </RuntimeModuleDependency> +<RuntimeModuleDependency> cppu1 </RuntimeModuleDependency> +<RuntimeModuleDependency> sal1 </RuntimeModuleDependency> +<RuntimeModuleDependency> vos </RuntimeModuleDependency> + +<Language> c++ </Language> + +<Status StatusValue="final"/> + +<Type> com.sun.star.util.XCancellable </Type> +<Type> com.sun.star.util.XNumberFormatter </Type> +<Type> com.sun.star.uno.TypeClass </Type> +<Type> com.sun.star.uno.XWeak </Type> +<Type> com.sun.star.uno.XAggregation </Type> +<Type> com.sun.star.beans.XPropertyState </Type> +<Type> com.sun.star.beans.XPropertySet </Type> +<Type> com.sun.star.beans.PropertyValue </Type> +<Type> com.sun.star.beans.XMultiPropertySet </Type> +<Type> com.sun.star.beans.XFastPropertySet </Type> +<Type> com.sun.star.lang.XTypeProvider </Type> +<Type> com.sun.star.lang.EventObject </Type> +<Type> com.sun.star.lang.XComponent </Type> +<Type> com.sun.star.lang.IllegalArgumentException </Type> +<Type> com.sun.star.lang.XMultiServiceFactory </Type> +<Type> com.sun.star.java.XJavaThreadRegister_11 </Type> +<Type> com.sun.star.java.XJavaVM </Type> +<Type> com.sun.star.sdbc.XConnection </Type> +<Type> com.sun.star.sdbc.XStatement </Type> +<Type> com.sun.star.sdbc.XResultSet </Type> +<Type> com.sun.star.sdbc.XResultSetMetaDataSupplier</Type> +<Type> com.sun.star.sdbc.XColumnLocate </Type> +<Type> com.sun.star.sdbc.XResultSetUpdate </Type> +<Type> com.sun.star.sdbc.XWarningsSupplier </Type> +<Type> com.sun.star.sdbc.XRowUpdate </Type> +<Type> com.sun.star.sdbc.XMultipleResults </Type> +<Type> com.sun.star.sdbc.XBatchExecution </Type> +<Type> com.sun.star.sdbc.XPreparedBatchExecution </Type> +<Type> com.sun.star.sdbc.XParameters </Type> +<Type> com.sun.star.sdbc.XOutParameters </Type> +<Type> com.sun.star.sdbc.DriverPropertyInfo </Type> +<Type> com.sun.star.sdbc.XRow </Type> +<Type> com.sun.star.sdb.XColumnUpdate </Type> +<Type> com.sun.star.sdb.XColumn </Type> + +</COMPONENTDESCRIPTION> + + diff --git a/connectivity/source/drivers/adabas/exports.dxp b/connectivity/source/drivers/adabas/exports.dxp new file mode 100644 index 000000000000..9630d7e06768 --- /dev/null +++ b/connectivity/source/drivers/adabas/exports.dxp @@ -0,0 +1,3 @@ +component_getImplementationEnvironment +component_writeInfo +component_getFactory diff --git a/connectivity/source/drivers/adabas/makefile.mk b/connectivity/source/drivers/adabas/makefile.mk new file mode 100644 index 000000000000..2df67f8df3d1 --- /dev/null +++ b/connectivity/source/drivers/adabas/makefile.mk @@ -0,0 +1,199 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/..$/.. +PRJINC=..$/.. +PRJNAME=connectivity +TARGET=adabas + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ---------------------------------- +.IF "$(DBGUTIL_OJ)"!="" +ENVCFLAGS+=/FR$(SLO)$/ +.ENDIF + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/version.mk + +# --- Types ------------------------------------- + + +UNOUCRDEP=$(SOLARBINDIR)$/applicat.rdb +UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb + +UNOUCROUT=$(OUT)$/inc +INCPRE+=$(UNOUCROUT) + +# --- Types ------------------------------------- + +UNOTYPES+= \ + com.sun.star.util.XCancellable \ + com.sun.star.util.XNumberFormatter \ + com.sun.star.uno.TypeClass \ + com.sun.star.uno.XWeak \ + com.sun.star.uno.XAggregation \ + com.sun.star.beans.XPropertyState \ + com.sun.star.beans.XPropertySet \ + com.sun.star.beans.PropertyValue \ + com.sun.star.beans.XMultiPropertySet \ + com.sun.star.beans.XFastPropertySet \ + com.sun.star.lang.XTypeProvider \ + com.sun.star.lang.EventObject \ + com.sun.star.lang.XComponent \ + com.sun.star.lang.IllegalArgumentException \ + com.sun.star.lang.DisposedException \ + com.sun.star.lang.XMultiServiceFactory \ + com.sun.star.lang.XSingleServiceFactory \ + com.sun.star.lang.XUnoTunnel \ + com.sun.star.registry.XRegistryKey \ + com.sun.star.java.XJavaThreadRegister_11 \ + com.sun.star.java.XJavaVM \ + com.sun.star.sdbc.XConnection \ + com.sun.star.sdbc.XStatement \ + com.sun.star.sdbc.XResultSet \ + com.sun.star.sdbc.XResultSetMetaDataSupplier \ + com.sun.star.sdbc.XColumnLocate \ + com.sun.star.sdbc.XResultSetUpdate \ + com.sun.star.sdbc.XWarningsSupplier \ + com.sun.star.sdbc.XRowUpdate \ + com.sun.star.sdbc.XMultipleResults \ + com.sun.star.sdbc.XBatchExecution \ + com.sun.star.sdbc.XPreparedBatchExecution \ + com.sun.star.sdbc.XParameters \ + com.sun.star.sdbc.XOutParameters \ + com.sun.star.sdbc.DriverPropertyInfo \ + com.sun.star.sdbc.XDriver \ + com.sun.star.sdbc.XRow \ + com.sun.star.sdbc.SQLWarning \ + com.sun.star.sdbc.ColumnSearch \ + com.sun.star.sdbc.DataType \ + com.sun.star.sdbc.ResultSetConcurrency \ + com.sun.star.sdbc.ResultSetType \ + com.sun.star.sdbc.ColumnValue \ + com.sun.star.sdbcx.KeyType \ + com.sun.star.sdb.XColumnUpdate \ + com.sun.star.sdb.XColumn \ + + + +# --- Files ------------------------------------- + +SLOFILES=\ + $(SLO)$/BConnection.obj \ + $(SLO)$/BDriver.obj \ + $(SLO)$/BCatalog.obj \ + $(SLO)$/BGroups.obj \ + $(SLO)$/BGroup.obj \ + $(SLO)$/BUser.obj \ + $(SLO)$/BUsers.obj \ + $(SLO)$/BKeyColumns.obj \ + $(SLO)$/BKey.obj \ + $(SLO)$/BKeys.obj \ + $(SLO)$/BColumns.obj \ + $(SLO)$/BIndex.obj \ + $(SLO)$/BIndexColumns.obj \ + $(SLO)$/BIndexes.obj \ + $(SLO)$/BTable.obj \ + $(SLO)$/BTables.obj \ + $(SLO)$/Bservices.obj \ + $(SLO)$/BDatabaseMetaData.obj \ + $(SLO)$/OPreparedStatement.obj \ + $(SLO)$/OStatement.obj \ + $(SLO)$/OResultSetMetaData.obj \ + $(SLO)$/OResultSet.obj \ + $(SLO)$/OTools.obj \ + $(SLO)$/ODatabaseMetaData.obj \ + $(SLO)$/ODriver.obj \ + $(SLO)$/OFunctions.obj \ + $(SLO)$/OConnection.obj + + +# --- Library ----------------------------------- + +SHL1TARGET= $(ADABAS_TARGET)$(ADABAS_MAJOR) +SHL1VERSIONMAP= $(TARGET).map +SHL1OBJS=$(SLOFILES) +SHL1STDLIBS=\ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(VOSLIB) \ + $(OSLLIB) \ + $(SALLIB) + +SHL1DEPN= +SHL1IMPLIB= i$(SHL1TARGET) +SHL1LIBS= $(SLB)$/commontools.lib \ + $(SLB)$/resource.lib \ + $(SLB)$/sdbcx.lib + +SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME= $(SHL1TARGET) +DEF1EXPORTFILE= exports.dxp + + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + + diff --git a/connectivity/source/drivers/ado/ACallableStatement.cxx b/connectivity/source/drivers/ado/ACallableStatement.cxx new file mode 100644 index 000000000000..487cf29f4fca --- /dev/null +++ b/connectivity/source/drivers/ado/ACallableStatement.cxx @@ -0,0 +1,258 @@ +/************************************************************************* + * + * $RCSfile: ACallableStatement.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADO_ACALLABLESTATEMENT_HXX_ +#include "ado/ACallableStatement.hxx" +#endif + +using namespace connectivity::ado; +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::container; +using namespace com::sun::star::lang; + +IMPLEMENT_SERVICE_INFO(OCallableStatement,"com.sun.star.sdbcx.ACallableStatement","com.sun.star.sdbc.CallableStatement"); + +#define GET_PARAM() \ + ADOParameter* pParam = NULL; \ + m_pParameters->get_Item(OLEVariant(columnIndex-1),&pParam); \ + if(pParam) \ + pParam->get_Value(&m_aValue); +//************************************************************** +//************ Class: java.sql.CallableStatement +//************************************************************** +OCallableStatement::OCallableStatement( OConnection* _pConnection,const ::std::vector<connectivity::OTypeInfo>& _TypeInfo,const ::rtl::OUString& sql ) + : OPreparedStatement( _pConnection, _TypeInfo, sql ) +{ + m_Command.put_CommandType(adCmdStoredProc); +} +// ------------------------------------------------------------------------- + +Any SAL_CALL OCallableStatement::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = OPreparedStatement::queryInterface(rType); + if(!aRet.hasValue()) + aRet = ::cppu::queryInterface(rType,static_cast< XRow*>(this)); + return aRet; +} +// ------------------------------------------------------------------------- + + +sal_Bool SAL_CALL OCallableStatement::wasNull( ) throw(SQLException, RuntimeException) +{ + return m_aValue.isNull(); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OCallableStatement::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + GET_PARAM() + return m_aValue; +} +// ------------------------------------------------------------------------- +sal_Int8 SAL_CALL OCallableStatement::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + GET_PARAM() + return m_aValue; +} +// ------------------------------------------------------------------------- +Sequence< sal_Int8 > SAL_CALL OCallableStatement::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + GET_PARAM() + return m_aValue; +} +// ------------------------------------------------------------------------- +::com::sun::star::util::Date SAL_CALL OCallableStatement::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + GET_PARAM() + return m_aValue; +} +// ------------------------------------------------------------------------- +double SAL_CALL OCallableStatement::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + GET_PARAM() + return m_aValue; +} +// ------------------------------------------------------------------------- + +float SAL_CALL OCallableStatement::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + GET_PARAM() + return m_aValue; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OCallableStatement::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + GET_PARAM() + return m_aValue; +} +// ------------------------------------------------------------------------- + +sal_Int64 SAL_CALL OCallableStatement::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + GET_PARAM() + return (sal_Int64)m_aValue.getCurrency(); +} +// ------------------------------------------------------------------------- + +Any SAL_CALL OCallableStatement::getObject( sal_Int32 columnIndex, const Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(SQLException, RuntimeException) +{ + return Any(); +} +// ------------------------------------------------------------------------- + +sal_Int16 SAL_CALL OCallableStatement::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + GET_PARAM() + return m_aValue; +} +// ------------------------------------------------------------------------- + +::rtl::OUString SAL_CALL OCallableStatement::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + GET_PARAM() + return m_aValue; +} +// ------------------------------------------------------------------------- + + ::com::sun::star::util::Time SAL_CALL OCallableStatement::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + GET_PARAM() + return m_aValue; +} +// ------------------------------------------------------------------------- + + ::com::sun::star::util::DateTime SAL_CALL OCallableStatement::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + GET_PARAM() + return m_aValue; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OCallableStatement::registerOutParameter( sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& typeName ) throw(SQLException, RuntimeException) +{ + ADOParameter* pParam = NULL; + m_pParameters->get_Item(OLEVariant(parameterIndex-1),&pParam); + if(pParam) + { + pParam->put_Type(ADOS::MapJdbc2ADOType(sqlType)); + pParam->put_Direction(adParamOutput); + } +} +// ------------------------------------------------------------------------- +void SAL_CALL OCallableStatement::registerNumericOutParameter( sal_Int32 parameterIndex, sal_Int32 sqlType, sal_Int32 scale ) throw(SQLException, RuntimeException) +{ + ADOParameter* pParam = NULL; + m_pParameters->get_Item(OLEVariant(parameterIndex-1),&pParam); + if(pParam) + { + pParam->put_Type(ADOS::MapJdbc2ADOType(sqlType)); + pParam->put_Direction(adParamOutput); + pParam->put_NumericScale(scale); + } +} +// ------------------------------------------------------------------------- + + +Reference< ::com::sun::star::io::XInputStream > SAL_CALL OCallableStatement::getBinaryStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + m_aValue.setNull(); + return NULL; +} +// ------------------------------------------------------------------------- +Reference< ::com::sun::star::io::XInputStream > SAL_CALL OCallableStatement::getCharacterStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + m_aValue.setNull(); + return NULL; +} +// ------------------------------------------------------------------------- + +Reference< XArray > SAL_CALL OCallableStatement::getArray( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + m_aValue.setNull(); + return NULL; +} +// ------------------------------------------------------------------------- + +Reference< XClob > SAL_CALL OCallableStatement::getClob( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + m_aValue.setNull(); + return NULL; +} +// ------------------------------------------------------------------------- +Reference< XBlob > SAL_CALL OCallableStatement::getBlob( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + m_aValue.setNull(); + return NULL; +} +// ------------------------------------------------------------------------- + +Reference< XRef > SAL_CALL OCallableStatement::getRef( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + m_aValue.setNull(); + return NULL; +} +// ------------------------------------------------------------------------- + + diff --git a/connectivity/source/drivers/ado/ACatalog.cxx b/connectivity/source/drivers/ado/ACatalog.cxx new file mode 100644 index 000000000000..1f78d41c2e32 --- /dev/null +++ b/connectivity/source/drivers/ado/ACatalog.cxx @@ -0,0 +1,216 @@ +/************************************************************************* + * + * $RCSfile: ACatalog.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADO_CATALOG_HXX_ +#include "ado/ACatalog.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_BCONNECTION_HXX_ +#include "ado/AConnection.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_GROUPS_HXX_ +#include "ado/AGroups.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_USERS_HXX_ +#include "ado/AUsers.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_TABLES_HXX_ +#include "ado/ATables.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_VIEWS_HXX_ +#include "ado/AViews.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif + + +// ------------------------------------------------------------------------- +using namespace connectivity::ado; +// ------------------------------------------------------------------------- +OCatalog::OCatalog(_ADOCatalog* _pCatalog,OConnection* _pCon) : connectivity::sdbcx::OCatalog(_pCon) + ,m_pConnection(_pCon) + ,m_aCatalog(_pCatalog) +{ + osl_incrementInterlockedCount( &m_refCount ); + refreshTables(); + refreshViews(); + refreshGroups(); + refreshUsers(); + osl_decrementInterlockedCount( &m_refCount ); +} +// ------------------------------------------------------------------------- +void OCatalog::refreshTables() +{ + ::std::vector< ::rtl::OUString> aVector; + + ADOTables* pTables = m_aCatalog.get_Tables(); + if(pTables) + { + pTables->Refresh(); + + sal_Int32 nCount = 0; + pTables->get_Count(&nCount); + for(sal_Int32 i=0;i< nCount;++i) + { + ADOTable* pTable = NULL; + pTables->get_Item(OLEVariant(i),&pTable); + if(pTable) + { + WpADOTable aTable(pTable); + aVector.push_back(aTable.get_Name()); + } + } + } + + if(m_pTables) + delete m_pTables; + m_pTables = new OTables(*this,m_aMutex,aVector,pTables,m_pConnection->getMetaData()->storesMixedCaseQuotedIdentifiers()); +} +// ------------------------------------------------------------------------- +void OCatalog::refreshViews() +{ + ::std::vector< ::rtl::OUString> aVector; + + ADOViews* pViews = m_aCatalog.get_Views(); + if(pViews) + { + pViews->Refresh(); + + sal_Int32 nCount = 0; + pViews->get_Count(&nCount); + for(sal_Int32 i=0;i< nCount;++i) + { + ADOView* pView = NULL; + pViews->get_Item(OLEVariant(i),&pView); + if(pView) + { + WpADOView aView(pView); + aVector.push_back(aView.get_Name()); + } + } + } + + if(m_pViews) + delete m_pViews; + m_pViews = new OViews(*this,m_aMutex,aVector,pViews,m_pConnection->getMetaData()->storesMixedCaseQuotedIdentifiers()); +} +// ------------------------------------------------------------------------- +void OCatalog::refreshGroups() +{ + ::std::vector< ::rtl::OUString> aVector; + + ADOGroups* pGroups = m_aCatalog.get_Groups(); + if(pGroups) + { + pGroups->Refresh(); + + sal_Int32 nCount = 0; + pGroups->get_Count(&nCount); + for(sal_Int32 i=0;i< nCount;++i) + { + ADOGroup* pGroup = NULL; + pGroups->get_Item(OLEVariant(i),&pGroup); + if(pGroup) + { + WpADOGroup aGroup(pGroup); + aVector.push_back(aGroup.get_Name()); + } + } + } + + if(m_pGroups) + delete m_pGroups; + m_pGroups = new OGroups(*this,m_aMutex,aVector,pGroups,m_pConnection->getMetaData()->storesMixedCaseQuotedIdentifiers()); +} +// ------------------------------------------------------------------------- +void OCatalog::refreshUsers() +{ + ::std::vector< ::rtl::OUString> aVector; + + ADOUsers* pUsers = m_aCatalog.get_Users(); + if(pUsers) + { + pUsers->Refresh(); + + sal_Int32 nCount = 0; + pUsers->get_Count(&nCount); + for(sal_Int32 i=0;i< nCount;++i) + { + ADOUser* pUser = NULL; + pUsers->get_Item(OLEVariant(i),&pUser); + if(pUser) + { + WpADOUser aUser(pUser); + aVector.push_back(aUser.get_Name()); + } + } + } + + if(m_pUsers) + delete m_pUsers; + m_pUsers = new OUsers(*this,m_aMutex,aVector,pUsers,m_pConnection->getMetaData()->storesMixedCaseQuotedIdentifiers()); +} +// ------------------------------------------------------------------------- + + diff --git a/connectivity/source/drivers/ado/AColumn.cxx b/connectivity/source/drivers/ado/AColumn.cxx new file mode 100644 index 000000000000..7bb7d0c45d30 --- /dev/null +++ b/connectivity/source/drivers/ado/AColumn.cxx @@ -0,0 +1,426 @@ +/************************************************************************* + * + * $RCSfile: AColumn.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADO_COLUMN_HXX_ +#include "ado/AColumn.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_AWRAPADO_HXX_ +#include "ado/Awrapado.hxx" +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif + +using namespace connectivity::ado; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::sdbc; + +void WpADOColumn::Create() +{ + IClassFactory2* pIUnknown = NULL; + IUnknown *pOuter = NULL; + HRESULT hr = -1; + _ADOColumn* pCommand; + hr = CoCreateInstance(ADOS::CLSID_ADOCOLUMN_25, + NULL, + CLSCTX_INPROC_SERVER, + ADOS::IID_ADOCOLUMN_25, + (void**)&pCommand ); + + + if( !FAILED( hr ) ) + { + pInterface = pCommand; + pInterface->AddRef(); + } +} +// ------------------------------------------------------------------------- +OAdoColumn::OAdoColumn(sal_Bool _bCase,_ADOColumn* _pColumn) : connectivity::sdbcx::OColumn(_bCase) +{ + if(_pColumn) + m_aColumn = WpADOColumn(_pColumn); + else + m_aColumn.Create(); +} +// ------------------------------------------------------------------------- +OAdoColumn::OAdoColumn( const ::rtl::OUString& _Name, + const ::rtl::OUString& _TypeName, + const ::rtl::OUString& _DefaultValue, + sal_Int32 _IsNullable, + sal_Int32 _Precision, + sal_Int32 _Scale, + sal_Int32 _Type, + sal_Bool _IsAutoIncrement, + sal_Bool _IsCurrency, + sal_Bool _bCase + ) : connectivity::sdbcx::OColumn(_Name, + _TypeName, + _DefaultValue, + _IsNullable, + _Precision, + _Scale, + _Type, + _IsAutoIncrement, + sal_False,_IsCurrency,_bCase) +{ + m_aColumn.Create(); + m_aColumn.put_Name(_Name); + m_aColumn.put_Type(ADOS::MapJdbc2ADOType(_Type)); + m_aColumn.put_Precision(_Precision); + if(_IsNullable) + m_aColumn.put_Attributes(adColNullable); + { + ADOProperties* pProps = m_aColumn.get_Properties(); + pProps->AddRef(); + ADOProperty* pProp = NULL; + pProps->get_Item(OLEVariant(::rtl::OUString::createFromAscii("AutoIncrement")),&pProp); + WpADOProperty aProp(pProp); + if(pProp) + aProp.PutValue(_IsAutoIncrement); + pProps->Release(); + } + { + ADOProperties* pProps = m_aColumn.get_Properties(); + pProps->AddRef(); + ADOProperty* pProp = NULL; + pProps->get_Item(OLEVariant(::rtl::OUString::createFromAscii("Default")),&pProp); + WpADOProperty aProp(pProp); + if(pProp) + aProp.PutValue(_DefaultValue); + pProps->Release(); + } +} +// ------------------------------------------------------------------------- +Any SAL_CALL OAdoColumn::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = ::cppu::queryInterface(rType,static_cast< ::com::sun::star::lang::XUnoTunnel*> (this)); + if(aRet.hasValue()) + return aRet; + return OColumn_ADO::queryInterface(rType); +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OAdoColumn::getTypes( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > *)0 )); + + return ::utl::concatSequences(aTypes.getTypes(),OColumn_ADO::getTypes()); +} + +//-------------------------------------------------------------------------- +Sequence< sal_Int8 > OAdoColumn::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 OAdoColumn::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException) +{ + if (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) + return (sal_Int64)this; + + return 0; +} + + +typedef connectivity::sdbcx::ODescriptor ODescriptor_TYPEDEF; +// ------------------------------------------------------------------------- +//void OAdoColumn::construct() +//{ +// ODescriptor_TYPEDEF::construct(); +// sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY; +// +// registerProperty(PROPERTY_TYPENAME, PROPERTY_ID_TYPENAME, nAttrib,&m_TypeName, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); +// registerProperty(PROPERTY_DEFAULTVALUE, PROPERTY_ID_DEFAULTVALUE, nAttrib,&m_DefaultValue, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); +// registerProperty(PROPERTY_PRECISION, PROPERTY_ID_PRECISION, nAttrib,&m_Precision, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))); +// registerProperty(PROPERTY_TYPE, PROPERTY_ID_TYPE, nAttrib,&m_Type, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))); +// registerProperty(PROPERTY_SCALE, PROPERTY_ID_SCALE, nAttrib,&m_Scale, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))); +// registerProperty(PROPERTY_ISNULLABLE, PROPERTY_ID_ISNULLABLE, nAttrib,&m_IsNullable, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))); +// registerProperty(PROPERTY_ISAUTOINCREMENT, PROPERTY_ID_ISAUTOINCREMENT, nAttrib,&m_IsAutoIncrement, ::getBooleanCppuType()); +//} +// +void OAdoColumn::setFastPropertyValue_NoBroadcast( + sal_Int32 nHandle, + const Any& rValue + ) + throw (Exception) +{ + if(m_aColumn.IsValid()) + { + + switch(nHandle) + { + case PROPERTY_ID_NAME: + { + ::rtl::OUString aVal; + rValue >>= aVal; + m_aColumn.put_Name(aVal); + } + break; + case PROPERTY_ID_TYPE: + { + sal_Int32 nVal=0; + rValue >>= nVal; + m_aColumn.put_Type(ADOS::MapJdbc2ADOType(nVal)); + } + break; + case PROPERTY_ID_TYPENAME: + // rValue <<= getResultSetType(); + break; + case PROPERTY_ID_PRECISION: + { + sal_Int32 nVal=0; + rValue >>= nVal; + m_aColumn.put_Precision(nVal); + } + break; + case PROPERTY_ID_SCALE: + { + sal_Int32 nVal=0; + rValue >>= nVal; + m_aColumn.put_NumericScale(nVal); + } + break; + case PROPERTY_ID_ISNULLABLE: + { + sal_Bool _b; + rValue >>= _b; + if(_b) + m_aColumn.put_Attributes(adColNullable); + } + break; + case PROPERTY_ID_ISASCENDING: + { + sal_Bool _b; + rValue >>= _b; + m_aColumn.put_SortOrder( _b ? adSortAscending : adSortDescending); + } + break; + case PROPERTY_ID_ISROWVERSION: + break; + case PROPERTY_ID_ISAUTOINCREMENT: + { + ADOProperties* pProps = m_aColumn.get_Properties(); + pProps->AddRef(); + ADOProperty* pProp = NULL; + pProps->get_Item(OLEVariant(::rtl::OUString::createFromAscii("AutoIncrement")),&pProp); + WpADOProperty aProp(pProp); + if(pProp) + aProp.PutValue(getString(rValue)); + pProps->Release(); + } + break; + case PROPERTY_ID_DESCRIPTION: + { + ADOProperties* pProps = m_aColumn.get_Properties(); + pProps->AddRef(); + ADOProperty* pProp = NULL; + pProps->get_Item(OLEVariant(::rtl::OUString::createFromAscii("Default")),&pProp); + WpADOProperty aProp(pProp); + if(pProp) + aProp.PutValue(getString(rValue)); + pProps->Release(); + } + break; + case PROPERTY_ID_DEFAULTVALUE: + { + ADOProperties* pProps = m_aColumn.get_Properties(); + pProps->AddRef(); + ADOProperty* pProp = NULL; + pProps->get_Item(OLEVariant(::rtl::OUString::createFromAscii("Description")),&pProp); + WpADOProperty aProp(pProp); + if(pProp) + aProp.PutValue(getString(rValue)); + pProps->Release(); + } + break; + case PROPERTY_ID_ISCURRENCY: + { + ADOProperties* pProps = m_aColumn.get_Properties(); + pProps->AddRef(); + ADOProperty* pProp = NULL; + pProps->get_Item(OLEVariant(::rtl::OUString::createFromAscii("Fixed Length")),&pProp); + WpADOProperty aProp(pProp); + if(pProp) + aProp.PutValue(getBOOL(rValue)); + pProps->Release(); + } + break; + } + } +} +// ------------------------------------------------------------------------- +void OAdoColumn::getFastPropertyValue( + Any& rValue, + sal_Int32 nHandle + ) const +{ + if(m_aColumn.IsValid()) + { + switch(nHandle) + { + case PROPERTY_ID_NAME: + rValue <<= m_aColumn.get_Name(); + break; + case PROPERTY_ID_TYPE: + rValue <<= ADOS::MapADOType2Jdbc(m_aColumn.get_Type()); + break; + case PROPERTY_ID_TYPENAME: + // rValue <<= getResultSetType(); + break; + case PROPERTY_ID_PRECISION: + rValue <<= m_aColumn.get_Precision(); + break; + case PROPERTY_ID_SCALE: + rValue <<= m_aColumn.get_NumericScale(); + break; + case PROPERTY_ID_ISNULLABLE: + { + sal_Bool _b = m_aColumn.get_Attributes() == adColNullable; + rValue <<= Any(&_b, ::getBooleanCppuType()); + } + break; + case PROPERTY_ID_ISASCENDING: + { + sal_Bool _b = m_aColumn.get_SortOrder() == adSortAscending; + rValue <<= Any(&_b, ::getBooleanCppuType()); + } + case PROPERTY_ID_ISAUTOINCREMENT: + { + ADOProperties* pProps = m_aColumn.get_Properties(); + pProps->AddRef(); + ADOProperty* pProp = NULL; + pProps->get_Item(OLEVariant(::rtl::OUString::createFromAscii("AutoIncrement")),&pProp); + WpADOProperty aProp(pProp); + if(pProp) + { + sal_Bool b = aProp.GetValue(); + rValue <<= Any(&b, ::getBooleanCppuType()); + } + pProps->Release(); + } + break; + case PROPERTY_ID_ISROWVERSION: + // rValue <<= getResultSetType(); + break; + case PROPERTY_ID_DESCRIPTION: + { + ADOProperties* pProps = m_aColumn.get_Properties(); + pProps->AddRef(); + ADOProperty* pProp = NULL; + pProps->get_Item(OLEVariant(::rtl::OUString::createFromAscii("Description")),&pProp); + WpADOProperty aProp(pProp); + if(pProp) + rValue <<= (::rtl::OUString)aProp.GetValue(); + pProps->Release(); + } + break; + case PROPERTY_ID_DEFAULTVALUE: + { + ADOProperties* pProps = m_aColumn.get_Properties(); + pProps->AddRef(); + ADOProperty* pProp = NULL; + pProps->get_Item(OLEVariant(::rtl::OUString::createFromAscii("Default")),&pProp); + WpADOProperty aProp(pProp); + if(pProp) + rValue <<= (::rtl::OUString)aProp.GetValue(); + pProps->Release(); + } + break; + case PROPERTY_ID_ISCURRENCY: + { + ADOProperties* pProps = m_aColumn.get_Properties(); + pProps->AddRef(); + ADOProperty* pProp = NULL; + pProps->get_Item(OLEVariant(::rtl::OUString::createFromAscii("Fixed Length")),&pProp); + WpADOProperty aProp(pProp); + if(pProp) + { + sal_Bool bVal = aProp.GetValue(); + rValue <<= Any(&bVal,getBooleanCppuType()); + } + pProps->Release(); + } + break; + } + } +} + + + diff --git a/connectivity/source/drivers/ado/AColumns.cxx b/connectivity/source/drivers/ado/AColumns.cxx new file mode 100644 index 000000000000..bbed8e773114 --- /dev/null +++ b/connectivity/source/drivers/ado/AColumns.cxx @@ -0,0 +1,149 @@ +/************************************************************************* + * + * $RCSfile: AColumns.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADO_COLUMNS_HXX_ +#include "ado/AColumns.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_COLUMN_HXX_ +#include "ado/AColumn.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ +#include <com/sun/star/sdbc/ColumnValue.hpp> +#endif + +using namespace connectivity::ado; +using namespace connectivity; +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::container; + +typedef connectivity::sdbcx::OCollection OCollection_TYPE; + +Reference< XNamed > OColumns::createObject(const ::rtl::OUString& _rName) +{ + + ADOColumn* pColumn = NULL; + m_pCollection->get_Item(OLEVariant(_rName),&pColumn); + + Reference< XNamed > xRet = new OAdoColumn(isCaseSensitive(),pColumn); + + return xRet; +} + +// ------------------------------------------------------------------------- +void OColumns::impl_refresh() throw(RuntimeException) +{ + m_pCollection->Refresh(); +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > OColumns::createEmptyObject() +{ + OAdoColumn* pNew = new OAdoColumn(isCaseSensitive()); + return pNew; +} +// ------------------------------------------------------------------------- +// XAppend +void SAL_CALL OColumns::appendByDescriptor( const Reference< XPropertySet >& descriptor ) throw(SQLException, ElementExistException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(descriptor,UNO_QUERY); + if(xTunnel.is()) + { + OAdoColumn* pColumn = (OAdoColumn*)xTunnel->getSomething(OAdoColumn::getUnoTunnelImplementationId()); + m_pCollection->Append(OLEVariant(pColumn->getColumnImpl())); + } + + OCollection_TYPE::appendByDescriptor(descriptor); +} +// ------------------------------------------------------------------------- +// XDrop +void SAL_CALL OColumns::dropByName( const ::rtl::OUString& elementName ) throw(SQLException, NoSuchElementException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + m_pCollection->Delete(OLEVariant(elementName)); + + OCollection_TYPE::dropByName(elementName); +} +// ------------------------------------------------------------------------- +void SAL_CALL OColumns::dropByIndex( sal_Int32 index ) throw(SQLException, IndexOutOfBoundsException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + if (index < 0 || index >= getCount()) + throw IndexOutOfBoundsException(); + + m_pCollection->Delete(OLEVariant(index)); + OCollection_TYPE::dropByIndex(index); +} + + diff --git a/connectivity/source/drivers/ado/AConnection.cxx b/connectivity/source/drivers/ado/AConnection.cxx new file mode 100644 index 000000000000..7baf3eed0c05 --- /dev/null +++ b/connectivity/source/drivers/ado/AConnection.cxx @@ -0,0 +1,554 @@ +/************************************************************************* + * + * $RCSfile: AConnection.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADO_ACONNECTION_HXX_ +#include "ado/AConnection.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_ADATABASEMETADATA_HXX_ +#include "ado/ADatabaseMetaData.hxx" +#endif + +#ifndef _CONNECTIVITY_RESOURCE_HRC_ +#include "Resource.hrc" +#endif +#ifndef _CONNECTIVITY_MODULECONTEXT_HXX_ +#include "ModuleContext.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_ADRIVER_HXX_ +#include "ado/ADriver.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_ASTATEMENT_HXX_ +#include "ado/AStatement.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_ACALLABLESTATEMENT_HXX_ +#include "ado/ACallableStatement.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_APREPAREDSTATEMENT_HXX_ +#include "ado/APreparedStatement.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ +#include <com/sun/star/sdbc/ColumnValue.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_TRANSACTIONISOLATION_HPP_ +#include <com/sun/star/sdbc/TransactionIsolation.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif + +using namespace connectivity::ado; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::sdbc; + +//------------------------------------------------------------------------------ +IMPLEMENT_SERVICE_INFO(OConnection,"com.sun.star.sdbcx.AConnection","com.sun.star.sdbc.Connection"); +// -------------------------------------------------------------------------------- +OConnection::OConnection(const ::rtl::OUString& url, const Sequence< PropertyValue >& info, + ODriver* _pDriver) throw(SQLException, RuntimeException) + : OConnection_BASE(m_aMutex), + OSubComponent<OConnection>((::cppu::OWeakObject*)_pDriver), + m_bClosed(sal_False), + m_xMetaData(NULL), + m_xCatalog(NULL), + m_pDriver(_pDriver), + m_pAdoConnection(NULL), + m_bAutocommit(sal_True) +{ + ModuleContext::AddRef(); + + osl_incrementInterlockedCount( &m_refCount ); + + IClassFactory2* pIUnknown = NULL; + IUnknown *pOuter = NULL; + HRESULT hr; + hr = CoGetClassObject( ADOS::CLSID_ADOCONNECTION_21, + CLSCTX_INPROC_SERVER, + NULL, + IID_IClassFactory2, + (void**)&pIUnknown ); + + if( !FAILED( hr ) ) + { + pIUnknown->AddRef(); + + ADOConnection *pCon = NULL; + hr = pIUnknown->CreateInstanceLic( pOuter, + NULL, + ADOS::IID_ADOCONNECTION_21, + ADOS::GetKeyStr(), + (void**) &pCon); + + if( !FAILED( hr ) ) + { + m_pAdoConnection = new WpADOConnection(pCon); + // Class Factory is no longer needed + + + } + pIUnknown->Release(); + } + + osl_decrementInterlockedCount( &m_refCount ); +} +//----------------------------------------------------------------------------- +OConnection::~OConnection() +{ + delete m_pAdoConnection; + ModuleContext::ReleaseRef(); +} +//----------------------------------------------------------------------------- +void OConnection::construct(const ::rtl::OUString& url,const Sequence< PropertyValue >& info) +{ + osl_incrementInterlockedCount( &m_refCount ); + + sal_Int32 nLen = url.indexOf(':'); + nLen = url.indexOf(':',nLen+1); + ::rtl::OUString aDSN(url.copy(nLen+1)),aUID,aPWD; + + sal_Int32 nTimeout = 20; + sal_Bool bSilent = sal_True; + const PropertyValue *pBegin = info.getConstArray(); + const PropertyValue *pEnd = pBegin + info.getLength(); + for(;pBegin != pEnd;++pBegin) + { + if(!pBegin->Name.compareToAscii("Timeout")) + pBegin->Value >>= nTimeout; + else if(!pBegin->Name.compareToAscii("Silent")) + pBegin->Value >>= bSilent; + else if(!pBegin->Name.compareToAscii("user")) + pBegin->Value >>= aUID; + else if(!pBegin->Name.compareToAscii("password")) + pBegin->Value >>= aPWD; + } + + if(m_pAdoConnection) + { + if(m_pAdoConnection->Open(aDSN,aUID,aPWD,adConnectUnspecified)) + m_pAdoConnection->PutCommandTimeout(nTimeout); + else + ADOS::ThrowException(*m_pAdoConnection,*this); + if(m_pAdoConnection->get_State() != adStateOpen) + throw SQLException(); + + ADOProperties* pProps=m_pAdoConnection->get_Properties(); + if(pProps) + { + pProps->AddRef(); + ADOProperty* pProp = NULL; + pProps->get_Item(OLEVariant(::rtl::OUString::createFromAscii("Jet OLEDB:ODBC Parsing")),&pProp); + WpADOProperty aProp(pProp); + if(pProp) + { + aProp.PutValue(OLEVariant(VARIANT_TRUE)); + OLEVariant aVar = aProp.GetValue(); + } + pProps->Release(); + } + //bErg = TRUE; + } + else + throw SQLException(); + + osl_decrementInterlockedCount( &m_refCount ); +} +//----------------------------------------------------------------------------- +void SAL_CALL OConnection::release() throw(RuntimeException) +{ + relase_ChildImpl(); + OConnection_BASE::release(); +} +// -------------------------------------------------------------------------------- +Reference< XStatement > SAL_CALL OConnection::createStatement( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + OStatement* pStmt = new OStatement(this); + Reference< XStatement > xStmt = pStmt; + m_aStatements.push_back(WeakReferenceHelper(*pStmt)); + return pStmt; +} +// -------------------------------------------------------------------------------- +Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + OPreparedStatement* pStmt = new OPreparedStatement(this,m_aTypeInfo,sql); + Reference< XPreparedStatement > xPStmt = pStmt; + m_aStatements.push_back(WeakReferenceHelper(*pStmt)); + return xPStmt; +} +// -------------------------------------------------------------------------------- +Reference< XPreparedStatement > SAL_CALL OConnection::prepareCall( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + OCallableStatement* pStmt = new OCallableStatement(this,m_aTypeInfo,sql); + Reference< XPreparedStatement > xPStmt = pStmt; + m_aStatements.push_back(WeakReferenceHelper(*pStmt)); + return xPStmt; +} +// -------------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OConnection::nativeSQL( const ::rtl::OUString& _sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + ::rtl::OUString sql = _sql; + ADOProperties* pProps=m_pAdoConnection->get_Properties(); + if(pProps) + { + pProps->AddRef(); + ADOProperty* pProp = NULL; + pProps->get_Item(OLEVariant(::rtl::OUString::createFromAscii("Jet OLEDB:ODBC Parsing")),&pProp); + WpADOProperty aProp(pProp); + if(pProp) + { + pProp->put_Value(OLEVariant(VARIANT_TRUE)); + WpADOCommand aCommand; + aCommand.Create(); + aCommand.put_ActiveConnection((IDispatch*)*m_pAdoConnection); + aCommand.put_CommandText(sql); + sql = aCommand.get_CommandText(); + } + pProps->Release(); + } + + return sql; +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::setAutoCommit( sal_Bool autoCommit ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_bAutocommit = autoCommit; + if(!autoCommit) + m_pAdoConnection->BeginTrans(); + else + m_pAdoConnection->RollbackTrans(); +} +// -------------------------------------------------------------------------------- +sal_Bool SAL_CALL OConnection::getAutoCommit( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return m_bAutocommit; +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::commit( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_pAdoConnection->CommitTrans(); +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::rollback( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_pAdoConnection->RollbackTrans(); +} +// -------------------------------------------------------------------------------- +sal_Bool SAL_CALL OConnection::isClosed( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return OConnection_BASE::rBHelper.bDisposed && !m_pAdoConnection->get_State(); +} +// -------------------------------------------------------------------------------- +Reference< XDatabaseMetaData > SAL_CALL OConnection::getMetaData( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(!m_xMetaData.is()) + m_xMetaData = new ODatabaseMetaData(this); + + return m_xMetaData; +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::setReadOnly( sal_Bool readOnly ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_pAdoConnection->put_Mode(adModeRead); + ADOS::ThrowException(*m_pAdoConnection,*this); +} +// -------------------------------------------------------------------------------- +sal_Bool SAL_CALL OConnection::isReadOnly( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return m_pAdoConnection->get_Mode() == adModeRead; +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::setCatalog( const ::rtl::OUString& catalog ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_pAdoConnection->PutDefaultDatabase(catalog); + ADOS::ThrowException(*m_pAdoConnection,*this); +} +// -------------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OConnection::getCatalog( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return m_pAdoConnection->GetDefaultDatabase(); +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::setTransactionIsolation( sal_Int32 level ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + IsolationLevelEnum eIso; + switch(level) + { + case TransactionIsolation::NONE: + eIso = adXactUnspecified; + break; + case TransactionIsolation::READ_UNCOMMITTED: + eIso = adXactReadUncommitted; + break; + case TransactionIsolation::READ_COMMITTED: + eIso = adXactReadCommitted; + break; + case TransactionIsolation::REPEATABLE_READ: + eIso = adXactRepeatableRead; + break; + case TransactionIsolation::SERIALIZABLE: + eIso = adXactSerializable; + break; + default: + OSL_ENSHURE(0,"OConnection::setTransactionIsolation invalid level"); + return; + } + m_pAdoConnection->put_IsolationLevel(eIso); + ADOS::ThrowException(*m_pAdoConnection,*this); +} +// -------------------------------------------------------------------------------- +sal_Int32 SAL_CALL OConnection::getTransactionIsolation( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_Int32 nRet = 0; + switch(m_pAdoConnection->get_IsolationLevel()) + { + case adXactUnspecified: + nRet = TransactionIsolation::NONE; + break; + case adXactReadUncommitted: + nRet = TransactionIsolation::READ_UNCOMMITTED; + break; + case adXactReadCommitted: + nRet = TransactionIsolation::READ_COMMITTED; + break; + case adXactRepeatableRead: + nRet = TransactionIsolation::REPEATABLE_READ; + break; + case adXactSerializable: + nRet = TransactionIsolation::SERIALIZABLE; + break; + default: + OSL_ENSHURE(0,"OConnection::setTransactionIsolation invalid level"); + } + ADOS::ThrowException(*m_pAdoConnection,*this); + return nRet; +} +// -------------------------------------------------------------------------------- +Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OConnection::getTypeMap( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return NULL; +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::setTypeMap( const Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(SQLException, RuntimeException) +{ +} +// -------------------------------------------------------------------------------- +// XCloseable +void SAL_CALL OConnection::close( ) throw(SQLException, RuntimeException) +{ + { + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + } + dispose(); +} +// -------------------------------------------------------------------------------- +// XWarningsSupplier +Any SAL_CALL OConnection::getWarnings( ) throw(SQLException, RuntimeException) +{ + return Any(); +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::clearWarnings( ) throw(SQLException, RuntimeException) +{ +} +//-------------------------------------------------------------------- +void OConnection::buildTypeInfo() throw( SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + Reference< XResultSet> xRs = getMetaData ()->getTypeInfo (); + Reference< XRow> xRow(xRs,UNO_QUERY); + // Information for a single SQL type + + // Loop on the result set until we reach end of file + + sal_Bool more = xRs->next (); + while (more) + { + OTypeInfo aInfo; + aInfo.aTypeName = xRow->getString (1); + aInfo.aLiteralPrefix = xRow->getString (4); + aInfo.aLiteralSuffix = xRow->getString (5); + aInfo.aCreateParams = xRow->getString (6); + aInfo.aLocalTypeName = xRow->getString (13); + + aInfo.nPrecision = xRow->getInt (3); + aInfo.nMaximumScale = xRow->getShort (15); + aInfo.nMinimumScale = xRow->getShort (14); + aInfo.nType = xRow->getShort (2); + aInfo.nSearchType = xRow->getShort (9); + aInfo.nNumPrecRadix = xRow->getInt (18); + + aInfo.bCurrency = xRow->getBoolean (11); + aInfo.bAutoIncrement = xRow->getBoolean (12); + aInfo.bNullable = xRow->getBoolean (7) == ColumnValue::NULLABLE; + aInfo.bCaseSensitive = xRow->getBoolean (8); + aInfo.bUnsigned = xRow->getBoolean (10); + + // Now that we have the type info, save it + // in the Hashtable if we don't already have an + // entry for this SQL type. + + m_aTypeInfo.push_back(aInfo); + more = xRs->next (); + } + + // Close the result set/statement. + + Reference< XCloseable>(xRs,UNO_QUERY)->close(); +} +//------------------------------------------------------------------------------ +void OConnection::disposing() +{ + ::osl::MutexGuard aGuard(m_aMutex); + + // m_aTables.disposing(); + for (OWeakRefArray::iterator i = m_aStatements.begin(); m_aStatements.end() != i; ++i) + { + Reference< XComponent > xComp(i->get(), UNO_QUERY); + if (xComp.is()) + xComp->dispose(); + } + m_aStatements.clear(); + + Reference< XComponent > xComp2(m_xCatalog.get(), UNO_QUERY); + if(xComp2.is()) + xComp2->dispose(); + + m_bClosed = sal_True; + m_xMetaData = NULL; + + m_pAdoConnection->Close(); + + dispose_ChildImpl(); + OConnection_BASE::disposing(); +} + + diff --git a/connectivity/source/drivers/ado/ADatabaseMetaData.cxx b/connectivity/source/drivers/ado/ADatabaseMetaData.cxx new file mode 100644 index 000000000000..1484b81cc008 --- /dev/null +++ b/connectivity/source/drivers/ado/ADatabaseMetaData.cxx @@ -0,0 +1,1602 @@ +/************************************************************************* + * + * $RCSfile: ADatabaseMetaData.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_ADO_ADATABASEMETADATA_HXX_ +#include "ado/ADatabaseMetaData.hxx" +#endif + +#ifndef _CONNECTIVITY_ADO_ADATABASEMETADATARESULTSET_HXX_ +#include "ado/ADatabaseMetaDataResultSet.hxx" +#endif + +#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_RESULTSETTYPE_HPP_ +#include <com/sun/star/sdbc/ResultSetType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_RESULTSETCONCURRENCY_HPP_ +#include <com/sun/star/sdbc/ResultSetConcurrency.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_TRANSACTIONISOLATION_HPP_ +#include <com/sun/star/sdbc/TransactionIsolation.hpp> +#endif + +#ifndef _CONNECTIVITY_ADO_ADOIMP_HXX_ +#include "ado/adoimp.hxx" +#endif + +using namespace connectivity::ado; +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 connectivity; + +ODatabaseMetaData::ODatabaseMetaData(OConnection* _pCon) + : m_pADOConnection(_pCon->getConnection()) + ,m_pConnection(_pCon) +{ +} +// ------------------------------------------------------------------------- +void ODatabaseMetaData::fillLiterals() throw(SQLException, RuntimeException) +{ + ADORecordset *pRecordset = NULL; + OLEVariant vtEmpty; + vtEmpty.setNoArg(); + m_pADOConnection->OpenSchema(adSchemaDBInfoLiterals,vtEmpty,vtEmpty,&pRecordset); + + ADOS::ThrowException(*m_pADOConnection,*this); + + OSL_ENSHURE(pRecordset,"getMaxSize no resultset!"); + WpADORecordset aRecordset(pRecordset); + + aRecordset.MoveFirst(); + OLEVariant aValue; + sal_Int32 nRet = 0; + LiteralInfo aInfo; + while(!aRecordset.IsAtEOF()) + { + WpOLEAppendCollection<ADOFields, ADOField, WpADOField> aFields(aRecordset.GetFields()); + WpADOField aField(aFields.GetItem(1)); + aInfo.pwszLiteralValue = aField.get_Value(); + aField = aFields.GetItem(5); + aInfo.fSupported = aField.get_Value(); + aField = aFields.GetItem(6); + aInfo.cchMaxLen = aField.get_Value().getUInt32(); + + aField = aFields.GetItem(4); + sal_uInt32 nId = aField.get_Value().getUInt32(); + m_aLiteralInfo[nId] = aInfo; + + aRecordset.MoveNext(); + } + aRecordset.Close(); +} +// ------------------------------------------------------------------------- +sal_Int32 ODatabaseMetaData::getMaxSize(sal_uInt32 _nId) throw(SQLException, RuntimeException) +{ + if(!m_aLiteralInfo.size()) + fillLiterals(); + ::std::map<sal_uInt32,LiteralInfo>::const_iterator aIter = m_aLiteralInfo.find(_nId); + if(aIter != m_aLiteralInfo.end() && (*aIter).second.fSupported) + return ((*aIter).second.cchMaxLen == (-1)) ? 0 : (*aIter).second.cchMaxLen; + return 0; +} +// ------------------------------------------------------------------------- +sal_Bool ODatabaseMetaData::isCapable(sal_uInt32 _nId) throw(SQLException, RuntimeException) +{ + if(!m_aLiteralInfo.size()) + fillLiterals(); + ::std::map<sal_uInt32,LiteralInfo>::const_iterator aIter = m_aLiteralInfo.find(_nId); + if(aIter != m_aLiteralInfo.end()) + (*aIter).second.fSupported; + return sal_False; +} + +// ------------------------------------------------------------------------- +::rtl::OUString ODatabaseMetaData::getLiteral(sal_uInt32 _nId) throw(SQLException, RuntimeException) +{ + if(!m_aLiteralInfo.size()) + fillLiterals(); + ::std::map<sal_uInt32,LiteralInfo>::const_iterator aIter = m_aLiteralInfo.find(_nId); + if(aIter != m_aLiteralInfo.end() && (*aIter).second.fSupported) + return (*aIter).second.pwszLiteralValue; + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +sal_Int32 ODatabaseMetaData::getInt32Property(const ::rtl::OUString& _aProperty) throw(SQLException, RuntimeException) +{ + WpOLEAppendCollection<ADOProperties, ADOProperty, WpADOProperty> aProps(m_pADOConnection->get_Properties()); + ADOS::ThrowException(*m_pADOConnection,*this); + OSL_ENSHURE(aProps.IsValid(),"There are no properties at the connection"); + ADO_PROP(_aProperty); + sal_Int32 nValue(0); + if(!aVar.isNull() && !aVar.isEmpty()) + nValue = aVar; + return nValue; +} + +// ------------------------------------------------------------------------- +sal_Bool ODatabaseMetaData::getBoolProperty(const ::rtl::OUString& _aProperty) throw(SQLException, RuntimeException) +{ + WpOLEAppendCollection<ADOProperties, ADOProperty, WpADOProperty> aProps(m_pADOConnection->get_Properties()); + ADOS::ThrowException(*m_pADOConnection,*this); + OSL_ENSHURE(aProps.IsValid(),"There are no properties at the connection"); + ADO_PROP(_aProperty); + return (!aVar.isNull() && !aVar.isEmpty() ? aVar.getBool() : sal_False); +} +// ------------------------------------------------------------------------- +::rtl::OUString ODatabaseMetaData::getStringProperty(const ::rtl::OUString& _aProperty) throw(SQLException, RuntimeException) +{ + WpOLEAppendCollection<ADOProperties, ADOProperty, WpADOProperty> aProps(m_pADOConnection->get_Properties()); + ADOS::ThrowException(*m_pADOConnection,*this); + OSL_ENSHURE(aProps.IsValid(),"There are no properties at the connection"); + + ADO_PROP(_aProperty); + ::rtl::OUString aValue; + if(!aVar.isNull() && !aVar.isEmpty() && aVar.getType() == VT_BSTR) + aValue = aVar; + + return aValue; +} + +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo( ) throw(SQLException, RuntimeException) +{ + HRESULT hr = S_OK; + // Create elements used in the array + OLEVariant varCriteria[2]; + const int nCrit = sizeof varCriteria / sizeof varCriteria[0]; + // Create SafeArray Bounds and initialize the array + SAFEARRAYBOUND rgsabound[1]; + rgsabound[0].lLbound = 0; + rgsabound[0].cElements = nCrit; + SAFEARRAY *psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); + + sal_Int32 nPos = 0; + SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++; + SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++; + + // Initialize and fill the SafeArray + OLEVariant vsa; + vsa.setArray(psa,VT_VARIANT); + + OLEVariant aEmpty; + aEmpty.setNoArg(); + + ADORecordset *pRec=NULL; + m_pADOConnection->OpenSchema(adSchemaProviderTypes,vsa,aEmpty,&pRec); + ADOS::ThrowException(*m_pADOConnection,*this); + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRec); + pResult->setTypeInfoMap(); + Reference< XResultSet > xRef = pResult; + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getCatalogs( ) throw(SQLException, RuntimeException) +{ + OLEVariant vtEmpty; + vtEmpty.setNoArg(); + + ADORecordset *pRecordset = NULL; + m_pADOConnection->OpenSchema(adSchemaCatalogs,vtEmpty,vtEmpty,&pRecordset); + ADOS::ThrowException(*m_pADOConnection,*this); + + Reference< XResultSet > xRef = NULL; + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + pResult->setCatalogsMap(); + xRef = pResult; + + return xRef; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getCatalogSeparator( ) throw(SQLException, RuntimeException) +{ + return getLiteral(DBLITERAL_CATALOG_SEPARATOR); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getSchemas( ) throw(SQLException, RuntimeException) +{ + OLEVariant vtEmpty; + vtEmpty.setNoArg(); + + ADORecordset *pRecordset = NULL; + m_pADOConnection->OpenSchema(adSchemaSchemata,vtEmpty,vtEmpty,&pRecordset); + ADOS::ThrowException(*m_pADOConnection,*this); + + Reference< XResultSet > xRef = NULL; + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + pResult->setSchemasMap(); + xRef = pResult; + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumnPrivileges( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, + const ::rtl::OUString& columnNamePattern ) throw(SQLException, RuntimeException) +{ + // Create elements used in the array + HRESULT hr = S_OK; + SAFEARRAYBOUND rgsabound[1]; + SAFEARRAY *psa = NULL; + OLEVariant varCriteria[4]; + + // Create SafeArray Bounds and initialize the array + rgsabound[0].lLbound = 0; + rgsabound[0].cElements = sizeof varCriteria / sizeof varCriteria[0]; + psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); + + sal_Int32 nPos=0; + if(catalog.hasValue()) + varCriteria[nPos].setString(getString(catalog)); + + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_CATALOG + if(schema.toChar() != '%') + varCriteria[nPos].setString(schema); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_SCHEMA + + varCriteria[nPos].setString(table); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_NAME + + varCriteria[nPos].setString(columnNamePattern); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// COLUMN_NAME + + OLEVariant vtEmpty; + vtEmpty.setNoArg(); + + // Initialize and fill the SafeArray + OLEVariant vsa; + vsa.setArray(psa,VT_VARIANT); + + ADORecordset *pRecordset = NULL; + m_pADOConnection->OpenSchema(adSchemaColumnPrivileges,vsa,vtEmpty,&pRecordset); + ADOS::ThrowException(*m_pADOConnection,*this); + + Reference< XResultSet > xRef = NULL; + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + pResult->setColumnPrivilegesMap(); + xRef = pResult; + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns( + const Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& tableNamePattern, + const ::rtl::OUString& columnNamePattern ) throw(SQLException, RuntimeException) +{ + // Create elements used in the array + HRESULT hr = S_OK; + SAFEARRAYBOUND rgsabound[1]; + SAFEARRAY *psa = NULL; + OLEVariant varCriteria[4]; + + // Create SafeArray Bounds and initialize the array + rgsabound[0].lLbound = 0; + rgsabound[0].cElements = sizeof varCriteria / sizeof varCriteria[0]; + psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); + + sal_Int32 nPos=0; + if(catalog.hasValue()) + varCriteria[nPos].setString(getString(catalog)); + + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_CATALOG + if(schemaPattern.toChar() != '%') + varCriteria[nPos].setString(schemaPattern); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_SCHEMA + + if(tableNamePattern.toChar() != '%') + varCriteria[nPos].setString(tableNamePattern); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_NAME + + varCriteria[nPos].setString(columnNamePattern); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// COLUMN_NAME + + OLEVariant vtEmpty; + vtEmpty.setNoArg(); + + // Initialize and fill the SafeArray + OLEVariant vsa; + vsa.setArray(psa,VT_VARIANT); + + ADORecordset *pRecordset = NULL; + m_pADOConnection->OpenSchema(adSchemaColumns,vsa,vtEmpty,&pRecordset); + ADOS::ThrowException(*m_pADOConnection,*this); + + Reference< XResultSet > xRef = NULL; + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + pResult->setColumnsMap(); + xRef = pResult; + + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables( + const Any& catalog, const ::rtl::OUString& schemaPattern, + const ::rtl::OUString& tableNamePattern, const Sequence< ::rtl::OUString >& types ) throw(SQLException, RuntimeException) +{ + // Create elements used in the array + HRESULT hr = S_OK; + SAFEARRAYBOUND rgsabound[1]; + SAFEARRAY *psa = NULL; + OLEVariant varCriteria[4]; + + // Create SafeArray Bounds and initialize the array + rgsabound[0].lLbound = 0; + rgsabound[0].cElements = sizeof varCriteria / sizeof varCriteria[0]; + psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); + + sal_Int32 nPos=0; + if(catalog.hasValue()) + varCriteria[nPos].setString(getString(catalog)); + + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_CATALOG + if(schemaPattern.toChar() != '%') + varCriteria[nPos].setString(schemaPattern); + + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_SCHEMA + if(tableNamePattern.toChar() != '%') + varCriteria[nPos].setString(tableNamePattern); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_NAME + + ::rtl::OUString aTypes,aComma = ::rtl::OUString::createFromAscii(","); + const ::rtl::OUString* pBegin = types.getConstArray(); + const ::rtl::OUString* pEnd = pBegin + types.getLength(); + for(;pBegin != pEnd;++pBegin) + aTypes = aTypes + *pBegin + aComma; + + if(aTypes.getLength()) + varCriteria[nPos].setString(aTypes); + // else + // varCriteria[nPos].setString(::rtl::OUString::createFromAscii("TABLE")); + + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_TYPE + + OLEVariant vtEmpty; + vtEmpty.setNoArg(); + + // Initialize and fill the SafeArray + OLEVariant vsa; + vsa.setArray(psa,VT_VARIANT); + + ADORecordset *pRecordset = NULL; + m_pADOConnection->OpenSchema(adSchemaTables,vsa,vtEmpty,&pRecordset); + ADOS::ThrowException(*m_pADOConnection,*this); + + Reference< XResultSet > xRef = NULL; + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + pResult->setTablesMap(); + xRef = pResult; + + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getProcedureColumns( + const Any& catalog, const ::rtl::OUString& schemaPattern, + const ::rtl::OUString& procedureNamePattern, const ::rtl::OUString& columnNamePattern ) throw(SQLException, RuntimeException) +{ + // Create elements used in the array + HRESULT hr = S_OK; + SAFEARRAYBOUND rgsabound[1]; + SAFEARRAY *psa = NULL; + OLEVariant varCriteria[4]; + + // Create SafeArray Bounds and initialize the array + rgsabound[0].lLbound = 0; + rgsabound[0].cElements = sizeof varCriteria / sizeof varCriteria[0]; + psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); + + sal_Int32 nPos=0; + if(catalog.hasValue()) + varCriteria[nPos].setString(getString(catalog)); + + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_CATALOG + if(schemaPattern.toChar() != '%') + varCriteria[nPos].setString(schemaPattern); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_SCHEMA + + if(procedureNamePattern.toChar() != '%') + varCriteria[nPos].setString(procedureNamePattern); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_NAME + + if(columnNamePattern.toChar() != '%') + varCriteria[nPos].setString(columnNamePattern); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// COLUMN_NAME + + OLEVariant vtEmpty; + vtEmpty.setNoArg(); + + // Initialize and fill the SafeArray + OLEVariant vsa; + vsa.setArray(psa,VT_VARIANT); + + ADORecordset *pRecordset = NULL; + m_pADOConnection->OpenSchema(adSchemaProcedureParameters,vsa,vtEmpty,&pRecordset); + ADOS::ThrowException(*m_pADOConnection,*this); + + Reference< XResultSet > xRef = NULL; + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + pResult->setProcedureColumnsMap(); + xRef = pResult; + + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getProcedures( + const Any& catalog, const ::rtl::OUString& schemaPattern, + const ::rtl::OUString& procedureNamePattern ) throw(SQLException, RuntimeException) +{ + // Create elements used in the array + HRESULT hr = S_OK; + SAFEARRAYBOUND rgsabound[1]; + SAFEARRAY *psa = NULL; + OLEVariant varCriteria[3]; + + // Create SafeArray Bounds and initialize the array + rgsabound[0].lLbound = 0; + rgsabound[0].cElements = sizeof varCriteria / sizeof varCriteria[0]; + psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); + + sal_Int32 nPos=0; + if(catalog.hasValue()) + varCriteria[nPos].setString(getString(catalog)); + + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_CATALOG + if(schemaPattern.toChar() != '%') + varCriteria[nPos].setString(schemaPattern); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_SCHEMA + + if(procedureNamePattern.toChar() != '%') + varCriteria[nPos].setString(procedureNamePattern); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_NAME + + OLEVariant vtEmpty; + vtEmpty.setNoArg(); + + // Initialize and fill the SafeArray + OLEVariant vsa; + vsa.setArray(psa,VT_VARIANT); + + ADORecordset *pRecordset = NULL; + m_pADOConnection->OpenSchema(adSchemaProcedures,vsa,vtEmpty,&pRecordset); + ADOS::ThrowException(*m_pADOConnection,*this); + + Reference< XResultSet > xRef = NULL; + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + pResult->setProceduresMap(); + xRef = pResult; + + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getVersionColumns( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + Reference< XResultSet > xRef = NULL; + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(NULL); + xRef = pResult; + return xRef; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxBinaryLiteralLength( ) throw(SQLException, RuntimeException) +{ + return getMaxSize(DBLITERAL_BINARY_LITERAL); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxRowSize( ) throw(SQLException, RuntimeException) +{ + return getInt32Property(::rtl::OUString::createFromAscii("Maximum Row Size")); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxCatalogNameLength( ) throw(SQLException, RuntimeException) +{ + return getMaxSize(DBLITERAL_CATALOG_NAME); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxCharLiteralLength( ) throw(SQLException, RuntimeException) +{ + return getMaxSize(DBLITERAL_CHAR_LITERAL); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnNameLength( ) throw(SQLException, RuntimeException) +{ + return getMaxSize(DBLITERAL_COLUMN_NAME); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInIndex( ) throw(SQLException, RuntimeException) +{ + return getInt32Property(::rtl::OUString::createFromAscii("Max Columns in Index")); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxCursorNameLength( ) throw(SQLException, RuntimeException) +{ + return getMaxSize(DBLITERAL_CURSOR_NAME); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxConnections( ) throw(SQLException, RuntimeException) +{ + return getInt32Property(::rtl::OUString::createFromAscii("Active Sessions")); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInTable( ) throw(SQLException, RuntimeException) +{ + return getInt32Property(::rtl::OUString::createFromAscii("Max Columns in Table")); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxStatementLength( ) throw(SQLException, RuntimeException) +{ + return getMaxSize(DBLITERAL_TEXT_COMMAND); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxTableNameLength( ) throw(SQLException, RuntimeException) +{ + return getMaxSize(DBLITERAL_TABLE_NAME); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxTablesInSelect( ) throw(SQLException, RuntimeException) +{ + return getInt32Property(::rtl::OUString::createFromAscii("Maximum Tables in SELECT")); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getExportedKeys( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + // Create elements used in the array + HRESULT hr = S_OK; + SAFEARRAYBOUND rgsabound[1]; + SAFEARRAY *psa = NULL; + OLEVariant varCriteria[6]; + + // Create SafeArray Bounds and initialize the array + rgsabound[0].lLbound = 0; + rgsabound[0].cElements = sizeof varCriteria / sizeof varCriteria[0]; + psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); + + sal_Int32 nPos=0; + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_CATALOG + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_SCHEMA + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_NAME + + if(catalog.hasValue()) + varCriteria[nPos].setString(getString(catalog)); + + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_CATALOG + if(schema.toChar() != '%') + varCriteria[nPos].setString(schema); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_SCHEMA + + varCriteria[nPos].setString(table); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_NAME + + OLEVariant vtEmpty; + vtEmpty.setNoArg(); + + // Initialize and fill the SafeArray + OLEVariant vsa; + vsa.setArray(psa,VT_VARIANT); + + ADORecordset *pRecordset = NULL; + m_pADOConnection->OpenSchema(adSchemaForeignKeys,vsa,vtEmpty,&pRecordset); + ADOS::ThrowException(*m_pADOConnection,*this); + + Reference< XResultSet > xRef = NULL; + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + pResult->setCrossReferenceMap(); + xRef = pResult; + + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getImportedKeys( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + // Create elements used in the array + HRESULT hr = S_OK; + SAFEARRAYBOUND rgsabound[1]; + SAFEARRAY *psa = NULL; + OLEVariant varCriteria[6]; + + // Create SafeArray Bounds and initialize the array + rgsabound[0].lLbound = 0; + rgsabound[0].cElements = sizeof varCriteria / sizeof varCriteria[0]; + psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); + + sal_Int32 nPos=0; + if(catalog.hasValue()) + varCriteria[nPos].setString(getString(catalog)); + + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_CATALOG + if(schema.toChar() != '%') + varCriteria[nPos].setString(schema); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_SCHEMA + + varCriteria[nPos].setString(table); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_NAME + + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_CATALOG + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_SCHEMA + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_NAME + + OLEVariant vtEmpty; + vtEmpty.setNoArg(); + + // Initialize and fill the SafeArray + OLEVariant vsa; + vsa.setArray(psa,VT_VARIANT); + + ADORecordset *pRecordset = NULL; + m_pADOConnection->OpenSchema(adSchemaForeignKeys,vsa,vtEmpty,&pRecordset); + ADOS::ThrowException(*m_pADOConnection,*this); + + Reference< XResultSet > xRef = NULL; + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + pResult->setCrossReferenceMap(); + xRef = pResult; + + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getPrimaryKeys( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + // Create elements used in the array + HRESULT hr = S_OK; + SAFEARRAYBOUND rgsabound[1]; + SAFEARRAY *psa = NULL; + OLEVariant varCriteria[3]; + + // Create SafeArray Bounds and initialize the array + rgsabound[0].lLbound = 0; + rgsabound[0].cElements = sizeof varCriteria / sizeof varCriteria[0]; + psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); + + sal_Int32 nPos=0; + if(catalog.hasValue()) + varCriteria[nPos].setString(getString(catalog)); + + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_CATALOG + if(schema.toChar() != '%') + varCriteria[nPos].setString(schema); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_SCHEMA + + varCriteria[nPos].setString(table); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_NAME + + + OLEVariant vtEmpty; + vtEmpty.setNoArg(); + + // Initialize and fill the SafeArray + OLEVariant vsa; + vsa.setArray(psa,VT_VARIANT); + + ADORecordset *pRecordset = NULL; + m_pADOConnection->OpenSchema(adSchemaPrimaryKeys,vsa,vtEmpty,&pRecordset); + ADOS::ThrowException(*m_pADOConnection,*this); + + Reference< XResultSet > xRef = NULL; + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + pResult->setPrimaryKeysMap(); + xRef = pResult; + + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getIndexInfo( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, + sal_Bool unique, sal_Bool approximate ) throw(SQLException, RuntimeException) +{ + // Create elements used in the array + HRESULT hr = S_OK; + SAFEARRAYBOUND rgsabound[1]; + SAFEARRAY *psa = NULL; + OLEVariant varCriteria[5]; + + // Create SafeArray Bounds and initialize the array + rgsabound[0].lLbound = 0; + rgsabound[0].cElements = sizeof varCriteria / sizeof varCriteria[0]; + psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); + + sal_Int32 nPos=0; + if(catalog.hasValue()) + varCriteria[nPos].setString(getString(catalog)); + + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_CATALOG + if(schema.toChar() != '%') + varCriteria[nPos].setString(schema); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_SCHEMA + + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// INDEX_NAME + + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TYPE + + varCriteria[nPos].setString(table); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_NAME + + OLEVariant vtEmpty; + vtEmpty.setNoArg(); + + // Initialize and fill the SafeArray + OLEVariant vsa; + vsa.setArray(psa,VT_VARIANT); + + ADORecordset *pRecordset = NULL; + m_pADOConnection->OpenSchema(adSchemaIndexes,vsa,vtEmpty,&pRecordset); + ADOS::ThrowException(*m_pADOConnection,*this); + + Reference< XResultSet > xRef = NULL; + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + pResult->setIndexInfoMap(); + xRef = pResult; + + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getBestRowIdentifier( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, sal_Int32 scope, + sal_Bool nullable ) throw(SQLException, RuntimeException) +{ + Reference< XResultSet > xRef = NULL; + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(NULL); + xRef = pResult; + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges( + const Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& tableNamePattern ) throw(SQLException, RuntimeException) +{ + // Create elements used in the array + HRESULT hr = S_OK; + SAFEARRAYBOUND rgsabound[1]; + SAFEARRAY *psa = NULL; + OLEVariant varCriteria[5]; + + // Create SafeArray Bounds and initialize the array + rgsabound[0].lLbound = 0; + rgsabound[0].cElements = sizeof varCriteria / sizeof varCriteria[0]; + psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); + + sal_Int32 nPos=0; + if(catalog.hasValue()) + varCriteria[nPos].setString(getString(catalog)); + + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_CATALOG + if(schemaPattern.toChar() != '%') + varCriteria[nPos].setString(schemaPattern); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_SCHEMA + + if(tableNamePattern.toChar() != '%') + varCriteria[nPos].setString(tableNamePattern); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_NAME + + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// GRANTOR + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// GRANTEE + + OLEVariant vtEmpty; + vtEmpty.setNoArg(); + + // Initialize and fill the SafeArray + OLEVariant vsa; + vsa.setArray(psa,VT_VARIANT); + + ADORecordset *pRecordset = NULL; + m_pADOConnection->OpenSchema(adSchemaTablePrivileges,vsa,vtEmpty,&pRecordset); + ADOS::ThrowException(*m_pADOConnection,*this); + + Reference< XResultSet > xRef = NULL; + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + pResult->setTablePrivilegesMap(); + xRef = pResult; + + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getCrossReference( + const Any& primaryCatalog, const ::rtl::OUString& primarySchema, + const ::rtl::OUString& primaryTable, const Any& foreignCatalog, + const ::rtl::OUString& foreignSchema, const ::rtl::OUString& foreignTable ) throw(SQLException, RuntimeException) +{ + // Create elements used in the array + HRESULT hr = S_OK; + SAFEARRAYBOUND rgsabound[1]; + SAFEARRAY *psa = NULL; + OLEVariant varCriteria[6]; + + // Create SafeArray Bounds and initialize the array + rgsabound[0].lLbound = 0; + rgsabound[0].cElements = sizeof varCriteria / sizeof varCriteria[0]; + psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); + + sal_Int32 nPos=0; + if(primaryCatalog.hasValue()) + varCriteria[nPos].setString(getString(primaryCatalog)); + + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_CATALOG + if(primarySchema.toChar() != '%') + varCriteria[nPos].setString(primarySchema); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_SCHEMA + + varCriteria[nPos].setString(primaryTable); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_NAME + + if(foreignCatalog.hasValue()) + varCriteria[nPos].setString(getString(foreignCatalog)); + + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_CATALOG + if(foreignSchema.toChar() != '%') + varCriteria[nPos].setString(foreignSchema); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_SCHEMA + + varCriteria[nPos].setString(foreignTable); + hr = SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_NAME + + OLEVariant vtEmpty; + vtEmpty.setNoArg(); + + // Initialize and fill the SafeArray + OLEVariant vsa; + vsa.setArray(psa,VT_VARIANT); + + ADORecordset *pRecordset = NULL; + m_pADOConnection->OpenSchema(adSchemaForeignKeys,vsa,vtEmpty,&pRecordset); + ADOS::ThrowException(*m_pADOConnection,*this); + + Reference< XResultSet > xRef = NULL; + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + pResult->setCrossReferenceMap(); + xRef = pResult; + + return xRef; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::doesMaxRowSizeIncludeBlobs( ) throw(SQLException, RuntimeException) +{ + return getBoolProperty(::rtl::OUString::createFromAscii("Maximum Row Size Includes BLOB")); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesLowerCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Quoted Identifier Case Sensitivity")) & DBPROPVAL_IC_LOWER) == DBPROPVAL_IC_LOWER ; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesLowerCaseIdentifiers( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Identifier Case Sensitivity")) & DBPROPVAL_IC_LOWER) == DBPROPVAL_IC_LOWER ; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesMixedCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Quoted Identifier Case Sensitivity")) & DBPROPVAL_IC_MIXED) == DBPROPVAL_IC_MIXED ; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesMixedCaseIdentifiers( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Identifier Case Sensitivity")) & DBPROPVAL_IC_MIXED) == DBPROPVAL_IC_MIXED ; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesUpperCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Quoted Identifier Case Sensitivity")) & DBPROPVAL_IC_UPPER) == DBPROPVAL_IC_UPPER ; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesUpperCaseIdentifiers( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Identifier Case Sensitivity")) & DBPROPVAL_IC_UPPER) == DBPROPVAL_IC_UPPER ; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsAlterTableWithAddColumn( ) throw(SQLException, RuntimeException) +{ + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsAlterTableWithDropColumn( ) throw(SQLException, RuntimeException) +{ + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxIndexLength( ) throw(SQLException, RuntimeException) +{ + return getInt32Property(::rtl::OUString::createFromAscii("Maximum Index Size")); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsNonNullableColumns( ) throw(SQLException, RuntimeException) +{ + return getInt32Property(::rtl::OUString::createFromAscii("NULL Concatenation Behavior")) == DBPROPVAL_CB_NON_NULL; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getCatalogTerm( ) throw(SQLException, RuntimeException) +{ + return getStringProperty(::rtl::OUString::createFromAscii("Catalog Term")); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getIdentifierQuoteString( ) throw(SQLException, RuntimeException) +{ + return getLiteral(DBLITERAL_QUOTE_PREFIX); + +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getExtraNameCharacters( ) throw(SQLException, RuntimeException) +{ + return getStringProperty(::rtl::OUString::createFromAscii("Special Characters")); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsDifferentTableCorrelationNames( ) throw(SQLException, RuntimeException) +{ + return isCapable(DBLITERAL_CORRELATION_NAME); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::isCatalogAtStart( ) throw(SQLException, RuntimeException) +{ + return getInt32Property(::rtl::OUString::createFromAscii("Catalog Location")) == DBPROPVAL_CL_START; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::dataDefinitionIgnoredInTransactions( ) throw(SQLException, RuntimeException) +{ + return getInt32Property(::rtl::OUString::createFromAscii("Transaction DDL")) == DBPROPVAL_TC_DDL_IGNORE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::dataDefinitionCausesTransactionCommit( ) throw(SQLException, RuntimeException) +{ + return getInt32Property(::rtl::OUString::createFromAscii("Transaction DDL")) == DBPROPVAL_TC_DDL_COMMIT; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsDataManipulationTransactionsOnly( ) throw(SQLException, RuntimeException) +{ + return getInt32Property(::rtl::OUString::createFromAscii("Transaction DDL")) == DBPROPVAL_TC_DML; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsDataDefinitionAndDataManipulationTransactions( ) throw(SQLException, RuntimeException) +{ + return getInt32Property(::rtl::OUString::createFromAscii("Transaction DDL")) == DBPROPVAL_TC_ALL; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsPositionedDelete( ) throw(SQLException, RuntimeException) +{ + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsPositionedUpdate( ) throw(SQLException, RuntimeException) +{ + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenStatementsAcrossRollback( ) throw(SQLException, RuntimeException) +{ + return getInt32Property(::rtl::OUString::createFromAscii("Prepare Abort Behavior")) == DBPROPVAL_CB_PRESERVE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenStatementsAcrossCommit( ) throw(SQLException, RuntimeException) +{ + return getInt32Property(::rtl::OUString::createFromAscii("Prepare Commit Behavior")) == DBPROPVAL_CB_PRESERVE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenCursorsAcrossCommit( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Isolation Retention")) & DBPROPVAL_TR_COMMIT) == DBPROPVAL_TR_COMMIT; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenCursorsAcrossRollback( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Isolation Retention")) & DBPROPVAL_TR_ABORT) == DBPROPVAL_TR_ABORT; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsTransactionIsolationLevel( sal_Int32 level ) throw(SQLException, RuntimeException) +{ + sal_Bool bValue(sal_False); + + sal_Int32 nTxn = getInt32Property(::rtl::OUString::createFromAscii("Isolation Levels")); + if(level == TransactionIsolation::NONE) + bValue = sal_True; + else if(level == TransactionIsolation::READ_UNCOMMITTED) + bValue = (nTxn & DBPROPVAL_TI_READUNCOMMITTED) == DBPROPVAL_TI_READUNCOMMITTED; + else if(level == TransactionIsolation::READ_COMMITTED) + bValue = (nTxn & DBPROPVAL_TI_READCOMMITTED) == DBPROPVAL_TI_READCOMMITTED; + else if(level == TransactionIsolation::REPEATABLE_READ) + bValue = (nTxn & DBPROPVAL_TI_REPEATABLEREAD) == DBPROPVAL_TI_REPEATABLEREAD; + else if(level == TransactionIsolation::SERIALIZABLE) + bValue = (nTxn & DBPROPVAL_TI_SERIALIZABLE) == DBPROPVAL_TI_SERIALIZABLE; + + return bValue; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInDataManipulation( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Schema Usage")) & DBPROPVAL_SU_DML_STATEMENTS) == DBPROPVAL_SU_DML_STATEMENTS; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsANSI92FullSQL( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("SQL Support")) & DBPROPVAL_SQL_ANSI92_FULL) == DBPROPVAL_SQL_ANSI92_FULL; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsANSI92EntryLevelSQL( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("SQL Support")) & DBPROPVAL_SQL_ANSI92_ENTRY) == DBPROPVAL_SQL_ANSI92_ENTRY; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsIntegrityEnhancementFacility( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("SQL Support")) & DBPROPVAL_SQL_ANSI89_IEF) == DBPROPVAL_SQL_ANSI89_IEF; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInIndexDefinitions( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Schema Usage")) & DBPROPVAL_SU_INDEX_DEFINITION) == DBPROPVAL_SU_INDEX_DEFINITION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInTableDefinitions( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Schema Usage")) & DBPROPVAL_SU_TABLE_DEFINITION) == DBPROPVAL_SU_TABLE_DEFINITION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInTableDefinitions( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Catalog Usage")) & DBPROPVAL_CU_TABLE_DEFINITION) == DBPROPVAL_CU_TABLE_DEFINITION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInIndexDefinitions( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Catalog Usage")) & DBPROPVAL_CU_INDEX_DEFINITION) == DBPROPVAL_CU_INDEX_DEFINITION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInDataManipulation( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Catalog Usage")) & DBPROPVAL_CU_DML_STATEMENTS) == DBPROPVAL_CU_DML_STATEMENTS; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOuterJoins( ) throw(SQLException, RuntimeException) +{ + return getBoolProperty(::rtl::OUString::createFromAscii("Outer Join Capabilities")); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTableTypes( ) throw(SQLException, RuntimeException) +{ + // Create elements used in the array + Reference< XResultSet > xRef = NULL; + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(NULL); + xRef = pResult; + return xRef; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxStatements( ) throw(SQLException, RuntimeException) +{ + return 0; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxProcedureNameLength( ) throw(SQLException, RuntimeException) +{ + return getMaxSize(DBLITERAL_PROCEDURE_NAME); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxSchemaNameLength( ) throw(SQLException, RuntimeException) +{ + return getMaxSize(DBLITERAL_SCHEMA_NAME); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsTransactions( ) throw(SQLException, RuntimeException) +{ + return getInt32Property(::rtl::OUString::createFromAscii("Transaction DDL")) == DBPROPVAL_TC_NONE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::allProceduresAreCallable( ) throw(SQLException, RuntimeException) +{ + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsStoredProcedures( ) throw(SQLException, RuntimeException) +{ + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSelectForUpdate( ) throw(SQLException, RuntimeException) +{ + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::allTablesAreSelectable( ) throw(SQLException, RuntimeException) +{ + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::isReadOnly( ) throw(SQLException, RuntimeException) +{ + return getBoolProperty(::rtl::OUString::createFromAscii("Read-Only Data Source")); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::usesLocalFiles( ) throw(SQLException, RuntimeException) +{ + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::usesLocalFilePerTable( ) throw(SQLException, RuntimeException) +{ + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsTypeConversion( ) throw(SQLException, RuntimeException) +{ + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::nullPlusNonNullIsNull( ) throw(SQLException, RuntimeException) +{ + return getInt32Property(::rtl::OUString::createFromAscii("NULL Concatenation Behavior")) == DBPROPVAL_CB_NULL; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsColumnAliasing( ) throw(SQLException, RuntimeException) +{ + return isCapable(DBLITERAL_COLUMN_ALIAS); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsTableCorrelationNames( ) throw(SQLException, RuntimeException) +{ + return isCapable(DBLITERAL_CORRELATION_NAME); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsConvert( sal_Int32 fromType, sal_Int32 toType ) throw(SQLException, RuntimeException) +{ + return getBoolProperty(::rtl::OUString::createFromAscii("Rowset Conversions on Command")); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsExpressionsInOrderBy( ) throw(SQLException, RuntimeException) +{ + return getBoolProperty(::rtl::OUString::createFromAscii("ORDER BY Columns in Select List")); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsGroupBy( ) throw(SQLException, RuntimeException) +{ + return getInt32Property(::rtl::OUString::createFromAscii("GROUP BY Support")) != DBPROPVAL_GB_NOT_SUPPORTED; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsGroupByBeyondSelect( ) throw(SQLException, RuntimeException) +{ + return getInt32Property(::rtl::OUString::createFromAscii("GROUP BY Support")) != DBPROPVAL_GB_CONTAINS_SELECT; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsGroupByUnrelated( ) throw(SQLException, RuntimeException) +{ + return getInt32Property(::rtl::OUString::createFromAscii("GROUP BY Support")) == DBPROPVAL_GB_NO_RELATION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsMultipleTransactions( ) throw(SQLException, RuntimeException) +{ + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsMultipleResultSets( ) throw(SQLException, RuntimeException) +{ + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsLikeEscapeClause( ) throw(SQLException, RuntimeException) +{ + return isCapable(DBLITERAL_ESCAPE_PERCENT); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOrderByUnrelated( ) throw(SQLException, RuntimeException) +{ + return getBoolProperty(::rtl::OUString::createFromAscii("ORDER BY Columns in Select List")); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsUnion( ) throw(SQLException, RuntimeException) +{ + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsUnionAll( ) throw(SQLException, RuntimeException) +{ + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsMixedCaseIdentifiers( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Identifier Case Sensitivity")) & DBPROPVAL_IC_MIXED) == DBPROPVAL_IC_MIXED; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsMixedCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Identifier Case Sensitivity")) & DBPROPVAL_IC_MIXED) == DBPROPVAL_IC_MIXED; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedAtEnd( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("NULL Collation Order")) & DBPROPVAL_NC_END) == DBPROPVAL_NC_END; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedAtStart( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("NULL Collation Order")) & DBPROPVAL_NC_START) == DBPROPVAL_NC_START; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedHigh( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("NULL Collation Order")) & DBPROPVAL_NC_HIGH) == DBPROPVAL_NC_HIGH; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedLow( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("NULL Collation Order")) & DBPROPVAL_NC_LOW) == DBPROPVAL_NC_LOW; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInProcedureCalls( ) throw(SQLException, RuntimeException) +{ + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInPrivilegeDefinitions( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Schema Usage")) & DBPROPVAL_SU_PRIVILEGE_DEFINITION) == DBPROPVAL_SU_PRIVILEGE_DEFINITION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInProcedureCalls( ) throw(SQLException, RuntimeException) +{ + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInPrivilegeDefinitions( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Catalog Usage")) & DBPROPVAL_CU_PRIVILEGE_DEFINITION) == DBPROPVAL_CU_PRIVILEGE_DEFINITION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCorrelatedSubqueries( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Subquery Support")) & DBPROPVAL_SQ_CORRELATEDSUBQUERIES) == DBPROPVAL_SQ_CORRELATEDSUBQUERIES; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInComparisons( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Subquery Support")) & DBPROPVAL_SQ_COMPARISON) == DBPROPVAL_SQ_COMPARISON; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInExists( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Subquery Support")) & DBPROPVAL_SQ_EXISTS) == DBPROPVAL_SQ_EXISTS; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInIns( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Subquery Support")) & DBPROPVAL_SQ_IN) == DBPROPVAL_SQ_IN; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInQuantifieds( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Subquery Support")) & DBPROPVAL_SQ_QUANTIFIED) == DBPROPVAL_SQ_QUANTIFIED; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsANSI92IntermediateSQL( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("SQL Support")) & DBPROPVAL_SQL_ANSI92_INTERMEDIATE) == DBPROPVAL_SQL_ANSI92_INTERMEDIATE; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getURL( ) throw(SQLException, RuntimeException) +{ + return ::rtl::OUString::createFromAscii("sdbc:ado:")+ m_pADOConnection->GetConnectionString(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getUserName( ) throw(SQLException, RuntimeException) +{ + return getStringProperty(::rtl::OUString::createFromAscii("User Name")); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getDriverName( ) throw(SQLException, RuntimeException) +{ + return getStringProperty(::rtl::OUString::createFromAscii("Provider Friendly Name")); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getDriverVersion( ) throw(SQLException, RuntimeException) +{ + return getStringProperty(::rtl::OUString::createFromAscii("Provider Version")); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getDatabaseProductVersion( ) throw(SQLException, RuntimeException) +{ + return getStringProperty(::rtl::OUString::createFromAscii("DBMS Version")); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getDatabaseProductName( ) throw(SQLException, RuntimeException) +{ + return getStringProperty(::rtl::OUString::createFromAscii("DBMS Name")); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getProcedureTerm( ) throw(SQLException, RuntimeException) +{ + return getStringProperty(::rtl::OUString::createFromAscii("Procedure Term")); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getSchemaTerm( ) throw(SQLException, RuntimeException) +{ + return getStringProperty(::rtl::OUString::createFromAscii("Schema Term")); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getDriverMajorVersion( ) throw(RuntimeException) +{ + return 1; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getDefaultTransactionIsolation( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nRet = TransactionIsolation::NONE; + switch(m_pADOConnection->get_IsolationLevel()) + { + case adXactReadCommitted: + nRet = TransactionIsolation::READ_COMMITTED; + break; + case adXactRepeatableRead: + nRet = TransactionIsolation::REPEATABLE_READ; + break; + case adXactSerializable: + nRet = TransactionIsolation::SERIALIZABLE; + break; + case adXactReadUncommitted: + nRet = TransactionIsolation::READ_UNCOMMITTED; + break; + default: + ; + } + return nRet; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getDriverMinorVersion( ) throw(RuntimeException) +{ + return 0; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getSQLKeywords( ) throw(SQLException, RuntimeException) +{ + ADORecordset *pRecordset = NULL; + OLEVariant vtEmpty; + vtEmpty.setNoArg(); + m_pADOConnection->OpenSchema(adSchemaDBInfoKeywords,vtEmpty,vtEmpty,&pRecordset); + ADOS::ThrowException(*m_pADOConnection,*this); + WpADORecordset aRecordset(pRecordset); + + aRecordset.MoveFirst(); + OLEVariant aValue; + ::rtl::OUString aRet,aComma = ::rtl::OUString::createFromAscii(",");; + while(!aRecordset.IsAtEOF()) + { + WpOLEAppendCollection<ADOFields, ADOField, WpADOField> aFields(aRecordset.GetFields()); + WpADOField aField(aFields.GetItem(0)); + aField.get_Value(aValue); + aRet = aRet + aValue + aComma; + aRecordset.MoveNext(); + } + aRecordset.Close(); + return aRet.copy(0,aRet.lastIndexOf(',')); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getSearchStringEscape( ) throw(SQLException, RuntimeException) +{ + return getLiteral(DBLITERAL_ESCAPE_PERCENT); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getStringFunctions( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + return aValue.copy(0,aValue.lastIndexOf(',')); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getTimeDateFunctions( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + return aValue; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getSystemFunctions( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + return aValue.copy(0,aValue.lastIndexOf(',')); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getNumericFunctions( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + return aValue; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsExtendedSQLGrammar( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("SQL Support")) & DBPROPVAL_SQL_ODBC_EXTENDED) == DBPROPVAL_SQL_ODBC_EXTENDED; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCoreSQLGrammar( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("SQL Support")) & DBPROPVAL_SQL_ODBC_CORE) == DBPROPVAL_SQL_ODBC_CORE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsMinimumSQLGrammar( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("SQL Support")) & DBPROPVAL_SQL_ODBC_MINIMUM) == DBPROPVAL_SQL_ODBC_MINIMUM; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsFullOuterJoins( ) throw(SQLException, RuntimeException) +{ + return (getInt32Property(::rtl::OUString::createFromAscii("Outer Join Capabilities")) & 0x00000004L) == 0x00000004L; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsLimitedOuterJoins( ) throw(SQLException, RuntimeException) +{ + return supportsFullOuterJoins( ); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInGroupBy( ) throw(SQLException, RuntimeException) +{ + return getInt32Property(::rtl::OUString::createFromAscii("Max Columns in Group By")); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInOrderBy( ) throw(SQLException, RuntimeException) +{ + return getInt32Property(::rtl::OUString::createFromAscii("Max Columns in Order by")); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInSelect( ) throw(SQLException, RuntimeException) +{ + return getInt32Property(::rtl::OUString::createFromAscii("Max Columns in Select")); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxUserNameLength( ) throw(SQLException, RuntimeException) +{ + return getMaxSize(DBLITERAL_USER_NAME); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsResultSetType( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsResultSetConcurrency( sal_Int32 setType, sal_Int32 concurrency ) throw(SQLException, RuntimeException) +{ +// ADOProperties* pProps = m_pADOConnection->get_Properties(); +// OSL_ENSHURE(pProps,"There are no properties at the connection"); +// if(!pProps) +// return sal_False; +// pProps->AddRef(); +// ADO_PROP("Maximum Row Size"INCLUDESBLOB); +// sal_Bool bValue(sal_False); +// bValue = (!aVar.isNull() && !aVar.isEmpty() ? aVar.getBool() : sal_False); +// pProps->Release(); +// return bValue; + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::ownUpdatesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + return ResultSetType::FORWARD_ONLY != setType; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::ownDeletesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + return ResultSetType::FORWARD_ONLY != setType; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::ownInsertsAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + return ResultSetType::FORWARD_ONLY != setType; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::othersUpdatesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + return ResultSetType::FORWARD_ONLY != setType; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::othersDeletesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + return ResultSetType::FORWARD_ONLY != setType; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::othersInsertsAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + return ResultSetType::FORWARD_ONLY != setType; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::updatesAreDetected( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + return ResultSetType::FORWARD_ONLY != setType; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::deletesAreDetected( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + return ResultSetType::FORWARD_ONLY != setType; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::insertsAreDetected( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + return ResultSetType::FORWARD_ONLY != setType; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsBatchUpdates( ) throw(SQLException, RuntimeException) +{ + return sal_True; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getUDTs( const Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& typeNamePattern, const Sequence< sal_Int32 >& types ) throw(SQLException, RuntimeException) +{ + Reference< XResultSet > xRef = NULL; + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(NULL); + xRef = pResult; + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XConnection > SAL_CALL ODatabaseMetaData::getConnection( ) throw(SQLException, RuntimeException) +{ + return (Reference< XConnection >)m_pConnection;//new OConnection(m_aConnectionHandle); +} +// ------------------------------------------------------------------------- + + diff --git a/connectivity/source/drivers/ado/ADatabaseMetaDataResultSet.cxx b/connectivity/source/drivers/ado/ADatabaseMetaDataResultSet.cxx new file mode 100644 index 000000000000..295029ab8a1f --- /dev/null +++ b/connectivity/source/drivers/ado/ADatabaseMetaDataResultSet.cxx @@ -0,0 +1,1282 @@ +/************************************************************************* + * + * $RCSfile: ADatabaseMetaDataResultSet.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#ifndef _CONNECTIVITY_ADO_ADATABASEMETADATARESULTSET_HXX_ +#include "ado/ADatabaseMetaDataResultSet.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_ADATABASEMETADATARESULTSETMETADATA_HXX_ +#include "ado/ADatabaseMetaDataResultSetMetaData.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_KEYRULE_HPP_ +#include <com/sun/star/sdbc/KeyRule.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_PROCEDURERESULT_HPP_ +#include <com/sun/star/sdbc/ProcedureResult.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_INDEXTYPE_HPP_ +#include <com/sun/star/sdbc/IndexType.hpp> +#endif +#ifndef _UTL_PROPERTY_HXX_ +#include <unotools/property.hxx> +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_RESULTSETCONCURRENCY_HPP_ +#include <com/sun/star/sdbc/ResultSetConcurrency.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_RESULTSETTYPE_HPP_ +#include <com/sun/star/sdbc/ResultSetType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_FETCHDIRECTION_HPP_ +#include <com/sun/star/sdbc/FetchDirection.hpp> +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif + +#include <oledb.h> + + +using namespace connectivity::ado; +using namespace cppu; +//------------------------------------------------------------------------------ +using namespace ::com::sun::star::lang; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::sdbc; + +// ------------------------------------------------------------------------- +ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet(ADORecordset* _pRecordSet) : ODatabaseMetaDataResultSet_BASE(m_aMutex) + ,OPropertySetHelper(ODatabaseMetaDataResultSet_BASE::rBHelper) + ,m_aStatement(NULL) + ,m_xMetaData(NULL) + ,m_pRecordSet(_pRecordSet) + ,m_bEOF(sal_False) +{ + osl_incrementInterlockedCount( &m_refCount ); + m_aColMapping.push_back(-1); + if(_pRecordSet) + { + m_pRecordSet->AddRef(); + VARIANT_BOOL bIsAtBOF; + m_pRecordSet->get_BOF(&bIsAtBOF); + m_bOnFirstAfterOpen = !(sal_Bool)bIsAtBOF; + } + else + m_bOnFirstAfterOpen = sal_False; + osl_decrementInterlockedCount( &m_refCount ); + // allocBuffer(); +} + +// ------------------------------------------------------------------------- +ODatabaseMetaDataResultSet::~ODatabaseMetaDataResultSet() +{ + if(m_pRecordSet) + m_pRecordSet->Release(); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::disposing(void) +{ + OPropertySetHelper::disposing(); + + ::osl::MutexGuard aGuard(m_aMutex); + if(m_pRecordSet) + m_pRecordSet->Close(); + m_aStatement = NULL; + m_xMetaData = NULL; +} +// ------------------------------------------------------------------------- +Any SAL_CALL ODatabaseMetaDataResultSet::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = OPropertySetHelper::queryInterface(rType); + if(!aRet.hasValue()) + aRet = ODatabaseMetaDataResultSet_BASE::queryInterface(rType); + return aRet; +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL ODatabaseMetaDataResultSet::getTypes( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ), + ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ), + ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > *)0 )); + + return ::utl::concatSequences(aTypes.getTypes(),ODatabaseMetaDataResultSet_BASE::getTypes()); +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed ) + throw DisposedException(); + + Reference< XResultSetMetaData > xMeta = getMetaData(); + sal_Int32 nLen = xMeta->getColumnCount(); + sal_Int32 i = 1; + for(;i<=nLen;++i) + if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) : columnName.equalsIgnoreCase(xMeta->getColumnName(i))) + break; + return i; +} +// ------------------------------------------------------------------------- +Reference< ::com::sun::star::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getBinaryStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + columnIndex = mapColumn(columnIndex); + return NULL; +} +// ------------------------------------------------------------------------- +Reference< ::com::sun::star::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getCharacterStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + columnIndex = mapColumn(columnIndex); + return NULL; +} + +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + columnIndex = mapColumn(columnIndex); + ADO_GETFIELD(columnIndex); + aField.get_Value(m_aValue); return m_aValue; +} +// ------------------------------------------------------------------------- + +sal_Int8 SAL_CALL ODatabaseMetaDataResultSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + columnIndex = mapColumn(columnIndex); + ADO_GETFIELD(columnIndex); + aField.get_Value(m_aValue); + if(m_aValueRange.size() && (m_aValueRangeIter = m_aValueRange.find(columnIndex)) != m_aValueRange.end()) + return (*m_aValueRangeIter).second[(sal_Int32)m_aValue]; + else if(m_aStrValueRange.size() && (m_aStrValueRangeIter = m_aStrValueRange.find(columnIndex)) != m_aStrValueRange.end()) + return (*m_aStrValueRangeIter).second[m_aValue]; + return m_aValue; +} +// ------------------------------------------------------------------------- + +Sequence< sal_Int8 > SAL_CALL ODatabaseMetaDataResultSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + columnIndex = mapColumn(columnIndex); + ADO_GETFIELD(columnIndex); + aField.get_Value(m_aValue); + return m_aValue; +} +// ------------------------------------------------------------------------- + +::com::sun::star::util::Date SAL_CALL ODatabaseMetaDataResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + columnIndex = mapColumn(columnIndex); + ADO_GETFIELD(columnIndex); + aField.get_Value(m_aValue); + return m_aValue; +} +// ------------------------------------------------------------------------- + +double SAL_CALL ODatabaseMetaDataResultSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + columnIndex = mapColumn(columnIndex); + ADO_GETFIELD(columnIndex); + aField.get_Value(m_aValue); + return m_aValue; +} +// ------------------------------------------------------------------------- + +float SAL_CALL ODatabaseMetaDataResultSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + columnIndex = mapColumn(columnIndex); + ADO_GETFIELD(columnIndex); + aField.get_Value(m_aValue); + return m_aValue; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + columnIndex = mapColumn(columnIndex); + ADO_GETFIELD(columnIndex); + aField.get_Value(m_aValue); + if(m_aValueRange.size() && (m_aValueRangeIter = m_aValueRange.find(columnIndex)) != m_aValueRange.end()) + return (*m_aValueRangeIter).second[(sal_Int32)m_aValue]; + else if(m_aStrValueRange.size() && (m_aStrValueRangeIter = m_aStrValueRange.find(columnIndex)) != m_aStrValueRange.end()) + return (*m_aStrValueRangeIter).second[m_aValue]; + return m_aValue; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getRow( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + return 0; +} +// ------------------------------------------------------------------------- + +sal_Int64 SAL_CALL ODatabaseMetaDataResultSet::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + columnIndex = mapColumn(columnIndex); + ADO_GETFIELD(columnIndex); + return sal_Int64(0); +} +// ------------------------------------------------------------------------- + +Reference< XResultSetMetaData > SAL_CALL ODatabaseMetaDataResultSet::getMetaData( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + if(!m_xMetaData.is()) + m_xMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); + + return m_xMetaData; +} +// ------------------------------------------------------------------------- +Reference< XArray > SAL_CALL ODatabaseMetaDataResultSet::getArray( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + columnIndex = mapColumn(columnIndex); + return NULL; +} + +// ------------------------------------------------------------------------- + +Reference< XClob > SAL_CALL ODatabaseMetaDataResultSet::getClob( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + columnIndex = mapColumn(columnIndex); + return NULL; +} +// ------------------------------------------------------------------------- +Reference< XBlob > SAL_CALL ODatabaseMetaDataResultSet::getBlob( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + columnIndex = mapColumn(columnIndex); + return NULL; +} +// ------------------------------------------------------------------------- + +Reference< XRef > SAL_CALL ODatabaseMetaDataResultSet::getRef( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + columnIndex = mapColumn(columnIndex); + return NULL; +} +// ------------------------------------------------------------------------- + +Any SAL_CALL ODatabaseMetaDataResultSet::getObject( sal_Int32 columnIndex, const Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + columnIndex = mapColumn(columnIndex); + return Any(); +} +// ------------------------------------------------------------------------- + +sal_Int16 SAL_CALL ODatabaseMetaDataResultSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + columnIndex = mapColumn(columnIndex); + ADO_GETFIELD(columnIndex); + aField.get_Value(m_aValue); + if(m_aValueRange.size() && (m_aValueRangeIter = m_aValueRange.find(columnIndex)) != m_aValueRange.end()) + return (*m_aValueRangeIter).second[(sal_Int32)m_aValue]; + else if(m_aStrValueRange.size() && (m_aStrValueRangeIter = m_aStrValueRange.find(columnIndex)) != m_aStrValueRange.end()) + return (*m_aStrValueRangeIter).second[m_aValue]; + return m_aValue; +} +// ------------------------------------------------------------------------- + +::rtl::OUString SAL_CALL ODatabaseMetaDataResultSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + columnIndex = mapColumn(columnIndex); + ADO_GETFIELD(columnIndex); + aField.get_Value(m_aValue); + + if(m_aIntValueRange.size() && (m_aIntValueRangeIter = m_aIntValueRange.find(columnIndex)) != m_aIntValueRange.end()) + return (*m_aIntValueRangeIter).second[m_aValue]; + return m_aValue; +} + +// ------------------------------------------------------------------------- + + +::com::sun::star::util::Time SAL_CALL ODatabaseMetaDataResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + columnIndex = mapColumn(columnIndex); + ADO_GETFIELD(columnIndex); + aField.get_Value(m_aValue); return m_aValue; +} +// ------------------------------------------------------------------------- + + +::com::sun::star::util::DateTime SAL_CALL ODatabaseMetaDataResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + columnIndex = mapColumn(columnIndex); + ADO_GETFIELD(columnIndex); + aField.get_Value(m_aValue); return m_aValue; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isAfterLast( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + sal_Int16 bIsAtEOF; + m_pRecordSet->get_EOF(&bIsAtEOF); + return bIsAtEOF; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isFirst( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + return m_nRowPos == 1; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isLast( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + return sal_True; +} +// ------------------------------------------------------------------------- +void SAL_CALL ODatabaseMetaDataResultSet::beforeFirst( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + if(first()) + previous(); +} +// ------------------------------------------------------------------------- +void SAL_CALL ODatabaseMetaDataResultSet::afterLast( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + if(last()) + next(); + m_bEOF = sal_True; +} +// ------------------------------------------------------------------------- + +void SAL_CALL ODatabaseMetaDataResultSet::close( ) throw(SQLException, RuntimeException) +{ + { + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + } + dispose(); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::first( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(!m_pRecordSet) + return sal_False; + + sal_Bool bRet; + if(bRet = SUCCEEDED(m_pRecordSet->MoveFirst())) + m_nRowPos = 1; + return bRet; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::last( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed ) + throw DisposedException(); + + return m_pRecordSet ? SUCCEEDED(m_pRecordSet->MoveLast()) : sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(first()) + { + OLEVariant aEmpty; + aEmpty.setNoArg(); + sal_Bool bRet = SUCCEEDED(m_pRecordSet->Move(row,aEmpty)); + if(bRet) + m_nRowPos = row; + return bRet; + } + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::relative( sal_Int32 row ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(!m_pRecordSet) + return sal_False; + + OLEVariant aEmpty; + aEmpty.setNoArg(); + sal_Bool bRet = SUCCEEDED(m_pRecordSet->Move(row,aEmpty)); + if(bRet) + m_nRowPos += row; + return bRet; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::previous( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(!m_pRecordSet) + return sal_False; + + sal_Bool bRet = SUCCEEDED(m_pRecordSet->MovePrevious()); + if(bRet) + --m_nRowPos; + return bRet; +} +// ------------------------------------------------------------------------- +Reference< XInterface > SAL_CALL ODatabaseMetaDataResultSet::getStatement( ) throw(SQLException, RuntimeException) +{ + return m_aStatement.get(); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowDeleted( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + RecordStatusEnum eRec; + m_pRecordSet->get_Status((sal_Int32*)&eRec); + return (eRec & adRecDeleted) == adRecDeleted; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowInserted( ) throw(SQLException, RuntimeException) +{ ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + RecordStatusEnum eRec; + m_pRecordSet->get_Status((sal_Int32*)&eRec); + return (eRec & adRecNew) == adRecNew; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowUpdated( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + RecordStatusEnum eRec; + m_pRecordSet->get_Status((sal_Int32*)&eRec); + return (eRec & adRecModified) == adRecModified; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isBeforeFirst( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(!m_pRecordSet) + return sal_True; + + sal_Int16 bIsAtBOF; + m_pRecordSet->get_BOF(&bIsAtBOF); + return bIsAtBOF; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::next( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(!m_pRecordSet) + return sal_False; + + if(m_bOnFirstAfterOpen) + { + m_bOnFirstAfterOpen = sal_False; + return sal_True; + } + else + return SUCCEEDED(m_pRecordSet->MoveNext()); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::wasNull( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + return m_aValue.isNull(); +} +// ------------------------------------------------------------------------- +void SAL_CALL ODatabaseMetaDataResultSet::refreshRow( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + m_pRecordSet->Resync(adAffectCurrent,adResyncAllValues); +} +// ------------------------------------------------------------------------- + +void SAL_CALL ODatabaseMetaDataResultSet::cancel( ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(!m_pRecordSet) + throw SQLException(); + + m_pRecordSet->Cancel(); +} +// ------------------------------------------------------------------------- +void SAL_CALL ODatabaseMetaDataResultSet::clearWarnings( ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- +Any SAL_CALL ODatabaseMetaDataResultSet::getWarnings( ) throw(SQLException, RuntimeException) +{ + return Any(); +} +//------------------------------------------------------------------------------ +sal_Int32 ODatabaseMetaDataResultSet::getResultSetConcurrency() const +{ + return ResultSetConcurrency::READ_ONLY; +} +//------------------------------------------------------------------------------ +sal_Int32 ODatabaseMetaDataResultSet::getResultSetType() const +{ + return ResultSetType::FORWARD_ONLY; +} +//------------------------------------------------------------------------------ +sal_Int32 ODatabaseMetaDataResultSet::getFetchDirection() const +{ + return FetchDirection::FORWARD; +} +//------------------------------------------------------------------------------ +sal_Int32 ODatabaseMetaDataResultSet::getFetchSize() const +{ + sal_Int32 nValue=-1; + if(m_pRecordSet) + m_pRecordSet->get_CacheSize(&nValue); + return nValue; +} +//------------------------------------------------------------------------------ +::rtl::OUString ODatabaseMetaDataResultSet::getCursorName() const +{ + return ::rtl::OUString(); +} + +//------------------------------------------------------------------------------ +void ODatabaseMetaDataResultSet::setFetchDirection(sal_Int32 _par0) +{ +} +//------------------------------------------------------------------------------ +void ODatabaseMetaDataResultSet::setFetchSize(sal_Int32 _par0) +{ + if(m_pRecordSet) + m_pRecordSet->put_CacheSize(_par0); +} +// ------------------------------------------------------------------------- +::cppu::IPropertyArrayHelper* ODatabaseMetaDataResultSet::createArrayHelper( ) const +{ + + Sequence< com::sun::star::beans::Property > aProps(5); + com::sun::star::beans::Property* pProperties = aProps.getArray(); + sal_Int32 nPos = 0; + DECL_PROP0(CURSORNAME, ::rtl::OUString); + DECL_PROP0(FETCHDIRECTION, sal_Int32); + DECL_PROP0(FETCHSIZE, sal_Int32); + DECL_PROP0(RESULTSETCONCURRENCY,sal_Int32); + DECL_PROP0(RESULTSETTYPE, sal_Int32); + + return new ::cppu::OPropertyArrayHelper(aProps); +} +// ------------------------------------------------------------------------- +::cppu::IPropertyArrayHelper & ODatabaseMetaDataResultSet::getInfoHelper() +{ + return *const_cast<ODatabaseMetaDataResultSet*>(this)->getArrayHelper(); +} +// ------------------------------------------------------------------------- +sal_Bool ODatabaseMetaDataResultSet::convertFastPropertyValue( + Any & rConvertedValue, + Any & rOldValue, + sal_Int32 nHandle, + const Any& rValue ) + throw (::com::sun::star::lang::IllegalArgumentException) +{ + switch(nHandle) + { + case PROPERTY_ID_CURSORNAME: + case PROPERTY_ID_RESULTSETCONCURRENCY: + case PROPERTY_ID_RESULTSETTYPE: + throw ::com::sun::star::lang::IllegalArgumentException(); + break; + case PROPERTY_ID_FETCHDIRECTION: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection()); + case PROPERTY_ID_FETCHSIZE: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize()); + default: + ; + } + return sal_False; +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::setFastPropertyValue_NoBroadcast( + sal_Int32 nHandle, + const Any& rValue + ) + throw (Exception) +{ + switch(nHandle) + { + case PROPERTY_ID_CURSORNAME: + case PROPERTY_ID_RESULTSETCONCURRENCY: + case PROPERTY_ID_RESULTSETTYPE: + case PROPERTY_ID_FETCHDIRECTION: + case PROPERTY_ID_FETCHSIZE: + throw Exception(); + break; + default: + OSL_ENSHURE(0,"setFastPropertyValue_NoBroadcast: Illegal handle value!"); + } +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::getFastPropertyValue( + Any& rValue, + sal_Int32 nHandle + ) const +{ + switch(nHandle) + { + case PROPERTY_ID_CURSORNAME: + rValue <<= getCursorName(); + break; + case PROPERTY_ID_RESULTSETCONCURRENCY: + rValue <<= getResultSetConcurrency(); + break; + case PROPERTY_ID_RESULTSETTYPE: + rValue <<= getResultSetType(); + break; + case PROPERTY_ID_FETCHDIRECTION: + rValue <<= getFetchDirection(); + break; + case PROPERTY_ID_FETCHSIZE: + rValue <<= getFetchSize(); + break; + } +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::setProceduresMap() +{ + + for(sal_Int32 i=1;i<4;i++) + m_aColMapping.push_back(i); + m_aColMapping.push_back(5); + m_aColMapping.push_back(7); + m_aColMapping.push_back(8); + m_aColMapping.push_back(6); + m_aColMapping.push_back(4); + + ::std::map<sal_Int32,sal_Int32> aMap; + aMap[DB_PT_UNKNOWN] = ProcedureResult::UNKNOWN; + aMap[DB_PT_PROCEDURE] = ProcedureResult::NONE; + aMap[DB_PT_FUNCTION] = ProcedureResult::RETURN; + m_aValueRange[4] = aMap; + + ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); + pMetaData->setProceduresMap(); + m_xMetaData = pMetaData; +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::setCatalogsMap() +{ + m_aColMapping.push_back(1); + + m_xMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::setSchemasMap() +{ + m_aColMapping.push_back(2); + + m_xMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::setColumnPrivilegesMap() +{ + + m_aColMapping.push_back(3); + m_aColMapping.push_back(4); + m_aColMapping.push_back(5); + m_aColMapping.push_back(6); + m_aColMapping.push_back(2); + m_aColMapping.push_back(9); + m_aColMapping.push_back(10); + + ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); + pMetaData->setColumnPrivilegesMap(); + m_xMetaData = pMetaData; +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::setColumnsMap() +{ + + for(sal_Int32 i=1;i<5;++i) + m_aColMapping.push_back(i); + + m_aColMapping.push_back(12); + m_aColMapping.push_back(12); // is used as TYPE_NAME + + m_aColMapping.push_back(14); + m_aColMapping.push_back(6); + m_aColMapping.push_back(17); + m_aColMapping.push_back(18); + + m_aColMapping.push_back(11); + m_aColMapping.push_back(29); + m_aColMapping.push_back(9); + m_aColMapping.push_back(18); + m_aColMapping.push_back(18); + + m_aColMapping.push_back(15); + m_aColMapping.push_back(7); + m_aColMapping.push_back(11); + + ::std::map<sal_Int32,sal_Int32> aMap; + aMap[DBTYPE_EMPTY] = DataType::SQLNULL; + aMap[DBTYPE_NULL] = DataType::SQLNULL; + aMap[DBTYPE_I2] = DataType::SMALLINT; + aMap[DBTYPE_I4] = DataType::INTEGER; + aMap[DBTYPE_R4] = DataType::FLOAT; + aMap[DBTYPE_R8] = DataType::DOUBLE; + aMap[DBTYPE_CY] = DataType::BIGINT; + aMap[DBTYPE_DATE] = DataType::DATE; + aMap[DBTYPE_BSTR] = DataType::VARCHAR; + aMap[DBTYPE_IDISPATCH] = DataType::OBJECT; + aMap[DBTYPE_ERROR] = DataType::OTHER; + aMap[DBTYPE_BOOL] = DataType::BIT; + aMap[DBTYPE_VARIANT] = DataType::STRUCT; + aMap[DBTYPE_IUNKNOWN] = DataType::OTHER; + aMap[DBTYPE_DECIMAL] = DataType::DECIMAL; + aMap[DBTYPE_UI1] = DataType::TINYINT; + aMap[DBTYPE_ARRAY] = DataType::ARRAY; + aMap[DBTYPE_BYREF] = DataType::REF; + aMap[DBTYPE_I1] = DataType::CHAR; + aMap[DBTYPE_UI2] = DataType::SMALLINT; + aMap[DBTYPE_UI4] = DataType::INTEGER; + + // aMap[The] = ; + // aMap[in] = ; + aMap[DBTYPE_I8] = DataType::BIGINT; + aMap[DBTYPE_UI8] = DataType::BIGINT; + aMap[DBTYPE_GUID] = DataType::OTHER; + aMap[DBTYPE_VECTOR] = DataType::OTHER; + aMap[DBTYPE_FILETIME] = DataType::OTHER; + aMap[DBTYPE_RESERVED] = DataType::OTHER; + + // aMap[The] = ; + aMap[DBTYPE_BYTES] = DataType::VARBINARY; + aMap[DBTYPE_STR] = DataType::LONGVARCHAR; + aMap[DBTYPE_WSTR] = DataType::LONGVARCHAR; + aMap[DBTYPE_NUMERIC] = DataType::NUMERIC; + aMap[DBTYPE_UDT] = DataType::OTHER; + aMap[DBTYPE_DBDATE] = DataType::DATE; + aMap[DBTYPE_DBTIME] = DataType::TIME; + aMap[DBTYPE_DBTIMESTAMP] = DataType::TIMESTAMP; + aMap[DBTYPE_HCHAPTER] = DataType::OTHER; + aMap[DBTYPE_PROPVARIANT] = DataType::OTHER; + aMap[DBTYPE_VARNUMERIC] = DataType::NUMERIC; + + m_aValueRange[12] = aMap; + + ::std::map< sal_Int32,::rtl::OUString> aMap2; + aMap2[0] = ::rtl::OUString::createFromAscii("YES"); + aMap2[1] = ::rtl::OUString::createFromAscii("NO"); + m_aIntValueRange[18] = aMap2; + + ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); + pMetaData->setColumnsMap(); + m_xMetaData = pMetaData; +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::setTablesMap() +{ + + for(sal_Int32 i=1;i<5;i++) + m_aColMapping.push_back(i); + m_aColMapping.push_back(6); + + ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); + pMetaData->setTablesMap(); + m_xMetaData = pMetaData; +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::setProcedureColumnsMap() +{ + + for(sal_Int32 i=1;i<5;i++) + m_aColMapping.push_back(i); + m_aColMapping.push_back(6); + m_aColMapping.push_back(10); + m_aColMapping.push_back(16); + m_aColMapping.push_back(13); + m_aColMapping.push_back(11); + m_aColMapping.push_back(12); + + m_aColMapping.push_back(9); + m_aColMapping.push_back(14); + + ::std::map<sal_Int32,sal_Int32> aMap; + aMap[DBTYPE_EMPTY] = DataType::SQLNULL; + aMap[DBTYPE_NULL] = DataType::SQLNULL; + aMap[DBTYPE_I2] = DataType::SMALLINT; + aMap[DBTYPE_I4] = DataType::INTEGER; + aMap[DBTYPE_R4] = DataType::FLOAT; + aMap[DBTYPE_R8] = DataType::DOUBLE; + aMap[DBTYPE_CY] = DataType::BIGINT; + aMap[DBTYPE_DATE] = DataType::DATE; + aMap[DBTYPE_BSTR] = DataType::VARCHAR; + aMap[DBTYPE_IDISPATCH] = DataType::OBJECT; + aMap[DBTYPE_ERROR] = DataType::OTHER; + aMap[DBTYPE_BOOL] = DataType::BIT; + aMap[DBTYPE_VARIANT] = DataType::STRUCT; + aMap[DBTYPE_IUNKNOWN] = DataType::OTHER; + aMap[DBTYPE_DECIMAL] = DataType::DECIMAL; + aMap[DBTYPE_UI1] = DataType::TINYINT; + aMap[DBTYPE_ARRAY] = DataType::ARRAY; + aMap[DBTYPE_BYREF] = DataType::REF; + aMap[DBTYPE_I1] = DataType::CHAR; + aMap[DBTYPE_UI2] = DataType::SMALLINT; + aMap[DBTYPE_UI4] = DataType::INTEGER; + + // aMap[The] = ; + // aMap[in] = ; + aMap[DBTYPE_I8] = DataType::BIGINT; + aMap[DBTYPE_UI8] = DataType::BIGINT; + aMap[DBTYPE_GUID] = DataType::OTHER; + aMap[DBTYPE_VECTOR] = DataType::OTHER; + aMap[DBTYPE_FILETIME] = DataType::OTHER; + aMap[DBTYPE_RESERVED] = DataType::OTHER; + + // aMap[The] = ; + aMap[DBTYPE_BYTES] = DataType::VARBINARY; + aMap[DBTYPE_STR] = DataType::LONGVARCHAR; + aMap[DBTYPE_WSTR] = DataType::LONGVARCHAR; + aMap[DBTYPE_NUMERIC] = DataType::NUMERIC; + aMap[DBTYPE_UDT] = DataType::OTHER; + aMap[DBTYPE_DBDATE] = DataType::DATE; + aMap[DBTYPE_DBTIME] = DataType::TIME; + aMap[DBTYPE_DBTIMESTAMP] = DataType::TIMESTAMP; + aMap[DBTYPE_HCHAPTER] = DataType::OTHER; + aMap[DBTYPE_PROPVARIANT] = DataType::OTHER; + aMap[DBTYPE_VARNUMERIC] = DataType::NUMERIC; + + m_aValueRange[10] = aMap; + + ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); + pMetaData->setProcedureColumnsMap(); + m_xMetaData = pMetaData; +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::setPrimaryKeysMap() +{ + + sal_Int32 i=1; + for(;i<5;i++) + m_aColMapping.push_back(i); + m_aColMapping.push_back(7); + m_aColMapping.push_back(8); + + ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); + pMetaData->setProcedureColumnsMap(); + m_xMetaData = pMetaData; +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::setIndexInfoMap() +{ + + sal_Int32 i=1; + for(;i<4;i++) + m_aColMapping.push_back(i); + m_aColMapping.push_back(8); + m_aColMapping.push_back(4); + m_aColMapping.push_back(6); + m_aColMapping.push_back(10); + m_aColMapping.push_back(17); + m_aColMapping.push_back(18); + m_aColMapping.push_back(21); + m_aColMapping.push_back(22); + m_aColMapping.push_back(23); + m_aColMapping.push_back(24); + + ::std::map<sal_Int32,sal_Int32> aMap; + aMap[DBPROPVAL_IT_HASH] = IndexType::HASHED; + aMap[DBPROPVAL_IT_CONTENT] = IndexType::OTHER; + aMap[DBPROPVAL_IT_OTHER] = IndexType::OTHER; + aMap[DBPROPVAL_IT_BTREE] = IndexType::OTHER; + + m_aValueRange[10] = aMap; + + ::std::map<sal_Int32,sal_Int32> aMap2; + aMap[0] = 1; + aMap[1] = 0; + m_aValueRange[8] = aMap2; + + ::std::map< sal_Int32,::rtl::OUString> aMap3; + aMap3[0] = ::rtl::OUString(); + aMap3[DB_COLLATION_ASC] = ::rtl::OUString::createFromAscii("A"); + aMap3[DB_COLLATION_DESC] = ::rtl::OUString::createFromAscii("D"); + + m_aIntValueRange[21] = aMap3; + + ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); + pMetaData->setIndexInfoMap(); + m_xMetaData = pMetaData; +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::setTablePrivilegesMap() +{ + + sal_Int32 i=3; + for(;i<6;i++) + m_aColMapping.push_back(i); + m_aColMapping.push_back(1); + m_aColMapping.push_back(2); + m_aColMapping.push_back(6); + m_aColMapping.push_back(7); + + ::std::map< sal_Int32,::rtl::OUString> aMap; + aMap[0] = ::rtl::OUString::createFromAscii("YES"); + aMap[1] = ::rtl::OUString::createFromAscii("NO"); + m_aIntValueRange[7] = aMap; + + + ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); + pMetaData->setTablePrivilegesMap(); + m_xMetaData = pMetaData; +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::setCrossReferenceMap() +{ + + sal_Int32 i=1; + for(;i<5;i++) + m_aColMapping.push_back(i); + for(i=7;i<11;i++) + m_aColMapping.push_back(i); + + m_aColMapping.push_back(13); + m_aColMapping.push_back(14); + m_aColMapping.push_back(15); + m_aColMapping.push_back(17); + m_aColMapping.push_back(16); + m_aColMapping.push_back(18); + + ::std::map< ::rtl::OUString,sal_Int32> aMap; + aMap[ ::rtl::OUString::createFromAscii("CASCADE")] = KeyRule::CASCADE; + aMap[ ::rtl::OUString::createFromAscii("RESTRICT")] = KeyRule::RESTRICT; + aMap[ ::rtl::OUString::createFromAscii("SET NULL")] = KeyRule::SET_NULL; + aMap[ ::rtl::OUString::createFromAscii("SET DEFAULT")] = KeyRule::SET_DEFAULT; + aMap[ ::rtl::OUString::createFromAscii("NO ACTION")] = KeyRule::NO_ACTION; + + m_aStrValueRange[14] = aMap; + m_aStrValueRange[15] = aMap; + + ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); + pMetaData->setCrossReferenceMap(); + m_xMetaData = pMetaData; +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSet::setTypeInfoMap() +{ + sal_Int32 i=1; + for(;i<19;i++) + m_aColMapping.push_back(i); + + ::std::map< ::rtl::OUString,sal_Int32> aMap1; + aMap1[ ::rtl::OUString()] = 10; + + m_aStrValueRange[18] = aMap1; + + ::std::map<sal_Int32,sal_Int32> aMap; + aMap[DBTYPE_EMPTY] = DataType::SQLNULL; + aMap[DBTYPE_NULL] = DataType::SQLNULL; + aMap[DBTYPE_I2] = DataType::SMALLINT; + aMap[DBTYPE_I4] = DataType::INTEGER; + aMap[DBTYPE_R4] = DataType::FLOAT; + aMap[DBTYPE_R8] = DataType::DOUBLE; + aMap[DBTYPE_CY] = DataType::BIGINT; + aMap[DBTYPE_DATE] = DataType::DATE; + aMap[DBTYPE_BSTR] = DataType::VARCHAR; + aMap[DBTYPE_IDISPATCH] = DataType::OBJECT; + aMap[DBTYPE_ERROR] = DataType::OTHER; + aMap[DBTYPE_BOOL] = DataType::BIT; + aMap[DBTYPE_VARIANT] = DataType::STRUCT; + aMap[DBTYPE_IUNKNOWN] = DataType::OTHER; + aMap[DBTYPE_DECIMAL] = DataType::DECIMAL; + aMap[DBTYPE_UI1] = DataType::TINYINT; + aMap[DBTYPE_ARRAY] = DataType::ARRAY; + aMap[DBTYPE_BYREF] = DataType::REF; + aMap[DBTYPE_I1] = DataType::CHAR; + aMap[DBTYPE_UI2] = DataType::SMALLINT; + aMap[DBTYPE_UI4] = DataType::INTEGER; + + // aMap[The] = ; + // aMap[in] = ; + aMap[DBTYPE_I8] = DataType::BIGINT; + aMap[DBTYPE_UI8] = DataType::BIGINT; + aMap[DBTYPE_GUID] = DataType::OTHER; + aMap[DBTYPE_VECTOR] = DataType::OTHER; + aMap[DBTYPE_FILETIME] = DataType::OTHER; + aMap[DBTYPE_RESERVED] = DataType::OTHER; + + // aMap[The] = ; + aMap[DBTYPE_BYTES] = DataType::VARBINARY; + aMap[DBTYPE_STR] = DataType::LONGVARCHAR; + aMap[DBTYPE_WSTR] = DataType::LONGVARCHAR; + aMap[DBTYPE_NUMERIC] = DataType::NUMERIC; + aMap[DBTYPE_UDT] = DataType::OTHER; + aMap[DBTYPE_DBDATE] = DataType::DATE; + aMap[DBTYPE_DBTIME] = DataType::TIME; + aMap[DBTYPE_DBTIMESTAMP] = DataType::TIMESTAMP; + aMap[DBTYPE_HCHAPTER] = DataType::OTHER; + aMap[DBTYPE_PROPVARIANT] = DataType::OTHER; + aMap[DBTYPE_VARNUMERIC] = DataType::NUMERIC; + + m_aValueRange[2] = aMap; + + ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); + pMetaData->setTypeInfoMap(); + m_xMetaData = pMetaData; +} + diff --git a/connectivity/source/drivers/ado/ADatabaseMetaDataResultSetMetaData.cxx b/connectivity/source/drivers/ado/ADatabaseMetaDataResultSetMetaData.cxx new file mode 100644 index 000000000000..ede0a0d5be02 --- /dev/null +++ b/connectivity/source/drivers/ado/ADatabaseMetaDataResultSetMetaData.cxx @@ -0,0 +1,515 @@ +/************************************************************************* + * + * $RCSfile: ADatabaseMetaDataResultSetMetaData.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADO_ADATABASEMETADATARESULTSETMETADATA_HXX_ +#include "ado/ADatabaseMetaDataResultSetMetaData.hxx" +#endif + +#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_PROCEDURERESULT_HPP_ +#include <com/sun/star/sdbc/ProcedureResult.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ +#include <com/sun/star/sdbc/ColumnValue.hpp> +#endif + +#ifndef _CONNECTIVITY_ADO_AWRAPADO_HXX_ +#include "ado/Awrapado.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif + +using namespace connectivity; +using namespace connectivity::ado; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::sdbc; + +// ------------------------------------------------------------------------- +ODatabaseMetaDataResultSetMetaData::~ODatabaseMetaDataResultSetMetaData() +{ + if(m_pRecordSet) + m_pRecordSet->Release(); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + return (*m_mColumnsIter).second.getColumnDisplaySize(); + + if(!m_pRecordSet) + return 0; + ADO_GETFIELD(m_vMapping[column]); + if(aField.IsValid()) + return aField.GetActualSize(); + return 0; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnType( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + return (*m_mColumnsIter).second.getColumnType(); + if(!m_pRecordSet) + return 0; + ADO_GETFIELD(m_vMapping[column]); + return MapADOType2Jdbc(aField.GetADOType()); +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnCount( ) throw(SQLException, RuntimeException) +{ + if(!m_pRecordSet) + return 0; + if(m_nColCount != -1) + return m_nColCount; + + if(m_vMapping.size()) + return m_mColumns.size(); + + ADOFields* pFields = NULL; + m_pRecordSet->get_Fields(&pFields); + WpOLEAppendCollection<ADOFields, ADOField, WpADOField> aFields(pFields); + m_nColCount = aFields.GetItemCount(); + return m_nColCount; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isCaseSensitive( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + return (*m_mColumnsIter).second.isCaseSensitive(); + return sal_True; +} +// ------------------------------------------------------------------------- + +::rtl::OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getSchemaName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + return (*m_mColumnsIter).second.getSchemaName(); + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- + +::rtl::OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + return (*m_mColumnsIter).second.getColumnName(); + if(!m_pRecordSet) + return ::rtl::OUString(); + ADO_GETFIELD(m_vMapping[column]); + if(aField.IsValid()) + return aField.GetName(); + + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getTableName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + return (*m_mColumnsIter).second.getTableName(); + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getCatalogName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + return (*m_mColumnsIter).second.getCatalogName(); + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnTypeName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + return (*m_mColumnsIter).second.getColumnTypeName(); + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnLabel( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + return (*m_mColumnsIter).second.getColumnLabel(); + return getColumnName(column); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnServiceName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + return (*m_mColumnsIter).second.getColumnServiceName(); + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isCurrency( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + return (*m_mColumnsIter).second.isCurrency(); + if(!m_pRecordSet) + return 0; + ADO_GETFIELD(m_vMapping[column]); + if(aField.IsValid()) + { + return (aField.GetAttributes() & adFldFixed) == adFldFixed; + } + return sal_False; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isAutoIncrement( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + return (*m_mColumnsIter).second.isAutoIncrement(); + return sal_False; +} +// ------------------------------------------------------------------------- + + +sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isSigned( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + return (*m_mColumnsIter).second.isSigned(); + if(!m_pRecordSet) + return 0; + ADO_GETFIELD(m_vMapping[column]); + if(aField.IsValid()) + { + return (aField.GetAttributes() & adFldNegativeScale) == adFldNegativeScale; + } + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getPrecision( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + return (*m_mColumnsIter).second.getPrecision(); + if(!m_pRecordSet) + return 0; + ADO_GETFIELD(m_vMapping[column]); + if(aField.IsValid()) + return aField.GetPrecision(); + return 0; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getScale( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + return (*m_mColumnsIter).second.getScale(); + + if(!m_pRecordSet) + return 0; + + ADO_GETFIELD(m_vMapping[column]); + if(aField.IsValid()) + return aField.GetNumericScale(); + return 0; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::isNullable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + return (*m_mColumnsIter).second.isNullable(); + + if(!m_pRecordSet) + return 0; + + ADO_GETFIELD(m_vMapping[column]); + if(aField.IsValid()) + { + return (aField.GetAttributes() & adFldIsNullable) == adFldIsNullable; + } + return sal_False; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isSearchable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + return (*m_mColumnsIter).second.isSearchable(); + return sal_True; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isReadOnly( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + return (*m_mColumnsIter).second.isReadOnly(); + + if(!m_pRecordSet) + return 0; + + ADO_GETFIELD(m_vMapping[column]); + if(aField.IsValid()) + { + // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly; + } + return sal_False; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + return (*m_mColumnsIter).second.isDefinitelyWritable(); + + if(!m_pRecordSet) + return 0; + + ADO_GETFIELD(m_vMapping[column]); + if(aField.IsValid()) + { + return (aField.GetAttributes() & adFldUpdatable) == adFldUpdatable; + } + return sal_False; +; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isWritable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + return (*m_mColumnsIter).second.isWritable(); + return isDefinitelyWritable(column); +} +// ------------------------------------------------------------------------- +sal_Int32 ODatabaseMetaDataResultSetMetaData::MapADOType2Jdbc(DataTypeEnum eType) +{ + switch (eType) + { + case adUnsignedSmallInt: + case adSmallInt: return DataType::SMALLINT; break; + case adUnsignedInt: + case adInteger: return DataType::INTEGER; break; + case adUnsignedBigInt: + case adBigInt: return DataType::BIGINT; break; + case adSingle: return DataType::FLOAT; break; + case adDouble: return DataType::DOUBLE; break; + case adCurrency: return DataType::DOUBLE; break; + case adVarNumeric: + case adNumeric: return DataType::NUMERIC; break; + case adDecimal: return DataType::DECIMAL; break; + case adDate: + case adDBDate: return DataType::DATE; break; + case adDBTime: return DataType::TIME; break; + case adDBTimeStamp: return DataType::TIMESTAMP; break; + case adBoolean: return DataType::BIT; break; + case adBinary: + case adGUID: return DataType::BINARY; break; + case adBSTR: + case adVarWChar: + case adVarChar: return DataType::VARCHAR; break; + case adLongVarWChar: + case adLongVarChar: return DataType::LONGVARCHAR; break; + case adVarBinary: return DataType::VARBINARY; break; + case adLongVarBinary: return DataType::LONGVARBINARY; break; + case adWChar: + case adChar: return DataType::CHAR; break; + case adUnsignedTinyInt: + case adTinyInt: return DataType::TINYINT; break; + default: + ; + } +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSetMetaData::setColumnPrivilegesMap() +{ + m_mColumns[8] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("IS_GRANTABLE"), + ColumnValue::NULLABLE, + 3,3,0, + DataType::VARCHAR); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSetMetaData::setColumnsMap() +{ + m_mColumns[6] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("TYPE_NAME"), + ColumnValue::NO_NULLS, + 0,0,0, + DataType::VARCHAR); + m_mColumns[11] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("NULLABLE"), + ColumnValue::NO_NULLS, + 1,1,0, + DataType::INTEGER); + m_mColumns[12] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("REMARKS"), + ColumnValue::NULLABLE, + 0,0,0, + DataType::VARCHAR); + m_mColumns[13] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("COLUMN_DEF"), + ColumnValue::NULLABLE, + 0,0,0, + DataType::VARCHAR); + m_mColumns[14] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("SQL_DATA_TYPE"), + ColumnValue::NO_NULLS, + 1,1,0, + DataType::INTEGER); + m_mColumns[15] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("SQL_DATETIME_SUB"), + ColumnValue::NO_NULLS, + 1,1,0, + DataType::INTEGER); + m_mColumns[16] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("CHAR_OCTET_LENGTH"), + ColumnValue::NO_NULLS, + 1,1,0, + DataType::INTEGER); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSetMetaData::setTablesMap() +{ + m_mColumns[5] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("REMARKS"), + ColumnValue::NULLABLE, + 0,0,0, + DataType::VARCHAR); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSetMetaData::setProcedureColumnsMap() +{ + m_mColumns[12] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("NULLABLE"), + ColumnValue::NO_NULLS, + 1,1,0, + DataType::INTEGER); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSetMetaData::setPrimaryKeysMap() +{ + m_mColumns[5] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("KEY_SEQ"), + ColumnValue::NO_NULLS, + 1,1,0, + DataType::INTEGER); + m_mColumns[6] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("PK_NAME"), + ColumnValue::NULLABLE, + 0,0,0, + DataType::VARCHAR); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSetMetaData::setIndexInfoMap() +{ + m_mColumns[4] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("NON_UNIQUE"), + ColumnValue::NO_NULLS, + 1,1,0, + DataType::BIT); + m_mColumns[5] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("INDEX_QUALIFIER"), + ColumnValue::NULLABLE, + 0,0,0, + DataType::VARCHAR); + m_mColumns[10] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("ASC_OR_DESC"), + ColumnValue::NULLABLE, + 0,0,0, + DataType::VARCHAR); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSetMetaData::setTablePrivilegesMap() +{ + m_mColumns[6] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("PRIVILEGE"), + ColumnValue::NULLABLE, + 0,0,0, + DataType::VARCHAR); + m_mColumns[7] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("IS_GRANTABLE"), + ColumnValue::NULLABLE, + 0,0,0, + DataType::VARCHAR); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSetMetaData::setCrossReferenceMap() +{ + m_mColumns[9] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("KEY_SEQ"), + ColumnValue::NO_NULLS, + 1,1,0, + DataType::INTEGER); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSetMetaData::setTypeInfoMap() +{ + m_mColumns[3] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("PRECISION"), + ColumnValue::NO_NULLS, + 1,1,0, + DataType::INTEGER); + m_mColumns[7] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("NULLABLE"), + ColumnValue::NO_NULLS, + 1,1,0, + DataType::INTEGER); + m_mColumns[12] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("AUTO_INCREMENT"), + ColumnValue::NO_NULLS, + 1,1,0, + DataType::BIT); + m_mColumns[16] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("SQL_DATA_TYPE"), + ColumnValue::NO_NULLS, + 1,1,0, + DataType::INTEGER); + m_mColumns[17] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("SQL_DATETIME_SUB"), + ColumnValue::NO_NULLS, + 1,1,0, + DataType::INTEGER); + m_mColumns[18] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("NUM_PREC_RADIX"), + ColumnValue::NO_NULLS, + 1,1,0, + DataType::INTEGER); +} +// ------------------------------------------------------------------------- +void ODatabaseMetaDataResultSetMetaData::setProceduresMap() +{ + m_mColumns[7] = OColumn(::rtl::OUString(),::rtl::OUString::createFromAscii("REMARKS"), + ColumnValue::NULLABLE, + 0,0,0, + DataType::VARCHAR); +} +// ------------------------------------------------------------------------- + diff --git a/connectivity/source/drivers/ado/ADriver.cxx b/connectivity/source/drivers/ado/ADriver.cxx new file mode 100644 index 000000000000..f0b8ce81a1bf --- /dev/null +++ b/connectivity/source/drivers/ado/ADriver.cxx @@ -0,0 +1,265 @@ +/************************************************************************* + * + * $RCSfile: ADriver.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADO_ADRIVER_HXX_ +#include "ado/ADriver.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_ACONNECTION_HXX_ +#include "ado/AConnection.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_AWRAPADOX_HXX_ +#include "ado/Awrapadox.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_AWRAPADO_HXX_ +#include "ado/Awrapado.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_ADOIMP_HXX_ +#include "ado/adoimp.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_CATALOG_HXX_ +#include "ado/ACatalog.hxx" +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif + + +using namespace connectivity::ado; +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::lang; + +// -------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------- +ODriver::ODriver() : ODriver_BASE(m_aMutex) +{ + CoInitialize(NULL); +} +// ------------------------------------------------------------------------- +ODriver::~ODriver() +{ + CoUninitialize(); +} +//------------------------------------------------------------------------------ +void ODriver::disposing() +{ + ::osl::MutexGuard aGuard(m_aMutex); + + + for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i) + { + Reference< XComponent > xComp(i->get(), UNO_QUERY); + if (xComp.is()) + xComp->dispose(); + } + m_xConnections.clear(); + + ODriver_BASE::disposing(); +} +// static ServiceInfo +//------------------------------------------------------------------------------ +rtl::OUString ODriver::getImplementationName_Static( ) throw(RuntimeException) +{ + return rtl::OUString::createFromAscii("com.sun.star.sdbc.ADriver"); +} +//------------------------------------------------------------------------------ +Sequence< ::rtl::OUString > ODriver::getSupportedServiceNames_Static( ) throw (RuntimeException) +{ + Sequence< ::rtl::OUString > aSNS( 2 ); + aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver"); + aSNS[1] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Driver"); + return aSNS; +} +//------------------------------------------------------------------ +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL connectivity::ado::ODriver_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception ) +{ + return *(new ODriver()); +} + +// -------------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODriver::getImplementationName( ) throw(RuntimeException) +{ + return getImplementationName_Static(); +} + +// -------------------------------------------------------------------------------- +sal_Bool SAL_CALL ODriver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException) +{ + Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); + const ::rtl::OUString* pSupported = aSupported.getConstArray(); + for (sal_Int32 i=0; i<aSupported.getLength(); ++i, ++pSupported) + if (pSupported->equals(_rServiceName)) + return sal_True; + + return sal_False; +} + +// -------------------------------------------------------------------------------- +Sequence< ::rtl::OUString > SAL_CALL ODriver::getSupportedServiceNames( ) throw(RuntimeException) +{ + return getSupportedServiceNames_Static(); +} + +// -------------------------------------------------------------------------------- +Reference< XConnection > SAL_CALL ODriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException) +{ + OConnection* pCon = new OConnection(url,info,this); + pCon->construct(url,info); + Reference< XConnection > xCon = pCon; + m_xConnections.push_back(WeakReferenceHelper(*pCon)); + + return xCon; +} +// -------------------------------------------------------------------------------- +sal_Bool SAL_CALL ODriver::acceptsURL( const ::rtl::OUString& url ) + throw(SQLException, RuntimeException) +{ + if(!url.compareTo(::rtl::OUString::createFromAscii("sdbc:ado:"),9)) + { + return sal_True; + } + return sal_False; +} +// -------------------------------------------------------------------------------- +Sequence< DriverPropertyInfo > SAL_CALL ODriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException) +{ + return Sequence< DriverPropertyInfo >(); +} +// -------------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODriver::getMajorVersion( ) throw(RuntimeException) +{ + return 1; +} +// -------------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODriver::getMinorVersion( ) throw(RuntimeException) +{ + return 0; +} +// -------------------------------------------------------------------------------- +// XDataDefinitionSupplier +Reference< XTablesSupplier > SAL_CALL ODriver::getDataDefinitionByConnection( const Reference< ::com::sun::star::sdbc::XConnection >& connection ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODriver_BASE::rBHelper.bDisposed) + throw DisposedException(); + + OConnection* pConnection = NULL; + for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i) + { + if ((OConnection*) Reference< XConnection >::query(i->get().get()).get() == (OConnection*)connection.get()) + { + pConnection = (OConnection*)connection.get(); + break; + } + } + Reference< XTablesSupplier > xTab = NULL; + if(pConnection) + { + WpADOCatalog aCatalog; + aCatalog.Create(); + if(aCatalog.IsValid()) + { + aCatalog.putref_ActiveConnection(*pConnection->getConnection()); + xTab = new OCatalog(aCatalog,pConnection); + pConnection->setCatalog(xTab); + } + } + return xTab; +} +// -------------------------------------------------------------------------------- +Reference< XTablesSupplier > SAL_CALL ODriver::getDataDefinitionByURL( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) +{ + return getDataDefinitionByConnection(connect(url,info)); +} + +//#include <tools/prewin.h> +//namespace test__rr__ +//{ +// +//#import "c:\Program Files\Common Files\system\ado\msadox.dll" +// +//} +//#include <tools/postwin.h> + +void WpADOCatalog::Create() +{ + IClassFactory2* pIUnknown = NULL; + IUnknown *pOuter = NULL; + HRESULT hr = -1; + _ADOCatalog* pCommand; + hr = CoCreateInstance(ADOS::CLSID_ADOCATALOG_25, + NULL, + CLSCTX_INPROC_SERVER, + ADOS::IID_ADOCATALOG_25, + (void**)&pCommand ); + + + if( !FAILED( hr ) ) + { + pInterface = pCommand; + pInterface->AddRef(); + } +} + + diff --git a/connectivity/source/drivers/ado/AGroup.cxx b/connectivity/source/drivers/ado/AGroup.cxx new file mode 100644 index 000000000000..971922addf62 --- /dev/null +++ b/connectivity/source/drivers/ado/AGroup.cxx @@ -0,0 +1,342 @@ +/************************************************************************* + * + * $RCSfile: AGroup.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADO_GROUP_HXX_ +#include "ado/AGroup.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_USERS_HXX_ +#include "ado/AUsers.hxx" +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif +#ifdef DELETE +#undef DELETE +#endif +#ifndef _COM_SUN_STAR_SDBCX_PRIVILEGE_HPP_ +#include <com/sun/star/sdbcx/Privilege.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBCX_PRIVILEGEOBJECT_HPP_ +#include <com/sun/star/sdbcx/PrivilegeObject.hpp> +#endif + +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _CONNECTIVITY_ADO_BCONNECTION_HXX_ +#include "ado/AConnection.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +using namespace connectivity::ado; +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; + +// ------------------------------------------------------------------------- +void WpADOGroup::Create() +{ + IClassFactory2* pIUnknown = NULL; + IUnknown *pOuter = NULL; + HRESULT hr = -1; + ADOGroup* pCommand; + hr = CoCreateInstance(ADOS::CLSID_ADOGROUP_25, + NULL, + CLSCTX_INPROC_SERVER, + ADOS::IID_ADOGROUP_25, + (void**)&pCommand ); + + + if( !FAILED( hr ) ) + { + pInterface = pCommand; + pInterface->AddRef(); + } +} +// ------------------------------------------------------------------------- +OAdoGroup::OAdoGroup(sal_Bool _bCase, ADOGroup* _pGroup) : OGroup_ADO(_bCase) +{ + construct(); + if(_pGroup) + m_aGroup = WpADOGroup(_pGroup); + else + m_aGroup.Create(); + + refreshUsers(); +} +// ------------------------------------------------------------------------- +OAdoGroup::OAdoGroup(sal_Bool _bCase, const ::rtl::OUString& _Name) : OGroup_ADO(_Name,_bCase) +{ + construct(); + m_aGroup.Create(); + m_aGroup.put_Name(_Name); + refreshUsers(); +} +// ------------------------------------------------------------------------- +void OAdoGroup::refreshUsers() +{ + ::std::vector< ::rtl::OUString> aVector; + + ADOUsers* pUsers = m_aGroup.get_Users(); + if(pUsers) + { + pUsers->Refresh(); + + sal_Int32 nCount = 0; + pUsers->get_Count(&nCount); + for(sal_Int32 i=0;i< nCount;++i) + { + ADOUser* pUser = NULL; + pUsers->get_Item(OLEVariant(i),&pUser); + if(pUser) + { + WpADOUser aUser(pUser); + aVector.push_back(aUser.get_Name()); + } + } + } + + if(m_pUsers) + delete m_pUsers; + m_pUsers = new OUsers(*this,m_aMutex,aVector,pUsers,isCaseSensitive()); +} +// ------------------------------------------------------------------------- +Any SAL_CALL OAdoGroup::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = ::cppu::queryInterface(rType,static_cast< ::com::sun::star::lang::XUnoTunnel*> (this)); + if(aRet.hasValue()) + return aRet; + return OGroup_ADO::queryInterface(rType); +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OAdoGroup::getTypes( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > *)0 )); + + return ::utl::concatSequences(aTypes.getTypes(),OGroup_ADO::getTypes()); +} +//-------------------------------------------------------------------------- +Sequence< sal_Int8 > OAdoGroup::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 OAdoGroup::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException) +{ + if (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) + return (sal_Int64)this; + + return 0; +} + +// ------------------------------------------------------------------------- +void OAdoGroup::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)throw (Exception) +{ + if(m_aGroup.IsValid()) + { + + switch(nHandle) + { + case PROPERTY_ID_NAME: + { + ::rtl::OUString aVal; + rValue >>= aVal; + m_aGroup.put_Name(aVal); + } + break; + } + } +} +// ------------------------------------------------------------------------- +void OAdoGroup::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const +{ + if(m_aGroup.IsValid()) + { + switch(nHandle) + { + case PROPERTY_ID_NAME: + rValue <<= m_aGroup.get_Name(); + break; + } + } +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OAdoGroup::getPrivileges( const ::rtl::OUString& objName, sal_Int32 objType ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) +{ + return MapRight(m_aGroup.GetPermissions(objName,MapObjectType(objType))); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OAdoGroup::getGrantablePrivileges( const ::rtl::OUString& objName, sal_Int32 objType ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) +{ + RightsEnum eNum = m_aGroup.GetPermissions(objName,MapObjectType(objType)); + if(eNum & adRightWithGrant) + return MapRight(eNum); + return 0; +} +// ------------------------------------------------------------------------- +void SAL_CALL OAdoGroup::grantPrivileges( const ::rtl::OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) +{ + m_aGroup.SetPermissions(objName,MapObjectType(objType),adAccessGrant,Map2Right(objPrivileges)); +} +// ------------------------------------------------------------------------- +void SAL_CALL OAdoGroup::revokePrivileges( const ::rtl::OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) +{ + m_aGroup.SetPermissions(objName,MapObjectType(objType),adAccessDeny,Map2Right(objPrivileges)); +} +// ------------------------------------------------------------------------- +ObjectTypeEnum OAdoGroup::MapObjectType(sal_Int32 _ObjType) +{ + ObjectTypeEnum eNumType= adPermObjTable; + switch(_ObjType) + { + case PrivilegeObject::TABLE: + break; + case PrivilegeObject::VIEW: + eNumType = adPermObjView; + break; + case PrivilegeObject::COLUMN: + eNumType = adPermObjColumn; + break; + } + return eNumType; +} +// ------------------------------------------------------------------------- +sal_Int32 OAdoGroup::MapRight(RightsEnum _eNum) +{ + sal_Int32 nRight = 0; + if(_eNum & adRightRead) + nRight |= Privilege::SELECT; + if(_eNum & adRightInsert) + nRight |= Privilege::INSERT; + if(_eNum & adRightUpdate) + nRight |= Privilege::UPDATE; + if(_eNum & adRightDelete) + nRight |= Privilege::DELETE; + if(_eNum & adRightReadDesign) + nRight |= Privilege::READ; + if(_eNum & adRightCreate) + nRight |= Privilege::CREATE; + if(_eNum & adRightWriteDesign) + nRight |= Privilege::ALTER; + if(_eNum & adRightReference) + nRight |= Privilege::REFERENCE; + if(_eNum & adRightDrop) + nRight |= Privilege::DROP; + + return nRight; +} +// ------------------------------------------------------------------------- +RightsEnum OAdoGroup::Map2Right(sal_Int32 _eNum) +{ + sal_Int32 nRight = adRightNone; + if(_eNum & Privilege::SELECT) + nRight |= adRightRead; + + if(_eNum & Privilege::INSERT) + nRight |= adRightInsert; + + if(_eNum & Privilege::UPDATE) + nRight |= adRightUpdate; + + if(_eNum & Privilege::DELETE) + nRight |= adRightDelete; + + if(_eNum & Privilege::READ) + nRight |= adRightReadDesign; + + if(_eNum & Privilege::CREATE) + nRight |= adRightCreate; + + if(_eNum & Privilege::ALTER) + nRight |= adRightWriteDesign; + + if(_eNum & Privilege::REFERENCE) + nRight |= adRightReference; + + if(_eNum & Privilege::DROP) + nRight |= adRightDrop; + + return (RightsEnum)nRight; +} + + diff --git a/connectivity/source/drivers/ado/AGroups.cxx b/connectivity/source/drivers/ado/AGroups.cxx new file mode 100644 index 000000000000..d3e75885d029 --- /dev/null +++ b/connectivity/source/drivers/ado/AGroups.cxx @@ -0,0 +1,145 @@ +/************************************************************************* + * + * $RCSfile: AGroups.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADO_GROUPS_HXX_ +#include "ado/AGroups.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_GROUP_HXX_ +#include "ado/AGroup.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_TABLE_HXX_ +#include "ado/ATable.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _CONNECTIVITY_SDBCX_IREFRESHABLE_HXX_ +#include "connectivity/sdbcx/IRefreshable.hxx" +#endif + +using namespace connectivity::ado; +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::container; + +typedef connectivity::sdbcx::OCollection OCollection_TYPE; +// ------------------------------------------------------------------------- +Reference< XNamed > OGroups::createObject(const ::rtl::OUString& _rName) +{ + Reference< XNamed > xRet = NULL; + OAdoGroup* pRet = new OAdoGroup(isCaseSensitive(),_rName); + xRet = pRet; + return xRet; +} +// ------------------------------------------------------------------------- +void OGroups::impl_refresh() throw(RuntimeException) +{ + m_pCollection->Refresh(); +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > OGroups::createEmptyObject() +{ + OAdoGroup* pNew = new OAdoGroup(isCaseSensitive()); + return pNew; +} +// ------------------------------------------------------------------------- +// XAppend +void SAL_CALL OGroups::appendByDescriptor( const Reference< XPropertySet >& descriptor ) throw(SQLException, ElementExistException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(descriptor,UNO_QUERY); + if(xTunnel.is()) + { + OAdoGroup* pGroup = (OAdoGroup*)xTunnel->getSomething(OAdoGroup::getUnoTunnelImplementationId()); + m_pCollection->Append(OLEVariant(pGroup->getImpl())); + } + + OCollection_TYPE::appendByDescriptor(descriptor); +} +// ------------------------------------------------------------------------- +// XDrop +void SAL_CALL OGroups::dropByName( const ::rtl::OUString& elementName ) throw(SQLException, NoSuchElementException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + m_pCollection->Delete(OLEVariant(elementName)); + + OCollection_TYPE::dropByName(elementName); +} +// ------------------------------------------------------------------------- +void SAL_CALL OGroups::dropByIndex( sal_Int32 index ) throw(SQLException, IndexOutOfBoundsException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + if (index < 0 || index >= getCount()) + throw IndexOutOfBoundsException(); + + m_pCollection->Delete(OLEVariant(index)); + + OCollection_TYPE::dropByIndex(index); +} + + diff --git a/connectivity/source/drivers/ado/AIndex.cxx b/connectivity/source/drivers/ado/AIndex.cxx new file mode 100644 index 000000000000..f5c60ea843b9 --- /dev/null +++ b/connectivity/source/drivers/ado/AIndex.cxx @@ -0,0 +1,283 @@ +/************************************************************************* + * + * $RCSfile: AIndex.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADO_INDEX_HXX_ +#include "ado/AIndex.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif +#ifndef _CONNECTIVITY_ADO_COLUMNS_HXX_ +#include "ado/AColumns.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif + +using namespace connectivity::ado; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::sdbc; + +// ------------------------------------------------------------------------- +void WpADOIndex::Create() +{ + IClassFactory2* pIUnknown = NULL; + IUnknown *pOuter = NULL; + HRESULT hr = -1; + _ADOIndex* pCommand; + hr = CoCreateInstance(ADOS::CLSID_ADOINDEX_25, + NULL, + CLSCTX_INPROC_SERVER, + ADOS::IID_ADOINDEX_25, + (void**)&pCommand ); + + + if( !FAILED( hr ) ) + { + pInterface = pCommand; + pInterface->AddRef(); + } +} +// ------------------------------------------------------------------------- +OAdoIndex::OAdoIndex(sal_Bool _bCase, ADOIndex* _pIndex) : OIndex_ADO(_bCase) +{ + construct(); + if(_pIndex) + m_aIndex = WpADOIndex(_pIndex); + else + m_aIndex.Create(); + + refreshColumns(); +} +// ------------------------------------------------------------------------- +OAdoIndex::OAdoIndex( const ::rtl::OUString& _Name, + const ::rtl::OUString& _Catalog, + sal_Bool _isUnique, + sal_Bool _isPrimaryKeyIndex, + sal_Bool _isClustered, + sal_Bool _bCase + ) : OIndex_ADO(_Name, + _Catalog, + _isUnique, + _isPrimaryKeyIndex, + _isClustered,_bCase) +{ + construct(); + m_aIndex.Create(); + m_aIndex.put_Name(_Name); + m_aIndex.put_Unique(_isUnique); + m_aIndex.put_PrimaryKey(_isPrimaryKeyIndex); + m_aIndex.put_Clustered(_isClustered); + + refreshColumns(); +} +// ------------------------------------------------------------------------- + +void OAdoIndex::refreshColumns() +{ + ::std::vector< ::rtl::OUString> aVector; + + ADOColumns* pColumns = m_aIndex.get_Columns(); + if(pColumns) + { + pColumns->Refresh(); + + sal_Int32 nCount = 0; + pColumns->get_Count(&nCount); + for(sal_Int32 i=0;i< nCount;++i) + { + ADOColumn* pColumn = NULL; + pColumns->get_Item(OLEVariant(i),&pColumn); + if(pColumn) + { + WpADOColumn aColumn(pColumn); + aVector.push_back(aColumn.get_Name()); + } + } + } + if(m_pColumns) + delete m_pColumns; + m_pColumns = new OColumns(*this,m_aMutex,aVector,pColumns,isCaseSensitive()); +} + +// ------------------------------------------------------------------------- +Any SAL_CALL OAdoIndex::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = ::cppu::queryInterface(rType,static_cast< ::com::sun::star::lang::XUnoTunnel*> (this)); + if(aRet.hasValue()) + return aRet; + return OIndex_ADO::queryInterface(rType); +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OAdoIndex::getTypes( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > *)0 )); + + return ::utl::concatSequences(aTypes.getTypes(),OIndex_ADO::getTypes()); +} +//-------------------------------------------------------------------------- +Sequence< sal_Int8 > OAdoIndex::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 OAdoIndex::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException) +{ + if (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) + return (sal_Int64)this; + + return 0; +} +// ------------------------------------------------------------------------- +void SAL_CALL OAdoIndex::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)throw (Exception) +{ + if(m_aIndex.IsValid()) + { + + switch(nHandle) + { + case PROPERTY_ID_NAME: + { + ::rtl::OUString aVal; + rValue >>= aVal; + m_aIndex.put_Name(aVal); + } + break; + case PROPERTY_ID_CATALOG: + { + ::rtl::OUString aVal; + rValue >>= aVal; + m_aIndex.put_Name(aVal); + } + break; + case PROPERTY_ID_ISUNIQUE: + m_aIndex.put_Unique(getBOOL(rValue)); + break; + case PROPERTY_ID_ISPRIMARYKEYINDEX: + m_aIndex.put_PrimaryKey(getBOOL(rValue)); + break; + case PROPERTY_ID_ISCLUSTERED: + m_aIndex.put_Clustered(getBOOL(rValue)); + break; + } + } +} +// ------------------------------------------------------------------------- +void SAL_CALL OAdoIndex::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const +{ + if(m_aIndex.IsValid()) + { + switch(nHandle) + { + case PROPERTY_ID_NAME: + rValue <<= m_aIndex.get_Name(); + break; + case PROPERTY_ID_CATALOG: + // rValue <<= getResultSetType(); + break; + case PROPERTY_ID_ISUNIQUE: + { + sal_Bool _b = m_aIndex.get_Unique(); + rValue <<= Any(&_b, ::getBooleanCppuType()); + } + break; + case PROPERTY_ID_ISPRIMARYKEYINDEX: + { + sal_Bool _b = m_aIndex.get_PrimaryKey(); + rValue <<= Any(&_b, ::getBooleanCppuType()); + } + break; + case PROPERTY_ID_ISCLUSTERED: + { + sal_Bool _b = m_aIndex.get_Clustered(); + rValue <<= Any(&_b, ::getBooleanCppuType()); + } + break; + } + } +} + + + + diff --git a/connectivity/source/drivers/ado/AIndexes.cxx b/connectivity/source/drivers/ado/AIndexes.cxx new file mode 100644 index 000000000000..798f54916660 --- /dev/null +++ b/connectivity/source/drivers/ado/AIndexes.cxx @@ -0,0 +1,148 @@ +/************************************************************************* + * + * $RCSfile: AIndexes.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_ADO_INDEXES_HXX_ +#include "ado/AIndexes.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_INDEX_HXX_ +#include "ado/AIndex.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_INDEXTYPE_HPP_ +#include <com/sun/star/sdbc/IndexType.hpp> +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif + +using namespace connectivity::ado; +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::container; + +typedef connectivity::sdbcx::OCollection OCollection_TYPE; + +Reference< XNamed > OIndexes::createObject(const ::rtl::OUString& _rName) +{ + ADOIndex* pIndex = NULL; + m_pCollection->get_Item(OLEVariant(_rName),&pIndex); + + Reference< XNamed > xRet = new OAdoIndex(isCaseSensitive(),pIndex); + + return xRet; +} +// ------------------------------------------------------------------------- +void OIndexes::impl_refresh() throw(RuntimeException) +{ + m_pCollection->Refresh(); +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > OIndexes::createEmptyObject() +{ + OAdoIndex* pNew = new OAdoIndex(isCaseSensitive()); + return pNew; +} +// ------------------------------------------------------------------------- +// XAppend +void SAL_CALL OIndexes::appendByDescriptor( const Reference< XPropertySet >& descriptor ) throw(SQLException, ElementExistException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(descriptor,UNO_QUERY); + if(xTunnel.is()) + { + OAdoIndex* pIndex = (OAdoIndex*)xTunnel->getSomething(OAdoIndex:: getUnoTunnelImplementationId()); + m_pCollection->Append(OLEVariant(getString(descriptor->getPropertyValue(PROPERTY_NAME))), + OLEVariant(pIndex->getImpl())); + } + + OCollection_TYPE::appendByDescriptor(descriptor); +} +// ------------------------------------------------------------------------- +// XDrop +void SAL_CALL OIndexes::dropByName( const ::rtl::OUString& elementName ) throw(SQLException, NoSuchElementException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + m_pCollection->Delete(OLEVariant(elementName)); + + OCollection_TYPE::dropByName(elementName); +} +// ------------------------------------------------------------------------- +void SAL_CALL OIndexes::dropByIndex( sal_Int32 index ) throw(SQLException, IndexOutOfBoundsException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + if (index < 0 || index >= getCount()) + throw IndexOutOfBoundsException(); + + m_pCollection->Delete(OLEVariant(index)); + + OCollection_TYPE::dropByIndex(index); +} +// ------------------------------------------------------------------------- + + diff --git a/connectivity/source/drivers/ado/AKey.cxx b/connectivity/source/drivers/ado/AKey.cxx new file mode 100644 index 000000000000..6a7f7a437cf7 --- /dev/null +++ b/connectivity/source/drivers/ado/AKey.cxx @@ -0,0 +1,326 @@ +/************************************************************************* + * + * $RCSfile: AKey.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADO_KEY_HXX_ +#include "ado/AKey.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif +#ifndef _COM_SUN_STAR_SDBC_KEYRULE_HPP_ +#include <com/sun/star/sdbc/KeyRule.hpp> +#endif +#ifndef _CONNECTIVITY_ADO_COLUMNS_HXX_ +#include "ado/AColumns.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +using namespace connectivity::ado; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::sdbc; + +// ------------------------------------------------------------------------- +void WpADOKey::Create() +{ + IClassFactory2* pIUnknown = NULL; + IUnknown *pOuter = NULL; + HRESULT hr = -1; + _ADOKey* pCommand; + hr = CoCreateInstance(ADOS::CLSID_ADOKEY_25, + NULL, + CLSCTX_INPROC_SERVER, + ADOS::IID_ADOKEY_25, + (void**)&pCommand ); + + + if( !FAILED( hr ) ) + { + pInterface = pCommand; + pInterface->AddRef(); + } +} +// ------------------------------------------------------------------------- +OAdoKey::OAdoKey(sal_Bool _bCase, ADOKey* _pKey) : OKey_ADO(_bCase) +{ + construct(); + if(_pKey) + m_aKey = WpADOKey(_pKey); + else + m_aKey.Create(); + + refreshColumns(); +} +// ------------------------------------------------------------------------- +OAdoKey::OAdoKey( const ::rtl::OUString& _Name, + const ::rtl::OUString& _ReferencedTable, + sal_Int32 _Type, + sal_Int32 _UpdateRule, + sal_Int32 _DeleteRule, + sal_Bool _bCase + ) : OKey_ADO(_Name, + _ReferencedTable, + _Type, + _UpdateRule, + _DeleteRule,_bCase) +{ + construct(); + m_aKey.Create(); + m_aKey.put_Name(_Name); + m_aKey.put_UpdateRule(Map2Rule(_UpdateRule)); + m_aKey.put_DeleteRule(Map2Rule(_DeleteRule)); + m_aKey.put_RelatedTable(_ReferencedTable); + m_aKey.put_Type((KeyTypeEnum)_Type); + + refreshColumns(); +} +// ------------------------------------------------------------------------- +void OAdoKey::refreshColumns() +{ + ::std::vector< ::rtl::OUString> aVector; + + ADOColumns* pColumns = m_aKey.get_Columns(); + if(pColumns) + { + pColumns->Refresh(); + + sal_Int32 nCount = 0; + pColumns->get_Count(&nCount); + for(sal_Int32 i=0;i< nCount;++i) + { + ADOColumn* pColumn = NULL; + pColumns->get_Item(OLEVariant(i),&pColumn); + if(pColumn) + { + WpADOColumn aColumn(pColumn); + aVector.push_back(aColumn.get_Name()); + } + } + } + + m_pColumns = new OColumns(*this,m_aMutex,aVector,pColumns,isCaseSensitive()); +} +// ------------------------------------------------------------------------- +Any SAL_CALL OAdoKey::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = ::cppu::queryInterface(rType,static_cast< ::com::sun::star::lang::XUnoTunnel*> (this)); + if(aRet.hasValue()) + return aRet; + return OKey_ADO::queryInterface(rType); +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OAdoKey::getTypes( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > *)0 )); + + return ::utl::concatSequences(aTypes.getTypes(),OKey_ADO::getTypes()); +} +//-------------------------------------------------------------------------- +Sequence< sal_Int8 > OAdoKey::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 OAdoKey::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException) +{ + if (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) + return (sal_Int64)this; + + return 0; +} +// ------------------------------------------------------------------------- +void OAdoKey::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)throw (Exception) +{ + if(m_aKey.IsValid()) + { + + switch(nHandle) + { + case PROPERTY_ID_NAME: + { + ::rtl::OUString aVal; + rValue >>= aVal; + m_aKey.put_Name(aVal); + } + break; + case PROPERTY_ID_TYPE: + { + sal_Int32 nVal=0; + rValue >>= nVal; + m_aKey.put_Type((KeyTypeEnum)nVal); + } + break; + case PROPERTY_ID_REFERENCEDTABLE: + { + ::rtl::OUString aVal; + rValue >>= aVal; + m_aKey.put_RelatedTable(aVal); + } + break; + case PROPERTY_ID_UPDATERULE: + { + sal_Int32 nVal=0; + rValue >>= nVal; + m_aKey.put_UpdateRule(Map2Rule(nVal)); + } + break; + case PROPERTY_ID_DELETERULE: + { + sal_Int32 nVal=0; + rValue >>= nVal; + m_aKey.put_DeleteRule(Map2Rule(nVal)); + } + break; + } + } +} +// ------------------------------------------------------------------------- +void OAdoKey::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const +{ + if(m_aKey.IsValid()) + { + switch(nHandle) + { + case PROPERTY_ID_NAME: + rValue <<= m_aKey.get_Name(); + break; + case PROPERTY_ID_TYPE: + rValue <<= (sal_Int32)m_aKey.get_Type(); + break; + case PROPERTY_ID_REFERENCEDTABLE: + rValue <<= m_aKey.get_RelatedTable(); + break; + case PROPERTY_ID_UPDATERULE: + rValue <<= MapRule(m_aKey.get_UpdateRule()); + break; + case PROPERTY_ID_DELETERULE: + rValue <<= MapRule(m_aKey.get_DeleteRule()); + break; + } + } +} +// ------------------------------------------------------------------------- +sal_Int32 OAdoKey::MapRule(const RuleEnum& _eNum) const +{ + sal_Int32 eNum = KeyRule::NO_ACTION; + switch(_eNum) + { + case adRICascade: + eNum = KeyRule::CASCADE; + break; + case adRISetNull: + eNum = KeyRule::SET_NULL; + break; + case adRINone: + eNum = KeyRule::NO_ACTION; + break; + case adRISetDefault: + eNum = KeyRule::SET_DEFAULT; + break; + } + return eNum; +} +// ------------------------------------------------------------------------- +RuleEnum OAdoKey::Map2Rule(const sal_Int32& _eNum) const +{ + RuleEnum eNum = adRINone; + switch(_eNum) + { + case KeyRule::CASCADE: + eNum = adRICascade; + break; + case KeyRule::SET_NULL: + eNum = adRISetNull; + break; + case KeyRule::NO_ACTION: + eNum = adRINone; + break; + case KeyRule::SET_DEFAULT: + eNum = adRISetDefault; + break; + } + return eNum; +} + + diff --git a/connectivity/source/drivers/ado/AKeyColumn.cxx b/connectivity/source/drivers/ado/AKeyColumn.cxx new file mode 100644 index 000000000000..2ed8f753acec --- /dev/null +++ b/connectivity/source/drivers/ado/AKeyColumn.cxx @@ -0,0 +1,101 @@ +/************************************************************************* + * + * $RCSfile: AKeyColumn.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADABAS_KEYCOLUMN_HXX_ +#include "adabas/BKeyColumn.hxx" +#endif + +using namespace connectivity::adabas; +namespace starbeans = ::com::sun::star::beans; +// ------------------------------------------------------------------------- +OKeyColumn::OKeyColumn() : OColumn() +{ + construct(); +} +// ------------------------------------------------------------------------- +OKeyColumn::OKeyColumn( const ::rtl::OUString& _ReferencedColumn, + const ::rtl::OUString& _Name, + const ::rtl::OUString& _TypeName, + const ::rtl::OUString& _DefaultValue, + sal_Int32 _IsNullable, + sal_Int32 _Precision, + sal_Int32 _Scale, + sal_Int32 _Type, + sal_Bool _IsAutoIncrement + ) : OColumn(_Name, + _TypeName, + _DefaultValue, + _IsNullable, + _Precision, + _Scale, + _Type, + _IsAutoIncrement) + , m_ReferencedColumn(_ReferencedColumn) +{ + construct(); +} +// ------------------------------------------------------------------------- +void OKeyColumn::construct() +{ + sal_Int32 nAttrib = isNew() ? 0 : starbeans::PropertyAttribute::READONLY; + registerProperty(PROPERTY_REFERENCEDCOLUMN, PROPERTY_ID_REFERENCEDCOLUMN, nAttrib,&m_ReferencedColumn, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); +} + diff --git a/connectivity/source/drivers/ado/AKeyColumns.cxx b/connectivity/source/drivers/ado/AKeyColumns.cxx new file mode 100644 index 000000000000..251dfbe4ca6a --- /dev/null +++ b/connectivity/source/drivers/ado/AKeyColumns.cxx @@ -0,0 +1,142 @@ +/************************************************************************* + * + * $RCSfile: AKeyColumns.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADABAS_KEYCOLUMNS_HXX_ +#include "adabas/BKeyColumns.hxx" +#endif +#ifndef _CONNECTIVITY_ADABAS_KEYCOLUMN_HXX_ +#include "adabas/BKeyColumn.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ +#include <com/sun/star/sdbc/ColumnValue.hpp> +#endif +#ifndef _CONNECTIVITY_ADABAS_TABLE_HXX_ +#include "adabas/BTable.hxx" +#endif + +using namespace connectivity::adabas; +// ------------------------------------------------------------------------- +staruno::Reference< starcontainer::XNamed > OKeyColumns::createObject(const ::rtl::OUString& _rName) +{ + + staruno::Reference< starsdbc::XResultSet > + xResult = m_pTable->getConnection()->getMetaData()->getImportedKeys(staruno::Any(), + m_pTable->getSchema(),m_pTable->getName()); + + ::rtl::OUString aRefColumnName; + if(xResult.is()) + { + staruno::Reference< starsdbc::XRow > xRow(xResult,staruno::UNO_QUERY); + ::rtl::OUString aDot = ::rtl::OUString::createFromAscii("."); + while(xResult->next()) + { + if(xRow->getString(8) == _rName) + { + aRefColumnName = xRow->getString(4); + break; + } + } + } + + xResult = m_pTable->getConnection()->getMetaData()->getColumns(staruno::Any(), + m_pTable->getSchema(),m_pTable->getName(),_rName); + + staruno::Reference< starcontainer::XNamed > xRet = NULL; + if(xResult.is()) + { + staruno::Reference< starsdbc::XRow > xRow(xResult,staruno::UNO_QUERY); + if(xResult->next()) + { + if(xRow->getString(4) == _rName) + { + OKeyColumn* pRet = new OKeyColumn(aRefColumnName, + _rName, + xRow->getString(6), + xRow->getString(13), + xRow->getInt(11), + xRow->getInt(7), + xRow->getInt(9), + xRow->getInt(5), + sal_False); + xRet = pRet; + } + } + } + + return xRet; +} +// ------------------------------------------------------------------------- +staruno::Reference< starbeans::XPropertySet > OKeyColumns::createEmptyObject() +{ + OKeyColumn* pNew = new OKeyColumn(); + return pNew; +} +// ------------------------------------------------------------------------- + diff --git a/connectivity/source/drivers/ado/AKeys.cxx b/connectivity/source/drivers/ado/AKeys.cxx new file mode 100644 index 000000000000..e24988173ad3 --- /dev/null +++ b/connectivity/source/drivers/ado/AKeys.cxx @@ -0,0 +1,153 @@ +/************************************************************************* + * + * $RCSfile: AKeys.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADO_KEYS_HXX_ +#include "ado/AKeys.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_INDEX_HXX_ +#include "ado/AKey.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBCX_KEYTYPE_HPP_ +#include <com/sun/star/sdbcx/KeyType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_KEYRULE_HPP_ +#include <com/sun/star/sdbc/KeyRule.hpp> +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +using namespace connectivity::ado; +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::container; + +typedef connectivity::sdbcx::OCollection OCollection_TYPE; + +Reference< XNamed > OKeys::createObject(const ::rtl::OUString& _rName) +{ + ADOKey* pKey = NULL; + m_pCollection->get_Item(OLEVariant(_rName),&pKey); + + Reference< XNamed > xRet = new OAdoKey(isCaseSensitive(),pKey); + + return xRet; +} +// ------------------------------------------------------------------------- +void OKeys::impl_refresh() throw(RuntimeException) +{ + m_pCollection->Refresh(); +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > OKeys::createEmptyObject() +{ + OAdoKey* pNew = new OAdoKey(isCaseSensitive()); + return pNew; +} +// ------------------------------------------------------------------------- +// XAppend +void SAL_CALL OKeys::appendByDescriptor( const Reference< XPropertySet >& descriptor ) throw(SQLException, ElementExistException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(descriptor,UNO_QUERY); + if(xTunnel.is()) + { + OAdoKey* pKey = (OAdoKey*)xTunnel->getSomething(OAdoKey:: getUnoTunnelImplementationId()); + // To pass as column parameter to Key's Apppend method + OLEVariant vOptional; + vOptional.vt = VT_ERROR; + vOptional.scode = DISP_E_PARAMNOTFOUND; + + m_pCollection->Append(OLEVariant(pKey->getImpl()),(KeyTypeEnum)getINT32(descriptor->getPropertyValue(PROPERTY_TYPE)),vOptional); + } + + OCollection_TYPE::appendByDescriptor(descriptor); +} +// ------------------------------------------------------------------------- +// XDrop +void SAL_CALL OKeys::dropByName( const ::rtl::OUString& elementName ) throw(SQLException, NoSuchElementException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + m_pCollection->Delete(OLEVariant(elementName)); + + OCollection_TYPE::dropByName(elementName); +} +// ------------------------------------------------------------------------- +void SAL_CALL OKeys::dropByIndex( sal_Int32 index ) throw(SQLException, IndexOutOfBoundsException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + if (index < 0 || index >= getCount()) + throw IndexOutOfBoundsException(); + + m_pCollection->Delete(OLEVariant(index)); + + OCollection_TYPE::dropByIndex(index); +} + diff --git a/connectivity/source/drivers/ado/APreparedStatement.cxx b/connectivity/source/drivers/ado/APreparedStatement.cxx new file mode 100644 index 000000000000..423bff42b47c --- /dev/null +++ b/connectivity/source/drivers/ado/APreparedStatement.cxx @@ -0,0 +1,446 @@ +/************************************************************************* + * + * $RCSfile: APreparedStatement.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_ADO_APREPAREDSTATEMENT_HXX_ +#include "ado/APreparedStatement.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif +#ifndef _CONNECTIVITY_ADO_ARESULTSETMETADATA_HXX_ +#include "ado/AResultSetMetaData.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_ARESULTSET_HXX_ +#include "ado/AResultSet.hxx" +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif + +#define CHECK_RETURN(x) \ + if(!x) \ + ADOS::ThrowException(*m_pConnection->getConnection(),*this); + +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +using namespace connectivity::ado; +using namespace connectivity; +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::util; + + +IMPLEMENT_SERVICE_INFO(OPreparedStatement,"com.sun.star.sdbcx.APreparedStatement","com.sun.star.sdbc.PreparedStatement"); + +OPreparedStatement::OPreparedStatement( OConnection* _pConnection,const ::std::vector<OTypeInfo>& _TypeInfo,const ::rtl::OUString& sql) + : OStatement_Base( _pConnection ),m_aTypeInfo(_TypeInfo) +{ + osl_incrementInterlockedCount( &m_refCount ); + + CHECK_RETURN(m_Command.put_CommandText(sql)) + CHECK_RETURN(m_Command.put_Prepared(VARIANT_TRUE)) + m_pParameters = m_Command.get_Parameters(); + m_pParameters->AddRef(); + m_pParameters->Refresh(); + + osl_decrementInterlockedCount( &m_refCount ); +} +// ------------------------------------------------------------------------- + +Any SAL_CALL OPreparedStatement::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = OStatement_Base::queryInterface(rType); + if(!aRet.hasValue()) + aRet = ::cppu::queryInterface( rType, + static_cast< XPreparedStatement*>(this), + static_cast< XParameters*>(this), + static_cast< XPreparedBatchExecution*>(this), + static_cast< XResultSetMetaDataSupplier*>(this)); + return aRet; +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OPreparedStatement::getTypes( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< XPreparedStatement > *)0 ), + ::getCppuType( (const ::com::sun::star::uno::Reference< XParameters > *)0 ), + ::getCppuType( (const ::com::sun::star::uno::Reference< XResultSetMetaDataSupplier > *)0 ), + ::getCppuType( (const ::com::sun::star::uno::Reference< XPreparedBatchExecution > *)0 )); + + return ::utl::concatSequences(aTypes.getTypes(),OStatement_Base::getTypes()); +} +// ------------------------------------------------------------------------- + +Reference< XResultSetMetaData > SAL_CALL OPreparedStatement::getMetaData( ) throw(SQLException, RuntimeException) +{ + Reference< XResultSetMetaData > xRef = new OResultSetMetaData(m_RecordSet); + return xRef; +} +// ------------------------------------------------------------------------- +void OPreparedStatement::disposing() +{ + if(m_RecordSet.IsValid()) + m_RecordSet.Close(); + if(m_pParameters) + m_pParameters->Release(); + OStatement_Base::disposing(); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::close( ) throw(SQLException, RuntimeException) +{ + + { + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + } + dispose(); + +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OPreparedStatement::execute( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + SQLWarning warning; + + // Reset warnings + + clearWarnings (); + + // Reset the statement handle, warning and saved Resultset + + reset(); + + // Call SQLExecute + + try { + ADORecordset* pSet=NULL; + CHECK_RETURN(m_Command.Execute(m_RecordsAffected,m_Parameters,adCmdUnknown,&pSet)) + m_RecordSet = WpADORecordset(pSet); + } + catch (SQLWarning& ex) + { + + // Save pointer to warning and save with ResultSet + // object once it is created. + + warning = ex; + } + return m_RecordSet.IsValid(); +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OPreparedStatement::executeUpdate( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + ADORecordset* pSet=NULL; + CHECK_RETURN(m_Command.Execute(m_RecordsAffected,m_Parameters,adCmdUnknown,&pSet)) + m_RecordSet = WpADORecordset(pSet); + return m_RecordsAffected; +} + +// ------------------------------------------------------------------------- +void OPreparedStatement::setParameter(sal_Int32 parameterIndex, const DataTypeEnum& _eType, + const sal_Int32& _nSize,const OLEVariant& _Val) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_Int32 nCount = 0; + m_pParameters->get_Count(&nCount); + if(!nCount) + { + + ADOParameter* pParam = m_Command.CreateParameter(::rtl::OUString(),_eType,adParamInput,_nSize,_Val); + if(pParam) + { + pParam->AddRef(); + m_pParameters->Append(pParam); + } + } + else + { + ADOParameter* pParam = NULL; + m_pParameters->get_Item(OLEVariant(parameterIndex-1),&pParam); + if(pParam) + pParam->put_Value(_Val); + } + ADOS::ThrowException(*m_pConnection->getConnection(),*this); +} +// ------------------------------------------------------------------------- +void SAL_CALL OPreparedStatement::setString( sal_Int32 parameterIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException) +{ + setParameter(parameterIndex,adLongVarWChar,x.getLength(),x); +} +// ------------------------------------------------------------------------- + +Reference< XConnection > SAL_CALL OPreparedStatement::getConnection( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return (Reference< XConnection >)m_pConnection; +} +// ------------------------------------------------------------------------- + +Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + WpADORecordset aSet; + aSet.Create(); + OLEVariant aCmd; + aCmd.setIDispatch(m_Command); + OLEVariant aCon; + aCon.setNoArg(); + CHECK_RETURN(aSet.put_CacheSize(m_nFetchSize)) + CHECK_RETURN(aSet.put_MaxRecords(m_nMaxRows)) + CHECK_RETURN(aSet.Open(aCmd,aCon,m_eCursorType,m_eLockType,adOpenUnspecified)) + + CHECK_RETURN(aSet.get_CacheSize(m_nFetchSize)) + CHECK_RETURN(aSet.get_MaxRecords(m_nMaxRows)) + CHECK_RETURN(aSet.get_CursorType(m_eCursorType)) + CHECK_RETURN(aSet.get_LockType(m_eLockType)) + + OResultSet* pSet = new OResultSet(aSet,this); + Reference< XResultSet > pRs = pSet; + m_xResultSet = WeakReference<XResultSet>(pRs); + + return m_xResultSet; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setBoolean( sal_Int32 parameterIndex, sal_Bool x ) throw(SQLException, RuntimeException) +{ + setParameter(parameterIndex,adBoolean,sizeof(x),x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setByte( sal_Int32 parameterIndex, sal_Int8 x ) throw(SQLException, RuntimeException) +{ + setParameter(parameterIndex,adTinyInt,sizeof(x),x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setDate( sal_Int32 parameterIndex, const Date& x ) throw(SQLException, RuntimeException) +{ + setParameter(parameterIndex,adDBDate,sizeof(x),x); +} +// ------------------------------------------------------------------------- + + +void SAL_CALL OPreparedStatement::setTime( sal_Int32 parameterIndex, const Time& x ) throw(SQLException, RuntimeException) +{ + setParameter(parameterIndex,adDBTime,sizeof(x),x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setTimestamp( sal_Int32 parameterIndex, const DateTime& x ) throw(SQLException, RuntimeException) +{ + setParameter(parameterIndex,adDBTimeStamp,sizeof(x),x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setDouble( sal_Int32 parameterIndex, double x ) throw(SQLException, RuntimeException) +{ + setParameter(parameterIndex,adDouble,sizeof(x),x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setFloat( sal_Int32 parameterIndex, float x ) throw(SQLException, RuntimeException) +{ + setParameter(parameterIndex,adSingle,sizeof(x),x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setInt( sal_Int32 parameterIndex, sal_Int32 x ) throw(SQLException, RuntimeException) +{ + setParameter(parameterIndex,adInteger,sizeof(x),x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setLong( sal_Int32 parameterIndex, sal_Int64 x ) throw(SQLException, RuntimeException) +{ + setParameter(parameterIndex,adBigInt,sizeof(x),x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setNull( sal_Int32 parameterIndex, sal_Int32 sqlType ) throw(SQLException, RuntimeException) +{ + OLEVariant aVal; + aVal.setNull(); + setParameter(parameterIndex,adEmpty,0,aVal); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setClob( sal_Int32 parameterIndex, const Reference< XClob >& x ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setBlob( sal_Int32 parameterIndex, const Reference< XBlob >& x ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setArray( sal_Int32 parameterIndex, const Reference< XArray >& x ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setRef( sal_Int32 parameterIndex, const Reference< XRef >& x ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setObjectWithInfo( sal_Int32 parameterIndex, const Any& x, sal_Int32 sqlType, sal_Int32 scale ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& typeName ) throw(SQLException, RuntimeException) +{ + setNull(parameterIndex,sqlType); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setObject( sal_Int32 parameterIndex, const Any& x ) throw(SQLException, RuntimeException) +{ + // setObject (parameterIndex, x, sqlType, 0); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setShort( sal_Int32 parameterIndex, sal_Int16 x ) throw(SQLException, RuntimeException) +{ + setParameter(parameterIndex,adSmallInt,sizeof(x),x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setBytes( sal_Int32 parameterIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException) +{ + setParameter(parameterIndex,adVarBinary,sizeof(sal_Int8)*x.getLength(),x); +} + +// ------------------------------------------------------------------------- + + +void SAL_CALL OPreparedStatement::setCharacterStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setBinaryStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::clearParameters( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(m_pParameters) + { + sal_Int32 nCount = 0; + m_pParameters->get_Count(&nCount); + for(sal_Int32 i=nCount-1;i>=0;--i) + m_pParameters->Delete(OLEVariant(i)); + + } +} +// ------------------------------------------------------------------------- +void SAL_CALL OPreparedStatement::clearBatch( ) throw(SQLException, RuntimeException) +{ + // clearParameters( ); + // m_aBatchList.erase(); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::addBatch( ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +Sequence< sal_Int32 > SAL_CALL OPreparedStatement::executeBatch( ) throw(SQLException, RuntimeException) +{ + return Sequence< sal_Int32 > (); +} + + diff --git a/connectivity/source/drivers/ado/AResultSet.cxx b/connectivity/source/drivers/ado/AResultSet.cxx new file mode 100644 index 000000000000..f85bed5f0207 --- /dev/null +++ b/connectivity/source/drivers/ado/AResultSet.cxx @@ -0,0 +1,1269 @@ +/************************************************************************* + * + * $RCSfile: AResultSet.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#ifndef _CONNECTIVITY_ADO_ARESULTSET_HXX_ +#include "ado/AResultSet.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_ARESULTSETMETADATA_HXX_ +#include "ado/AResultSetMetaData.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_KEYRULE_HPP_ +#include <com/sun/star/sdbc/KeyRule.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_INDEXTYPE_HPP_ +#include <com/sun/star/sdbc/IndexType.hpp> +#endif +#ifndef _UTL_PROPERTY_HXX_ +#include <unotools/property.hxx> +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_RESULTSETCONCURRENCY_HPP_ +#include <com/sun/star/sdbc/ResultSetConcurrency.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_RESULTSETTYPE_HPP_ +#include <com/sun/star/sdbc/ResultSetType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_FETCHDIRECTION_HPP_ +#include <com/sun/star/sdbc/FetchDirection.hpp> +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif + +#include <oledb.h> + +#define CHECK_RETURN(x) \ + if(!SUCCEEDED(x)) \ + ADOS::ThrowException(*m_pStmt->m_pConnection->getConnection(),*this); + +using namespace connectivity::ado; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::sdbc; + +//------------------------------------------------------------------------------ +// IMPLEMENT_SERVICE_INFO(OResultSet,"com.sun.star.sdbcx.AResultSet","com.sun.star.sdbc.ResultSet"); +::rtl::OUString SAL_CALL OResultSet::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException) \ +{ + return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.ado.ResultSet"); +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OResultSet::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::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 OResultSet::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); + const ::rtl::OUString* pSupported = aSupported.getConstArray(); + for (sal_Int32 i=0; i<aSupported.getLength(); ++i, ++pSupported) + if (pSupported->equals(_rServiceName)) + return sal_True; + + return sal_False; +} +// ------------------------------------------------------------------------- +OResultSet::OResultSet(ADORecordset* _pRecordSet,OStatement_Base* pStmt) : OResultSet_BASE(m_aMutex) + ,OPropertySetHelper(OResultSet_BASE::rBHelper) + ,m_aStatement((::cppu::OWeakObject*)pStmt) + ,m_pStmt(pStmt) + ,m_nRowPos(0) + ,m_xMetaData(NULL) + ,m_pRecordSet(_pRecordSet) + ,m_bEOF(sal_False) +{ + osl_incrementInterlockedCount( &m_refCount ); + OSL_ENSHURE(_pRecordSet,"No RecordSet !"); + if(!_pRecordSet) + throw SQLException(); + m_pRecordSet->AddRef(); + VARIANT_BOOL bIsAtBOF; + CHECK_RETURN(m_pRecordSet->get_BOF(&bIsAtBOF)) + m_bOnFirstAfterOpen = !(sal_Bool)bIsAtBOF; + osl_decrementInterlockedCount( &m_refCount ); +} +// ------------------------------------------------------------------------- +OResultSet::OResultSet(ADORecordset* _pRecordSet) : OResultSet_BASE(m_aMutex) + ,OPropertySetHelper(OResultSet_BASE::rBHelper) + ,m_aStatement(NULL) + ,m_xMetaData(NULL) + ,m_pRecordSet(_pRecordSet) + ,m_bEOF(sal_False) +{ + osl_incrementInterlockedCount( &m_refCount ); + OSL_ENSHURE(_pRecordSet,"No RecordSet !"); + if(!_pRecordSet) + throw SQLException(); + m_pRecordSet->AddRef(); + VARIANT_BOOL bIsAtBOF; + CHECK_RETURN(m_pRecordSet->get_BOF(&bIsAtBOF)) + m_bOnFirstAfterOpen = !(sal_Bool)bIsAtBOF; + osl_decrementInterlockedCount( &m_refCount ); + // allocBuffer(); +} + +// ------------------------------------------------------------------------- +OResultSet::~OResultSet() +{ + if(m_pRecordSet) + m_pRecordSet->Release(); +} +// ------------------------------------------------------------------------- +void OResultSet::disposing(void) +{ + OPropertySetHelper::disposing(); + + ::osl::MutexGuard aGuard(m_aMutex); + if(m_pRecordSet) + m_pRecordSet->Close(); + m_aStatement = NULL; + m_xMetaData = NULL; +} +// ------------------------------------------------------------------------- +Any SAL_CALL OResultSet::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = OPropertySetHelper::queryInterface(rType); + if(!aRet.hasValue()) + aRet = OResultSet_BASE::queryInterface(rType); + return aRet; +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OResultSet::getTypes( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ), + ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ), + ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > *)0 )); + + return ::utl::concatSequences(aTypes.getTypes(),OResultSet_BASE::getTypes()); +} + +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSet::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + Reference< XResultSetMetaData > xMeta = getMetaData(); + sal_Int32 nLen = xMeta->getColumnCount(); + sal_Int32 i = 1; + for(;i<=nLen;++i) + if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) : columnName.equalsIgnoreCase(xMeta->getColumnName(i))) + break; + return i; +} +// ------------------------------------------------------------------------- +Reference< ::com::sun::star::io::XInputStream > SAL_CALL OResultSet::getBinaryStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + return NULL; +} +// ------------------------------------------------------------------------- +Reference< ::com::sun::star::io::XInputStream > SAL_CALL OResultSet::getCharacterStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + return NULL; +} + +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + ADO_GETFIELD(columnIndex); + aField.get_Value(m_aValue); + return m_aValue; +} +// ------------------------------------------------------------------------- + +sal_Int8 SAL_CALL OResultSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + ADO_GETFIELD(columnIndex); + aField.get_Value(m_aValue); + return m_aValue; +} +// ------------------------------------------------------------------------- + +Sequence< sal_Int8 > SAL_CALL OResultSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + ADO_GETFIELD(columnIndex); + aField.get_Value(m_aValue); + return m_aValue; +} +// ------------------------------------------------------------------------- + +::com::sun::star::util::Date SAL_CALL OResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + ADO_GETFIELD(columnIndex); + aField.get_Value(m_aValue); + return m_aValue; +} +// ------------------------------------------------------------------------- + +double SAL_CALL OResultSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + ADO_GETFIELD(columnIndex); + aField.get_Value(m_aValue); + return m_aValue; +} +// ------------------------------------------------------------------------- + +float SAL_CALL OResultSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + ADO_GETFIELD(columnIndex); + aField.get_Value(m_aValue); + return m_aValue; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + ADO_GETFIELD(columnIndex); + aField.get_Value(m_aValue); + return m_aValue; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSet::getRow( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + PositionEnum aPos; + m_pRecordSet->get_AbsolutePosition(&aPos); + return (aPos > 0) ? aPos : m_nRowPos; + // return the rowcount from driver if the driver doesn't support this return our count +} +// ------------------------------------------------------------------------- + +sal_Int64 SAL_CALL OResultSet::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + ADO_GETFIELD(columnIndex); + return sal_Int64(0); +} +// ------------------------------------------------------------------------- + +Reference< XResultSetMetaData > SAL_CALL OResultSet::getMetaData( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(!m_xMetaData.is()) + m_xMetaData = new OResultSetMetaData(m_pRecordSet); + return m_xMetaData; +} +// ------------------------------------------------------------------------- +Reference< XArray > SAL_CALL OResultSet::getArray( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + + return NULL; +} + +// ------------------------------------------------------------------------- + +Reference< XClob > SAL_CALL OResultSet::getClob( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + + return NULL; +} +// ------------------------------------------------------------------------- +Reference< XBlob > SAL_CALL OResultSet::getBlob( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + + return NULL; +} +// ------------------------------------------------------------------------- + +Reference< XRef > SAL_CALL OResultSet::getRef( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + + return NULL; +} +// ------------------------------------------------------------------------- + +Any SAL_CALL OResultSet::getObject( sal_Int32 columnIndex, const Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(SQLException, RuntimeException) +{ + + return Any(); +} +// ------------------------------------------------------------------------- + +sal_Int16 SAL_CALL OResultSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + ADO_GETFIELD(columnIndex); + aField.get_Value(m_aValue); + return m_aValue; +} +// ------------------------------------------------------------------------- + +::rtl::OUString SAL_CALL OResultSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + ADO_GETFIELD(columnIndex); + m_aValue = aField.get_Value(); + return m_aValue; +} + +// ------------------------------------------------------------------------- + + +::com::sun::star::util::Time SAL_CALL OResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + ADO_GETFIELD(columnIndex); + aField.get_Value(m_aValue); + return m_aValue; +} +// ------------------------------------------------------------------------- + + +::com::sun::star::util::DateTime SAL_CALL OResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + ADO_GETFIELD(columnIndex); + aField.get_Value(m_aValue); + return m_aValue; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::isAfterLast( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_Int16 bIsAtEOF; + CHECK_RETURN(m_pRecordSet->get_EOF(&bIsAtEOF)) + return bIsAtEOF; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::isFirst( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return m_nRowPos == 1; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::isLast( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return sal_True; +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::beforeFirst( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(first()) + previous(); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::afterLast( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(last()) + next(); + m_bEOF = sal_True; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::close( ) throw(SQLException, RuntimeException) +{ + { + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + } + dispose(); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::first( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(SUCCEEDED(m_pRecordSet->MoveFirst())) + { + m_nRowPos = 1; + return sal_True; + } + return sal_False; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::last( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_Bool bRet = SUCCEEDED(m_pRecordSet->MoveLast()); + if(bRet) + m_pRecordSet->get_RecordCount(&m_nRowPos); + return bRet; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(!row) // absolute with zero not allowed + throw SQLException(); + + sal_Bool bCheck = sal_True; + if(row < 0) + { + if(bCheck = SUCCEEDED(m_pRecordSet->MoveLast())) + { + while(++row < 0 && bCheck) + bCheck = m_pRecordSet->MovePrevious(); + } + } + else + { + first(); + OLEVariant aEmpty; + aEmpty.setNoArg(); + bCheck = SUCCEEDED(m_pRecordSet->Move(row-1,aEmpty)); // move to row -1 because we stand already on the first + if(bCheck) + m_nRowPos = row; + } + return bCheck; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::relative( sal_Int32 row ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + OLEVariant aEmpty; + aEmpty.setNoArg(); + sal_Bool bRet = SUCCEEDED(m_pRecordSet->Move(row,aEmpty)); + if(bRet) + m_nRowPos += row; + return bRet; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::previous( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_Bool bRet = SUCCEEDED(m_pRecordSet->MovePrevious()); + if(bRet) + --m_nRowPos; + return bRet; +} +// ------------------------------------------------------------------------- +Reference< XInterface > SAL_CALL OResultSet::getStatement( ) throw(SQLException, RuntimeException) +{ + return m_aStatement.get(); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::rowDeleted( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + RecordStatusEnum eRec; + m_pRecordSet->get_Status((sal_Int32*)&eRec); + sal_Bool bRet = (eRec & adRecDeleted) == adRecDeleted; + if(bRet) + --m_nRowPos; + return bRet; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::rowInserted( ) throw(SQLException, RuntimeException) +{ ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + RecordStatusEnum eRec; + m_pRecordSet->get_Status((sal_Int32*)&eRec); + sal_Bool bRet = (eRec & adRecNew) == adRecNew; + if(bRet) + ++m_nRowPos; + return bRet; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::rowUpdated( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + RecordStatusEnum eRec; + m_pRecordSet->get_Status((sal_Int32*)&eRec); + return (eRec & adRecModified) == adRecModified; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::isBeforeFirst( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + OSL_ENSHURE(!m_nRowPos,"OResultSet::isBeforeFirst: Error in setting m_nRowPos!"); + sal_Int16 bIsAtBOF; + m_pRecordSet->get_BOF(&bIsAtBOF); + return bIsAtBOF; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::next( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_Bool bRet = sal_True; + if(m_bOnFirstAfterOpen) + { + m_bOnFirstAfterOpen = sal_False; + ++m_nRowPos; + } + else + { + bRet = SUCCEEDED(m_pRecordSet->MoveNext()); + + if(bRet) + { + VARIANT_BOOL bIsAtEOF; + CHECK_RETURN(m_pRecordSet->get_EOF(&bIsAtEOF)) + bRet = !(sal_Bool)bIsAtEOF; + ++m_nRowPos; + } + else + ADOS::ThrowException(*m_pStmt->m_pConnection->getConnection(),*this); + } + + return bRet; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::wasNull( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return m_aValue.isNull(); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::cancel( ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_pRecordSet->Cancel(); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::clearWarnings( ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- +Any SAL_CALL OResultSet::getWarnings( ) throw(SQLException, RuntimeException) +{ + return Any(); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::insertRow( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + OLEVariant aEmpty; + aEmpty.setNoArg(); + m_pRecordSet->AddNew(aEmpty,aEmpty); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateRow( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + OLEVariant aEmpty; + aEmpty.setNoArg(); + m_pRecordSet->Update(aEmpty,aEmpty); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::deleteRow( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_pRecordSet->Delete(adAffectCurrent); + m_pRecordSet->UpdateBatch(adAffectCurrent); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::cancelRowUpdates( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_pRecordSet->CancelUpdate(); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::moveToInsertRow( ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::moveToCurrentRow( ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateNull( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + + ADO_GETFIELD(columnIndex); + OLEVariant x; + x.setNull(); + aField.PutValue(x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateBoolean( sal_Int32 columnIndex, sal_Bool x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + + ADO_GETFIELD(columnIndex); + aField.PutValue(x); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateByte( sal_Int32 columnIndex, sal_Int8 x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + + ADO_GETFIELD(columnIndex); + aField.PutValue(x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateShort( sal_Int32 columnIndex, sal_Int16 x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + + ADO_GETFIELD(columnIndex); + aField.PutValue(x); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateInt( sal_Int32 columnIndex, sal_Int32 x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + + ADO_GETFIELD(columnIndex); + aField.PutValue(x); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateLong( sal_Int32 columnIndex, sal_Int64 x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + + ADO_GETFIELD(columnIndex); + aField.PutValue(x); +} +// ----------------------------------------------------------------------- +void SAL_CALL OResultSet::updateFloat( sal_Int32 columnIndex, float x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + + ADO_GETFIELD(columnIndex); + aField.PutValue(x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateDouble( sal_Int32 columnIndex, double x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + + ADO_GETFIELD(columnIndex); + aField.PutValue(x); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateString( sal_Int32 columnIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + + ADO_GETFIELD(columnIndex); + aField.PutValue(x); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateBytes( sal_Int32 columnIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + + ADO_GETFIELD(columnIndex); + aField.PutValue(x); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateDate( sal_Int32 columnIndex, const ::com::sun::star::util::Date& x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + + ADO_GETFIELD(columnIndex); + aField.PutValue(x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateTime( sal_Int32 columnIndex, const ::com::sun::star::util::Time& x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + + ADO_GETFIELD(columnIndex); + aField.PutValue(x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateTimestamp( sal_Int32 columnIndex, const ::com::sun::star::util::DateTime& x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + + ADO_GETFIELD(columnIndex); + aField.PutValue(x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateBinaryStream( sal_Int32 columnIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException) +{ + +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateCharacterStream( sal_Int32 columnIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException) +{ + +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::refreshRow( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_pRecordSet->Resync(adAffectCurrent,adResyncAllValues); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateObject( sal_Int32 columnIndex, const Any& x ) throw(SQLException, RuntimeException) +{ + +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateNumericObject( sal_Int32 columnIndex, const Any& x, sal_Int32 scale ) throw(SQLException, RuntimeException) +{ + + OSL_ENSHURE(0,"OResultSet::updateNumericObject: NYI"); +} +//------------------------------------------------------------------------------ +// XRowLocate +Any SAL_CALL OResultSet::getBookmark( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(m_nRowPos < m_aBookmarks.size()) // this bookmark was already fetched + return makeAny(sal_Int32(m_nRowPos-1)); + + OLEVariant aVar; + m_pRecordSet->get_Bookmark(&aVar); + m_aBookmarks.push_back(aVar); + return makeAny((sal_Int32)(m_aBookmarks.size()-1)); + +} +//------------------------------------------------------------------------------ +sal_Bool SAL_CALL OResultSet::moveToBookmark( const Any& bookmark ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_Int32 nPos; + bookmark >>= nPos; + OSL_ENSHURE(nPos >= 0 && nPos < m_aBookmarks.size(),"Invalid Index for vector"); + if(nPos < 0 || nPos >= m_aBookmarks.size()) + throw SQLException(); + + return SUCCEEDED(m_pRecordSet->Move(0,m_aBookmarks[nPos])); +} +//------------------------------------------------------------------------------ +sal_Bool SAL_CALL OResultSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_Int32 nPos; + bookmark >>= nPos; + nPos += rows; + OSL_ENSHURE(nPos >= 0 && nPos < m_aBookmarks.size(),"Invalid Index for vector"); + if(nPos < 0 || nPos >= m_aBookmarks.size()) + throw SQLException(); + return SUCCEEDED(m_pRecordSet->Move(rows,m_aBookmarks[nPos])); +} +//------------------------------------------------------------------------------ +sal_Int32 SAL_CALL OResultSet::compareBookmarks( const Any& first, const Any& second ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_Int32 nPos1; + first >>= nPos1; + sal_Int32 nPos2; + second >>= nPos2; + if(nPos1 == nPos2) // they should be equal + return sal_True; + + OSL_ENSHURE((nPos1 >= 0 && nPos1 < m_aBookmarks.size()) || (nPos1 >= 0 && nPos2 < m_aBookmarks.size()),"Invalid Index for vector"); + + CompareEnum eNum; + m_pRecordSet->CompareBookmarks(m_aBookmarks[nPos1],m_aBookmarks[nPos2],&eNum); + return ((sal_Int32)eNum) +1; +} +//------------------------------------------------------------------------------ +sal_Bool SAL_CALL OResultSet::hasOrderedBookmarks( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + ADOProperties* pProps = NULL; + m_pRecordSet->get_Properties(&pProps); + WpOLEAppendCollection<ADOProperties, ADOProperty, WpADOProperty> aProps(pProps); + ADOS::ThrowException(*((OConnection*)m_pStmt->getConnection().get())->getConnection(),*this); + OSL_ENSHURE(aProps.IsValid(),"There are no properties at the connection"); + + WpADOProperty aProp(aProps.GetItem(::rtl::OUString::createFromAscii("Bookmarks Ordered"))); + OLEVariant aVar; + if(aProp.IsValid()) + aVar = aProp.GetValue(); + else + ADOS::ThrowException(*((OConnection*)m_pStmt->getConnection().get())->getConnection(),*this); + + sal_Bool bValue(sal_False); + if(!aVar.isNull() && !aVar.isEmpty()) + bValue = aVar; + return bValue; +} +//------------------------------------------------------------------------------ +sal_Int32 SAL_CALL OResultSet::hashBookmark( const Any& bookmark ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_Int32 nPos; + bookmark >>= nPos; + return nPos; +} +//------------------------------------------------------------------------------ +// XDeleteRows +Sequence< sal_Int32 > SAL_CALL OResultSet::deleteRows( const Sequence< Any >& rows ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + OLEVariant aVar; + sal_Int32 nPos; + + // Create SafeArray Bounds and initialize the array + SAFEARRAYBOUND rgsabound[1]; + rgsabound[0].lLbound = 0; + rgsabound[0].cElements = rows.getLength(); + SAFEARRAY *psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); + + const Any* pBegin = rows.getConstArray(); + const Any* pEnd = pBegin + rows.getLength(); + for(sal_Int32 i=0;pBegin != pEnd ;++pBegin,++i) + { + *pBegin >>= nPos; + SafeArrayPutElement(psa,&i,&m_aBookmarks[nPos]); + } + + // Initialize and fill the SafeArray + OLEVariant vsa; + vsa.setArray(psa,VT_VARIANT); + + m_pRecordSet->put_Filter(vsa); + m_pRecordSet->Delete(adAffectGroup); + m_pRecordSet->UpdateBatch(adAffectGroup); + + Sequence< sal_Int32 > aSeq(rows.getLength()); + if(first()) + { + sal_Int32* pSeq = aSeq.getArray(); + sal_Int32 i=0; + do + { + OSL_ENSHURE(i<aSeq.getLength(),"Index greater than length of sequence"); + m_pRecordSet->get_Status(&pSeq[i]); + if(pSeq[i++] == adRecDeleted) + --m_nRowPos; + } + while(next()); + } + return aSeq; +} +//------------------------------------------------------------------------------ +sal_Int32 OResultSet::getResultSetConcurrency() const +{ + sal_Int32 nValue=0; + LockTypeEnum eRet; + if(!SUCCEEDED(m_pRecordSet->get_LockType(&eRet))) + { + switch(eRet) + { + case adLockReadOnly: + nValue = ResultSetConcurrency::READ_ONLY; + break; + default: + nValue = ResultSetConcurrency::UPDATABLE; + break; + } + } + return nValue; +} +//------------------------------------------------------------------------------ +sal_Int32 OResultSet::getResultSetType() const +{ + sal_Int32 nValue=0; + CursorTypeEnum eRet; + if(!SUCCEEDED(m_pRecordSet->get_CursorType(&eRet))) + { + switch(eRet) + { + case adOpenUnspecified: + case adOpenForwardOnly: + nValue = ResultSetType::FORWARD_ONLY; + break; + case adOpenStatic: + case adOpenKeyset: + nValue = ResultSetType::SCROLL_INSENSITIVE; + break; + case adOpenDynamic: + nValue = ResultSetType::SCROLL_SENSITIVE; + break; + } + } + return nValue; +} +//------------------------------------------------------------------------------ +sal_Int32 OResultSet::getFetchDirection() const +{ + return FetchDirection::FORWARD; +} +//------------------------------------------------------------------------------ +sal_Int32 OResultSet::getFetchSize() const +{ + sal_Int32 nValue=-1; + m_pRecordSet->get_CacheSize(&nValue); + return nValue; +} +//------------------------------------------------------------------------------ +::rtl::OUString OResultSet::getCursorName() const +{ + return ::rtl::OUString(); +} + +//------------------------------------------------------------------------------ +void OResultSet::setFetchDirection(sal_Int32 _par0) +{ +} +//------------------------------------------------------------------------------ +void OResultSet::setFetchSize(sal_Int32 _par0) +{ + m_pRecordSet->put_CacheSize(_par0); +} +// ------------------------------------------------------------------------- +::cppu::IPropertyArrayHelper* OResultSet::createArrayHelper( ) const +{ + Sequence< com::sun::star::beans::Property > aProps(5); + com::sun::star::beans::Property* pProperties = aProps.getArray(); + sal_Int32 nPos = 0; + + // DECL_PROP1IMPL(CURSORNAME, ::rtl::OUString) PropertyAttribute::READONLY); + DECL_PROP0(FETCHDIRECTION, sal_Int32); + DECL_PROP0(FETCHSIZE, sal_Int32); + DECL_BOOL_PROP1IMPL(ISBOOKMARKABLE) PropertyAttribute::READONLY); + DECL_PROP1IMPL(RESULTSETCONCURRENCY,sal_Int32) PropertyAttribute::READONLY); + DECL_PROP1IMPL(RESULTSETTYPE, sal_Int32) PropertyAttribute::READONLY); + + return new ::cppu::OPropertyArrayHelper(aProps); +} +// ------------------------------------------------------------------------- +::cppu::IPropertyArrayHelper & OResultSet::getInfoHelper() +{ + return *const_cast<OResultSet*>(this)->getArrayHelper(); +} +// ------------------------------------------------------------------------- +sal_Bool OResultSet::convertFastPropertyValue( + Any & rConvertedValue, + Any & rOldValue, + sal_Int32 nHandle, + const Any& rValue ) + throw (::com::sun::star::lang::IllegalArgumentException) +{ + switch(nHandle) + { + case PROPERTY_ID_ISBOOKMARKABLE: + case PROPERTY_ID_CURSORNAME: + case PROPERTY_ID_RESULTSETCONCURRENCY: + case PROPERTY_ID_RESULTSETTYPE: + throw ::com::sun::star::lang::IllegalArgumentException(); + break; + case PROPERTY_ID_FETCHDIRECTION: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection()); + case PROPERTY_ID_FETCHSIZE: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize()); + default: + ; + } + return sal_False; +} +// ------------------------------------------------------------------------- +void OResultSet::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)throw (Exception) +{ + switch(nHandle) + { + case PROPERTY_ID_ISBOOKMARKABLE: + case PROPERTY_ID_CURSORNAME: + case PROPERTY_ID_RESULTSETCONCURRENCY: + case PROPERTY_ID_RESULTSETTYPE: + throw Exception(); + break; + case PROPERTY_ID_FETCHDIRECTION: + setFetchDirection(getINT32(rValue)); + break; + case PROPERTY_ID_FETCHSIZE: + setFetchSize(getINT32(rValue)); + break; + default: + ; + } +} +// ------------------------------------------------------------------------- +void OResultSet::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const +{ + switch(nHandle) + { + case PROPERTY_ID_ISBOOKMARKABLE: + { + VARIANT_BOOL bBool; + m_pRecordSet->Supports(adBookmark,&bBool); + sal_Bool bRet = bBool == VARIANT_TRUE; + rValue.setValue(&bRet, ::getCppuBooleanType() ); + } + break; + case PROPERTY_ID_CURSORNAME: + rValue <<= getCursorName(); + break; + case PROPERTY_ID_RESULTSETCONCURRENCY: + rValue <<= getResultSetConcurrency(); + break; + case PROPERTY_ID_RESULTSETTYPE: + rValue <<= getResultSetType(); + break; + case PROPERTY_ID_FETCHDIRECTION: + rValue <<= getFetchDirection(); + break; + case PROPERTY_ID_FETCHSIZE: + rValue <<= getFetchSize(); + break; + } +} + + diff --git a/connectivity/source/drivers/ado/AResultSetMetaData.cxx b/connectivity/source/drivers/ado/AResultSetMetaData.cxx new file mode 100644 index 000000000000..fa1161fd358a --- /dev/null +++ b/connectivity/source/drivers/ado/AResultSetMetaData.cxx @@ -0,0 +1,257 @@ +/************************************************************************* + * + * $RCSfile: AResultSetMetaData.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADO_ARESULTSETMETADATA_HXX_ +#include "ado/AResultSetMetaData.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ +#include <com/sun/star/sdbc/ColumnValue.hpp> +#endif + +#ifndef _CONNECTIVITY_ADO_AWRAPADO_HXX_ +#include "ado/Awrapado.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif + +using namespace connectivity; +using namespace connectivity::ado; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::sdbc; + +// ------------------------------------------------------------------------- +OResultSetMetaData::~OResultSetMetaData() +{ + m_pRecordSet->Release(); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + ADO_GETFIELD(column); + if(aField.IsValid() && aField.GetActualSize() != -1) + return aField.GetActualSize(); + return 0; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSetMetaData::getColumnType( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + ADO_GETFIELD(column); + return ADOS::MapADOType2Jdbc(aField.GetADOType()); +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount( ) throw(SQLException, RuntimeException) +{ + if(m_nColCount != -1) + return m_nColCount; + + ADOFields* pFields = NULL; + m_pRecordSet->get_Fields(&pFields); + WpOLEAppendCollection<ADOFields, ADOField, WpADOField> aFields(pFields); + m_nColCount = aFields.GetItemCount(); + return m_nColCount; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return sal_True; +} +// ------------------------------------------------------------------------- + +::rtl::OUString SAL_CALL OResultSetMetaData::getSchemaName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- + +::rtl::OUString SAL_CALL OResultSetMetaData::getColumnName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + ADO_GETFIELD(column); + if(aField.IsValid()) + return aField.GetName(); + + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getTableName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getCatalogName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getColumnTypeName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getColumnLabel( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getColumnName(column); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getColumnServiceName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isCurrency( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + ADO_GETFIELD(column); + if(aField.IsValid()) + { + return (aField.GetAttributes() & adFldFixed) == adFldFixed; + } + return sal_False; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return sal_False; +} +// ------------------------------------------------------------------------- + + +sal_Bool SAL_CALL OResultSetMetaData::isSigned( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + ADO_GETFIELD(column); + if(aField.IsValid()) + { + return (aField.GetAttributes() & adFldNegativeScale) == adFldNegativeScale; + } + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OResultSetMetaData::getPrecision( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + ADO_GETFIELD(column); + if(aField.IsValid()) + return aField.GetPrecision(); + return 0; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OResultSetMetaData::getScale( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + ADO_GETFIELD(column); + if(aField.IsValid()) + return aField.GetNumericScale(); + return 0; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSetMetaData::isNullable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + ADO_GETFIELD(column); + if(aField.IsValid()) + { + return (aField.GetAttributes() & adFldIsNullable) == adFldIsNullable; + } + return sal_False; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isSearchable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return sal_True; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isReadOnly( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + ADO_GETFIELD(column); + if(aField.IsValid()) + { + // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly; + } + return sal_False; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + ADO_GETFIELD(column); + if(aField.IsValid()) + { + return (aField.GetAttributes() & adFldUpdatable) == adFldUpdatable; + } + return sal_False; +; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return isDefinitelyWritable(column); +} +// ------------------------------------------------------------------------- + diff --git a/connectivity/source/drivers/ado/AStatement.cxx b/connectivity/source/drivers/ado/AStatement.cxx new file mode 100644 index 000000000000..652b17b42c4a --- /dev/null +++ b/connectivity/source/drivers/ado/AStatement.cxx @@ -0,0 +1,840 @@ +/************************************************************************* + * + * $RCSfile: AStatement.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_ADO_ASTATEMENT_HXX_ +#include "ado/AStatement.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_ACONNECTION_HXX_ +#include "ado/AConnection.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_ARESULTSET_HXX_ +#include "ado/AResultSet.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +#ifndef _UTL_PROPERTY_HXX_ +#include <unotools/property.hxx> +#endif +#ifndef _UTL_UNO3_HXX_ +#include <unotools/uno3.hxx> +#endif +#ifndef _OSL_THREAD_H_ +#include <osl/thread.h> +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif +#ifndef _COM_SUN_STAR_SDBC_RESULTSETCONCURRENCY_HPP_ +#include <com/sun/star/sdbc/ResultSetConcurrency.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_RESULTSETTYPE_HPP_ +#include <com/sun/star/sdbc/ResultSetType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_FETCHDIRECTION_HPP_ +#include <com/sun/star/sdbc/FetchDirection.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif + +#define CHECK_RETURN(x) \ + if(!x) \ + ADOS::ThrowException(*m_pConnection->getConnection(),*this); + +using namespace connectivity::ado; + +//------------------------------------------------------------------------------ +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::sdbc; + +//------------------------------------------------------------------------------ +OStatement_Base::OStatement_Base(OConnection* _pConnection ) : OStatement_BASE(m_aMutex) + ,OPropertySetHelper(OStatement_BASE::rBHelper) + ,OSubComponent< OStatement_Base>((::cppu::OWeakObject*)_pConnection) + ,m_pConnection(_pConnection) + ,m_nFetchSize(1) + ,m_nMaxRows(0) + ,m_eLockType(adLockReadOnly) + ,m_eCursorType(adOpenForwardOnly) +{ + osl_incrementInterlockedCount( &m_refCount ); + + m_Command.Create(); + if(m_Command.IsValid()) + m_Command.putref_ActiveConnection(m_pConnection->getConnection()); + else + ADOS::ThrowException(*m_pConnection->getConnection(),*this); + + m_RecordsAffected.setNoArg(); + m_Parameters.setNoArg(); + + m_pConnection->acquire(); + + osl_decrementInterlockedCount( &m_refCount ); +} +//------------------------------------------------------------------------------ +void OStatement_Base::disposeResultSet() +{ + // free the cursor if alive + Reference< XComponent > xComp(m_xResultSet.get(), UNO_QUERY); + if (xComp.is()) + xComp->dispose(); + m_xResultSet = Reference< XResultSet>(); +} + +//------------------------------------------------------------------------------ +void OStatement_Base::disposing() +{ + ::osl::MutexGuard aGuard(m_aMutex); + + + disposeResultSet(); + + m_Command.clear(); + m_RecordSet.clear(); + + if (m_pConnection) + m_pConnection->release(); + + dispose_ChildImpl(); + OStatement_BASE::disposing(); +} +//----------------------------------------------------------------------------- +void SAL_CALL OStatement_Base::release() throw(RuntimeException) +{ + relase_ChildImpl(); + OStatement_BASE::release(); +} +//----------------------------------------------------------------------------- +Any SAL_CALL OStatement_Base::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = OStatement_BASE::queryInterface(rType); + if(!aRet.hasValue()) + aRet = OPropertySetHelper::queryInterface(rType); + return aRet; +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OStatement_Base::getTypes( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ), + ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ), + ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > *)0 )); + + return ::utl::concatSequences(aTypes.getTypes(),OStatement_BASE::getTypes()); +} + +// ------------------------------------------------------------------------- + +void SAL_CALL OStatement_Base::cancel( ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + CHECK_RETURN(m_Command.Cancel()) +} +// ------------------------------------------------------------------------- + +void SAL_CALL OStatement_Base::close( ) throw(SQLException, RuntimeException) +{ + { + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + } + dispose(); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OStatement::clearBatch( ) throw(SQLException, RuntimeException) +{ + +} +// ------------------------------------------------------------------------- + +void OStatement_Base::reset() throw (SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + clearWarnings (); + + if (m_xResultSet.get().is()) + clearMyResultSet(); + else + { + if(0) + { + m_Command.clear(); + m_Command.Create(); + if(m_Command.IsValid()) + m_Command.putref_ActiveConnection(m_pConnection->getConnection()); + else + ADOS::ThrowException(*m_pConnection->getConnection(),*this); + + m_RecordsAffected.setNoArg(); + m_Parameters.setNoArg(); + } + } +} +//-------------------------------------------------------------------- +// clearMyResultSet +// If a ResultSet was created for this Statement, close it +//-------------------------------------------------------------------- + +void OStatement_Base::clearMyResultSet () throw (SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + Reference<XCloseable> xCloseable; + if(::utl::query_interface(m_xResultSet.get(),xCloseable)) + xCloseable->close(); + m_xResultSet = Reference< XResultSet>(); +} +//-------------------------------------------------------------------- +sal_Int32 OStatement_Base::getRowCount () throw( SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return m_RecordsAffected; +} +//-------------------------------------------------------------------- +// getPrecision +// Given a SQL type, return the maximum precision for the column. +// Returns -1 if not known +//-------------------------------------------------------------------- + +sal_Int32 OStatement_Base::getPrecision ( sal_Int32 sqlType) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_Int32 prec = -1; + OTypeInfo aInfo; + aInfo.nType = sqlType; + if (m_aTypeInfo.size()) + { + ::std::vector<OTypeInfo>::const_iterator aIter = ::std::find(m_aTypeInfo.begin(),m_aTypeInfo.end(),aInfo); + for(;aIter != m_aTypeInfo.end();++aIter) + { + prec = max(prec,(*aIter).nPrecision); + } + } + + return prec; +} +//-------------------------------------------------------------------- +// setWarning +// Sets the warning +//-------------------------------------------------------------------- + +void OStatement_Base::setWarning (const SQLWarning &ex) throw( SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_aLastWarning = ex; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OStatement_Base::execute( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + // Reset the statement handle and warning + + reset(); + + try { + ADORecordset* pSet = NULL; + CHECK_RETURN(m_Command.put_CommandText(sql)) + CHECK_RETURN(m_Command.Execute(m_RecordsAffected,m_Parameters,adCmdText,&pSet)) + m_RecordSet = WpADORecordset(pSet); + } + catch (SQLWarning& ex) { + + // Save pointer to warning and save with ResultSet + // object once it is created. + + m_aLastWarning = ex; + } + + return m_RecordSet.IsValid(); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL OStatement_Base::executeQuery( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + reset(); + + m_xResultSet = WeakReference<XResultSet>(NULL); + + WpADORecordset aSet; + aSet.Create(); + CHECK_RETURN(m_Command.put_CommandText(sql)) + OLEVariant aCmd; + aCmd.setIDispatch(m_Command); + OLEVariant aCon; + aCon.setNoArg(); + CHECK_RETURN(aSet.put_CacheSize(m_nFetchSize)) + CHECK_RETURN(aSet.put_MaxRecords(m_nMaxRows)) + CHECK_RETURN(aSet.Open(aCmd,aCon,m_eCursorType,m_eLockType,adOpenUnspecified)) + + + CHECK_RETURN(aSet.get_CacheSize(m_nFetchSize)) + CHECK_RETURN(aSet.get_MaxRecords(m_nMaxRows)) + CHECK_RETURN(aSet.get_CursorType(m_eCursorType)) + CHECK_RETURN(aSet.get_LockType(m_eLockType)) + + OResultSet* pSet = new OResultSet(aSet,this); + Reference< XResultSet > pRs = pSet; + + m_xResultSet = WeakReference<XResultSet>(pRs); + + return m_xResultSet; +} +// ------------------------------------------------------------------------- + +Reference< XConnection > SAL_CALL OStatement_Base::getConnection( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return (Reference< XConnection >)m_pConnection; +} +// ------------------------------------------------------------------------- + +Any SAL_CALL OStatement::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = ::cppu::queryInterface(rType,static_cast< XBatchExecution*> (this)); + if(!aRet.hasValue()) + aRet = OStatement_Base::queryInterface(rType); + return aRet; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OStatement::addBatch( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_aBatchList.push_back(sql); +} +// ------------------------------------------------------------------------- +Sequence< sal_Int32 > SAL_CALL OStatement::executeBatch( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + reset(); + + ::rtl::OUString aBatchSql; + sal_Int32 nLen = 0; + for(::std::list< ::rtl::OUString>::const_iterator i=m_aBatchList.begin();i != m_aBatchList.end();++i,++nLen) + aBatchSql = aBatchSql + *i + ::rtl::OUString::createFromAscii(";"); + + ADORecordset* pSet=NULL; + m_RecordSet.clear(); + m_RecordSet.Create(); + + CHECK_RETURN(m_Command.put_CommandText(aBatchSql)) + m_RecordSet.PutRefDataSource((IDispatch*)&m_Command); + + CHECK_RETURN(m_RecordSet.UpdateBatch(adAffectAll)) + + Sequence< sal_Int32 > aRet(nLen); + sal_Int32* pArray = aRet.getArray(); + for(sal_Int32 j=0;j<nLen;++j) + { + pSet = NULL; + OLEVariant aRecordsAffected; + if(m_RecordSet.NextRecordset(aRecordsAffected,&pSet) && pSet) + { + m_RecordSet = WpADORecordset(pSet); + sal_Int32 nValue; + if(m_RecordSet.get_RecordCount(nValue)) + pArray[j] = nValue; + } + } + return aRet; +} +// ------------------------------------------------------------------------- + + +sal_Int32 SAL_CALL OStatement_Base::executeUpdate( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + reset(); + + try { + ADORecordset* pSet = NULL; + CHECK_RETURN(m_Command.put_CommandText(sql)) + CHECK_RETURN(m_Command.Execute(m_RecordsAffected,m_Parameters,adCmdText|adExecuteNoRecords,&pSet)) + } + catch (SQLWarning& ex) { + + // Save pointer to warning and save with ResultSet + // object once it is created. + + m_aLastWarning = ex; + } + if(!m_RecordsAffected.isEmpty() && !m_RecordsAffected.isNull() && m_RecordsAffected.getType() != VT_ERROR) + return m_RecordsAffected; + + return 0; +} +// ------------------------------------------------------------------------- + +Reference< XResultSet > SAL_CALL OStatement_Base::getResultSet( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return m_xResultSet; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OStatement_Base::getUpdateCount( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_Int32 nRet; + if(m_RecordSet.IsValid() && m_RecordSet.get_RecordCount(nRet)) + return nRet; + return -1; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OStatement_Base::getMoreResults( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + SQLWarning warning; + + // clear previous warnings + + clearWarnings (); + + // Call SQLMoreResults + + try { + ADORecordset* pSet=NULL; + OLEVariant aRecordsAffected; + if(m_RecordSet.IsValid() && m_RecordSet.NextRecordset(aRecordsAffected,&pSet) && pSet) + m_RecordSet = WpADORecordset(pSet); + } + catch (SQLWarning &ex) { + + // Save pointer to warning and save with ResultSet + // object once it is created. + + warning = ex; + } + return m_RecordSet.IsValid(); +} +// ------------------------------------------------------------------------- + +// ------------------------------------------------------------------------- +Any SAL_CALL OStatement_Base::getWarnings( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return makeAny(m_aLastWarning); +} +// ------------------------------------------------------------------------- + +// ------------------------------------------------------------------------- +void SAL_CALL OStatement_Base::clearWarnings( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_aLastWarning = SQLWarning(); +} +// ------------------------------------------------------------------------- +//------------------------------------------------------------------------------ +sal_Int32 OStatement_Base::getQueryTimeOut() const throw(SQLException, RuntimeException) +{ + return m_Command.get_CommandTimeout(); +} +//------------------------------------------------------------------------------ +sal_Int32 OStatement_Base::getMaxRows() const throw(SQLException, RuntimeException) +{ + sal_Int32 nRet=-1; + if(!m_RecordSet.IsValid() && m_RecordSet.get_MaxRecords(nRet)) + throw SQLException(); + return nRet; +} +//------------------------------------------------------------------------------ +sal_Int32 OStatement_Base::getResultSetConcurrency() const throw(SQLException, RuntimeException) +{ + return m_eLockType; + sal_Int32 nValue=0; + switch(m_eLockType) + { + case adLockReadOnly: + nValue = ResultSetConcurrency::READ_ONLY; + break; + default: + nValue = ResultSetConcurrency::UPDATABLE; + break; + } + + return nValue; +} +//------------------------------------------------------------------------------ +sal_Int32 OStatement_Base::getResultSetType() const throw(SQLException, RuntimeException) +{ + sal_Int32 nValue=0; + switch(m_eCursorType) + { + case adOpenUnspecified: + case adOpenForwardOnly: + nValue = ResultSetType::FORWARD_ONLY; + break; + case adOpenStatic: + case adOpenKeyset: + nValue = ResultSetType::SCROLL_INSENSITIVE; + break; + case adOpenDynamic: + nValue = ResultSetType::SCROLL_SENSITIVE; + break; + } + return nValue; +} +//------------------------------------------------------------------------------ +sal_Int32 OStatement_Base::getFetchDirection() const throw(SQLException, RuntimeException) +{ + return FetchDirection::FORWARD; +} +//------------------------------------------------------------------------------ +sal_Int32 OStatement_Base::getFetchSize() const throw(SQLException, RuntimeException) +{ + return m_nFetchSize; +} +//------------------------------------------------------------------------------ +sal_Int32 OStatement_Base::getMaxFieldSize() const throw(SQLException, RuntimeException) +{ + return 0; +} +//------------------------------------------------------------------------------ +::rtl::OUString OStatement_Base::getCursorName() const throw(SQLException, RuntimeException) +{ + return m_Command.GetName(); +} +//------------------------------------------------------------------------------ +void OStatement_Base::setQueryTimeOut(sal_Int32 seconds) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_Command.put_CommandTimeout(seconds); +} +//------------------------------------------------------------------------------ +void OStatement_Base::setMaxRows(sal_Int32 _par0) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_nMaxRows = _par0; +} +//------------------------------------------------------------------------------ +void OStatement_Base::setResultSetConcurrency(sal_Int32 _par0) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + switch(_par0) + { + case ResultSetConcurrency::READ_ONLY: + m_eLockType = adLockReadOnly; + break; + default: + m_eLockType = adLockOptimistic; + break; + } +} +//------------------------------------------------------------------------------ +void OStatement_Base::setResultSetType(sal_Int32 _par0) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + switch(_par0) + { + case ResultSetType::FORWARD_ONLY: + m_eCursorType = adOpenForwardOnly; + break; + case ResultSetType::SCROLL_INSENSITIVE: + m_eCursorType = adOpenKeyset; + break; + case ResultSetType::SCROLL_SENSITIVE: + m_eCursorType = adOpenDynamic; + break; + } +} +//------------------------------------------------------------------------------ +void OStatement_Base::setFetchDirection(sal_Int32 _par0) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); +} +//------------------------------------------------------------------------------ +void OStatement_Base::setFetchSize(sal_Int32 _par0) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_nFetchSize = _par0; + // m_RecordSet.put_CacheSize(_par0); +} +//------------------------------------------------------------------------------ +void OStatement_Base::setMaxFieldSize(sal_Int32 _par0) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + +} +//------------------------------------------------------------------------------ +void OStatement_Base::setCursorName(const ::rtl::OUString &_par0) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + m_Command.put_Name(_par0); +} + +// ------------------------------------------------------------------------- +::cppu::IPropertyArrayHelper* OStatement_Base::createArrayHelper( ) const +{ + Sequence< com::sun::star::beans::Property > aProps(10); + com::sun::star::beans::Property* pProperties = aProps.getArray(); + sal_Int32 nPos = 0; + DECL_PROP0(CURSORNAME, ::rtl::OUString); + DECL_BOOL_PROP0(ESCAPEPROCESSING); + DECL_PROP0(FETCHDIRECTION,sal_Int32); + DECL_PROP0(FETCHSIZE, sal_Int32); + DECL_PROP0(MAXFIELDSIZE,sal_Int32); + DECL_PROP0(MAXROWS, sal_Int32); + DECL_PROP0(QUERYTIMEOUT,sal_Int32); + DECL_PROP0(RESULTSETCONCURRENCY,sal_Int32); + DECL_PROP0(RESULTSETTYPE,sal_Int32); + DECL_BOOL_PROP0(USEBOOKMARKS); + + + return new ::cppu::OPropertyArrayHelper(aProps); +} + +// ------------------------------------------------------------------------- +::cppu::IPropertyArrayHelper & OStatement_Base::getInfoHelper() +{ + return *const_cast<OStatement_Base*>(this)->getArrayHelper(); +} +// ------------------------------------------------------------------------- +sal_Bool OStatement_Base::convertFastPropertyValue( + Any & rConvertedValue, + Any & rOldValue, + sal_Int32 nHandle, + const Any& rValue ) + throw (::com::sun::star::lang::IllegalArgumentException) +{ + switch(nHandle) + { + case PROPERTY_ID_QUERYTIMEOUT: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getQueryTimeOut()); + case PROPERTY_ID_MAXFIELDSIZE: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxFieldSize()); + case PROPERTY_ID_MAXROWS: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxRows()); + case PROPERTY_ID_CURSORNAME: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getCursorName()); + case PROPERTY_ID_RESULTSETCONCURRENCY: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetConcurrency()); + case PROPERTY_ID_RESULTSETTYPE: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetType()); + case PROPERTY_ID_FETCHDIRECTION: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection()); + case PROPERTY_ID_FETCHSIZE: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize()); + case PROPERTY_ID_ESCAPEPROCESSING: + // return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink); + case PROPERTY_ID_USEBOOKMARKS: + // return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink); + default: + ; + } + return sal_False; +} +// ------------------------------------------------------------------------- +void OStatement_Base::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception) +{ + switch(nHandle) + { + case PROPERTY_ID_QUERYTIMEOUT: + setQueryTimeOut(connectivity::getINT32(rValue)); + break; + case PROPERTY_ID_MAXFIELDSIZE: + setMaxFieldSize(connectivity::getINT32(rValue)); + break; + case PROPERTY_ID_MAXROWS: + setMaxRows(connectivity::getINT32(rValue)); + break; + case PROPERTY_ID_CURSORNAME: + setCursorName(connectivity::getString(rValue)); + break; + case PROPERTY_ID_RESULTSETCONCURRENCY: + setResultSetConcurrency(connectivity::getINT32(rValue)); + break; + case PROPERTY_ID_RESULTSETTYPE: + setResultSetType(connectivity::getINT32(rValue)); + break; + case PROPERTY_ID_FETCHDIRECTION: + setFetchDirection(connectivity::getINT32(rValue)); + break; + case PROPERTY_ID_FETCHSIZE: + setFetchSize(connectivity::getINT32(rValue)); + break; + case PROPERTY_ID_ESCAPEPROCESSING: + // return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink); + case PROPERTY_ID_USEBOOKMARKS: + // return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink); + default: + ; + } +} +// ------------------------------------------------------------------------- +void OStatement_Base::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const +{ + switch(nHandle) + { + case PROPERTY_ID_QUERYTIMEOUT: + rValue <<= getQueryTimeOut(); + break; + case PROPERTY_ID_MAXFIELDSIZE: + rValue <<= getMaxFieldSize(); + break; + case PROPERTY_ID_MAXROWS: + rValue <<= getMaxRows(); + break; + case PROPERTY_ID_CURSORNAME: + rValue <<= getCursorName(); + break; + case PROPERTY_ID_RESULTSETCONCURRENCY: + rValue <<= getResultSetConcurrency(); + break; + case PROPERTY_ID_RESULTSETTYPE: + rValue <<= getResultSetType(); + break; + case PROPERTY_ID_FETCHDIRECTION: + rValue <<= getFetchDirection(); + break; + case PROPERTY_ID_FETCHSIZE: + rValue <<= getFetchSize(); + break; + case PROPERTY_ID_ESCAPEPROCESSING: + case PROPERTY_ID_USEBOOKMARKS: + default: + ; + } +} +// ------------------------------------------------------------------------- +OStatement::~OStatement() +{ +} +IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbcx.AStatement","com.sun.star.sdbc.Statement"); + diff --git a/connectivity/source/drivers/ado/ATable.cxx b/connectivity/source/drivers/ado/ATable.cxx new file mode 100644 index 000000000000..7d106cfa5323 --- /dev/null +++ b/connectivity/source/drivers/ado/ATable.cxx @@ -0,0 +1,444 @@ +/************************************************************************* + * + * $RCSfile: ATable.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADO_TABLE_HXX_ +#include "ado/ATable.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_INDEXES_HXX_ +#include "ado/AIndexes.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_COLUMNS_HXX_ +#include "ado/AColumns.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_COLUMN_HXX_ +#include "ado/AColumn.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_KEYS_HXX_ +#include "ado/AKeys.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBCX_KEYTYPE_HPP_ +#include <com/sun/star/sdbcx/KeyType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_KEYRULE_HPP_ +#include <com/sun/star/sdbc/KeyRule.hpp> +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ +#include <com/sun/star/sdbc/ColumnValue.hpp> +#endif +#ifndef _CONNECTIVITY_ADO_AWRAPADO_HXX_ +#include "ado/Awrapado.hxx" +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +using namespace connectivity::ado; +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::container; +using namespace com::sun::star::lang; + +// ------------------------------------------------------------------------- +void WpADOTable::Create() +{ + IClassFactory2* pIUnknown = NULL; + IUnknown *pOuter = NULL; + HRESULT hr = -1; + _ADOTable* pCommand; + hr = CoCreateInstance(ADOS::CLSID_ADOTABLE_25, + NULL, + CLSCTX_INPROC_SERVER, + ADOS::IID_ADOTABLE_25, + (void**)&pCommand ); + + + if( !FAILED( hr ) ) + { + pInterface = pCommand; + pInterface->AddRef(); + } +} +// ------------------------------------------------------------------------- +OAdoTable::OAdoTable(sal_Bool _bCase,_ADOTable* _pTable) : OTable_TYPEDEF(_bCase) +{ + construct(); + if(_pTable) + m_aTable = WpADOTable(_pTable); + else + m_aTable.Create(); + + refreshColumns(); + refreshKeys(); + refreshIndexes(); +} +// ------------------------------------------------------------------------- +OAdoTable::OAdoTable(sal_Bool _bCase, const ::rtl::OUString& _Name, + const ::rtl::OUString& _Type, + const ::rtl::OUString& _Description , + const ::rtl::OUString& _SchemaName, + const ::rtl::OUString& _CatalogName + ) : OTable_TYPEDEF(_bCase,_Name, + _Type, + _Description, + _SchemaName, + _CatalogName) +{ + construct(); + m_aTable.Create(); + m_aTable.put_Name(_Name); + { + ADOProperties* pProps = m_aTable.get_Properties(); + pProps->AddRef(); + ADOProperty* pProp = NULL; + pProps->get_Item(OLEVariant(::rtl::OUString::createFromAscii("Type")),&pProp); + WpADOProperty aProp(pProp); + if(pProp) + aProp.PutValue(_Type); + pProps->Release(); + } + { + ADOProperties* pProps = m_aTable.get_Properties(); + pProps->AddRef(); + ADOProperty* pProp = NULL; + pProps->get_Item(OLEVariant(::rtl::OUString::createFromAscii("Description")),&pProp); + WpADOProperty aProp(pProp); + if(pProp) + aProp.PutValue(_Description); + pProps->Release(); + } + + + refreshColumns(); + refreshKeys(); + refreshIndexes(); +} +// ------------------------------------------------------------------------- +void OAdoTable::refreshColumns() +{ + ::std::vector< ::rtl::OUString> aVector; + + ADOColumns* pColumns = m_aTable.get_Columns(); + if(pColumns) + { + pColumns->Refresh(); + + sal_Int32 nCount = 0; + pColumns->get_Count(&nCount); + for(sal_Int32 i=0;i< nCount;++i) + { + ADOColumn* pColumn = NULL; + pColumns->get_Item(OLEVariant(i),&pColumn); + if(pColumn) + { + WpADOColumn aColumn(pColumn); + aVector.push_back(aColumn.get_Name()); + } + } + } + + m_pColumns = new OColumns(*this,m_aMutex,aVector,pColumns,isCaseSensitive()); +} +// ------------------------------------------------------------------------- +void OAdoTable::refreshKeys() +{ + ::std::vector< ::rtl::OUString> aVector; + + ADOKeys* pKeys = m_aTable.get_Keys(); + if(pKeys) + { + pKeys->Refresh(); + + sal_Int32 nCount = 0; + pKeys->get_Count(&nCount); + for(sal_Int32 i=0;i< nCount;++i) + { + ADOKey* pKey = NULL; + pKeys->get_Item(OLEVariant(i),&pKey); + if(pKey) + { + WpADOKey aKey(pKey); + aVector.push_back(aKey.get_Name()); + } + } + } + + m_pKeys = new OKeys(*this,m_aMutex,aVector,pKeys,isCaseSensitive()); +} +// ------------------------------------------------------------------------- +void OAdoTable::refreshIndexes() +{ + ::std::vector< ::rtl::OUString> aVector; + + ADOIndexes* pIndexes = m_aTable.get_Indexes(); + if(pIndexes) + { + pIndexes->Refresh(); + + sal_Int32 nCount = 0; + pIndexes->get_Count(&nCount); + for(sal_Int32 i=0;i< nCount;++i) + { + ADOIndex* pIndex = NULL; + pIndexes->get_Item(OLEVariant(i),&pIndex); + if(pIndex) + { + WpADOIndex aIndex(pIndex); + aVector.push_back(aIndex.get_Name()); + } + } + } + + m_pIndexes = new OIndexes(*this,m_aMutex,aVector,pIndexes,isCaseSensitive()); +} +// ------------------------------------------------------------------------- +Any SAL_CALL OAdoTable::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = ::cppu::queryInterface(rType,static_cast< ::com::sun::star::lang::XUnoTunnel*> (this)); + if(aRet.hasValue()) + return aRet; + return OTable_TYPEDEF::queryInterface(rType); +} + +// ------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OAdoTable::getTypes( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > *)0 )); + + return ::utl::concatSequences(aTypes.getTypes(),OTable_TYPEDEF::getTypes()); +} +//-------------------------------------------------------------------------- +Sequence< sal_Int8 > OAdoTable::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 OAdoTable::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException) +{ + if (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) + return (sal_Int64)this; + + return 0; +} +// ------------------------------------------------------------------------- +// XRename +void SAL_CALL OAdoTable::rename( const ::rtl::OUString& newName ) throw(SQLException, ElementExistException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_aMutex); + if (rBHelper.bDisposed) + throw DisposedException(); + + m_aTable.put_Name(newName); +} +// ------------------------------------------------------------------------- +// XAlterTable +void SAL_CALL OAdoTable::alterColumnByName( const ::rtl::OUString& colName, const Reference< XPropertySet >& descriptor ) throw(SQLException, NoSuchElementException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_aMutex); + if (rBHelper.bDisposed) + throw DisposedException(); + + Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(descriptor,UNO_QUERY); + if(xTunnel.is()) + { + OAdoColumn* pColumn = (OAdoColumn*)xTunnel->getSomething(OAdoColumn:: getUnoTunnelImplementationId()); + m_aTable.get_Columns()->Delete(OLEVariant(colName)); + m_aTable.get_Columns()->Append(OLEVariant(pColumn->getColumnImpl())); + } + + refreshColumns(); + +} +// ------------------------------------------------------------------------- +void SAL_CALL OAdoTable::alterColumnByIndex( sal_Int32 index, const Reference< XPropertySet >& descriptor ) throw(SQLException, ::com::sun::star::lang::IndexOutOfBoundsException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_aMutex); + if (rBHelper.bDisposed) + throw DisposedException(); + + Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(descriptor,UNO_QUERY); + if(xTunnel.is()) + { + OAdoColumn* pColumn = (OAdoColumn*)xTunnel->getSomething(OAdoColumn:: getUnoTunnelImplementationId()); + m_aTable.get_Columns()->Delete(OLEVariant(index)); + m_aTable.get_Columns()->Append(OLEVariant(pColumn->getColumnImpl())); + } +} +// ------------------------------------------------------------------------- +void OAdoTable::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)throw (Exception) +{ + if(m_aTable.IsValid()) + { + switch(nHandle) + { + case PROPERTY_ID_NAME: + m_aTable.put_Name(getString(rValue)); + break; + case PROPERTY_ID_TYPE: + { + ADOProperties* pProps = m_aTable.get_Properties(); + pProps->AddRef(); + ADOProperty* pProp = NULL; + pProps->get_Item(OLEVariant(::rtl::OUString::createFromAscii("Type")),&pProp); + WpADOProperty aProp(pProp); + if(pProp) + aProp.PutValue(getString(rValue)); + pProps->Release(); + } + break; + case PROPERTY_ID_DESCRIPTION: + { + ADOProperties* pProps = m_aTable.get_Properties(); + pProps->AddRef(); + ADOProperty* pProp = NULL; + pProps->get_Item(OLEVariant(::rtl::OUString::createFromAscii("Description")),&pProp); + WpADOProperty aProp(pProp); + if(pProp) + aProp.PutValue(getString(rValue)); + pProps->Release(); + } + break; + case PROPERTY_ID_SCHEMANAME: + break; + default: + throw Exception(); + } + } +} +// ------------------------------------------------------------------------- +void OAdoTable::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const +{ + if(m_aTable.IsValid()) + { + switch(nHandle) + { + case PROPERTY_ID_NAME: + rValue <<= m_aTable.get_Name(); + break; + case PROPERTY_ID_TYPE: + rValue <<= m_aTable.get_Type(); + break; + case PROPERTY_ID_CATALOGNAME: + { + WpADOCatalog aCat(m_aTable.get_ParentCatalog()); + if(aCat.IsValid()) + rValue <<= aCat.GetObjectOwner(m_aTable.get_Name(),adPermObjTable); + } + break; + case PROPERTY_ID_SCHEMANAME: + // rValue <<= m_aTable.get_Type(); + break; + case PROPERTY_ID_DESCRIPTION: + { + ADOProperties* pProps = m_aTable.get_Properties(); + pProps->AddRef(); + ADOProperty* pProp = NULL; + pProps->get_Item(OLEVariant(::rtl::OUString::createFromAscii("Description")),&pProp); + WpADOProperty aProp(pProp); + if(pProp) + rValue <<= (::rtl::OUString)aProp.GetValue(); + pProps->Release(); + } + break; + } + } +} +// ------------------------------------------------------------------------- +::rtl::OUString WpADOCatalog::GetObjectOwner(const ::rtl::OUString& _rName, ObjectTypeEnum _eNum) +{ + OLEVariant _rVar; + _rVar.setNoArg(); + BSTR aBSTR; + pInterface->GetObjectOwner(SysAllocString(_rName.getStr()),_eNum,_rVar,&aBSTR); + rtl::OUString sRetStr((sal_Unicode*)aBSTR); + SysFreeString(aBSTR); + return sRetStr; +} + + + diff --git a/connectivity/source/drivers/ado/ATables.cxx b/connectivity/source/drivers/ado/ATables.cxx new file mode 100644 index 000000000000..3dd247d3f731 --- /dev/null +++ b/connectivity/source/drivers/ado/ATables.cxx @@ -0,0 +1,158 @@ +/************************************************************************* + * + * $RCSfile: ATables.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADO_TABLES_HXX_ +#include "ado/ATables.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_TABLE_HXX_ +#include "ado/ATable.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ +#include <com/sun/star/sdbc/ColumnValue.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_KEYRULE_HPP_ +#include <com/sun/star/sdbc/KeyRule.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBCX_KEYTYPE_HPP_ +#include <com/sun/star/sdbcx/KeyType.hpp> +#endif +#ifndef _CONNECTIVITY_ADO_CATALOG_HXX_ +#include "ado/ACatalog.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_BCONNECTION_HXX_ +#include "ado/AConnection.hxx" +#endif + +using namespace connectivity::ado; +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::container; +using namespace com::sun::star::lang; + +typedef connectivity::sdbcx::OCollection OCollection_TYPE; + +Reference< XNamed > OTables::createObject(const ::rtl::OUString& _rName) +{ + ADOTable* pTable = NULL; + m_pCollection->get_Item(OLEVariant(_rName),&pTable); + + Reference< XNamed > xRet = new OAdoTable(isCaseSensitive(),pTable); + + return xRet; +} +// ------------------------------------------------------------------------- +void OTables::impl_refresh( ) throw(RuntimeException) +{ + m_pCollection->Refresh(); +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > OTables::createEmptyObject() +{ + OAdoTable* pNew = new OAdoTable(isCaseSensitive()); + return pNew; +} +// ------------------------------------------------------------------------- +// XAppend +void SAL_CALL OTables::appendByDescriptor( const Reference< XPropertySet >& descriptor ) throw(SQLException, ElementExistException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(descriptor,UNO_QUERY); + if(xTunnel.is()) + { + OAdoTable* pTable = (OAdoTable*)xTunnel->getSomething(OAdoTable:: getUnoTunnelImplementationId()); + m_pCollection->Append(OLEVariant(pTable->getImpl())); + } + + OCollection_TYPE::appendByDescriptor(descriptor); +} +// ------------------------------------------------------------------------- +// XDrop +void SAL_CALL OTables::dropByName( const ::rtl::OUString& elementName ) throw(SQLException, NoSuchElementException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + m_pCollection->Delete(OLEVariant(elementName)); + + OCollection_TYPE::dropByName(elementName); +} +// ------------------------------------------------------------------------- +void SAL_CALL OTables::dropByIndex( sal_Int32 index ) throw(SQLException, IndexOutOfBoundsException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + if (index < 0 || index >= getCount()) + throw IndexOutOfBoundsException(); + + m_pCollection->Delete(OLEVariant(index)); + + OCollection_TYPE::dropByIndex(index); +} +// ------------------------------------------------------------------------- + + diff --git a/connectivity/source/drivers/ado/AUser.cxx b/connectivity/source/drivers/ado/AUser.cxx new file mode 100644 index 000000000000..c15770cca86c --- /dev/null +++ b/connectivity/source/drivers/ado/AUser.cxx @@ -0,0 +1,248 @@ +/************************************************************************* + * + * $RCSfile: AUser.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADO_USER_HXX_ +#include "ado/AUser.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_GROUPS_HXX_ +#include "ado/AGroups.hxx" +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _CONNECTIVITY_ADO_BCONNECTION_HXX_ +#include "ado/AConnection.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif + +using namespace connectivity::ado; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::sdbc; + +// ------------------------------------------------------------------------- +void WpADOUser::Create() +{ + IClassFactory2* pIUnknown = NULL; + IUnknown *pOuter = NULL; + HRESULT hr = -1; + _ADOUser* pCommand; + hr = CoCreateInstance(ADOS::CLSID_ADOUSER_25, + NULL, + CLSCTX_INPROC_SERVER, + ADOS::IID_ADOUSER_25, + (void**)&pCommand ); + + + if( !FAILED( hr ) ) + { + pInterface = pCommand; + pInterface->AddRef(); + } +} +// ------------------------------------------------------------------------- +OAdoUser::OAdoUser(sal_Bool _bCase, ADOUser* _pUser) : OUser_TYPEDEF(_bCase) +{ + construct(); + + if(_pUser) + m_aUser = WpADOUser(_pUser); + else + m_aUser.Create(); + refreshGroups(); +} +// ------------------------------------------------------------------------- +OAdoUser::OAdoUser(sal_Bool _bCase, const ::rtl::OUString& _Name) : OUser_TYPEDEF(_Name,_bCase) +{ + construct(); + m_aUser.Create(); + m_aUser.put_Name(_Name); + refreshGroups(); +} +// ------------------------------------------------------------------------- +void OAdoUser::refreshGroups() +{ + + ::std::vector< ::rtl::OUString> aVector; + + ADOGroups* pGroups = m_aUser.get_Groups(); + if(pGroups) + { + pGroups->Refresh(); + + sal_Int32 nCount = 0; + pGroups->get_Count(&nCount); + for(sal_Int32 i=0;i< nCount;++i) + { + ADOGroup* pGroup = NULL; + pGroups->get_Item(OLEVariant(i),&pGroup); + if(pGroup) + { + WpADOGroup aGroup(pGroup); + aVector.push_back(aGroup.get_Name()); + } + } + } + + if(m_pGroups) + delete m_pGroups; + m_pGroups = new OGroups(*this,m_aMutex,aVector,pGroups,isCaseSensitive()); +} +// ------------------------------------------------------------------------- +Any SAL_CALL OAdoUser::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = ::cppu::queryInterface(rType,static_cast< ::com::sun::star::lang::XUnoTunnel*> (this)); + if(aRet.hasValue()) + return aRet; + return OUser_TYPEDEF::queryInterface(rType); +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OAdoUser::getTypes( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > *)0 )); + + return ::utl::concatSequences(aTypes.getTypes(),OUser_TYPEDEF::getTypes()); +} +//-------------------------------------------------------------------------- +Sequence< sal_Int8 > OAdoUser::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 OAdoUser::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException) +{ + if (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) + return (sal_Int64)this; + + return 0; +} + +// ------------------------------------------------------------------------- +void OAdoUser::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)throw (Exception) +{ + if(m_aUser.IsValid()) + { + + switch(nHandle) + { + case PROPERTY_ID_NAME: + { + ::rtl::OUString aVal; + rValue >>= aVal; + m_aUser.put_Name(aVal); + } + break; + } + } +} +// ------------------------------------------------------------------------- +void OAdoUser::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const +{ + if(m_aUser.IsValid()) + { + switch(nHandle) + { + case PROPERTY_ID_NAME: + rValue <<= m_aUser.get_Name(); + break; + } + } +} +// ------------------------------------------------------------------------- +OUserExtend::OUserExtend(sal_Bool _bCase, ADOUser* _pUser) : OAdoUser(_bCase,_pUser) +{ +} +// ------------------------------------------------------------------------- +OUserExtend::OUserExtend(sal_Bool _bCase, const ::rtl::OUString& _Name) : OAdoUser(_bCase,_Name) +{ +} +// ------------------------------------------------------------------------- +void OUserExtend::construct() +{ + OUser_TYPEDEF::construct(); + registerProperty(PROPERTY_PASSWORD, PROPERTY_ID_PASSWORD,0,&m_Password,::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); +} + + diff --git a/connectivity/source/drivers/ado/AUsers.cxx b/connectivity/source/drivers/ado/AUsers.cxx new file mode 100644 index 000000000000..29a2c9bf3f56 --- /dev/null +++ b/connectivity/source/drivers/ado/AUsers.cxx @@ -0,0 +1,144 @@ +/************************************************************************* + * + * $RCSfile: AUsers.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADO_USERS_HXX_ +#include "ado/AUsers.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_USER_HXX_ +#include "ado/AUser.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_TABLE_HXX_ +#include "ado/ATable.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _CONNECTIVITY_SDBCX_IREFRESHABLE_HXX_ +#include "connectivity/sdbcx/IRefreshable.hxx" +#endif + +using namespace connectivity::ado; +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::container; + +typedef connectivity::sdbcx::OCollection OCollection_TYPE; + +Reference< XNamed > OUsers::createObject(const ::rtl::OUString& _rName) +{ + OAdoUser* pRet = new OAdoUser(isCaseSensitive(),_rName); + Reference< XNamed > xRet = pRet; + return xRet; +} +// ------------------------------------------------------------------------- +void OUsers::impl_refresh() throw(RuntimeException) +{ + m_pCollection->Refresh(); +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > OUsers::createEmptyObject() +{ + OUserExtend* pNew = new OUserExtend(isCaseSensitive()); + return pNew; +} +// ------------------------------------------------------------------------- +// XAppend +void SAL_CALL OUsers::appendByDescriptor( const Reference< XPropertySet >& descriptor ) throw(SQLException, ElementExistException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(descriptor,UNO_QUERY); + if(xTunnel.is()) + { + OUserExtend* pUser = (OUserExtend*)xTunnel->getSomething(OUserExtend::getUnoTunnelImplementationId()); + if(pUser) + m_pCollection->Append(OLEVariant(pUser->getImpl()),(BSTR)pUser->getPassword().getStr()); + } + + OCollection_TYPE::appendByDescriptor(descriptor); +} +// ------------------------------------------------------------------------- +// XDrop +void SAL_CALL OUsers::dropByName( const ::rtl::OUString& elementName ) throw(SQLException, NoSuchElementException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + m_pCollection->Delete(OLEVariant(elementName)); + + OCollection_TYPE::dropByName(elementName); +} +// ------------------------------------------------------------------------- +void SAL_CALL OUsers::dropByIndex( sal_Int32 index ) throw(SQLException, IndexOutOfBoundsException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + if (index < 0 || index >= getCount()) + throw IndexOutOfBoundsException(); + + m_pCollection->Delete(OLEVariant(index)); + + OCollection_TYPE::dropByIndex(index); +} + diff --git a/connectivity/source/drivers/ado/AView.cxx b/connectivity/source/drivers/ado/AView.cxx new file mode 100644 index 000000000000..690eb3735e84 --- /dev/null +++ b/connectivity/source/drivers/ado/AView.cxx @@ -0,0 +1,222 @@ +/************************************************************************* + * + * $RCSfile: AView.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_ADO_VIEW_HXX_ +#include "ado/AView.hxx" +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_ADOIMP_HXX_ +#include "ado/adoimp.hxx" +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _CONNECTIVITY_ADO_AWRAPADO_HXX_ +#include "ado/Awrapado.hxx" +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif +// ------------------------------------------------------------------------- +using namespace connectivity::ado; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::sdbc; + +// IMPLEMENT_SERVICE_INFO(OAdoView,"com.sun.star.sdbcx.AView","com.sun.star.sdbcx.View"); +// ------------------------------------------------------------------------- +void WpADOView::Create() +{ + IClassFactory2* pIUnknown = NULL; + IUnknown *pOuter = NULL; + HRESULT hr = -1; + ADOView* pCommand; + hr = CoCreateInstance(ADOS::CLSID_ADOVIEW_25, + NULL, + CLSCTX_INPROC_SERVER, + ADOS::IID_ADOVIEW_25, + (void**)&pCommand ); + + + if( !FAILED( hr ) ) + { + pInterface = pCommand; + pInterface->AddRef(); + } +} + +// ------------------------------------------------------------------------- +OAdoView::OAdoView(sal_Bool _bCase,ADOView* _pView) : OView_ADO(_bCase) +{ + construct(); + + if(_pView) + m_aView = WpADOView(_pView); + else + m_aView.Create(); +} +// ------------------------------------------------------------------------- +OAdoView::OAdoView(sal_Bool _bCase, const ::rtl::OUString& _Name, + sal_Int32 _CheckOption, + const ::rtl::OUString& _Command, + const ::rtl::OUString& _SchemaName, + const ::rtl::OUString& _CatalogName) + : OView_ADO( _bCase, + _Name, + _CheckOption, + _Command, + _SchemaName, + _CatalogName) +{ + construct(); + m_aView.Create(); + WpADOCommand aCommand; + aCommand.Create(); + aCommand.put_Name(_Name); + aCommand.put_CommandText(_Command); + + m_aView.put_Command(OLEVariant((IDispatch*)aCommand)); + +} +// ------------------------------------------------------------------------- +Any SAL_CALL OAdoView::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = ::cppu::queryInterface(rType,static_cast< ::com::sun::star::lang::XUnoTunnel*> (this)); + if(aRet.hasValue()) + return aRet; + return OView_ADO::queryInterface(rType); +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OAdoView::getTypes( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > *)0 )); + + return ::utl::concatSequences(aTypes.getTypes(),OAdoView::getTypes()); +} +//-------------------------------------------------------------------------- +Sequence< sal_Int8 > OAdoView::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 OAdoView::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException) +{ + if (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) + return (sal_Int64)this; + + return 0; +} + +// ------------------------------------------------------------------------- +void OAdoView::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception) +{ + throw Exception(); +} +// ------------------------------------------------------------------------- +void OAdoView::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const +{ + if(m_aView.IsValid()) + { + switch(nHandle) + { + case PROPERTY_ID_NAME: + rValue <<= m_aView.get_Name(); + break; + case PROPERTY_ID_CATALOGNAME: + break; + case PROPERTY_ID_SCHEMANAME: + // rValue <<= m_aView.get_Type(); + break; + case PROPERTY_ID_COMMAND: + { + OLEVariant aVar; + m_aView.get_Command(aVar); + if(!aVar.isNull() && !aVar.isEmpty()) + { + ADOCommand* pCom = (ADOCommand*)aVar.getIDispatch(); + BSTR aBSTR; pCom->get_CommandText(&aBSTR); + ::rtl::OUString sRetStr(aBSTR); + SysFreeString(aBSTR); + rValue <<= sRetStr; + } + } + break; + } + } +} + diff --git a/connectivity/source/drivers/ado/AViews.cxx b/connectivity/source/drivers/ado/AViews.cxx new file mode 100644 index 000000000000..afabefabbfb5 --- /dev/null +++ b/connectivity/source/drivers/ado/AViews.cxx @@ -0,0 +1,158 @@ +/************************************************************************* + * + * $RCSfile: AViews.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_ADO_VIEWS_HXX_ +#include "ado/AViews.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_VIEW_HXX_ +#include "ado/AView.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ +#include <com/sun/star/sdbc/ColumnValue.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_KEYRULE_HPP_ +#include <com/sun/star/sdbc/KeyRule.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBCX_KEYTYPE_HPP_ +#include <com/sun/star/sdbcx/KeyType.hpp> +#endif +#ifndef _CONNECTIVITY_ADO_CATALOG_HXX_ +#include "ado/ACatalog.hxx" +#endif +#ifndef _CONNECTIVITY_ADO_BCONNECTION_HXX_ +#include "ado/AConnection.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +using namespace connectivity::ado; +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::container; + +typedef connectivity::sdbcx::OCollection OCollection_TYPE; + +Reference< XNamed > OViews::createObject(const ::rtl::OUString& _rName) +{ + ADOView* pView = NULL; + m_pCollection->get_Item(OLEVariant(_rName),&pView); + + Reference< XNamed > xRet = new OAdoView(isCaseSensitive(),pView); + + return xRet; +} +// ------------------------------------------------------------------------- +void OViews::impl_refresh( ) throw(RuntimeException) +{ + m_pCollection->Refresh(); +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > OViews::createEmptyObject() +{ + OAdoView* pNew = new OAdoView(isCaseSensitive()); + return pNew; +} +// ------------------------------------------------------------------------- +// XAppend +void SAL_CALL OViews::appendByDescriptor( const Reference< XPropertySet >& descriptor ) throw(SQLException, ElementExistException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(descriptor,UNO_QUERY); + if(xTunnel.is()) + { + OAdoView* pView = (OAdoView*)xTunnel->getSomething(OAdoView:: getUnoTunnelImplementationId()); + m_pCollection->Append((BSTR)getString(descriptor->getPropertyValue(PROPERTY_NAME)).getStr(),(IDispatch *)pView->getImpl()); + } + + OCollection_TYPE::appendByDescriptor(descriptor); +} +// ------------------------------------------------------------------------- +// XDrop +void SAL_CALL OViews::dropByName( const ::rtl::OUString& elementName ) throw(SQLException, NoSuchElementException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + m_pCollection->Delete(OLEVariant(elementName)); + + OCollection_TYPE::dropByName(elementName); +} +// ------------------------------------------------------------------------- +void SAL_CALL OViews::dropByIndex( sal_Int32 index ) throw(SQLException, IndexOutOfBoundsException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + if (index < 0 || index >= getCount()) + throw IndexOutOfBoundsException(); + + m_pCollection->Delete(OLEVariant(index)); + + OCollection_TYPE::dropByIndex(index); +} +// ------------------------------------------------------------------------- + + diff --git a/connectivity/source/drivers/ado/Aservices.cxx b/connectivity/source/drivers/ado/Aservices.cxx new file mode 100644 index 000000000000..b62d68b4c3d0 --- /dev/null +++ b/connectivity/source/drivers/ado/Aservices.cxx @@ -0,0 +1,212 @@ +/************************************************************************* + * + * $RCSfile: Aservices.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADO_ADRIVER_HXX_ +#include "ado/ADriver.hxx" +#endif +#ifndef _CPPUHELPER_FACTORY_HXX_ +#include <cppuhelper/factory.hxx> +#endif +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +using namespace connectivity::ado; +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 + ); + +//*************************************************************************************** +// +// 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_ENSHURE(xNewKey.is(), "ADO::component_writeInfo : could not create a registry key !"); + + for (sal_uInt32 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); + } + catch(...) + { + } + return xRet.is(); + } + + void* getProvider() const { return xRet.get(); } +}; + +//--------------------------------------------------------------------------------------- + +extern "C" void SAL_CALL component_getImplementationEnvironment( + const sal_Char **ppEnvTypeName, + uno_Environment **ppEnv + ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +//--------------------------------------------------------------------------------------- +extern "C" 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( + ODriver::getImplementationName_Static(), + ODriver::getSupportedServiceNames_Static(), xKey); + + return sal_True; + } + catch (::com::sun::star::registry::InvalidRegistryException& ) + { + OSL_ENSHURE(sal_False, "ODBC::component_writeInfo : could not create a registry key ! ## InvalidRegistryException !"); + } + + return sal_False; +} + +//--------------------------------------------------------------------------------------- +extern "C" 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( + ODriver::getImplementationName_Static(), + ODriver::getSupportedServiceNames_Static(), + ODriver_CreateInstance, ::cppu::createSingleFactory) + ; + + if(aReq.xRet.is()) + aReq.xRet->acquire(); + + pRet = aReq.getProvider(); + } + + return pRet; +}; + + diff --git a/connectivity/source/drivers/ado/ado.xml b/connectivity/source/drivers/ado/ado.xml new file mode 100644 index 000000000000..1e923b53493f --- /dev/null +++ b/connectivity/source/drivers/ado/ado.xml @@ -0,0 +1,70 @@ +<?xml version='1.0' encoding="UTF-8"?> +<!DOCTYPE COMPONENTDESCRIPTION PUBLIC "-//W3C//DTD HTML 3.2//EN" "componentdependencies.dtd"> +<COMPONENTDESCRIPTION> + +<Name> com.sun.star.sdbc.ADODriver </Name> + +<Description> + This is the implementation of the sdbc-ado bridge. +</Description> + +<ModuleName> ado </ModuleName> + +<LoaderName> com.sun.star.loader.SharedLibrary </LoaderName> + +<SupportedService> com.sun.star.sdbc.Driver </SupportedService> + +<ServiceDependency> ... </ServiceDependency> + +<ProjectBuildDependency> cppuhelper </ProjectBuildDependency> +<ProjectBuildDependency> cppu </ProjectBuildDependency> +<ProjectBuildDependency> sal </ProjectBuildDependency> +<ProjectBuildDependency> vos </ProjectBuildDependency> + +<RuntimeModuleDependency> cppuhelper </RuntimeModuleDependency> +<RuntimeModuleDependency> cppu1 </RuntimeModuleDependency> +<RuntimeModuleDependency> sal1 </RuntimeModuleDependency> +<RuntimeModuleDependency> vos </RuntimeModuleDependency> + +<Language> c++ </Language> + +<Status StatusValue="final"/> + +<Type> com.sun.star.util.XCancellable </Type> +<Type> com.sun.star.util.XNumberFormatter </Type> +<Type> com.sun.star.uno.TypeClass </Type> +<Type> com.sun.star.uno.XWeak </Type> +<Type> com.sun.star.uno.XAggregation </Type> +<Type> com.sun.star.beans.XPropertyState </Type> +<Type> com.sun.star.beans.XPropertySet </Type> +<Type> com.sun.star.beans.PropertyValue </Type> +<Type> com.sun.star.beans.XMultiPropertySet </Type> +<Type> com.sun.star.beans.XFastPropertySet </Type> +<Type> com.sun.star.lang.XTypeProvider </Type> +<Type> com.sun.star.lang.EventObject </Type> +<Type> com.sun.star.lang.XComponent </Type> +<Type> com.sun.star.lang.IllegalArgumentException </Type> +<Type> com.sun.star.lang.XMultiServiceFactory </Type> +<Type> com.sun.star.java.XJavaThreadRegister_11 </Type> +<Type> com.sun.star.java.XJavaVM </Type> +<Type> com.sun.star.sdbc.XConnection </Type> +<Type> com.sun.star.sdbc.XStatement </Type> +<Type> com.sun.star.sdbc.XResultSet </Type> +<Type> com.sun.star.sdbc.XResultSetMetaDataSupplier</Type> +<Type> com.sun.star.sdbc.XColumnLocate </Type> +<Type> com.sun.star.sdbc.XResultSetUpdate </Type> +<Type> com.sun.star.sdbc.XWarningsSupplier </Type> +<Type> com.sun.star.sdbc.XRowUpdate </Type> +<Type> com.sun.star.sdbc.XMultipleResults </Type> +<Type> com.sun.star.sdbc.XBatchExecution </Type> +<Type> com.sun.star.sdbc.XPreparedBatchExecution </Type> +<Type> com.sun.star.sdbc.XParameters </Type> +<Type> com.sun.star.sdbc.XOutParameters </Type> +<Type> com.sun.star.sdbc.DriverPropertyInfo </Type> +<Type> com.sun.star.sdbc.XRow </Type> +<Type> com.sun.star.sdb.XColumnUpdate </Type> +<Type> com.sun.star.sdb.XColumn </Type> + +</COMPONENTDESCRIPTION> + + diff --git a/connectivity/source/drivers/ado/adoimp.cxx b/connectivity/source/drivers/ado/adoimp.cxx new file mode 100644 index 000000000000..f86752150032 --- /dev/null +++ b/connectivity/source/drivers/ado/adoimp.cxx @@ -0,0 +1,229 @@ +/************************************************************************* + * + * $RCSfile: adoimp.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ADO_AWRAPADO_HXX_ +#include "ado/Awrapado.hxx" +#endif + +#ifndef _CONNECTIVITY_ADO_ADOIMP_HXX_ +#include "ado/adoimp.hxx" +#endif + +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif +#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif + +using namespace connectivity::ado; +using namespace com::sun::star::uno; +using namespace com::sun::star::sdbc; + + +#define MYADOID(l) {l, 0,0x10,0x80,0,0,0xAA,0,0x6D,0x2E,0xA4}; + +const CLSID ADOS::CLSID_ADOCONNECTION_21 = MYADOID(0x00000514); +const IID ADOS::IID_ADOCONNECTION_21 = MYADOID(0x00000550); + +const CLSID ADOS::CLSID_ADOCOMMAND_21 = MYADOID(0x00000507); +const IID ADOS::IID_ADOCOMMAND_21 = MYADOID(0x0000054E); + +const CLSID ADOS::CLSID_ADORECORDSET_21 = MYADOID(0x00000535); +const IID ADOS::IID_ADORECORDSET_21 = MYADOID(0x0000054F); + +const CLSID ADOS::CLSID_ADOCATALOG_25 = MYADOID(0x00000602); +const IID ADOS::IID_ADOCATALOG_25 = MYADOID(0x00000603); + +const CLSID ADOS::CLSID_ADOINDEX_25 = MYADOID(0x0000061E); +const IID ADOS::IID_ADOINDEX_25 = MYADOID(0x0000061F); + +const CLSID ADOS::CLSID_ADOTABLE_25 = MYADOID(0x00000609); +const IID ADOS::IID_ADOTABLE_25 = MYADOID(0x00000610); + +const CLSID ADOS::CLSID_ADOKEY_25 = MYADOID(0x00000621); +const IID ADOS::IID_ADOKEY_25 = MYADOID(0x00000622); + +const CLSID ADOS::CLSID_ADOCOLUMN_25 = MYADOID(0x0000061B); +const IID ADOS::IID_ADOCOLUMN_25 = MYADOID(0x0000061C); + +const CLSID ADOS::CLSID_ADOGROUP_25 = MYADOID(0x00000615); +const IID ADOS::IID_ADOGROUP_25 = MYADOID(0x00000616); + +const CLSID ADOS::CLSID_ADOUSER_25 = MYADOID(0x00000618); +const IID ADOS::IID_ADOUSER_25 = MYADOID(0x00000619); + +const CLSID ADOS::CLSID_ADOVIEW_25 = MYADOID(0x00000612); +const IID ADOS::IID_ADOVIEW_25 = MYADOID(0x00000613); + +void ADOS::ThrowException(ADOConnection* _pAdoCon,const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException) +{ + ADOErrors *pErrors = NULL; + _pAdoCon->get_Errors(&pErrors); + if(!pErrors) + return; // no error found + + pErrors->AddRef( ); + + // alle aufgelaufenen Fehler auslesen und ausgeben + sal_Int32 nLen; + pErrors->get_Count(&nLen); + if (nLen) + { + ::rtl::OUString sError; + ::rtl::OUString aSQLState; + SQLException aException; + for (sal_Int32 i = nLen-1; i>=0; i--) + { + ADOError *pError = NULL; + pErrors->get_Item(OLEVariant(i),&pError); + WpADOError aErr(pError); + OSL_ENSHURE(pError,"No error in collection found! BAD!"); + if(pError) + { + if(i==nLen-1) + aException = SQLException(aErr.GetDescription(),_xInterface,aErr.GetSQLState(),aErr.GetNumber(),Any()); + else + { + SQLException aTemp = SQLException(aErr.GetDescription(), + _xInterface,aErr.GetSQLState(),aErr.GetNumber(),makeAny(aException)); + aTemp.NextException <<= aException; + aException = aTemp; + } + } + } + pErrors->Release(); + throw aException; + } + pErrors->Release(); +} + +// ------------------------------------------------------------------------- +sal_Int32 ADOS::MapADOType2Jdbc(DataTypeEnum eType) +{ + switch (eType) + { + case adUnsignedSmallInt: + case adSmallInt: return DataType::SMALLINT; break; + case adUnsignedInt: + case adInteger: return DataType::INTEGER; break; + case adUnsignedBigInt: + case adBigInt: return DataType::BIGINT; break; + case adSingle: return DataType::FLOAT; break; + case adDouble: return DataType::DOUBLE; break; + case adCurrency: return DataType::DOUBLE; break; + case adVarNumeric: + case adNumeric: return DataType::NUMERIC; break; + case adDecimal: return DataType::DECIMAL; break; + case adDate: + case adDBDate: return DataType::DATE; break; + case adDBTime: return DataType::TIME; break; + case adDBTimeStamp: return DataType::TIMESTAMP; break; + case adBoolean: return DataType::BIT; break; + case adBinary: + case adGUID: return DataType::BINARY; break; + case adBSTR: + case adVarWChar: + case adVarChar: return DataType::VARCHAR; break; + case adLongVarWChar: + case adLongVarChar: return DataType::LONGVARCHAR; break; + case adVarBinary: return DataType::VARBINARY; break; + case adLongVarBinary: return DataType::LONGVARBINARY; break; + case adWChar: + case adChar: return DataType::CHAR; break; + case adUnsignedTinyInt: + case adTinyInt: return DataType::TINYINT; break; + default: + ; + } + return DataType::TINYINT; +} +// ------------------------------------------------------------------------- +DataTypeEnum ADOS::MapJdbc2ADOType(sal_Int32 _nType) +{ + switch (_nType) + { + case DataType::SMALLINT: return adSmallInt; break; + case DataType::INTEGER: return adInteger; break; + case DataType::BIGINT: return adBigInt; break; + case DataType::FLOAT: return adSingle; break; + case DataType::DOUBLE: return adDouble; break; + case DataType::NUMERIC: return adNumeric; break; + case DataType::DECIMAL: return adDecimal; break; + case DataType::DATE: return adDBDate; break; + case DataType::TIME: return adDBTime; break; + case DataType::TIMESTAMP: return adDBTimeStamp; break; + case DataType::BIT: return adBoolean; break; + case DataType::BINARY: return adBinary; break; + case DataType::VARCHAR: return adVarWChar; break; + case DataType::LONGVARCHAR: return adLongVarWChar; break; + case DataType::VARBINARY: return adVarBinary; break; + case DataType::LONGVARBINARY: return adLongVarBinary; break; + case DataType::CHAR: return adWChar; break; + case DataType::TINYINT: return adTinyInt; break; + default: + ; + } + return adEmpty; +} + + + diff --git a/connectivity/source/drivers/ado/exports.dxp b/connectivity/source/drivers/ado/exports.dxp new file mode 100644 index 000000000000..9630d7e06768 --- /dev/null +++ b/connectivity/source/drivers/ado/exports.dxp @@ -0,0 +1,3 @@ +component_getImplementationEnvironment +component_writeInfo +component_getFactory diff --git a/connectivity/source/drivers/ado/makefile.mk b/connectivity/source/drivers/ado/makefile.mk new file mode 100644 index 000000000000..649e0c507b40 --- /dev/null +++ b/connectivity/source/drivers/ado/makefile.mk @@ -0,0 +1,226 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* +.IF "$(GUI)"=="WNT" + +PRJ=..$/..$/.. +PRJINC=..$/.. +PRJNAME=connectivity +TARGET=ado + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ---------------------------------- +.IF "$(DBGUTIL_OJ)"!="" +ENVCFLAGS+=/FR$(SLO)$/ +.ENDIF + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/version.mk + +# --- Types ------------------------------------- + + +UNOUCRDEP=$(SOLARBINDIR)$/applicat.rdb +UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb + +UNOUCROUT=$(OUT)$/inc +INCPRE+=$(UNOUCROUT) + +# --- Types ------------------------------------- + +UNOTYPES+= \ + com.sun.star.util.XCancellable \ + com.sun.star.util.XNumberFormatter \ + com.sun.star.uno.TypeClass \ + com.sun.star.uno.XWeak \ + com.sun.star.uno.XAggregation \ + com.sun.star.beans.XPropertyState \ + com.sun.star.beans.XPropertySet \ + com.sun.star.beans.PropertyValue \ + com.sun.star.beans.XMultiPropertySet \ + com.sun.star.beans.XFastPropertySet \ + com.sun.star.container.XIndexAccess \ + com.sun.star.lang.XTypeProvider \ + com.sun.star.lang.EventObject \ + com.sun.star.lang.XComponent \ + com.sun.star.lang.IllegalArgumentException \ + com.sun.star.lang.DisposedException \ + com.sun.star.lang.XMultiServiceFactory \ + com.sun.star.lang.XSingleServiceFactory \ + com.sun.star.registry.XRegistryKey \ + com.sun.star.java.XJavaThreadRegister_11 \ + com.sun.star.java.XJavaVM \ + com.sun.star.sdbc.XConnection \ + com.sun.star.sdbc.XStatement \ + com.sun.star.sdbc.XResultSet \ + com.sun.star.sdbc.XResultSetMetaDataSupplier \ + com.sun.star.sdbc.XColumnLocate \ + com.sun.star.sdbc.XResultSetUpdate \ + com.sun.star.sdbc.XWarningsSupplier \ + com.sun.star.sdbc.XRowUpdate \ + com.sun.star.sdbc.XMultipleResults \ + com.sun.star.sdbc.XBatchExecution \ + com.sun.star.sdbc.XPreparedBatchExecution \ + com.sun.star.sdbc.XParameters \ + com.sun.star.sdbc.XOutParameters \ + com.sun.star.sdbc.DriverPropertyInfo \ + com.sun.star.sdbc.XDriver \ + com.sun.star.sdbc.XRow \ + com.sun.star.sdbc.SQLWarning \ + com.sun.star.sdbc.ColumnSearch \ + com.sun.star.sdbc.DataType \ + com.sun.star.sdbc.ResultSetConcurrency \ + com.sun.star.sdbc.ResultSetType \ + com.sun.star.sdbc.ColumnValue \ + com.sun.star.sdbc.TransactionIsolation \ + com.sun.star.sdbc.FetchDirection \ + com.sun.star.sdbc.KeyRule \ + com.sun.star.sdbc.IndexType \ + com.sun.star.sdbc.ProcedureResult \ + com.sun.star.sdb.XColumnUpdate \ + com.sun.star.sdb.XColumn \ + com.sun.star.sdbcx.XDataDescriptorFactory \ + com.sun.star.sdbcx.XColumnsSupplier \ + com.sun.star.sdbcx.XIndexesSupplier \ + com.sun.star.sdbcx.XKeysSupplier \ + com.sun.star.sdbcx.XRename \ + com.sun.star.sdbcx.XAlterTable \ + com.sun.star.sdbcx.XDataDefinitionSupplier \ + com.sun.star.sdbcx.XViewsSupplier \ + com.sun.star.sdbcx.XUsersSupplier \ + com.sun.star.sdbcx.XGroupsSupplier \ + com.sun.star.sdbcx.XAuthorizable \ + com.sun.star.sdbcx.Privilege \ + com.sun.star.sdbcx.PrivilegeObject \ + com.sun.star.sdbcx.XUser \ + com.sun.star.sdbcx.XRowLocate \ + com.sun.star.sdbcx.XDeleteRows \ + com.sun.star.lang.XServiceInfo + + + +# --- Files ------------------------------------- + +SLOFILES=\ + $(SLO)$/AColumn.obj \ + $(SLO)$/AColumns.obj \ + $(SLO)$/AIndex.obj \ + $(SLO)$/AIndexes.obj \ + $(SLO)$/AKey.obj \ + $(SLO)$/AKeys.obj \ + $(SLO)$/AUser.obj \ + $(SLO)$/AUsers.obj \ + $(SLO)$/AGroup.obj \ + $(SLO)$/AGroups.obj \ + $(SLO)$/ACatalog.obj \ + $(SLO)$/AView.obj \ + $(SLO)$/AViews.obj \ + $(SLO)$/ATable.obj \ + $(SLO)$/ATables.obj \ + $(SLO)$/ACallableStatement.obj \ + $(SLO)$/ADatabaseMetaDataResultSetMetaData.obj \ + $(SLO)$/ADatabaseMetaDataResultSet.obj \ + $(SLO)$/AResultSet.obj \ + $(SLO)$/AConnection.obj \ + $(SLO)$/ADatabaseMetaData.obj \ + $(SLO)$/AStatement.obj \ + $(SLO)$/APreparedStatement.obj \ + $(SLO)$/AResultSetMetaData.obj \ + $(SLO)$/ADriver.obj \ + $(SLO)$/Aservices.obj \ + $(SLO)$/adoimp.obj + + +# --- Library ----------------------------------- + +SHL1TARGET= $(ADO_TARGET)$(ADO_MAJOR) +SHL1OBJS=$(SLOFILES) +SHL1STDLIBS=\ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(VOSLIB) \ + $(OSLLIB) \ + $(SALLIB) \ + ole32.lib \ + oleaut32.lib \ + uuid.lib + +SHL1DEPN= +SHL1IMPLIB= i$(SHL1TARGET) +SHL1LIBS= $(SLB)$/$(TARGET).lib \ + $(SLB)$/commontools.lib \ + $(SLB)$/resource.lib \ + $(SLB)$/sdbcx.lib + + +SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME= $(SHL1TARGET) +DEF1EXPORTFILE= exports.dxp + + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + +.ENDIF + diff --git a/connectivity/source/drivers/dbase/DCatalog.cxx b/connectivity/source/drivers/dbase/DCatalog.cxx new file mode 100644 index 000000000000..ece2f98db7d2 --- /dev/null +++ b/connectivity/source/drivers/dbase/DCatalog.cxx @@ -0,0 +1,115 @@ +/************************************************************************* + * + * $RCSfile: DCatalog.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#ifndef _CONNECTIVITY_DBASE_CATALOG_HXX_ +#include "dbase/DCatalog.hxx" +#endif + +#ifndef _CONNECTIVITY_DBASE_DCONNECTION_HXX_ +#include "dbase/DConnection.hxx" +#endif +#ifndef _CONNECTIVITY_DBASE_TABLES_HXX_ +#include "dbase/DTables.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif + +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::dbase; +// ------------------------------------------------------------------------- +ODbaseCatalog::ODbaseCatalog(ODbaseConnection* _pCon) : file::OFileCatalog(_pCon) +{ + osl_incrementInterlockedCount( &m_refCount ); + refreshTables(); + osl_decrementInterlockedCount( &m_refCount ); +} +// ------------------------------------------------------------------------- +void ODbaseCatalog::refreshTables() +{ + ::std::vector< ::rtl::OUString> aVector; + Sequence< ::rtl::OUString > aTypes(1); + aTypes[0] = ::rtl::OUString::createFromAscii("%"); + 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) + delete m_pTables; + m_pTables = new ODbaseTables(m_xMetaData,*this,m_aMutex,aVector); +} + + diff --git a/connectivity/source/drivers/dbase/DColumns.cxx b/connectivity/source/drivers/dbase/DColumns.cxx new file mode 100644 index 000000000000..d375e517f602 --- /dev/null +++ b/connectivity/source/drivers/dbase/DColumns.cxx @@ -0,0 +1,105 @@ +/************************************************************************* + * + * $RCSfile: DColumns.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_DBASE_COLUMNS_HXX_ +#include "dbase/DColumns.hxx" +#endif +#ifndef _CONNECTIVITY_DBASE_TABLE_HXX_ +#include "dbase/DTable.hxx" +#endif +#ifndef _CONNECTIVITY_SDBCX_COLUMN_HXX_ +#include "connectivity/sdbcx/VColumn.hxx" +#endif + +using namespace connectivity::dbase; +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; + + +Reference< XNamed > ODbaseColumns::createObject(const ::rtl::OUString& _rName) +{ + + ODbaseTable* pTable = (ODbaseTable*)m_pTable; + + // Reference< XFastPropertySet> xCol(pTable->getColumns()[_rName],UNO_QUERY); + ::vos::ORef<OSQLColumns> aCols = pTable->getTableColumns(); + + Reference< XNamed > xRet(*find(aCols->begin(),aCols->end(),_rName,::utl::UStringMixEqual(isCaseSensitive())),UNO_QUERY); + return xRet; +} + +// ------------------------------------------------------------------------- +void ODbaseColumns::impl_refresh() throw(RuntimeException) +{ + m_pTable->refreshColumns(); +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > ODbaseColumns::createEmptyObject() +{ + sdbcx::OColumn* pRet = new sdbcx::OColumn(isCaseSensitive()); + Reference< XPropertySet > xRet = pRet; + return xRet; +} + diff --git a/connectivity/source/drivers/dbase/DConnection.cxx b/connectivity/source/drivers/dbase/DConnection.cxx new file mode 100644 index 000000000000..7756d01f637e --- /dev/null +++ b/connectivity/source/drivers/dbase/DConnection.cxx @@ -0,0 +1,141 @@ +/************************************************************************* + * + * $RCSfile: DConnection.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_DBASE_OCONNECTION_HXX_ +#include "dbase/DConnection.hxx" +#endif +#ifndef _CONNECTIVITY_DBASE_ODATABASEMETADATA_HXX_ +#include "dbase/DDatabaseMetaData.hxx" +#endif +#ifndef _CONNECTIVITY_DBASE_CATALOG_HXX_ +#include "dbase/DCatalog.hxx" +#endif +#ifndef _CONNECTIVITY_RESOURCE_HRC_ +#include "Resource.hrc" +#endif +#ifndef _CONNECTIVITY_MODULECONTEXT_HXX_ +#include "ModuleContext.hxx" +#endif +#ifndef _CONNECTIVITY_DBASE_ODRIVER_HXX_ +#include "dbase/DDriver.hxx" +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif +#ifndef _URLOBJ_HXX //autogen wg. INetURLObject +#include <tools/urlobj.hxx> +#endif +//#ifndef _FSYS_HXX //autogen +//#include <tools/fsys.hxx> +//#endif + +using namespace connectivity::dbase; +using namespace connectivity::file; + +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; + +// -------------------------------------------------------------------------------- +ODbaseConnection::ODbaseConnection(ODriver* _pDriver) : OConnection(_pDriver) +{ + m_aFilenameExtension = String::CreateFromAscii("dbf"); +} +//----------------------------------------------------------------------------- +ODbaseConnection::~ODbaseConnection() +{ +} + +// XServiceInfo +// -------------------------------------------------------------------------------- +IMPLEMENT_SERVICE_INFO(ODbaseConnection, "com.sun.star.sdbc.drivers.dbase.Connection", "com.sun.star.sdbc.Connection") + +// -------------------------------------------------------------------------------- +Reference< XDatabaseMetaData > SAL_CALL ODbaseConnection::getMetaData( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_B::rBHelper.bDisposed) + throw DisposedException(); + + if(!m_xMetaData.is()) + m_xMetaData = new ODbaseDatabaseMetaData(this); + + return m_xMetaData; +} +//------------------------------------------------------------------------------ +::com::sun::star::uno::Reference< XTablesSupplier > ODbaseConnection::createCatalog() +{ + ::osl::MutexGuard aGuard( m_aMutex ); + Reference< XTablesSupplier > xTab = m_xCatalog; + if(!m_xCatalog.get().is()) + { + ODbaseCatalog *pCat = new ODbaseCatalog(this); + xTab = pCat; + m_xCatalog = xTab; + } + return xTab; +} + diff --git a/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx b/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx new file mode 100644 index 000000000000..40a12d9e234d --- /dev/null +++ b/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx @@ -0,0 +1,457 @@ +/************************************************************************* + * + * $RCSfile: DDatabaseMetaData.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_DBASE_ODATABASEMETADATA_HXX_ +#include "dbase/DDatabaseMetaData.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_RESULTSETTYPE_HPP_ +#include <com/sun/star/sdbc/ResultSetType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ +#include <com/sun/star/sdbc/ColumnValue.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XFASTPROPERTYSET_HPP_ +#include <com/sun/star/beans/XFastPropertySet.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_RESULTSETCONCURRENCY_HPP_ +#include <com/sun/star/sdbc/ResultSetConcurrency.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_ +#include <com/sun/star/sdbcx/XColumnsSupplier.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBCX_XINDEXESSUPPLIER_HPP_ +#include <com/sun/star/sdbcx/XIndexesSupplier.hpp> +#endif +#ifndef _URLOBJ_HXX //autogen wg. INetURLObject +#include <tools/urlobj.hxx> +#endif +//#ifndef _FSYS_HXX //autogen +//#include <tools/fsys.hxx> +//#endif +#ifndef _CONNECTIVITY_FILE_ADATABASEMETADATARESULTSET_HXX_ +#include "file/FDatabaseMetaDataResultSet.hxx" +#endif +#ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_ +#include <com/sun/star/lang/XUnoTunnel.hpp> +#endif +#ifndef _CONNECTIVITY_DBASE_INDEX_HXX_ +#include "dbase/DIndex.hxx" +#endif + +using namespace connectivity::dbase; +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::container; + + + +ODbaseDatabaseMetaData::ODbaseDatabaseMetaData(OConnection* _pCon) :ODatabaseMetaData(_pCon) +{ +} +// ------------------------------------------------------------------------- +ODbaseDatabaseMetaData::~ODbaseDatabaseMetaData() +{ +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getTypeInfo( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(); + Reference< XResultSet > xRef = pResult; + pResult->setTypeInfoMap(); + ORows aRows; + ORow aRow; + + aRow.push_back(Any()); + aRow.push_back(makeAny(::rtl::OUString::createFromAscii("CHAR"))); + aRow.push_back(makeAny(DataType::CHAR)); + aRow.push_back(makeAny((sal_Int32)254)); + aRow.push_back(makeAny(::rtl::OUString::createFromAscii("'"))); + aRow.push_back(makeAny(::rtl::OUString::createFromAscii("'"))); + aRow.push_back(Any()); + aRow.push_back(makeAny((sal_Int32)ColumnValue::NULLABLE)); + aRow.push_back(makeAny((sal_Int32)1)); + aRow.push_back(makeAny((sal_Int32)ColumnSearch::CHAR)); + aRow.push_back(makeAny((sal_Int32)1)); + aRow.push_back(makeAny((sal_Int32)0)); + aRow.push_back(makeAny((sal_Int32)0)); + aRow.push_back(Any()); + aRow.push_back(makeAny((sal_Int32)0)); + aRow.push_back(makeAny((sal_Int32)0)); + aRow.push_back(Any()); + aRow.push_back(Any()); + aRow.push_back(makeAny((sal_Int32)10)); + aRows.push_back(aRow); + + aRow[1] = makeAny(::rtl::OUString::createFromAscii("VARCHAR")); + aRow[2] = makeAny(DataType::VARCHAR); + aRow[4] = makeAny(::rtl::OUString::createFromAscii("'")); + aRow[5] = makeAny(::rtl::OUString::createFromAscii("'")); + aRows.push_back(aRow); + + + aRow[1] = makeAny(::rtl::OUString::createFromAscii("LONGVARCHAR")); + aRow[2] = makeAny(DataType::LONGVARCHAR); + aRow[3] = makeAny((sal_Int32)65535); + aRow[4] = makeAny(::rtl::OUString::createFromAscii("'")); + aRow[5] = makeAny(::rtl::OUString::createFromAscii("'")); + aRows.push_back(aRow); + + aRow[1] = makeAny(::rtl::OUString::createFromAscii("BOOL")); + aRow[2] = makeAny(DataType::BIT); + aRow[3] = makeAny((sal_Int32)1); + aRow[9] = makeAny((sal_Int32)ColumnSearch::BASIC); + aRows.push_back(aRow); + + aRow[1] = makeAny(::rtl::OUString::createFromAscii("DATE")); + aRow[2] = makeAny(DataType::DATE); + aRow[3] = makeAny((sal_Int32)10); + aRow[4] = makeAny(::rtl::OUString::createFromAscii("'")); + aRow[5] = makeAny(::rtl::OUString::createFromAscii("'")); + aRows.push_back(aRow); + + aRow[1] = makeAny(::rtl::OUString::createFromAscii("DECIMAL")); + aRow[2] = makeAny(DataType::DECIMAL); + aRow[3] = makeAny((sal_Int32)20); + aRow[15] = makeAny((sal_Int32)15); + aRows.push_back(aRow); + + aRow[1] = makeAny(::rtl::OUString::createFromAscii("NUMERIC")); + aRow[2] = makeAny(DataType::NUMERIC); + aRow[3] = makeAny((sal_Int32)20); + aRow[15] = makeAny((sal_Int32)20); + aRows.push_back(aRow); + + pResult->setRows(aRows); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getColumnPrivileges( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, + const ::rtl::OUString& columnNamePattern ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(); + Reference< XResultSet > xRef = pResult; + pResult->setColumnPrivilegesMap(); + return xRef; +} + +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getColumns( + const Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& tableNamePattern, + const ::rtl::OUString& columnNamePattern ) throw(SQLException, RuntimeException) +{ + ::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(); + + ORows aRows; + ORow aRow(19); + aRow[10] <<= (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; + xNames->getByName(*pTabBegin) >>= xTable; + aRow[3] <<= *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< XFastPropertySet> xColumn; + for(sal_Int32 i=1;pBegin != pEnd;++pBegin,++i) + { + if(match(columnNamePattern,*pBegin,'\0')) + { + aRow[4] <<= *pBegin; + + xColumns->getByName(*pBegin) >>= xColumn; + OSL_ENSHURE(xColumn.is(),"Columns contains a column who isn't a fastpropertyset!"); + aRow[5] = xColumn->getFastPropertyValue(PROPERTY_ID_TYPE); + aRow[6] = xColumn->getFastPropertyValue(PROPERTY_ID_TYPENAME); + aRow[7] = xColumn->getFastPropertyValue(PROPERTY_ID_PRECISION); + // aRow[8] = xColumn->getFastPropertyValue(PROPERTY_ID_TYPENAME); + aRow[9] = xColumn->getFastPropertyValue(PROPERTY_ID_SCALE); + aRow[11] = xColumn->getFastPropertyValue(PROPERTY_ID_ISNULLABLE); + // aRow[12] = xColumn->getFastPropertyValue(PROPERTY_ID_TYPENAME); + aRow[13] = xColumn->getFastPropertyValue(PROPERTY_ID_DEFAULTVALUE); + // aRow[14] = xColumn->getFastPropertyValue(PROPERTY_ID_TYPENAME); + // aRow[15] = xColumn->getFastPropertyValue(PROPERTY_ID_TYPENAME); + switch(getINT32(aRow[5])) + { + case DataType::CHAR: + case DataType::VARCHAR: + aRow[16] <<= (sal_Int32)254; + break; + case DataType::LONGVARCHAR: + aRow[16] <<= (sal_Int32)65535; + break; + default: + aRow[16] <<= (sal_Int32)0; + } + aRow[17] <<= i; + switch(getINT32(aRow[11])) + { + case ColumnValue::NO_NULLS: + aRow[18] <<= ::rtl::OUString::createFromAscii("NO"); + break; + case ColumnValue::NULLABLE: + aRow[18] <<= ::rtl::OUString::createFromAscii("YES"); + break; + default: + aRow[18] <<= ::rtl::OUString(); + } + aRows.push_back(aRow); + } + } + } + } + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(); + Reference< XResultSet > xRef = pResult; + pResult->setColumnsMap(); + pResult->setRows(aRows); + + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getVersionColumns( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(); + Reference< XResultSet > xRef = pResult; + pResult->setVersionColumnsMap(); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getExportedKeys( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(); + Reference< XResultSet > xRef = pResult; + pResult->setExportedKeysMap(); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getImportedKeys( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(); + Reference< XResultSet > xRef = pResult; + pResult->setImportedKeysMap(); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getPrimaryKeys( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(); + Reference< XResultSet > xRef = pResult; + pResult->setPrimaryKeysMap(); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getIndexInfo( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, + sal_Bool unique, sal_Bool approximate ) throw(SQLException, RuntimeException) +{ + ::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(); + + ORows aRows; + ORow aRow(14); + aRow[5] <<= ::rtl::OUString(); + aRow[10] <<= ::rtl::OUString::createFromAscii("A"); + + Reference< XIndexesSupplier> xTable; + xNames->getByName(table) >>= xTable; + aRow[3] <<= table; + aRow[7] <<= (sal_Int32)3; + + Reference< XNameAccess> xIndexes = xTable->getIndexes(); + if(!xIndexes.is()) + throw SQLException(); + + Sequence< ::rtl::OUString> aIdxNames(xIndexes->getElementNames()); + + const ::rtl::OUString* pBegin = aIdxNames.getConstArray(); + const ::rtl::OUString* pEnd = pBegin + aIdxNames.getLength(); + Reference< XFastPropertySet> xIndex; + for(;pBegin != pEnd;++pBegin) + { + xIndexes->getByName(*pBegin) >>= xIndex; + OSL_ENSHURE(xIndex.is(),"Indexes contains a column who isn't a fastpropertyset!"); + + if(unique && !getBOOL(xIndex->getFastPropertyValue(PROPERTY_ID_ISUNIQUE))) + continue; + aRow[4] = xIndex->getFastPropertyValue(PROPERTY_ID_ISUNIQUE); + aRow[6] <<= *pBegin; + + Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(xIndex,UNO_QUERY); + if(xTunnel.is()) + { + ODbaseIndex* pIndex = (ODbaseIndex*)xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()); + if(pIndex) + { + aRow[11] <<= pIndex->getHeader().db_maxkeys; + aRow[12] <<= pIndex->getHeader().db_pagecount; + } + } + + Reference<XColumnsSupplier> xColumnsSup(xIndex,UNO_QUERY); + Reference< XNameAccess> xColumns = xColumnsSup->getColumns(); + Sequence< ::rtl::OUString> aColNames(xColumns->getElementNames()); + + const ::rtl::OUString* pColBegin = aColNames.getConstArray(); + const ::rtl::OUString* pColEnd = pColBegin + aColNames.getLength(); + Reference< XFastPropertySet> xColumn; + for(sal_Int32 j=1;pColBegin != pColEnd;++pColBegin,++j) + { + xColumns->getByName(*pColBegin) >>= xColumn; + aRow[8] <<= j; + aRow[9] <<= *pColBegin; + aRows.push_back(aRow); + } + } + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(); + Reference< XResultSet > xRef = pResult; + pResult->setIndexInfoMap(); + pResult->setRows(aRows); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getBestRowIdentifier( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, sal_Int32 scope, + sal_Bool nullable ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(); + Reference< XResultSet > xRef = pResult; + pResult->setBestRowIdentifierMap(); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getTablePrivileges( + const Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& tableNamePattern ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(); + Reference< XResultSet > xRef = pResult; + pResult->setTablePrivilegesMap(); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getCrossReference( + const Any& primaryCatalog, const ::rtl::OUString& primarySchema, + const ::rtl::OUString& primaryTable, const Any& foreignCatalog, + const ::rtl::OUString& foreignSchema, const ::rtl::OUString& foreignTable ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(); + Reference< XResultSet > xRef = pResult; + pResult->setCrossReferenceMap(); + return xRef; +} + diff --git a/connectivity/source/drivers/dbase/DDriver.cxx b/connectivity/source/drivers/dbase/DDriver.cxx new file mode 100644 index 000000000000..66639239c8e3 --- /dev/null +++ b/connectivity/source/drivers/dbase/DDriver.cxx @@ -0,0 +1,151 @@ +/************************************************************************* + * + * $RCSfile: DDriver.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_DBASE_DDRIVER_HXX_ +#include "dbase/DDriver.hxx" +#endif +#ifndef _CONNECTIVITY_DBASE_DCONNECTION_HXX_ +#include "dbase/DConnection.hxx" +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif + +using namespace connectivity::dbase; +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; + + +// static ServiceInfo +//------------------------------------------------------------------------------ +rtl::OUString ODriver::getImplementationName_Static( ) throw(RuntimeException) +{ + return rtl::OUString::createFromAscii("com.sun.star.sdbc.driver.dbase.Driver"); +} +//------------------------------------------------------------------------------ +//Sequence< ::rtl::OUString > ODriver::getSupportedServiceNames_Static( ) throw (RuntimeException) +//{ +// Sequence< ::rtl::OUString > aSNS( 2 ); +// aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver"); +// aSNS[1] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Driver"); +// return aSNS; +//} + +//------------------------------------------------------------------ +::rtl::OUString SAL_CALL ODriver::getImplementationName( ) throw(RuntimeException) +{ + return getImplementationName_Static(); +} + +//------------------------------------------------------------------ +//sal_Bool SAL_CALL ODriver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException) +//{ +// Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); +// const ::rtl::OUString* pSupported = aSupported.getConstArray(); +// for (sal_Int32 i=0; i<aSupported.getLength(); ++i, ++pSupported) +// if (pSupported->equals(_rServiceName)) +// return sal_True; +// +// return sal_False; +//} + +//------------------------------------------------------------------ +//Sequence< ::rtl::OUString > SAL_CALL ODriver::getSupportedServiceNames( ) throw(RuntimeException) +//{ +// return getSupportedServiceNames_Static(); +//} + + +//------------------------------------------------------------------ +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL connectivity::dbase::ODriver_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception ) +{ + return *(new ODriver(_rxFactory)); +} +// -------------------------------------------------------------------------------- +Reference< XConnection > SAL_CALL ODriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODriver_BASE::rBHelper.bDisposed) + throw DisposedException(); + + ODbaseConnection* pCon = new ODbaseConnection(this); + pCon->construct(url,info); + Reference< XConnection > xCon = pCon; + m_xConnections.push_back(WeakReferenceHelper(*pCon)); + + return xCon; +} +// -------------------------------------------------------------------------------- +sal_Bool SAL_CALL ODriver::acceptsURL( const ::rtl::OUString& url ) + throw(SQLException, RuntimeException) +{ + if(!url.compareTo(::rtl::OUString::createFromAscii("sdbc:dbase:"),11)) + { + return sal_True; + } + return sal_False; +} + + diff --git a/connectivity/source/drivers/dbase/DIndex.cxx b/connectivity/source/drivers/dbase/DIndex.cxx new file mode 100644 index 000000000000..62315ef98f88 --- /dev/null +++ b/connectivity/source/drivers/dbase/DIndex.cxx @@ -0,0 +1,701 @@ +/************************************************************************* + * + * $RCSfile: DIndex.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_DBASE_INDEX_HXX_ +#include "dbase/DIndex.hxx" +#endif +#ifndef _CONNECTIVITY_DBASE_INDEXCOLUMNS_HXX_ +#include "dbase/DIndexColumns.hxx" +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +#ifndef _CONNECTIVITY_SDBCX_COLUMN_HXX_ +#include "connectivity/sdbcx/VColumn.hxx" +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif +#ifndef _CONNECTIVITY_DBASE_TABLE_HXX_ +#include "dbase/DTable.hxx" +#endif +#ifndef _CONNECTIVITY_DBASE_INDEXITER_HXX_ +#include "dbase/DIndexIter.hxx" +#endif +//#ifndef _FSYS_HXX //autogen +//#include <tools/fsys.hxx> +//#endif +#ifndef _CONFIG_HXX //autogen +#include <vcl/config.hxx> +#endif +#ifndef _CONNECTIVITY_COMMONTOOLS_HXX_ +#include "connectivity/CommonTools.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATA_HPP_ +#include <com/sun/star/sdbc/XResultSetMetaData.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _UCBHELPER_CONTENT_HXX +#include <ucbhelper/content.hxx> +#endif +#ifndef _CPPUHELPER_EXTRACT_HXX_ +#include <cppuhelper/extract.hxx> +#endif +// ------------------------------------------------------------------------- +using namespace connectivity; +using namespace ucb; +using namespace cppu; +using namespace connectivity::file; +using namespace connectivity::sdbcx; +using namespace connectivity::dbase; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::uno; +using namespace com::sun::star::beans; +using namespace com::sun::star::ucb; + + +IMPLEMENT_SERVICE_INFO(ODbaseIndex,"com.sun.star.sdbcx.driver.dbase.Index","com.sun.star.sdbcx.Index"); +// ------------------------------------------------------------------------- +ODbaseIndex::ODbaseIndex(ODbaseTable* _pTable) : OIndex(_pTable->getConnection()->getMetaData()->storesMixedCaseQuotedIdentifiers()) + , m_pTable(_pTable) +{ + construct(); +} +// ------------------------------------------------------------------------- +ODbaseIndex::ODbaseIndex( ODbaseTable* _pTable, + const NDXHeader& _rHeader, + const ::rtl::OUString& _rName) + : OIndex(_rName,::rtl::OUString(),_rHeader.db_unique,sal_False,sal_False,_pTable->getConnection()->getMetaData()->storesMixedCaseQuotedIdentifiers()) + , m_aHeader(_rHeader) + , m_pTable(_pTable) +{ + construct(); +} +// ------------------------------------------------------------------------- +void ODbaseIndex::refreshColumns() +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + ::std::vector< ::rtl::OUString> aVector; + aVector.push_back(::rtl::OUString::createFromAscii(m_aHeader.db_name)); + + if(m_pColumns) + delete m_pColumns; + m_pColumns = new ODbaseIndexColumns(this,m_aMutex,aVector); +} +// ------------------------------------------------------------------------- +Any SAL_CALL ODbaseIndex::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = ::cppu::queryInterface(rType,static_cast< ::com::sun::star::lang::XUnoTunnel*> (this)); + if(aRet.hasValue()) + return aRet; + + return ODbaseIndex_BASE::queryInterface(rType); +} + +//-------------------------------------------------------------------------- +Sequence< sal_Int8 > ODbaseIndex::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 ODbaseIndex::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException) +{ + if (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) + return (sal_Int64)this; + + return 0; +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL ODbaseIndex::getTypes( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > *)0 )); + + return ::utl::concatSequences(aTypes.getTypes(),ODbaseIndex_BASE::getTypes()); +} + +//------------------------------------------------------------------ +ONDXPagePtr ODbaseIndex::getRoot() +{ + openIndexFile(); + if (!m_aRoot.Is()) + { + m_nRootPage = m_aHeader.db_rootpage; + m_nPageCount = m_aHeader.db_pagecount; + m_aRoot = CreatePage(m_nRootPage,NULL,TRUE); + } + return m_aRoot; +} +//------------------------------------------------------------------ +sal_Bool ODbaseIndex::openIndexFile() +{ + if(!m_aFileStream.IsOpen()) + { + INetURLObject aURL; + aURL.SetSmartProtocol(INET_PROT_FILE); + aURL.SetSmartURL(m_pTable->getEntry(), INetURLObject::ENCODE_ALL); + + aURL.setName(m_Name); + aURL.setExtension(String::CreateFromAscii("ndx")); + + // Dir* pDir = m_pTable->getConnection()->getDir(); + // String aPath = pDir->GetName(); + // aPath += m_Name.getStr(); + // DirEntry aEntry(aPath); + // aEntry.setExtension(String::CreateFromAscii("ndx")); + m_aFileStream.Open(aURL.GetMainURL(), STREAM_READWRITE | STREAM_NOCREATE | STREAM_SHARE_DENYWRITE); + + m_aFileStream.SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN); + m_aFileStream.SetBufferSize(512); + } + + return m_aFileStream.IsOpen(); +} +//------------------------------------------------------------------ +OIndexIterator* ODbaseIndex::createIterator(OBoolOperator* pOp, + const OOperand* pOperand) +{ + openIndexFile(); + return new OIndexIterator(this, pOp, pOperand); +} +//------------------------------------------------------------------ +BOOL ODbaseIndex::ConvertToKey(ONDXKey* rKey, sal_uInt32 nRec, const OFileValue& rValue) +{ + OSL_ENSHURE(m_aFileStream.IsOpen(),"FileStream is not opened!"); + // Sucht ein bestimmten Wert im Index + // Wenn der Index Unique ist, interssiert der Key nicht, sonst ja + try + { + if (m_aHeader.db_keytype == 0) + { + *rKey = ONDXKey(rValue.getString(), nRec ); + } + else + { + if (rValue.isNull()) + *rKey = ONDXKey(rValue.getDouble(), DataType::DOUBLE, nRec ); + else + *rKey = ONDXKey(rValue.getDouble(), nRec ); + } + } + catch (...) + { + return FALSE; + } + return TRUE; +} + +//------------------------------------------------------------------ +BOOL ODbaseIndex::Find(sal_uInt32 nRec, const OFileValue& rValue) +{ + openIndexFile(); + OSL_ENSHURE(m_aFileStream.IsOpen(),"FileStream is not opened!"); + // Sucht ein bestimmten Wert im Index + // Wenn der Index Unique ist, interssiert der Key nicht, sonst ja + ONDXKey aKey; + return ConvertToKey(&aKey, nRec, rValue) && getRoot()->Find(aKey); +} + +//------------------------------------------------------------------ +BOOL ODbaseIndex::Insert(sal_uInt32 nRec, const OFileValue& rValue) +{ + openIndexFile(); + OSL_ENSHURE(m_aFileStream.IsOpen(),"FileStream is not opened!"); + ONDXKey aKey; + + // Existiert der Wert bereits + // Find immer verwenden um das aktuelle Blatt zu bestimmen + if (!ConvertToKey(&aKey, nRec, rValue) || (getRoot()->Find(aKey) && isUnique())) + return FALSE; + + ONDXNode aNewNode(aKey); + + // einfuegen in das aktuelle Blatt + if (!m_aCurLeaf.Is()) + return FALSE; + + BOOL bResult = m_aCurLeaf->Insert(aNewNode); + Release(bResult); + + return bResult; +} + +//------------------------------------------------------------------ +BOOL ODbaseIndex::Update(sal_uInt32 nRec, const OFileValue& rOldValue, + const OFileValue& rNewValue) +{ + openIndexFile(); + OSL_ENSHURE(m_aFileStream.IsOpen(),"FileStream is not opened!"); + ONDXKey aKey; + if (!ConvertToKey(&aKey, nRec, rNewValue) || (isUnique() && getRoot()->Find(aKey))) + return FALSE; + else + return Delete(nRec, rOldValue) && Insert(nRec,rNewValue); +} + +//------------------------------------------------------------------ +BOOL ODbaseIndex::Delete(sal_uInt32 nRec, const OFileValue& rValue) +{ + openIndexFile(); + OSL_ENSHURE(m_aFileStream.IsOpen(),"FileStream is not opened!"); + // Existiert der Wert bereits + // Find immer verwenden um das aktuelle Blatt zu bestimmen + ONDXKey aKey; + if (!ConvertToKey(&aKey, nRec, rValue) || !getRoot()->Find(aKey)) + return FALSE; + + ONDXNode aNewNode(aKey); + + // einfuegen in das aktuelle Blatt + if (!m_aCurLeaf.Is()) + return FALSE; +#if DEBUG + m_aRoot->PrintPage(); +#endif + + return m_aCurLeaf->Delete(m_nCurNode); +} +//------------------------------------------------------------------ +void ODbaseIndex::Collect(ONDXPage* pPage) +{ + OSL_ENSHURE(m_aFileStream.IsOpen(),"FileStream is not opened!"); + if (pPage) + m_aCollector.push_back(pPage); +} +//------------------------------------------------------------------ +void ODbaseIndex::Release(BOOL bSave) +{ + // Freigeben der Indexressourcen + m_bUseCollector = FALSE; + + if (m_aCurLeaf.Is()) + { + m_aCurLeaf->Release(bSave); + m_aCurLeaf.Clear(); + } + + // Wurzel freigeben + if (m_aRoot.Is()) + { + m_aRoot->Release(bSave); + m_aRoot.Clear(); + } + // alle Referenzen freigeben, bevor der FileStream geschlossen wird + for (ULONG i = 0; i < m_aCollector.size(); i++) + m_aCollector[i]->QueryDelete(); + + m_aCollector.clear(); + + // Header modifiziert ? + if (bSave && (m_aHeader.db_rootpage != m_nRootPage || + m_aHeader.db_pagecount != m_nPageCount)) + { + m_aHeader.db_rootpage = m_nRootPage; + m_aHeader.db_pagecount = m_nPageCount; + m_aFileStream << *this; + } + m_nRootPage = m_nPageCount = 0; + m_nCurNode = NODE_NOTFOUND; +} +//------------------------------------------------------------------ +ONDXPage* ODbaseIndex::CreatePage(sal_uInt32 nPagePos, ONDXPage* pParent, BOOL bLoad) +{ + OSL_ENSHURE(m_aFileStream.IsOpen(),"FileStream is not opened!"); + + ONDXPage* pPage; + if (m_aCollector.size()) + { + pPage = *(m_aCollector.end() - 1); + m_aCollector.pop_back(); + pPage->SetPagePos(nPagePos); + pPage->SetParent(pParent); + } + else + pPage = new ONDXPage(*this, nPagePos, pParent); + + if (bLoad) + m_aFileStream >> *pPage; + + return pPage; +} + +//------------------------------------------------------------------ +SvStream& connectivity::dbase::operator >> (SvStream &rStream, ODbaseIndex& rIndex) +{ + rStream.Seek(0); + rStream.Read(&rIndex.m_aHeader,512); + + // Text convertierung + ByteString aText(rIndex.m_aHeader.db_name); + // aText.Convert(rIndex.GetDBFConnection()->GetCharacterSet(), gsl_getSystemTextEncoding()); + // aText.Convert(rIndex.GetDBFConnection()->GetCharacterSet(), gsl_getSystemTextEncoding()); + strcpy(rIndex.m_aHeader.db_name,aText.GetBuffer()); + + rIndex.m_nRootPage = rIndex.m_aHeader.db_rootpage; + rIndex.m_nPageCount = rIndex.m_aHeader.db_pagecount; + return rStream; +} +//------------------------------------------------------------------ +SvStream& connectivity::dbase::operator << (SvStream &rStream, ODbaseIndex& rIndex) +{ + rStream.Seek(0); + ByteString aText(rIndex.m_aHeader.db_name); + // aText.Convert(gsl_getSystemTextEncoding(), rIndex.GetDBFConnection()->GetCharacterSet()); + strcpy(rIndex.m_aHeader.db_name,aText.GetBuffer()); + sal_Int32 nWrites = rStream.Write(&rIndex.m_aHeader,512); + OSL_ENSHURE(nWrites == 512,"Write not successful: Wrong header size for dbase index!"); + return rStream; +} +// ------------------------------------------------------------------------- +INetURLObject ODbaseIndex::getEntry() +{ + INetURLObject aDir = m_pTable->getEntry(); + aDir.setName(m_Name); + return aDir; +} +//------------------------------------------------------------------ +void ODbaseIndex::createINFEntry() +{ + // inf Datei abgleichen + String aNDX; + // Dir* pDir = m_pTable->getConnection()->getDir(); + // String aPath = pDir->GetName(); + // aPath += m_Name.getStr(); + INetURLObject aEntry(getEntry()); + aEntry.setExtension(String::CreateFromAscii("ndx")); + + INetURLObject aInfEntry(m_pTable->getEntry()); + aInfEntry.setExtension(String::CreateFromAscii("inf")); + + Config aInfFile(aInfEntry.GetMainURL()); + aInfFile.SetGroup(dBASE_III_GROUP); + + USHORT nSuffix = aInfFile.GetKeyCount(); + ByteString aNewEntry,aKeyName; + BOOL bCase = isCaseSensitive(); + while (!aNewEntry.Len()) + { + aNewEntry = "NDX"; + aNewEntry += ByteString::CreateFromInt32(++nSuffix); + for (USHORT i = 0; i < aInfFile.GetKeyCount(); i++) + { + aKeyName = aInfFile.GetKeyName(i); + if (bCase ? aKeyName == aNewEntry : aKeyName.EqualsIgnoreCaseAscii(aNewEntry)) + { + aNewEntry.Erase(); + break; + } + } + } + aInfFile.WriteKey(aNewEntry,ByteString(aEntry.GetName(),gsl_getSystemTextEncoding())); +} +// ------------------------------------------------------------------------- +BOOL ODbaseIndex::DropImpl() +{ + if (m_aFileStream.IsOpen()) + m_aFileStream.Close(); + + INetURLObject aIndexEntry(getEntry()); + aIndexEntry.setExtension(String::CreateFromAscii("ndx")); + + Content aContent(aIndexEntry.GetMainURL(),Reference<XCommandEnvironment>()); + aContent.executeCommand( rtl::OUString::createFromAscii( "delete" ),bool2any( sal_True ) ); + +// ULONG nErrorCode = aIndexEntry.Kill(); +// if (nErrorCode != SVSTREAM_OK && nErrorCode != SVSTREAM_FILE_NOT_FOUND) +// { +// // aStatus.SetError(nErrorCode,INDEX,aName); +// return FALSE; +// } + + // InfDatei abgleichen + String aNDX; + INetURLObject aEntry( m_pTable->getEntry()); + aEntry.setExtension(String::CreateFromAscii("inf")); + + Config aInfFile(aEntry.GetMainURL()); + aInfFile.SetGroup(dBASE_III_GROUP); + USHORT nKeyCnt = aInfFile.GetKeyCount(); + ByteString aKeyName; + + INetURLObject aEntryToComp(getEntry()); + aEntryToComp.setExtension(String::CreateFromAscii("ndx")); + + for (USHORT nKey = 0; nKey < nKeyCnt; nKey++) + { + // Verweist der Key auf ein Indexfile?... + aKeyName = aInfFile.GetKeyName( nKey ); + //...wenn ja, Indexliste der Tabelle hinzufuegen + if (aEntry.IsCaseSensitive() ? aKeyName.Copy(0,3) == "NDX" : aKeyName.Copy(0,3).EqualsIgnoreCaseAscii("NDX")) + { + aEntryToComp.setName(String(aInfFile.ReadKey(aKeyName),gsl_getSystemTextEncoding())); + aEntryToComp.setExtension(String::CreateFromAscii("ndx")); + if (aEntryToComp == aIndexEntry) + { + aInfFile.DeleteKey(aKeyName); + break; + } + } + } + return TRUE; +} +// ------------------------------------------------------------------------- +//------------------------------------------------------------------ +BOOL ODbaseIndex::CreateImpl() +{ + // Anlegen des Index + INetURLObject aEntry(getEntry()); + aEntry.setExtension(String::CreateFromAscii("ndx")); + + Content aContent(aEntry.GetMainURL(),Reference<XCommandEnvironment>()); + if (aContent.isDocument()) + { + // aStatus.SetError(ERRCODE_IO_ALREADYEXISTS,INDEX,aEntry.GetFull()); + return FALSE; + } + + // Index ist nur einstufig + if (m_pColumns->getCount() != 2) + { + // aStatus.SetDriverNotCapableError(); + return FALSE; + } + + Reference<XFastPropertySet> xCol; + m_pColumns->getByIndex(1) >>= xCol; + + // ist die Spalte schon indiziert ? + if (!xCol.is()) + { +// String aText = String(OResId(STR_STAT_INDEX_COLUMN_NOT_FOUND)); +// aText.SearchAndReplace(String::CreateFromAscii("#"),pColumn->GetName()); +// aText.SearchAndReplace(String::CreateFromAscii("%"),GetTable()->Name()); +// aStatus.Set(SDB_STAT_ERROR, +// String::CreateFromAscii("01000"), +// aStatus.CreateErrorMessage(aText), +// 0, String() ); + return FALSE; + } +// else if (pColumn && pColumn->IsIndexed()) +// { +// String aText = String(OResId(STR_STAT_INDEX_COLUMN_ALREADY_INDEXED)); +// aText.SearchAndReplace(String::CreateFromAscii("#"),pColumn->GetName()); +// aStatus.Set(SDB_STAT_ERROR, +// String::CreateFromAscii("01000"), +// aStatus.CreateErrorMessage(aText), +// 0, String() ); +// return FALSE; +// } + + // Anlegen des Indexfiles + m_aFileStream.Open(aEntry.GetMainURL(), STREAM_READWRITE | STREAM_SHARE_DENYWRITE | STREAM_TRUNC); + if (!m_aFileStream.IsOpen()) + return FALSE; + + m_aFileStream.SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN); + m_aFileStream.SetBufferSize(512); + + // Zunchst mu das Ergebnis sortiert sein + Reference<XStatement> xStmt = m_pTable->getConnection()->createStatement(); + + String aName(getString(xCol->getFastPropertyValue(PROPERTY_ID_NAME))); + + String aQuote(m_pTable->getConnection()->getMetaData()->getIdentifierQuoteString()); + String aStatement; + aStatement.AssignAscii("SELECT "); + aStatement += aQuote; + aStatement += aName; + aStatement += aQuote; + aStatement.AppendAscii(" FROM "); + aStatement += aQuote; + aStatement += m_pTable->getName().getStr(); + aStatement += aQuote; + aStatement.AppendAscii(" ORDER BY "); + aStatement += aQuote; + aStatement += aName; + aStatement += aQuote; + + if (!m_IsUnique) // zusaetzlich sortierung mit der bookmarkspalte + { + aStatement.AppendAscii(" ,"); + aStatement += aQuote; + aStatement.AppendAscii("[BOOKMARK]"); // this is a special column + aStatement += aQuote; + } + + Reference<XResultSet> xSet = xStmt->executeQuery(aStatement); + + if (!xSet.is()) + { + m_aFileStream.Close(); + // aEntry.Kill(); + aContent.executeCommand( rtl::OUString::createFromAscii( "delete" ),bool2any( sal_True ) ); + return FALSE; + } + + // Setzen der Headerinfo + memset(&m_aHeader,0,sizeof(m_aHeader)); + m_aFileStream.SetStreamSize(512); + + sal_Int32 nType = 0; + xCol->getFastPropertyValue(PROPERTY_ID_TYPE) >>= nType; + + m_aHeader.db_keytype = (nType == DataType::VARCHAR || nType == DataType::CHAR) ? 0 : 1; + m_aHeader.db_keylen = (m_aHeader.db_keytype) ? 8 : (USHORT)getINT32(xCol->getFastPropertyValue(PROPERTY_ID_PRECISION)); + m_aHeader.db_maxkeys = (512 - 8) / (8 + m_aHeader.db_keylen); + ByteString aCol(aName,gsl_getSystemTextEncoding()); + strcpy(m_aHeader.db_name,aCol.GetBuffer()); + m_aHeader.db_unique = m_IsUnique ? 1: 0; + m_aHeader.db_keyrec = m_aHeader.db_keylen + 8; + + // modifizierung am Header werden ueber Unterschiede zw. HeaderInfo und nRootPage + // bzw. nPageCout erkannt + + m_nRootPage = 1; + m_nPageCount = 2; + + // ODatabaseType eType = m_aHeader.db_keytype == 0 ? DataType::VARCHAR : DataType::DOUBLE; + m_aCurLeaf = m_aRoot = CreatePage(m_nRootPage); + m_aRoot->SetModified(TRUE); + + m_bUseCollector = TRUE; + + // ULONG nRowsLeft = pCursor->RowCount(); + Reference<XRow> xRow(xSet,UNO_QUERY); + + xSet->last(); + sal_Int32 nRowsLeft = xSet->getRow(); + xSet->beforeFirst(); + + // Erzeugen der Indexstruktur + while (xSet->next()) + { + // ODbRow& rRow = *pCursor->GetRow(); + // ueberpruefen auf doppelten eintrag + if (m_IsUnique && m_nCurNode != NODE_NOTFOUND) + { + ONDXKey aKey(m_aHeader.db_keytype ? OFileValue(xRow->getDouble(1)) : OFileValue(xRow->getString(1)), nType, 0); + if (aKey == (*m_aCurLeaf)[m_nCurNode].GetKey()) + { +// String aText = String(OResId(STR_STAT_INDEX_NOT_UNIQUE)); +// aText.SearchAndReplace(String::CreateFromAscii("#"),aName); +// aStatus.Set(SDB_STAT_ERROR, +// String::CreateFromAscii("01000"), +// aStatus.CreateErrorMessage(aText), +// 0, String() ); + break; + } + } + ONDXKey aKey(m_aHeader.db_keytype ? OFileValue(xRow->getDouble(1)) : OFileValue(xRow->getString(1)), nType, xSet->getRow()); + ONDXNode aNewNode(aKey); + if (!m_aCurLeaf->Insert(aNewNode, --nRowsLeft)) + break; + +#ifdef DEBUG + //DBG_TRACE1("SDB: %s", (const char*)pCursor->Variable(1)->GetString()); + // PrintTree(); +#endif + } + +// BOOL bResult = !pCursor->IsInRange(); +// if (!bResult) +// { +// m_aFileStream.Close(); +// aEntry.Kill(); +// Release(FALSE); +// } +// else +// { + + Release(); +// m_aFileStream.Close(); + // den FielStream NICHT schliessen, da per definitionem ein OObject nach dem Kreieren offen ist + + // inf Datei abgleichen + createINFEntry(); +// } +// + // pCursor->ReleaseRef(); + return sal_True; +} + + + diff --git a/connectivity/source/drivers/dbase/DIndexColumns.cxx b/connectivity/source/drivers/dbase/DIndexColumns.cxx new file mode 100644 index 000000000000..56d473a2ddff --- /dev/null +++ b/connectivity/source/drivers/dbase/DIndexColumns.cxx @@ -0,0 +1,119 @@ +/************************************************************************* + * + * $RCSfile: DIndexColumns.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_DBASE_INDEXCOLUMNS_HXX_ +#include "dbase/DIndexColumns.hxx" +#endif +#ifndef _CONNECTIVITY_DBASE_TABLE_HXX_ +#include "dbase/DTable.hxx" +#endif + +#ifndef _CONNECTIVITY_SDBCX_INDEXCOLUMN_HXX_ +#include "connectivity/sdbcx/VIndexColumn.hxx" +#endif + +using namespace connectivity::dbase; +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; + + +Reference< XNamed > ODbaseIndexColumns::createObject(const ::rtl::OUString& _rName) +{ + const ODbaseTable* pTable = m_pIndex->getTable(); + + ::vos::ORef<OSQLColumns> aCols = pTable->getTableColumns(); + + Reference< XFastPropertySet > xCol(*find(aCols->begin(),aCols->end(),_rName,::utl::UStringMixEqual(isCaseSensitive()))); + if(!xCol.is()) + return Reference< XNamed >(); + + Reference< XNamed > xRet = new sdbcx::OIndexColumn(sal_True,_rName + ,getString(xCol->getFastPropertyValue(PROPERTY_ID_TYPENAME)) + ,::rtl::OUString() + ,getINT32(xCol->getFastPropertyValue(PROPERTY_ID_ISNULLABLE)) + ,getINT32(xCol->getFastPropertyValue(PROPERTY_ID_PRECISION)) + ,getINT32(xCol->getFastPropertyValue(PROPERTY_ID_SCALE)) + ,getINT32(xCol->getFastPropertyValue(PROPERTY_ID_TYPE)) + ,sal_False + ,sal_False + ,sal_False + ,pTable->getConnection()->getMetaData()->storesMixedCaseQuotedIdentifiers()); + + return xRet; +} + +// ------------------------------------------------------------------------- +void ODbaseIndexColumns::impl_refresh() throw(RuntimeException) +{ + m_pIndex->refreshColumns(); +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > ODbaseIndexColumns::createEmptyObject() +{ + sdbcx::OColumn* pRet = new sdbcx::OIndexColumn(m_pIndex->getTable()->getConnection()->getMetaData()->storesMixedCaseQuotedIdentifiers()); + Reference< XPropertySet > xRet = pRet; + return xRet; +} + diff --git a/connectivity/source/drivers/dbase/DIndexIter.cxx b/connectivity/source/drivers/dbase/DIndexIter.cxx new file mode 100644 index 000000000000..e5669df7d29f --- /dev/null +++ b/connectivity/source/drivers/dbase/DIndexIter.cxx @@ -0,0 +1,344 @@ +/************************************************************************* + * + * $RCSfile: DIndexIter.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_DBASE_INDEXITER_HXX_ +#include "dbase/DIndexIter.hxx" +#endif + +using namespace connectivity; +using namespace connectivity::dbase; +using namespace connectivity::file; +//================================================================== +// OIndexIterator +//================================================================== +//------------------------------------------------------------------ +OIndexIterator::~OIndexIterator() +{ + // m_pIndex->UnLock(); + m_pIndex->release(); +} + +//------------------------------------------------------------------ +ULONG OIndexIterator::First() +{ + return Find(TRUE); +} + +//------------------------------------------------------------------ +ULONG OIndexIterator::Next() +{ + return Find(FALSE); +} +//------------------------------------------------------------------ +ULONG OIndexIterator::Find(BOOL bFirst) +{ + // ONDXIndex* m_pIndex = GetNDXIndex(); + + ULONG nRes = STRING_NOTFOUND; +// if (!m_pIndex->IsOpen()) +// return nRes; + + if (bFirst) + { + m_aRoot = m_pIndex->getRoot(); + m_aCurLeaf = NULL; + } + + if (!m_pOperator) + { + // Vorbereitung , auf kleinstes Element positionieren + if (bFirst) + { + ONDXPage* pPage = m_aRoot.getBodyPtr(); + while (pPage && !pPage->IsLeaf()) + pPage = pPage->GetChild(m_pIndex).getBodyPtr(); + + m_aCurLeaf = pPage; + m_nCurNode = NODE_NOTFOUND; + } + ONDXKey* pKey = GetNextKey(); + nRes = pKey ? pKey->GetRecord() : STRING_NOTFOUND; + } + else if (m_pOperator->IsA(TYPE(OOp_ISNOTNULL))) + nRes = GetNotNull(bFirst); + else if (m_pOperator->IsA(TYPE(OOp_ISNULL))) + nRes = GetNull(bFirst); + else if (m_pOperator->IsA(TYPE(OOp_LIKE))) + nRes = GetLike(bFirst); + else if (m_pOperator->IsA(TYPE(OOp_COMPARE))) + nRes = GetCompare(bFirst); + + return nRes; +} + +//------------------------------------------------------------------ +ONDXKey* OIndexIterator::GetFirstKey(ONDXPage* pPage, const OOperand& rKey) +{ + // sucht den vorgegeben key + // Besonderheit: gelangt der Algorithmus ans Ende + // wird immer die aktuelle Seite und die Knotenposition vermerkt + // auf die die Bedingung <= zutrifft + // dieses findet beim Insert besondere Beachtung + // ONDXIndex* m_pIndex = GetNDXIndex(); + OOp_COMPARE aTempOp(SQL_PRED_GREATER); + USHORT i = 0; + + if (pPage->IsLeaf()) + { + // im blatt wird die eigentliche Operation ausgefuehrt, sonst die temp. (>) + while (i < pPage->Count() && !m_pOperator->operate(&((*pPage)[i]).GetKey(),&rKey)) + i++; + } + else + while (i < pPage->Count() && !aTempOp.operate(&((*pPage)[i]).GetKey(),&rKey)) + i++; + + + ONDXKey* pFoundKey = NULL; + if (!pPage->IsLeaf()) + { + // weiter absteigen + ONDXPagePtr aPage = (i==0) ? pPage->GetChild(m_pIndex) + : ((*pPage)[i-1]).GetChild(m_pIndex, pPage); + pFoundKey = aPage.Is() ? GetFirstKey(aPage.getBodyPtr(), rKey) : NULL; + } + else if (i == pPage->Count()) + { + pFoundKey = NULL; + } + else + { + pFoundKey = &(*pPage)[i].GetKey(); + if (!m_pOperator->operate(pFoundKey,&rKey)) + pFoundKey = NULL; + + m_aCurLeaf = pPage; + m_nCurNode = pFoundKey ? i : i - 1; + } + return pFoundKey; +} + +//------------------------------------------------------------------ +ULONG OIndexIterator::GetCompare(BOOL bFirst) +{ + ONDXKey* pKey = NULL; + // ONDXIndex* m_pIndex = GetNDXIndex(); + OSQLPredicateType ePredicateType = PTR_CAST(file::OOp_COMPARE,m_pOperator)->getPredicateType(); + + if (bFirst) + { + // Vorbereitung , auf kleinstes Element positionieren + ONDXPage* pPage = m_aRoot.getBodyPtr(); + switch (ePredicateType) + { + case SQL_PRED_NOTEQUAL: + case SQL_PRED_LESS: + case SQL_PRED_LESSOREQUAL: + while (pPage && !pPage->IsLeaf()) + pPage = pPage->GetChild(m_pIndex).getBodyPtr(); + + m_aCurLeaf = pPage; + m_nCurNode = NODE_NOTFOUND; + } + + + switch (ePredicateType) + { + case SQL_PRED_NOTEQUAL: + while ((pKey = GetNextKey()) && !m_pOperator->operate(pKey,m_pOperand)); + break; + case SQL_PRED_LESS: + while ((pKey = GetNextKey()) && !pKey->getValue().hasValue()); + break; + case SQL_PRED_LESSOREQUAL: + while (pKey = GetNextKey()); + break; + case SQL_PRED_GREATEROREQUAL: + case SQL_PRED_EQUAL: + pKey = GetFirstKey(m_aRoot.getBodyPtr(),*m_pOperand); + break; + case SQL_PRED_GREATER: + if (!(pKey = GetFirstKey(m_aRoot.getBodyPtr(),*m_pOperand))) + while ((pKey = GetNextKey()) && !m_pOperator->operate(pKey,m_pOperand)); + } + } + else + { + switch (ePredicateType) + { + case SQL_PRED_NOTEQUAL: + while ((pKey = GetNextKey()) && !m_pOperator->operate(pKey,m_pOperand)) + ; + break; + case SQL_PRED_LESS: + case SQL_PRED_LESSOREQUAL: + case SQL_PRED_EQUAL: + if (!(pKey = GetNextKey()) || !m_pOperator->operate(pKey,m_pOperand)) + { + pKey = NULL; + m_aCurLeaf = NULL; + } + break; + case SQL_PRED_GREATEROREQUAL: + case SQL_PRED_GREATER: + pKey = GetNextKey(); + } + } + + return pKey ? pKey->GetRecord() : STRING_NOTFOUND; +} + +//------------------------------------------------------------------ +ULONG OIndexIterator::GetLike(BOOL bFirst) +{ + // ONDXIndex* m_pIndex = GetNDXIndex(); + if (bFirst) + { + ONDXPage* pPage = m_aRoot.getBodyPtr(); + + while (pPage && !pPage->IsLeaf()) + pPage = pPage->GetChild(m_pIndex).getBodyPtr(); + + m_aCurLeaf = pPage; + m_nCurNode = NODE_NOTFOUND; + } + + ONDXKey* pKey; + while ((pKey = GetNextKey()) && !m_pOperator->operate(pKey,m_pOperand)) + ; + return pKey ? pKey->GetRecord() : STRING_NOTFOUND; +} + +//------------------------------------------------------------------ +ULONG OIndexIterator::GetNull(BOOL bFirst) +{ + // ONDXIndex* m_pIndex = GetNDXIndex(); + if (bFirst) + { + ONDXPage* pPage = m_aRoot.getBodyPtr(); + while (pPage && !pPage->IsLeaf()) + pPage = pPage->GetChild(m_pIndex).getBodyPtr(); + + m_aCurLeaf = pPage; + m_nCurNode = NODE_NOTFOUND; + } + + ONDXKey* pKey; + if (!(pKey = GetNextKey()) || pKey->getValue().hasValue()) + { + pKey = NULL; + m_aCurLeaf = NULL; + } + return pKey ? pKey->GetRecord() : STRING_NOTFOUND; +} + +//------------------------------------------------------------------ +ULONG OIndexIterator::GetNotNull(BOOL bFirst) +{ + ONDXKey* pKey; + // ONDXIndex* m_pIndex = GetNDXIndex(); + if (bFirst) + { + // erst alle NULL werte abklappern + for (ULONG nRec = GetNull(bFirst); + nRec != STRING_NOTFOUND; + nRec = GetNull(FALSE)) + ; + pKey = m_aCurLeaf.Is() ? &(*m_aCurLeaf)[m_nCurNode].GetKey() : NULL; + } + else + pKey = GetNextKey(); + + return pKey ? pKey->GetRecord() : STRING_NOTFOUND; +} + +//------------------------------------------------------------------ +ONDXKey* OIndexIterator::GetNextKey() +{ + // ONDXIndex* m_pIndex = GetNDXIndex(); + if (m_aCurLeaf.Is() && ((++m_nCurNode) >= m_aCurLeaf->Count())) + { + ONDXPage* pPage = m_aCurLeaf.getBodyPtr(); + // naechste Seite suchen + while (pPage) + { + ONDXPage* pParentPage = pPage->GetParent().getBodyPtr(); + if (pParentPage) + { + USHORT nPos = pParentPage->Search(pPage); + if (nPos != pParentPage->Count() - 1) + { // Seite gefunden + pPage = (*pParentPage)[nPos+1].GetChild(m_pIndex,pParentPage).getBodyPtr(); + break; + } + } + pPage = pParentPage; + } + + // jetzt wieder zum Blatt + while (pPage && !pPage->IsLeaf()) + pPage = pPage->GetChild(m_pIndex).getBodyPtr(); + + m_aCurLeaf = pPage; + m_nCurNode = 0; + } + return m_aCurLeaf.Is() ? &(*m_aCurLeaf)[m_nCurNode].GetKey() : NULL; +} + diff --git a/connectivity/source/drivers/dbase/DIndexes.cxx b/connectivity/source/drivers/dbase/DIndexes.cxx new file mode 100644 index 000000000000..0ad5cd4127d6 --- /dev/null +++ b/connectivity/source/drivers/dbase/DIndexes.cxx @@ -0,0 +1,172 @@ +/************************************************************************* + * + * $RCSfile: DIndexes.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_DBASE_INDEXES_HXX_ +#include "dbase/DIndexes.hxx" +#endif +//#ifndef _FSYS_HXX //autogen +//#include <tools/fsys.hxx> +//#endif +#ifndef _CONNECTIVITY_DBASE_INDEX_HXX_ +#include "dbase/DIndex.hxx" +#endif + + +using namespace connectivity::dbase; +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; + +namespace starutil = ::com::sun::star::util; + +Reference< XNamed > ODbaseIndexes::createObject(const ::rtl::OUString& _rName) +{ + // Dir* pDir = m_pTable->getConnection()->getDir(); + // String aPath = pDir->GetName(); + // aPath += _rName.getStr(); + INetURLObject aEntry(m_pTable->getEntry()); + aEntry.setName(_rName); + aEntry.setExtension(String::CreateFromAscii("ndx")); + SvFileStream aFileStream; + aFileStream.Open(aEntry.GetMainURL(), STREAM_READ | STREAM_NOCREATE| STREAM_SHARE_DENYWRITE); + + + // Anlegen des Indexfiles + // aFileStream.Open(aEntry.GetFull(), STREAM_READWRITE | STREAM_NOCREATE| STREAM_SHARE_DENYWRITE); + + aFileStream.SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN); + aFileStream.SetBufferSize(512); + ODbaseIndex::NDXHeader aHeader; + + aFileStream.Seek(0); + aFileStream.Read(&aHeader,512); + + ODbaseIndex* pIndex = new ODbaseIndex(m_pTable,aHeader,_rName); + + Reference< XNamed > xRet = pIndex; + return xRet; +} +// ------------------------------------------------------------------------- +void ODbaseIndexes::impl_refresh( ) throw(RuntimeException) +{ + if(m_pTable) + m_pTable->refreshIndexes(); +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > ODbaseIndexes::createEmptyObject() +{ + ODbaseIndex* pRet = new ODbaseIndex(m_pTable); + Reference< XPropertySet > xRet = pRet; + return xRet; +} +typedef connectivity::sdbcx::OCollection ODbaseTables_BASE_BASE; +// ------------------------------------------------------------------------- +// XAppend +void SAL_CALL ODbaseIndexes::appendByDescriptor( const Reference< XPropertySet >& descriptor ) throw(SQLException, ElementExistException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + ::rtl::OUString aName = getString(descriptor->getPropertyValue(PROPERTY_NAME)); + ObjectMap::iterator aIter = m_aNameMap.find(aName); + if( aIter != m_aNameMap.end()) + throw ElementExistException(aName,*this); + + Reference<XUnoTunnel> xTunnel(descriptor,UNO_QUERY); + if(xTunnel.is()) + { + ODbaseIndex* pIndex = (ODbaseIndex*)xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()); + if(pIndex && pIndex->CreateImpl()) + ODbaseIndexes_BASE::appendByDescriptor(descriptor); + } +} +// ------------------------------------------------------------------------- +// XDrop +void SAL_CALL ODbaseIndexes::dropByName( const ::rtl::OUString& elementName ) throw(SQLException, NoSuchElementException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + ObjectMap::iterator aIter = m_aNameMap.find(elementName); + if( aIter == m_aNameMap.end()) + throw NoSuchElementException(elementName,*this); + + Reference< XUnoTunnel> xTunnel(aIter->second.get(),UNO_QUERY); + if(xTunnel.is()) + { + ODbaseIndex* pIndex = (ODbaseIndex*)xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()); + if(pIndex && pIndex->DropImpl()) + ODbaseIndexes_BASE::dropByName(elementName); + } + +} +// ------------------------------------------------------------------------- +void SAL_CALL ODbaseIndexes::dropByIndex( sal_Int32 index ) throw(SQLException, IndexOutOfBoundsException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + if (index < 0 || index >= getCount()) + throw IndexOutOfBoundsException(); + + dropByName((*m_aElements[index]).first); +} +// ------------------------------------------------------------------------- + + diff --git a/connectivity/source/drivers/dbase/DTable.cxx b/connectivity/source/drivers/dbase/DTable.cxx new file mode 100644 index 000000000000..268792404cd6 --- /dev/null +++ b/connectivity/source/drivers/dbase/DTable.cxx @@ -0,0 +1,1861 @@ +/************************************************************************* + * + * $RCSfile: DTable.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_DBASE_TABLE_HXX_ +#include "dbase/DTable.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ +#include <com/sun/star/sdbc/ColumnValue.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTACCESS_HPP_ +#include <com/sun/star/ucb/XContentAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_SQLC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _SV_CONVERTER_HXX_ +#include <svtools/converter.hxx> +#endif +#ifndef _CONNECTIVITY_DBASE_DCONNECTION_HXX_ +#include "dbase/DConnection.hxx" +#endif +#ifndef _CONNECTIVITY_DBASE_COLUMNS_HXX_ +#include "dbase/DColumns.hxx" +#endif +#ifndef _OSL_THREAD_H_ +#include <osl/thread.h> +#endif +#ifndef _CONFIG_HXX //autogen +#include <vcl/config.hxx> +#endif +#ifndef _CONNECTIVITY_DBASE_INDEX_HXX_ +#include "dbase/DIndex.hxx" +#endif +#ifndef _CONNECTIVITY_DBASE_INDEXES_HXX_ +#include "dbase/DIndexes.hxx" +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif +#ifndef _CONNECTIVITY_DATECONVERSION_HXX_ +#include "DateConversion.hxx" +#endif +#ifndef _INTN_HXX //autogen +#include <tools/intn.hxx> +#endif +#ifndef _ZFORLIST_HXX //autogen +#include <svtools/zforlist.hxx> +#endif +#ifndef _SOLMATH_HXX //autogen wg. SolarMath +#include <tools/solmath.hxx> +#endif +#include <stdio.h> //sprintf +#ifndef _UCBHELPER_CONTENT_HXX +#include <ucbhelper/content.hxx> +#endif +#ifndef _CPPUHELPER_EXTRACT_HXX_ +#include <cppuhelper/extract.hxx> +#endif + +using namespace connectivity; +using namespace connectivity::dbase; +using namespace connectivity::file; +using namespace ucb; +using namespace cppu; +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 ODbaseTable::readHeader() +{ + m_aFileStream.RefreshBuffer(); // sicherstellen, dass die Kopfinformationen tatsaechlich neu gelesen werden + m_aFileStream.Seek(STREAM_SEEK_TO_BEGIN); + + BYTE aTyp; + m_aFileStream >> aTyp; + m_aFileStream.Read((char*)m_aHeader.db_aedat, 3*sizeof(BYTE)); + m_aFileStream >> m_aHeader.db_anz; + m_aFileStream >> m_aHeader.db_kopf; + m_aFileStream >> m_aHeader.db_slng; + m_aFileStream.Read((char*)m_aHeader.db_frei, 20*sizeof(BYTE)); + + if (m_aHeader.db_anz < 0 || + m_aHeader.db_kopf <= 0 || + m_aHeader.db_slng <= 0 || + ((m_aHeader.db_kopf - 1) / 32 - 1) <= 0) // anzahl felder + { + // Dies ist keine DBase Datei + } + else + { + // Konsistenzpruefung des Header: + m_aHeader.db_typ = (DBFType)aTyp; + switch (m_aHeader.db_typ) + { + case dBaseIII: + case dBaseIV: + case dBaseV: + case dBaseFS: + case dBaseFSMemo: + case dBaseIVMemoSQL: + case dBaseIIIMemo: + case dBaseIVMemo: + case FoxProMemo: + m_aFileStream.SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN); + break; + default: + { // Dies ist keine DBase Datei + } + } + } +} +// ------------------------------------------------------------------------- +void ODbaseTable::fillColumns() +{ + m_aFileStream.Seek(STREAM_SEEK_TO_BEGIN); + m_aFileStream.Seek(32L); + + // Anzahl Felder: + sal_uInt32 nFieldCount = (m_aHeader.db_kopf - 1) / 32 - 1; + + String aStrFieldName;aStrFieldName.AssignAscii("Column"); + sal_Int32 nFieldCnt = 0; + ::rtl::OUString aTypeName; + + for (sal_uInt32 i = 0; i < nFieldCount; i++) + { + DBFColumn aDBFColumn; + m_aFileStream.Read((char*)&aDBFColumn, sizeof(aDBFColumn)); + + // Info auslesen und in SdbColumn packen: + String aColumnName((const char *)aDBFColumn.db_fnm,osl_getThreadTextEncoding()); + +// while (aOriginalColumns->ColumnNumber(aColumnName) != SDB_COLUMN_NOTFOUND) +// (aColumnName = aStrFieldName) += String::CreateFromsal_Int32(++nFieldCnt); + + sal_Int32 nPrecision = aDBFColumn.db_flng; + sal_Int32 eType; + + switch (aDBFColumn.db_typ) + { + case 'C': + eType = DataType::VARCHAR; + aTypeName = ::rtl::OUString::createFromAscii("VARCHAR"); + break; + case 'F': + case 'N': + eType = DataType::DECIMAL; + aTypeName = ::rtl::OUString::createFromAscii("DECIMAL"); + + // Bei numerischen Feldern werden zwei Zeichen mehr geschrieben, als die Precision der Spaltenbeschreibung eigentlich + // angibt, um Platz fuer das eventuelle Vorzeichen und das Komma zu haben. Das muss ich jetzt aber wieder rausrechnen. + nPrecision = SvDbaseConverter::ConvertPrecisionToOdbc(nPrecision,aDBFColumn.db_dez); + // leider gilt das eben Gesagte nicht fuer aeltere Versionen .... + ; + break; + case 'L': + eType = DataType::BIT; + aTypeName = ::rtl::OUString::createFromAscii("BIT"); + break; + case 'D': + eType = DataType::DATE; + aTypeName = ::rtl::OUString::createFromAscii("DATE"); + break; + case 'M': + eType = DataType::LONGVARCHAR; + aTypeName = ::rtl::OUString::createFromAscii("LONGVARCHAR"); + nPrecision = 0; + break; + default: + aTypeName = ::rtl::OUString::createFromAscii("OTHER"); + eType = DataType::OTHER; + + } + + sal_Int32 nFlags = 0; + switch (aDBFColumn.db_typ) + { + case 'C': + case 'D': + case 'L': nFlags = ColumnSearch::FULL; break; + case 'F': + case 'N': nFlags = ColumnSearch::BASIC; break; + case 'M': nFlags = ColumnSearch::CHAR; break; + default: + nFlags = ColumnSearch::NONE; + + } + sdbcx::OColumn* pColumn = new sdbcx::OColumn(aColumnName,aTypeName,::rtl::OUString(), + ColumnValue::NULLABLE,nPrecision,aDBFColumn.db_dez,eType,sal_False,sal_False,sal_False, + getConnection()->getMetaData()->storesMixedCaseQuotedIdentifiers()); + Reference< XFastPropertySet> xCol = pColumn; + m_aColumns->push_back(xCol); + } +} +// ------------------------------------------------------------------------- +//void ODbaseTable::fillIndexes() +//{ +// Dir* pDir = m_pConnection->getDir(); +// String aPath = pDir->GetName(); +// aPath += _Name.getStr(); +// DirEntry aEntry(aPath); +// aEntry.SetExtension(String::CreateFromAscii("inf")); +// +// Config aInfFile(aEntry.GetFull()); +// aInfFile.SetGroup(dBASE_III_GROUP); +// sal_Int32 nKeyCnt = aInfFile.GetKeyCount(); +// ByteString aKeyName; +// ByteString aIndexName; +// +// for (sal_Int32 nKey = 0,nPos=0; nKey < nKeyCnt; nKey++) +// { +// // Verweist der Key auf ein Indexfile?... +// aKeyName = aInfFile.GetKeyName( nKey ); +// //...wenn ja, Indexliste der Tabelle hinzufuegen +// if (aKeyName.Copy(0,3) == ByteString("NDX") ) +// { +// aIndexName = aInfFile.ReadKey(aKeyName); +// aEntry.SetName(String(aIndexName,osl_getThreadTextEncoding())); +// if (aEntry.Exists()) +// { +// readIndex(aEntry.GetBase()); +// } +// // _rList.Insert(new String(aEntry.GetBase()), nPos++); +// } +// } +//} +// ------------------------------------------------------------------------- +//void ODbaseTable::readIndex(const String& _rName) +//{ +//} +// ------------------------------------------------------------------------- +ODbaseTable::ODbaseTable(ODbaseConnection* _pConnection) : ODbaseTable_BASE(_pConnection) + // , m_aColumns(_pConnection->getMetaData()->storesMixedCaseQuotedIdentifiers()) +{ + +} +// ------------------------------------------------------------------------- +ODbaseTable::ODbaseTable(ODbaseConnection* _pConnection, + const ::rtl::OUString& _Name, + const ::rtl::OUString& _Type, + const ::rtl::OUString& _Description , + const ::rtl::OUString& _SchemaName, + const ::rtl::OUString& _CatalogName + ) : ODbaseTable_BASE(_pConnection,_Name, + _Type, + _Description, + _SchemaName, + _CatalogName) + // , m_aColumns(_pConnection->getMetaData()->storesMixedCaseQuotedIdentifiers()) +{ + INetURLObject aURL; + aURL.SetSmartProtocol(INET_PROT_FILE); + aURL.SetSmartURL(getEntry(), INetURLObject::ENCODE_ALL); + + if(aURL.getExtension() != m_pConnection->getExtension()) + aURL.setExtension(m_pConnection->getExtension()); + + // Content aContent(aURL.GetMainURL()); + + m_aFileStream.Open(aURL.GetMainURL(), STREAM_READWRITE | STREAM_NOCREATE | STREAM_SHARE_DENYWRITE); + if(!m_aFileStream.IsOpen()) + m_aFileStream.Open(aURL.GetMainURL(), STREAM_READ | STREAM_NOCREATE | STREAM_SHARE_DENYNONE ); + + if(m_aFileStream.IsOpen()) + { + readHeader(); + + if (HasMemoFields()) + { + // Memo-Dateinamen bilden (.DBT): + // nyi: Unschoen fuer Unix und Mac! + + if (m_aHeader.db_typ == FoxProMemo) // foxpro verwendet andere extension + aURL.SetExtension(String::CreateFromAscii("fpt")); // nyi: Gross-/Kleinschreibung bei Unix? Klein ist sicherlich schoener. + else + aURL.SetExtension(String::CreateFromAscii("dbt")); // nyi: Gross-/Kleinschreibung bei Unix? Klein ist sicherlich schoener. + + // Wenn die Memodatei nicht gefunden wird, werden die Daten trotzdem angezeigt + // allerdings koennen keine Updates durchgefuehrt werden + // jedoch die Operation wird ausgefuehrt + m_aMemoStream.Open(aURL.GetMainURL(), STREAM_READWRITE | STREAM_NOCREATE | STREAM_SHARE_DENYWRITE); + if (m_aMemoStream.IsOpen()) + ReadMemoHeader(); + + // if (aStatus.IsError()) + // { + // String aText = String(SdbResId(STR_STAT_FILE_NOT_FOUND)); + // aText.SearchAndReplace(String::CreateFromAscii("%%d"),aFileEntry.GetName()); + // aText.SearchAndReplace(String::CreateFromAscii("%%t"),aStatus.TypeToString(MEMO)); + // aStatus.Set(SDB_STAT_SUCCESS_WITH_INFO, + // String::CreateFromAscii("01000"), + // aStatus.CreateErrorMessage(aText), + // 0, String() ); + // m_aMemoStream.Close(); + // } + } + // if (aStatus.IsError()) + // FileClose(); + // + fillColumns(); + + m_aFileStream.Seek(STREAM_SEEK_TO_END); + UINT32 nFileSize = m_aFileStream.Tell(); + m_aFileStream.Seek(STREAM_SEEK_TO_BEGIN); + + // Buffersize abhaengig von der Filegroesse + m_aFileStream.SetBufferSize(nFileSize > 1000000 ? 32768 : + nFileSize > 100000 ? 16384 : + nFileSize > 10000 ? 4096 : 1024); + + if (m_aMemoStream.IsOpen()) + { + // Puffer genau auf Laenge eines Satzes stellen + m_aMemoStream.Seek(STREAM_SEEK_TO_END); + nFileSize = m_aMemoStream.Tell(); + m_aMemoStream.Seek(STREAM_SEEK_TO_BEGIN); + + // Buffersize abhaengig von der Filegroesse + m_aMemoStream.SetBufferSize(nFileSize > 1000000 ? 32768 : + nFileSize > 100000 ? 16384 : + nFileSize > 10000 ? 4096 : + m_aMemoHeader.db_size); + } + + AllocBuffer(); + + refreshColumns(); + refreshIndexes(); + } +} +//------------------------------------------------------------------ +BOOL ODbaseTable::ReadMemoHeader() +{ + m_aMemoStream.SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN); + m_aMemoStream.RefreshBuffer(); // sicherstellen das die Kopfinformationen tatsaechlich neu gelesen werden + m_aMemoStream.Seek(0L); + + m_aMemoStream >> m_aMemoHeader.db_next; + switch (m_aHeader.db_typ) + { + case dBaseIIIMemo: // dBase III: feste Blockgre + case dBaseIVMemo: + // manchmal wird aber auch dBase3 dBase4 Memo zugeordnet + m_aMemoStream.Seek(20L); + m_aMemoStream >> m_aMemoHeader.db_size; + if (m_aMemoHeader.db_size > 1 && m_aMemoHeader.db_size != 512) // 1 steht auch fuer dBase 3 + m_aMemoHeader.db_typ = MemodBaseIV; + else if (m_aMemoHeader.db_size > 1 && m_aMemoHeader.db_size == 512) + { + // nun gibt es noch manche Dateien, die verwenden eine Genangabe, + // sind aber dennoch dBase Dateien + char sHeader[4]; + m_aMemoStream.Seek(m_aMemoHeader.db_size); + m_aMemoStream.Read(sHeader,4); + + if ((m_aMemoStream.GetErrorCode() != ERRCODE_NONE) || ((BYTE)sHeader[0]) != 0xFF || ((BYTE)sHeader[1]) != 0xFF || ((BYTE)sHeader[2]) != 0x08) + m_aMemoHeader.db_typ = MemodBaseIII; + else + m_aMemoHeader.db_typ = MemodBaseIV; + } + else + { + m_aMemoHeader.db_typ = MemodBaseIII; + m_aMemoHeader.db_size = 512; + } + break; + case FoxProMemo: + m_aMemoHeader.db_typ = MemoFoxPro; + m_aMemoStream.Seek(6L); + m_aMemoStream.SetNumberFormatInt(NUMBERFORMAT_INT_BIGENDIAN); + m_aMemoStream >> m_aMemoHeader.db_size; + } + return TRUE; +} +// ------------------------------------------------------------------------- +::rtl::OUString ODbaseTable::getEntry() +{ + ::rtl::OUString aURL; + Reference< XResultSet > xDir = m_pConnection->getDir(); + Reference< XRow> xRow(xDir,UNO_QUERY); + while(xDir->next()) + { + if(xRow->getString(1) == m_Name) + { + Reference< XContentAccess > xContentAccess( xDir, UNO_QUERY ); + aURL = xContentAccess->queryContentIdentfierString(); + break; + } + } + xDir->beforeFirst(); // move back to before first record + return aURL; +} +// ------------------------------------------------------------------------- +void ODbaseTable::refreshColumns() +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + ::std::vector< ::rtl::OUString> aVector; + + for(OSQLColumns::const_iterator aIter = m_aColumns->begin();aIter != m_aColumns->end();++aIter) + aVector.push_back(Reference< XNamed>(*aIter,UNO_QUERY)->getName()); + + if(m_pColumns) + delete m_pColumns; + m_pColumns = new ODbaseColumns(this,m_aMutex,aVector); +} +// ------------------------------------------------------------------------- +void ODbaseTable::refreshIndexes() +{ +// Dir* pDir = m_pConnection->getDir(); +// String aPath = pDir->GetName(); +// aPath += m_Name.getStr(); + INetURLObject aURL; + aURL.SetSmartProtocol(INET_PROT_FILE); + aURL.SetSmartURL(getEntry(), INetURLObject::ENCODE_ALL); + + aURL.setExtension(String::CreateFromAscii("inf")); + + Config aInfFile(aURL.GetMainURL()); + aInfFile.SetGroup(dBASE_III_GROUP); + sal_Int32 nKeyCnt = aInfFile.GetKeyCount(); + ByteString aKeyName; + ByteString aIndexName; + + ::std::vector< ::rtl::OUString> aVector; + + for (sal_Int32 nKey = 0,nPos=0; nKey < nKeyCnt; nKey++) + { + // Verweist der Key auf ein Indexfile?... + aKeyName = aInfFile.GetKeyName( nKey ); + //...wenn ja, Indexliste der Tabelle hinzufuegen + if (aKeyName.Copy(0,3) == ByteString("NDX") ) + { + aIndexName = aInfFile.ReadKey(aKeyName); + aURL.setName(String(aIndexName,osl_getThreadTextEncoding())); + Content aCnt(aURL.GetMainURL(),Reference<XCommandEnvironment>()); + if (aCnt.isDocument()) + { + aVector.push_back(aURL.getBase()); + } + } + } + if(m_pIndexes) + delete m_pIndexes; + m_pIndexes = new ODbaseIndexes(this,m_aMutex,aVector); +} + +// ------------------------------------------------------------------------- +void SAL_CALL ODbaseTable::disposing(void) +{ + OFileTable::disposing(); + ::osl::MutexGuard aGuard(m_aMutex); + m_aColumns->clear(); +} +// ------------------------------------------------------------------------- +Sequence< Type > SAL_CALL ODbaseTable::getTypes( ) throw(RuntimeException) +{ + Sequence< Type > aTypes = OTable_TYPEDEF::getTypes(); + Sequence< Type > aRet(aTypes.getLength()-3); + const Type* pBegin = aTypes.getConstArray(); + const Type* pEnd = pBegin + aTypes.getLength(); + sal_Int32 i=0; + for(;pBegin != pEnd;++pBegin,++i) + { + if(!(*pBegin == ::getCppuType((const Reference<XKeysSupplier>*)0) || + *pBegin == ::getCppuType((const Reference<XRename>*)0) || + *pBegin == ::getCppuType((const Reference<XAlterTable>*)0) || + *pBegin == ::getCppuType((const Reference<XDataDescriptorFactory>*)0))) + { + aRet.getArray()[i] = *pBegin; + } + } + aRet.getArray()[i] = ::getCppuType( (const Reference< ::com::sun::star::lang::XUnoTunnel > *)0 ); + + return aRet; +} + +// ------------------------------------------------------------------------- +Any SAL_CALL ODbaseTable::queryInterface( const Type & rType ) throw(RuntimeException) +{ + if( rType == ::getCppuType((const Reference<XKeysSupplier>*)0) || + rType == ::getCppuType((const Reference<XRename>*)0) || + rType == ::getCppuType((const Reference<XAlterTable>*)0) || + rType == ::getCppuType((const Reference<XDataDescriptorFactory>*)0)) + return Any(); + + Any aRet = ::cppu::queryInterface(rType,static_cast< ::com::sun::star::lang::XUnoTunnel*> (this)); + if(aRet.hasValue()) + return aRet; + + return OTable_TYPEDEF::queryInterface(rType); +} + +//-------------------------------------------------------------------------- +Sequence< sal_Int8 > ODbaseTable::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 ODbaseTable::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException) +{ + if (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) + return (sal_Int64)this; + + return ODbaseTable_BASE::getSomething(rId); +} +//------------------------------------------------------------------ +sal_Bool ODbaseTable::seekRow(FilePosition eCursorPosition, sal_Int32 nOffset, sal_Int32& nCurPos) +{ + // ---------------------------------------------------------- + // Positionierung vorbereiten: + + sal_uInt32 nNumberOfRecords = (sal_uInt32)m_aHeader.db_anz; + sal_uInt32 nTempPos = m_nFilePos; + m_nFilePos = nCurPos; + + switch(eCursorPosition) + { + case FILE_NEXT: + m_nFilePos++; + break; + case FILE_PRIOR: + if (m_nFilePos > 0) + m_nFilePos--; + break; + case FILE_FIRST: + m_nFilePos = 1; + break; + case FILE_LAST: + m_nFilePos = nNumberOfRecords; + break; + case FILE_RELATIVE: + m_nFilePos = (((sal_Int32)m_nFilePos) + nOffset < 0) ? 0L + : (sal_uInt32)(((sal_Int32)m_nFilePos) + nOffset); + break; + case FILE_ABSOLUTE: + case FILE_BOOKMARK: + m_nFilePos = (sal_uInt32)nOffset; + break; + } + + if (m_nFilePos > (sal_Int32)nNumberOfRecords) + m_nFilePos = (sal_Int32)nNumberOfRecords + 1; + + if (m_nFilePos == 0 || m_nFilePos == (sal_Int32)nNumberOfRecords + 1) + goto Error; + else + { + sal_uInt16 nEntryLen = m_aHeader.db_slng; + + OSL_ENSHURE(m_nFilePos >= 1,"SdbDBFCursor::FileFetchRow: ungueltige Record-Position"); + sal_Int32 nPos = m_aHeader.db_kopf + (sal_Int32)(m_nFilePos-1) * nEntryLen; + + m_aFileStream.Seek(nPos); +// if (aStatus.SetError(m_aFileStream) +// goto Error; + + m_aFileStream.Read((char*)m_pBuffer, nEntryLen); +// if (aStatus.SetError(m_aFileStream) +// goto Error; + } + goto End; + +Error: + switch(eCursorPosition) + { + case FILE_PRIOR: + case FILE_FIRST: + m_nFilePos = 0; + break; + case FILE_LAST: + case FILE_NEXT: + case FILE_ABSOLUTE: + case FILE_RELATIVE: + if (nOffset > 0) + m_nFilePos = nNumberOfRecords + 1; + else if (nOffset < 0) + m_nFilePos = 0; + break; + case FILE_BOOKMARK: + m_nFilePos = nTempPos; // vorherige Position + } + // aStatus.Set(SDB_STAT_NO_DATA_FOUND); + return sal_False; + +End: + nCurPos = m_nFilePos; + return sal_True; +} +//------------------------------------------------------------------ +sal_Bool ODbaseTable::fetchRow(file::OValueRow _rRow,const OSQLColumns & _rCols, sal_Bool bRetrieveData) +{ + // Einlesen der Daten + BOOL bIsCurRecordDeleted = ((char)m_pBuffer[0] == '*') ? TRUE : FALSE; + + // only read the bookmark + + // Satz als geloescht markieren + // rRow.setState(bIsCurRecordDeleted ? ROW_DELETED : ROW_CLEAN ); + _rRow->setDeleted(bIsCurRecordDeleted); + (*_rRow)[0] = m_nFilePos; + + if (!bRetrieveData) + return TRUE; + + sal_Int32 nByteOffset = 1; + // Felder: + OSQLColumns::const_iterator aIter = _rCols.begin(); + for (sal_Int32 i = 1; aIter != _rCols.end();++aIter, i++) + { + // pVal = (*_rRow)[i].getBodyPtr(); + Reference< XFastPropertySet> xColumn = *aIter; + + // Laengen je nach Datentyp: + // nyi: eine zentrale Funktion, die die Laenge liefert! + sal_Int32 nLen; + xColumn->getFastPropertyValue(PROPERTY_ID_PRECISION) >>= nLen; + sal_Int32 nType = getINT32(xColumn->getFastPropertyValue(PROPERTY_ID_TYPE)); + switch(nType) + { + case DataType::DATE: nLen = 8; break; + case DataType::DECIMAL: + nLen = SvDbaseConverter::ConvertPrecisionToDbase(nLen,getINT32(xColumn->getFastPropertyValue(PROPERTY_ID_SCALE))); + break; // das Vorzeichen und das Komma + case DataType::BIT: nLen = 1; break; + case DataType::LONGVARCHAR: nLen = 10; break; + case DataType::OTHER: + nByteOffset += nLen; + continue; + default: break; + } + + // Ist die Variable ueberhaupt gebunden? + if (!(*_rRow)[i].isBound()) + { + // Nein - naechstes Feld. + nByteOffset += nLen; + continue; + } + + char *pData = (char *) (m_pBuffer + nByteOffset); + + (*_rRow)[i].setType(nType); + + if (nType == DataType::CHAR || nType == DataType::VARCHAR) + { + char cLast = pData[nLen]; + pData[nLen] = 0; + String aStr(pData,osl_getThreadTextEncoding()); + aStr.EraseTrailingChars(); + + if (!aStr.Len()) // keine StringLaenge, dann NULL + (*_rRow)[i].setNull(); + else + { + ::rtl::OUString aStr2(aStr); + (*_rRow)[i] = aStr2; + } + pData[nLen] = cLast; + } + else + { + // Falls Nul-Zeichen im String enthalten sind, in Blanks umwandeln! + for (sal_Int32 k = 0; k < nLen; k++) + { + if (pData[k] == '\0') + pData[k] = ' '; + } + + String aStr(pData, nLen); // Spaces am Anfang und am Ende entfernen: + aStr.EraseLeadingChars(); + aStr.EraseTrailingChars(); + + if (!aStr.Len()) + { + nByteOffset += nLen; + (*_rRow)[i].setNull(); // keine Werte -> fertig + continue; + } + + switch (nType) + { + case DataType::DATE: + { + if (aStr.Len() != nLen) + { + (*_rRow)[i].setNull(); + break; + } + sal_Int32 nYear = aStr.Copy( 0, 4 ).ToInt32(); + sal_Int32 nMonth = aStr.Copy( 4, 2 ).ToInt32(); + sal_Int32 nDay = aStr.Copy( 6, 2 ).ToInt32(); + + ::com::sun::star::util::Date aDate(nDay,nMonth,nYear); + (*_rRow)[i] = DateConversion::toDouble(aDate); + } + break; + case DataType::DECIMAL: + (*_rRow)[i] = aStr.ToDouble(); + // pVal->setDouble(SdbTools::ToDouble(aStr)); + break; + case DataType::BIT: + { + BOOL b; + switch (* ((const char *)pData)) + { + case 'T': + case 'Y': + case 'J': b = TRUE; break; + default: b = FALSE; break; + } + (*_rRow)[i] = b; + // pVal->setDouble(b); + } + break; + case DataType::LONGVARCHAR: + { + long nBlockNo = aStr.ToInt32(); // Blocknummer lesen + if (nBlockNo > 0 && m_aMemoStream.IsOpen()) // Daten aus Memo-Datei lesen, nur wenn + { + if (!ReadMemo(nBlockNo, (*_rRow)[i])) + break; + } + else + (*_rRow)[i].setNull(); + } break; + default: + OSL_ASSERT("Falscher Type"); + } + } + +// if (aStatus.IsError()) +// break; + // Und weiter ... + nByteOffset += nLen; + } + return sal_True; +} +//------------------------------------------------------------------ +BOOL ODbaseTable::ReadMemo(ULONG nBlockNo, OFileValue& aVariable) +{ + BOOL bIsText = TRUE; + // SdbConnection* pConnection = GetConnection(); + + m_aMemoStream.Seek(nBlockNo * m_aMemoHeader.db_size); + switch (m_aMemoHeader.db_typ) + { + case MemodBaseIII: // dBase III-Memofeld, endet mit Ctrl-Z + { + const char cEOF = (char) 0x1a; + ByteString aStr; + static char aBuf[514]; + aBuf[512] = 0; // sonst kann der Zufall uebel mitspielen + BOOL bReady = FALSE; + + do + { + m_aMemoStream.Read(&aBuf,512); + + USHORT i = 0; + while (aBuf[i] != cEOF && ++i < 512) + ; + bReady = aBuf[i] == cEOF; + + aBuf[i] = 0; + aStr += aBuf; + + } while (!bReady && !m_aMemoStream.IsEof() && aStr.Len() < STRING_MAXLEN); + + aVariable = ::rtl::OUString(aStr.GetBuffer(), aStr.Len(),osl_getThreadTextEncoding()); + } break; + case MemoFoxPro: + case MemodBaseIV: // dBase IV-Memofeld mit Laengenangabe + { + char sHeader[4]; + m_aMemoStream.Read(sHeader,4); + // Foxpro stores text and binary data + if (m_aMemoHeader.db_typ == MemoFoxPro) + { + if (((BYTE)sHeader[0]) != 0 || ((BYTE)sHeader[1]) != 0 || ((BYTE)sHeader[2]) != 0) + { +// String aText = String(SdbResId(STR_STAT_FILE_INVALID)); +// aText.SearchAndReplace(String::CreateFromAscii("%%d"),m_aMemoStream.GetFileName()); +// aText.SearchAndReplace(String::CreateFromAscii("%%t"),aStatus.TypeToString(MEMO)); +// aStatus.Set(SDB_STAT_ERROR, +// String::CreateFromAscii("01000"), +// aStatus.CreateErrorMessage(aText), +// 0, String() ); + return FALSE; + } + + bIsText = sHeader[3] != 0; + } + else if (((BYTE)sHeader[0]) != 0xFF || ((BYTE)sHeader[1]) != 0xFF || ((BYTE)sHeader[2]) != 0x08) + { +// String aText = String(SdbResId(STR_STAT_FILE_INVALID)); +// aText.SearchAndReplace(String::CreateFromAscii("%%d"),m_aMemoStream.GetFileName()); +// aText.SearchAndReplace(String::CreateFromAscii("%%t"),aStatus.TypeToString(MEMO)); +// aStatus.Set(SDB_STAT_ERROR, +// String::CreateFromAscii("01000"), +// aStatus.CreateErrorMessage(aText), +// 0, String() ); + return FALSE; + } + + ULONG nLength; + m_aMemoStream >> nLength; + + if (m_aMemoHeader.db_typ == MemodBaseIV) + nLength -= 8; + + // char cChar; + if (nLength < STRING_MAXLEN && bIsText) + { + ByteString aStr; + aStr.Expand(USHORT (nLength)); + m_aMemoStream.Read(aStr.AllocBuffer((USHORT)nLength),nLength); + aStr.ReleaseBufferAccess(); + aVariable = ::rtl::OUString(aStr.GetBuffer(),aStr.Len(), osl_getThreadTextEncoding()); + } + else + { +// ::Sequence<sal_Int8> aText(nLength); +// sal_Int8* pData = aText.getArray(); +// for (ULONG i = 0; i < nLength; i++) +// { +// m_aMemoStream.Read(&cChar,1); +// (*pData++) = cChar; +// } +// aVariable.setBytes(aText); + return sal_False; + } + } + } + return sal_True; +} +// ------------------------------------------------------------------------- +void ODbaseTable::FileClose() +{ + // falls noch nicht alles geschrieben wurde + if (m_aMemoStream.IsOpen() && m_aMemoStream.IsWritable()) + m_aMemoStream.Flush(); + + m_aMemoStream.Close(); + + if (m_aFileStream.IsOpen() && m_aFileStream.IsWritable()) + m_aFileStream.Flush(); + + m_aFileStream.Close(); + + if (m_pBuffer != NULL) + { + delete m_pBuffer; + m_pBuffer = NULL; + } +} +// ------------------------------------------------------------------------- +BOOL ODbaseTable::CreateImpl() +{ + OSL_ENSHURE(!m_aFileStream.IsOpen(), "SequenceError"); + + INetURLObject aURL; + aURL.SetSmartProtocol(INET_PROT_FILE); + aURL.SetSmartURL(getEntry(), INetURLObject::ENCODE_ALL); + + if(aURL.getExtension() != m_pConnection->getExtension()) + aURL.setExtension(m_pConnection->getExtension()); + + Content aContent(aURL.GetMainURL(),Reference<XCommandEnvironment>()); + + if (aContent.isDocument()) + { + // Hack fuer Bug #30609 , nur wenn das File existiert und die Laenge > 0 gibt es einen Fehler + SvFileStream m_aFileStream; + m_aFileStream.Open(aURL.GetMainURL(),STREAM_STD_READ); + + if (m_aFileStream.IsOpen() && m_aFileStream.Seek(STREAM_SEEK_TO_END)) + { + // aStatus.SetError(ERRCODE_IO_ALREADYEXISTS,TABLE,aFile.GetFull()); + return FALSE; + } + m_aFileStream.Close(); + } + + BOOL bMemoFile = FALSE; + + sal_Bool bOk = CreateFile(aURL, bMemoFile); + + FileClose(); + + if (!bOk) + { + aContent.executeCommand( rtl::OUString::createFromAscii( "delete" ),bool2any( sal_True ) ); + return FALSE; + } + + if (bMemoFile) + { + String aExt = aURL.getExtension(); + aURL.setExtension(String::CreateFromAscii("dbt")); // extension for memo file + Content aMemo1Content(aURL.GetMainURL(),Reference<XCommandEnvironment>()); + + if (aMemo1Content.isDocument()) + { + // aStatus.SetError(ERRCODE_IO_ALREADYEXISTS,MEMO,aFile.GetFull()); + aURL.setExtension(aExt); // kill dbf file + Content aMemoContent(aURL.GetMainURL(),Reference<XCommandEnvironment>()); + aMemoContent.executeCommand( rtl::OUString::createFromAscii( "delete" ),bool2any( sal_True ) ); + return FALSE; + } + if (!CreateMemoFile(aURL)) + { + aURL.setExtension(aExt); // kill dbf file + Content aMemoContent(aURL.GetMainURL(),Reference<XCommandEnvironment>()); + aMemoContent.executeCommand( rtl::OUString::createFromAscii( "delete" ),bool2any( sal_True ) ); + return FALSE; + } + m_aHeader.db_typ = dBaseIIIMemo; + } + else + m_aHeader.db_typ = dBaseIII; + +// if (GetDBFConnection()->GetShowDeleted()) +// nPrivileges = SDB_PR_READ | SDB_PR_INSERT | SDB_PR_UPDATE | +// SDB_PR_ALTER | SDB_PR_DROP; +// else + // nPrivileges = SDB_PR_READ | SDB_PR_INSERT | SDB_PR_UPDATE | + // SDB_PR_DELETE | SDB_PR_ALTER | SDB_PR_DROP; + + return TRUE; +} + +//------------------------------------------------------------------ +// erzeugt grundstzlich dBase IV Datei Format +BOOL ODbaseTable::CreateFile(const INetURLObject& aFile, BOOL& bCreateMemo) +{ + bCreateMemo = FALSE; + Date aDate; // aktuelles Datum + + m_aFileStream.Open(aFile.GetMainURL(), STREAM_READWRITE | STREAM_SHARE_DENYWRITE | STREAM_TRUNC); + if (!m_aFileStream.IsOpen()) + return FALSE; + + char aBuffer[21]; // write buffer + memset(aBuffer,0,sizeof(aBuffer)); + + m_aFileStream.Seek(0L); + m_aFileStream << (BYTE) dBaseIII; // dBase format + m_aFileStream << (BYTE) (aDate.GetYear() % 100); // aktuelles Datum + + + m_aFileStream << (BYTE) aDate.GetMonth(); + m_aFileStream << (BYTE) aDate.GetDay(); + m_aFileStream << 0L; // Anzahl der Datenstze + m_aFileStream << (USHORT)(m_pColumns->getCount() * 32 + 1); // Kopfinformationen, + // pColumns erhlt immer eine Spalte mehr + m_aFileStream << (USHORT) 0; // Satzlnge wird spter bestimmt + m_aFileStream.Write(aBuffer, 20); + + USHORT nRecLength = 1; // Lnge 1 fr deleted flag + ULONG nMaxFieldLength = m_pConnection->getMetaData()->getMaxColumnNameLength(); + Reference<XIndexAccess> xColumns(getColumns(),UNO_QUERY); + + ::rtl::OUString aName; + Reference<XFastPropertySet> xCol; + for(sal_Int32 i=0;i<xColumns->getCount();++i) + { + xColumns->getByIndex(i) >>= xCol; + OSL_ENSHURE(xCol.is(),"This should be a column!"); + + char cTyp; + + xCol->getFastPropertyValue(PROPERTY_ID_NAME) >>= aName; + + if (aName.getLength() > nMaxFieldLength) + { +// String aText = String(SdbResId(STR_DBF_INVALIDFIELDNAMELENGTH)); +// aText.SearchAndReplace(String::CreateFromAscii("#"),rColumn.GetName()); +// aStatus.Set(SDB_STAT_ERROR, +// String::CreateFromAscii("01000"), +// aStatus.CreateErrorMessage(aText), +// 0, String() ); + break; + } + + ByteString aCol(aName.getStr(),gsl_getSystemTextEncoding()); + m_aFileStream << aCol.GetBuffer(); + m_aFileStream.Write(aBuffer, 11 - aCol.Len()); + + switch (getINT32(xCol->getFastPropertyValue(PROPERTY_ID_TYPE))) + { + case DataType::CHAR: + case DataType::VARCHAR: + cTyp = 'C'; + break; + case DataType::TINYINT: + case DataType::SMALLINT: + case DataType::INTEGER: + case DataType::BIGINT: + case DataType::DECIMAL: + case DataType::NUMERIC: + case DataType::REAL: + case DataType::DOUBLE: + cTyp = 'N'; // nur dBase 3 format + break; + case DataType::DATE: + cTyp = 'D'; + break; + case DataType::BIT: + cTyp = 'L'; + break; + case DataType::LONGVARBINARY: + case DataType::LONGVARCHAR: + cTyp = 'M'; + break; + default: + { +// aStatus.Set(SDB_STAT_ERROR, +// String::CreateFromAscii("01000"), +// aStatus.CreateErrorMessage(String(SdbResId(STR_DBF_INVALIDFORMAT))), +// 0, String() ); + break; + } + } + + m_aFileStream << cTyp; + m_aFileStream.Write(aBuffer, 4); + + sal_Int32 nPrecision = 0; + xCol->getFastPropertyValue(PROPERTY_ID_PRECISION) >>= nPrecision; + sal_Int32 nScale = 0; + xCol->getFastPropertyValue(PROPERTY_ID_SCALE) >>= nScale; + + switch(cTyp) + { + case 'C': + OSL_ENSHURE(nPrecision < 255, "ODbaseTable::Create: Column zu lang!"); + if (nPrecision > 254) + { +// String aText = String(SdbResId(STR_DBF_INVALIDFIELDLENGTH)); +// aText.SearchAndReplace(String::CreateFromAscii("#"),rColumn.GetName()); +// aStatus.Set(SDB_STAT_ERROR, +// String::CreateFromAscii("01000"), +// aStatus.CreateErrorMessage(aText), +// 0, String() ); + // break; + } + m_aFileStream << (BYTE) min(nPrecision, 255UL); //Feldlnge + nRecLength += (USHORT)min(nPrecision, 255UL); + m_aFileStream << (BYTE)0; //Nachkommastellen + break; + case 'F': + case 'N': + OSL_ENSHURE(nPrecision >= nScale, + "ODbaseTable::Create: Feldlnge mu grer Nachkommastellen sein!"); + if (nPrecision < nScale) + { +// aStatus.Set(SDB_STAT_ERROR, +// String::CreateFromAscii("01000"), +// aStatus.CreateErrorMessage(String(SdbResId(STR_DBF_INVALIDFORMAT))), +// 0, String() ); + break; + } + if (getBOOL(xCol->getFastPropertyValue(PROPERTY_ID_ISCURRENCY))) // Currency wird gesondert behandelt + { + m_aFileStream << (BYTE)10; // Standard Laenge + m_aFileStream << (BYTE)4; + nRecLength += 10; + } + else + { + UINT16 nPrec = SvDbaseConverter::ConvertPrecisionToDbase(nPrecision,nScale); + + m_aFileStream << (BYTE)( nPrec); + m_aFileStream << (BYTE)nScale; + nRecLength += (USHORT)nPrec; + } + break; + case 'L': + m_aFileStream << (BYTE)1; + m_aFileStream << (BYTE)0; + nRecLength++; + break; + case 'D': + m_aFileStream << (BYTE)8; + m_aFileStream << (BYTE)0; + nRecLength += 8; + break; + case 'M': + bCreateMemo = TRUE; + m_aFileStream << (BYTE)10; + m_aFileStream << (BYTE)0; + nRecLength += 10; + break; + default: +// aStatus.Set(SDB_STAT_ERROR, +// String::CreateFromAscii("01000"), +// aStatus.CreateErrorMessage(String(SdbResId(STR_DBF_INVALIDFORMAT))), +// 0, String() ); + break; + } + m_aFileStream.Write(aBuffer, 14); + } + +// if (aStatus.IsError()) +// return FALSE; + + m_aFileStream << (BYTE)0x0d; // kopf ende + m_aFileStream.Seek(10L); + m_aFileStream << nRecLength; // satzlnge nachtrglich eintragen + + if (bCreateMemo) + { + m_aFileStream.Seek(0L); + m_aFileStream << (BYTE) dBaseIIIMemo; + } + return TRUE; +} + +//------------------------------------------------------------------ +// erzeugt grundstzlich dBase III Datei Format +BOOL ODbaseTable::CreateMemoFile(const INetURLObject& aFile) +{ + // Makro zum Filehandling frs Erzeugen von Tabellen + m_aMemoStream.Open(aFile.GetMainURL(), STREAM_READWRITE | STREAM_SHARE_DENYWRITE); + if (!m_aMemoStream.IsOpen()) + return FALSE; + + char aBuffer[512]; // write buffer + memset(aBuffer,0,sizeof(aBuffer)); + +#ifdef WIN + m_aMemoStream.Seek(0L); + for (UINT16 i = 0; i < 512; i++) + { + m_aMemoStream << BYTE(0); + } +#else + m_aMemoStream.SetFiller('\0'); + m_aMemoStream.SetStreamSize(512); +#endif + + m_aMemoStream.Seek(0L); + m_aMemoStream << long(1); // Zeiger auf ersten freien Block + + m_aMemoStream.Close(); + return TRUE; +} +//------------------------------------------------------------------ +BOOL ODbaseTable::DropImpl() +{ +// NAMESPACE_VOS(OGuard) aGuard(m_pLock); +// +// if (InUse()) +// { +// aStatus.SetError(ERRCODE_IO_LOCKVIOLATION,TABLE,aName); +// return FALSE; +// } + + FileClose(); + + INetURLObject aURL; + aURL.SetSmartProtocol(INET_PROT_FILE); + aURL.SetSmartURL(getEntry(), INetURLObject::ENCODE_ALL); + + Content aContent(aURL.GetMainURL(),Reference<XCommandEnvironment>()); + aContent.executeCommand( rtl::OUString::createFromAscii( "delete" ), + makeAny( sal_Bool( sal_True ) ) ); + + if (HasMemoFields()) + { + aURL.setExtension(String::CreateFromAscii("dbt")); + Content aMemoContent(aURL.GetMainURL(),Reference<XCommandEnvironment>()); + aMemoContent.executeCommand( rtl::OUString::createFromAscii( "delete" ),bool2any( sal_True ) ); + } + + // jetzt noch die Indices loeschen + String aIndexName; + // aFile.SetExtension(String::CreateFromAscii("ndx")); + USHORT nCount = m_pIndexes->getCount(), + i = 0; + while (i < nCount) + { + m_pIndexes->dropByIndex(i); + } + // aFile.SetBase(m_Name); + aURL.setExtension(String::CreateFromAscii("inf")); + Content aInfContent(aURL.GetMainURL(),Reference<XCommandEnvironment>()); + aInfContent.executeCommand( rtl::OUString::createFromAscii( "delete" ),bool2any( sal_True ) ); + return TRUE; +} +//------------------------------------------------------------------ +BOOL ODbaseTable::InsertRow(ORefAssignValues& rRow, BOOL bFlush,const Reference<XIndexAccess>& _xCols) +{ + // Buffer mit Leerzeichen fllen + AllocBuffer(); + memset(m_pBuffer, ' ', m_aHeader.db_slng); + + // Gesamte neue Row uebernehmen: + // ... und am Ende als neuen Record hinzufuegen: + UINT32 nTempPos = m_nFilePos, + nFileSize, + nMemoFileSize; + + m_nFilePos = (ULONG)m_aHeader.db_anz + 1; + if (!UpdateBuffer(rRow.getBody(),NULL,_xCols)) + { + m_nFilePos = nTempPos; + return FALSE; + } + + String aName = m_aFileStream.GetFileName(); + + m_aFileStream.Seek(STREAM_SEEK_TO_END); + nFileSize = m_aFileStream.Tell(); + + if (HasMemoFields() && m_aMemoStream.IsOpen()) + { + m_aMemoStream.Seek(STREAM_SEEK_TO_END); + nMemoFileSize = m_aMemoStream.Tell(); + } + + if (!WriteBuffer()) + { + m_aFileStream.SetStreamSize(nFileSize); // alte Gre restaurieren + + if (HasMemoFields() && m_aMemoStream.IsOpen()) + m_aMemoStream.SetStreamSize(nMemoFileSize); // alte Gre restaurieren + m_nFilePos = nTempPos; // Fileposition restaurieren + } + else + { + // Anzahl Datensaetze im Header erhoehen: + m_aFileStream.Seek( 4L ); + m_aFileStream << (m_aHeader.db_anz + 1); + + // beim AppendOnly kein Flush! + if (bFlush) + m_aFileStream.Flush(); + + // bei Erfolg # erhhen + m_aHeader.db_anz++; + (*rRow)[0] = m_nFilePos; // BOOKmark setzen + m_nFilePos = nTempPos; + } + + return sal_True;; +} + +//------------------------------------------------------------------ +BOOL ODbaseTable::UpdateRow(file::OValueVector& rRow, OValueRow pOrgRow,const Reference<XIndexAccess>& _xCols) +{ + // Buffer mit Leerzeichen fllen + AllocBuffer(); + + // Auf gewuenschten Record positionieren: + long nPos = m_aHeader.db_kopf + (long)(m_nFilePos-1) * m_aHeader.db_slng; + m_aFileStream.Seek(nPos); + m_aFileStream.Read((char*)m_pBuffer, m_aHeader.db_slng); + + UINT32 nMemoFileSize; + if (HasMemoFields() && m_aMemoStream.IsOpen()) + { + m_aMemoStream.Seek(STREAM_SEEK_TO_END); + nMemoFileSize = m_aMemoStream.Tell(); + } + if (!UpdateBuffer(rRow, pOrgRow,_xCols) || !WriteBuffer()) + { + if (HasMemoFields() && m_aMemoStream.IsOpen()) + m_aMemoStream.SetStreamSize(nMemoFileSize); // alte Gre restaurieren + } + else + { + m_aFileStream.Flush(); + } + return sal_True; +} + +//------------------------------------------------------------------ +BOOL ODbaseTable::DeleteRow(const OSQLColumns& _rCols) +{ + // Einfach das Loesch-Flag setzen (egal, ob es schon gesetzt war + // oder nicht): + // Auf gewuenschten Record positionieren: + long nPos = m_aHeader.db_kopf + (long)(m_nFilePos-1) * m_aHeader.db_slng; + m_aFileStream.Seek(nPos); + + OValueRow aRow = new OValueVector(_rCols.size()); + + if (!fetchRow(aRow,_rCols,TRUE)) + return FALSE; + + Reference<XFastPropertySet> xCol; + ::rtl::OUString aColName; + ::utl::UStringMixEqual aCase(isCaseSensitive()); + for (USHORT i = 0; i < m_pColumns->getCount(); i++) + { + m_pColumns->getByIndex(i) >>= xCol; + // const SdbFILEColumn *pColumn = (const SdbFILEColumn *)(*aOriginalColumns)[i]; + + xCol->getFastPropertyValue(PROPERTY_ID_NAME) >>= aColName; + Reference<XFastPropertySet> xIndex = isUniqueByColumnName(aColName); + if (xIndex.is()) + { + Reference<XUnoTunnel> xTunnel(xIndex,UNO_QUERY); + OSL_ENSHURE(xTunnel.is(),"No TunnelImplementation!"); + ODbaseIndex* pIndex = (ODbaseIndex*)xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()); + OSL_ENSHURE(pIndex,"ODbaseTable::UpdateBuffer: No Index returned!"); + + OSQLColumns::const_iterator aIter = _rCols.begin(); + // sal_Int32 nPos = 0; + for(;aIter != _rCols.end();++aIter,++nPos) + { +// Reference<XFastPropertySet> xFindCol; +// _xCols->getByIndex(nPos) >>= xFindCol; + if(aCase(getString((*aIter)->getFastPropertyValue(PROPERTY_ID_REALNAME)),aColName)) + break; + } + if (aIter == _rCols.end()) + continue; + + pIndex->Delete(m_nFilePos,(*aRow)[nPos]); + } + } + + m_aFileStream.Seek(nPos); + m_aFileStream << (BYTE)'*'; + m_aFileStream.Flush(); + return sal_True;; +} + +//------------------------------------------------------------------ +BOOL ODbaseTable::WriteMemo(OFileValue& aVariable, ULONG& rBlockNr) +{ + // wird die BlockNr 0 vorgegeben, wird der block ans Ende gehaengt + char cChar = 0; + BOOL bIsText = TRUE; + // SdbConnection* pConnection = GetConnection(); + + ULONG nSize = 0; + ULONG nStreamSize; + BYTE nHeader[4]; + + ByteString aStr; + // ::Sequence<sal_Int8>* pData = NULL; +// if (aVariable.getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence< sal_Int8 > *)0)) +// { +// pData = (::Sequence<sal_Int8>*)aVariable.get(); +// nSize = pData->getLength(); +// } +// else +// { + aStr = ByteString(aVariable.getString().getStr(), osl_getThreadTextEncoding()); + nSize = aStr.Len(); + // } + + // Anhaengen oder ueberschreiben + BOOL bAppend = rBlockNr == 0; + + if (!bAppend) + { + switch (m_aMemoHeader.db_typ) + { + case MemodBaseIII: // dBase III-Memofeld, endet mit 2 * Ctrl-Z + bAppend = nSize > (512 - 2); + break; + case MemoFoxPro: + case MemodBaseIV: // dBase IV-Memofeld mit Laengenangabe + { + char sHeader[4]; + m_aMemoStream.Seek(rBlockNr * m_aMemoHeader.db_size); + m_aMemoStream.SeekRel(4L); + m_aMemoStream.Read(sHeader,4); + + ULONG nOldSize; + if (m_aMemoHeader.db_typ == MemoFoxPro) + nOldSize = ((((unsigned char)sHeader[0]) * 256 + + (unsigned char)sHeader[1]) * 256 + + (unsigned char)sHeader[2]) * 256 + + (unsigned char)sHeader[3]; + else + nOldSize = ((((unsigned char)sHeader[3]) * 256 + + (unsigned char)sHeader[2]) * 256 + + (unsigned char)sHeader[1]) * 256 + + (unsigned char)sHeader[0] - 8; + + // passt die neue Laenge in die belegten Bloecke + ULONG nUsedBlocks = ((nSize + 8) / m_aMemoHeader.db_size) + (((nSize + 8) % m_aMemoHeader.db_size > 0) ? 1 : 0), + nOldUsedBlocks = ((nOldSize + 8) / m_aMemoHeader.db_size) + (((nOldSize + 8) % m_aMemoHeader.db_size > 0) ? 1 : 0); + bAppend = nUsedBlocks > nOldUsedBlocks; + } + } + } + + if (bAppend) + { + ULONG nStreamSize; + nStreamSize = m_aMemoStream.Seek(STREAM_SEEK_TO_END); + // letzten block auffuellen + rBlockNr = (nStreamSize / m_aMemoHeader.db_size) + ((nStreamSize % m_aMemoHeader.db_size) > 0 ? 1 : 0); + + m_aMemoStream.SetStreamSize(rBlockNr * m_aMemoHeader.db_size); + m_aMemoStream.Seek(STREAM_SEEK_TO_END); + } + else + { + m_aMemoStream.Seek(rBlockNr * m_aMemoHeader.db_size); + } + + switch (m_aMemoHeader.db_typ) + { + case MemodBaseIII: // dBase III-Memofeld, endet mit Ctrl-Z + { + const char cEOF = (char) 0x1a; + nSize++; + +// if (pData) +// { +// m_aMemoStream.Write((const char*) pData->getConstArray(), pData->getLength()); +// } +// else +// { + m_aMemoStream.Write(aStr.GetBuffer(), aStr.Len()); + // } + + m_aMemoStream << cEOF << cEOF; + } break; + case MemoFoxPro: + case MemodBaseIV: // dBase IV-Memofeld mit Laengenangabe + { + m_aMemoStream << (BYTE)0xFF + << (BYTE)0xFF + << (BYTE)0x08; + + UINT32 nWriteSize = nSize; + if (m_aMemoHeader.db_typ == MemoFoxPro) + { + m_aMemoStream << (BYTE) 0x01; // ((pData = NULL) ? 0x01 : 0x00); + for (int i = 4; i > 0; nWriteSize >>= 8) + nHeader[--i] = (BYTE) (nWriteSize % 256); + } + else + { + m_aMemoStream << (BYTE) 0x00; + nWriteSize += 8; + for (int i = 0; i < 4; nWriteSize >>= 8) + nHeader[i++] = (BYTE) (nWriteSize % 256); + } + + m_aMemoStream.Write(nHeader,4); +// if (pData) +// { +// m_aMemoStream.Write((const char*) pData->getConstArray(), pData->getLength()); +// } +// else +// { + m_aMemoStream.Write(aStr.GetBuffer(), aStr.Len()); + // } + m_aMemoStream.Flush(); + } + } + + + // Schreiben der neuen Blocknummer + if (bAppend) + { + nStreamSize = m_aMemoStream.Seek(STREAM_SEEK_TO_END); + m_aMemoHeader.db_next = (nStreamSize / m_aMemoHeader.db_size) + ((nStreamSize % m_aMemoHeader.db_size) > 0 ? 1 : 0); + + // Schreiben der neuen Blocknummer + m_aMemoStream.Seek(0L); + m_aMemoStream << m_aMemoHeader.db_next; + m_aMemoStream.Flush(); + } + return sal_True; +} +//------------------------------------------------------------------ +void ODbaseTable::AllocBuffer() +{ + UINT16 nSize = m_aHeader.db_slng; + OSL_ENSHURE(nSize > 0, "Size too small"); + + if (m_nBufferSize != nSize) + { + delete m_pBuffer; + m_pBuffer = NULL; + } + + // Falls noch kein Puffer vorhanden: allozieren: + if (m_pBuffer == NULL && nSize) + { + m_nBufferSize = nSize; + m_pBuffer = new BYTE[m_nBufferSize+1]; + } +} +// ------------------------------------------------------------------------- +Reference<XFastPropertySet> ODbaseTable::isUniqueByColumnName(const ::rtl::OUString& _rColName) +{ + if(!m_pIndexes) + refreshIndexes(); + Reference<XFastPropertySet> xIndex; + for(sal_Int32 i=0;i<m_pIndexes->getCount();++i) + { + m_pIndexes->getByIndex(i) >>= xIndex; + if(getBOOL(xIndex->getFastPropertyValue(PROPERTY_ID_ISUNIQUE))) + { + Reference<XNameAccess> xCols(Reference<XColumnsSupplier>(xIndex,UNO_QUERY)->getColumns()); + if(xCols->hasByName(_rColName)) + return xIndex; + + } + } + return Reference<XFastPropertySet>(); +} +//------------------------------------------------------------------ +double toDouble(const ByteString& rString) +{ + static International aInter(LANGUAGE_ENGLISH); + static int nErrno=0; + BOOL bInitialized = FALSE; + if (!bInitialized) + { // ensure that the two members we're interested in are really set + // (if the system doesn't know the locale en_US aIntl would be initialized with the + // system language which may be anything - which we don't want ...) + // 74342 - 21.03.00 - FS + aInter.SetNumThousandSep(','); + aInter.SetNumDecimalSep('.'); + bInitialized = TRUE; + } + return SolarMath::StringToDouble(UniString(rString,gsl_getSystemTextEncoding()).GetBuffer(),aInter,nErrno); +} + +//------------------------------------------------------------------ +BOOL ODbaseTable::UpdateBuffer(OValueVector& rRow, OValueRow pOrgRow,const Reference<XIndexAccess>& _xCols) +{ + USHORT nByteOffset = 1; + + // Felder aktualisieren: + Reference<XFastPropertySet> xCol; + Reference<XFastPropertySet> xIndex; + USHORT i; + ::rtl::OUString aColName; + ::std::vector< Reference<XFastPropertySet> > aIndexedCols(m_pColumns->getCount()); + + ::utl::UStringMixEqual aCase(isCaseSensitive()); + + // first search a key that exist already in the table + for (i = 0; i < m_pColumns->getCount(); i++) + { + m_pColumns->getByIndex(i) >>= xCol; + xCol->getFastPropertyValue(PROPERTY_ID_NAME) >>= aColName; + + // const SdbFILEColumn *pColumn = (const SdbFILEColumn *)(*aOriginalColumns)[i]; + sal_Int32 nPos = 0; + for(;nPos<_xCols->getCount();++nPos) + { + Reference<XFastPropertySet> xFindCol; + _xCols->getByIndex(nPos) >>= xFindCol; + if(aCase(getString(xFindCol->getFastPropertyValue(PROPERTY_ID_NAME)),aColName)) + break; + } + if (nPos >= _xCols->getCount()) + continue; + + ++nPos; + // ODbVariant* pVal = (*rRow)[nPos].getBodyPtr(); + xIndex = isUniqueByColumnName(aColName); + aIndexedCols[i] = xIndex; + if (xIndex.is()) + { + // Update !! + if(pOrgRow.isValid() && (rRow[nPos].isNull() || rRow[nPos] == (*pOrgRow)[nPos])) +// +// if (pOrgRow && (pVal == NULL || +// !pVal->isModified() || +// *pVal == *(*pOrgRow)[nPos])) + continue; + else + { + // ODbVariantRef xVar = (pVal == NULL) ? new ODbVariant() : pVal; + Reference<XUnoTunnel> xTunnel(xIndex,UNO_QUERY); + OSL_ENSHURE(xTunnel.is(),"No TunnelImplementation!"); + ODbaseIndex* pIndex = (ODbaseIndex*)xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()); + OSL_ENSHURE(pIndex,"ODbaseTable::UpdateBuffer: No Index returned!"); + + if (pIndex->Find(0,rRow[nPos])) + { + // es existiert kein eindeutiger Wert +// String aText = String(SdbResId(STR_VALUE_NOTUNIQUE)); +// aText.SearchAndReplace(String::CreateFromAscii("#"),pColumn->GetName()); +// String strDetailed = String(SdbResId(STR_DBF_DUPL_VALUE_INFO)); +// strDetailed.SearchAndReplace(String::CreateFromAscii("$col$"),pColumn->GetName()); +// aStatus.Set(SDB_STAT_ERROR, +// String::CreateFromAscii("01000"), +// aStatus.CreateErrorMessage(aText), +// 0, strDetailed ); + return FALSE; + } + } + } + } + + // when we are here there is no double key in the table + + for (i = 0; i < m_pColumns->getCount(); i++) + { + m_pColumns->getByIndex(i) >>= xCol; + xCol->getFastPropertyValue(PROPERTY_ID_NAME) >>= aColName; + + // Laengen je nach Datentyp: + // nyi: eine zentrale Funktion, die die Laenge liefert! + USHORT nLen = (USHORT)getINT32(xCol->getFastPropertyValue(PROPERTY_ID_PRECISION)); + sal_Int32 nType = getINT32(xCol->getFastPropertyValue(PROPERTY_ID_TYPE)); + switch (nType) + { + case DataType::DATE: nLen = 8; break; + case DataType::DECIMAL: + nLen = SvDbaseConverter::ConvertPrecisionToDbase(nLen,getINT32(xCol->getFastPropertyValue(PROPERTY_ID_SCALE))); + break; // das Vorzeichen und das Komma + case DataType::BIT: nLen = 1; break; + case DataType::LONGVARCHAR:nLen = 10; break; + default: break; + + } + + sal_Int32 nPos = 0; + for(;nPos<_xCols->getCount();++nPos) + { + Reference<XFastPropertySet> xFindCol; + _xCols->getByIndex(nPos) >>= xFindCol; + if(aCase(getString(xFindCol->getFastPropertyValue(PROPERTY_ID_NAME)),aColName)) + break; + } + + if (nPos >= _xCols->getCount()) + { + nByteOffset += nLen; + continue; + } + + ++nPos; // the row values start at 1 + // ODbVariant* pVal = (*rRow)[nPos].getBodyPtr(); + if (aIndexedCols[i].is()) + { + Reference<XUnoTunnel> xTunnel(aIndexedCols[i],UNO_QUERY); + OSL_ENSHURE(xTunnel.is(),"No TunnelImplementation!"); + ODbaseIndex* pIndex = (ODbaseIndex*)xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()); + OSL_ENSHURE(pIndex,"ODbaseTable::UpdateBuffer: No Index returned!"); + // Update !! + if (pOrgRow.isValid() && !rRow[nPos].isNull() )//&& pVal->isModified()) + pIndex->Update(m_nFilePos,(*pOrgRow)[nPos],rRow[nPos]); + else + { + // ODbVariantRef xVar = (pVal == NULL) ? new ODbVariant() : pVal; + pIndex->Insert(m_nFilePos,rRow[nPos]); + } + } + + // Ist die Variable ueberhaupt gebunden? + if (!rRow[nPos].isBound() )//|| !pVal->isModified()) + { + // Nein - naechstes Feld. + nByteOffset += nLen; + continue; + } + + char* pData = (char *)(m_pBuffer + nByteOffset); + if (rRow[nPos].isNull()) + { + memset(pData,' ',nLen); // Zuruecksetzen auf NULL + nByteOffset += nLen; + continue; + } + try + { + switch (nType) + { + case DataType::DATE: + { + ::com::sun::star::util::Date aDate = DateConversion::toDate(rRow[nPos]); + char s[9]; + sprintf(s,"%04d%02d%02d", + (int)aDate.Year, + (int)aDate.Month, + (int)aDate.Day); + + // Genau 8 Byte kopieren: + strncpy(pData,s,sizeof s - 1); + } break; + case DataType::DECIMAL: + { + memset(pData,' ',nLen); // Zuruecksetzen auf NULL + + double n = rRow[nPos]; + + int nPrecision = (int)getINT32(xCol->getFastPropertyValue(PROPERTY_ID_PRECISION)); + int nScale = (int)getINT32(xCol->getFastPropertyValue(PROPERTY_ID_SCALE)); + // ein const_cast, da GetFormatPrecision am SvNumberFormat nicht const ist, obwohl es das eigentlich + // sein koennte und muesste + + String aString; + SolarMath::DoubleToString(aString,n,'F',nScale,'.'); + ByteString aDefaultValue(aString,gsl_getSystemTextEncoding()); + BOOL bValidLength = FALSE; + if (aDefaultValue.Len() <= nLen) + { + strncpy(pData,aDefaultValue.GetBuffer(),nLen); + // write the resulting double back + rRow[nPos] = toDouble(aDefaultValue); + bValidLength = TRUE; + } + if (!bValidLength) + { +// String strError(SdbResId(STR_DBF_INVALID_FIELD_VALUE)); +// strError.SearchAndReplace(String::CreateFromAscii("$name$"), pColumn->GetName()); +// +// String strDetailedInformation(SdbResId(STR_DBF_INVALID_FIELD_VALUE_DECIMAL)); +// strDetailedInformation.SearchAndReplace(String::CreateFromAscii("$name$"), pColumn->GetName()); +// strDetailedInformation.SearchAndReplace(String::CreateFromAscii("#length#"), nPrecision); +// strDetailedInformation.SearchAndReplace(String::CreateFromAscii("#scale#"), nScale); +// aStatus.Set(SDB_STAT_ERROR, String::CreateFromAscii("S1000"), aStatus.CreateErrorMessage(strError), 0, strDetailedInformation); + } + } break; + case DataType::BIT: + *pData = rRow[nPos].getBool() ? 'T' : 'F'; + break; + case DataType::LONGVARCHAR: + { + char cNext = pData[nLen]; // merken und temporaer durch 0 ersetzen + pData[nLen] = '\0'; // das geht, da der Puffer immer ein Zeichen groesser ist ... + + ULONG nBlockNo = strtol((const char *)pData,NULL,10); // Blocknummer lesen + + // Naechstes Anfangszeichen wieder restaurieren: + pData[nLen] = cNext; + if (!m_aMemoStream.IsOpen() || !WriteMemo(rRow[nPos], nBlockNo)) + break; + + ByteString aStr; + ByteString aBlock(ByteString::CreateFromInt32(nBlockNo)); + aStr.Expand(nLen - aBlock.Len(), '0'); + aStr += aBlock; + aStr.Convert(gsl_getSystemTextEncoding(),osl_getThreadTextEncoding()); + // Zeichen kopieren: + memset(pData,' ',nLen); // Zuruecksetzen auf NULL + memcpy(pData, aStr.GetBuffer(), nLen); + } break; + default: + { + memset(pData,' ',nLen); // Zuruecksetzen auf NULL + ByteString aStr(rRow[nPos].getString().getStr(),osl_getThreadTextEncoding()); + // Zeichen kopieren: + memcpy(pData, aStr.GetBuffer(), min(nLen,aStr.Len())); + } break; + } + } + catch ( ... ) + { +// String strError(SdbResId(STR_DBF_INVALID_FIELD_VALUE)); +// strError.SearchAndReplace(String::CreateFromAscii("$name$"), pColumn->GetName()); +// aStatus.Set(SDB_STAT_ERROR, String::CreateFromAscii("S1000"), aStatus.CreateErrorMessage(strError), 0, String()); + } +// if (aStatus.IsError()) +// break; + // Und weiter ... + nByteOffset += nLen; + } + return sal_True; +} + + +//------------------------------------------------------------------ +BOOL ODbaseTable::WriteBuffer() +{ + OSL_ENSHURE(m_nFilePos >= 1,"SdbDBFCursor::FileFetchRow: ungueltige Record-Position"); + + // Auf gewuenschten Record positionieren: + long nPos = m_aHeader.db_kopf + (long)(m_nFilePos-1) * m_aHeader.db_slng; + m_aFileStream.Seek(nPos); + return m_aFileStream.Write((char*) m_pBuffer, m_aHeader.db_slng) > 0; +} + + diff --git a/connectivity/source/drivers/dbase/DTables.cxx b/connectivity/source/drivers/dbase/DTables.cxx new file mode 100644 index 000000000000..2585efa8a5c0 --- /dev/null +++ b/connectivity/source/drivers/dbase/DTables.cxx @@ -0,0 +1,176 @@ +/************************************************************************* + * + * $RCSfile: DTables.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_DBASE_TABLES_HXX_ +#include "dbase/DTables.hxx" +#endif +#ifndef _CONNECTIVITY_DBASE_TABLE_HXX_ +#include "dbase/DTable.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ +#include <com/sun/star/sdbc/ColumnValue.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_KEYRULE_HPP_ +#include <com/sun/star/sdbc/KeyRule.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBCX_KEYTYPE_HPP_ +#include <com/sun/star/sdbcx/KeyType.hpp> +#endif +#ifndef _CONNECTIVITY_FILE_CATALOG_HXX_ +#include "file/FCatalog.hxx" +#endif +#ifndef _CONNECTIVITY_FILE_BCONNECTION_HXX_ +#include "file/FConnection.hxx" +#endif +#ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_ +#include <com/sun/star/lang/XUnoTunnel.hpp> +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +using namespace connectivity::dbase; +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; + +Reference< XNamed > ODbaseTables::createObject(const ::rtl::OUString& _rName) +{ + ::rtl::OUString aName,aSchema; + ODbaseTable* pRet = new ODbaseTable((ODbaseConnection*)static_cast<OFileCatalog&>(m_rParent).getConnection(), + _rName,::rtl::OUString::createFromAscii("TABLE")); + + Reference< XNamed > xRet = pRet; + + return xRet; +} +// ------------------------------------------------------------------------- +void ODbaseTables::impl_refresh( ) throw(RuntimeException) +{ + // static_cast<OFileCatalog&>(m_rParent).refreshTables(); +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > ODbaseTables::createEmptyObject() +{ + ODbaseTable* pRet = new ODbaseTable((ODbaseConnection*)static_cast<OFileCatalog&>(m_rParent).getConnection()); + Reference< XPropertySet > xRet = pRet; + return xRet; +} +typedef connectivity::sdbcx::OCollection ODbaseTables_BASE_BASE; +// ------------------------------------------------------------------------- +// XAppend +void SAL_CALL ODbaseTables::appendByDescriptor( const Reference< XPropertySet >& descriptor ) throw(SQLException, ElementExistException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + ::rtl::OUString aName = getString(descriptor->getPropertyValue(PROPERTY_NAME)); + ObjectMap::iterator aIter = m_aNameMap.find(aName); + if( aIter != m_aNameMap.end()) + throw ElementExistException(aName,*this); + + Reference<XUnoTunnel> xTunnel(descriptor,UNO_QUERY); + if(xTunnel.is()) + { + ODbaseTable* pTable = (ODbaseTable*)xTunnel->getSomething(ODbaseTable::getUnoTunnelImplementationId()); + if(pTable && pTable->CreateImpl()) + ODbaseTables_BASE_BASE::appendByDescriptor(descriptor); + } +} +// ------------------------------------------------------------------------- +// XDrop +void SAL_CALL ODbaseTables::dropByName( const ::rtl::OUString& elementName ) throw(SQLException, NoSuchElementException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + ObjectMap::iterator aIter = m_aNameMap.find(elementName); + if( aIter == m_aNameMap.end()) + throw NoSuchElementException(elementName,*this); + + Reference< XUnoTunnel> xTunnel(aIter->second.get(),UNO_QUERY); + if(xTunnel.is()) + { + ODbaseTable* pTable = (ODbaseTable*)xTunnel->getSomething(ODbaseTable::getUnoTunnelImplementationId()); + if(pTable && pTable->DropImpl()) + ODbaseTables_BASE_BASE::dropByName(elementName); + } + +} +// ------------------------------------------------------------------------- +void SAL_CALL ODbaseTables::dropByIndex( sal_Int32 index ) throw(SQLException, IndexOutOfBoundsException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + if (index < 0 || index >= getCount()) + throw IndexOutOfBoundsException(); + + dropByName((*m_aElements[index]).first); +} +// ------------------------------------------------------------------------- + diff --git a/connectivity/source/drivers/dbase/Dservices.cxx b/connectivity/source/drivers/dbase/Dservices.cxx new file mode 100644 index 000000000000..8a0c200523f0 --- /dev/null +++ b/connectivity/source/drivers/dbase/Dservices.cxx @@ -0,0 +1,211 @@ +/************************************************************************* + * + * $RCSfile: Dservices.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_DBASE_DDRIVER_HXX_ +#include "dbase/DDriver.hxx" +#endif +#ifndef _CPPUHELPER_FACTORY_HXX_ +#include <cppuhelper/factory.hxx> +#endif +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +using namespace connectivity::dbase; +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 + ); + +//*************************************************************************************** +// +// 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_ENSHURE(xNewKey.is(), "FILE::component_writeInfo : could not create a registry key !"); + + for (sal_uInt32 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); + } + catch(...) + { + } + return xRet.is(); + } + + void* getProvider() const { return xRet.get(); } +}; + +//--------------------------------------------------------------------------------------- + +extern "C" void SAL_CALL component_getImplementationEnvironment( + const sal_Char **ppEnvTypeName, + uno_Environment **ppEnv + ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +//--------------------------------------------------------------------------------------- +extern "C" 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( + ODriver::getImplementationName_Static(), + ODriver::getSupportedServiceNames_Static(), xKey); + + return sal_True; + } + catch (::com::sun::star::registry::InvalidRegistryException& ) + { + OSL_ENSHURE(sal_False, "FILE::component_writeInfo : could not create a registry key ! ## InvalidRegistryException !"); + } + + return sal_False; +} + +//--------------------------------------------------------------------------------------- +extern "C" 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( + ODriver::getImplementationName_Static(), + ODriver::getSupportedServiceNames_Static(), + ODriver_CreateInstance, ::cppu::createSingleFactory) + ; + + if(aReq.xRet.is()) + aReq.xRet->acquire(); + + pRet = aReq.getProvider(); + } + + return pRet; +}; + diff --git a/connectivity/source/drivers/dbase/dindexnode.cxx b/connectivity/source/drivers/dbase/dindexnode.cxx new file mode 100644 index 000000000000..5401bc213d8c --- /dev/null +++ b/connectivity/source/drivers/dbase/dindexnode.cxx @@ -0,0 +1,1006 @@ +/************************************************************************* + * + * $RCSfile: dindexnode.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_DBASE_INDEXNODE_HXX_ +#include "dbase/dindexnode.hxx" +#endif +#ifndef _CONNECTIVITY_COMMONTOOLS_HXX_ +#include "connectivity/CommonTools.hxx" +#endif +#ifndef _OSL_THREAD_H_ +#include <osl/thread.h> +#endif +#ifndef _CONNECTIVITY_DBASE_INDEX_HXX_ +#include "dbase/DIndex.hxx" +#endif + + +using namespace connectivity; +using namespace connectivity::dbase; +using namespace connectivity::file; +using namespace com::sun::star::sdbc; +//================================================================== +// Index Seite +//================================================================== +ONDXPage::ONDXPage(ODbaseIndex& rInd, sal_uInt32 nPos, ONDXPage* pParent) + :rIndex(rInd) + ,nPagePos(nPos) + ,nCount(0) + ,bModified(FALSE) + ,ppNodes(NULL) + ,m_refCount(0) +{ + sal_uInt16 nT=rIndex.getHeader().db_maxkeys; + ppNodes = new ONDXNode[nT]; + aParent = new ONDXPagePtr(pParent); + aChild = new ONDXPagePtr(); +} + +//------------------------------------------------------------------ +ONDXPage::~ONDXPage() +{ + delete[] ppNodes; + delete aParent; + delete aChild; +} +// ------------------------------------------------------------------------- +void ONDXPage::release() +{ + if (! osl_decrementInterlockedCount( &m_refCount )) + { + QueryDelete(); + delete this; + } +} +//------------------------------------------------------------------ +void ONDXPage::QueryDelete() +{ + // Ablegen im GarbageCollector + if (IsModified()) + rIndex.m_aFileStream << *this; + + bModified = FALSE; + if (rIndex.UseCollector()) + { + if ((*aChild).Is()) + (*aChild)->Release(FALSE); + + for (USHORT i = 0; i < rIndex.getHeader().db_maxkeys;i++) + { + if (ppNodes[i].GetChild().Is()) + ppNodes[i].GetChild()->Release(FALSE); + + ppNodes[i] = ONDXNode(); + } + // RestoreNoDelete(); + + nCount = 0; + (*aParent).Clear(); + rIndex.Collect(this); + } +// else +// SvRefBase::QueryDelete(); +} +//------------------------------------------------------------------ +ONDXPagePtr& ONDXPage::GetChild(ODbaseIndex* pIndex) +{ + if (!(*aChild).Is() && pIndex) + { + (*aChild) = rIndex.CreatePage((*aChild).GetPagePos(),this,(*aChild).HasPage()); + } + return (*aChild); +} + +//------------------------------------------------------------------ +USHORT ONDXPage::FindPos(const ONDXKey& rKey) const +{ + // sucht nach Platz fuer den vorgegeben key auf einer Seite + USHORT i = 0; + while (i < nCount && rKey > ((*this)[i]).GetKey()) + i++; + + return i; +} + +//------------------------------------------------------------------ +BOOL ONDXPage::Find(const ONDXKey& rKey) +{ + // sucht den vorgegeben key + // Besonderheit: gelangt der Algorithmus ans Ende + // wird immer die aktuelle Seite und die Knotenposition vermerkt + // auf die die Bedingung <= zutrifft + // dieses findet beim Insert besondere Beachtung + USHORT i = 0; + while (i < nCount && rKey > ((*this)[i]).GetKey()) + i++; + + BOOL bResult = FALSE; + + if (!IsLeaf()) + { + // weiter absteigen + ONDXPagePtr aPage = (i==0) ? GetChild(&rIndex) : ((*this)[i-1]).GetChild(&rIndex, this); + bResult = aPage.Is() && aPage->Find(rKey); + } + else if (i == nCount) + { + rIndex.m_aCurLeaf = this; + rIndex.m_nCurNode = i - 1; + bResult = FALSE; + } + else + { + bResult = rKey == ((*this)[i]).GetKey(); + rIndex.m_aCurLeaf = this; + rIndex.m_nCurNode = bResult ? i : i - 1; + } + return bResult; +} + +//------------------------------------------------------------------ +BOOL ONDXPage::Insert(ONDXNode& rNode, sal_uInt32 nRowsLeft) +{ + // beim Erzeugen eines Index koennen auch mehrere Knoten eingefuegt werden + // diese sin dann aufsteigend sortiert + BOOL bAppend = nRowsLeft > 0; + if (IsFull()) + { + BOOL bResult = TRUE; + ONDXNode aSplitNode; + if (bAppend) + aSplitNode = rNode; + else + { + // merken des letzten Knotens + aSplitNode = (*this)[nCount-1]; + if(rNode.GetKey() <= aSplitNode.GetKey()) + { + + // und damit habe ich im folgenden praktisch eine Node weniger + if (IsLeaf() && this == rIndex.m_aCurLeaf.getBodyPtr()) + { + // geht davon aus, dass der Knoten, auf dem die Bedingung (<=) + // zutrifft, als m_nCurNode gesetzt ist + --nCount; // (sonst bekomme ich u.U. Assertions und GPFs - 60593) + bResult = Insert(rIndex.m_nCurNode + 1, rNode); + } + else // Position unbekannt + { + USHORT nPos = NODE_NOTFOUND; + while (++nPos < nCount && rNode.GetKey() > ((*this)[nPos]).GetKey()); + + --nCount; // (sonst bekomme ich u.U. Assertions und GPFs - 60593) + bResult = Insert(nPos, rNode); + } + + // konnte der neue Knoten eingefuegt werden + if (!bResult) + { + nCount++; + aSplitNode = rNode; + } + } + else + aSplitNode = rNode; + } + + sal_uInt32 nNewPagePos = rIndex.GetPageCount(); + sal_uInt32 nNewPageCount = nNewPagePos + 1; + + // Herausgeloesten Knoten beim Vater einfuegen + if (!HasParent()) + { + // Kein Vater, dann neue Wurzel + ONDXPagePtr aNewRoot = rIndex.CreatePage(nNewPagePos + 1); + aNewRoot->SetChild(this); + + rIndex.m_aRoot = aNewRoot; + rIndex.SetRootPos(nNewPagePos + 1); + rIndex.SetPageCount(++nNewPageCount); + } + + // neues blatt erzeugen und Seite aufteilen + ONDXPagePtr aNewPage = rIndex.CreatePage(nNewPagePos,(*aParent).getBodyPtr()); + rIndex.SetPageCount(nNewPageCount); + + // wieviele Knoten weren noch eingefuegt + // kommen noch ausreichend, dann koennen die Seiten bis zum Rand vollgestopft werden + + ONDXNode aInnerNode; + if (!IsLeaf() || nRowsLeft < (sal_uInt32)(rIndex.GetMaxNodes() / 2)) + aInnerNode = Split(*aNewPage); + else + { + aInnerNode = (*this)[nCount - 1]; + //aInnerNode = aSplitNode; + + // Knoten zeigt auf neue Seite + aInnerNode.SetChild(aNewPage); + + // innere Knoten haben keine Recordnummer + if (rIndex.isUnique()) + aInnerNode.GetKey().ResetRecord(); + + // neue Seite zeigt nun auf Seite des herausgelsten Knoten + if (!IsLeaf()) + aNewPage->SetChild(aInnerNode.GetChild()); + } + + aNewPage->Append(aSplitNode); + ONDXPagePtr aTempParent = (*aParent); + if (IsLeaf()) + { + rIndex.m_aCurLeaf = aNewPage; + rIndex.m_nCurNode = rIndex.m_aCurLeaf->Count() - 1; + + // Freigeben nicht benoetigter Seiten, danach besteht keine Referenz + // mehr auf die Seite, danach kann 'this' nicht mehr gueltig sein!!! + ReleaseFull(); + } + + // Einfuegen des herausgeloesten Knotens + return aTempParent->Insert(aInnerNode); + } + else // Seite einfach weiter auffuellen + { + if (bAppend) + { + if (IsLeaf()) + rIndex.m_nCurNode = nCount - 1; + return Append(rNode); + } + else + { + USHORT nNodePos = FindPos(rNode.GetKey()); + if (IsLeaf()) + rIndex.m_nCurNode = nNodePos; + + return Insert(nNodePos, rNode); + } + } +} + +//------------------------------------------------------------------ +BOOL ONDXPage::Insert(USHORT nPos, ONDXNode& rNode) +{ + USHORT nMaxCount = rIndex.getHeader().db_maxkeys; + if (nPos >= nMaxCount) + return FALSE; + + if (nCount) + { + ++nCount; + // nach rechts verschieben + for (USHORT i = min(nMaxCount-1, nCount-1); nPos < i; i--) + (*this)[i] = (*this)[i-1]; + } + else + if (nCount < nMaxCount) + nCount++; + + // einfuegen an der Position + ONDXNode& rInsertNode = (*this)[nPos]; + rInsertNode = rNode; + if (rInsertNode.GetChild().Is()) + { + rInsertNode.GetChild()->SetParent(this); + rNode.GetChild()->SetParent(this); + } + + bModified = TRUE; + + return TRUE; +} + +//------------------------------------------------------------------ +BOOL ONDXPage::Append(ONDXNode& rNode) +{ + DBG_ASSERT(!IsFull(), "kein Append moeglich"); + return Insert(nCount, rNode); +} + +//------------------------------------------------------------------ +void ONDXPage::Remove(USHORT nPos) +{ + DBG_ASSERT(nCount > nPos, "falscher Indexzugriff"); + + for (USHORT i = nPos; i < (nCount-1); i++) + (*this)[i] = (*this)[i+1]; + + nCount--; + bModified = TRUE; +} + +//------------------------------------------------------------------ +void ONDXPage::Release(BOOL bSave) +{ + // freigeben der Pages + if ((*aChild).Is()) + (*aChild)->Release(bSave); + + // Pointer freigeben + (*aChild).Clear(); + + for (USHORT i = 0; i < rIndex.getHeader().db_maxkeys;i++) + { + if (ppNodes[i].GetChild().isValid()) + ppNodes[i].GetChild()->Release(bSave); + + ppNodes[i].GetChild().Clear(); + } + (*aParent) = NULL; +} +//------------------------------------------------------------------ +void ONDXPage::ReleaseFull(BOOL bSave) +{ + ONDXPagePtr aTempParent = (*aParent); + Release(bSave); + + if (aTempParent.Is()) + { + // Freigeben nicht benoetigter Seiten, danach besteht keine Referenz + // mehr auf die Seite, danach kann 'this' nicht mehr gueltig sein!!! + USHORT nParentPos = aTempParent->Search(this); + if (nParentPos != NODE_NOTFOUND) + (*aTempParent)[nParentPos].GetChild().Clear(); + else + aTempParent->GetChild().Clear(); + } +} + + +//------------------------------------------------------------------ +ONDXNode& ONDXPage::operator[] (USHORT nPos) +{ + DBG_ASSERT(nCount > nPos, "falscher Indexzugriff"); + return ppNodes[nPos]; +} + +//------------------------------------------------------------------ +const ONDXNode& ONDXPage::operator[] (USHORT nPos) const +{ + DBG_ASSERT(nCount > nPos, "falscher Indexzugriff"); + return ppNodes[nPos]; +} + +//------------------------------------------------------------------ +// laeuft rekursiv +void ONDXPage::SearchAndReplace(const ONDXKey& rSearch, + ONDXKey& rReplace) +{ + if (rSearch == rReplace) + return; + + USHORT nPos = NODE_NOTFOUND; + ONDXPage* pPage = this; + + while (pPage && (nPos = pPage->Search(rSearch)) == NODE_NOTFOUND) + pPage = pPage->aParent->getBodyPtr(); + + if (pPage) + { + (*pPage)[nPos].GetKey() = rReplace; + pPage->SetModified(TRUE); + } +} + +//------------------------------------------------------------------ +USHORT ONDXPage::Search(const ONDXKey& rSearch) +{ + // binare Suche spaeter + USHORT i = 0xFFFF; + while (++i < Count()) + if ((*this)[i].GetKey() == rSearch) + break; + + return (i < Count()) ? i : NODE_NOTFOUND; +} + +//------------------------------------------------------------------ +USHORT ONDXPage::Search(const ONDXPage* pPage) +{ + USHORT i = 0xFFFF; + while (++i < Count()) + if (((*this)[i]).GetChild().getBodyPtr() == pPage) + break; + + // wenn nicht gefunden, dann wird davon ausgegangen, dass die Seite selbst + // auf die Page zeigt + return (i < Count()) ? i : NODE_NOTFOUND; +} + +//------------------------------------------------------------------ +BOOL ONDXPage::Delete(USHORT nNodePos) +{ + if (IsLeaf()) + { + // Letztes Element wird geloescht + if (nNodePos == (nCount - 1)) + { + ONDXNode aNode = (*this)[nNodePos]; + + // beim Parent muss nun der KeyValue ausgetauscht werden + if (HasParent()) + (*aParent)->SearchAndReplace(aNode.GetKey(), + (*this)[nNodePos-1].GetKey()); + } + } + + // Loeschen des Knoten + Remove(nNodePos); + + // Unterlauf + if (HasParent() && nCount < (rIndex.GetMaxNodes() / 2)) + { + // Feststellen, welcher Knoten auf die Seite zeigt + USHORT nParentNodePos = (*aParent)->Search(this); + // letzte Element auf Vaterseite + // -> zusammenlegen mit vorletzter Seite + if (nParentNodePos == ((*aParent)->Count() - 1)) + { + if (!nParentNodePos) + // zusammenlegen mit linken nachbarn + Merge(nParentNodePos,(*aParent)->GetChild(&rIndex)); + else + Merge(nParentNodePos,(*(*aParent))[nParentNodePos-1].GetChild(&rIndex,(*aParent).getBodyPtr())); + } + // sonst Seite mit naechster Seite zusammenlegen + else + { + // zusammenlegen mit rechten nachbarn + Merge(nParentNodePos + 1,((*(*aParent))[nParentNodePos + 1].GetChild(&rIndex,(*aParent).getBodyPtr()))); + nParentNodePos++; + } + if (HasParent() && !(*(*aParent))[nParentNodePos].HasChild()) + (*aParent)->Delete(nParentNodePos); +/* + // letzte Element auf Vaterseite + // -> zusammenlegen mit vorletzter Seite + if (nParentNodePos == ((*aParent)->Count() - 1)) + { + if (!nParentNodePos) + // zusammenlegen mit linken nachbarn + Merge(nParentNodePos,(*aParent)->GetChild(&rIndex)); + else + Merge(nParentNodePos,(*(*aParent))[nParentNodePos-1].GetChild(&rIndex,(*aParent))); + } + // sonst Seite mit naechster Seite zusammenlegen + else if(nParentNodePos != NODE_NOTFOUND) + { + // zusammenlegen mit rechten nachbarn + Merge(nParentNodePos + 1,((*(*aParent))[nParentNodePos + 1].GetChild(&rIndex,(*aParent)))); + nParentNodePos++; + } + else // Sonderbehandlung + { + // Page ist (*aChild) Page vom Parent => erste Page aus ppNodes an (*aChild) anhngen + Merge(0,(*(*aParent))[0].GetChild(&rIndex,(*aParent))); + nParentNodePos = 0; + } + + if (HasParent() && !(*(*aParent))[nParentNodePos].HasChild()) + (*aParent)->Delete(nParentNodePos); +*/ + + } + else if (IsRoot()) + // Sicherstellen das die Position der Wurzel festgehalten wird + rIndex.SetRootPos(nPagePos); + return TRUE; +} + + +//------------------------------------------------------------------ +ONDXNode ONDXPage::Split(ONDXPage& rPage) +{ + DBG_ASSERT(IsFull(), "Falsches Splitting"); + /* Aufteilen einer Seite auf zwei + Blatt: + Seite 1 behaelt (n - (n/2)) + Seite 2 erhaelt (n/2) + Knoten n/2 wird dupliziert + Innerer Knoten: + Seite 1 behaelt (n+1)/2 + Seite 2 erhaelt (n/2-1) + Knoten ((n+1)/2 + 1) : wird herausgenommen + */ + ONDXNode aResultNode; + if (IsLeaf()) + { + for (USHORT i = (nCount - (nCount / 2)), j = 0 ; i < nCount; i++) + rPage.Insert(j++,(*this)[i]); + + // dieser Knoten enthaelt einen Schluessel der noch einmal im Tree vorkommt + // und ersetzt werden muss + ONDXNode aLastNode = (*this)[nCount - 1]; + nCount = nCount - (nCount / 2); + aResultNode = (*this)[nCount - 1]; + + if (HasParent()) + (*aParent)->SearchAndReplace(aLastNode.GetKey(), + aResultNode.GetKey()); + } + else + { + for (USHORT i = (nCount + 1) / 2 + 1, j = 0 ; i < nCount; i++) + rPage.Insert(j++,(*this)[i]); + + aResultNode = (*this)[(nCount + 1) / 2]; + nCount = (nCount + 1) / 2; + + // neue Seite zeigt nun auf Seite des herausgelsten Knoten + rPage.SetChild(aResultNode.GetChild()); + } + // Knoten zeigt auf neue Seite + aResultNode.SetChild(&rPage); + + // innere Knoten haben keine Recordnummer + if (rIndex.isUnique()) + aResultNode.GetKey().ResetRecord(); + bModified = TRUE; + return aResultNode; +} + +//------------------------------------------------------------------ +void ONDXPage::Merge(USHORT nParentNodePos, ONDXPagePtr xPage) +{ + DBG_ASSERT(HasParent(), "kein Vater vorhanden"); + DBG_ASSERT(nParentNodePos != NODE_NOTFOUND, "Falscher Indexaufbau"); + + /* Zusammenlegen zweier Seiten */ + ONDXNode aResultNode; + USHORT nMaxNodes = rIndex.GetMaxNodes(), + nMaxNodes_2 = nMaxNodes / 2; + + // Feststellen ob Seite rechter oder linker Nachbar + BOOL bRight = ((*xPage)[0].GetKey() > (*this)[0].GetKey()); // TRUE, wenn xPage die rechte Seite ist + USHORT nNewCount = (*xPage).Count() + Count(); + + if (IsLeaf()) + { + // Bedingung fuers zusammenlegen + if (nNewCount < (nMaxNodes_2 * 2)) + { + USHORT nLastNode = bRight ? Count() - 1 : xPage->Count() - 1; + if (bRight) + { + DBG_ASSERT(xPage.getBodyPtr() != this,"xPage und THIS drfen nicht gleich sein: Endlosschleife"); + // alle Knoten aus xPage auf den linken Knoten verschieben (anhngen) + while (xPage->Count()) + { + Append((*xPage)[0]); + xPage->Remove(0); + } + } + else + { + DBG_ASSERT(xPage.getBodyPtr() != this,"xPage und THIS drfen nicht gleich sein: Endlosschleife"); + // xPage ist die linke Page und THIS die rechte + while (xPage->Count()) + { + Insert(0,(*xPage)[xPage->Count()-1]); + xPage->Remove(xPage->Count()-1); + } + // alte Position von xPage beim Parent mit this ersetzen + if (nParentNodePos) + (*(*aParent))[nParentNodePos-1].SetChild(this,(*aParent).getBodyPtr()); + else // oder als rechten Knoten setzen + (*aParent)->SetChild(this); + (*aParent)->SetModified(TRUE); + + } + + // Child beziehung beim Vaterknoten aufheben + (*(*aParent))[nParentNodePos].SetChild(); + // Austauschen des KnotenWertes, nur wenn geaenderte Page + // die linke ist, ansonsten werde + + if((*aParent)->IsRoot() && (*aParent)->Count() == 1) + { + (*(*aParent))[0].SetChild(); + (*aParent)->ReleaseFull(); + (*aParent) = NULL; + rIndex.SetRootPos(nPagePos); + rIndex.m_aRoot = this; + SetModified(TRUE); + } + else + (*aParent)->SearchAndReplace((*this)[nLastNode].GetKey(),(*this)[nCount-1].GetKey()); + + xPage->SetModified(FALSE); + xPage->ReleaseFull(); // wird nicht mehr benoetigt + } + // Ausgleichen der Elemente nNewCount >= (nMaxNodes_2 * 2) + else + { + if (bRight) + { + // alle Knoten aus xPage auf den linken Knoten verschieben (anhngen) + ONDXNode aReplaceNode = (*this)[nCount - 1]; + while (nCount < nMaxNodes_2) + { + Append((*xPage)[0]); + xPage->Remove(0); + } + // Austauschen des KnotenWertes: Setzt alten letzten Wert durch den letzten von xPage + (*aParent)->SearchAndReplace(aReplaceNode.GetKey(),(*this)[nCount-1].GetKey()); + } + else + { + // alle Knoten aus this vor die xPage Knoten einfgen + ONDXNode aReplaceNode = (*this)[nCount - 1]; + while (xPage->Count() < nMaxNodes_2) + { + xPage->Insert(0,(*this)[nCount-1]); + Remove(nCount-1); + } + // Austauschen des KnotenWertes + (*aParent)->SearchAndReplace(aReplaceNode.GetKey(),(*this)[Count()-1].GetKey()); + } + } + } + else // !IsLeaf() + { + // Bedingung fuers zusammenlegen + if (nNewCount < nMaxNodes_2 * 2) + { + if (bRight) + { + DBG_ASSERT(xPage.getBodyPtr() != this,"xPage und THIS drfen nicht gleich sein: Endlosschleife"); + // Vaterknoten wird mit integriert + // erhaelt zunaechst Child von xPage + (*(*aParent))[nParentNodePos].SetChild(xPage->GetChild(),(*aParent).getBodyPtr()); + Append((*(*aParent))[nParentNodePos]); + for (USHORT i = 0 ; i < xPage->Count(); i++) + Append((*xPage)[i]); + } + else + { + DBG_ASSERT(xPage.getBodyPtr() != this,"xPage und THIS drfen nicht gleich sein: Endlosschleife"); + // Vaterknoten wird mit integriert + // erhaelt zunaechst Child + (*(*aParent))[nParentNodePos].SetChild(GetChild(),(*aParent).getBodyPtr()); // Parent merkt sich mein Child + Insert(0,(*(*aParent))[nParentNodePos]); // Node vom Parent bei mir einfgen + while (xPage->Count()) + { + Insert(0,(*xPage)[xPage->Count()-1]); + xPage->Remove(xPage->Count()-1); + } + SetChild(xPage->GetChild()); + + if (nParentNodePos) + (*(*aParent))[nParentNodePos-1].SetChild(this,(*aParent).getBodyPtr()); + else + (*aParent)->SetChild(this); + } + + // danach wird der Vaterknoten zurueckgesetzt + (*(*aParent))[nParentNodePos].SetChild(); + (*aParent)->SetModified(TRUE); + + if((*aParent)->IsRoot() && (*aParent)->Count() == 1) + { + (*(*aParent)).SetChild(); + (*aParent)->ReleaseFull(); + (*aParent) = NULL; + rIndex.SetRootPos(nPagePos); + rIndex.m_aRoot = this; + SetModified(TRUE); + } + else if(nParentNodePos) + // Austauschen des KnotenWertes + // beim Append wird der Bereich erweitert, beim INsert verweist der alte Knoten von xPage auf this + // deshalb mu der Knoten auch hier aktualisiert werden + (*aParent)->SearchAndReplace((*(*aParent))[nParentNodePos-1].GetKey(),(*(*aParent))[nParentNodePos].GetKey()); + + xPage->SetModified(FALSE); + xPage->ReleaseFull(); + } + // Ausgleichen der Elemente + else + { + if (bRight) + { + while (nCount < nMaxNodes_2) + { + (*(*aParent))[nParentNodePos].SetChild(xPage->GetChild(),(*aParent).getBodyPtr()); + Append((*(*aParent))[nParentNodePos]); + (*(*aParent))[nParentNodePos] = (*xPage)[0]; + xPage->Remove(0); + } + xPage->SetChild((*(*aParent))[nParentNodePos].GetChild()); + (*(*aParent))[nParentNodePos].SetChild(xPage,(*aParent).getBodyPtr()); + } + else + { + while (nCount < nMaxNodes_2) + { + (*(*aParent))[nParentNodePos].SetChild(GetChild(),(*aParent).getBodyPtr()); + Insert(0,(*(*aParent))[nParentNodePos]); + (*(*aParent))[nParentNodePos] = (*xPage)[xPage->Count()-1]; + xPage->Remove(xPage->Count()-1); + } + SetChild((*(*aParent))[nParentNodePos].GetChild()); + (*(*aParent))[nParentNodePos].SetChild(this,(*aParent).getBodyPtr()); + + } + (*aParent)->SetModified(TRUE); + } + } +} +// ------------------------------------------------------------------------- +BOOL ONDXPage::IsFull() const +{ + return Count() == rIndex.getHeader().db_maxkeys; +} + +#ifdef DEBUG +//------------------------------------------------------------------ +void ONDXPage::PrintPage() +{ + DBG_TRACE4("\nSDB: -----------Page: %d Parent: %d Count: %d Child: %d-----", + nPagePos, HasParent() ? (*aParent)->GetPagePos() : 0 ,nCount, (*aChild).GetPagePos()); + + for (USHORT i = 0; i < nCount; i++) + { + ONDXNode rNode = (*this)[i]; + ONDXKey& rKey = rNode.GetKey(); + if (!IsLeaf()) + rNode.GetChild(&rIndex, this); + + if (!rKey.getValue().hasValue()) + { + DBG_TRACE2("SDB: [%d,NULL,%d]",rKey.GetRecord(), rNode.GetChild().GetPagePos()); + } + else if (rIndex.getHeader().db_keytype) + { + DBG_TRACE3("SDB: [%d,%f,%d]",rKey.GetRecord(), getDouble(rKey.getValue()),rNode.GetChild().GetPagePos()); + } + else + { + DBG_TRACE3("SDB: [%d,%s,%d]",rKey.GetRecord(), (const char* )ByteString(getString(rKey.getValue()).getStr(), gsl_getSystemTextEncoding()).GetBuffer(),rNode.GetChild().GetPagePos()); + } + } + DBG_TRACE("SDB: -----------------------------------------------\n"); + if (!IsLeaf()) + { + GetChild(&rIndex)->PrintPage(); + for (USHORT i = 0; i < nCount; i++) + { + ONDXNode rNode = (*this)[i]; + rNode.GetChild(&rIndex,this)->PrintPage(); + } + } + DBG_TRACE("SDB: ===============================================\n"); +} +#endif + + +static UINT32 nValue; +//------------------------------------------------------------------ +SvStream& connectivity::dbase::operator >> (SvStream &rStream, ONDXPage& rPage) +{ + rStream.Seek(rPage.GetPagePos() * 512); + rStream >> nValue >> (*rPage.aChild); + rPage.nCount = USHORT(nValue); + +// DBG_ASSERT(rPage.nCount && rPage.nCount < rPage.GetIndex().GetMaxNodes(), "Falscher Count"); + for (USHORT i = 0; i < rPage.nCount; i++) + rPage[i].Read(rStream, rPage.GetIndex()); + return rStream; +} + +//------------------------------------------------------------------ +SvStream& connectivity::dbase::operator << (SvStream &rStream, const ONDXPage& rPage) +{ + // Seite existiert noch nicht + if ((rPage.GetPagePos() + 1) * 512 > rStream.Seek(STREAM_SEEK_TO_END)) + rStream.SetStreamSize((rPage.GetPagePos() + 1) * 512); + rStream.Seek(rPage.GetPagePos() * 512); + + nValue = rPage.nCount; + rStream << nValue << (*rPage.aChild); + + for (USHORT i = 0; i < rPage.nCount; i++) + rPage[i].Write(rStream, rPage); + return rStream; +} + +//================================================================== +// ONDXNode +//================================================================== + +//------------------------------------------------------------------ +void ONDXNode::Read(SvStream &rStream, ODbaseIndex& rIndex) +{ + rStream >> aKey.nRecord; // schluessel + if (rIndex.getHeader().db_keytype) + { + double aDbl; + rStream >> aDbl; + aKey = ONDXKey(aDbl,aKey.nRecord); + } + else + { + ByteString aBuf; + USHORT nLen = rIndex.getHeader().db_keylen; + char* pStr = aBuf.AllocBuffer(nLen+1); + + rStream.Read(pStr,nLen); + pStr[nLen] = 0; + aBuf.ReleaseBufferAccess(); + aBuf.EraseTrailingChars(); + + // aKey = ONDXKey((aBuf,rIndex.GetDBFConnection()->GetCharacterSet()) ,aKey.nRecord); + aKey = ONDXKey((aBuf,osl_getThreadTextEncoding()) ,aKey.nRecord); + } + rStream >> aChild; +} + +union +{ + double aDbl; + char aData[128]; +} aNodeData; +//------------------------------------------------------------------ +void ONDXNode::Write(SvStream &rStream, const ONDXPage& rPage) const +{ + const ODbaseIndex& rIndex = rPage.GetIndex(); + if (!rIndex.isUnique() || rPage.IsLeaf()) + rStream << aKey.nRecord; // schluessel + else + rStream << (sal_uInt32)0; // schluessel + + if (rIndex.getHeader().db_keytype) // double + { + if (!aKey.getValue().hasValue()) + { + memset(aNodeData.aData,0,rIndex.getHeader().db_keylen); + rStream.Write((BYTE*)aNodeData.aData,rIndex.getHeader().db_keylen); + } + else + rStream << (double) getDouble(aKey.getValue()); + } + else + { + memset(aNodeData.aData,0x20,rIndex.getHeader().db_keylen); + if (aKey.getValue().hasValue()) + { + // ODBFConnection *pCon = rIndex.GetDBFConnection(); + if (NULL) + { + ByteString aText(getString(aKey.getValue()).getStr(), gsl_getSystemTextEncoding());//pCon->GetCharacterSet()); + strncpy(aNodeData.aData,aText.GetBuffer(),min(rIndex.getHeader().db_keylen, aText.Len())); + } + else + { + DBG_ERROR("No Connection"); + ByteString aText(getString(aKey.getValue()).getStr(), gsl_getSystemTextEncoding()); + strncpy(aNodeData.aData,aText.GetBuffer(),min(rIndex.getHeader().db_keylen, aText.Len())); + } + } + rStream.Write((BYTE*)aNodeData.aData,rIndex.getHeader().db_keylen); + } + rStream << aChild; +} + + +//------------------------------------------------------------------ +ONDXPagePtr& ONDXNode::GetChild(ODbaseIndex* pIndex, ONDXPage* pParent) +{ + if (!aChild.Is() && pIndex) + { + aChild = pIndex->CreatePage(aChild.GetPagePos(),pParent,aChild.HasPage()); + } + return aChild; +} + +//================================================================== +// ONDXKey +//================================================================== +//------------------------------------------------------------------ +BOOL ONDXKey::IsText(sal_Int32 eType) +{ + return eType == DataType::VARCHAR || eType == DataType::CHAR; +} + +//------------------------------------------------------------------ +StringCompare ONDXKey::Compare(const ONDXKey& rKey) const +{ + // DBG_ASSERT(is(), "Falscher Indexzugriff"); + StringCompare eResult; + + if (!getValue().getValue() || !getValue().hasValue()) + { + if (!rKey.getValue().getValue() || !rKey.getValue().hasValue() || (rKey.IsText(getDBType()) && !getString(rKey.getValue()).getLength())) + eResult = COMPARE_EQUAL; + else + eResult = COMPARE_LESS; + } + else if (!rKey.getValue().getValue() || !rKey.getValue().hasValue()) + { + if (!getValue().getValue() || !getValue().hasValue() || (IsText(getDBType()) && !getString(getValue()).getLength())) + eResult = COMPARE_EQUAL; + else + eResult = COMPARE_GREATER; + } + else if (IsText(getDBType())) + { + INT32 nRes = getString(getValue()).compareTo(getString(rKey.getValue())); + eResult = (nRes > 0) ? COMPARE_GREATER : (nRes == 0) ? COMPARE_EQUAL : COMPARE_LESS; + } + else + { + double m,n; + getValue() >>= m; + rKey.getValue() >>= n; + + eResult = (m > n) ? COMPARE_GREATER : (n == m) ? COMPARE_EQUAL : COMPARE_LESS; + } + + // Record vergleich, wenn Index !Unique + if (eResult == COMPARE_EQUAL && nRecord && rKey.nRecord) + eResult = (nRecord > rKey.nRecord) ? COMPARE_GREATER : + (nRecord == rKey.nRecord) ? COMPARE_EQUAL : COMPARE_LESS; + + return eResult; +} + diff --git a/connectivity/source/drivers/dbase/exports.dxp b/connectivity/source/drivers/dbase/exports.dxp new file mode 100644 index 000000000000..9630d7e06768 --- /dev/null +++ b/connectivity/source/drivers/dbase/exports.dxp @@ -0,0 +1,3 @@ +component_getImplementationEnvironment +component_writeInfo +component_getFactory diff --git a/connectivity/source/drivers/dbase/makefile.mk b/connectivity/source/drivers/dbase/makefile.mk new file mode 100644 index 000000000000..0de686b1f257 --- /dev/null +++ b/connectivity/source/drivers/dbase/makefile.mk @@ -0,0 +1,132 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/..$/.. +PRJINC=..$/.. +PRJNAME=connectivity +TARGET=dbase + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ---------------------------------- +.IF "$(DBGUTIL_OJ)"!="" +ENVCFLAGS+=/FR$(SLO)$/ +.ENDIF + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/version.mk + + +# --- Files ------------------------------------- + +SLOFILES=\ + $(SLO)$/dindexnode.obj \ + $(SLO)$/DIndexPage.obj \ + $(SLO)$/DIndexIter.obj \ + $(SLO)$/DDatabaseMetaData.obj \ + $(SLO)$/DCatalog.obj \ + $(SLO)$/DColumns.obj \ + $(SLO)$/DIndexColumns.obj \ + $(SLO)$/DIndex.obj \ + $(SLO)$/DIndexes.obj \ + $(SLO)$/DTable.obj \ + $(SLO)$/DTables.obj \ + $(SLO)$/DConnection.obj \ + $(SLO)$/Dservices.obj \ + $(SLO)$/DDriver.obj + + + +# --- Library ----------------------------------- + +SHL1TARGET= $(DBASE_TARGET)$(DBASE_MAJOR) +SHL1OBJS=$(SLOFILES) +SHL1STDLIBS=\ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(VOSLIB) \ + $(OSLLIB) \ + $(SVLLIB) \ + $(SVLIB) \ + $(TOOLSLIB) \ + $(UCBHELPERLIB) \ + $(SALLIB) + +SHL1DEPN= +SHL1IMPLIB= i$(DBASE_TARGET) +SHL1LIBS= $(SLB)$/commontools.lib \ + $(SLB)$/resource.lib \ + $(SLB)$/sdbcx.lib \ + $(SLB)$/file.lib \ + $(SLB)$/sql.lib + +SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME= $(SHL1TARGET) +DEF1EXPORTFILE= exports.dxp + + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + + diff --git a/connectivity/source/drivers/file/FCatalog.cxx b/connectivity/source/drivers/file/FCatalog.cxx new file mode 100644 index 000000000000..7e7a38415d8d --- /dev/null +++ b/connectivity/source/drivers/file/FCatalog.cxx @@ -0,0 +1,136 @@ +/************************************************************************* + * + * $RCSfile: FCatalog.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_FILE_CATALOG_HXX_ +#include "file/FCatalog.hxx" +#endif +#ifndef _CONNECTIVITY_FILE_BCONNECTION_HXX_ +#include "file/FConnection.hxx" +#endif +#ifndef _CONNECTIVITY_FILE_TABLES_HXX_ +#include "file/FTables.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +//#ifndef _CONNECTIVITY_FILE_OEMPTYCOLLECTION_HXX_ +//#include "file/FEmptyCollection.hxx" +//#endif + +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::file; +// ------------------------------------------------------------------------- +OFileCatalog::OFileCatalog(OConnection* _pCon) : connectivity::sdbcx::OCatalog(_pCon) + ,m_pConnection(_pCon) + ,m_xMetaData(m_pConnection->getMetaData( )) +{ +} +// ------------------------------------------------------------------------- +void SAL_CALL OFileCatalog::disposing() +{ + ::osl::MutexGuard aGuard(m_aMutex); + + typedef connectivity::sdbcx::OCatalog OFileCatalog_BASE; + m_xMetaData = NULL; + OFileCatalog_BASE::disposing(); +} +// ------------------------------------------------------------------------- +void OFileCatalog::refreshTables() +{ + ::std::vector< ::rtl::OUString> aVector; + Sequence< ::rtl::OUString > aTypes(1); + aTypes[0] = ::rtl::OUString::createFromAscii("%"); + 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) + delete m_pTables; + m_pTables = new OTables(m_xMetaData,*this,m_aMutex,aVector); +} + +// ------------------------------------------------------------------------- +Any SAL_CALL OFileCatalog::queryInterface( const Type & rType ) throw(RuntimeException) +{ + if( rType == ::getCppuType((const Reference<XGroupsSupplier>*)0) || + rType == ::getCppuType((const Reference<XUsersSupplier>*)0) || + rType == ::getCppuType((const Reference<XViewsSupplier>*)0)) + return Any(); + + + typedef sdbcx::OCatalog OFileCatalog_BASE; + return OFileCatalog_BASE::queryInterface(rType); +} + diff --git a/connectivity/source/drivers/file/FColumns.cxx b/connectivity/source/drivers/file/FColumns.cxx new file mode 100644 index 000000000000..a80367236e50 --- /dev/null +++ b/connectivity/source/drivers/file/FColumns.cxx @@ -0,0 +1,142 @@ +/************************************************************************* + * + * $RCSfile: FColumns.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_FILE_COLUMNS_HXX_ +#include "file/FColumns.hxx" +#endif +#ifndef _CONNECTIVITY_SDBCX_COLUMN_HXX_ +#include "connectivity/sdbcx/VColumn.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ +#include <com/sun/star/sdbc/ColumnValue.hpp> +#endif +#ifndef _CONNECTIVITY_FILE_TABLE_HXX_ +#include "file/FTable.hxx" +#endif + +using namespace connectivity::file; +using namespace connectivity; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::sdbcx; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; + +typedef connectivity::sdbcx::OCollection OCollection_TYPE; + +Reference< XNamed > OColumns::createObject(const ::rtl::OUString& _rName) +{ + + Reference< XResultSet > xResult = m_pTable->getConnection()->getMetaData()->getColumns(Any(), + m_pTable->getSchema(),m_pTable->getName(),_rName); + + Reference< XNamed > xRet = NULL; + if(xResult.is()) + { + Reference< XRow > xRow(xResult,UNO_QUERY); + while(xResult->next()) + { + if(xRow->getString(4) == _rName) + { + sdbcx::OColumn* pRet = new sdbcx::OColumn(_rName, + xRow->getString(6), + xRow->getString(13), + xRow->getInt(11), + xRow->getInt(7), + xRow->getInt(9), + xRow->getInt(5), + sal_False, + sal_False, + sal_False, + m_pTable->getConnection()->getMetaData()->storesMixedCaseQuotedIdentifiers()); + xRet = pRet; + break; + } + } + } + + return xRet; +} + +// ------------------------------------------------------------------------- +void OColumns::impl_refresh() throw(RuntimeException) +{ + m_pTable->refreshColumns(); +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > OColumns::createEmptyObject() +{ + sdbcx::OColumn* pRet = new sdbcx::OColumn(m_pTable->getConnection()->getMetaData()->storesMixedCaseQuotedIdentifiers()); + Reference< XPropertySet > xRet = pRet; + return xRet; +} + + diff --git a/connectivity/source/drivers/file/FConnection.cxx b/connectivity/source/drivers/file/FConnection.cxx new file mode 100644 index 000000000000..13295d74c3bb --- /dev/null +++ b/connectivity/source/drivers/file/FConnection.cxx @@ -0,0 +1,451 @@ +/************************************************************************* + * + * $RCSfile: FConnection.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_FILE_OCONNECTION_HXX_ +#include "file/FConnection.hxx" +#endif +#ifndef _CONNECTIVITY_FILE_ODATABASEMETADATA_HXX_ +#include "file/FDatabaseMetaData.hxx" +#endif +#ifndef _CONNECTIVITY_RESOURCE_HRC_ +#include "Resource.hrc" +#endif +#ifndef _CONNECTIVITY_MODULECONTEXT_HXX_ +#include "ModuleContext.hxx" +#endif +#ifndef _CONNECTIVITY_FILE_ODRIVER_HXX_ +#include "file/FDriver.hxx" +#endif +#ifndef _CONNECTIVITY_FILE_OSTATEMENT_HXX_ +#include "file/FStatement.hxx" +#endif +#ifndef _CONNECTIVITY_FILE_OPREPAREDSTATEMENT_HXX_ +#include "file/FPreparedStatement.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ +#include <com/sun/star/sdbc/ColumnValue.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_ +#include <com/sun/star/container/XChild.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENT_HPP_ +#include <com/sun/star/ucb/XContent.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTIDENTIFIER_HPP_ +#include <com/sun/star/ucb/XContentIdentifier.hpp> +#endif +#ifndef _URLOBJ_HXX //autogen wg. INetURLObject +#include <tools/urlobj.hxx> +#endif +#ifndef _FSYS_HXX //autogen +#include <tools/fsys.hxx> +#endif +#ifndef _CONNECTIVITY_FILE_CATALOG_HXX_ +#include "file/FCatalog.hxx" +#endif +#ifndef _COM_SUN_STAR_FRAME_XCONFIGMANAGER_HPP_ +#include <com/sun/star/frame/XConfigManager.hpp> +#endif +#ifndef _UCBHELPER_CONTENT_HXX +#include <ucbhelper/content.hxx> +#endif + +using namespace connectivity::file; + +//------------------------------------------------------------------------------ +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::ucb; +using namespace rtl; +// -------------------------------------------------------------------------------- +OConnection::OConnection(OFileDriver* _pDriver) + : OConnection_BASE(m_aMutex), + OSubComponent<OConnection>((::cppu::OWeakObject*)_pDriver), + m_pDriver(_pDriver), + m_bClosed(sal_False), + m_xMetaData(NULL) +{ + ModuleContext::AddRef(); +} +//----------------------------------------------------------------------------- +OConnection::~OConnection() +{ + if(!isClosed( )) + close(); + ModuleContext::ReleaseRef(); +} +//----------------------------------------------------------------------------- +void SAL_CALL OConnection::release() throw(RuntimeException) +{ + relase_ChildImpl(); + OConnection_BASE::release(); +} + +//----------------------------------------------------------------------------- +void OConnection::construct(const ::rtl::OUString& url,const Sequence< PropertyValue >& info) throw(SQLException) +{ + osl_incrementInterlockedCount( &m_refCount ); + + sal_Int32 nLen = url.indexOf(':'); + nLen = url.indexOf(':',nLen+1); + ::rtl::OUString aDSN(url.copy(nLen+1)),aUID,aPWD; + + INetURLObject aURL; + aURL.SetSmartProtocol(INET_PROT_FILE); + aURL.SetURL(aDSN, INetURLObject::ENCODE_ALL); + + + // String aFileName = aURL.PathToFileName(); + String aFileName = aURL.GetMainURL(); + + if(!aFileName.Len()) + aFileName = aDSN; + String aWildcard; + + if (aURL.GetProtocol() == INET_PROT_FILE) + { + // $Inst mu gesetzt sein + // sehr umstaendlicher weg, um an den Inimanager zu kommen + // aber ohne Arme(Sfx) keine Kekse + Reference< ::com::sun::star::frame::XConfigManager > xSofficeIni( + m_pDriver->getFactory()->createInstance(rtl::OUString::createFromAscii("com.sun.star.config.SpecialConfigManager")), UNO_QUERY); + + aFileName = xSofficeIni->substituteVariables(aDSN); + } + + ::rtl::OUString aExt; + const PropertyValue *pBegin = info.getConstArray(); + const PropertyValue *pEnd = pBegin + info.getLength(); + for(;pBegin != pEnd;++pBegin) + { + if(!pBegin->Name.compareToAscii("EXTENSTION")) + pBegin->Value >>= aExt; + } + + m_aFilenameExtension = aExt; + + ::ucb::Content aFile(aFileName,Reference< ::com::sun::star::ucb::XCommandEnvironment >()); + +// if (aFileStat.IsKind(FSYS_KIND_WILD)) +// { +// m_aDirectoryName = (DirEntry(aFileName).GetPath()).GetFull(); +// m_aFilenameExtension = DirEntry(aFileName).GetExtension(); +// +// // nyi: Verschiedene Extensions (aufgrund des angegebenen Wildcard) +// // (bisher keine Wildcard in der Extension moeglich!) +// aWildcard = DirEntry(aFileName).GetName(); +// } else + + // set fields to fetch + Sequence< OUString > aProps(1); + OUString* pProps = aProps.getArray(); + pProps[ 0 ] = OUString::createFromAscii( "Title" ); + + if (aFile.isFolder()) + { + m_xDir = aFile.createCursor(aProps, ::ucb::INCLUDE_DOCUMENTS_ONLY ); + m_xContent = aFile.get(); + } + else if (aFile.isDocument()) + { + Reference<XContent> xParent(Reference<XChild>(aFile.get(),UNO_QUERY)->getParent(),UNO_QUERY); + Reference<XContentIdentifier> xIdent = xParent->getIdentifier(); + m_xContent = xParent; + + ::ucb::Content aParent(xIdent->getContentIdentifier(),Reference< XCommandEnvironment >()); + m_xDir = aParent.createCursor(aProps, ::ucb::INCLUDE_DOCUMENTS_ONLY ); + } + else + throw SQLException(); + + if (m_aFilenameExtension.Search('*') != STRING_NOTFOUND || m_aFilenameExtension.Search('?') != STRING_NOTFOUND) + throw SQLException(); + + osl_decrementInterlockedCount( &m_refCount ); +} +// XServiceInfo +// -------------------------------------------------------------------------------- +IMPLEMENT_SERVICE_INFO(OConnection, "com.sun.star.sdbc.drivers.file.Connection", "com.sun.star.sdbc.Connection") + +// -------------------------------------------------------------------------------- +Reference< XStatement > SAL_CALL OConnection::createStatement( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + OStatement* pStmt = new OStatement(this); + + m_aStatements.push_back(WeakReferenceHelper(*pStmt)); + return pStmt; +} +// -------------------------------------------------------------------------------- +Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + OPreparedStatement* pStmt = new OPreparedStatement(this,m_aTypeInfo); + pStmt->construct(sql); + m_aStatements.push_back(WeakReferenceHelper(*pStmt)); + return pStmt; +} +// -------------------------------------------------------------------------------- +Reference< XPreparedStatement > SAL_CALL OConnection::prepareCall( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + return NULL; +} +// -------------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OConnection::nativeSQL( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sql; +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::setAutoCommit( sal_Bool autoCommit ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_bAutoCommit = autoCommit; +} +// -------------------------------------------------------------------------------- +sal_Bool SAL_CALL OConnection::getAutoCommit( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return m_bAutoCommit; +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::commit( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::rollback( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + +} +// -------------------------------------------------------------------------------- +sal_Bool SAL_CALL OConnection::isClosed( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return OConnection_BASE::rBHelper.bDisposed; +} +// -------------------------------------------------------------------------------- +Reference< XDatabaseMetaData > SAL_CALL OConnection::getMetaData( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(!m_xMetaData.is()) + m_xMetaData = new ODatabaseMetaData(this); + + return m_xMetaData; +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::setReadOnly( sal_Bool readOnly ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_bReadOnly = readOnly; +} +// -------------------------------------------------------------------------------- +sal_Bool SAL_CALL OConnection::isReadOnly( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return m_bReadOnly; +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::setCatalog( const ::rtl::OUString& catalog ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); +} +// -------------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OConnection::getCatalog( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return ::rtl::OUString(); +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::setTransactionIsolation( sal_Int32 level ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + +} +// -------------------------------------------------------------------------------- +sal_Int32 SAL_CALL OConnection::getTransactionIsolation( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return 0; +} +// -------------------------------------------------------------------------------- +Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OConnection::getTypeMap( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return NULL; +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::setTypeMap( const Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(SQLException, RuntimeException) +{ +} +// -------------------------------------------------------------------------------- +// XCloseable +void SAL_CALL OConnection::close( ) throw(SQLException, RuntimeException) +{ + { + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + } + dispose(); +} +// -------------------------------------------------------------------------------- +// XWarningsSupplier +Any SAL_CALL OConnection::getWarnings( ) throw(SQLException, RuntimeException) +{ + return Any(); +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::clearWarnings( ) throw(SQLException, RuntimeException) +{ +} +//------------------------------------------------------------------------------ +void OConnection::disposing() +{ + ::osl::MutexGuard aGuard(m_aMutex); + + + // m_aTables.disposing(); + for (OWeakRefArray::iterator i = m_aStatements.begin(); m_aStatements.end() != i; ++i) + { + Reference< XComponent > xComp(i->get(), UNO_QUERY); + if (xComp.is()) + xComp->dispose(); + } + m_aStatements.clear(); + + m_bClosed = sal_True; + m_xMetaData = NULL; + m_xDir = NULL; + + dispose_ChildImpl(); + OConnection_BASE::disposing(); +} +//------------------------------------------------------------------------------ +::com::sun::star::uno::Reference< XTablesSupplier > OConnection::createCatalog() +{ + ::osl::MutexGuard aGuard( m_aMutex ); + Reference< XTablesSupplier > xTab = m_xCatalog; + if(!m_xCatalog.get().is()) + { + OFileCatalog *pCat = new OFileCatalog(this); + xTab = pCat; + m_xCatalog = xTab; + } + return xTab; +} + + diff --git a/connectivity/source/drivers/file/FDatabaseMetaData.cxx b/connectivity/source/drivers/file/FDatabaseMetaData.cxx new file mode 100644 index 000000000000..393273b485c4 --- /dev/null +++ b/connectivity/source/drivers/file/FDatabaseMetaData.cxx @@ -0,0 +1,1327 @@ +/************************************************************************* + * + * $RCSfile: FDatabaseMetaData.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_FILE_ODATABASEMETADATA_HXX_ +#include "file/FDatabaseMetaData.hxx" +#endif +#ifndef _CONNECTIVITY_FILE_ORESULTSET_HXX_ +#include "file/FDatabaseMetaDataResultSet.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_RESULTSETTYPE_HPP_ +#include <com/sun/star/sdbc/ResultSetType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_RESULTSETCONCURRENCY_HPP_ +#include <com/sun/star/sdbc/ResultSetConcurrency.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_SEARCHRECURSION_HPP_ +#include <com/sun/star/ucb/SearchRecursion.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_SEARCHCOMMANDARGUMENT_HPP_ +#include <com/sun/star/ucb/SearchCommandArgument.hpp> +#endif +#ifndef _URLOBJ_HXX //autogen wg. INetURLObject +#include <tools/urlobj.hxx> +#endif + +using namespace com::sun::star::ucb; +using namespace connectivity::file; +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; + +ODatabaseMetaData::ODatabaseMetaData(OConnection* _pCon) + : m_pConnection(_pCon) +{ + m_pConnection->acquire(); +} +// ------------------------------------------------------------------------- +ODatabaseMetaData::~ODatabaseMetaData() +{ + if (m_pConnection) + m_pConnection->release(); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + +// OResultSet* pResult = new OResultSet(hStmt); +// Reference< XResultSet > xRef = pResult; +// pResult->openTypeInfo(); +// return xRef; + return Reference< XResultSet >(); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getCatalogs( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + +// +// OResultSet* pResult = new OResultSet(hStmt); +// Reference< XResultSet > xRef = pResult; +// pResult->openCatalogs(); +// return xRef; + return Reference< XResultSet >(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getCatalogSeparator( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + ::rtl::OUString aVal; + return aVal; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getSchemas( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + +// OResultSet* pResult = new OResultSet(hStmt); +// Reference< XResultSet > xRef = pResult; +// pResult->openSchemas(); +// return xRef; + return Reference< XResultSet >(); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumnPrivileges( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, + const ::rtl::OUString& columnNamePattern ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + +// OResultSet* pResult = new OResultSet(hStmt); +// Reference< XResultSet > xRef = pResult; +// pResult->openColumnPrivileges(catalog,schema,table,columnNamePattern); +// return xRef; + return Reference< XResultSet >(); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns( + const Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& tableNamePattern, + const ::rtl::OUString& columnNamePattern ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + +// OResultSet* pResult = new OResultSet(hStmt); +// Reference< XResultSet > xRef = pResult; +// pResult->openColumns(catalog,schemaPattern,tableNamePattern,columnNamePattern); +// return xRef; + return Reference< XResultSet >(); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::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(); + Reference< XResultSet > xRef = pResult; + pResult->setTablesMap(); +#if 0 + ORows aRows; + + Reference<XContent> xContent = m_pConnection->getContent(); + + Sequence<RuleTerm> aRules(1); + aRules[0].Property = OUString::createFromAscii( "Title" ); + aRules[0].Operand <<= tableNamePattern; + aRules[0].Operator = + aRules[0].CaseSensitive + aRules[0].RegularExpression = sal_False; + + SearchCriterium aCrit(aRules); + + SearchInfo aInfo; + aInfo.Recursion = 0; + aInfo.IncludeBase = sal_False; + aInfo.RespectFolderViewRestrictions = sal_False; + aInfo.RespectDocViewRestrictions = sal_False; + aInfo.FollowIndirections = sal_False; + + Sequence<Property> aProps(1); + aProps[0].Name = OUString::createFromAscii( "Title" ); + aProps[0].Type = ::getCppuType((OUString*)0); + + SearchCommandArgument aArg(aInfo,aProps); + + String aFilenameExtension = m_pConnection->getExtension(); + + + pDir->SetSort(FSYS_SORT_NAME | FSYS_SORT_ASCENDING | FSYS_SORT_END); + pDir->Update(); + + ::rtl::OUString aTable(::rtl::OUString::createFromAscii("TABLE")); + for (sal_uInt16 nDirPos = 0; nDirPos < pDir->Count(); nDirPos++) + { + ORow aRow(3); + if (aFilenameExtension.Len()) + { + if(match(tableNamePattern,(*pDir)[nDirPos].GetBase().GetBuffer(),'\0')) + aRow.push_back(makeAny(::rtl::OUString((*pDir)[nDirPos].GetBase()))); + } + else // keine extension, dann selbst filtern + { + do + { + DirEntry aEntry = (*pDir)[nDirPos]; + if (!(*pDir)[nDirPos].GetExtension().Len()) + { + if(match(tableNamePattern,(*pDir)[nDirPos].GetBase().GetBuffer(),'\0')) + aRow.push_back(makeAny(::rtl::OUString((*pDir)[nDirPos].GetBase()))); + break; + } + else + nDirPos++; + } while ((unsigned int)nDirPos < pDir->Count()); + } + aRow.push_back(makeAny(aTable)); + aRow.push_back(Any()); + aRows.push_back(aRow); + } + + pResult->setRows(aRows); +#endif + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getProcedureColumns( + const Any& catalog, const ::rtl::OUString& schemaPattern, + const ::rtl::OUString& procedureNamePattern, const ::rtl::OUString& columnNamePattern ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + +// OResultSet* pResult = new OResultSet(hStmt); +// Reference< XResultSet > xRef = pResult; +// pResult->openProcedureColumns(catalog,schemaPattern,procedureNamePattern,columnNamePattern); +// return xRef; + return Reference< XResultSet >(); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getProcedures( + const Any& catalog, const ::rtl::OUString& schemaPattern, + const ::rtl::OUString& procedureNamePattern ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + +// OResultSet* pResult = new OResultSet(hStmt); +// Reference< XResultSet > xRef = pResult; +// pResult->openProcedures(catalog,schemaPattern,procedureNamePattern); +// return xRef; + return Reference< XResultSet >(); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getVersionColumns( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + +// OResultSet* pResult = new OResultSet(hStmt); +// Reference< XResultSet > xRef = pResult; +// pResult->openVersionColumns(catalog,schema,table); +// return xRef; + return Reference< XResultSet >(); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxBinaryLiteralLength( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return 0; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxRowSize( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return 0; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxCatalogNameLength( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return 0; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxCharLiteralLength( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return STRING_MAXLEN; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnNameLength( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return 0; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInIndex( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return 0; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxCursorNameLength( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return 0; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxConnections( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return 0; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInTable( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return 0; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxStatementLength( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return 0; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxTableNameLength( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return 0; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxTablesInSelect( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return 1; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getExportedKeys( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + +// +// OResultSet* pResult = new OResultSet(hStmt); +// Reference< XResultSet > xRef = pResult; +// pResult->openExportedKeys(catalog,schema,table); +// return xRef; + return Reference< XResultSet >(); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getImportedKeys( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + +// OResultSet* pResult = new OResultSet(hStmt); +// Reference< XResultSet > xRef = pResult; +// pResult->openImportedKeys(catalog,schema,table); +// return xRef; + return Reference< XResultSet >(); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getPrimaryKeys( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + +// OResultSet* pResult = new OResultSet(hStmt); +// Reference< XResultSet > xRef = pResult; +// pResult->openPrimaryKeys(catalog,schema,table); +// return xRef; + return Reference< XResultSet >(); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getIndexInfo( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, + sal_Bool unique, sal_Bool approximate ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + +// OResultSet* pResult = new OResultSet(hStmt); +// Reference< XResultSet > xRef = pResult; +// pResult->openIndexInfo(catalog,schema,table,unique,approximate); +// return xRef; + return Reference< XResultSet >(); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getBestRowIdentifier( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, sal_Int32 scope, + sal_Bool nullable ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + +// OResultSet* pResult = new OResultSet(hStmt); +// Reference< XResultSet > xRef = pResult; +// pResult->openBestRowIdentifier(catalog,schema,table,scope,nullable); +// return xRef; + return Reference< XResultSet >(); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges( + const Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& tableNamePattern ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + +// OResultSet* pResult = new OResultSet(hStmt); +// Reference< XResultSet > xRef = pResult; +// pResult->openTablePrivileges(catalog,schemaPattern,tableNamePattern); +// return xRef; + return Reference< XResultSet >(); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getCrossReference( + const Any& primaryCatalog, const ::rtl::OUString& primarySchema, + const ::rtl::OUString& primaryTable, const Any& foreignCatalog, + const ::rtl::OUString& foreignSchema, const ::rtl::OUString& foreignTable ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + +// OResultSet* pResult = new OResultSet(hStmt); +// Reference< XResultSet > xRef = pResult; +// pResult->openForeignKeys(primaryCatalog,primarySchema.toChar() == '%' ? &primarySchema : NULL,&primaryTable, +// foreignCatalog, foreignSchema.toChar() == '%' ? &foreignSchema : NULL,&foreignTable); +// return xRef; + return Reference< XResultSet >(); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::doesMaxRowSizeIncludeBlobs( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesLowerCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesLowerCaseIdentifiers( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesMixedCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesMixedCaseIdentifiers( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesUpperCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesUpperCaseIdentifiers( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsAlterTableWithAddColumn( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsAlterTableWithDropColumn( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxIndexLength( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return 0; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsNonNullableColumns( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getCatalogTerm( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getIdentifierQuoteString( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return ::rtl::OUString::createFromAscii("\""); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getExtraNameCharacters( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsDifferentTableCorrelationNames( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::isCatalogAtStart( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::dataDefinitionIgnoredInTransactions( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::dataDefinitionCausesTransactionCommit( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsDataManipulationTransactionsOnly( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsDataDefinitionAndDataManipulationTransactions( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsPositionedDelete( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsPositionedUpdate( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenStatementsAcrossRollback( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenStatementsAcrossCommit( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenCursorsAcrossCommit( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenCursorsAcrossRollback( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsTransactionIsolationLevel( sal_Int32 level ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInDataManipulation( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsANSI92FullSQL( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsANSI92EntryLevelSQL( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsIntegrityEnhancementFacility( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInIndexDefinitions( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInTableDefinitions( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInTableDefinitions( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInIndexDefinitions( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInDataManipulation( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOuterJoins( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTableTypes( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(); + Reference< XResultSet > xRef = pResult; + pResult->setTableTypes(); + ORows aRows; + ORow aRow; + aRow.push_back(Any()); + aRow.push_back(makeAny(::rtl::OUString::createFromAscii("TABLE"))); + aRows.push_back(aRow); + pResult->setRows(aRows); + return xRef; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxStatements( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return 0; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxProcedureNameLength( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return 0; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxSchemaNameLength( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return 0; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsTransactions( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::allProceduresAreCallable( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsStoredProcedures( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSelectForUpdate( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::allTablesAreSelectable( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::isReadOnly( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::usesLocalFiles( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::usesLocalFilePerTable( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsTypeConversion( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::nullPlusNonNullIsNull( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsColumnAliasing( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsTableCorrelationNames( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsConvert( sal_Int32 fromType, sal_Int32 toType ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsExpressionsInOrderBy( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsGroupBy( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsGroupByBeyondSelect( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsGroupByUnrelated( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsMultipleTransactions( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsMultipleResultSets( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsLikeEscapeClause( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOrderByUnrelated( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsUnion( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsUnionAll( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsMixedCaseIdentifiers( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsMixedCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedAtEnd( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedAtStart( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedHigh( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedLow( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInProcedureCalls( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInPrivilegeDefinitions( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInProcedureCalls( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInPrivilegeDefinitions( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCorrelatedSubqueries( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInComparisons( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInExists( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInIns( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInQuantifieds( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsANSI92IntermediateSQL( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getURL( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + ::rtl::OUString aValue = ::rtl::OUString::createFromAscii("sdbc:file:"); + return aValue; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getUserName( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getDriverName( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getDriverVersion( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return ::rtl::OUString::valueOf((sal_Int32)1); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getDatabaseProductVersion( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return ::rtl::OUString::valueOf((sal_Int32)0); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getDatabaseProductName( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getProcedureTerm( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getSchemaTerm( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getDriverMajorVersion( ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return 0; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getDefaultTransactionIsolation( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return 0; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getDriverMinorVersion( ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return 0; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getSQLKeywords( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getSearchStringEscape( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getStringFunctions( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getTimeDateFunctions( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getSystemFunctions( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getNumericFunctions( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsExtendedSQLGrammar( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCoreSQLGrammar( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsMinimumSQLGrammar( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsFullOuterJoins( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsLimitedOuterJoins( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInGroupBy( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return 0; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInOrderBy( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return 0; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInSelect( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return 0; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxUserNameLength( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return 0; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsResultSetType( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsResultSetConcurrency( sal_Int32 setType, sal_Int32 concurrency ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + switch(setType) + { + case ResultSetType::FORWARD_ONLY: + return sal_True; + break; + case ResultSetType::SCROLL_INSENSITIVE: + break; + case ResultSetType::SCROLL_SENSITIVE: + break; + } + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::ownUpdatesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::ownDeletesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::ownInsertsAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::othersUpdatesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::othersDeletesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::othersInsertsAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_True; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::updatesAreDetected( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::deletesAreDetected( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::insertsAreDetected( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsBatchUpdates( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return sal_False; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getUDTs( const Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& typeNamePattern, const Sequence< sal_Int32 >& types ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return NULL; +} +// ------------------------------------------------------------------------- +Reference< XConnection > SAL_CALL ODatabaseMetaData::getConnection( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return (Reference< XConnection >)m_pConnection;//new OConnection(m_aConnectionHandle); +} +// ------------------------------------------------------------------------- + + diff --git a/connectivity/source/drivers/file/FDriver.cxx b/connectivity/source/drivers/file/FDriver.cxx new file mode 100644 index 000000000000..254fd36a9238 --- /dev/null +++ b/connectivity/source/drivers/file/FDriver.cxx @@ -0,0 +1,219 @@ +/************************************************************************* + * + * $RCSfile: FDriver.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_FILE_ODRIVER_HXX_ +#include "file/FDriver.hxx" +#endif +#ifndef _CONNECTIVITY_FILE_OCONNECTION_HXX_ +#include "file/FConnection.hxx" +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif + +using namespace connectivity::file; +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; +// -------------------------------------------------------------------------------- +OFileDriver::OFileDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) + : ODriver_BASE(m_aMutex) + ,m_xFactory(_rxFactory) +{ +} +// -------------------------------------------------------------------------------- +void OFileDriver::disposing() +{ + ::osl::MutexGuard aGuard(m_aMutex); + + + for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i) + { + Reference< XComponent > xComp(i->get(), UNO_QUERY); + if (xComp.is()) + xComp->dispose(); + } + m_xConnections.clear(); + + ODriver_BASE::disposing(); +} + +// static ServiceInfo +//------------------------------------------------------------------------------ +rtl::OUString OFileDriver::getImplementationName_Static( ) throw(RuntimeException) +{ + return rtl::OUString::createFromAscii("com.sun.star.sdbc.driver.file.Driver"); +} +//------------------------------------------------------------------------------ +Sequence< ::rtl::OUString > OFileDriver::getSupportedServiceNames_Static( ) throw (RuntimeException) +{ + Sequence< ::rtl::OUString > aSNS( 2 ); + aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver"); + aSNS[1] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Driver"); + return aSNS; +} + +//------------------------------------------------------------------ +::rtl::OUString SAL_CALL OFileDriver::getImplementationName( ) throw(RuntimeException) +{ + return getImplementationName_Static(); +} + +//------------------------------------------------------------------ +sal_Bool SAL_CALL OFileDriver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException) +{ + Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); + const ::rtl::OUString* pSupported = aSupported.getConstArray(); + for (sal_Int32 i=0; i<aSupported.getLength(); ++i, ++pSupported) + if (pSupported->equals(_rServiceName)) + return sal_True; + + return sal_False; +} + +//------------------------------------------------------------------ +Sequence< ::rtl::OUString > SAL_CALL OFileDriver::getSupportedServiceNames( ) throw(RuntimeException) +{ + return getSupportedServiceNames_Static(); +} + +// -------------------------------------------------------------------------------- +Reference< XConnection > SAL_CALL OFileDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODriver_BASE::rBHelper.bDisposed) + throw DisposedException(); + + OConnection* pCon = new OConnection(this); + pCon->construct(url,info); + Reference< XConnection > xCon = pCon; + m_xConnections.push_back(WeakReferenceHelper(*pCon)); + + return xCon; +} +// -------------------------------------------------------------------------------- +sal_Bool SAL_CALL OFileDriver::acceptsURL( const ::rtl::OUString& url ) + throw(SQLException, RuntimeException) +{ + if(!url.compareTo(::rtl::OUString::createFromAscii("sdbc:file:"),10)) + { + return sal_True; + } + return sal_False; +} +// -------------------------------------------------------------------------------- +Sequence< DriverPropertyInfo > SAL_CALL OFileDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException) +{ + return Sequence< DriverPropertyInfo >(); +} +// -------------------------------------------------------------------------------- +sal_Int32 SAL_CALL OFileDriver::getMajorVersion( ) throw(RuntimeException) +{ + return 1; +} +// -------------------------------------------------------------------------------- +sal_Int32 SAL_CALL OFileDriver::getMinorVersion( ) throw(RuntimeException) +{ + return 0; +} +// -------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------- +// XDataDefinitionSupplier +Reference< XTablesSupplier > SAL_CALL OFileDriver::getDataDefinitionByConnection( const Reference< ::com::sun::star::sdbc::XConnection >& connection ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (ODriver_BASE::rBHelper.bDisposed) + throw DisposedException(); + + OConnection* pConnection = NULL; + for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i) + { + if ((OConnection*) Reference< XConnection >::query(i->get().get()).get() == (OConnection*)connection.get()) + { + pConnection = (OConnection*)connection.get(); + break; + } + } + + Reference< XTablesSupplier > xTab = NULL; + if(pConnection) + xTab = pConnection->createCatalog(); + return xTab; +} + +//------------------------------------------------------------------ +Any SAL_CALL OFileDriver::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = ::cppu::queryInterface(rType, static_cast<XDataDefinitionSupplier*>(this)); + if(aRet.hasValue()) + return aRet; + return ODriver_BASE::queryInterface(rType); +} +// -------------------------------------------------------------------------------- +Reference< XTablesSupplier > SAL_CALL OFileDriver::getDataDefinitionByURL( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) +{ + return getDataDefinitionByConnection(connect(url,info)); +} + + diff --git a/connectivity/source/drivers/file/FPreparedStatement.cxx b/connectivity/source/drivers/file/FPreparedStatement.cxx new file mode 100644 index 000000000000..20203d7b643c --- /dev/null +++ b/connectivity/source/drivers/file/FPreparedStatement.cxx @@ -0,0 +1,473 @@ +/************************************************************************* + * + * $RCSfile: FPreparedStatement.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif +#ifndef _CONNECTIVITY_FILE_OPREPAREDSTATEMENT_HXX_ +#include "file/FPreparedStatement.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif +#ifndef _CONNECTIVITY_FILE_ORESULTSETMETADATA_HXX_ +#include "file/FResultSetMetaData.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif +#ifndef _CONNECTIVITY_DATECONVERSION_HXX_ +#include "DateConversion.hxx" +#endif + +using namespace connectivity; +using namespace connectivity::file; +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; + +IMPLEMENT_SERVICE_INFO(OPreparedStatement,"com.sun.star.sdbc.driver.file.PreparedStatement","com.sun.star.sdbc.PreparedStatement"); + +OPreparedStatement::OPreparedStatement( OConnection* _pConnection,const ::std::vector<OTypeInfo>& _TypeInfo) + : OStatement_BASE2( _pConnection ) + ,m_pResultSet(NULL) +{ +} +// ------------------------------------------------------------------------- +void OPreparedStatement::construct(const ::rtl::OUString& sql) throw(SQLException, RuntimeException) +{ + String aErr; + m_pParseTree = m_aParser.parseTree(aErr,sql); + if(m_pParseTree) + { + m_aSQLIterator.setParseTree(m_pParseTree); + m_aSQLIterator.traverseAll(); + const OSQLTables& xTabs = m_aSQLIterator.getTables(); + if(xTabs.begin() == xTabs.end()) + throw SQLException(aErr,*this,::rtl::OUString(),0,Any()); + + m_pResultSet = new OResultSet(this,m_aSQLIterator); + if(m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT || + m_aSQLIterator.getStatementType() == SQL_STATEMENT_UPDATE) + m_pResultSet->describeParameter(); + m_aRow = new OValueVector(); + m_xRS = m_pResultSet; + + } + else + throw SQLException(aErr,*this,::rtl::OUString(),0,Any()); +} +// ------------------------------------------------------------------------- + +Any SAL_CALL OPreparedStatement::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = OStatement_BASE2::queryInterface(rType); + if(!aRet.hasValue()) + aRet = ::cppu::queryInterface( rType, + static_cast< XPreparedStatement*>(this), + static_cast< XParameters*>(this), + static_cast< XResultSetMetaDataSupplier*>(this)); + return aRet; +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OPreparedStatement::getTypes( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< XPreparedStatement > *)0 ), + ::getCppuType( (const ::com::sun::star::uno::Reference< XParameters > *)0 ), + ::getCppuType( (const ::com::sun::star::uno::Reference< XResultSetMetaDataSupplier > *)0 )); + + return ::utl::concatSequences(aTypes.getTypes(),OStatement_BASE2::getTypes()); +} +// ------------------------------------------------------------------------- + +Reference< XResultSetMetaData > SAL_CALL OPreparedStatement::getMetaData( ) throw(SQLException, RuntimeException) +{ + if(m_xMetaData.is()) + m_xMetaData = new OResultSetMetaData(m_aSQLIterator.getSelectColumns().getBody(),m_aSQLIterator.getTables().begin()->first); + return m_xMetaData; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::close( ) throw(SQLException, RuntimeException) +{ + m_xRS = NULL; + clearMyResultSet(); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OPreparedStatement::execute( ) throw(SQLException, RuntimeException) +{ + sal_Bool hasResultSet = sal_False; + SQLWarning warning; + sal_Bool needData = sal_False; + + m_pResultSet->setParameterRow(m_aRow); + m_pResultSet->OpenImpl(); + return m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT || m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT_COUNT; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OPreparedStatement::executeUpdate( ) throw(SQLException, RuntimeException) +{ + m_pResultSet->setParameterRow(m_aRow); + m_pResultSet->OpenImpl(); + return m_pResultSet->getRowCountResult(); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setString( sal_Int32 parameterIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException) +{ + if( !parameterIndex) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + if(parameterIndex >= m_aRow->size()) + m_aRow->push_back(x); + else + (*m_aRow)[parameterIndex] = x; +} +// ------------------------------------------------------------------------- + +Reference< XConnection > SAL_CALL OPreparedStatement::getConnection( ) throw(SQLException, RuntimeException) +{ + return (Reference< XConnection >)m_pConnection; +} +// ------------------------------------------------------------------------- + +Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery( ) throw(SQLException, RuntimeException) +{ + Reference< XResultSet > rs = m_pResultSet; + m_pResultSet->setParameterRow(m_aRow); + m_pResultSet->OpenImpl(); + return rs; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setBoolean( sal_Int32 parameterIndex, sal_Bool x ) throw(SQLException, RuntimeException) +{ + if( !parameterIndex) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + + if(parameterIndex >= m_aRow->size()) + m_aRow->push_back(x); + else + (*m_aRow)[parameterIndex] = x; +} +// ------------------------------------------------------------------------- +void SAL_CALL OPreparedStatement::setByte( sal_Int32 parameterIndex, sal_Int8 x ) throw(SQLException, RuntimeException) +{ + if( !parameterIndex) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + + if(parameterIndex >= m_aRow->size()) + m_aRow->push_back((sal_Int32)x); + else + (*m_aRow)[parameterIndex] = (sal_Int32)x; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setDate( sal_Int32 parameterIndex, const Date& aData ) throw(SQLException, RuntimeException) +{ + if( !parameterIndex) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + + if(parameterIndex >= m_aRow->size()) + m_aRow->push_back(DateConversion::toDouble(aData)); + else + (*m_aRow)[parameterIndex] = DateConversion::toDouble(aData); +} +// ------------------------------------------------------------------------- + + +void SAL_CALL OPreparedStatement::setTime( sal_Int32 parameterIndex, const Time& aVal ) throw(SQLException, RuntimeException) +{ + if( !parameterIndex) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + + if(parameterIndex >= m_aRow->size()) + m_aRow->push_back(DateConversion::toDouble(aVal)); + else + (*m_aRow)[parameterIndex] = DateConversion::toDouble(aVal); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setTimestamp( sal_Int32 parameterIndex, const DateTime& aVal ) throw(SQLException, RuntimeException) +{ + if( !parameterIndex) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + + if(parameterIndex >= m_aRow->size()) + m_aRow->push_back(DateConversion::toDouble(aVal)); + else + (*m_aRow)[parameterIndex] = DateConversion::toDouble(aVal); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setDouble( sal_Int32 parameterIndex, double x ) throw(SQLException, RuntimeException) +{ + if( !parameterIndex) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + + if(parameterIndex >= m_aRow->size()) + m_aRow->push_back(x); + else + (*m_aRow)[parameterIndex] = x; +} + +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setFloat( sal_Int32 parameterIndex, float x ) throw(SQLException, RuntimeException) +{ + if( !parameterIndex) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + + if(parameterIndex >= m_aRow->size()) + m_aRow->push_back((double)x); + else + (*m_aRow)[parameterIndex] = (double)x; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setInt( sal_Int32 parameterIndex, sal_Int32 x ) throw(SQLException, RuntimeException) +{ + if( !parameterIndex) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + + if(parameterIndex >= m_aRow->size()) + m_aRow->push_back(x); + else + (*m_aRow)[parameterIndex] = x; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setLong( sal_Int32 parameterIndex, sal_Int64 aVal ) throw(SQLException, RuntimeException) +{ + if( !parameterIndex || parameterIndex > m_aRow->size()) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setNull( sal_Int32 parameterIndex, sal_Int32 sqlType ) throw(SQLException, RuntimeException) +{ + // Get the buffer needed for the length + if( !parameterIndex) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + + if(parameterIndex >= m_aRow->size()) + m_aRow->push_back(OFileValue()); + else + (*m_aRow)[parameterIndex].setNull(); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setClob( sal_Int32 parameterIndex, const Reference< XClob >& x ) throw(SQLException, RuntimeException) +{ + if( !parameterIndex || parameterIndex >= m_aRow->size()) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setBlob( sal_Int32 parameterIndex, const Reference< XBlob >& x ) throw(SQLException, RuntimeException) +{ + if( !parameterIndex || parameterIndex >= m_aRow->size()) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setArray( sal_Int32 parameterIndex, const Reference< XArray >& x ) throw(SQLException, RuntimeException) +{ + if( !parameterIndex || parameterIndex >= m_aRow->size()) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setRef( sal_Int32 parameterIndex, const Reference< XRef >& x ) throw(SQLException, RuntimeException) +{ + if( !parameterIndex || parameterIndex >= m_aRow->size()) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setObjectWithInfo( sal_Int32 parameterIndex, const Any& x, sal_Int32 sqlType, sal_Int32 scale ) throw(SQLException, RuntimeException) +{ + if( !parameterIndex) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + // For each known SQL Type, call the appropriate + // set routine + + switch (sqlType) + { + case DataType::CHAR: + case DataType::VARCHAR: + case DataType::LONGVARCHAR: + (*m_aRow)[parameterIndex] = *(::rtl::OUString*) x.getValue(); + break; + case DataType::BIT: + (*m_aRow)[parameterIndex] = *(sal_Bool*) x.getValue(); + break; + + case DataType::TINYINT: + case DataType::SMALLINT: + case DataType::INTEGER: + (*m_aRow)[parameterIndex] = *(sal_Int32*)x.getValue(); + break; + + case DataType::BIGINT: + case DataType::REAL: + case DataType::FLOAT: + case DataType::DOUBLE: + (*m_aRow)[parameterIndex] = *(double*)x.getValue(); + break; + + case DataType::BINARY: + break; + + case DataType::VARBINARY: + case DataType::LONGVARBINARY: + break; + + case DataType::DATE: + (*m_aRow)[parameterIndex] = DateConversion::toDouble(*(Date*) x.getValue()); + break; + + case DataType::TIME: + (*m_aRow)[parameterIndex] = DateConversion::toDouble(*(Time*)x.getValue()); + break; + + case DataType::TIMESTAMP: + (*m_aRow)[parameterIndex] = DateConversion::toDouble(*(DateTime*)x.getValue()); + break; + + default: + { + ::rtl::OUString aVal = ::rtl::OUString::createFromAscii("Unknown SQL Type for PreparedStatement.setObject (SQL Type="); + aVal += ::rtl::OUString::valueOf(sqlType); + throw SQLException( aVal,*this,::rtl::OUString(),0,Any()); + } + + } +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& typeName ) throw(SQLException, RuntimeException) +{ + if( !parameterIndex) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + + if(parameterIndex >= m_aRow->size()) + m_aRow->push_back(OFileValue()); + else + (*m_aRow)[parameterIndex].setNull(); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setObject( sal_Int32 parameterIndex, const Any& x ) throw(SQLException, RuntimeException) +{ + if( !parameterIndex || parameterIndex >= m_aRow->size()) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + // setObject (parameterIndex, x, sqlType, 0); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setShort( sal_Int32 parameterIndex, sal_Int16 x ) throw(SQLException, RuntimeException) +{ + if( !parameterIndex) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + setInt(parameterIndex,x); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setBytes( sal_Int32 parameterIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException) +{ + if( !parameterIndex || parameterIndex >= m_aRow->size()) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); +} +// ------------------------------------------------------------------------- + + +void SAL_CALL OPreparedStatement::setCharacterStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException) +{ + if( !parameterIndex || parameterIndex >= m_aRow->size()) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setBinaryStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException) +{ + if( !parameterIndex || parameterIndex >= m_aRow->size()) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::clearParameters( ) throw(SQLException, RuntimeException) +{ + m_aRow->clear(); +} + + diff --git a/connectivity/source/drivers/file/FResultSet.cxx b/connectivity/source/drivers/file/FResultSet.cxx new file mode 100644 index 000000000000..ee25dfe374a3 --- /dev/null +++ b/connectivity/source/drivers/file/FResultSet.cxx @@ -0,0 +1,2297 @@ +/************************************************************************* + * + * $RCSfile: FResultSet.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#ifndef _CONNECTIVITY_FILE_ORESULTSET_HXX_ +#include "file/FResultSet.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +#ifndef _CONNECTIVITY_FILE_ORESULTSETMETADATA_HXX_ +#include "file/FResultSetMetaData.hxx" +#endif +#ifndef _COM_SUN_STAR_SQLC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ +#include <com/sun/star/sdbc/ColumnValue.hpp> +#endif +#ifndef _UTL_PROPERTY_HXX_ +#include <unotools/property.hxx> +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XINDEXACCESS_HPP_ +#include <com/sun/star/container/XIndexAccess.hpp> +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _CONNECTIVITY_DATECONVERSION_HXX_ +#include "DateConversion.hxx" +#endif +#ifndef _CONNECTIVITY_DBASE_INDEX_HXX_ +#include "dbase/DIndex.hxx" +#endif +#ifndef _CONNECTIVITY_DBASE_INDEXITER_HXX_ +#include "dbase/DIndexIter.hxx" +#endif +#ifndef _ITERATOR_ +#include <iterator> +#endif +using namespace connectivity; +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; + +// Maximale Anzahl von Rows, die mit ORDER BY sortiert durchlaufen werden koennen: +#if defined (WIN) +#define MAX_KEYSET_SIZE 0x3ff0 // Etwas weniger als ein Segment, damit + // noch Platz fuer Memory Debug-Informationen +#else +#define MAX_KEYSET_SIZE 0x40000 // 256K +#endif +//------------------------------------------------------------------------------ +IMPLEMENT_SERVICE_INFO(OResultSet,"com.sun.star.sdbcx.drivers.file.ResultSet","com.sun.star.sdbc.ResultSet"); +// ------------------------------------------------------------------------- +OResultSet::OResultSet(OStatement_Base* pStmt,OSQLParseTreeIterator& _aSQLIterator) : OResultSet_BASE(m_aMutex) + ,connectivity::OSimplePropertyContainer(OResultSet_BASE::rBHelper) + ,m_aStatement((OWeakObject*)pStmt) + ,m_nRowPos(-1) + ,m_bLastRecord(sal_False) + ,m_bEOF(sal_False) + ,m_xDBMetaData(pStmt->getConnection()->getMetaData()) + ,m_xMetaData(NULL) + ,m_aSQLIterator(_aSQLIterator) + ,m_pTable(NULL) + ,m_nRowCountResult(-1) + ,m_nFilePos(0) + ,m_nLastVisitedPos(-1) + ,m_pParseTree(pStmt->getParseTree()) + ,m_pFileSet(NULL) + ,m_pEvaluationKeySet(NULL) + ,m_pSortIndex(NULL) + ,m_aAssignValues(NULL) +{ + osl_incrementInterlockedCount( &m_refCount ); + + + for (int jj = 0; jj < sizeof nOrderbyColumnNumber / sizeof (* nOrderbyColumnNumber); jj++) + { + nOrderbyColumnNumber[jj] = SQL_COLUMN_NOTFOUND; + bOrderbyAscending[jj] = TRUE; + } + construct(); + osl_decrementInterlockedCount( &m_refCount ); +} + +// ------------------------------------------------------------------------- +OResultSet::~OResultSet() +{ +} +// ------------------------------------------------------------------------- +void OResultSet::construct() +{ + registerProperty(PROPERTY_FETCHSIZE, PROPERTY_ID_FETCHSIZE, 0,&m_nFetchSize, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))); + registerProperty(PROPERTY_RESULTSETTYPE, PROPERTY_ID_RESULTSETTYPE, PropertyAttribute::READONLY,&m_nResultSetType, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))); + registerProperty(PROPERTY_FETCHDIRECTION, PROPERTY_ID_FETCHDIRECTION, 0,&m_nFetchDirection, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))); + registerProperty(PROPERTY_RESULTSETCONCURRENCY, PROPERTY_ID_RESULTSETCONCURRENCY, PropertyAttribute::READONLY,&m_nResultSetConcurrency, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))); +} +// ------------------------------------------------------------------------- +void OResultSet::disposing(void) +{ + OPropertySetHelper::disposing(); + + ::osl::MutexGuard aGuard(m_aMutex); + m_aStatement = NULL; + m_xMetaData = NULL; + m_pParseTree = NULL; + if(m_pTable) + { + m_pTable->release(); + m_pTable = NULL; + } + DELETEZ(m_pFileSet); + DELETEZ(m_pEvaluationKeySet); + DELETEZ(m_pSortIndex); + + m_aRow->clear(); + m_aEvaluateRow->clear(); + m_aAssignValues->clear(); + m_xParamColumns->clear(); +} +// ------------------------------------------------------------------------- +Any SAL_CALL OResultSet::queryInterface( const Type & rType ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + Any aRet = OPropertySetHelper::queryInterface(rType); + if(!aRet.hasValue()) + aRet = OResultSet_BASE::queryInterface(rType); + return aRet; +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OResultSet::getTypes( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ), + ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ), + ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > *)0 )); + + return ::utl::concatSequences(aTypes.getTypes(),OResultSet_BASE::getTypes()); +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSet::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + Reference< XResultSetMetaData > xMeta = getMetaData(); + sal_Int32 nLen = xMeta->getColumnCount(); + sal_Int32 i = 1; + for(;i<=nLen;++i) + if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) : columnName.equalsIgnoreCase(xMeta->getColumnName(i))) + break; + return i; +} +// ------------------------------------------------------------------------- +Reference< ::com::sun::star::io::XInputStream > SAL_CALL OResultSet::getBinaryStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + columnIndex = mapColumn(columnIndex); + return NULL; +} +// ------------------------------------------------------------------------- +Reference< ::com::sun::star::io::XInputStream > SAL_CALL OResultSet::getCharacterStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + columnIndex = mapColumn(columnIndex); + return NULL; +} + +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + columnIndex = mapColumn(columnIndex); + m_bWasNull = (*m_aRow)[columnIndex].isNull(); + return (*m_aRow)[columnIndex]; +} +// ------------------------------------------------------------------------- + +sal_Int8 SAL_CALL OResultSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + columnIndex = mapColumn(columnIndex); + m_bWasNull = (*m_aRow)[columnIndex].isNull(); + return (*m_aRow)[columnIndex].getInt32(); +} +// ------------------------------------------------------------------------- + +Sequence< sal_Int8 > SAL_CALL OResultSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + columnIndex = mapColumn(columnIndex); + return Sequence< sal_Int8 >(); +} +// ------------------------------------------------------------------------- + +::com::sun::star::util::Date SAL_CALL OResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + columnIndex = mapColumn(columnIndex); + m_bWasNull = (*m_aRow)[columnIndex].isNull(); + + return DateConversion::toDate((*m_aRow)[columnIndex]); +} +// ------------------------------------------------------------------------- + +double SAL_CALL OResultSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + columnIndex = mapColumn(columnIndex); + m_bWasNull = (*m_aRow)[columnIndex].isNull(); + return (*m_aRow)[columnIndex]; +} +// ------------------------------------------------------------------------- + +float SAL_CALL OResultSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + columnIndex = mapColumn(columnIndex); + m_bWasNull = (*m_aRow)[columnIndex].isNull(); + return (*m_aRow)[columnIndex].getDouble(); +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + columnIndex = mapColumn(columnIndex); + m_bWasNull = (*m_aRow)[columnIndex].isNull(); + return (*m_aRow)[columnIndex]; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSet::getRow( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return m_nRowPos; +} +// ------------------------------------------------------------------------- + +sal_Int64 SAL_CALL OResultSet::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + columnIndex = mapColumn(columnIndex); + return sal_Int64(); +} +// ------------------------------------------------------------------------- + +Reference< XResultSetMetaData > SAL_CALL OResultSet::getMetaData( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if(!m_xMetaData.is()) + m_xMetaData = new OResultSetMetaData(m_xColumns.getBody(),m_aSQLIterator.getTables().begin()->first); + return m_xMetaData; +} +// ------------------------------------------------------------------------- +Reference< XArray > SAL_CALL OResultSet::getArray( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + columnIndex = mapColumn(columnIndex); + return NULL; +} + +// ------------------------------------------------------------------------- + +Reference< XClob > SAL_CALL OResultSet::getClob( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + columnIndex = mapColumn(columnIndex); + return NULL; +} +// ------------------------------------------------------------------------- +Reference< XBlob > SAL_CALL OResultSet::getBlob( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + columnIndex = mapColumn(columnIndex); + return NULL; +} +// ------------------------------------------------------------------------- + +Reference< XRef > SAL_CALL OResultSet::getRef( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + columnIndex = mapColumn(columnIndex); + return NULL; +} +// ------------------------------------------------------------------------- + +Any SAL_CALL OResultSet::getObject( sal_Int32 columnIndex, const Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + columnIndex = mapColumn(columnIndex); + return Any(); +} +// ------------------------------------------------------------------------- + +sal_Int16 SAL_CALL OResultSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + columnIndex = mapColumn(columnIndex); + m_bWasNull = (*m_aRow)[columnIndex].isNull(); + return (*m_aRow)[columnIndex].getInt32(); +} +// ------------------------------------------------------------------------- + + +::rtl::OUString SAL_CALL OResultSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + columnIndex = mapColumn(columnIndex); + m_bWasNull = (*m_aRow)[columnIndex].isNull(); + return (*m_aRow)[columnIndex]; +} + +// ------------------------------------------------------------------------- + + +::com::sun::star::util::Time SAL_CALL OResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + columnIndex = mapColumn(columnIndex); + return DateConversion::toTime((*m_aRow)[columnIndex]); +} +// ------------------------------------------------------------------------- + + +::com::sun::star::util::DateTime SAL_CALL OResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + columnIndex = mapColumn(columnIndex); + return DateConversion::toDateTime((*m_aRow)[columnIndex]); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::isAfterLast( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::isFirst( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return m_nRowPos == 1; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::isLast( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return m_bEOF; +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::beforeFirst( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(first()) + previous(); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::afterLast( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(last()) + next(); + m_bEOF = sal_True; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::close( ) throw(SQLException, RuntimeException) +{ + { + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + } + dispose(); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::first( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return Move(OFileTable::FILE_FIRST,1,sal_True); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::last( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + // here I know definitely that I stand on the last record + return Move(OFileTable::FILE_LAST,1,sal_True); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return Move(OFileTable::FILE_ABSOLUTE,row,sal_True); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::relative( sal_Int32 row ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return Move(OFileTable::FILE_RELATIVE,row,sal_True); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::previous( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + --m_nRowPos; + return sal_True; +} +// ------------------------------------------------------------------------- +Reference< XInterface > SAL_CALL OResultSet::getStatement( ) throw(SQLException, RuntimeException) +{ + return m_aStatement.get(); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::rowDeleted( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::rowInserted( ) throw(SQLException, RuntimeException) +{ ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::rowUpdated( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return sal_False; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::isBeforeFirst( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return m_nRowPos == 0; +} +// ------------------------------------------------------------------------- +sal_Bool OResultSet::evaluate() +{ + sal_Bool bRet = sal_True; + while(!m_aSQLAnalyzer.evaluateRestriction()) + { + if(m_pEvaluationKeySet) + { + if(m_aEvaluateIter == m_pEvaluationKeySet->end()) + return sal_False; + bRet = m_pTable->seekRow(OFileTable::FILE_BOOKMARK,(*m_aEvaluateIter),m_nRowPos); + ++m_aEvaluateIter; + } + else + bRet = m_pTable->seekRow(OFileTable::FILE_NEXT,1,m_nRowPos); + if(bRet) + { + if(m_pEvaluationKeySet) + { + bRet = m_pTable->fetchRow(m_aEvaluateRow,m_pTable->getTableColumns().getBody(),sal_True); + evaluate(); + + } + else + bRet = m_pTable->fetchRow(m_aRow,m_xColumns.getBody(),sal_True); + } + } + + return bRet; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::next( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(!m_pTable) + return sal_False; + + return Move(OFileTable::FILE_NEXT,1,sal_True); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::wasNull( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return m_bWasNull; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::cancel( ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::clearWarnings( ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- +Any SAL_CALL OResultSet::getWarnings( ) throw(SQLException, RuntimeException) +{ + return Any(); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::insertRow( ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateRow( ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::deleteRow( ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::cancelRowUpdates( ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::moveToInsertRow( ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::moveToCurrentRow( ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateNull( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + columnIndex = mapColumn(columnIndex); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateBoolean( sal_Int32 columnIndex, sal_Bool x ) throw(SQLException, RuntimeException) +{ + columnIndex = mapColumn(columnIndex); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateByte( sal_Int32 columnIndex, sal_Int8 x ) throw(SQLException, RuntimeException) +{ + columnIndex = mapColumn(columnIndex); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateShort( sal_Int32 columnIndex, sal_Int16 x ) throw(SQLException, RuntimeException) +{ + columnIndex = mapColumn(columnIndex); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateInt( sal_Int32 columnIndex, sal_Int32 x ) throw(SQLException, RuntimeException) +{ + columnIndex = mapColumn(columnIndex); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateLong( sal_Int32 columnIndex, sal_Int64 x ) throw(SQLException, RuntimeException) +{ + columnIndex = mapColumn(columnIndex); + throw RuntimeException(); +} +// ----------------------------------------------------------------------- +void SAL_CALL OResultSet::updateFloat( sal_Int32 columnIndex, float x ) throw(SQLException, RuntimeException) +{ + columnIndex = mapColumn(columnIndex); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateDouble( sal_Int32 columnIndex, double x ) throw(SQLException, RuntimeException) +{ + columnIndex = mapColumn(columnIndex); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateString( sal_Int32 columnIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException) +{ + columnIndex = mapColumn(columnIndex); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateBytes( sal_Int32 columnIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException) +{ + columnIndex = mapColumn(columnIndex); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateDate( sal_Int32 columnIndex, const ::com::sun::star::util::Date& x ) throw(SQLException, RuntimeException) +{ + columnIndex = mapColumn(columnIndex); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateTime( sal_Int32 columnIndex, const ::com::sun::star::util::Time& x ) throw(SQLException, RuntimeException) +{ + columnIndex = mapColumn(columnIndex); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateTimestamp( sal_Int32 columnIndex, const ::com::sun::star::util::DateTime& x ) throw(SQLException, RuntimeException) +{ + columnIndex = mapColumn(columnIndex); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateBinaryStream( sal_Int32 columnIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException) +{ + columnIndex = mapColumn(columnIndex); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateCharacterStream( sal_Int32 columnIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException) +{ + columnIndex = mapColumn(columnIndex); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::refreshRow( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateObject( sal_Int32 columnIndex, const Any& x ) throw(SQLException, RuntimeException) +{ + columnIndex = mapColumn(columnIndex); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateNumericObject( sal_Int32 columnIndex, const Any& x, sal_Int32 scale ) throw(SQLException, RuntimeException) +{ + columnIndex = mapColumn(columnIndex); + OSL_ENSHURE(0,"OResultSet::updateNumericObject: NYI"); +} +// ------------------------------------------------------------------------- +IPropertyArrayHelper* OResultSet::createArrayHelper( ) const +{ + Sequence< Property > aProps; + describeProperties(aProps); + return new ::cppu::OPropertyArrayHelper(aProps); +} +// ------------------------------------------------------------------------- +IPropertyArrayHelper & OResultSet::getInfoHelper() +{ + return *const_cast<OResultSet*>(this)->getArrayHelper(); +} + +//------------------------------------------------------------------ +BOOL OResultSet::ExecuteRow(OFileTable::FilePosition eFirstCursorPosition, + INT32 nFirstOffset, + BOOL bRebind, + BOOL bEvaluate, + BOOL bRetrieveData) +{ + + // Fuer weitere Fetch-Operationen werden diese Angaben ggf. veraendert ... + OFileTable::FilePosition eCursorPosition = eFirstCursorPosition; + INT32 nOffset = nFirstOffset; + UINT32 nLoopCount = 0; + +again: + + // protect from reading over the end when someboby is inserting while we are reading + // this method works only for dBase at the moment !!!! + if (eCursorPosition == OFileTable::FILE_NEXT && m_nFilePos == m_nLastVisitedPos) + { + return sal_False; + } + + if (!m_pTable->seekRow(eCursorPosition, nOffset, m_nFilePos)) + { + return sal_False; + } + + if (!bEvaluate) // Laeuft keine Auswertung, dann nur Ergebniszeile fuellen + { + m_pTable->fetchRow(m_aRow,m_pTable->getTableColumns().getBody(), bRetrieveData); + + // if (bShowDeleted && m_aRow->isDeleted()) + // m_aRow->setState(ROW_DELETED); + } + else + { + m_pTable->fetchRow(m_aEvaluateRow, m_pTable->getTableColumns().getBody(), TRUE); + + if (m_aSQLAnalyzer.hasRestriction() && //!bShowDeleted && m_aEvaluateRow->isDeleted() ||// keine Anzeige von geloeschten Stzen + !m_aSQLAnalyzer.evaluateRestriction()) // Auswerten der Bedingungen + { // naechsten Satz auswerten + // aktuelle Zeile loeschen im Keyset + OSL_ENSHURE(!m_pFileSet || + // !m_pFileSet->IsFrozen() || + eCursorPosition == OFileTable::FILE_NEXT, "Falsche CursorPosition!"); + + if (m_pEvaluationKeySet) + { + ++m_aEvaluateIter; + if (m_pEvaluationKeySet->end() != m_aEvaluateIter) + nOffset = (*m_aEvaluateIter); + else + { + return sal_False; + } + } + else if (m_pFileSet) + { + OSL_ENSHURE(//!m_pFileSet->IsFrozen() && + eCursorPosition == OFileTable::FILE_NEXT, "Falsche CursorPosition!"); + eCursorPosition = OFileTable::FILE_NEXT; + nOffset = 1; + } + else if (eCursorPosition == OFileTable::FILE_FIRST || + eCursorPosition == OFileTable::FILE_NEXT || + eCursorPosition == OFileTable::FILE_ABSOLUTE) + { + eCursorPosition = OFileTable::FILE_NEXT; + nOffset = 1; + } + else if (eCursorPosition == OFileTable::FILE_LAST || + eCursorPosition == OFileTable::FILE_PRIOR) + { + eCursorPosition = OFileTable::FILE_PRIOR; + nOffset = 1; + } + else if (eCursorPosition == OFileTable::FILE_RELATIVE) + { + eCursorPosition = (nOffset >= 0) ? OFileTable::FILE_NEXT : OFileTable::FILE_PRIOR; + } + else + { + // aStatus.Set(SQL_STAT_NO_DATA_FOUND); + return sal_False; + } + // Nochmal probieren ... + goto again; + } + } + // Evaluate darf nur gesetzt sein, + // wenn der Keyset weiter aufgebaut werden soll + if (m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT && + (m_pFileSet || m_pSortIndex) && bEvaluate) + { + if (m_pSortIndex) + { + OFILEKeyValue* pKeyValue = GetOrderbyKeyValue(m_aEvaluateRow); + if (!m_pSortIndex->AddKeyValue(pKeyValue)) + { + // Ueberwachung auf Ueberschreitung der Index-Kapazitaet: + } + } + else if (m_pFileSet) + { + // OSL_ENSHURE(!m_pFileSet->IsFrozen() , "Falsche CursorPosition!"); + sal_uInt32 nBookmarkValue = Abs((sal_Int32)(*m_aEvaluateRow)[0]); + m_pFileSet->push_back(nBookmarkValue); + } + } + else if (m_aSQLIterator.getStatementType() == SQL_STATEMENT_UPDATE) + { + sal_Bool bOK = sal_True; + if (bEvaluate) + { + // jetzt die eigentliche Ergebniszeile Lesen + bOK = m_pTable->fetchRow(m_aEvaluateRow, m_pTable->getTableColumns().getBody(), TRUE); + } + + if (bOK) + { + // Nur die zu aendernden Werte uebergeben: + if(!m_pTable->UpdateRow(m_aAssignValues.getBody(),m_aEvaluateRow,Reference<XIndexAccess>(m_xColNames,UNO_QUERY))) + return sal_False; + } + } + else if (m_aSQLIterator.getStatementType() == SQL_STATEMENT_DELETE) + { + sal_Bool bOK = sal_True; + if (bEvaluate) + { + bOK = m_pTable->fetchRow(m_aEvaluateRow, m_pTable->getTableColumns().getBody(), TRUE); + } + if (bOK) + { + if(!m_pTable->DeleteRow(m_xColumns.getBody())) + return sal_False; + } + } + return sal_True; +} + +//------------------------------------------------------------------- +BOOL OResultSet::Move(OFileTable::FilePosition eCursorPosition, INT32 nOffset, BOOL bRetrieveData) +{ + +IgnoreDeletedRows: + + INT32 nTempPos = m_nRowPos; + // exclusiver zugriff auf die Tabelle + // NAMESPACE_VOS(OGuard)* pGuard = m_pTable->Lock(); + + if (m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT) + { + if (m_pFileSet == NULL) // kein Index verfuegbar + { + // Normales FETCH + ExecuteRow(eCursorPosition,nOffset,TRUE,FALSE,bRetrieveData); + + // now set the bookmark for outside + (*m_aRow->begin()) = sal_Int32(m_nRowPos + 1); + } + else + { + switch(eCursorPosition) + { + case OFileTable::FILE_NEXT: + m_nRowPos++; + break; + case OFileTable::FILE_PRIOR: + if (m_nRowPos >= 0) + m_nRowPos--; + break; + case OFileTable::FILE_FIRST: + m_nRowPos = 0; + break; + case OFileTable::FILE_LAST: + // OSL_ENSHURE(IsRowCountFinal(), "Fehler im Keyset!"); // mu eingefroren sein, sonst Fehler beim SQLCursor + m_nRowPos = m_pFileSet->size() - 1; + break; + case OFileTable::FILE_RELATIVE: + m_nRowPos += nOffset; + break; + case OFileTable::FILE_ABSOLUTE: + m_nRowPos = nOffset - 1; + break; + case OFileTable::FILE_BOOKMARK: + m_nRowPos = nOffset - 1; + break; + } + + // OffRange? + // Der FileCursor ist auerhalb des gueltigen Bereichs, wenn + // a.) m_nRowPos < 1 + // b.) Ein KeySet besteht und m_nRowPos > m_pFileSet->size() + if (m_nRowPos < 0 || (m_pFileSet->isFrozen() && eCursorPosition != OFileTable::FILE_BOOKMARK && m_nRowPos >= (INT32)m_pFileSet->size() )) // && m_pFileSet->IsFrozen() + { + // aStatus.Set(SQL_STAT_NO_DATA_FOUND); + goto Error; + } + else + { + if (m_nRowPos < (INT32)m_pFileSet->size()) + { + // Fetch ueber Index + ExecuteRow(OFileTable::FILE_BOOKMARK,(*m_pFileSet)[m_nRowPos],TRUE,FALSE,bRetrieveData); + + // now set the bookmark for outside + (*m_aRow->begin()) = sal_Int32(m_nRowPos + 1); + } + else // Index mu weiter aufgebaut werden + { + // Zunaechst auf die letzte bekannte Zeile setzen + if (m_pFileSet->size()) + { + m_aFileSetIter = m_pFileSet->end()-1; + // m_pFileSet->SeekPos(m_pFileSet->size()-1); + m_pTable->seekRow(OFileTable::FILE_BOOKMARK, *m_aFileSetIter, m_nFilePos); + } + sal_Bool bOK = sal_True; + // Ermitteln der Anzahl weiterer Fetches + while (bOK && m_nRowPos >= (INT32)m_pFileSet->size()) + { + if (m_pEvaluationKeySet) + { + if (m_nRowPos >= (INT32)m_pEvaluationKeySet->size()) + return sal_False; + // aStatus.Set(SQL_STAT_NO_DATA_FOUND); + else if (m_nRowPos == 0) + { + m_aEvaluateIter = m_pEvaluationKeySet->begin(); + bOK = ExecuteRow(OFileTable::FILE_BOOKMARK,*m_aEvaluateIter,FALSE,TRUE, bRetrieveData); + } + else + { + ++m_aEvaluateIter; + bOK = ExecuteRow(OFileTable::FILE_BOOKMARK,*m_aEvaluateIter,FALSE,TRUE, bRetrieveData); + } + } + else + bOK = ExecuteRow(OFileTable::FILE_NEXT,1,FALSE,TRUE, bRetrieveData); + } + + if (bOK) + { + // jetzt nochmal die Ergebnisse lesen + m_pTable->fetchRow(m_aRow, m_pTable->getTableColumns().getBody(), bRetrieveData); + + // now set the bookmark for outside + (*m_aRow->begin()) = sal_Int32(m_nRowPos + 1); + } + else if (!m_pFileSet->isFrozen()) // keinen gueltigen Satz gefunden + { + //m_pFileSet->Freeze(); + m_pFileSet->setFrozen(); + + DELETEZ(m_pEvaluationKeySet); + // aStatus.Set(SQL_STAT_NO_DATA_FOUND); + goto Error; + } + } + } + } + } + else if (m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT_COUNT) + { + // Fetch des COUNT(*) + switch (eCursorPosition) + { + case OFileTable::FILE_NEXT: + m_nRowPos++; + break; + case OFileTable::FILE_PRIOR: + m_nRowPos--; + break; + case OFileTable::FILE_FIRST: + m_nRowPos = 0; + break; + case OFileTable::FILE_LAST: + m_nRowPos = 0; + break; + case OFileTable::FILE_RELATIVE: + m_nRowPos += nOffset; + break; + case OFileTable::FILE_BOOKMARK: + case OFileTable::FILE_ABSOLUTE: + m_nRowPos = nOffset - 1; + break; + } + + if (m_nRowPos == 0) + { + // COUNT(*) in Ergebnisrow packen + // (muss die erste und einzige Variable in der Row sein) + if (m_aRow->size() == 2) + { + (*m_aRow)[1] = m_nRowCountResult; + (*m_aRow)[0] = sal_Int32(1); + } + } + else + { + goto Error; + } + } + else + // Fetch nur bei SELECT moeglich! + return sal_False; + + if(m_aRow->isDeleted()) + goto IgnoreDeletedRows; + return sal_True; + +Error: + // steht der Cursor vor dem ersten Satz + // dann wird die position beibehalten + if (nTempPos == -1) + m_nRowPos = nTempPos; + else + { + switch(eCursorPosition) + { + case OFileTable::FILE_PRIOR: + case OFileTable::FILE_FIRST: + m_nRowPos = -1; + break; + case OFileTable::FILE_LAST: + case OFileTable::FILE_NEXT: + case OFileTable::FILE_ABSOLUTE: + case OFileTable::FILE_RELATIVE: + if (nOffset > 0) + m_nRowPos = (m_pFileSet) ? m_pFileSet->size() : -1; + else if (nOffset < 0) + m_nRowPos = -1; + break; + case OFileTable::FILE_BOOKMARK: + m_nRowPos = nTempPos; // vorherige Position + } + } + // delete pGuard; + // rMode = (!bShowDeleted && aStatus.IsSuccessful() && m_aRow->isDeleted()) ? // keine Anzeige von gelschten Stzen + // OCursor::SQL_MOD_INVALID : OCursor::SQL_MOD_NONE; + return sal_False; +} +// ------------------------------------------------------------------------- +OFILEKeyValue* OResultSet::GetOrderbyKeyValue(OValueRow _rRow) +{ + UINT32 nBookmarkValue = Abs((sal_Int32)(*_rRow)[0]); + + OFILEKeyValue* pKeyValue = new OFILEKeyValue((UINT32)nBookmarkValue); + for (int i = 0; i < sizeof nOrderbyColumnNumber / sizeof (* nOrderbyColumnNumber); i++) + { + if (nOrderbyColumnNumber[i] == SQL_COLUMN_NOTFOUND) break; + + OFileValue xKey = (*_rRow)[nOrderbyColumnNumber[i]]; + switch (xKey.getType()) + { + case ::com::sun::star::sdbc::DataType::VARCHAR: + case ::com::sun::star::sdbc::DataType::CHAR: + pKeyValue->SetKey(i,(rtl::OUString)xKey); + break; + default: + pKeyValue->SetKey(i,(double)xKey); + break; + } + } + return pKeyValue; +} +OFILESortIndex * OFILESortIndex::pCurrentIndex; +CharSet OFILESortIndex::eCurrentCharSet; +//------------------------------------------------------------------ +OFILESortIndex::OFILESortIndex(const OKeyType eKeyType2[], // Genau 3 Eintraege! + const BOOL bAscending2[], // Genau 3 Eintraege! + INT32 nMaxNumberOfRows, CharSet eSet) // Obere Schranke fuer die Anzahl indizierbarer Zeilen + : nMaxCount(nMaxNumberOfRows), + nCount(0), + bFrozen(FALSE), eCharSet(eSet) +{ + for (int j = 0; j < SQL_ORDERBYKEYS; j++) + { + eKeyType[j] = eKeyType2[j]; + bAscending[j] = bAscending2[j]; + } + +#if defined MAX_KEYSET_SIZE + // Zur Sicherheit Maximalgroesse nochmal pruefen: + if (nMaxCount > MAX_KEYSET_SIZE) + { + DBG_WARNING("OFILESortIndex::OFILESortIndex: nMaxNumberOfRows zur Zeit auf <16K beschraenkt!"); + nMaxCount = MAX_KEYSET_SIZE; + } +#endif + + ppKeyValueArray = new OFILEKeyValuePtr[nMaxCount]; + + for (INT32 i = 0; i < nMaxCount; i++) + ppKeyValueArray[i] = NULL; +} + +//------------------------------------------------------------------ +OFILESortIndex::~OFILESortIndex() +{ + +// Nicht mehr noetig - wird durch Freeze() erledigt ... +// for (INT32 i = 0; i < nCount; i++) { +// delete ppKeyValueArray[i]; +// } + + __DELETE(nMaxCount) ppKeyValueArray; +} + + +//------------------------------------------------------------------ +BOOL OFILESortIndex::AddKeyValue(OFILEKeyValue * pKeyValue) +{ + if (nCount < nMaxCount) + { + if (bFrozen) // wenn der Index schon eingefroren + // dann wird der Key einfach ans Ende gehaengt + { + OSL_ENSHURE(pKeyValue != NULL,"OFILESortIndex::Freeze: pKeyValue == NULL"); + INT32 nValue = pKeyValue->GetValue(); // Wert holen ... + + // Strings in KeyValue freigeben! + for (int j = 0; j < SQL_ORDERBYKEYS; j++) + { + if (eKeyType[j] == SQL_ORDERBYKEY_STRING) + delete pKeyValue->GetKeyString(j); + } + delete pKeyValue; + ppKeyValueArray[nCount++] = (OFILEKeyValuePtr) nValue; + } + else + ppKeyValueArray[nCount++] = pKeyValue; + return TRUE; + } + else + return FALSE; +} + + +//------------------------------------------------------------------ +void OFILESortIndex::Freeze() +{ + OSL_ENSHURE(! bFrozen,"OFILESortIndex::Freeze: already frozen!"); + + // Kritischer Bereich: Hinterlegung von this in statischer Variable. + // Zugriff auf diese Variable von der OFILECompare-Funktion aus. + // Da dies NUR waehrend der Ausfuehrung der qsort-Funktion stattfindet, + // ist dies aber unkritisch: unter Windows 3.x ist diese Ausfuehrung + // UNUNTERBRECHBAR; unter NT, OS/2, Unix, ... hat jede DLL ihr + // eigenes Datensegment. + pCurrentIndex = this; + eCurrentCharSet = eCharSet; + + // Sortierung: + if (eKeyType[0] != SQL_ORDERBYKEY_NONE) + // Sortierung, wenn mindestens nach dem ersten Key sortiert werden soll: + qsort(ppKeyValueArray,nCount,sizeof(void *),&OFILEKeyCompare); + + + // Ende des kritischen Bereiches + pCurrentIndex = NULL; + + // Wert auslesen, KeyValue loeschen und in den void * den Value + // reinschreiben (uebler Trick mit Typecast!) + for (INT32 i = 0; i < nCount; i++) + { + OFILEKeyValuePtr pKeyValue = ppKeyValueArray[i]; + + OSL_ENSHURE(pKeyValue != NULL,"OFILESortIndex::Freeze: pKeyValue == NULL"); + INT32 nValue = pKeyValue->GetValue(); // Wert holen ... + + // Strings in KeyValue freigeben! + for (int j = 0; j < SQL_ORDERBYKEYS; j++) + { + if (eKeyType[j] == SQL_ORDERBYKEY_STRING) + delete pKeyValue->GetKeyString(j); + } + delete pKeyValue; + ppKeyValueArray[i] = (OFILEKeyValuePtr) nValue; + } + + bFrozen = TRUE; +} + +//------------------------------------------------------------------ +INT32 OFILESortIndex::GetValue(INT32 nPos) const +{ + OSL_ENSHURE(nPos > 0,"OFILESortIndex::GetValue: nPos == 0"); + OSL_ENSHURE(nPos <= nCount,"OFILESortIndex::GetValue: Zugriff ausserhalb der Array-Grenzen"); + +// OSL_ENSHURE(ppKeyValueArray[nPos-1] != NULL,"OFILESortIndex::GetValue: interner Fehler: kein KeyValue an dieser Stelle"); +// return ppKeyValueArray[nPos-1]->GetValue(); + + if (!bFrozen) + { + if (eKeyType[0] == SQL_ORDERBYKEY_NONE) // wenn keine Sortierung vorliegt + // darf auf die Values schon vorher zugegriffen werden + return ppKeyValueArray[nPos-1]->GetValue(); + else + { + OSL_ASSERT("OFILESortIndex::GetValue: Invalid use of index!"); + return 0; + } + } + else + return (INT32) ppKeyValueArray[nPos-1]; // Trick: nach Freeze sind hier nur noch Values, keine KeyValue-Strukturen mehr! + +} + +//------------------------------------------------------------------ +OKeySet* OFILESortIndex::CreateKeySet() +{ + + OSL_ENSHURE(! bFrozen,"OFILESortIndex::Freeze: already frozen!"); + + // Kritischer Bereich: Hinterlegung von this in statischer Variable. + // Zugriff auf diese Variable von der OFILECompare-Funktion aus. + // Da dies NUR waehrend der Ausfuehrung der qsort-Funktion stattfindet, + // ist dies aber unkritisch: unter Windows 3.x ist diese Ausfuehrung + // UNUNTERBRECHBAR; unter NT, OS/2, Unix, ... hat jede DLL ihr + // eigenes Datensegment. + pCurrentIndex = this; + eCurrentCharSet = eCharSet; + + // Sortierung: + if (eKeyType[0] != SQL_ORDERBYKEY_NONE) + // Sortierung, wenn mindestens nach dem ersten Key sortiert werden soll: + qsort(ppKeyValueArray,nCount,sizeof(void *),&OFILEKeyCompare); + + + // Ende des kritischen Bereiches + pCurrentIndex = NULL; + + + OKeySet* pKeySet = new OKeySet(nCount); + OKeySet::iterator aIter = pKeySet->begin(); + for (INT32 i = 0; i < nCount; i++,++aIter) + { + OFILEKeyValuePtr pKeyValue = ppKeyValueArray[i]; + + OSL_ENSHURE(pKeyValue != NULL,"OFILESortIndex::Freeze: pKeyValue == NULL"); + (*aIter) = pKeyValue->GetValue(); // Wert holen ... + + // Strings in KeyValue freigeben! + for (int j = 0; j < SQL_ORDERBYKEYS; j++) + { + if (eKeyType[j] == SQL_ORDERBYKEY_STRING) + delete pKeyValue->GetKeyString(j); + } + delete pKeyValue; + } + bFrozen = TRUE; + pKeySet->setFrozen(); + return pKeySet; +} + +//------------------------------------------------------------------ +int +#if defined(WIN) || defined(WNT) +__cdecl +#endif +#if defined(ICC) && defined(OS2) +_Optlink +#endif +connectivity::file::OFILEKeyCompare(const void * elem1, const void * elem2) +{ + const OFILESortIndex * pIndex = OFILESortIndex::pCurrentIndex; + const OFILEKeyValue * pKeyValue1 = (OFILEKeyValue *) * (OFILEKeyValue **) elem1; + const OFILEKeyValue * pKeyValue2 = (OFILEKeyValue *) * (OFILEKeyValue **) elem2; + + // Ueber die (max.) drei ORDER BY-Columns iterieren. Abbruch des Vergleiches, wenn Ungleichheit erkannt + // oder alle Columns gleich. + for (UINT16 i = 0; i < SQL_ORDERBYKEYS && pIndex->eKeyType[i] != SQL_ORDERBYKEY_NONE; i++) + { + const int nGreater = (pIndex->bAscending[i]) ? 1 : -1; + const int nLess = - nGreater; + + // Vergleich (je nach Datentyp): + switch (pIndex->eKeyType[i]) + { + case SQL_ORDERBYKEY_STRING: + { + INT32 nRes = pKeyValue1->GetKeyString(i)->compareTo(*pKeyValue2->GetKeyString(i)); + if (nRes < 0) + return nLess; + else if (nRes > 0) + return nGreater; + } + break; + case SQL_ORDERBYKEY_DOUBLE: + { + double d1 = pKeyValue1->GetKeyDouble(i); + double d2 = pKeyValue2->GetKeyDouble(i); + + if (d1 < d2) + return nLess; + else if (d1 > d2) + return nGreater; + } + break; + } + } + + // Wenn wir bis hierher gekommen sind, waren alle Werte gleich: + return 0; +} +//------------------------------------------------------------------ +BOOL OResultSet::OpenImpl() +{ + const OSQLTables& xTabs = m_aSQLIterator.getTables(); + OSL_ENSHURE(xTabs.begin() != xTabs.end(),"NO table in statement!"); + + OSQLTable xTable = xTabs.begin()->second; + m_xColumns = m_aSQLIterator.getSelectColumns(); + + m_xColNames = xTable->getColumns(); + + Reference<XIndexAccess> xNames(m_xColNames,UNO_QUERY); + + m_aRow = new OValueVector(xNames->getCount()); + m_aEvaluateRow = new OValueVector(xNames->getCount()); + // m_aParameterRow = new OValueVector(); + m_aAssignValues = new OAssignValues(); + + if(!m_xParamColumns.isValid()) + m_xParamColumns = new OSQLColumns(); + + m_aSQLAnalyzer.clean(); + + Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(xTable,UNO_QUERY); + if(xTunnel.is()) + { + m_pTable = (OFileTable*)xTunnel->getSomething(OFileTable::getUnoTunnelImplementationId()); + if(m_pTable) + m_pTable->acquire(); + } + + GetAssignValues(); // assign values and describe parameter columns + m_aSQLAnalyzer.setParameterColumns(m_xParamColumns); + anylizeSQL(); + // m_aSQLAnalyzer.describeParam(m_xParamColumns); + + + // now check which columns are bound + OValueVector::iterator aRowIter = m_aRow->begin(); + ::utl::UStringMixEqual aCase(m_xDBMetaData->storesMixedCaseQuotedIdentifiers()); + sal_Int32 i=0; + Reference<XFastPropertySet> xProp; + ++aRowIter; + for(OSQLColumns::iterator aIter = m_xColumns->begin();aIter != m_xColumns->end();++aIter,++i,++aRowIter) + { + xNames->getByIndex(i) >>= xProp; + try + { + aRowIter->setBound(aCase(connectivity::getString(xProp->getFastPropertyValue(PROPERTY_ID_NAME)),connectivity::getString((*aIter)->getFastPropertyValue(PROPERTY_ID_REALNAME)))); + sal_Int32 nType; + xProp->getFastPropertyValue(PROPERTY_ID_TYPE) >>= nType; + aRowIter->setType(nType); + } + catch(...) + { + } + } + + + + + // Parameter substituieren (AssignValues und Kriterien): + if (m_xParamColumns->size()) + { + // Zunchst AssignValues + USHORT nParaCount=0; // gibt die aktuelle Anzahl der bisher gesetzen Parameter an + + // Nach zu substituierenden Parametern suchen: + UINT16 nCount = m_aAssignValues.isValid() ? m_aAssignValues->size() : 1; // 1 ist wichtig fr die Kriterien + for (UINT16 j = 1; j < nCount; j++) + { +// if ((*m_aAssignValues)[j].isNull()) +// continue; + + UINT32 nParameter = (*m_aAssignValues).getParameterIndex(j); + if (nParameter == SQL_NO_PARAMETER) + continue; // dieser AssignValue ist kein Parameter + + ++nParaCount; // ab hier ist der Parameter gueltig + // Parameter ersetzen. Wenn Parameter nicht verfuegbar, + // Value auf NULL setzen. + (*m_aAssignValues)[j] = (*m_aParameterRow)[(UINT16)nParameter]; + } + + if (m_aParameterRow.isValid() && nParaCount < m_aParameterRow->size()) + m_aSQLAnalyzer.bindParameterRow(m_aParameterRow); + } + + // Neuen Index aufbauen: + DELETEZ(m_pFileSet); + DELETEZ(m_pEvaluationKeySet); + + // if (!aEvaluateRow.Is()) + { + // aEvaluateRow = new ODbRow(*aFileColumns, FALSE); + // (*aEvaluateRow)[0] = new ODbVariant(); + + // Row zur Auswertung binden, wenn Preprocessing erfolg, dann bereits ein Keyset + m_pEvaluationKeySet = m_aSQLAnalyzer.bindResultRow(m_aEvaluateRow); // Werte im Code des Compilers setzen + // (Verbindung zur ResultRow herstellen) + } + + // An den Anfang positionieren + m_nRowPos = -1; + m_nFilePos = 0; + m_nRowCountResult = -1; + + // exclusiver zugriff auf die Tabelle + // NAMESPACE_VOS(OGuard)* pGuard = pTable->Lock(); + m_nLastVisitedPos = m_pTable->getCurrentLastPos(); + + UINT32 nLoopCount = 0; + switch(m_aSQLIterator.getStatementType()) + { + case SQL_STATEMENT_SELECT: + { + INT32 nMaxRowCount = m_pTable->getCurrentLastPos(); + + BOOL bDistinct = FALSE; + BOOL bWasSorted = FALSE; + OSQLParseNode *pDistinct = m_pParseTree->getChild(1); + if (pDistinct && pDistinct->getTokenID() == SQL_TOKEN_DISTINCT ) + { + if(!IsSorted()) + { + nOrderbyColumnNumber[0] = 1; + bOrderbyAscending[0] = FALSE; + } + else + bWasSorted = TRUE; + bDistinct = TRUE; + } + // Ohne Restriction und Sortierung RowCount bekannt. + // if (!HasRestriction() && !IsSorted() && bShowDeleted) + // SetRowCount(MaxRowCount()); + + OSL_ENSHURE(sizeof nOrderbyColumnNumber / sizeof (* nOrderbyColumnNumber) == SQL_ORDERBYKEYS,"Maximale Anzahl der ORDER BY Columns muss derzeit genau 3 sein!"); + OKeyType eKeyType[SQL_ORDERBYKEYS]; + aRowIter = m_aRow->begin(); + for (int i = 0; i < SQL_ORDERBYKEYS; i++) + { + if (nOrderbyColumnNumber[i] == SQL_COLUMN_NOTFOUND) + eKeyType[i] = SQL_ORDERBYKEY_NONE; + else + { + switch (aRowIter->getType()) + { + case DataType::CHAR: + case DataType::VARCHAR: + eKeyType[i] = SQL_ORDERBYKEY_STRING; + break; + + case DataType::OTHER: + case DataType::TINYINT: + case DataType::SMALLINT: + case DataType::INTEGER: + case DataType::DECIMAL: + case DataType::NUMERIC: + case DataType::REAL: + case DataType::DOUBLE: + case DataType::DATE: + case DataType::TIME: + case DataType::TIMESTAMP: + case DataType::BIT: + eKeyType[i] = SQL_ORDERBYKEY_DOUBLE; + break; + + // Andere Typen sind nicht implementiert (und damit immer FALSE) + default: + eKeyType[i] = SQL_ORDERBYKEY_NONE; + OSL_ASSERT("OFILECursor::Execute: Datentyp nicht implementiert"); + break; + } + (*m_aEvaluateRow)[nOrderbyColumnNumber[i]].setBound(sal_True); + } + } + + // Nur wenn Sortierung gewuenscht, ueber alle Datensaetze iterieren und + // dabei den "Key", nach dem sortiert werden soll, in den Index eintragen: + if (IsSorted()) + { + if (!m_aSQLAnalyzer.hasRestriction() && nOrderbyColumnNumber[1] == SQL_COLUMN_NOTFOUND) + { + // Ist nur ein Feld fuer die Sortierung angegeben + // Und diese Feld ist indiziert, dann den Index ausnutzen + Reference<XIndexesSupplier> xIndexSup(xTable,UNO_QUERY); + Reference<XIndexAccess> xIndexes; + if(xIndexSup.is()) + { + xIndexes = Reference<XIndexAccess>(xIndexSup->getIndexes(),UNO_QUERY); + Reference<XFastPropertySet> xColProp; + xNames->getByIndex(nOrderbyColumnNumber[0]) >>= xColProp; + // iterate through the indexes to find the matching column + for(sal_Int32 i=0;i<xIndexes->getCount();++i) + { + Reference<XColumnsSupplier> xIndex; + xIndexes->getByIndex(i) >>= xIndex; + Reference<XNameAccess> xIndexCols = xIndex->getColumns(); + if(xIndexCols->hasByName(connectivity::getString(xColProp->getFastPropertyValue(PROPERTY_ID_NAME)))) + { + m_pFileSet = new OKeySet(); + + Reference<XUnoTunnel> xTunnel(xIndex,UNO_QUERY); + if(xTunnel.is()) + { + dbase::ODbaseIndex* pIndex = (dbase::ODbaseIndex*)xTunnel->getSomething(dbase::ODbaseIndex::getUnoTunnelImplementationId()); + if(pIndex) + { + dbase::OIndexIterator* pIter = pIndex->createIterator(NULL,NULL); + + if (pIter) + { + sal_uInt32 nRec = pIter->First(); + while (nRec != SQL_COLUMN_NOTFOUND) + { + if (bOrderbyAscending[0]) + m_pFileSet->push_back(nRec); + else + m_pFileSet->insert(m_pFileSet->begin(),nRec); + nRec = pIter->Next(); + } + m_pFileSet->setFrozen(); + // m_bFileSetFrozen = sal_True; + // if(!bDistinct) + // SetRowCount(pFileSet->count()); + goto DISTINCT; + } + + delete pIter; + } + } + } + } + } + } + + m_pSortIndex = new OFILESortIndex(eKeyType, + bOrderbyAscending, + nMaxRowCount,RTL_TEXTENCODING_MS_1252); + + sal_Bool bOK = sal_True; + if (m_pEvaluationKeySet) + { + if (m_pEvaluationKeySet->size()) + m_aEvaluateIter = m_pEvaluationKeySet->begin(); + + } + while (bOK) + { + if (m_pEvaluationKeySet) + { + ExecuteRow(OFileTable::FILE_BOOKMARK,(*m_aEvaluateIter),FALSE,TRUE); + ++m_aEvaluateIter; + bOK = m_aEvaluateIter == m_pEvaluationKeySet->end(); + } + else + bOK = ExecuteRow(OFileTable::FILE_NEXT,1,FALSE,TRUE); + } + + // Sortiertes Keyset erzeugen + DELETEZ(m_pEvaluationKeySet); + m_pFileSet = m_pSortIndex->CreateKeySet(); + // if(!bDistinct) + // SetRowCount(pFileSet->count()); + DELETEZ(m_pSortIndex); + // Nun kann ueber den Index sortiert zugegriffen werden. + } + + if (!m_pFileSet) + { + m_pFileSet = new OKeySet(); + + if (!m_aSQLAnalyzer.hasRestriction()) + // jetzt kann das Keyset schon gefuellt werden! + // Aber Achtung: es wird davon ausgegangen, das die FilePositionen als Folge 1..n + // abgelegt werden! + { + for (sal_uInt32 i = 0; i < m_pTable->getCurrentLastPos(); i++) + m_pFileSet->push_back(i + 1); + } + } + OSL_ENSHURE(m_pFileSet,"Kein KeySet vorhanden! :-("); +DISTINCT: if(bDistinct && m_pFileSet) // sicher ist sicher + { + OValueRow aSearchRow;//(m_aRow); + // ODbRowRef aSearchRow = new ODbRow(*aFileRow); // nach dieser wird gesucht + // const ODbRow &rSearchRow = *aSearchRow, + // &rFileRow = *aFileRow; + INT32 nPos; + UINT16 nMaxRow = m_pFileSet->size(); + if (nMaxRow) + { +#if DEBUG + INT32 nFound=0; +#endif + vector<BOOL> nWasAllwaysFound(nMaxRow,FALSE); + INT32 nPrev_i; + for(INT32 j= nMaxRow-1;j >= 0;j--) + { + nPos = (*m_pFileSet)[j]; // aktuell zu lschender Key + if(!nWasAllwaysFound[j] && nPos) // nur falls noch nicht nach dieser Row gesucht wurde + { + ExecuteRow(OFileTable::FILE_BOOKMARK,nPos,TRUE,FALSE); + aSearchRow = m_aRow; + // jetzt den Rest nach doppelten durchsuchen + INT32 nKey; + nPrev_i = j; + for(INT32 i = j-1; i >= 0 ;i--) + { + nKey = (*m_pFileSet)[i]; + ExecuteRow(OFileTable::FILE_BOOKMARK,nKey ,TRUE,FALSE); + if(!nWasAllwaysFound[i] && aSearchRow == m_aRow) + { + // gefunden + // Key an der Stelle 0 setzen. + (*m_pFileSet)[nPrev_i] = 0; + // und altes i merken + nPrev_i = i; + nPos = nKey; // auf naechste gltige Position setzen + nWasAllwaysFound[i] = TRUE; + + } + } + } +#if DEBUG + else + nFound++; +#endif + } + vector<INT32>::iterator aIter = m_pFileSet->end()-1; + while(aIter != m_pFileSet->begin()) + { + if(!(*aIter)) + m_pFileSet->erase(aIter); + aIter--; + } + if (!bWasSorted) + { + nOrderbyColumnNumber[0] = SQL_COLUMN_NOTFOUND; + sort(m_pFileSet->begin(),m_pFileSet->end()); + } + } + // SetRowCount(m_pFileSet->count()); + } + } break; + + case SQL_STATEMENT_SELECT_COUNT: + case SQL_STATEMENT_UPDATE: + case SQL_STATEMENT_DELETE: + // waehrend der Bearbeitung die Anzahl der bearbeiteten Rows zaehlen: + m_nRowCountResult = 0; + // Vorlaeufig einfach ueber alle Datensaetze iterieren und + // dabei die Aktionen bearbeiten (bzw. einfach nur zaehlen): + { + + sal_Bool bOK = sal_True; + if (m_pEvaluationKeySet) + { + m_aEvaluateIter = m_pEvaluationKeySet->begin(); + bOK = m_aEvaluateIter == m_pEvaluationKeySet->end(); + + } + while (bOK) + { + if (m_pEvaluationKeySet) + ExecuteRow(OFileTable::FILE_BOOKMARK,(*m_aEvaluateIter),FALSE,TRUE); + else + bOK = ExecuteRow(OFileTable::FILE_NEXT,1,FALSE,TRUE); + + if (bOK) + { + m_nRowCountResult++; + if(m_pEvaluationKeySet) + { + ++m_aEvaluateIter; + bOK = m_aEvaluateIter == m_pEvaluationKeySet->end(); + } + } + } + + // Ergebnis von COUNT(*) in nRowCountResult merken. + // nRowCount, also die Anzahl der Rows in der Ergebnismenge, ist bei dieser + // Anfrage = 1! + DELETEZ(m_pEvaluationKeySet); + } + // SetRowCount(1); + break; + case SQL_STATEMENT_INSERT: + m_nRowCountResult = 0; + + if(!m_pTable->InsertRow(m_aAssignValues, TRUE,Reference<XIndexAccess>(m_xColNames,UNO_QUERY))) + { + m_nFilePos = 0; + return sal_False; + } + + m_nRowCountResult = 1; + break; + } + + // FilePos zuruecksetzen + m_nFilePos = 0; + + return sal_True; +} +//------------------------------------------------------------------ +void OResultSet::anylizeSQL() +{ + // start analysing the statement + m_aSQLAnalyzer.setOrigColumns(m_xColNames); + m_aSQLAnalyzer.start(m_pParseTree); + + const OSQLParseNode* pOrderbyClause = m_aSQLIterator.getOrderTree(); + if(pOrderbyClause) + { + OSQLParseNode * pOrderingSpecCommalist = pOrderbyClause->getChild(2); + OSL_ENSHURE(SQL_ISRULE(pOrderingSpecCommalist,ordering_spec_commalist),"OResultSet: Fehler im Parse Tree"); + + for (sal_uInt32 m = 0; m < pOrderingSpecCommalist->count(); m++) + { + OSQLParseNode * pOrderingSpec = pOrderingSpecCommalist->getChild(m); + OSL_ENSHURE(SQL_ISRULE(pOrderingSpec,ordering_spec),"OResultSet: Fehler im Parse Tree"); + OSL_ENSHURE(pOrderingSpec->count() == 2,"OResultSet: Fehler im Parse Tree"); + + OSQLParseNode * pColumnRef = pOrderingSpec->getChild(0); + if(!SQL_ISRULE(pColumnRef,column_ref)) + { + // aStatus.SetStatementTooComplex(); + return; + } + OSQLParseNode * pAscendingDescending = pOrderingSpec->getChild(1); + setOrderbyColumn((UINT16)m,pColumnRef,pAscendingDescending); + } + } +} + + +//------------------------------------------------------------------ +void OResultSet::setOrderbyColumn(UINT16 nOrderbyColumnNo, + OSQLParseNode* pColumnRef, + OSQLParseNode* pAscendingDescending) +{ + if (nOrderbyColumnNo >= (sizeof nOrderbyColumnNumber / sizeof (* nOrderbyColumnNumber))) + { + // aStatus.SetStatementTooComplex(); + return; + } + + String aColumnName; + if (pColumnRef->count() == 1) + aColumnName = pColumnRef->getChild(0)->getTokenValue(); + else if (pColumnRef->count() == 3) + { + // Nur die Table Range-Variable darf hier vorkommen: +// if (!(pColumnRef->getChild(0)->getTokenValue() == aTableRange)) +// { +// aStatus.Set(SQL_STAT_ERROR, +// String::CreateFromAscii("S1000"), +// aStatus.CreateErrorMessage(String(SdbResId(STR_STAT_INVALID_RANGE_VAR))), +// 0, String() ); + // return; + // } + aColumnName = pColumnRef->getChild(2)->getTokenValue(); + } + else + { + // aStatus.SetStatementTooComplex(); + return; + } + + Reference<XColumnLocate> xColLocate(m_xColNames,UNO_QUERY); + if(!xColLocate.is()) + return; + // Alles geprueft und wir haben den Namen der Column. + // Die wievielte Column ist das? + nOrderbyColumnNumber[nOrderbyColumnNo] = xColLocate->findColumn(aColumnName)-1; + + // Ascending or Descending? + bOrderbyAscending[nOrderbyColumnNo] = (SQL_ISTOKEN(pAscendingDescending,DESC)) ? + FALSE : TRUE; +} + +//-------------------------------------------------------------------------- +Sequence< sal_Int8 > OResultSet::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 OResultSet::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException) +{ + if (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) + return (sal_Int64)this; + + return 0; +} +//------------------------------------------------------------------ +void OResultSet::GetAssignValues() +{ + if (m_pParseTree == NULL) + { + // aStatus.SetInvalidStatement(); + return; + } + + if (SQL_ISRULE(m_pParseTree,select_statement)) + // Keine zu setzenden Werte bei SELECT + return; + else if (SQL_ISRULE(m_pParseTree,insert_statement)) + { + // Row fuer die zu setzenden Werte anlegen (Referenz durch new) + m_aAssignValues = new OAssignValues(Reference<XIndexAccess>(m_xColNames,UNO_QUERY)->getCount()); + + // Liste der Columns-Namen, die in der column_commalist vorkommen (mit ; getrennt): + ::std::vector<String> aColumnNameList; + + OSL_ENSHURE(m_pParseTree->count() >= 4,"OResultSet: Fehler im Parse Tree"); + + OSQLParseNode * pOptColumnCommalist = m_pParseTree->getChild(3); + OSL_ENSHURE(pOptColumnCommalist != NULL,"OResultSet: Fehler im Parse Tree"); + OSL_ENSHURE(SQL_ISRULE(pOptColumnCommalist,opt_column_commalist),"OResultSet: Fehler im Parse Tree"); + if (pOptColumnCommalist->count() == 0) + { + const Sequence< ::rtl::OUString>& aNames = m_xColNames->getElementNames(); + const ::rtl::OUString* pBegin = aNames.getConstArray(); + aColumnNameList.insert(aColumnNameList.begin(),::std::vector<String>::const_iterator(pBegin),::std::vector<String>::const_iterator(pBegin + aNames.getLength())); + } + else + { + OSL_ENSHURE(pOptColumnCommalist->count() == 3,"OResultSet: Fehler im Parse Tree"); + + OSQLParseNode * pColumnCommalist = pOptColumnCommalist->getChild(1); + OSL_ENSHURE(pColumnCommalist != NULL,"OResultSet: Fehler im Parse Tree"); + OSL_ENSHURE(SQL_ISRULE(pColumnCommalist,column_commalist),"OResultSet: Fehler im Parse Tree"); + OSL_ENSHURE(pColumnCommalist->count() > 0,"OResultSet: Fehler im Parse Tree"); + + // Alle Columns in der column_commalist ... + for (sal_uInt32 i = 0; i < pColumnCommalist->count(); i++) + { + OSQLParseNode * pCol = pColumnCommalist->getChild(i); + OSL_ENSHURE(pCol != NULL,"OResultSet: Fehler im Parse Tree"); + aColumnNameList.push_back(pCol->getTokenValue()); + } + } + if(!aColumnNameList.size()) + throw SQLException(); + + // Werte ... + OSQLParseNode * pValuesOrQuerySpec = m_pParseTree->getChild(4); + OSL_ENSHURE(pValuesOrQuerySpec != NULL,"OResultSet: pValuesOrQuerySpec darf nicht NULL sein!"); + OSL_ENSHURE(SQL_ISRULE(pValuesOrQuerySpec,values_or_query_spec),"OResultSet: ! SQL_ISRULE(pValuesOrQuerySpec,values_or_query_spec)"); + OSL_ENSHURE(pValuesOrQuerySpec->count() > 0,"OResultSet: pValuesOrQuerySpec->count() <= 0"); + + // nur "VALUES" ist erlaubt ... + if (! SQL_ISTOKEN(pValuesOrQuerySpec->getChild(0),VALUES)) + throw SQLException(); + + OSL_ENSHURE(pValuesOrQuerySpec->count() == 2,"OResultSet: pValuesOrQuerySpec->count() != 2"); + + // Liste von Werten + OSQLParseNode * pInsertAtomCommalist = pValuesOrQuerySpec->getChild(1); + OSL_ENSHURE(pInsertAtomCommalist != NULL,"OResultSet: pInsertAtomCommalist darf nicht NULL sein!"); + OSL_ENSHURE(pInsertAtomCommalist->count() > 0,"OResultSet: pInsertAtomCommalist <= 0"); + + String aColumnName; + OSQLParseNode * pRow_Value_Const; + xub_StrLen nIndex=0; + for (sal_uInt32 i = 0; i < pInsertAtomCommalist->count(); i++) + { + pRow_Value_Const = pInsertAtomCommalist->getChild(i); // row_value_constructor + if(pRow_Value_Const->count() == 3) // '(' row_value_const_list ')' + { + pRow_Value_Const = pRow_Value_Const->getChild(1); // row_value_const_list + OSL_ENSHURE(pRow_Value_Const != NULL,"OResultSet: pRow_Value_Const darf nicht NULL sein!"); + if(pRow_Value_Const->count() == 0) + { + if(pRow_Value_Const->count() == (aColumnNameList.size()-1)) + ParseAssignValues(aColumnNameList,pRow_Value_Const,nIndex++); // kann nur ein Columnname vorhanden sein pro Schleife + else + { +// aStatus.Set(SQL_STAT_ERROR, +// String::CreateFromAscii("S1000"), +// aStatus.CreateErrorMessage(String(SdbResId(STR_STAT_SYNTAX_ERROR))), +// 0, String() ); + throw SQLException(); + } + } + else + { + if(pRow_Value_Const->count() == aColumnNameList.size()) + { + for (sal_uInt32 j = 0; j < pRow_Value_Const->count(); ++j) + ParseAssignValues(aColumnNameList,pRow_Value_Const->getChild(j),nIndex++); + } + else + { +// aStatus.Set(SQL_STAT_ERROR, +// String::CreateFromAscii("S1000"), +// aStatus.CreateErrorMessage(String(SdbResId(STR_STAT_SYNTAX_ERROR))), +// 0, String() ); + throw SQLException(); + } + + } + } + else + { + // aStatus.SetStatementTooComplex(); + throw SQLException(); + } + } + } + else if (SQL_ISRULE(m_pParseTree,update_statement_positioned) || + SQL_ISRULE(m_pParseTree,update_statement_searched)) + { + m_aAssignValues = new OAssignValues(Reference<XIndexAccess>(m_xColNames,UNO_QUERY)->getCount()); + + OSL_ENSHURE(m_pParseTree->count() >= 4,"OResultSet: Fehler im Parse Tree"); + + OSQLParseNode * pAssignmentCommalist = m_pParseTree->getChild(3); + OSL_ENSHURE(pAssignmentCommalist != NULL,"OResultSet: pAssignmentCommalist == NULL"); + OSL_ENSHURE(SQL_ISRULE(pAssignmentCommalist,assignment_commalist),"OResultSet: Fehler im Parse Tree"); + OSL_ENSHURE(pAssignmentCommalist->count() > 0,"OResultSet: pAssignmentCommalist->count() <= 0"); + + // Alle Zuweisungen (Kommaliste) bearbeiten ... + ::std::vector< String> aList(1); + for (sal_uInt32 i = 0; i < pAssignmentCommalist->count(); i++) + { + OSQLParseNode * pAssignment = pAssignmentCommalist->getChild(i); + OSL_ENSHURE(pAssignment != NULL,"OResultSet: pAssignment == NULL"); + OSL_ENSHURE(SQL_ISRULE(pAssignment,assignment),"OResultSet: Fehler im Parse Tree"); + OSL_ENSHURE(pAssignment->count() == 3,"OResultSet: pAssignment->count() != 3"); + + OSQLParseNode * pCol = pAssignment->getChild(0); + OSL_ENSHURE(pCol != NULL,"OResultSet: pCol == NULL"); + + OSQLParseNode * pComp = pAssignment->getChild(1); + OSL_ENSHURE(pComp != NULL,"OResultSet: pComp == NULL"); + OSL_ENSHURE(pComp->getNodeType() == SQL_NODE_EQUAL,"OResultSet: pComp->getNodeType() != SQL_NODE_COMPARISON"); + if (pComp->getTokenValue().GetChar(0) != '=') + { + // aStatus.SetInvalidStatement(); + throw SQLException(); + } + + OSQLParseNode * pVal = pAssignment->getChild(2); + OSL_ENSHURE(pVal != NULL,"OResultSet: pVal == NULL"); + aList[0] = pCol->getTokenValue(); + ParseAssignValues(aList,pVal,0); + } + + } +} +// ------------------------------------------------------------------------- +void OResultSet::ParseAssignValues(const ::std::vector< String>& aColumnNameList,OSQLParseNode* pRow_Value_Constructor_Elem,xub_StrLen nIndex) +{ + OSL_ENSHURE(nIndex <= aColumnNameList.size(),"SdbFileCursor::ParseAssignValues: nIndex > aColumnNameList.GetTokenCount()"); + String aColumnName(aColumnNameList[nIndex]); + OSL_ENSHURE(aColumnName.Len() > 0,"OResultSet: Column-Name nicht gefunden"); + OSL_ENSHURE(pRow_Value_Constructor_Elem != NULL,"OResultSet: pRow_Value_Constructor_Elem darf nicht NULL sein!"); + + if (pRow_Value_Constructor_Elem->getNodeType() == SQL_NODE_STRING || + pRow_Value_Constructor_Elem->getNodeType() == SQL_NODE_INTNUM || + pRow_Value_Constructor_Elem->getNodeType() == SQL_NODE_APPROXNUM) + { + // Wert setzen: + SetAssignValue(aColumnName, pRow_Value_Constructor_Elem->getTokenValue()); + } + else if (SQL_ISTOKEN(pRow_Value_Constructor_Elem,NULL)) + { + // NULL setzen + SetAssignValue(aColumnName, String(), TRUE); + } + else if (SQL_ISRULE(pRow_Value_Constructor_Elem,parameter)) + { + // Parameter hinzufuegen, Typ ... entsprechend der Column, der der Wert zugewiesen wird + Reference<XFastPropertySet> xCol; + m_xColNames->getByName(aColumnName) >>= xCol; + sal_Int32 nParameter = -1; + if(m_xParamColumns.isValid()) + { + OSQLColumns::const_iterator aIter = find(m_xParamColumns->begin(),m_xParamColumns->end(),aColumnName,::utl::UStringMixEqual(m_pTable->isCaseSensitive())); + if(aIter != m_xParamColumns->end()) + nParameter = m_xParamColumns->size() - (m_xParamColumns->end() - aIter) +1;// +1 because the rows start at 1 + } + if(nParameter == -1) + nParameter = AddParameter(pRow_Value_Constructor_Elem,xCol); + // Nr. des Parameters in der Variablen merken: + SetAssignValue(aColumnName, String(), TRUE, nParameter); + } + else + { + // aStatus.SetStatementTooComplex(); + throw SQLException(); + } +} +//------------------------------------------------------------------ +void OResultSet::SetAssignValue(const String& aColumnName, + const String& aValue, + BOOL bSetNull, + UINT32 nParameter) +{ + Reference<XFastPropertySet> xCol; + m_xColNames->getByName(aColumnName) >>= xCol; + sal_Int32 nId = Reference<XColumnLocate>(m_xColNames,UNO_QUERY)->findColumn(aColumnName); + // Kommt diese Column ueberhaupt in der Datei vor? + + if (!xCol.is()) + { + // Diese Column gibt es nicht! +// aStatus.Set(SQL_STAT_ERROR, +// String::CreateFromAscii("S0022"), +// aStatus.CreateErrorMessage(String(SdbResId(STR_STAT_COLUMN_NOT_FOUND))), +// 0, String() ); + throw SQLException(); + } + + // Value an die Row mit den zuzuweisenden Werten binden: + // const ODbVariantRef& xValue = (*aAssignValues)[pFileColumn->GetId()]; + + // Alles geprueft und wir haben den Namen der Column. + // Jetzt eine Value allozieren, den Wert setzen und die Value an die Row binden. + if (bSetNull) + (*m_aAssignValues)[nId].setNull(); + else + { + switch (getINT32(xCol->getFastPropertyValue(PROPERTY_ID_TYPE))) + { + // Kriterium je nach Typ als String oder double in die Variable packen ... + case DataType::CHAR: + case DataType::VARCHAR: + (*m_aAssignValues)[nId] = aValue; + // Zeichensatz ist bereits konvertiert, da ja das gesamte Statement konvertiert wurde + break; + + case DataType::BIT: + { + // nyi: gemischte Gross-/Kleinschreibung??? + if (aValue.EqualsIgnoreCaseAscii("TRUE") || aValue.GetChar(0) == '1') + (*m_aAssignValues)[nId] = sal_True; + else if (aValue.EqualsIgnoreCaseAscii("FALSE") || aValue.GetChar(0) == '0') + (*m_aAssignValues)[nId] = sal_False; + else + { + // aStatus.Set(SQL_STAT_ERROR); // nyi: genauer! + throw SQLException(); + } + } + break; + case DataType::TINYINT: + case DataType::SMALLINT: + case DataType::INTEGER: + case DataType::DECIMAL: + case DataType::NUMERIC: + case DataType::REAL: + case DataType::DOUBLE: + case DataType::DATE: + case DataType::TIME: + case DataType::TIMESTAMP: + { + (*m_aAssignValues)[nId] = aValue.ToDouble(); +// try +// { +// double n = xValue->toDouble(); +// xValue->setDouble(n); +// } +// catch ( ... ) +// { +// aStatus.SetDriverNotCapableError(); +// } + } break; + default: + throw SQLException(); + } + } + + // Parameter-Nr. merken (als User Data) + // SQL_NO_PARAMETER = kein Parameter. + m_aAssignValues->setParameterIndex(nId,nParameter); + // ((ODbAssignRow*)aAssignValues.getBodyPtr())->setAssignedIndex(pFileColumn->GetId(), nParameter); +} + +//------------------------------------------------------------------ +UINT32 OResultSet::AddParameter(OSQLParseNode * pParameter, const Reference<XFastPropertySet>& _xCol) +{ + + // Nr. des neu hinzuzufuegenden Parameters: + UINT32 nParameter = m_xParamColumns->size()+1; + + OSL_ENSHURE(SQL_ISRULE(pParameter,parameter),"OResultSet::AddParameter: Argument ist kein Parameter"); + OSL_ENSHURE(pParameter->count() > 0,"OResultSet: Fehler im Parse Tree"); + OSQLParseNode * pMark = pParameter->getChild(0); + + String aParameterName; + if (SQL_ISPUNCTUATION(pMark,"?")) + aParameterName = '?'; + else if (SQL_ISPUNCTUATION(pMark,":")) + aParameterName = pParameter->getChild(1)->getTokenValue(); + else if (SQL_ISPUNCTUATION(pMark,"[")) + aParameterName = pParameter->getChild(1)->getTokenValue(); + else + { + OSL_ASSERT("OResultSet: Fehler im Parse Tree"); + } + + // Parameter-Column aufsetzen: + sal_Int32 eType = DataType::VARCHAR; + UINT32 nPrecision = 255; + UINT16 nScale = 0; + sal_Int32 nNullable = ColumnValue::NULLABLE; + + if (_xCol.is()) + { + // Typ, Precision, Scale ... der angegebenen Column verwenden, + // denn dieser Column wird der Wert zugewiesen bzw. mit dieser + // Column wird der Wert verglichen. + eType = getINT32(_xCol->getFastPropertyValue(PROPERTY_ID_TYPE)); + nPrecision = getINT32(_xCol->getFastPropertyValue(PROPERTY_ID_PRECISION)); + nScale = getINT32(_xCol->getFastPropertyValue(PROPERTY_ID_SCALE)); + nNullable = getINT32(_xCol->getFastPropertyValue(PROPERTY_ID_ISNULLABLE));; + } + + Reference<XFastPropertySet> xParaColumn; + sdbcx::OColumn* pRet = new sdbcx::OColumn(aParameterName + ,::rtl::OUString() + ,::rtl::OUString() + ,nNullable + , nPrecision + ,nScale + ,eType + ,sal_False + ,sal_False + ,sal_False + ,m_aSQLIterator.isCaseSensitive()); + xParaColumn = pRet; + m_xParamColumns->push_back(xParaColumn); + return nParameter; +} +// ------------------------------------------------------------------------- +void OResultSet::describeParameter() +{ + ::std::vector< OSQLParseNode*> aParseNodes; + scanParameter(m_pParseTree,aParseNodes); + if(aParseNodes.size()) + { + m_xParamColumns = new OSQLColumns(); + const OSQLTables& xTabs = m_aSQLIterator.getTables(); + OSQLTable xTable = xTabs.begin()->second; + + String aTabName,aTmp,aColName,aParameterName; + ::std::vector< OSQLParseNode*>::iterator aIter = aParseNodes.begin(); + for(;aIter != aParseNodes.end();++aIter) + { + BOOL bNotFound(TRUE); + OSQLParseNode* pParseNode = *aIter; + pParseNode = pParseNode->getParent(); + pParseNode = pParseNode->getChild(0); + + m_aSQLIterator.getColumnRange(pParseNode,aColName,aTabName); + Reference<XFastPropertySet> xCol; + xTable->getColumns()->getByName(aColName) >>= xCol; + m_xParamColumns->push_back(xCol); + } + } +} +//------------------------------------------------------------------ +void OResultSet::scanParameter(OSQLParseNode* pParseNode,::std::vector< OSQLParseNode*>& _rParaNodes) +{ + DBG_ASSERT(pParseNode != NULL,"SdbCursor: interner Fehler: ungueltiger ParseNode"); + + // Parameter Name-Regel gefunden? + if (SQL_ISRULE(pParseNode,parameter)) + { + DBG_ASSERT(pParseNode->count() >= 1,"OResultSet: Parse Tree fehlerhaft"); + DBG_ASSERT(pParseNode->getChild(0)->getNodeType() == SQL_NODE_PUNCTUATION,"OResultSet: Parse Tree fehlerhaft"); + + _rParaNodes.push_back(pParseNode); + // Weiterer Abstieg nicht erforderlich + return; + } + + // Weiter absteigen im Parse Tree + for (UINT32 i = 0; i < pParseNode->count(); i++) + scanParameter(pParseNode->getChild(i),_rParaNodes); +} + + diff --git a/connectivity/source/drivers/file/FResultSetMetaData.cxx b/connectivity/source/drivers/file/FResultSetMetaData.cxx new file mode 100644 index 000000000000..d595da005387 --- /dev/null +++ b/connectivity/source/drivers/file/FResultSetMetaData.cxx @@ -0,0 +1,201 @@ +/************************************************************************* + * + * $RCSfile: FResultSetMetaData.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_FILE_ORESULTSETMETADATA_HXX_ +#include "file/FResultSetMetaData.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +using namespace connectivity; +using namespace connectivity::file; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::sdbcx; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; +// ------------------------------------------------------------------------- +OResultSetMetaData::~OResultSetMetaData() +{ +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getINT32(m_rColumns[column-1]->getFastPropertyValue(PROPERTY_ID_PRECISION)); +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSetMetaData::getColumnType( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getINT32(m_rColumns[column-1]->getFastPropertyValue(PROPERTY_ID_TYPE)); +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount( ) throw(SQLException, RuntimeException) +{ + return m_rColumns.size(); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return sal_True; +} +// ------------------------------------------------------------------------- + +::rtl::OUString SAL_CALL OResultSetMetaData::getSchemaName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- + +::rtl::OUString SAL_CALL OResultSetMetaData::getColumnName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + Any aName(m_rColumns[column-1]->getFastPropertyValue(PROPERTY_ID_REALNAME)); + return aName.hasValue() ? getString(aName) : getString(m_rColumns[column-1]->getFastPropertyValue(PROPERTY_ID_NAME)); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getTableName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return m_aTableName; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getCatalogName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getColumnTypeName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getString(m_rColumns[column-1]->getFastPropertyValue(PROPERTY_ID_TYPENAME)); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getColumnLabel( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getString(m_rColumns[column-1]->getFastPropertyValue(PROPERTY_ID_NAME)); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getColumnServiceName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isCurrency( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getBOOL(m_rColumns[column-1]->getFastPropertyValue(PROPERTY_ID_TYPE)); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getBOOL(m_rColumns[column-1]->getFastPropertyValue(PROPERTY_ID_ISAUTOINCREMENT)); +} +// ------------------------------------------------------------------------- + + +sal_Bool SAL_CALL OResultSetMetaData::isSigned( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OResultSetMetaData::getPrecision( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getINT32(m_rColumns[column-1]->getFastPropertyValue(PROPERTY_ID_PRECISION)); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OResultSetMetaData::getScale( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + return getINT32(m_rColumns[column-1]->getFastPropertyValue(PROPERTY_ID_SCALE)); +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSetMetaData::isNullable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getINT32(m_rColumns[column-1]->getFastPropertyValue(PROPERTY_ID_ISNULLABLE)); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isSearchable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return sal_True; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isReadOnly( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return sal_True; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return sal_False; +; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return sal_False; +} +// ------------------------------------------------------------------------- + diff --git a/connectivity/source/drivers/file/FStatement.cxx b/connectivity/source/drivers/file/FStatement.cxx new file mode 100644 index 000000000000..8dfbb1fd9521 --- /dev/null +++ b/connectivity/source/drivers/file/FStatement.cxx @@ -0,0 +1,358 @@ +/************************************************************************* + * + * $RCSfile: FStatement.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif +#ifndef _CONNECTIVITY_FILE_OSTATEMENT_HXX_ +#include "file/FStatement.hxx" +#endif +#ifndef _CONNECTIVITY_FILE_OCONNECTION_HXX_ +#include "file/FConnection.hxx" +#endif +#ifndef _CONNECTIVITY_FILE_ORESULTSET_HXX_ +#include "file/FResultSet.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +#ifndef _UTL_PROPERTY_HXX_ +#include <unotools/property.hxx> +#endif +#ifndef _UTL_UNO3_HXX_ +#include <unotools/uno3.hxx> +#endif +#ifndef _OSL_THREAD_H_ +#include <osl/thread.h> +#endif + +#ifndef _COM_SUN_STAR_SDBC_RESULTSETCONCURRENCY_HPP_ +#include <com/sun/star/sdbc/ResultSetConcurrency.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_RESULTSETTYPE_HPP_ +#include <com/sun/star/sdbc/ResultSetType.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif + +#define THROW_SQL(x) \ + OTools::ThrowException(x,m_aStatementHandle,SQL_HANDLE_STMT,*this) + +using namespace connectivity::file; +using namespace connectivity; +//------------------------------------------------------------------------------ +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; +//------------------------------------------------------------------------------ +OStatement_Base::OStatement_Base(OConnection* _pConnection ) : OStatement_BASE(m_aMutex) + ,connectivity::OSimplePropertyContainer(OStatement_BASE::rBHelper) + ,rBHelper(OStatement_BASE::rBHelper) + ,m_pConnection(_pConnection) + ,m_pParseTree(NULL) + ,m_aSQLIterator(_pConnection->createCatalog()->getTables(),_pConnection->getMetaData(),NULL) +{ + m_pConnection->acquire(); + + sal_Int32 nAttrib = 0; + + registerProperty(PROPERTY_CURSORNAME, PROPERTY_ID_CURSORNAME, nAttrib,&m_aCursorName, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); + registerProperty(PROPERTY_MAXFIELDSIZE, PROPERTY_ID_MAXFIELDSIZE, nAttrib,&m_nMaxFieldSize, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))); + registerProperty(PROPERTY_MAXROWS, PROPERTY_ID_MAXROWS, nAttrib,&m_nMaxRows, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))); + registerProperty(PROPERTY_QUERYTIMEOUT, PROPERTY_ID_QUERYTIMEOUT, nAttrib,&m_nQueryTimeOut, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))); + registerProperty(PROPERTY_FETCHSIZE, PROPERTY_ID_FETCHSIZE, nAttrib,&m_nFetchSize, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))); + registerProperty(PROPERTY_RESULTSETTYPE, PROPERTY_ID_RESULTSETTYPE, nAttrib,&m_nResultSetType, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))); + registerProperty(PROPERTY_FETCHDIRECTION, PROPERTY_ID_FETCHDIRECTION, nAttrib,&m_nFetchDirection, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))); + registerProperty(PROPERTY_ESCAPEPROCESSING, PROPERTY_ID_ESCAPEPROCESSING, nAttrib,&m_bEscapeProcessing,::getCppuBooleanType()); + + registerProperty(PROPERTY_RESULTSETCONCURRENCY, PROPERTY_ID_RESULTSETCONCURRENCY, nAttrib,&m_nResultSetConcurrency, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))); +} +//------------------------------------------------------------------------------ +void OStatement_Base::disposeResultSet() +{ + // free the cursor if alive + Reference< XComponent > xComp(m_xResultSet.get(), UNO_QUERY); + if (xComp.is()) + xComp->dispose(); + m_xResultSet = Reference< XResultSet>(); +} +//------------------------------------------------------------------------------ +void OStatement_BASE2::disposing() +{ + ::osl::MutexGuard aGuard(m_aMutex); + + disposeResultSet(); + + if (m_pConnection) + m_pConnection->release(); + + dispose_ChildImpl(); + OStatement_Base::disposing(); +} +//----------------------------------------------------------------------------- +void SAL_CALL OStatement_BASE2::release() throw(RuntimeException) +{ + relase_ChildImpl(); +} +//----------------------------------------------------------------------------- +Any SAL_CALL OStatement_Base::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = OStatement_BASE::queryInterface(rType); + if(!aRet.hasValue()) + aRet = OPropertySetHelper::queryInterface(rType); + return aRet; +} +// ------------------------------------------------------------------------- +Sequence< Type > SAL_CALL OStatement_Base::getTypes( ) throw(RuntimeException) +{ + ::cppu::OTypeCollection aTypes( ::getCppuType( (const Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ), + ::getCppuType( (const Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ), + ::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet > *)0 )); + + return ::utl::concatSequences(aTypes.getTypes(),OStatement_BASE::getTypes()); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OStatement_Base::cancel( ) throw(RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +void SAL_CALL OStatement_Base::close( ) throw(SQLException, RuntimeException) +{ + { + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + } + dispose(); +} +// ------------------------------------------------------------------------- + +void OStatement_Base::reset() throw (SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + clearWarnings (); + + if (m_xResultSet.get().is()) + clearMyResultSet(); +} +//-------------------------------------------------------------------- +// clearMyResultSet +// If a ResultSet was created for this Statement, close it +//-------------------------------------------------------------------- + +void OStatement_Base::clearMyResultSet () throw (SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + Reference<XCloseable> xCloseable; + if(::utl::query_interface(m_xResultSet.get(),xCloseable)) + xCloseable->close(); + m_xResultSet = Reference< XResultSet>(); +} +//-------------------------------------------------------------------- +// setWarning +// Sets the warning +//-------------------------------------------------------------------- + +void OStatement_Base::setWarning (const SQLWarning &ex) throw( SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_aLastWarning = ex; +} + +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OStatement_Base::execute( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + // ::rtl::OString aSql(::rtl::OUStringToOString(sql,osl_getThreadTextEncoding())); + Reference< XResultSet > xRS = executeQuery(sql); + + return m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT || m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT_COUNT; +} + +// ------------------------------------------------------------------------- + +Reference< XResultSet > SAL_CALL OStatement_Base::executeQuery( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + Reference< XResultSet > xRS = NULL; + + String aErr; + m_pParseTree = m_aParser.parseTree(aErr,sql); + if(m_pParseTree) + { + m_aSQLIterator.setParseTree(m_pParseTree); + m_aSQLIterator.traverseAll(); + const OSQLTables& xTabs = m_aSQLIterator.getTables(); + if(xTabs.begin() == xTabs.end()) + throw SQLException(aErr,*this,::rtl::OUString(),0,Any()); + + OResultSet* pResult = new OResultSet(this,m_aSQLIterator); + pResult->OpenImpl(); + xRS = pResult; + + } + else + throw SQLException(aErr,*this,::rtl::OUString(),0,Any()); + + + + // Execute the statement. If execute returns true, a result + // set exists. + return xRS; +} +// ------------------------------------------------------------------------- +Reference< XConnection > SAL_CALL OStatement_Base::getConnection( ) throw(SQLException, RuntimeException) +{ + return (Reference< XConnection >)m_pConnection; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OStatement_Base::executeUpdate( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + Reference< XResultSet > xRS = NULL; + + String aErr; + m_pParseTree = m_aParser.parseTree(aErr,sql); + if(m_pParseTree) + { + m_aSQLIterator.setParseTree(m_pParseTree); + m_aSQLIterator.traverseAll(); + const OSQLTables& xTabs = m_aSQLIterator.getTables(); + if(xTabs.begin() == xTabs.end()) + throw SQLException(aErr,*this,::rtl::OUString(),0,Any()); + + OResultSet* pResult = new OResultSet(this,m_aSQLIterator); + pResult->OpenImpl(); + xRS = pResult; + return pResult->getRowCountResult(); + } + else + throw SQLException(aErr,*this,::rtl::OUString(),0,Any()); + + return 0; +} +// ------------------------------------------------------------------------- +Any SAL_CALL OStatement_Base::getWarnings( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return makeAny(m_aLastWarning); +} +// ------------------------------------------------------------------------- + +// ------------------------------------------------------------------------- +void SAL_CALL OStatement_Base::clearWarnings( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_aLastWarning = SQLWarning(); +} +// ------------------------------------------------------------------------- +::cppu::IPropertyArrayHelper* OStatement_Base::createArrayHelper( ) const +{ + Sequence< Property > aProps; + describeProperties(aProps); + return new ::cppu::OPropertyArrayHelper(aProps); +} + +// ------------------------------------------------------------------------- +::cppu::IPropertyArrayHelper & OStatement_Base::getInfoHelper() +{ + return *const_cast<OStatement_Base*>(this)->getArrayHelper(); +} +// ------------------------------------------------------------------------- +IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbc.driver.file.Statement","com.sun.star.sdbc.Statement"); + diff --git a/connectivity/source/drivers/file/FTable.cxx b/connectivity/source/drivers/file/FTable.cxx new file mode 100644 index 000000000000..9036acdde05c --- /dev/null +++ b/connectivity/source/drivers/file/FTable.cxx @@ -0,0 +1,201 @@ +/************************************************************************* + * + * $RCSfile: FTable.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_FILE_TABLE_HXX_ +#include "file/FTable.hxx" +#endif +#ifndef _CONNECTIVITY_FILE_COLUMNS_HXX_ +#include "file/FColumns.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ +#include <com/sun/star/sdbc/ColumnValue.hpp> +#endif + +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::container; + +OFileTable::OFileTable(OConnection* _pConnection) : OTable_TYPEDEF(_pConnection->getMetaData()->storesMixedCaseQuotedIdentifiers()) + ,m_pConnection(_pConnection) + ,m_nFilePos(0) + ,m_nBufferSize(0) + ,m_pBuffer(NULL) +{ + construct(); + ::std::vector< ::rtl::OUString> aVector; + m_pColumns = new OColumns(this,m_aMutex,aVector); + m_aColumns = new OSQLColumns(); +} +// ------------------------------------------------------------------------- +OFileTable::OFileTable( OConnection* _pConnection, + const ::rtl::OUString& _Name, + const ::rtl::OUString& _Type, + const ::rtl::OUString& _Description , + const ::rtl::OUString& _SchemaName, + const ::rtl::OUString& _CatalogName + ) : OTable_TYPEDEF(_pConnection->getMetaData()->storesMixedCaseQuotedIdentifiers(), + _Name, + _Type, + _Description, + _SchemaName, + _CatalogName) + ,m_pConnection(_pConnection) + ,m_nFilePos(0) + ,m_nBufferSize(0) + ,m_pBuffer(NULL) +{ + m_aColumns = new OSQLColumns(); + construct(); + // refreshColumns(); +} +// ------------------------------------------------------------------------- +void OFileTable::refreshColumns() +{ + ::std::vector< ::rtl::OUString> aVector; + Reference< XResultSet > xResult = m_pConnection->getMetaData()->getColumns(Any(), + m_SchemaName,m_Name,::rtl::OUString::createFromAscii("%")); + + if(xResult.is()) + { + Reference< XRow > xRow(xResult,UNO_QUERY); + while(xResult->next()) + aVector.push_back(xRow->getString(4)); + } + + if(m_pColumns) + delete m_pColumns; + m_pColumns = new OColumns(this,m_aMutex,aVector); +} +// ------------------------------------------------------------------------- +void OFileTable::refreshKeys() +{ +} +// ------------------------------------------------------------------------- +void OFileTable::refreshIndexes() +{ +} +// ------------------------------------------------------------------------- +Any SAL_CALL OFileTable::queryInterface( const Type & rType ) throw(RuntimeException) +{ + if( rType == ::getCppuType((const Reference<XKeysSupplier>*)0) || + rType == ::getCppuType((const Reference<XRename>*)0) || + rType == ::getCppuType((const Reference<XAlterTable>*)0) || + rType == ::getCppuType((const Reference<XIndexesSupplier>*)0) || + rType == ::getCppuType((const Reference<XDataDescriptorFactory>*)0)) + return Any(); + + Any aRet = ::cppu::queryInterface(rType,static_cast< ::com::sun::star::lang::XUnoTunnel*> (this)); + if(aRet.hasValue()) + return aRet; + + return OTable_TYPEDEF::queryInterface(rType); +} +// ------------------------------------------------------------------------- +void SAL_CALL OFileTable::disposing(void) +{ + OTable::disposing(); + ::osl::MutexGuard aGuard(m_aMutex); + m_xMetaData = NULL; + delete m_pBuffer; + m_pBuffer = NULL; +} +//-------------------------------------------------------------------------- +Sequence< sal_Int8 > OFileTable::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 OFileTable::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException) +{ + if (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) + return (sal_Int64)this; + + return 0; +} + + diff --git a/connectivity/source/drivers/file/FTables.cxx b/connectivity/source/drivers/file/FTables.cxx new file mode 100644 index 000000000000..6150ed228b39 --- /dev/null +++ b/connectivity/source/drivers/file/FTables.cxx @@ -0,0 +1,161 @@ +/************************************************************************* + * + * $RCSfile: FTables.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_FILE_TABLES_HXX_ +#include "file/FTables.hxx" +#endif +#ifndef _CONNECTIVITY_FILE_TABLE_HXX_ +#include "file/FTable.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ +#include <com/sun/star/sdbc/ColumnValue.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_KEYRULE_HPP_ +#include <com/sun/star/sdbc/KeyRule.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBCX_KEYTYPE_HPP_ +#include <com/sun/star/sdbcx/KeyType.hpp> +#endif +#ifndef _CONNECTIVITY_FILE_CATALOG_HXX_ +#include "file/FCatalog.hxx" +#endif +#ifndef _CONNECTIVITY_FILE_BCONNECTION_HXX_ +#include "file/FConnection.hxx" +#endif +//#ifndef _CONNECTIVITY_FILE_OEMPTYCOLLECTION_HXX_ +//#include "file/FEmptyCollection.hxx" +//#endif + +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::container; + +namespace starutil = ::com::sun::star::util; +typedef connectivity::sdbcx::OCollection OCollection_TYPE; + +Reference< XNamed > OTables::createObject(const ::rtl::OUString& _rName) +{ +// ::rtl::OUString aName,aSchema; +// sal_Int32 nLen = _rName.indexOf('.'); +// aSchema = _rName.copy(0,nLen); +// aName = _rName.copy(nLen+1); +// +// Sequence< ::rtl::OUString > aTypes(1); +// aTypes[0] = ::rtl::OUString::createFromAscii("%"); +// // aTypes[0] = ::rtl::OUString::createFromAscii("TABLE"); +// // aTypes[1] = ::rtl::OUString::createFromAscii("SYSTEMTABLE"); +// +// Reference< XResultSet > xResult = m_xMetaData->getTables(Any(), +// aSchema,aName,aTypes); + + Reference< XNamed > xRet = NULL; +// if(xResult.is()) +// { +// Reference< XRow > xRow(xResult,UNO_QUERY); +// if(xResult->next()) // there can be only one table with this name +// { +// OFileTable* pRet = new OFileTable(static_cast<OFileCatalog&>(m_rParent).getConnection()->getMetaData()->storesMixedCaseQuotedIdentifiers(), +// static_cast<OFileCatalog&>(m_rParent).getConnection(), +// aName,xRow->getString(4),xRow->getString(5),aSchema); +// xRet = pRet; +// } +// } +// + return xRet; +} +// ------------------------------------------------------------------------- +void OTables::impl_refresh( ) throw(RuntimeException) +{ + static_cast<OFileCatalog&>(m_rParent).refreshTables(); +} +// ------------------------------------------------------------------------- +void OTables::disposing(void) +{ + m_xMetaData = NULL; + OCollection::disposing(); +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > OTables::createEmptyObject() +{ + return Reference< XPropertySet >(); +} +//------------------------------------------------------------------ +Any SAL_CALL OTables::queryInterface( const Type & rType ) throw(RuntimeException) +{ + if( rType == ::getCppuType((const Reference<XColumnLocate>*)0) || + rType == ::getCppuType((const Reference<XDataDescriptorFactory>*)0) || + rType == ::getCppuType((const Reference<XAppend>*)0) || + rType == ::getCppuType((const Reference<XDrop>*)0)) + return Any(); + + typedef sdbcx::OCollection OTables_BASE; + return OTables_BASE::queryInterface(rType); +} + diff --git a/connectivity/source/drivers/file/file.xml b/connectivity/source/drivers/file/file.xml new file mode 100644 index 000000000000..253bccb84c4c --- /dev/null +++ b/connectivity/source/drivers/file/file.xml @@ -0,0 +1,70 @@ +<?xml version='1.0' encoding="UTF-8"?> +<!DOCTYPE COMPONENTDESCRIPTION PUBLIC "-//W3C//DTD HTML 3.2//EN" "componentdependencies.dtd"> +<COMPONENTDESCRIPTION> + +<Name> com.sun.star.sdbc.ODBCDriver </Name> + +<Description> + This is the implementation of the sdbc-odbc bridge. +</Description> + +<ModuleName> odbc </ModuleName> + +<LoaderName> com.sun.star.loader.SharedLibrary </LoaderName> + +<SupportedService> com.sun.star.sdbc.Driver </SupportedService> + +<ServiceDependency> ... </ServiceDependency> + +<ProjectBuildDependency> cppuhelper </ProjectBuildDependency> +<ProjectBuildDependency> cppu </ProjectBuildDependency> +<ProjectBuildDependency> sal </ProjectBuildDependency> +<ProjectBuildDependency> vos </ProjectBuildDependency> + +<RuntimeModuleDependency> cppuhelper </RuntimeModuleDependency> +<RuntimeModuleDependency> cppu1 </RuntimeModuleDependency> +<RuntimeModuleDependency> sal1 </RuntimeModuleDependency> +<RuntimeModuleDependency> vos </RuntimeModuleDependency> + +<Language> c++ </Language> + +<Status StatusValue="final"/> + +<Type> com.sun.star.util.XCancellable </Type> +<Type> com.sun.star.util.XNumberFormatter </Type> +<Type> com.sun.star.uno.TypeClass </Type> +<Type> com.sun.star.uno.XWeak </Type> +<Type> com.sun.star.uno.XAggregation </Type> +<Type> com.sun.star.beans.XPropertyState </Type> +<Type> com.sun.star.beans.XPropertySet </Type> +<Type> com.sun.star.beans.PropertyValue </Type> +<Type> com.sun.star.beans.XMultiPropertySet </Type> +<Type> com.sun.star.beans.XFastPropertySet </Type> +<Type> com.sun.star.lang.XTypeProvider </Type> +<Type> com.sun.star.lang.EventObject </Type> +<Type> com.sun.star.lang.XComponent </Type> +<Type> com.sun.star.lang.IllegalArgumentException </Type> +<Type> com.sun.star.lang.XMultiServiceFactory </Type> +<Type> com.sun.star.java.XJavaThreadRegister_11 </Type> +<Type> com.sun.star.java.XJavaVM </Type> +<Type> com.sun.star.sdbc.XConnection </Type> +<Type> com.sun.star.sdbc.XStatement </Type> +<Type> com.sun.star.sdbc.XResultSet </Type> +<Type> com.sun.star.sdbc.XResultSetMetaDataSupplier</Type> +<Type> com.sun.star.sdbc.XColumnLocate </Type> +<Type> com.sun.star.sdbc.XResultSetUpdate </Type> +<Type> com.sun.star.sdbc.XWarningsSupplier </Type> +<Type> com.sun.star.sdbc.XRowUpdate </Type> +<Type> com.sun.star.sdbc.XMultipleResults </Type> +<Type> com.sun.star.sdbc.XBatchExecution </Type> +<Type> com.sun.star.sdbc.XPreparedBatchExecution </Type> +<Type> com.sun.star.sdbc.XParameters </Type> +<Type> com.sun.star.sdbc.XOutParameters </Type> +<Type> com.sun.star.sdbc.DriverPropertyInfo </Type> +<Type> com.sun.star.sdbc.XRow </Type> +<Type> com.sun.star.sdb.XColumnUpdate </Type> +<Type> com.sun.star.sdb.XColumn </Type> + +</COMPONENTDESCRIPTION> + + diff --git a/connectivity/source/drivers/file/makefile.mk b/connectivity/source/drivers/file/makefile.mk new file mode 100644 index 000000000000..6497fcde76d3 --- /dev/null +++ b/connectivity/source/drivers/file/makefile.mk @@ -0,0 +1,158 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/..$/.. +PRJINC=..$/.. +PRJNAME=connectivity +TARGET=file + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ---------------------------------- +.IF "$(DBGUTIL_OJ)"!="" +ENVCFLAGS+=/FR$(SLO)$/ +.ENDIF + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/version.mk + +# --- Types ------------------------------------- + + +UNOUCRDEP=$(SOLARBINDIR)$/applicat.rdb +UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb + +UNOUCROUT=$(OUT)$/inc +INCPRE+=$(UNOUCROUT) + +# --- Types ------------------------------------- + +UNOTYPES+= \ + com.sun.star.util.XCancellable \ + com.sun.star.util.XNumberFormatter \ + com.sun.star.uno.TypeClass \ + com.sun.star.uno.XWeak \ + com.sun.star.uno.XAggregation \ + com.sun.star.beans.XPropertyState \ + com.sun.star.beans.XPropertySet \ + com.sun.star.beans.PropertyValue \ + com.sun.star.beans.XMultiPropertySet \ + com.sun.star.beans.XFastPropertySet \ + com.sun.star.lang.XTypeProvider \ + com.sun.star.lang.EventObject \ + com.sun.star.lang.XComponent \ + com.sun.star.lang.IllegalArgumentException \ + com.sun.star.lang.DisposedException \ + com.sun.star.lang.XMultiServiceFactory \ + com.sun.star.lang.XSingleServiceFactory \ + com.sun.star.registry.XRegistryKey \ + com.sun.star.java.XJavaThreadRegister_11 \ + com.sun.star.java.XJavaVM \ + com.sun.star.sdbc.XConnection \ + com.sun.star.sdbc.XStatement \ + com.sun.star.sdbc.XResultSet \ + com.sun.star.sdbc.XResultSetMetaDataSupplier \ + com.sun.star.sdbc.XColumnLocate \ + com.sun.star.sdbc.XResultSetUpdate \ + com.sun.star.sdbc.XWarningsSupplier \ + com.sun.star.sdbc.XRowUpdate \ + com.sun.star.sdbc.XMultipleResults \ + com.sun.star.sdbc.XBatchExecution \ + com.sun.star.sdbc.XPreparedBatchExecution \ + com.sun.star.sdbc.XParameters \ + com.sun.star.sdbc.XOutParameters \ + com.sun.star.sdbc.DriverPropertyInfo \ + com.sun.star.sdbc.XDriver \ + com.sun.star.sdbc.XRow \ + com.sun.star.sdbc.SQLWarning \ + com.sun.star.sdbc.ColumnSearch \ + com.sun.star.sdbc.DataType \ + com.sun.star.sdbc.ResultSetConcurrency \ + com.sun.star.sdbc.ResultSetType \ + com.sun.star.sdbc.ColumnValue \ + com.sun.star.sdb.XColumnUpdate \ + com.sun.star.sdb.XColumn \ + com.sun.star.lang.XServiceInfo + +# --- Files ------------------------------------- + +SLOFILES=\ + $(SLO)$/FConnection.obj \ + $(SLO)$/FValue.obj \ + $(SLO)$/FDatabaseMetaDataResultSetMetaData.obj \ + $(SLO)$/FDatabaseMetaDataResultSet.obj \ + $(SLO)$/FResultSetMetaData.obj \ + $(SLO)$/FColumns.obj \ + $(SLO)$/FTables.obj \ + $(SLO)$/FTable.obj \ + $(SLO)$/FCatalog.obj \ + $(SLO)$/FResultSet.obj \ + $(SLO)$/FStatement.obj \ + $(SLO)$/FPreparedStatement.obj \ + $(SLO)$/FDatabaseMetaData.obj \ + $(SLO)$/FDriver.obj + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + + diff --git a/connectivity/source/drivers/jdbc/Array.cxx b/connectivity/source/drivers/jdbc/Array.cxx new file mode 100644 index 000000000000..21566a30afc3 --- /dev/null +++ b/connectivity/source/drivers/jdbc/Array.cxx @@ -0,0 +1,238 @@ +/************************************************************************* + * + * $RCSfile: Array.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_JAVA_SQL_ARRAY_HXX_ +#include "java/sql/Array.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_ +#include "java/tools.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_RESULTSET_HXX_ +#include "java/sql/ResultSet.hxx" +#endif + +using namespace connectivity; +//************************************************************** +//************ Class: java.sql.Array +//************************************************************** + +jclass java_sql_Array::theClass = 0; + +java_sql_Array::~java_sql_Array() +{} + +jclass java_sql_Array::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; + if( !t.pEnv ) return (jclass)NULL; + jclass tempClass = t.pEnv->FindClass( "java/sql/Array" ); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} + +void java_sql_Array::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==NULL ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} +::rtl::OUString SAL_CALL java_sql_Array::getBaseTypeName( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jstring out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + ::rtl::OUString aStr; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/lang/String;"; + char * cMethodName = "getBaseTypeName"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = (jstring)t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} + +sal_Int32 SAL_CALL java_sql_Array::getBaseType( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getBaseType"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return (sal_Int32)out; +} + +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > SAL_CALL java_sql_Array::getArray( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jobjectArray out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + jobject obj = XNameAccess2Map(t.pEnv,typeMap); + char * cSignature = "(Ljava/util/Map;)[Ljava/lang/Object;"; + char * cMethodName = "getArray"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = (jobjectArray)t.pEnv->CallObjectMethod( object, mID, obj); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + t.pEnv->DeleteLocalRef(obj); + } //mID + } //t.pEnv + return ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >();//copyArrayAndDelete< ::com::sun::star::uno::Any,jobject>(t.pEnv,out); +} + +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > SAL_CALL java_sql_Array::getArrayAtIndex( sal_Int32 index, sal_Int32 count, const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jobjectArray out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + jobject obj = XNameAccess2Map(t.pEnv,typeMap); + char * cSignature = "(IILjava/util/Map;)[Ljava/lang/Object;"; + char * cMethodName = "getArray"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = (jobjectArray)t.pEnv->CallObjectMethod( object, mID, index,count,obj); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + t.pEnv->DeleteLocalRef(obj); + } //mID + } //t.pEnv + return ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >();//copyArrayAndDelete< ::com::sun::star::uno::Any,jobject>(t.pEnv,out); +} + +::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL java_sql_Array::getResultSet( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[1]; + // Parameter konvertieren + args[0].l = XNameAccess2Map(t.pEnv,typeMap); + // temporaere Variable initialisieren + char * cSignature = "(Ljava/util/Map;)Ljava/sql/ResultSet;"; + char * cMethodName = "getResultSet"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, args[0].l); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + t.pEnv->DeleteLocalRef((jobjectArray)args[0].l); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + // return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out ); + return NULL; +} + +::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL java_sql_Array::getResultSetAtIndex( sal_Int32 index, sal_Int32 count, const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[1]; + // Parameter konvertieren + args[0].l = XNameAccess2Map(t.pEnv,typeMap); + // temporaere Variable initialisieren + char * cSignature = "(Ljava/util/Map;)Ljava/sql/ResultSet;"; + char * cMethodName = "getResultSet"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, index,count,args[0].l); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + t.pEnv->DeleteLocalRef((jobjectArray)args[0].l); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + // return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out ); + return NULL; +} + + + diff --git a/connectivity/source/drivers/jdbc/Blob.cxx b/connectivity/source/drivers/jdbc/Blob.cxx new file mode 100644 index 000000000000..7a2b3ab808a5 --- /dev/null +++ b/connectivity/source/drivers/jdbc/Blob.cxx @@ -0,0 +1,221 @@ +/************************************************************************* + * + * $RCSfile: Blob.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_JAVA_SQL_BLOB_HXX_ +#include "java/sql/Blob.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_ +#include "java/tools.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_IO_INPUTSTREAM_HXX_ +#include "java/io/InputStream.hxx" +#endif +#ifndef _INC_MEMORY +#include <memory.h> +#endif + +using namespace connectivity; +//************************************************************** +//************ Class: java.sql.Blob +//************************************************************** + +jclass java_sql_Blob::theClass = 0; + +java_sql_Blob::~java_sql_Blob() +{} + +jclass java_sql_Blob::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; + if( !t.pEnv ) return (jclass)NULL; + jclass tempClass = t.pEnv->FindClass( "java/sql/Blob" ); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} + +void java_sql_Blob::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==NULL ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} + +sal_Int64 SAL_CALL java_sql_Blob::length( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jlong out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()J"; + char * cMethodName = "length"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallLongMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return (sal_Int64)out; +} +::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL java_sql_Blob::getBytes( sal_Int64 pos, sal_Int32 length ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + ::com::sun::star::uno::Sequence< sal_Int8 > aSeq; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(JI)[B"; + char * cMethodName = "getBytes"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + jbyteArray out = (jbyteArray)t.pEnv->CallObjectMethod( object, mID,pos,length); + ThrowSQLException(t.pEnv,*this); + if(out) + { + jboolean p = sal_False; + aSeq.realloc(t.pEnv->GetArrayLength(out)); + memcpy(aSeq.getArray(),t.pEnv->GetByteArrayElements(out,&p),aSeq.getLength()); + t.pEnv->DeleteLocalRef(out); + } + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aSeq; +} + +::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL java_sql_Blob::getBinaryStream( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "()Ljava/io/InputStream;"; + char * cMethodName = "getBinaryStream"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_io_InputStream( t.pEnv, out ); +} + +sal_Int64 SAL_CALL java_sql_Blob::position( const ::com::sun::star::uno::Sequence< sal_Int8 >& pattern, sal_Int64 start ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jlong out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + jvalue args[1]; + // Parameter konvertieren + jbyteArray pByteArray = t.pEnv->NewByteArray(pattern.getLength()); + t.pEnv->SetByteArrayRegion(pByteArray,0,pattern.getLength(),(jbyte*)pattern.getConstArray()); + args[0].l = pByteArray; + // temporaere Variable initialisieren + char * cSignature = "([BI)J"; + char * cMethodName = "position"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallLongMethod( object, mID, args[0].l,start ); + ThrowSQLException(t.pEnv,*this); + t.pEnv->DeleteLocalRef((jbyteArray)args[0].l); + // und aufraeumen + } //mID + } //t.pEnv + return (sal_Int64)out; +} + +sal_Int64 SAL_CALL java_sql_Blob::positionOfBlob( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XBlob >& pattern, sal_Int64 start ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jlong out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + jvalue args[1]; + // Parameter konvertieren + args[0].l = 0; + // temporaere Variable initialisieren + char * cSignature = "(Ljava/sql/Blob;I)J"; + char * cMethodName = "position"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallLongMethod( object, mID,args[0].l,start ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return (sal_Int64)out; +} + diff --git a/connectivity/source/drivers/jdbc/Boolean.cxx b/connectivity/source/drivers/jdbc/Boolean.cxx new file mode 100644 index 000000000000..0d72ac908689 --- /dev/null +++ b/connectivity/source/drivers/jdbc/Boolean.cxx @@ -0,0 +1,114 @@ +/************************************************************************* + * + * $RCSfile: Boolean.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_JAVA_LANG_BOOLEAN_HXX_ +#include "java/lang/Boolean.hxx" +#endif +using namespace connectivity; +//************************************************************** +//************ Class: java.lang.Boolean +//************************************************************** + +jclass java_lang_Boolean::theClass = 0; + +java_lang_Boolean::~java_lang_Boolean() +{} + +jclass java_lang_Boolean::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; + if( !t.pEnv ) return (jclass)NULL; + jclass tempClass = t.pEnv->FindClass("java/lang/Boolean"); OSL_ENSHURE(tempClass,"Java : FindClass nicht erfolgreich!"); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} + +void java_lang_Boolean::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==NULL ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} + +java_lang_Boolean::java_lang_Boolean( sal_Bool _par0 ): java_lang_Object( NULL, (jobject)NULL ){ + SDBThreadAttach t; + if( !t.pEnv ) + return; + jvalue args[1]; + // Parameter konvertieren + args[0].z = _par0; + // Java-Call fuer den Konstruktor absetzen + // temporaere Variable initialisieren + char * cSignature = "(Z)V"; + jobject tempObj; + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), "<init>", cSignature ); + tempObj = t.pEnv->NewObjectA( getMyClass(), mID, args ); + saveRef( t.pEnv, tempObj ); + t.pEnv->DeleteLocalRef( tempObj ); + // und aufraeumen +} + + diff --git a/connectivity/source/drivers/jdbc/CallableStatement.cxx b/connectivity/source/drivers/jdbc/CallableStatement.cxx new file mode 100644 index 000000000000..be6616d4b0ae --- /dev/null +++ b/connectivity/source/drivers/jdbc/CallableStatement.cxx @@ -0,0 +1,590 @@ +/************************************************************************* + * + * $RCSfile: CallableStatement.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_JAVA_SQL_CALLABLESTATEMENT_HXX_ +#include "java/sql/CallableStatement.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_ +#include "java/tools.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_ARRAY_HXX_ +#include "java/sql/Array.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_CLOB_HXX_ +#include "java/sql/Clob.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_BLOB_HXX_ +#include "java/sql/Blob.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_REF_HXX_ +#include "java/sql/Ref.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_TIMESTAMP_HXX_ +#include "java/sql/Timestamp.hxx" +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif + +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; +using namespace ::com::sun::star::lang; + + +IMPLEMENT_SERVICE_INFO(java_sql_CallableStatement,"com.sun.star.sdbcx.ACallableStatement","com.sun.star.sdbc.CallableStatement"); + +//************************************************************** +//************ Class: java.sql.CallableStatement +//************************************************************** +Any SAL_CALL java_sql_CallableStatement::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = java_sql_PreparedStatement::queryInterface(rType); + if(!aRet.hasValue()) + aRet = ::cppu::queryInterface(rType,static_cast< starsdbc::XRow*>(this),static_cast< starsdbc::XOutParameters*>(this)); + return aRet; +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL java_sql_CallableStatement::getTypes( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< starsdbc::XRow > *)0 ), + ::getCppuType( (const ::com::sun::star::uno::Reference< starsdbc::XOutParameters > *)0 )); + + return ::utl::concatSequences(aTypes.getTypes(),java_sql_PreparedStatement::getTypes()); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_CallableStatement::wasNull( ) throw(starsdbc::SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + + { + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "wasNull"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} + +sal_Bool SAL_CALL java_sql_CallableStatement::getBoolean( sal_Int32 columnIndex ) throw(starsdbc::SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + + { + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "getBoolean"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID, columnIndex ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return out; +} +sal_Int8 SAL_CALL java_sql_CallableStatement::getByte( sal_Int32 columnIndex ) throw(starsdbc::SQLException, RuntimeException) +{ + jbyte out; + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + + { + // temporaere Variable initialisieren + char * cSignature = "(I)B"; + char * cMethodName = "getByte"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallByteMethod( object, mID, columnIndex); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return out; +} +Sequence< sal_Int8 > SAL_CALL java_sql_CallableStatement::getBytes( sal_Int32 columnIndex ) throw(starsdbc::SQLException, RuntimeException) +{ + Sequence< sal_Int8 > aSeq; + + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + char * cSignature = "(I)[B"; + char * cMethodName = "getBytes"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + jbyteArray out(0); + out = (jbyteArray)t.pEnv->CallObjectMethod( object, mID, columnIndex); + ThrowSQLException(t.pEnv,*this); + if (out) + { + jboolean p = sal_False; + aSeq.realloc(t.pEnv->GetArrayLength(out)); + memcpy(aSeq.getArray(),t.pEnv->GetByteArrayElements(out,&p),aSeq.getLength()); + t.pEnv->DeleteLocalRef(out); + } + // und aufraeumen + } //mID + } //t.pEnv + return aSeq; +} +::com::sun::star::util::Date SAL_CALL java_sql_CallableStatement::getDate( sal_Int32 columnIndex ) throw(starsdbc::SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + + { + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/sql/Date;"; + char * cMethodName = "getDate"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, columnIndex ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return java_sql_Date( t.pEnv, out ); +} +double SAL_CALL java_sql_CallableStatement::getDouble( sal_Int32 columnIndex ) throw(starsdbc::SQLException, RuntimeException) +{ + jdouble out; + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + + { + jvalue args[1]; + args[0].i = (sal_Int32)columnIndex; + // temporaere Variable initialisieren + char * cSignature = "(I)D"; + char * cMethodName = "getDouble"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallDoubleMethod( object, mID, args[0].i); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return out; +} + +float SAL_CALL java_sql_CallableStatement::getFloat( sal_Int32 columnIndex ) throw(starsdbc::SQLException, RuntimeException) +{ + jfloat out; + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + + { + // temporaere Variable initialisieren + char * cSignature = "(I)F"; + char * cMethodName = "getFloat"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallFloatMethod( object, mID, columnIndex ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return out; +} + +sal_Int32 SAL_CALL java_sql_CallableStatement::getInt( sal_Int32 columnIndex ) throw(starsdbc::SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + + { + // temporaere Variable initialisieren + char * cSignature = "(I)I"; + char * cMethodName = "getInt"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID, columnIndex ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return (sal_Int32)out; +} + +sal_Int64 SAL_CALL java_sql_CallableStatement::getLong( sal_Int32 columnIndex ) throw(starsdbc::SQLException, RuntimeException) +{ + jlong out; + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[1]; + // Parameter konvertieren + args[0].i = (sal_Int32)columnIndex; + // temporaere Variable initialisieren + char * cSignature = "(I)J"; + char * cMethodName = "getLong"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallLongMethod( object, mID, args[0].i ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return out; +} + +Any SAL_CALL java_sql_CallableStatement::getObject( sal_Int32 columnIndex, const Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(starsdbc::SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[1]; + // Parameter konvertieren + args[0].i = (sal_Int32)columnIndex; + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/lang/Object;"; + char * cMethodName = "getObject"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, args[0].i); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return Any(); //out==0 ? 0 : new java_lang_Object( t.pEnv, out ); +} + +sal_Int16 SAL_CALL java_sql_CallableStatement::getShort( sal_Int32 columnIndex ) throw(starsdbc::SQLException, RuntimeException) +{ + jshort out; + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[1]; + // Parameter konvertieren + args[0].i = (sal_Int32)columnIndex; + // temporaere Variable initialisieren + char * cSignature = "(I)S"; + char * cMethodName = "getShort"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallShortMethod( object, mID, args[0].i); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return (sal_Int16)out; +} + +::rtl::OUString SAL_CALL java_sql_CallableStatement::getString( sal_Int32 columnIndex ) throw(starsdbc::SQLException, RuntimeException) +{ + jstring out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + ::rtl::OUString aStr; + if( t.pEnv ){ + jvalue args[1]; + // Parameter konvertieren + args[0].i = (sal_Int32)columnIndex; + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/lang/String;"; + char * cMethodName = "getString"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = (jstring)t.pEnv->CallObjectMethod( object, mID, columnIndex ); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} + + ::com::sun::star::util::Time SAL_CALL java_sql_CallableStatement::getTime( sal_Int32 columnIndex ) throw(starsdbc::SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + + { + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/sql/Time;"; + char * cMethodName = "getTime"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, columnIndex); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return java_sql_Time( t.pEnv, out ); +} + + ::com::sun::star::util::DateTime SAL_CALL java_sql_CallableStatement::getTimestamp( sal_Int32 columnIndex ) throw(starsdbc::SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[1]; + // Parameter konvertieren + args[0].i = (sal_Int32)columnIndex; + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/sql/Timestamp;"; + char * cMethodName = "getTimestamp"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, args[0].i); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return java_sql_Timestamp( t.pEnv, out ); +} + +void SAL_CALL java_sql_CallableStatement::registerOutParameter( sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& typeName ) throw(starsdbc::SQLException, RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + jvalue args[3]; + // Parameter konvertieren + args[0].i = (sal_Int32)parameterIndex; + args[1].i = (sal_Int32)sqlType; + args[2].l = convertwchar_tToJavaString(t.pEnv,typeName); + // temporaere Variable initialisieren + char * cSignature = "(IILjava/lang/String;)V"; + char * cMethodName = "registerOutParameter"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + t.pEnv->CallVoidMethod( object, mID, args[0].i,args[1].i,args[2].l); + ThrowSQLException(t.pEnv,*this); + t.pEnv->DeleteLocalRef((jstring)args[2].l); + } + } +} +void SAL_CALL java_sql_CallableStatement::registerNumericOutParameter( sal_Int32 parameterIndex, sal_Int32 sqlType, sal_Int32 scale ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + jvalue args[3]; + // Parameter konvertieren + args[0].i = (sal_Int32)parameterIndex; + args[1].i = (sal_Int32)sqlType; + args[2].i = scale; + // temporaere Variable initialisieren + char * cSignature = "(III)V"; + char * cMethodName = "registerOutParameter"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + t.pEnv->CallVoidMethod( object, mID, args[0].i,args[1].i,args[2].i); + ThrowSQLException(t.pEnv,*this); + } + } +} + +jclass java_sql_CallableStatement::theClass = 0; + +jclass java_sql_CallableStatement::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( !t.pEnv ) return (jclass)0; + jclass tempClass = t.pEnv->FindClass("java/sql/CallableStatement"); OSL_ENSHURE(tempClass,"Java : FindClass nicht erfolgreich!"); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} + +void java_sql_CallableStatement::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==0 ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} + +Reference< ::com::sun::star::io::XInputStream > SAL_CALL java_sql_CallableStatement::getBinaryStream( sal_Int32 columnIndex ) throw(starsdbc::SQLException, RuntimeException) +{ + Reference< starsdbc::XBlob > xBlob = getBlob(columnIndex); + return xBlob.is() ? xBlob->getBinaryStream() : Reference< ::com::sun::star::io::XInputStream >(); +} +Reference< ::com::sun::star::io::XInputStream > SAL_CALL java_sql_CallableStatement::getCharacterStream( sal_Int32 columnIndex ) throw(starsdbc::SQLException, RuntimeException) +{ + Reference< starsdbc::XClob > xClob = getClob(columnIndex); + return xClob.is() ? xClob->getCharacterStream() : Reference< ::com::sun::star::io::XInputStream >(); +} + +Reference< starsdbc::XArray > SAL_CALL java_sql_CallableStatement::getArray( sal_Int32 columnIndex ) throw(starsdbc::SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/sql/Ref;"; + char * cMethodName = "getArray"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, columnIndex); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_Array( t.pEnv, out ); +} + +Reference< starsdbc::XClob > SAL_CALL java_sql_CallableStatement::getClob( sal_Int32 columnIndex ) throw(starsdbc::SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/sql/Ref;"; + char * cMethodName = "getClob"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, columnIndex); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_Clob( t.pEnv, out ); +} +Reference< starsdbc::XBlob > SAL_CALL java_sql_CallableStatement::getBlob( sal_Int32 columnIndex ) throw(starsdbc::SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/sql/Ref;"; + char * cMethodName = "getBlob"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, columnIndex); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_Blob( t.pEnv, out ); +} + +Reference< starsdbc::XRef > SAL_CALL java_sql_CallableStatement::getRef( sal_Int32 columnIndex ) throw(starsdbc::SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/sql/Ref;"; + char * cMethodName = "getRef"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, columnIndex); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_Ref( t.pEnv, out ); +} + + diff --git a/connectivity/source/drivers/jdbc/Class.cxx b/connectivity/source/drivers/jdbc/Class.cxx new file mode 100644 index 000000000000..e11dbd3a3b15 --- /dev/null +++ b/connectivity/source/drivers/jdbc/Class.cxx @@ -0,0 +1,185 @@ +/************************************************************************* + * + * $RCSfile: Class.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_JAVA_LANG_CLASS_HXX_ +#include "java/lang/Class.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_ +#include "java/tools.hxx" +#endif + +using namespace connectivity; +//************************************************************** +//************ Class: java.lang.Class +//************************************************************** + +jclass java_lang_Class::theClass = 0; + +java_lang_Class::~java_lang_Class() +{} + +jclass java_lang_Class::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; + if( !t.pEnv ) return (jclass)NULL; + jclass tempClass = t.pEnv->FindClass("java/lang/Class"); OSL_ENSHURE(tempClass,"Java : FindClass nicht erfolgreich!"); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} + +void java_lang_Class::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==NULL ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} + +java_lang_Class * java_lang_Class::forName( const ::rtl::OUString& _par0 ) +{ + jobject out(NULL); + SDBThreadAttach t; + if( t.pEnv ){ + jvalue args[1]; + // Parameter konvertieren + args[0].l = convertwchar_tToJavaString(t.pEnv,_par0); + // temporaere Variable initialisieren + char * cSignature = "(Ljava/lang/String;)Ljava/lang/Class;"; + char * cMethodName = "forName"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetStaticMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallStaticObjectMethod( getMyClass(), mID, args[0].l ); + ThrowSQLException(t.pEnv,0); + // und aufraeumen + t.pEnv->DeleteLocalRef((jstring)args[0].l); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? NULL : new java_lang_Class( t.pEnv, out ); +} + +sal_Bool java_lang_Class::isAssignableFrom( java_lang_Class * _par0 ) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + jvalue args[1]; + // Parameter konvertieren + args[0].l = _par0 != NULL ? ((java_lang_Object *)_par0)->getJavaObject() : NULL; + // temporaere Variable initialisieren + char * cSignature = "(Ljava/lang/Class;)Z"; + char * cMethodName = "isAssignableFrom"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID, args[0].l ); + ThrowSQLException(t.pEnv,0); + // und aufraeumen + } //mID + } //t.pEnv + return out; +} + +java_lang_Object * java_lang_Class::newInstance() +{ + jobject out(NULL); + SDBThreadAttach t; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/Object;"; + char * cMethodName = "newInstance"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,0); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? NULL : new java_lang_Object( t.pEnv, out ); +} + +::rtl::OUString java_lang_Class::getName() +{ + jstring out = (jstring)NULL; + SDBThreadAttach t; + ::rtl::OUString aStr; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getName"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = (jstring)t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,0); + aStr = JavaString2String(t.pEnv, (jstring)out ); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} + diff --git a/connectivity/source/drivers/jdbc/Clob.cxx b/connectivity/source/drivers/jdbc/Clob.cxx new file mode 100644 index 000000000000..661b86541385 --- /dev/null +++ b/connectivity/source/drivers/jdbc/Clob.cxx @@ -0,0 +1,212 @@ +/************************************************************************* + * + * $RCSfile: Clob.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_JAVA_SQL_CLOB_HXX_ +#include "java/sql/Clob.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_ +#include "java/tools.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_IO_READER_HXX_ +#include "java/io/Reader.hxx" +#endif +using namespace connectivity; +//************************************************************** +//************ Class: java.sql.Clob +//************************************************************** + +jclass java_sql_Clob::theClass = 0; + +java_sql_Clob::~java_sql_Clob() +{} + +jclass java_sql_Clob::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; + if( !t.pEnv ) return (jclass)NULL; + jclass tempClass = t.pEnv->FindClass( "java/sql/Clob" ); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} + +void java_sql_Clob::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==NULL ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} + +sal_Int64 SAL_CALL java_sql_Clob::length( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jlong out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()J"; + char * cMethodName = "length"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallLongMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return (sal_Int64)out; +} + +::rtl::OUString SAL_CALL java_sql_Clob::getSubString( sal_Int64 pos, sal_Int32 length ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jstring out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + ::rtl::OUString aStr; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(JI)Ljava/lang/String;"; + char * cMethodName = "getBaseTypeName"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = (jstring)t.pEnv->CallObjectMethod( object, mID,pos,length); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} + +::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL java_sql_Clob::getCharacterStream( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "()Ljava/io/Reader;"; + char * cMethodName = "getCharacterStream"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_io_Reader( t.pEnv, out ); +} + +sal_Int64 SAL_CALL java_sql_Clob::position( const ::rtl::OUString& searchstr, sal_Int32 start ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jlong out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + jvalue args[1]; + // Parameter konvertieren + args[0].l = convertwchar_tToJavaString(t.pEnv,searchstr); + // temporaere Variable initialisieren + char * cSignature = "(Ljava/lang/String;I)J"; + char * cMethodName = "position"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallLongMethod( object, mID, args[0].l,start ); + ThrowSQLException(t.pEnv,*this); + t.pEnv->DeleteLocalRef((jstring)args[0].l); + // und aufraeumen + } //mID + } //t.pEnv + return (sal_Int64)out; +} + +sal_Int64 SAL_CALL java_sql_Clob::positionOfClob( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XClob >& pattern, sal_Int64 start ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jlong out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + jvalue args[1]; + // Parameter konvertieren + args[0].l = 0; + // temporaere Variable initialisieren + char * cSignature = "(Ljava/sql/Clob;I)J"; + char * cMethodName = "position"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallLongMethod( object, mID,args[0].l,start ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return (sal_Int64)out; +} + + diff --git a/connectivity/source/drivers/jdbc/DatabaseMetaData.cxx b/connectivity/source/drivers/jdbc/DatabaseMetaData.cxx new file mode 100644 index 000000000000..ff93e7751a38 --- /dev/null +++ b/connectivity/source/drivers/jdbc/DatabaseMetaData.cxx @@ -0,0 +1,3269 @@ +/************************************************************************* + * + * $RCSfile: DatabaseMetaData.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_JAVA_SQL_DATABASEMETADATA_HXX_ +#include "java/sql/DatabaseMetaData.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_CONNECTION_HXX_ +#include "java/sql/Connection.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_RESULTSET_HXX_ +#include "java/sql/ResultSet.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_ +#include "java/tools.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_LANG_STRING_HXX_ +#include "java/lang/String.hxx" +#endif +#ifndef _CONNECTIVITY_COMMONTOOLS_HXX_ +#include "connectivity/CommonTools.hxx" +#endif +//#ifndef _UTL_TYPES_HXX_ +//#include <unotools/types.hxx> +//#endif + +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; +using namespace ::com::sun::star::lang; + +//************************************************************** +//************ Class: java.sql.DatabaseMetaData +//************************************************************** + +jclass java_sql_DatabaseMetaData::theClass = 0; + +java_sql_DatabaseMetaData::~java_sql_DatabaseMetaData() +{} + +jclass java_sql_DatabaseMetaData::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( !t.pEnv ) return (jclass)0; + jclass tempClass = t.pEnv->FindClass("java/sql/DatabaseMetaData"); OSL_ENSHURE(tempClass,"Java : FindClass nicht erfolgreich!"); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} +// ------------------------------------------------------------------------- + + +void java_sql_DatabaseMetaData::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==0 ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getTypeInfo( ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + + { + // temporaere Variable initialisieren + char * cSignature = "()Ljava/sql/ResultSet;"; + char * cMethodName = "getTypeInfo"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out ); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getCatalogs( ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + + { + // temporaere Variable initialisieren + char * cSignature = "()Ljava/sql/ResultSet;"; + char * cMethodName = "getCatalogs"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out ); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_DatabaseMetaData::getCatalogSeparator( ) throw(SQLException, RuntimeException) +{ + jstring out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + ::rtl::OUString aStr; + if( t.pEnv ) + + { + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getCatalogSeparator"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = (jstring)t.pEnv->CallObjectMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getSchemas( ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + char * cSignature = "()Ljava/sql/ResultSet;"; + char * cMethodName = "getSchemas"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + out = t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out ? new java_sql_ResultSet( t.pEnv, out ) : 0; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getColumnPrivileges( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, const ::rtl::OUString& columnNamePattern ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[4]; + // temporaere Variable initialisieren + args[0].l = catalog.hasValue() ? convertwchar_tToJavaString(t.pEnv,connectivity::getString(catalog)) : 0; + args[1].l = schema.toChar() == '%' ? NULL : convertwchar_tToJavaString(t.pEnv,schema); + args[2].l = convertwchar_tToJavaString(t.pEnv,table); + args[3].l = convertwchar_tToJavaString(t.pEnv,columnNamePattern); + + char * cSignature = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)Ljava/sql/ResultSet;"; + char * cMethodName = "getTables"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + out = t.pEnv->CallObjectMethod( object, mID, args[0].l, args[1].l,args[2].l,args[3].l); + ThrowSQLException(t.pEnv,*this); + if(catalog.hasValue()) + t.pEnv->DeleteLocalRef((jstring)args[0].l); + if(args[1].l) + t.pEnv->DeleteLocalRef((jstring)args[1].l); + if(table.getLength()) + t.pEnv->DeleteLocalRef((jstring)args[2].l); + if(columnNamePattern.getLength()) + t.pEnv->DeleteLocalRef((jstring)args[3].l); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out ? new java_sql_ResultSet( t.pEnv, out ) : 0; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getColumns( + const Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& tableNamePattern, const ::rtl::OUString& columnNamePattern ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[3]; + // temporaere Variable initialisieren + args[0].l = catalog.hasValue() ? convertwchar_tToJavaString(t.pEnv,connectivity::getString(catalog)) : 0; + args[1].l = schemaPattern.toChar() == '%' ? NULL : convertwchar_tToJavaString(t.pEnv,schemaPattern); + args[2].l = convertwchar_tToJavaString(t.pEnv,tableNamePattern); + + char * cSignature = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)Ljava/sql/ResultSet;"; + char * cMethodName = "getTables"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + out = t.pEnv->CallObjectMethod( object, mID, args[0].l, args[1].l,args[2].l); + ThrowSQLException(t.pEnv,*this); + if(catalog.hasValue()) + t.pEnv->DeleteLocalRef((jstring)args[0].l); + if(args[1].l) + t.pEnv->DeleteLocalRef((jstring)args[1].l); + if(tableNamePattern.getLength()) + t.pEnv->DeleteLocalRef((jstring)args[2].l); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out ? new java_sql_ResultSet( t.pEnv, out ) : 0; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getTables( + const Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& tableNamePattern, const Sequence< ::rtl::OUString >& types ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[4]; + sal_Int32 len = types.getLength(); + if(len) + { + jobjectArray pObjArray = t.pEnv->NewObjectArray((jsize) len, java_lang_String::getMyClass(), 0); + const ::rtl::OUString* pBegin = types.getConstArray(); + for(sal_Int32 i=0;i<len;i++,++pBegin) + { + jstring aT = convertwchar_tToJavaString(t.pEnv,*pBegin); + //jstring aT = t.pEnv->NewStringUTF(_par3.GetToken(i)); + t.pEnv->SetObjectArrayElement(pObjArray,(jsize)i,aT); + } + args[3].l = pObjArray; + }else + args[3].l = 0; + // temporaere Variable initialisieren + args[0].l = catalog.hasValue() ? convertwchar_tToJavaString(t.pEnv,connectivity::getString(catalog)) : 0; + args[1].l = schemaPattern.toChar() == '%' ? NULL : convertwchar_tToJavaString(t.pEnv,schemaPattern); + args[2].l = convertwchar_tToJavaString(t.pEnv,tableNamePattern); + + char * cSignature = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)Ljava/sql/ResultSet;"; + char * cMethodName = "getTables"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + out = t.pEnv->CallObjectMethod( object, mID, args[0].l, args[1].l,args[2].l,args[3].l); + ThrowSQLException(t.pEnv,*this); + if(catalog.hasValue()) + t.pEnv->DeleteLocalRef((jstring)args[0].l); + if(args[1].l) + t.pEnv->DeleteLocalRef((jstring)args[1].l); + if(tableNamePattern.getLength()) + t.pEnv->DeleteLocalRef((jstring)args[2].l); + //for(INT16 i=0;i<len;i++) + t.pEnv->DeleteLocalRef((jobjectArray)args[3].l); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out ? new java_sql_ResultSet( t.pEnv, out ) : 0; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getProcedureColumns( + const Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& procedureNamePattern, const ::rtl::OUString& columnNamePattern ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + jvalue args[4]; + // Parameter konvertieren + args[0].l = catalog.hasValue() ? convertwchar_tToJavaString(t.pEnv,connectivity::getString(catalog)) : 0; + args[1].l = schemaPattern.toChar() == '%' ? NULL : convertwchar_tToJavaString(t.pEnv,schemaPattern); + args[2].l = convertwchar_tToJavaString(t.pEnv,procedureNamePattern); + args[3].l = convertwchar_tToJavaString(t.pEnv,columnNamePattern); + // temporaere Variable initialisieren + char * cSignature = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/sql/ResultSet;"; + char * cMethodName = "getProcedures"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, args[0].l,args[1].l,args[2].l); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + if(catalog.hasValue()) + t.pEnv->DeleteLocalRef((jstring)args[0].l); + if(args[1].l) + t.pEnv->DeleteLocalRef((jstring)args[1].l); + if(procedureNamePattern.getLength()) + t.pEnv->DeleteLocalRef((jstring)args[2].l); + if(columnNamePattern.getLength()) + t.pEnv->DeleteLocalRef((jstring)args[3].l); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out ); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getProcedures( const Any& + catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& procedureNamePattern ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + jvalue args[3]; + // Parameter konvertieren + args[0].l = catalog.hasValue() ? convertwchar_tToJavaString(t.pEnv,connectivity::getString(catalog)) : 0; + args[1].l = schemaPattern.toChar() == '%' ? NULL : convertwchar_tToJavaString(t.pEnv,schemaPattern); + args[2].l = convertwchar_tToJavaString(t.pEnv,procedureNamePattern); + // temporaere Variable initialisieren + char * cSignature = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/sql/ResultSet;"; + char * cMethodName = "getProcedures"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, args[0].l,args[1].l,args[2].l); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + if(catalog.hasValue()) + t.pEnv->DeleteLocalRef((jstring)args[0].l); + if(args[1].l) + t.pEnv->DeleteLocalRef((jstring)args[1].l); + if(procedureNamePattern.getLength()) + t.pEnv->DeleteLocalRef((jstring)args[2].l); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out ); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getVersionColumns( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[3]; + // Parameter konvertieren + args[0].l = catalog.hasValue() ? convertwchar_tToJavaString(t.pEnv,connectivity::getString(catalog)) : 0; + args[1].l = schema.toChar() == '%' ? NULL : convertwchar_tToJavaString(t.pEnv,schema); + args[2].l = convertwchar_tToJavaString(t.pEnv,table); + // temporaere Variable initialisieren + char * cSignature = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/sql/ResultSet;"; + char * cMethodName = "getVersionColumns"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, args[0].l,args[1].l,args[2].l); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + if(catalog.hasValue()) + t.pEnv->DeleteLocalRef((jstring)args[0].l); + if(args[1].l) + t.pEnv->DeleteLocalRef((jstring)args[1].l); + if(table.getLength()) + t.pEnv->DeleteLocalRef((jstring)args[2].l); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out ); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getMaxBinaryLiteralLength( ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMaxBinaryLiteralLength"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getMaxRowSize( ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + + { + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMaxRowSize"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getMaxCatalogNameLength( ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + + { + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMaxCatalogNameLength"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getMaxCharLiteralLength( ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + + { + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMaxCharLiteralLength"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getMaxColumnNameLength( ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + + { + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMaxColumnNameLength"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getMaxColumnsInIndex( ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMaxColumnsInIndex"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getMaxCursorNameLength( ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMaxCursorNameLength"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getMaxConnections( ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMaxConnections"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getMaxColumnsInTable( ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMaxColumnsInTable"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getMaxStatementLength( ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMaxStatementLength"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getMaxTableNameLength( ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMaxTableNameLength"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getMaxTablesInSelect( ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMaxTablesInSelect"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getExportedKeys( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[3]; + // Parameter konvertieren + args[0].l = catalog.hasValue() ? convertwchar_tToJavaString(t.pEnv,connectivity::getString(catalog)) : 0; + args[1].l = schema.toChar() == '%' ? NULL : convertwchar_tToJavaString(t.pEnv,schema); + args[2].l = convertwchar_tToJavaString(t.pEnv,table); + // temporaere Variable initialisieren + char * cSignature = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/sql/ResultSet;"; + char * cMethodName = "getExportedKeys"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, args[0].l,args[1].l,args[2].l); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + if(catalog.hasValue()) + t.pEnv->DeleteLocalRef((jstring)args[0].l); + if(args[1].l) + t.pEnv->DeleteLocalRef((jstring)args[1].l); + if(table.getLength()) + t.pEnv->DeleteLocalRef((jstring)args[2].l); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out ); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getImportedKeys( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[3]; + // Parameter konvertieren + args[0].l = catalog.hasValue() ? convertwchar_tToJavaString(t.pEnv,connectivity::getString(catalog)) : 0; + args[1].l = schema.toChar() == '%' ? NULL : convertwchar_tToJavaString(t.pEnv,schema); + args[2].l = convertwchar_tToJavaString(t.pEnv,table); + // temporaere Variable initialisieren + char * cSignature = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/sql/ResultSet;"; + char * cMethodName = "getImportedKeys"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, args[0].l,args[1].l,args[2].l); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + if(catalog.hasValue()) + t.pEnv->DeleteLocalRef((jstring)args[0].l); + if(args[1].l) + t.pEnv->DeleteLocalRef((jstring)args[1].l); + if(table.getLength()) + t.pEnv->DeleteLocalRef((jstring)args[2].l); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out ); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getPrimaryKeys( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[3]; + // Parameter konvertieren + args[0].l = catalog.hasValue() ? convertwchar_tToJavaString(t.pEnv,connectivity::getString(catalog)) : 0; + args[1].l = schema.toChar() == '%' ? NULL : convertwchar_tToJavaString(t.pEnv,schema); + args[2].l = convertwchar_tToJavaString(t.pEnv,table); + // temporaere Variable initialisieren + char * cSignature = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/sql/ResultSet;"; + char * cMethodName = "getPrimaryKeys"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, args[0].l,args[1].l,args[2].l); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + if(catalog.hasValue()) + t.pEnv->DeleteLocalRef((jstring)args[0].l); + if(args[1].l) + t.pEnv->DeleteLocalRef((jstring)args[1].l); + if(table.getLength()) + t.pEnv->DeleteLocalRef((jstring)args[2].l); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out ); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getIndexInfo( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, + sal_Bool unique, sal_Bool approximate ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[5]; + // Parameter konvertieren + args[0].l = catalog.hasValue() ? convertwchar_tToJavaString(t.pEnv,connectivity::getString(catalog)) : 0; + args[1].l = schema.toChar() == '%' ? NULL : convertwchar_tToJavaString(t.pEnv,schema); + args[2].l = convertwchar_tToJavaString(t.pEnv,table); + args[3].z = unique; + args[4].z = approximate; + // temporaere Variable initialisieren + char * cSignature = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZ)Ljava/sql/ResultSet;"; + char * cMethodName = "getIndexInfo"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, args[0].l,args[1].l,args[2].l,args[3].z,args[4].z ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + if(catalog.hasValue()) + t.pEnv->DeleteLocalRef((jstring)args[0].l); + if(args[1].l) + t.pEnv->DeleteLocalRef((jstring)args[1].l); + if(table.getLength()) + t.pEnv->DeleteLocalRef((jstring)args[2].l); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out ); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getBestRowIdentifier( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, sal_Int32 scope, + sal_Bool nullable ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[3]; + // Parameter konvertieren + args[0].l = catalog.hasValue() ? convertwchar_tToJavaString(t.pEnv,connectivity::getString(catalog)) : 0; + args[1].l = schema.toChar() == '%' ? NULL : convertwchar_tToJavaString(t.pEnv,schema); + args[2].l = convertwchar_tToJavaString(t.pEnv,table); + + // temporaere Variable initialisieren + char * cSignature = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/sql/ResultSet;"; + char * cMethodName = "getTablePrivileges"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, args[0].l,args[1].l,args[2].l,scope,nullable); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + if(catalog.hasValue()) + t.pEnv->DeleteLocalRef((jstring)args[0].l); + if(args[1].l) + t.pEnv->DeleteLocalRef((jstring)args[1].l); + if(table.getLength()) + t.pEnv->DeleteLocalRef((jstring)args[2].l); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out ); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getTablePrivileges( + const Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& tableNamePattern ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[3]; + // Parameter konvertieren + args[0].l = catalog.hasValue() ? convertwchar_tToJavaString(t.pEnv,connectivity::getString(catalog)) : 0; + args[1].l = schemaPattern.toChar() == '%' ? NULL : convertwchar_tToJavaString(t.pEnv,schemaPattern); + args[2].l = convertwchar_tToJavaString(t.pEnv,tableNamePattern); + + // temporaere Variable initialisieren + char * cSignature = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/sql/ResultSet;"; + char * cMethodName = "getTablePrivileges"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, args[0].l,args[1].l,args[2].l); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + if(catalog.hasValue()) + t.pEnv->DeleteLocalRef((jstring)args[0].l); + if(args[1].l) + t.pEnv->DeleteLocalRef((jstring)args[1].l); + if(tableNamePattern.getLength()) + t.pEnv->DeleteLocalRef((jstring)args[2].l); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out ); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getCrossReference( + const Any& primaryCatalog, const ::rtl::OUString& primarySchema, + const ::rtl::OUString& primaryTable, const Any& foreignCatalog, + const ::rtl::OUString& foreignSchema, const ::rtl::OUString& foreignTable ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[6]; + // Parameter konvertieren + args[0].l = primaryCatalog.hasValue() ? convertwchar_tToJavaString(t.pEnv,connectivity::getString(primaryCatalog)) : 0; + args[1].l = primarySchema.toChar() == '%' ? NULL : convertwchar_tToJavaString(t.pEnv,primarySchema); + args[2].l = convertwchar_tToJavaString(t.pEnv,primaryTable); + args[3].l = foreignCatalog.hasValue() ? convertwchar_tToJavaString(t.pEnv,connectivity::getString(foreignCatalog)) : 0; + args[4].l = foreignSchema.toChar() == '%' ? NULL : convertwchar_tToJavaString(t.pEnv,foreignSchema); + args[5].l = convertwchar_tToJavaString(t.pEnv,foreignTable); + // temporaere Variable initialisieren + char * cSignature = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/sql/ResultSet;"; + char * cMethodName = "getCrossReference"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, args[0].l,args[2].l,args[2].l,args[3].l,args[4].l,args[5].l ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + if(primaryCatalog.hasValue()) + t.pEnv->DeleteLocalRef((jstring)args[0].l); + if(args[1].l) + t.pEnv->DeleteLocalRef((jstring)args[1].l); + if(primaryTable.getLength()) + t.pEnv->DeleteLocalRef((jstring)args[2].l); + if(foreignCatalog.hasValue()) + t.pEnv->DeleteLocalRef((jstring)args[3].l); + if(args[4].l) + t.pEnv->DeleteLocalRef((jstring)args[4].l); + if(foreignTable.getLength()) + t.pEnv->DeleteLocalRef((jstring)args[5].l); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out ); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::doesMaxRowSizeIncludeBlobs( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "doesMaxRowSizeIncludeBlobs"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::storesLowerCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "storesLowerCaseQuotedIdentifiers"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::storesLowerCaseIdentifiers( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "storesLowerCaseIdentifiers"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::storesMixedCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "storesMixedCaseQuotedIdentifiers"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::storesMixedCaseIdentifiers( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "storesMixedCaseIdentifiers"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::storesUpperCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "storesUpperCaseQuotedIdentifiers"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::storesUpperCaseIdentifiers( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "storesUpperCaseIdentifiers"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsAlterTableWithAddColumn( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsAlterTableWithAddColumn"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsAlterTableWithDropColumn( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsAlterTableWithDropColumn"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getMaxIndexLength( ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMaxIndexLength"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsNonNullableColumns( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsNonNullableColumns"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_DatabaseMetaData::getCatalogTerm( ) throw(SQLException, RuntimeException) +{ + jstring out = (jstring)0; + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + ::rtl::OUString aStr; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getCatalogTerm"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = (jstring)t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_DatabaseMetaData::getIdentifierQuoteString( ) throw(SQLException, RuntimeException) +{ + jstring out = (jstring)0; + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + ::rtl::OUString aStr; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getIdentifierQuoteString"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = (jstring)t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_DatabaseMetaData::getExtraNameCharacters( ) throw(SQLException, RuntimeException) +{ + jstring out = (jstring)0; + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + ::rtl::OUString aStr; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getExtraNameCharacters"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = (jstring)t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsDifferentTableCorrelationNames( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsDifferentTableCorrelationNames"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::isCatalogAtStart( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "isCatalogAtStart"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::dataDefinitionIgnoredInTransactions( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "dataDefinitionIgnoredInTransactions"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::dataDefinitionCausesTransactionCommit( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "dataDefinitionCausesTransactionCommit"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsDataManipulationTransactionsOnly( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsDataManipulationTransactionsOnly"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsDataDefinitionAndDataManipulationTransactions( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsDataDefinitionAndDataManipulationTransactions"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsPositionedDelete( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsPositionedDelete"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsPositionedUpdate( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsPositionedUpdate"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsOpenStatementsAcrossRollback( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsOpenStatementsAcrossRollback"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsOpenStatementsAcrossCommit( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsOpenStatementsAcrossCommit"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsOpenCursorsAcrossCommit( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsOpenCursorsAcrossCommit"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsOpenCursorsAcrossRollback( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsOpenCursorsAcrossRollback"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsTransactionIsolationLevel( sal_Int32 level ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "supportsTransactionIsolationLevel"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID, level); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsSchemasInDataManipulation( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsSchemasInDataManipulation"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsANSI92FullSQL( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsANSI92FullSQL"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsANSI92EntryLevelSQL( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsANSI92EntryLevelSQL"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsIntegrityEnhancementFacility( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsIntegrityEnhancementFacility"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsSchemasInIndexDefinitions( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsSchemasInIndexDefinitions"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsSchemasInTableDefinitions( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsSchemasInTableDefinitions"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsCatalogsInTableDefinitions( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsCatalogsInTableDefinitions"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsCatalogsInIndexDefinitions( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsCatalogsInIndexDefinitions"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsCatalogsInDataManipulation( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsCatalogsInDataManipulation"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsOuterJoins( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsOuterJoins"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getTableTypes( ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Ljava/sql/ResultSet;"; + char * cMethodName = "getTableTypes"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out ); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getMaxStatements( ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMaxStatements"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getMaxProcedureNameLength( ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMaxProcedureNameLength"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getMaxSchemaNameLength( ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMaxSchemaNameLength"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsTransactions( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsTransactions"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::allProceduresAreCallable( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "allProceduresAreCallable"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsStoredProcedures( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsStoredProcedures"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsSelectForUpdate( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsSelectForUpdate"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::allTablesAreSelectable( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "allTablesAreSelectable"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::isReadOnly( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "isReadOnly"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::usesLocalFiles( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "usesLocalFiles"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::usesLocalFilePerTable( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "usesLocalFilePerTable"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsTypeConversion( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsTypeConversion"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::nullPlusNonNullIsNull( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "nullPlusNonNullIsNull"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsColumnAliasing( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsColumnAliasing"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsTableCorrelationNames( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsTableCorrelationNames"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsConvert( sal_Int32 fromType, sal_Int32 toType ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + jvalue args[2]; + // Parameter konvertieren + args[0].i = (sal_Int32)fromType; + args[1].i = (sal_Int32)toType; + // temporaere Variable initialisieren + char * cSignature = "(II)Z"; + char * cMethodName = "supportsConvert"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID, args[0].i,args[0].i ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsExpressionsInOrderBy( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsExpressionsInOrderBy"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsGroupBy( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsGroupBy"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsGroupByBeyondSelect( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsGroupByBeyondSelect"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsGroupByUnrelated( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsGroupByUnrelated"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsMultipleTransactions( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsMultipleTransactions"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsMultipleResultSets( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsMultipleResultSets"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsLikeEscapeClause( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsLikeEscapeClause"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsOrderByUnrelated( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsOrderByUnrelated"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsUnion( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsUnion"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsUnionAll( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsUnionAll"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsMixedCaseIdentifiers( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsMixedCaseIdentifiers"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsMixedCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsMixedCaseQuotedIdentifiers"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::nullsAreSortedAtEnd( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "nullsAreSortedAtEnd"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::nullsAreSortedAtStart( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "nullsAreSortedAtStart"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::nullsAreSortedHigh( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "nullsAreSortedHigh"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::nullsAreSortedLow( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "nullsAreSortedLow"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsSchemasInProcedureCalls( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsSchemasInProcedureCalls"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsSchemasInPrivilegeDefinitions( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsSchemasInPrivilegeDefinitions"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsCatalogsInProcedureCalls( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsCatalogsInProcedureCalls"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsCatalogsInPrivilegeDefinitions( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsCatalogsInPrivilegeDefinitions"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsCorrelatedSubqueries( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsCorrelatedSubqueries"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsSubqueriesInComparisons( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsSubqueriesInComparisons"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsSubqueriesInExists( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsSubqueriesInExists"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsSubqueriesInIns( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsSubqueriesInIns"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsSubqueriesInQuantifieds( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsSubqueriesInQuantifieds"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsANSI92IntermediateSQL( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsANSI92IntermediateSQL"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_DatabaseMetaData::getURL( ) throw(SQLException, RuntimeException) +{ + + SDBThreadAttach t; + ::rtl::OUString aStr; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getURL"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + jstring out = (jstring)t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_DatabaseMetaData::getUserName( ) throw(SQLException, RuntimeException) +{ + SDBThreadAttach t; + ::rtl::OUString aStr; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getUserName"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + jstring out = (jstring)t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_DatabaseMetaData::getDriverName( ) throw(SQLException, RuntimeException) +{ + jstring out = (jstring)NULL; + SDBThreadAttach t; + ::rtl::OUString aStr; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getDriverName"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = (jstring)t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_DatabaseMetaData::getDriverVersion( ) throw(SQLException, RuntimeException) +{ + jstring out = (jstring)NULL; + SDBThreadAttach t; + ::rtl::OUString aStr; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getDriverVersion"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = (jstring)t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_DatabaseMetaData::getDatabaseProductVersion( ) throw(SQLException, RuntimeException) +{ + SDBThreadAttach t; + ::rtl::OUString aStr; + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getDatabaseProductVersion"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + jstring out = (jstring)t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_DatabaseMetaData::getDatabaseProductName( ) throw(SQLException, RuntimeException) +{ + SDBThreadAttach t; + ::rtl::OUString aStr; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getDatabaseProductName"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + jstring out = (jstring)t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_DatabaseMetaData::getProcedureTerm( ) throw(SQLException, RuntimeException) +{ + jstring out = (jstring)NULL; + SDBThreadAttach t; + ::rtl::OUString aStr; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getProcedureTerm"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = (jstring)t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_DatabaseMetaData::getSchemaTerm( ) throw(SQLException, RuntimeException) +{ + jstring out = (jstring)NULL; + SDBThreadAttach t; + ::rtl::OUString aStr; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getSchemaTerm"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = (jstring)t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getDriverMajorVersion( ) throw(RuntimeException) +{ + jint out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getDriverMajorVersion"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getDefaultTransactionIsolation( ) throw(SQLException, RuntimeException) +{ + jint out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getDefaultTransactionIsolation"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getDriverMinorVersion( ) throw(RuntimeException) +{ + jint out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getDriverMinorVersion"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_DatabaseMetaData::getSQLKeywords( ) throw(SQLException, RuntimeException) +{ + jstring out = (jstring)NULL; + SDBThreadAttach t; + ::rtl::OUString aStr; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getSQLKeywords"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = (jstring)t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_DatabaseMetaData::getSearchStringEscape( ) throw(SQLException, RuntimeException) +{ + jstring out = (jstring)NULL; + SDBThreadAttach t; + ::rtl::OUString aStr; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getSearchStringEscape"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = (jstring)t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_DatabaseMetaData::getStringFunctions( ) throw(SQLException, RuntimeException) +{ + jstring out = (jstring)NULL; + SDBThreadAttach t; + ::rtl::OUString aStr; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getStringFunctions"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = (jstring)t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_DatabaseMetaData::getTimeDateFunctions( ) throw(SQLException, RuntimeException) +{ + jstring out = (jstring)NULL; + SDBThreadAttach t; + ::rtl::OUString aStr; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getTimeDateFunctions"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = (jstring)t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_DatabaseMetaData::getSystemFunctions( ) throw(SQLException, RuntimeException) +{ + jstring out = (jstring)NULL; + SDBThreadAttach t; + ::rtl::OUString aStr; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getSystemFunctions"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = (jstring)t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_DatabaseMetaData::getNumericFunctions( ) throw(SQLException, RuntimeException) +{ + jstring out = (jstring)NULL; + SDBThreadAttach t; + ::rtl::OUString aStr; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getNumericFunctions"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = (jstring)t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsExtendedSQLGrammar( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsExtendedSQLGrammar"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsCoreSQLGrammar( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsCoreSQLGrammar"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsMinimumSQLGrammar( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsMinimumSQLGrammar"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsFullOuterJoins( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsFullOuterJoins"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsLimitedOuterJoins( ) throw(SQLException, RuntimeException) +{ + jboolean out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsLimitedOuterJoins"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getMaxColumnsInGroupBy( ) throw(SQLException, RuntimeException) +{ + jint out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMaxColumnsInGroupBy"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getMaxColumnsInOrderBy( ) throw(SQLException, RuntimeException) +{ + jint out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMaxColumnsInOrderBy"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getMaxColumnsInSelect( ) throw(SQLException, RuntimeException) +{ + jint out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMaxColumnsInSelect"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_DatabaseMetaData::getMaxUserNameLength( ) throw(SQLException, RuntimeException) +{ + jint out; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMaxUserNameLength"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsResultSetType( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "supportsResultSetType"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID,setType); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsResultSetConcurrency( sal_Int32 setType, sal_Int32 concurrency ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(II)Z"; + char * cMethodName = "supportsResultSetConcurrency"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID,setType,concurrency); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::ownUpdatesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "ownUpdatesAreVisible"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID,setType); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::ownDeletesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "ownDeletesAreVisible"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID,setType); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::ownInsertsAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "ownInsertsAreVisible"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID,setType); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::othersUpdatesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "othersUpdatesAreVisible"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID,setType); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::othersDeletesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "othersDeletesAreVisible"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID,setType); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::othersInsertsAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "othersInsertsAreVisible"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID,setType); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::updatesAreDetected( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "updatesAreDetected"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID,setType); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::deletesAreDetected( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "deletesAreDetected"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID,setType); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::insertsAreDetected( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "insertsAreDetected"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID,setType); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_DatabaseMetaData::supportsBatchUpdates( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "supportsBatchUpdates"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getUDTs( + const Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& typeNamePattern, + const Sequence< sal_Int32 >& types ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[4]; + // temporaere Variable initialisieren + args[0].l = catalog.hasValue() ? convertwchar_tToJavaString(t.pEnv,connectivity::getString(catalog)) : 0; + args[1].l = schemaPattern.toChar() == '%' ? NULL : convertwchar_tToJavaString(t.pEnv,schemaPattern); + args[2].l = convertwchar_tToJavaString(t.pEnv,typeNamePattern); + jintArray pArray = t.pEnv->NewIntArray(types.getLength()); + t.pEnv->SetIntArrayRegion(pArray,0,types.getLength(),(jint*)types.getConstArray()); + args[3].l = pArray; + + char * cSignature = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)Ljava/sql/ResultSet;"; + char * cMethodName = "getTables"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + out = t.pEnv->CallObjectMethod( object, mID, args[0].l, args[1].l,args[2].l,args[3].l); + ThrowSQLException(t.pEnv,*this); + if(catalog.hasValue()) + t.pEnv->DeleteLocalRef((jstring)args[0].l); + if(schemaPattern.getLength()) + t.pEnv->DeleteLocalRef((jstring)args[1].l); + if(typeNamePattern.getLength()) + t.pEnv->DeleteLocalRef((jstring)args[2].l); + if(args[3].l) + t.pEnv->DeleteLocalRef((jintArray)args[3].l); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out ? new java_sql_ResultSet( t.pEnv, out ) : 0; +} +// ------------------------------------------------------------------------- +Reference< XConnection > SAL_CALL java_sql_DatabaseMetaData::getConnection( ) throw(SQLException, RuntimeException) +{ +// jobject out(0); +// SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); +// if( t.pEnv ){ +// char * cSignature = "()Ljava/sql/Connection;"; +// char * cMethodName = "getConnection"; +// // Java-Call absetzen +// jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); +// if( mID ) +// { +// out = t.pEnv->CallObjectMethod( object, mID); +// ThrowSQLException(t.pEnv,*this); +// } //mID +// } //t.pEnv +// // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! +// return out ? new java_sql_Connection( t.pEnv, out,this ) : 0; + return (Reference< XConnection >)m_pConnection; +} +// ------------------------------------------------------------------------- + diff --git a/connectivity/source/drivers/jdbc/Date.cxx b/connectivity/source/drivers/jdbc/Date.cxx new file mode 100644 index 000000000000..d024ae0ddbed --- /dev/null +++ b/connectivity/source/drivers/jdbc/Date.cxx @@ -0,0 +1,225 @@ +/************************************************************************* + * + * $RCSfile: Date.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_JAVA_UTIL_DATE_HXX_ +#include "java/util/Date.hxx" +#endif + +#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_ +#include "java/tools.hxx" +#endif +#ifndef _CONNECTIVITY_DATECONVERSION_HXX_ +#include "DateConversion.hxx" +#endif + +using namespace connectivity; +//************************************************************** +//************ Class: java.util.Date +//************************************************************** + +jclass java_util_Date::theClass = 0; + +java_util_Date::java_util_Date( const ::com::sun::star::util::Date& _rOut ) //: java_lang_Object( NULL, (jobject)NULL ){ +{ + SDBThreadAttach t; + if( !t.pEnv ) + return; + jvalue args[1]; + // Parameter konvertieren + args[0].j = DateConversion::toINT32(_rOut); + // Java-Call fuer den Konstruktor absetzen + // temporaere Variable initialisieren + char * cSignature = "(J)V"; + jobject tempObj; + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), "<init>", cSignature ); + tempObj = t.pEnv->NewObjectA( getMyClass(), mID, args ); + saveRef( t.pEnv, tempObj ); + t.pEnv->DeleteLocalRef( tempObj ); + // und aufraeumen +} + +java_util_Date::~java_util_Date() +{} + +jclass java_util_Date::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; + if( !t.pEnv ) return (jclass)NULL; + jclass tempClass = t.pEnv->FindClass( "java/util/Date" ); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} + +void java_util_Date::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==NULL ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} + +sal_Int32 java_util_Date::getMinutes() +{ + jint out(0); + SDBThreadAttach t; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMinutes"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + } //mID + } //t.pEnv + return (sal_Int32)out; +} + +sal_Int32 java_util_Date::getMonth() +{ + jint out(0); + SDBThreadAttach t; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMonth"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + } //mID + } //t.pEnv + return (sal_Int32)out; +} + +sal_Int32 java_util_Date::getSeconds() +{ + jint out(0); + SDBThreadAttach t; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getSeconds"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + } //mID + } //t.pEnv + return (sal_Int32)out; +} + +sal_Int32 java_util_Date::getYear() +{ + jint out(0); + SDBThreadAttach t; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getYear"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + } //mID + } //t.pEnv + return (sal_Int32)out; +} + +sal_Int32 java_util_Date::getDate() +{ + jint out(0); + SDBThreadAttach t; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getDate"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + } //mID + } //t.pEnv + return (sal_Int32)out; +} + +sal_Int32 java_util_Date::getHours() +{ + jint out(0); + SDBThreadAttach t; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getHours"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + } //mID + } //t.pEnv + return (sal_Int32)out; +} + diff --git a/connectivity/source/drivers/jdbc/DriverManager.cxx b/connectivity/source/drivers/jdbc/DriverManager.cxx new file mode 100644 index 000000000000..bc20c0147e97 --- /dev/null +++ b/connectivity/source/drivers/jdbc/DriverManager.cxx @@ -0,0 +1,147 @@ +/************************************************************************* + * + * $RCSfile: DriverManager.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_JAVA_SQL_DRIVERMANAGER_HXX_ +#include "java/sql/DriverManager.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_ +#include "java/tools.hxx" +#endif + +using namespace connectivity; +//************************************************************** +//************ Class: java.sql.DriverManager +//************************************************************** + +jclass java_sql_DriverManager::theClass = 0; + +java_sql_DriverManager::~java_sql_DriverManager() +{} + +jclass java_sql_DriverManager::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( !t.pEnv ) return (jclass)0; + jclass tempClass = t.pEnv->FindClass("java/sql/DriverManager"); OSL_ENSHURE(tempClass,"Java : FindClass nicht erfolgreich!"); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} + +void java_sql_DriverManager::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==0 ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} + +jobject java_sql_DriverManager::getDriver(const ::rtl::OUString &url) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + jvalue args[1]; + // Parameter konvertieren + args[0].l = convertwchar_tToJavaString(t.pEnv,url); + // temporaere Variable initialisieren + char * cSignature = "(Ljava/lang/String;)Ljava/sql/Driver;"; + char * cMethodName = "getDriver"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetStaticMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + out = t.pEnv->CallStaticObjectMethod( getMyClass(), mID, args[0].l ); + ThrowSQLException(t.pEnv,0); + // und aufraeumen + t.pEnv->DeleteLocalRef((jstring)args[0].l); + } //mID + return t.pEnv->NewGlobalRef( out ); + } //t.pEnv + + return out; +} + + +void java_sql_DriverManager::setLoginTimeout(sal_Int32 _par0) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + jobject out(0); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)V"; + char * cMethodName = "setLoginTimeout"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + t.pEnv->CallStaticVoidMethod(getMyClass(), mID, _par0); + ThrowSQLException(t.pEnv,0); + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! +} + + diff --git a/connectivity/source/drivers/jdbc/DriverPropertyInfo.cxx b/connectivity/source/drivers/jdbc/DriverPropertyInfo.cxx new file mode 100644 index 000000000000..b38b2dbfb92b --- /dev/null +++ b/connectivity/source/drivers/jdbc/DriverPropertyInfo.cxx @@ -0,0 +1,191 @@ +/************************************************************************* + * + * $RCSfile: DriverPropertyInfo.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_JAVA_SQL_DRIVERPOPERTYINFO_HXX_ +#include "java/sql/DriverPropertyInfo.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_LANG_BOOLEAN_HXX_ +#include "java/lang/Boolean.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_ +#include "java/tools.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_LANG_STRING_HXX_ +#include "java/lang/String.hxx" +#endif +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; +using namespace ::com::sun::star::lang; + + +//************************************************************** +//************ Class: java.sql.Driver +//************************************************************** + +jclass java_sql_DriverPropertyInfo::theClass = 0; +// -------------------------------------------------------------------------------- +java_sql_DriverPropertyInfo::~java_sql_DriverPropertyInfo() +{} +// -------------------------------------------------------------------------------- +jclass java_sql_DriverPropertyInfo::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ) + { + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( !t.pEnv ) return (jclass)0; + jclass tempClass = t.pEnv->FindClass("java/sql/DriverPropertyInfo"); + OSL_ENSHURE(tempClass,"Java : FindClass nicht erfolgreich!"); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} +// -------------------------------------------------------------------------------- +void java_sql_DriverPropertyInfo::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==0 ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} +// -------------------------------------------------------------------------------- +java_sql_DriverPropertyInfo::operator starsdbc::DriverPropertyInfo() +{ + starsdbc::DriverPropertyInfo aInfo; + aInfo.Name = name(); + aInfo.Description = description(); + aInfo.IsRequired = required(); + aInfo.Value = value(); + aInfo.Choices = choices(); + + return aInfo; +} +// -------------------------------------------------------------------------------- +::rtl::OUString java_sql_DriverPropertyInfo::name() const +{ + ::rtl::OUString aStr; + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + jfieldID id = t.pEnv->GetFieldID(java_lang_Boolean::getMyClass(),"name","Ljava/lang/String;"); + if(id) + aStr = JavaString2String(t.pEnv,(jstring)t.pEnv->GetObjectField( object, id)); + } //t.pEnv + return aStr; +} +// -------------------------------------------------------------------------------- +::rtl::OUString java_sql_DriverPropertyInfo::description() const +{ + ::rtl::OUString aStr; + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + jfieldID id = t.pEnv->GetFieldID(java_lang_Boolean::getMyClass(),"description","Ljava/lang/String;"); + if(id) + aStr = JavaString2String(t.pEnv,(jstring)t.pEnv->GetObjectField( object, id)); + } //t.pEnv + return aStr; +} +// -------------------------------------------------------------------------------- +::rtl::OUString java_sql_DriverPropertyInfo::value() const +{ + ::rtl::OUString aStr; + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + jfieldID id = t.pEnv->GetFieldID(java_lang_Boolean::getMyClass(),"value","Ljava/lang/String;"); + if(id) + aStr = JavaString2String(t.pEnv,(jstring)t.pEnv->GetObjectField( object, id)); + } //t.pEnv + return aStr; +} +// -------------------------------------------------------------------------------- +sal_Bool java_sql_DriverPropertyInfo::required() const +{ + jboolean out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + jfieldID id = t.pEnv->GetFieldID(java_lang_Boolean::getMyClass(),"required","B"); + if(id) + out = t.pEnv->GetBooleanField( object, id); + } //t.pEnv + return out; +} +// -------------------------------------------------------------------------------- +Sequence< ::rtl::OUString> java_sql_DriverPropertyInfo::choices() const +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + jfieldID id = t.pEnv->GetFieldID(java_lang_Boolean::getMyClass(),"choices","[Ljava/lang/String"); + if(id) + return copyArrayAndDelete(t.pEnv,(jobjectArray)t.pEnv->GetObjectField( object, id), ::rtl::OUString(),java_lang_String(NULL,NULL)); + } //t.pEnv + return Sequence< ::rtl::OUString>(); +} +// -------------------------------------------------------------------------------- + diff --git a/connectivity/source/drivers/jdbc/Exception.cxx b/connectivity/source/drivers/jdbc/Exception.cxx new file mode 100644 index 000000000000..9d579b2f226f --- /dev/null +++ b/connectivity/source/drivers/jdbc/Exception.cxx @@ -0,0 +1,93 @@ +/************************************************************************* + * + * $RCSfile: Exception.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include "java/lang/Exception.hxx" +using namespace connectivity; +//************************************************************** +//************ Class: java.lang.Exception +//************************************************************** + +jclass java_lang_Exception::theClass = 0; + +java_lang_Exception::~java_lang_Exception() +{} + +jclass java_lang_Exception::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; + if( !t.pEnv ) return (jclass)NULL; + jclass tempClass = t.pEnv->FindClass("java/lang/Exception"); OSL_ENSHURE(tempClass,"Java : FindClass nicht erfolgreich!"); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} + +void java_lang_Exception::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==NULL ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} + diff --git a/connectivity/source/drivers/jdbc/InputStream.cxx b/connectivity/source/drivers/jdbc/InputStream.cxx new file mode 100644 index 000000000000..566c0dd02df7 --- /dev/null +++ b/connectivity/source/drivers/jdbc/InputStream.cxx @@ -0,0 +1,187 @@ +/************************************************************************* + * + * $RCSfile: InputStream.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_JAVA_IO_INPUTSTREAM_HXX_ +#include "java/io/InputStream.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_ +#include "java/tools.hxx" +#endif +#ifndef _INC_MEMORY +#include <memory.h> +#endif + +using namespace connectivity; +//************************************************************** +//************ Class: java.io.InputStream +//************************************************************** + +jclass java_io_InputStream::theClass = 0; + +java_io_InputStream::~java_io_InputStream() +{} + +jclass java_io_InputStream::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; + if( !t.pEnv ) return (jclass)NULL; + jclass tempClass = t.pEnv->FindClass( "java/io/InputStream" ); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} + +void java_io_InputStream::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==NULL ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} + +sal_Int32 SAL_CALL java_io_InputStream::readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) +{ + return readBytes(aData,nMaxBytesToRead); +} + +void SAL_CALL java_io_InputStream::skipBytes( sal_Int32 nBytesToSkip ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + char * cSignature = "(I)I"; + char * cMethodName = "skip"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + out = t.pEnv->CallIntMethod( object, mID,nBytesToSkip); + ThrowSQLException(t.pEnv,*this); + } + } //t.pEnv +} + +sal_Int32 SAL_CALL java_io_InputStream::available( ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + char * cSignature = "()Z"; + char * cMethodName = "available"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } + } //t.pEnv + return out; +} +void SAL_CALL java_io_InputStream::closeInput( ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + char * cSignature = "()V"; + char * cMethodName = "close"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + t.pEnv->CallVoidMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } + } //t.pEnv +} +// ----------------------------------------------------- +sal_Int32 SAL_CALL java_io_InputStream::readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + jbyteArray pByteArray = t.pEnv->NewByteArray(nBytesToRead); + char * cSignature = "([BII)I"; + char * cMethodName = "read"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + while(!(out = t.pEnv->CallIntMethod( object, mID,pByteArray,0,nBytesToRead))) + ThrowSQLException(t.pEnv,*this); + if(out > 0) + { + jboolean p = sal_False; + memcpy(aData.getArray(),t.pEnv->GetByteArrayElements(pByteArray,&p),out); + } + } + t.pEnv->DeleteLocalRef((jbyteArray)pByteArray); + } //t.pEnv + return out; +} + + diff --git a/connectivity/source/drivers/jdbc/JDriver.cxx b/connectivity/source/drivers/jdbc/JDriver.cxx new file mode 100644 index 000000000000..80e1a7013623 --- /dev/null +++ b/connectivity/source/drivers/jdbc/JDriver.cxx @@ -0,0 +1,295 @@ +/************************************************************************* + * + * $RCSfile: JDriver.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_JAVA_SQL_DRIVER_HXX_ +#include "java/sql/Driver.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_LANG_OBJECT_HXX_ +#include "java/lang/Object.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_DRIVERMANAGER_HXX_ +#include "java/sql/DriverManager.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_DRIVERPOPERTYINFO_HXX_ +#include "java/sql/DriverPropertyInfo.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_CONNECTION_HXX_ +#include "java/sql/Connection.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_ +#include "java/tools.hxx" +#endif + +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; +using namespace ::com::sun::star::lang; + +// ------------------------------------------------------------------------- +java_sql_Driver::java_sql_Driver(const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) + : java_lang_Object(_rxFactory) +{ +} +// -------------------------------------------------------------------------------- +jclass java_sql_Driver::theClass = 0; +// -------------------------------------------------------------------------------- +java_sql_Driver::~java_sql_Driver() +{} +// static ServiceInfo +//------------------------------------------------------------------------------ +rtl::OUString java_sql_Driver::getImplementationName_Static( ) throw(RuntimeException) +{ + return ::rtl::OUString::createFromAscii("com.sun.star.sdbc.JDriver"); +} +//------------------------------------------------------------------------------ +Sequence< ::rtl::OUString > java_sql_Driver::getSupportedServiceNames_Static( ) throw (RuntimeException) +{ + Sequence< ::rtl::OUString > aSNS( 1 ); + aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver"); + return aSNS; +} +//------------------------------------------------------------------ +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL connectivity::java_sql_Driver_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception ) +{ + return *(new java_sql_Driver(_rxFactory)); +} +// -------------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_Driver::getImplementationName( ) throw(RuntimeException) +{ + return getImplementationName_Static(); +} + +// -------------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_Driver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException) +{ + Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); + const ::rtl::OUString* pSupported = aSupported.getConstArray(); + for (sal_Int32 i=0; i<aSupported.getLength(); ++i, ++pSupported) + if (pSupported->equals(_rServiceName)) + return sal_True; + + return sal_False; +} + +// -------------------------------------------------------------------------------- +Sequence< ::rtl::OUString > SAL_CALL java_sql_Driver::getSupportedServiceNames( ) throw(RuntimeException) +{ + return getSupportedServiceNames_Static(); +} + +// -------------------------------------------------------------------------------- +jclass java_sql_Driver::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ) + { + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( !t.pEnv ) return (jclass)0; + jclass tempClass = t.pEnv->FindClass("java/sql/Driver"); + OSL_ENSHURE(tempClass,"Java : FindClass nicht erfolgreich!"); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} +// -------------------------------------------------------------------------------- +void java_sql_Driver::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==0 ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} +// ------------------------------------------------------------------------- +Reference< starsdbc::XConnection > SAL_CALL java_sql_Driver::connect( const ::rtl::OUString& url, const + Sequence< ::com::sun::star::beans::PropertyValue >& info ) throw(starsdbc::SQLException, RuntimeException) +{ + Reference< starsdbc::XConnection > xRet; + + object = java_sql_DriverManager::getDriver(url); + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + jvalue args[2]; + // Parameter konvertieren + args[0].l = convertwchar_tToJavaString(t.pEnv,url); + args[1].l = createStringPropertyArray(t.pEnv,info); + // temporaere Variable initialisieren + char * cSignature = "(Ljava/lang/String;Ljava/util/Properties)Ljava/sql/Connection;"; + char * cMethodName = "connect"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + out = t.pEnv->CallObjectMethodA( getMyClass(), mID, args ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + t.pEnv->DeleteLocalRef((jstring)args[0].l); + t.pEnv->DeleteLocalRef((jstring)args[1].l); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + Reference< starsdbc::XConnection > xOut; + return out==0 ? 0 : new java_sql_Connection( t.pEnv, out,this ); + // return xOut; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_Driver::acceptsURL( const ::rtl::OUString& url ) throw(starsdbc::SQLException, RuntimeException) +{ + if(!object) + object = java_sql_DriverManager::getDriver(url); + + jboolean out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + if(!object) + ThrowSQLException(t.pEnv,*this); + // temporaere Variable initialisieren + char * cSignature = "(Ljava/lang/String;)Z"; + char * cMethodName = "acceptsURL"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +Sequence< starsdbc::DriverPropertyInfo > SAL_CALL java_sql_Driver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< ::com::sun::star::beans::PropertyValue >& info ) throw(starsdbc::SQLException, RuntimeException) +{ + if(!object) + object = java_sql_DriverManager::getDriver(url); + + jobjectArray out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + jvalue args[2]; + // Parameter konvertieren + args[0].l = convertwchar_tToJavaString(t.pEnv,url); + args[1].l = createStringPropertyArray(t.pEnv,info); + // temporaere Variable initialisieren + char * cSignature = "(Ljava/lang/String;Ljava/util/Properties)[Ljava/sql/DriverPropertyInfo;"; + char * cMethodName = "getPropertyInfo"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + out = (jobjectArray)t.pEnv->CallObjectMethodA( getMyClass(), mID, args ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + t.pEnv->DeleteLocalRef((jstring)args[0].l); + t.pEnv->DeleteLocalRef((jstring)args[1].l); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return copyArrayAndDelete( t.pEnv, out, starsdbc::DriverPropertyInfo(),java_sql_DriverPropertyInfo(NULL,NULL)); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_Driver::getMajorVersion( ) throw(RuntimeException) +{ + if(!object) + throw RuntimeException(); + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMajorVersion"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_Driver::getMinorVersion( ) throw(RuntimeException) +{ + if(!object) + throw RuntimeException(); + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getMinorVersion"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- + + diff --git a/connectivity/source/drivers/jdbc/Object.cxx b/connectivity/source/drivers/jdbc/Object.cxx new file mode 100644 index 000000000000..c1caef75578e --- /dev/null +++ b/connectivity/source/drivers/jdbc/Object.cxx @@ -0,0 +1,396 @@ +/************************************************************************* + * + * $RCSfile: Object.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#ifndef _CONNECTIVITY_JAVA_LANG_OBJJECT_HXX_ +#include "java/lang/Class.hxx" +#endif + +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_UNO_EXCEPTION_HPP_ +#include <com/sun/star/uno/Exception.hpp> +#endif +#ifndef _COM_SUN_STAR_JAVA_XJAVATHREADREGISTER_11_HPP_ +#include <com/sun/star/java/XJavaThreadRegister_11.hpp> +#endif +#ifndef _COM_SUN_STAR_JAVA_XJAVAVM_HPP_ +#include <com/sun/star/java/XJavaVM.hpp> +#endif +#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_ +#include "java/tools.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_SQLEXCEPTION_HXX_ +#include "java/sql/SQLException.hxx" +#endif +#ifndef _VOS_MODULE_HXX_ +#include <vos/module.hxx> +#endif +#ifndef _VOS_PROCESS_HXX_ +#include <vos/process.hxx> +#endif +#ifndef _VOS_MUTEX_HXX_ +#include <vos/mutex.hxx> +#endif +#ifndef _VOS_DYNLOAD_HXX_ +#include <vos/dynload.hxx> +#endif + +#ifndef _RTL_PROCESS_H_ +#include <rtl/process.h> +#endif + +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#include <com/sun/star/uno/Sequence.hxx> +#endif + +using namespace connectivity; + +namespace starjava = com::sun::star::java; +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; + + +JavaVM * pJVM; +Reference< ::starjava::XJavaThreadRegister_11 > xRG11Ref; +sal_Bool bJRE_Error = sal_False; +JavaVM_ * pJRE_javaVM = NULL; + +int SDB_JRE_InitJava(const Reference<XMultiServiceFactory >& _rxFactory) +{ + int result = 0; + JNIEnv * pEnv = NULL; + + try + { + Reference< ::starjava::XJavaVM > xVM(_rxFactory->createInstance( + rtl::OUString::createFromAscii("com.sun.star.java.JavaVirtualMachine")), UNO_QUERY); + + OSL_ENSHURE(_rxFactory.is(),"SDB_JRE_InitJava: I have no factory!"); + if (!xVM.is() || !_rxFactory.is()) + throw Exception(); // -2; + + Sequence<sal_Int8> processID(16); + rtl_getGlobalProcessId( (sal_uInt8*) processID.getArray() ); + + Any uaJVM = xVM->getJavaVM( processID ); + + if (!uaJVM.hasValue()) + throw Exception(); // -5 + else + { + sal_Int32 nValue; + uaJVM >>= nValue; + pJVM = (JavaVM *)nValue; + } + + xRG11Ref = Reference< ::starjava::XJavaThreadRegister_11 >(xVM, UNO_QUERY); + if (xRG11Ref.is()) + xRG11Ref->registerThread(); + + pJVM->AttachCurrentThread(reinterpret_cast<void**>(&pEnv), NULL); + + /** + * Ist zur Zeit nicht funktionsfaehig, wegen Solaris Deadlock. + */ +// initStreamObserver(pEnv); +// if(pEnv->ExceptionOccurred()) +// { +// pEnv->ExceptionDescribe(); +// pEnv->ExceptionClear(); +// } + + } + catch (Exception e) + { + if (pEnv && pEnv->ExceptionOccurred()) + { + pEnv->ExceptionDescribe(); + pEnv->ExceptionClear(); + } + + result = -1; + } + + if(pEnv) + { + if(xRG11Ref.is()) + xRG11Ref->revokeThread(); + + if(!xRG11Ref.is() || !xRG11Ref->isThreadAttached()) + pJVM->DetachCurrentThread(); + } + + return result; +} + +SDBThreadAttach::SDBThreadAttach() : bDetach(sal_False), pEnv(NULL) +{ + attachThread(pEnv); +} + +SDBThreadAttach::SDBThreadAttach(const Reference<XMultiServiceFactory >& _rxFactory) : bDetach(sal_False), pEnv(NULL) +{ + attachThread(pEnv,_rxFactory); +} + +SDBThreadAttach::~SDBThreadAttach() +{ + detachThread(); +} + +void SDBThreadAttach::attachThread(JNIEnv * &pEnv,const Reference<XMultiServiceFactory >& _rxFactory) +{ + xInit(_rxFactory); + + if(xRG11Ref.is()) + { + xRG11Ref->registerThread(); + pJVM->AttachCurrentThread(reinterpret_cast<void**>(&pEnv), NULL); + } +} + +void SDBThreadAttach::detachThread() +{ + xInit(); + + if(xRG11Ref.is()) + { + xRG11Ref->revokeThread(); + if(!xRG11Ref->isThreadAttached()) + pJVM->DetachCurrentThread(); + } +} + +void SDBThreadAttach::xInit(const Reference<XMultiServiceFactory >& _rxFactory) +{ + StartJava(_rxFactory); +} + +sal_Bool SDBThreadAttach::IsJavaErrorOccured() +{ + return bJRE_Error; +} + +void SDBThreadAttach::setError() +{ + bJRE_Error = sal_True; +} + +static sal_Bool bStarted = sal_False; +int SDBThreadAttach::StartJava(const Reference<XMultiServiceFactory >& _rxFactory) +{ + static sal_Bool bRecFlag = sal_False; + static int err = 0; + if( !bStarted ) + { + vos::OGuard aGuard( vos::OMutex::getGlobalMutex() ); + if( !bStarted && !bRecFlag) + { + bRecFlag = sal_True; + // Application::EnterMultiThread(); + // bStarted = sal_True must set after the VM is complete initialized + err = SDB_JRE_InitJava(_rxFactory); + if(err) + setError(); + bStarted = sal_True; + } + } +// return bJRE_Error ? -1 : 0; + return err; +} + +// statische Variablen der Klasse: +jclass java_lang_Object::theClass = 0; +sal_uInt32 java_lang_Object::nObjCount = 0; + +jclass java_lang_Object::getMyClass() +{ + if( !theClass ) + { +// JNIEnv * pEnv = SDBThreadAttach::GetEnv(); + SDBThreadAttach t; + + if( !t.pEnv ) return (jclass)NULL; + jclass tempClass = t.pEnv->FindClass( "java/lang/Object" ); + theClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + } + return theClass; +} +// der eigentliche Konstruktor +java_lang_Object::java_lang_Object(const Reference<XMultiServiceFactory >& _rxFactory) + : object( 0 ),m_xFactory(_rxFactory) +{ + SDBThreadAttach t(m_xFactory); + if( !t.pEnv ) + return; + + // Java-Call fuer den Konstruktor absetzen + // temporaere Variable initialisieren + char * cSignature = "()V"; + jclass tempClass; + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), "<init>", cSignature ); + tempClass = (jclass)t.pEnv->NewObjectA( getMyClass(), mID, NULL ); + saveRef( t.pEnv, tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); +} + +// der protected-Konstruktor fuer abgeleitete Klassen +java_lang_Object::java_lang_Object( JNIEnv * pXEnv, jobject myObj ) + : object( NULL ) +{ + SDBThreadAttach t; + if( t.pEnv && myObj ) + object = t.pEnv->NewGlobalRef( myObj ); +} + +java_lang_Object::~java_lang_Object() +{ + if( object ) + { + SDBThreadAttach t; + if( t.pEnv ) + t.pEnv->DeleteGlobalRef( object ); + } +} + +// der protected-Konstruktor fuer abgeleitete Klassen +void java_lang_Object::saveRef( JNIEnv * pXEnv, jobject myObj ) +{ + OSL_ENSHURE( myObj, "object in c++ -> Java Wrapper" ); + SDBThreadAttach t; + if( t.pEnv && myObj ) + object = t.pEnv->NewGlobalRef( myObj ); +} + + +java_lang_Class * java_lang_Object::getClass() +{ + jobject out; + SDBThreadAttach t; + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/Class;"; + char * cMethodName = "getClass"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + out = t.pEnv->CallObjectMethodA( object, mID, NULL ); + + return new java_lang_Class( t.pEnv, out ); + } //mID + } //pEnv + return NULL; +} + +::rtl::OUString java_lang_Object::toString() +{ + + SDBThreadAttach t; + ::rtl::OUString aStr; + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "toString"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + jstring out(0); + out = (jstring)t.pEnv->CallObjectMethod( object, mID); + + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //pEnv + return aStr; +} +// -------------------------------------------------------------------------------- +void java_lang_Object::ThrowSQLException(JNIEnv * pEnv,const Reference< XInterface> & _rContext) throw(SQLException, RuntimeException) +{ + jthrowable jThrow = NULL; + if(pEnv && (jThrow = pEnv->ExceptionOccurred())) + { + if(pEnv->IsInstanceOf(jThrow,java_sql_SQLException_BASE::getMyClass())) + { + throw java_sql_SQLException(java_sql_SQLException_BASE(pEnv,jThrow),_rContext); + } + else if(pEnv->IsInstanceOf(jThrow,java_lang_Throwable::getMyClass())) + { + java_lang_Throwable *pThrow = new java_lang_Throwable(pEnv,jThrow); + ::rtl::OUString aMsg = pThrow->getMessage(); + delete pThrow; + throw RuntimeException(aMsg,_rContext); + } + pEnv->ExceptionClear(); + } +} + + diff --git a/connectivity/source/drivers/jdbc/PreparedStatement.cxx b/connectivity/source/drivers/jdbc/PreparedStatement.cxx new file mode 100644 index 000000000000..4b7a5dd70e07 --- /dev/null +++ b/connectivity/source/drivers/jdbc/PreparedStatement.cxx @@ -0,0 +1,842 @@ +/************************************************************************* + * + * $RCSfile: PreparedStatement.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_JAVA_SQL_PREPAREDSTATEMENT_HXX_ +#include "java/sql/PreparedStatement.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_RESULTSET_HXX_ +#include "java/sql/ResultSet.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_CONNECTION_HXX_ +#include "java/sql/Connection.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_TIMESTAMP_HXX_ +#include "java/sql/Timestamp.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_ +#include "java/tools.hxx" +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif + +using namespace connectivity; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; + +//************************************************************** +//************ Class: java.sql.PreparedStatement +//************************************************************** +IMPLEMENT_SERVICE_INFO(java_sql_PreparedStatement,"com.sun.star.sdbcx.JPreparedStatement","com.sun.star.sdbc.PreparedStatement"); + +jclass java_sql_PreparedStatement::theClass = 0; + +java_sql_PreparedStatement::~java_sql_PreparedStatement() +{} + +jclass java_sql_PreparedStatement::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( !t.pEnv ) return (jclass)0; + jclass tempClass = t.pEnv->FindClass("java/sql/PreparedStatement"); OSL_ENSHURE(tempClass,"Java : FindClass nicht erfolgreich!"); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} +// ------------------------------------------------------------------------- + +void java_sql_PreparedStatement::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==0 ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} +// ------------------------------------------------------------------------- + +::com::sun::star::uno::Any SAL_CALL java_sql_PreparedStatement::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = OStatement_BASE2::queryInterface(rType); + if(!aRet.hasValue()) + aRet = ::cppu::queryInterface( rType, + static_cast< XPreparedStatement*>(this), + static_cast< XParameters*>(this), + static_cast< XPreparedBatchExecution*>(this)); + return aRet; +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL java_sql_PreparedStatement::getTypes( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< XPreparedStatement > *)0 ), + ::getCppuType( (const ::com::sun::star::uno::Reference< XParameters > *)0 ), + ::getCppuType( (const ::com::sun::star::uno::Reference< XPreparedBatchExecution > *)0 )); + + return ::utl::concatSequences(aTypes.getTypes(),OStatement_BASE2::getTypes()); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL java_sql_PreparedStatement::execute( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "execute"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL java_sql_PreparedStatement::executeUpdate( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "executeUpdate"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_PreparedStatement::setString( sal_Int32 parameterIndex, const ::rtl::OUString& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[2]; + // Parameter konvertieren + args[0].i = parameterIndex; + args[1].l = convertwchar_tToJavaString(t.pEnv,x); + // temporaere Variable initialisieren + char * cSignature = "(ILjava/lang/String;)V"; + char * cMethodName = "setString"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID, args[0].i,args[1].l); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + t.pEnv->DeleteLocalRef((jstring)args[1].l); + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + +::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL java_sql_PreparedStatement::getConnection( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ +// jobject out(0); +// SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); +// if( t.pEnv ){ +// +// // temporaere Variable initialisieren +// char * cSignature = "()Ljava/sql/Connection;"; +// char * cMethodName = "getConnection"; +// // Java-Call absetzen +// jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); +// if( mID ){ +// out = t.pEnv->CallObjectMethod( object, mID); +// ThrowSQLException(t.pEnv,*this); +// } //mID +// } //t.pEnv +// // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! +// return out==0 ? 0 : new java_sql_Connection( t.pEnv, out ); + return (Reference< XConnection >)m_pConnection; +} +// ------------------------------------------------------------------------- + +::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL java_sql_PreparedStatement::executeQuery( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Ljava/sql/ResultSet;"; + char * cMethodName = "executeQuery"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_ResultSet( t.pEnv, out ); +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_PreparedStatement::setBoolean( sal_Int32 parameterIndex, sal_Bool x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[2]; + // Parameter konvertieren + args[0].i = (sal_Int32)parameterIndex; + args[1].z = x; + // temporaere Variable initialisieren + char * cSignature = "(IZ)V"; + char * cMethodName = "setBoolean"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID, args[0].i,args[1].z); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_PreparedStatement::setByte( sal_Int32 parameterIndex, sal_Int8 x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[2]; + // Parameter konvertieren + args[0].i = (sal_Int32)parameterIndex; + args[1].b = x; + // temporaere Variable initialisieren + char * cSignature = "(IB)V"; + char * cMethodName = "setByte"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID, args[0].i,args[1].b); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_PreparedStatement::setDate( sal_Int32 parameterIndex, const ::com::sun::star::util::Date& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[2]; + // Parameter konvertieren + args[0].i = parameterIndex; + java_sql_Date aT(x); + args[1].l = aT.getJavaObject(); + // temporaere Variable initialisieren + char * cSignature = "(ILjava/sql/Date;)V"; + char * cMethodName = "setDate"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID, args[0].i,args[1].l); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + + +void SAL_CALL java_sql_PreparedStatement::setTime( sal_Int32 parameterIndex, const ::com::sun::star::util::Time& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[2]; + // Parameter konvertieren + args[0].i = (sal_Int32)parameterIndex; + java_sql_Time aT(x); + args[1].l = aT.getJavaObject(); + // temporaere Variable initialisieren + char * cSignature = "(ILjava/sql/Time;)V"; + char * cMethodName = "setTime"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID, args[0].i,args[1].l); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_PreparedStatement::setTimestamp( sal_Int32 parameterIndex, const ::com::sun::star::util::DateTime& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[2]; + // Parameter konvertieren + args[0].i = (sal_Int32)parameterIndex; + java_sql_Timestamp aT(x); + args[1].l = aT.getJavaObject(); + // temporaere Variable initialisieren + char * cSignature = "(ILjava/sql/Timestamp;)V"; + char * cMethodName = "setTimestamp"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID, args[0].i,args[1].l); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + + + +void SAL_CALL java_sql_PreparedStatement::setDouble( sal_Int32 parameterIndex, double x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[2]; + // Parameter konvertieren + args[0].i = (sal_Int32)parameterIndex; + args[1].d = x; + // temporaere Variable initialisieren + char * cSignature = "(ID)V"; + char * cMethodName = "setDouble"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID, args[0].i,args[1].d); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_PreparedStatement::setFloat( sal_Int32 parameterIndex, float x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[2]; + // Parameter konvertieren + args[0].i = (sal_Int32)parameterIndex; + args[1].f = x; + // temporaere Variable initialisieren + char * cSignature = "(IF)V"; + char * cMethodName = "setFloat"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ +t.pEnv->CallVoidMethod( object, mID, args[0].i,args[1].f); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_PreparedStatement::setInt( sal_Int32 parameterIndex, sal_Int32 x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[2]; + // Parameter konvertieren + args[0].i = (sal_Int32)parameterIndex; + args[1].i = (sal_Int32)x; + // temporaere Variable initialisieren + char * cSignature = "(II)V"; + char * cMethodName = "setInt"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID, args[0].i,args[1].i); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_PreparedStatement::setLong( sal_Int32 parameterIndex, sal_Int64 x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[2]; + // Parameter konvertieren + args[0].i = (sal_Int32)parameterIndex; + args[1].j = x; + // temporaere Variable initialisieren + char * cSignature = "(IJ)V"; + char * cMethodName = "setLong"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ +t.pEnv->CallVoidMethod( object, mID, args[0].i,args[1].j); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_PreparedStatement::setNull( sal_Int32 parameterIndex, sal_Int32 sqlType ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[2]; + // Parameter konvertieren + args[0].i = (sal_Int32)parameterIndex; + args[1].i = (sal_Int32)sqlType; + // temporaere Variable initialisieren + char * cSignature = "(II)V"; + char * cMethodName = "setNull"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID, args[0].i,args[1].i); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_PreparedStatement::setClob( sal_Int32 parameterIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XClob >& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[2]; + // Parameter konvertieren + args[0].i = (sal_Int32)parameterIndex; + args[1].l = 0; + // temporaere Variable initialisieren + char * cSignature = "(ILjava/sql/Clob;)V"; + char * cMethodName = "setClob"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID, args[0].i,args[1].l); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_PreparedStatement::setBlob( sal_Int32 parameterIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XBlob >& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[2]; + // Parameter konvertieren + args[0].i = (sal_Int32)parameterIndex; + args[1].l = 0; + // temporaere Variable initialisieren + char * cSignature = "(ILjava/sql/Blob;)V"; + char * cMethodName = "setBlob"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID, args[0].i,args[1].l); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_PreparedStatement::setArray( sal_Int32 parameterIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XArray >& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[2]; + // Parameter konvertieren + args[0].i = (sal_Int32)parameterIndex; + args[1].l = 0; + // temporaere Variable initialisieren + char * cSignature = "(ILjava/sql/Array;)V"; + char * cMethodName = "setArray"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID, args[0].i,args[1].l); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_PreparedStatement::setRef( sal_Int32 parameterIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRef >& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[2]; + // Parameter konvertieren + args[0].i = (sal_Int32)parameterIndex; + args[1].l = 0; + // temporaere Variable initialisieren + char * cSignature = "(ILjava/sql/Ref;)V"; + char * cMethodName = "setRef"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID, args[0].i,args[1].l); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_PreparedStatement::setObjectWithInfo( sal_Int32 parameterIndex, const ::com::sun::star::uno::Any& x, sal_Int32 targetSqlType, sal_Int32 scale ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[2]; + // Parameter konvertieren + args[0].i = (sal_Int32)parameterIndex; + args[1].l = 0; + // temporaere Variable initialisieren + char * cSignature = "(ILjava/lang/Object;II)V"; + char * cMethodName = "setObject"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID, args[0].i,args[1].l,targetSqlType,scale); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_PreparedStatement::setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& typeName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[2]; + // Parameter konvertieren + args[0].i = (sal_Int32)parameterIndex; + args[1].l = 0; + // temporaere Variable initialisieren + char * cSignature = "(ILjava/lang/Object;)V"; + char * cMethodName = "setObject"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID, args[0].i,args[1].l); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_PreparedStatement::setObject( sal_Int32 parameterIndex, const ::com::sun::star::uno::Any& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[2]; + // Parameter konvertieren + args[0].i = (sal_Int32)parameterIndex; + args[1].l = 0; + // temporaere Variable initialisieren + char * cSignature = "(ILjava/lang/Object;)V"; + char * cMethodName = "setObject"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID, args[0].i,args[1].l); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_PreparedStatement::setShort( sal_Int32 parameterIndex, sal_Int16 x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[2]; + // Parameter konvertieren + args[0].i = (sal_Int32)parameterIndex; + args[1].s = (sal_Int16)x; + // temporaere Variable initialisieren + char * cSignature = "(IS)V"; + char * cMethodName = "setShort"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID, args[0].i,args[1].s); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_PreparedStatement::setBytes( sal_Int32 parameterIndex, const ::com::sun::star::uno::Sequence< sal_Int8 >& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[2]; + // Parameter konvertieren + args[0].i = (sal_Int32)parameterIndex; + jbyteArray pByteArray = t.pEnv->NewByteArray(x.getLength()); + t.pEnv->SetByteArrayRegion(pByteArray,0,x.getLength(),(jbyte*)x.getConstArray()); + args[1].l = pByteArray; + // temporaere Variable initialisieren + char * cSignature = "(I[B)V"; + char * cMethodName = "setBytes"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID, args[0].i,args[1].l); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + t.pEnv->DeleteLocalRef(pByteArray); + } //t.pEnv +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_PreparedStatement::setCharacterStream( sal_Int32 parameterIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + jvalue args2[3]; + jbyteArray pByteArray = t.pEnv->NewByteArray(length); + Sequence< sal_Int8> aSeq; + x->readBytes(aSeq,length); + t.pEnv->SetByteArrayRegion(pByteArray,0,length,(jbyte*)aSeq.getConstArray()); + args2[0].l = pByteArray; + args2[1].i = 0; + args2[2].i = (sal_Int32)length; + + // temporaere Variable initialisieren + char * cSignatureStream = "([BII)V"; + // Java-Call absetzen + jclass aClass = t.pEnv->FindClass("java/io/CharArrayInputStream"); + jmethodID mID2 = t.pEnv->GetMethodID( aClass, "<init>", cSignatureStream ); + jobject tempObj = NULL; + if(mID2) + tempObj = t.pEnv->NewObjectA( aClass, mID2, args2 ); + + // + jvalue args[1]; + // Parameter konvertieren + args[0].i = (sal_Int32)parameterIndex; + // temporaere Variable initialisieren + char * cSignature = "(ILjava/io/InputStream;I)V"; + char * cMethodName = "setCharacterStream"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + t.pEnv->CallVoidMethod( object, mID, args[0].i,tempObj,length); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + t.pEnv->DeleteLocalRef(pByteArray); + t.pEnv->DeleteLocalRef(tempObj); + t.pEnv->DeleteLocalRef(aClass); + } //t.pEnv +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_PreparedStatement::setBinaryStream( sal_Int32 parameterIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + jvalue args2[3]; + jbyteArray pByteArray = t.pEnv->NewByteArray(length); + Sequence< sal_Int8> aSeq; + x->readBytes(aSeq,length); + t.pEnv->SetByteArrayRegion(pByteArray,0,length,(jbyte*)aSeq.getConstArray()); + args2[0].l = pByteArray; + args2[1].i = 0; + args2[2].i = (sal_Int32)length; + + // temporaere Variable initialisieren + char * cSignatureStream = "([BII)V"; + // Java-Call absetzen + jclass aClass = t.pEnv->FindClass("java/io/ByteArrayInputStream"); + jmethodID mID2 = t.pEnv->GetMethodID( aClass, "<init>", cSignatureStream ); + jobject tempObj = NULL; + if(mID2) + tempObj = t.pEnv->NewObjectA( aClass, mID2, args2 ); + + // + jvalue args[1]; + // Parameter konvertieren + args[0].i = (sal_Int32)parameterIndex; + // temporaere Variable initialisieren + char * cSignature = "(ILjava/io/InputStream;I)V"; + char * cMethodName = "setBinaryStream"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + t.pEnv->CallVoidMethod( object, mID, args[0].i,tempObj,(sal_Int32)length); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + t.pEnv->DeleteLocalRef(pByteArray); + t.pEnv->DeleteLocalRef(tempObj); + t.pEnv->DeleteLocalRef(aClass); + } //t.pEnv +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_PreparedStatement::clearParameters( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()V"; + char * cMethodName = "clearParameters"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- +void SAL_CALL java_sql_PreparedStatement::clearBatch( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()V"; + char * cMethodName = "clearBatch"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_PreparedStatement::addBatch( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "()V"; + char * cMethodName = "addBatch"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + +::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL java_sql_PreparedStatement::executeBatch( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Sequence< sal_Int32 > aSeq; + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "()[I"; + char * cMethodName = "executeBatch"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + jintArray out = (jintArray)t.pEnv->CallObjectMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + if(out) + { + jboolean p = sal_False; + aSeq.realloc(t.pEnv->GetArrayLength(out)); + memcpy(aSeq.getArray(),t.pEnv->GetIntArrayElements(out,&p),aSeq.getLength()); + t.pEnv->DeleteLocalRef(out); + } + } //mID + } //t.pEnv + return aSeq; +} +// ------------------------------------------------------------------------- + + diff --git a/connectivity/source/drivers/jdbc/Reader.cxx b/connectivity/source/drivers/jdbc/Reader.cxx new file mode 100644 index 000000000000..11ba4fa816e2 --- /dev/null +++ b/connectivity/source/drivers/jdbc/Reader.cxx @@ -0,0 +1,187 @@ +/************************************************************************* + * + * $RCSfile: Reader.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_JAVA_IO_READER_HXX_ +#include "java/io/Reader.hxx" +#endif +#ifndef _INC_MEMORY +#include <memory.h> +#endif +using namespace connectivity; +//************************************************************** +//************ Class: java.io.Reader +//************************************************************** + +jclass java_io_Reader::theClass = 0; + +java_io_Reader::~java_io_Reader() +{} + +jclass java_io_Reader::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; + if( !t.pEnv ) return (jclass)NULL; + jclass tempClass = t.pEnv->FindClass( "java/io/Reader" ); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} + +void java_io_Reader::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==NULL ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} + +sal_Int32 SAL_CALL java_io_Reader::readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) +{ + return readBytes(aData,nMaxBytesToRead); +} + +void SAL_CALL java_io_Reader::skipBytes( sal_Int32 nBytesToSkip ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + char * cSignature = "(I)I"; + char * cMethodName = "skip"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + out = t.pEnv->CallIntMethod( object, mID,nBytesToSkip); + ThrowSQLException(t.pEnv,*this); + } + } //t.pEnv +} + +sal_Int32 SAL_CALL java_io_Reader::available( ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + char * cSignature = "()Z"; + char * cMethodName = "available"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } + } //t.pEnv + return out; +} +void SAL_CALL java_io_Reader::closeInput( ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + char * cSignature = "()V"; + char * cMethodName = "close"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + t.pEnv->CallVoidMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } + } //t.pEnv +} +// ----------------------------------------------------- +sal_Int32 SAL_CALL java_io_Reader::readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) +{ + OSL_ENSHURE(aData.getLength() < nBytesToRead," Sequence is smaller than BytesToRead"); + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + jcharArray pCharArray = t.pEnv->NewCharArray(nBytesToRead); + char * cSignature = "([CII)I"; + char * cMethodName = "read"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + while(!(out = t.pEnv->CallIntMethod( object, mID,pCharArray,0,nBytesToRead))) + ThrowSQLException(t.pEnv,*this); + if(out > 0) + { + jboolean p = sal_False; + if(aData.getLength() < out) + aData.realloc(out-aData.getLength()); + + memcpy(aData.getArray(),t.pEnv->GetCharArrayElements(pCharArray,&p),out); + } + } + t.pEnv->DeleteLocalRef((jcharArray)pCharArray); + } //t.pEnv + return out; +} + diff --git a/connectivity/source/drivers/jdbc/Ref.cxx b/connectivity/source/drivers/jdbc/Ref.cxx new file mode 100644 index 000000000000..50d9c39bb548 --- /dev/null +++ b/connectivity/source/drivers/jdbc/Ref.cxx @@ -0,0 +1,121 @@ +/************************************************************************* + * + * $RCSfile: Ref.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_JAVA_SQL_REF_HXX_ +#include "java/sql/Ref.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_ +#include "java/tools.hxx" +#endif +using namespace connectivity; +//************************************************************** +//************ Class: java.sql.Ref +//************************************************************** + +jclass java_sql_Ref::theClass = 0; + +java_sql_Ref::~java_sql_Ref() +{} + +jclass java_sql_Ref::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; + if( !t.pEnv ) return (jclass)NULL; + jclass tempClass = t.pEnv->FindClass( "java/sql/Ref" ); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} + +void java_sql_Ref::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==NULL ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} + +::rtl::OUString SAL_CALL java_sql_Ref::getBaseTypeName( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + ::rtl::OUString aStr; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getBaseTypeName"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + jstring out = (jstring)t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} + diff --git a/connectivity/source/drivers/jdbc/ResultSet.cxx b/connectivity/source/drivers/jdbc/ResultSet.cxx new file mode 100644 index 000000000000..94bd7aa197b4 --- /dev/null +++ b/connectivity/source/drivers/jdbc/ResultSet.cxx @@ -0,0 +1,1842 @@ +/************************************************************************* + * + * $RCSfile: ResultSet.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_JAVA_SQL_RESULTSET_HXX_ +#include "java/sql/ResultSet.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_STATEMENT_HXX_ +#include "java/sql/Statement.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_SQLWARNING_HXX_ +#include "java/sql/SQLWarning.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_ARRAY_HXX_ +#include "java/sql/Array.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_REF_HXX_ +#include "java/sql/Ref.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_CLOB_HXX_ +#include "java/sql/Clob.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_TIMESTAMP_HXX_ +#include "java/sql/Timestamp.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_BLOB_HXX_ +#include "java/sql/Blob.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_SQL_RESULTSETMETADATA_HXX_ +#include "java/sql/ResultSetMetaData.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_IO_INPUTSTREAM_HXX_ +#include "java/io/InputStream.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_ +#include "java/tools.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +#ifndef _UTL_PROPERTY_HXX_ +#include <unotools/property.hxx> +#endif +#ifndef _CONNECTIVITY_COMMONTOOLS_HXX_ +#include "connectivity/CommonTools.hxx" +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif + + +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; +using namespace ::com::sun::star::lang; + +IMPLEMENT_SERVICE_INFO(java_sql_ResultSet,"com.sun.star.sdbcx.JResultSet","com.sun.star.sdbc.ResultSet"); +//************************************************************** +//************ Class: java.sql.ResultSet +//************************************************************** + +jclass java_sql_ResultSet::theClass = 0; + +java_sql_ResultSet::~java_sql_ResultSet() +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + char * cSignature = "()V"; + char * cMethodName = "close"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + t.pEnv->CallVoidMethod( object, mID); + } +} + +jclass java_sql_ResultSet::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( !t.pEnv ) return (jclass)0; + jclass tempClass = t.pEnv->FindClass("java/sql/ResultSet"); OSL_ENSHURE(tempClass,"Java : FindClass nicht erfolgreich!"); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} + +void java_sql_ResultSet::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==0 ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} +// ------------------------------------------------------------------------- +void java_sql_ResultSet::disposing(void) +{ + OPropertySetHelper::disposing(); + + ::osl::MutexGuard aGuard(m_aMutex); + m_xMetaData = NULL; +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Any SAL_CALL java_sql_ResultSet::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = OPropertySetHelper::queryInterface(rType); + if(!aRet.hasValue()) + aRet = java_sql_ResultSet_BASE::queryInterface(rType); + return aRet; +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL java_sql_ResultSet::getTypes( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ), + ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ), + ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > *)0 )); + + return ::utl::concatSequences(aTypes.getTypes(),java_sql_ResultSet_BASE::getTypes()); +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL java_sql_ResultSet::findColumn( const ::rtl::OUString& columnName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[1]; + // Parameter konvertieren + args[0].l = convertwchar_tToJavaString(t.pEnv,columnName); + // temporaere Variable initialisieren + char * cSignature = "(Ljava/lang/String;)I"; + char * cMethodName = "findColumn"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID, args[0].l ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + t.pEnv->DeleteLocalRef((jstring)args[0].l); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- + + +Reference< ::com::sun::star::io::XInputStream > SAL_CALL java_sql_ResultSet::getBinaryStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/io/InputStream;"; + char * cMethodName = "getBinaryStream"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, columnIndex); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_io_InputStream( t.pEnv, out ); +} +// ------------------------------------------------------------------------- +Reference< ::com::sun::star::io::XInputStream > SAL_CALL java_sql_ResultSet::getCharacterStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/io/InputStream;"; + char * cMethodName = "getCharacterStream"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, columnIndex); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_io_InputStream( t.pEnv, out ); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL java_sql_ResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "getBoolean"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID, columnIndex ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- + +sal_Int8 SAL_CALL java_sql_ResultSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + jbyte out; + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)B"; + char * cMethodName = "getByte"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallByteMethod( object, mID, columnIndex); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- + +Sequence< sal_Int8 > SAL_CALL java_sql_ResultSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + Sequence< sal_Int8 > aSeq; + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + char * cSignature = "(I)[B"; + char * cMethodName = "getBytes"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + jbyteArray out = (jbyteArray)t.pEnv->CallObjectMethod( object, mID, columnIndex); + ThrowSQLException(t.pEnv,*this); + if (out) + { + jboolean p = sal_False; + aSeq.realloc(t.pEnv->GetArrayLength(out)); + memcpy(aSeq.getArray(),t.pEnv->GetByteArrayElements(out,&p),aSeq.getLength()); + t.pEnv->DeleteLocalRef(out); + } + // und aufraeumen + } //mID + } //t.pEnv + return aSeq; +} +// ------------------------------------------------------------------------- + +::com::sun::star::util::Date SAL_CALL java_sql_ResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/sql/Date;"; + char * cMethodName = "getDate"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, columnIndex ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return java_sql_Date( t.pEnv, out ); +} +// ------------------------------------------------------------------------- + +double SAL_CALL java_sql_ResultSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + jdouble out; + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)D"; + char * cMethodName = "getDouble"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallDoubleMethod( object, mID, columnIndex); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- + +float SAL_CALL java_sql_ResultSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + jfloat out; + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)F"; + char * cMethodName = "getFloat"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallFloatMethod( object, mID, columnIndex ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL java_sql_ResultSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)I"; + char * cMethodName = "getInt"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID, columnIndex ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL java_sql_ResultSet::getRow( ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getRow"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- + +sal_Int64 SAL_CALL java_sql_ResultSet::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + jlong out; + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)J"; + char * cMethodName = "getLong"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallLongMethod( object, mID, columnIndex ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- + +::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData > SAL_CALL java_sql_ResultSet::getMetaData( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + + { + // temporaere Variable initialisieren + char * cSignature = "()Ljava/sql/ResultSetMetaData;"; + char * cMethodName = "getMetaData"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_ResultSetMetaData( t.pEnv, out ); +} +// ------------------------------------------------------------------------- +Reference< XArray > SAL_CALL java_sql_ResultSet::getArray( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/sql/Ref;"; + char * cMethodName = "getArray"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, columnIndex); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_Array( t.pEnv, out ); +} +// ------------------------------------------------------------------------- + +Reference< XClob > SAL_CALL java_sql_ResultSet::getClob( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/sql/Ref;"; + char * cMethodName = "getClob"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, columnIndex); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_Clob( t.pEnv, out ); +} +// ------------------------------------------------------------------------- +Reference< XBlob > SAL_CALL java_sql_ResultSet::getBlob( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/sql/Ref;"; + char * cMethodName = "getBlob"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, columnIndex); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_Blob( t.pEnv, out ); +} +// ------------------------------------------------------------------------- + +Reference< XRef > SAL_CALL java_sql_ResultSet::getRef( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/sql/Ref;"; + char * cMethodName = "getRef"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, columnIndex); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? 0 : new java_sql_Ref( t.pEnv, out ); +} +// ------------------------------------------------------------------------- + +Any SAL_CALL java_sql_ResultSet::getObject( sal_Int32 columnIndex, const Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[2]; + // Parameter konvertieren + args[0].i = (sal_Int32)columnIndex; + args[1].l = XNameAccess2Map(t.pEnv,typeMap); + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/lang/Object;"; + char * cMethodName = "getObject"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethodA( object, mID, args); + ThrowSQLException(t.pEnv,*this); + t.pEnv->DeleteLocalRef((jstring)args[1].l); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out==0 ? Any() : Any();//new java_lang_Object( t.pEnv, out ); +} +// ------------------------------------------------------------------------- + +sal_Int16 SAL_CALL java_sql_ResultSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + jshort out; + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)S"; + char * cMethodName = "getShort"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallShortMethod( object, mID, columnIndex); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return (sal_Int16)out; +} +// ------------------------------------------------------------------------- + + +::rtl::OUString SAL_CALL java_sql_ResultSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + jstring out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + ::rtl::OUString aStr; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/lang/String;"; + char * cMethodName = "getString"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = (jstring)t.pEnv->CallObjectMethod( object, mID, columnIndex ); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} +// ------------------------------------------------------------------------- + + +::com::sun::star::util::Time SAL_CALL java_sql_ResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/sql/Time;"; + char * cMethodName = "getTime"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, columnIndex); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return java_sql_Time( t.pEnv, out ); +} +// ------------------------------------------------------------------------- + + +::com::sun::star::util::DateTime SAL_CALL java_sql_ResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + jobject out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[1]; + // Parameter konvertieren + args[0].i = (sal_Int32)columnIndex; + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/sql/Timestamp;"; + char * cMethodName = "getTimestamp"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID, args[0].i); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return java_sql_Timestamp( t.pEnv, out ); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL java_sql_ResultSet::isAfterLast( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + + { + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "isAfterLast"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_ResultSet::isFirst( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + + { + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "isFirst"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_ResultSet::isLast( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + + { + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "isLast"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +void SAL_CALL java_sql_ResultSet::beforeFirst( ) throw(SQLException, RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + + { + // temporaere Variable initialisieren + char * cSignature = "()V"; + char * cMethodName = "isBeforeFirst"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- +void SAL_CALL java_sql_ResultSet::afterLast( ) throw(SQLException, RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + + { + // temporaere Variable initialisieren + char * cSignature = "()V"; + char * cMethodName = "afterLast"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_ResultSet::close( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()V"; + char * cMethodName = "close"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL java_sql_ResultSet::first( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "first"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL java_sql_ResultSet::last( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "last"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_ResultSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "absolute"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID,row); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_ResultSet::relative( sal_Int32 row ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "relative"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID,row); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_ResultSet::previous( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + + { + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "previous"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +Reference< XInterface > SAL_CALL java_sql_ResultSet::getStatement( ) throw(SQLException, RuntimeException) +{ +// jobject out(0); +// SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); +// if( t.pEnv ) +// { +// // temporaere Variable initialisieren +// char * cSignature = "()Ljava/sql/Statement;"; +// char * cMethodName = "getStatement"; +// // Java-Call absetzen +// jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); +// if( mID ){ +// out = t.pEnv->CallObjectMethod( object, mID ); +// ThrowSQLException(t.pEnv,*this); +// } //mID +// } //t.pEnv +// // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! +// return out==0 ? 0 : (::cppu::OWeakObject*)new java_sql_Statement( t.pEnv, out ); + return m_aStatement.get(); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL java_sql_ResultSet::rowDeleted( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "rowDeleted"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_ResultSet::rowInserted( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "rowInserted"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_ResultSet::rowUpdated( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "rowUpdated"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL java_sql_ResultSet::isBeforeFirst( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "isBeforeFirst"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL java_sql_ResultSet::next( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + + { + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "next"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL java_sql_ResultSet::wasNull( ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()Z"; + char * cMethodName = "wasNull"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_ResultSet::cancel( ) throw(::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()V"; + char * cMethodName = "cancel"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID ); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv +} +// ------------------------------------------------------------------------- +// ------------------------------------------------------------------------- +void SAL_CALL java_sql_ResultSet::clearWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()V"; + char * cMethodName = "clearWarnings"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } + } +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Any SAL_CALL java_sql_ResultSet::getWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jobject out(NULL); + SDBThreadAttach t; + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()Ljava/sql/SQLWarning;"; + char * cMethodName = "getWarnings"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out ? makeAny(java_sql_SQLWarning(java_sql_SQLWarning_BASE( t.pEnv, out ),*this)) : ::com::sun::star::uno::Any(); +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_ResultSet::insertRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()V"; + char * cMethodName = "insertRow"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } + } +} +// ------------------------------------------------------------------------- +void SAL_CALL java_sql_ResultSet::updateRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()V"; + char * cMethodName = "updateRow"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } + } +} +// ------------------------------------------------------------------------- +void SAL_CALL java_sql_ResultSet::deleteRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()V"; + char * cMethodName = "deleteRow"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } + } +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_ResultSet::cancelRowUpdates( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()V"; + char * cMethodName = "cancelRowUpdates"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } + } +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_ResultSet::moveToInsertRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()V"; + char * cMethodName = "moveToInsertRow"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } + } +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_ResultSet::moveToCurrentRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()V"; + char * cMethodName = "moveToCurrentRow"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } + } +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_ResultSet::updateNull( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(I)V"; + char * cMethodName = "updateNull"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID,columnIndex); + ThrowSQLException(t.pEnv,*this); + } + } +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_ResultSet::updateBoolean( sal_Int32 columnIndex, sal_Bool x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(IZ)V"; + char * cMethodName = "updateNull"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID,columnIndex,x); + ThrowSQLException(t.pEnv,*this); + } + } +} +// ------------------------------------------------------------------------- +void SAL_CALL java_sql_ResultSet::updateByte( sal_Int32 columnIndex, sal_Int8 x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(IB)V"; + char * cMethodName = "updateByte"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID,columnIndex,x); + ThrowSQLException(t.pEnv,*this); + } + } +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_ResultSet::updateShort( sal_Int32 columnIndex, sal_Int16 x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(IS)V"; + char * cMethodName = "updateShort"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID,columnIndex,x); + ThrowSQLException(t.pEnv,*this); + } + } +} +// ------------------------------------------------------------------------- +void SAL_CALL java_sql_ResultSet::updateInt( sal_Int32 columnIndex, sal_Int32 x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(II)V"; + char * cMethodName = "updateInt"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID,columnIndex,x); + ThrowSQLException(t.pEnv,*this); + } + } +} +// ------------------------------------------------------------------------- +void SAL_CALL java_sql_ResultSet::updateLong( sal_Int32 columnIndex, sal_Int64 x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(IJ)V"; + char * cMethodName = "updateLong"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID,columnIndex,x); + ThrowSQLException(t.pEnv,*this); + } + } +} +// ------------------------------------------------------------------------- + +// ----------------------------------------------------------------------- +void SAL_CALL java_sql_ResultSet::updateFloat( sal_Int32 columnIndex, float x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(IF)V"; + char * cMethodName = "updateFloat"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID,columnIndex,x); + ThrowSQLException(t.pEnv,*this); + } + } +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_ResultSet::updateDouble( sal_Int32 columnIndex, double x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "(ID)V"; + char * cMethodName = "updateDouble"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID,columnIndex,x); + ThrowSQLException(t.pEnv,*this); + } + } +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_ResultSet::updateString( sal_Int32 columnIndex, const ::rtl::OUString& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + jvalue args[1]; + // Parameter konvertieren + args[0].l = convertwchar_tToJavaString(t.pEnv,x); + // temporaere Variable initialisieren + char * cSignature = "(ILjava/lang/String)V"; + char * cMethodName = "updateString"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID,columnIndex,args[0].l); + ThrowSQLException(t.pEnv,*this); + t.pEnv->DeleteLocalRef((jstring)args[0].l); + } + } +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_ResultSet::updateBytes( sal_Int32 columnIndex, const ::com::sun::star::uno::Sequence< sal_Int8 >& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + jvalue args[1]; + jbyteArray aArray = t.pEnv->NewByteArray(x.getLength()); + t.pEnv->SetByteArrayRegion(aArray,0,x.getLength(),(jbyte*)x.getConstArray()); + + // Parameter konvertieren + args[0].l = aArray; + // temporaere Variable initialisieren + char * cSignature = "(I[B)V"; + char * cMethodName = "updateBytes"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID,columnIndex,args[0].l); + ThrowSQLException(t.pEnv,*this); + t.pEnv->DeleteLocalRef((jbyteArray)args[0].l); + } + } +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_ResultSet::updateDate( sal_Int32 columnIndex, const ::com::sun::star::util::Date& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + jvalue args[1]; + // Parameter konvertieren + java_sql_Date aD(x); + args[0].l = aD.getJavaObject(); + // temporaere Variable initialisieren + char * cSignature = "(ILjava/sql/Date;)V"; + char * cMethodName = "updateDate"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID,columnIndex,args[0].l); + ThrowSQLException(t.pEnv,*this); + } + } +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_ResultSet::updateTime( sal_Int32 columnIndex, const ::com::sun::star::util::Time& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + jvalue args[1]; + // Parameter konvertieren + java_sql_Time aD(x); + args[0].l = aD.getJavaObject(); + // temporaere Variable initialisieren + char * cSignature = "(ILjava/sql/Time;)V"; + char * cMethodName = "updateTime"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID,columnIndex,args[0].l); + ThrowSQLException(t.pEnv,*this); + } + } +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_ResultSet::updateTimestamp( sal_Int32 columnIndex, const ::com::sun::star::util::DateTime& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + jvalue args[1]; + java_sql_Timestamp aD(x); + // Parameter konvertieren + args[0].l = aD.getJavaObject(); + // temporaere Variable initialisieren + char * cSignature = "(I;Ljava/sql/Timestamp;)V"; + char * cMethodName = "updateTimestamp"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID,columnIndex,args[0].l); + ThrowSQLException(t.pEnv,*this); + } + } +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_ResultSet::updateBinaryStream( sal_Int32 columnIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + jvalue args[1]; + // Parameter konvertieren + args[0].l = 0; + // temporaere Variable initialisieren + char * cSignature = "(ILjava/io/InputStream;I)V"; + char * cMethodName = "updateBinaryStream"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID,columnIndex,args[0].l,length); + ThrowSQLException(t.pEnv,*this); + t.pEnv->DeleteLocalRef((jobject)args[0].l); + } + } +} +// ------------------------------------------------------------------------- +void SAL_CALL java_sql_ResultSet::updateCharacterStream( sal_Int32 columnIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + jvalue args[1]; + // Parameter konvertieren + args[0].l = 0; + // temporaere Variable initialisieren + char * cSignature = "(ILjava/io/InputStream;I)V"; + char * cMethodName = "updateCharacterStream"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID,columnIndex,args[0].l,length); + ThrowSQLException(t.pEnv,*this); + t.pEnv->DeleteLocalRef((jobject)args[0].l); + } + } +} +// ------------------------------------------------------------------------- +void SAL_CALL java_sql_ResultSet::updateObject( sal_Int32 columnIndex, const ::com::sun::star::uno::Any& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; + if( t.pEnv ) + { + jvalue args[1]; + switch(x.getValueTypeClass()) + { + case TypeClass_VOID: + args[0].l = NULL; + break; + + case TypeClass_BOOLEAN: + { + sal_Bool f; + x >>= f; + updateBoolean(columnIndex,f); + } + break; + case TypeClass_BYTE: + { + sal_Int8 f; + x >>= f; + updateByte(columnIndex,f); + } + break; + case TypeClass_SHORT: + case TypeClass_UNSIGNED_SHORT: + { + sal_Int16 f; + x >>= f; + updateShort(columnIndex,f); + } + break; + case TypeClass_LONG: + case TypeClass_UNSIGNED_LONG: + { + sal_Int32 f; + x >>= f; + updateInt(columnIndex,f); + } + break; + case TypeClass_HYPER: + case TypeClass_UNSIGNED_HYPER: + { + sal_Int64 f; + x >>= f; + updateLong(columnIndex,f); + } + break; + case TypeClass_FLOAT: + { + float f; + x >>= f; + updateFloat(columnIndex,f); + } + break; + case TypeClass_DOUBLE: + updateDouble(columnIndex,connectivity::getDouble(x)); + break; + case TypeClass_CHAR: + case TypeClass_STRING: + updateString(columnIndex,connectivity::getString(x)); + break; + case TypeClass_ENUM: + default: + OSL_ENSHURE(0,"UNKOWN TYPE for java_sql_ResultSet::updateObject"); + } + return; + // Parameter konvertieren + // temporaere Variable initialisieren + char * cSignature = "(ILjava/lang/Object;)V"; + char * cMethodName = "updateObject"; + // Java-Call absetzen +// jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); +// if( mID ){ +// t.pEnv->CallVoidMethodA( object, mID,columnIndex,args); + ThrowSQLException(t.pEnv,*this); +// switch(x.getValueTypeClass()) +// { +// case TypeClass_CHAR: +// case TypeClass_STRING: +// t.pEnv->DeleteLocalRef((jobject)args[0].l); +// break; +// } +// } + } +} +// ------------------------------------------------------------------------- + +void SAL_CALL java_sql_ResultSet::updateNumericObject( sal_Int32 columnIndex, const ::com::sun::star::uno::Any& x, sal_Int32 scale ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + OSL_ENSHURE(0,"java_sql_ResultSet::updateNumericObject: NYI"); +// SDBThreadAttach t; +// if( t.pEnv ) +// { +// jvalue args[1]; +// // Parameter konvertieren +// args[0].l = +// // temporaere Variable initialisieren +// char * cSignature = "(I;Ljava/lang/Object;I)V"; +// char * cMethodName = "updateObject"; +// // Java-Call absetzen +// jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); +// if( mID ){ +// t.pEnv->CallVoidMethod( object, mID,columnIndex,args[0].l,scale); + // ThrowSQLException(t.pEnv,*this); +// t.pEnv->DeleteLocalRef((jobject)args[0].l); +// } +// } +} +// ------------------------------------------------------------------------- +//------------------------------------------------------------------------------ +sal_Int32 java_sql_ResultSet::getResultSetConcurrency() const throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getResultSetConcurrency"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*(::cppu::OWeakObject*)this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +//------------------------------------------------------------------------------ +sal_Int32 java_sql_ResultSet::getResultSetType() const throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getResultSetType"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*(::cppu::OWeakObject*)this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +//------------------------------------------------------------------------------ +sal_Int32 java_sql_ResultSet::getFetchDirection() const throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getFetchDirection"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*(::cppu::OWeakObject*)this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +//------------------------------------------------------------------------------ +sal_Int32 java_sql_ResultSet::getFetchSize() const throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getFetchSize"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*(::cppu::OWeakObject*)this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +//------------------------------------------------------------------------------ +::rtl::OUString java_sql_ResultSet::getCursorName() const throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + ::rtl::OUString aStr; + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getCursorName"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + jstring out = (jstring)t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,*(::cppu::OWeakObject*)this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} + +//------------------------------------------------------------------------------ +void java_sql_ResultSet::setFetchDirection(sal_Int32 _par0) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)V"; + char * cMethodName = "setFetchDirection"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID,_par0); + ThrowSQLException(t.pEnv,*(::cppu::OWeakObject*)this); + } //mID + } //t.pEnv + +} +//------------------------------------------------------------------------------ +void SAL_CALL java_sql_ResultSet::refreshRow( ) throw(SQLException, RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ) + { + // temporaere Variable initialisieren + char * cSignature = "()V"; + char * cMethodName = "refreshRow"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID); + ThrowSQLException(t.pEnv,*(::cppu::OWeakObject*)this); + } //mID + } //t.pEnv +} +//------------------------------------------------------------------------------ +void java_sql_ResultSet::setFetchSize(sal_Int32 _par0) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)V"; + char * cMethodName = "setFetchSize"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID,_par0); + ThrowSQLException(t.pEnv,*(::cppu::OWeakObject*)this); + } //mID + } //t.pEnv + +} +// ------------------------------------------------------------------------- +::cppu::IPropertyArrayHelper* java_sql_ResultSet::createArrayHelper( ) const +{ + Sequence< Property > aProps(5); + Property* pProperties = aProps.getArray(); + sal_Int32 nPos = 0; + DECL_PROP1IMPL(CURSORNAME, ::rtl::OUString) PropertyAttribute::READONLY); + DECL_PROP0(FETCHDIRECTION, sal_Int32); + DECL_PROP0(FETCHSIZE, sal_Int32); + DECL_PROP1IMPL(RESULTSETCONCURRENCY,sal_Int32) PropertyAttribute::READONLY); + DECL_PROP1IMPL(RESULTSETTYPE, sal_Int32) PropertyAttribute::READONLY); + + return new ::cppu::OPropertyArrayHelper(aProps); +} +// ------------------------------------------------------------------------- +::cppu::IPropertyArrayHelper & java_sql_ResultSet::getInfoHelper() +{ + return *const_cast<java_sql_ResultSet*>(this)->getArrayHelper(); +} +// ------------------------------------------------------------------------- +sal_Bool java_sql_ResultSet::convertFastPropertyValue( + ::com::sun::star::uno::Any & rConvertedValue, + ::com::sun::star::uno::Any & rOldValue, + sal_Int32 nHandle, + const ::com::sun::star::uno::Any& rValue ) + throw (::com::sun::star::lang::IllegalArgumentException) +{ + switch(nHandle) + { + case PROPERTY_ID_CURSORNAME: + case PROPERTY_ID_RESULTSETCONCURRENCY: + case PROPERTY_ID_RESULTSETTYPE: + throw ::com::sun::star::lang::IllegalArgumentException(); + break; + case PROPERTY_ID_FETCHDIRECTION: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection()); + case PROPERTY_ID_FETCHSIZE: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize()); + default: + ; + } + return sal_False; +} +// ------------------------------------------------------------------------- +void java_sql_ResultSet::setFastPropertyValue_NoBroadcast( + sal_Int32 nHandle, + const ::com::sun::star::uno::Any& rValue + ) + throw (::com::sun::star::uno::Exception) +{ + switch(nHandle) + { + case PROPERTY_ID_CURSORNAME: + case PROPERTY_ID_RESULTSETCONCURRENCY: + case PROPERTY_ID_RESULTSETTYPE: + throw ::com::sun::star::uno::Exception(); + break; + case PROPERTY_ID_FETCHDIRECTION: + setFetchDirection(connectivity::getINT32(rValue)); + break; + case PROPERTY_ID_FETCHSIZE: + setFetchSize(connectivity::getINT32(rValue)); + break; + default: + ; + } +} +// ------------------------------------------------------------------------- +void java_sql_ResultSet::getFastPropertyValue( + ::com::sun::star::uno::Any& rValue, + sal_Int32 nHandle + ) const +{ + switch(nHandle) + { + case PROPERTY_ID_CURSORNAME: + rValue <<= getCursorName(); + break; + case PROPERTY_ID_RESULTSETCONCURRENCY: + rValue <<= getResultSetConcurrency(); + break; + case PROPERTY_ID_RESULTSETTYPE: + rValue <<= getResultSetType(); + break; + case PROPERTY_ID_FETCHDIRECTION: + rValue <<= getFetchDirection(); + break; + case PROPERTY_ID_FETCHSIZE: + rValue <<= getFetchSize(); + break; + } +} + + + diff --git a/connectivity/source/drivers/jdbc/ResultSetMetaData.cxx b/connectivity/source/drivers/jdbc/ResultSetMetaData.cxx new file mode 100644 index 000000000000..b44bc920b6ef --- /dev/null +++ b/connectivity/source/drivers/jdbc/ResultSetMetaData.cxx @@ -0,0 +1,563 @@ +/************************************************************************* + * + * $RCSfile: ResultSetMetaData.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_JAVA_SQL_RESULTSETMETADATA_HXX_ +#include "java/sql/ResultSetMetaData.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_ +#include "java/tools.hxx" +#endif +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; +using namespace ::com::sun::star::lang; +//************************************************************** +//************ Class: java.sql.ResultSetMetaData +//************************************************************** + +jclass java_sql_ResultSetMetaData::theClass = 0; + +java_sql_ResultSetMetaData::~java_sql_ResultSetMetaData() +{} + +jclass java_sql_ResultSetMetaData::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( !t.pEnv ) return (jclass)0; + jclass tempClass = t.pEnv->FindClass("java/sql/ResultSetMetaData"); OSL_ENSHURE(tempClass,"Java : FindClass nicht erfolgreich!"); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} +// ------------------------------------------------------------------------- + +void java_sql_ResultSetMetaData::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==0 ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL java_sql_ResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "(I)I"; + char * cMethodName = "getColumnDisplaySize"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID,column); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL java_sql_ResultSetMetaData::getColumnType( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "(I)I"; + char * cMethodName = "getColumnType"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID,column); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL java_sql_ResultSetMetaData::getColumnCount( ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getColumnCount"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,*this); + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL java_sql_ResultSetMetaData::isCaseSensitive( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[1]; + // Parameter konvertieren + args[0].i = (sal_Int32)column; + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "isCaseSensitive"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + out = (sal_Bool)t.pEnv->CallIntMethod( object, mID, column ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_ResultSetMetaData::getSchemaName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + ::rtl::OUString aStr; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/lang/String;"; + char * cMethodName = "getSchemaName"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + jstring out = (jstring)t.pEnv->CallObjectMethod( object, mID, column ); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } + + // und aufraeumen + } //t.pEnv + return aStr; +} +// ------------------------------------------------------------------------- + +::rtl::OUString SAL_CALL java_sql_ResultSetMetaData::getColumnName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + ::rtl::OUString aStr; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/lang/String;"; + char * cMethodName = "getColumnName"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + jstring out = (jstring)t.pEnv->CallObjectMethod( object, mID, column ); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } + + // und aufraeumen + } //t.pEnv + return aStr; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_ResultSetMetaData::getTableName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + ::rtl::OUString aStr; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/lang/String;"; + char * cMethodName = "getTableName"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + jstring out = (jstring)t.pEnv->CallObjectMethod( object, mID, column ); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } + + // und aufraeumen + } //t.pEnv + return aStr; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_ResultSetMetaData::getCatalogName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + ::rtl::OUString aStr; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/lang/String;"; + char * cMethodName = "getCatalogName"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + jstring out = (jstring)t.pEnv->CallObjectMethod( object, mID, column ); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } + + // und aufraeumen + } //t.pEnv + return aStr; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_ResultSetMetaData::getColumnTypeName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + ::rtl::OUString aStr; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/lang/String;"; + char * cMethodName = "getColumnTypeName"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + jstring out = (jstring)t.pEnv->CallObjectMethod( object, mID, column ); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } + + // und aufraeumen + } //t.pEnv + return aStr; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_ResultSetMetaData::getColumnLabel( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + ::rtl::OUString aStr; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/lang/String;"; + char * cMethodName = "getColumnLabel"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + jstring out = (jstring)t.pEnv->CallObjectMethod( object, mID, column ); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } + + // und aufraeumen + } //t.pEnv + return aStr; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL java_sql_ResultSetMetaData::getColumnServiceName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + ::rtl::OUString aStr; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)Ljava/lang/String;"; + char * cMethodName = "getColumnClassName"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + { + jstring out = (jstring)t.pEnv->CallObjectMethod( object, mID, column ); + ThrowSQLException(t.pEnv,*this); + if(out) + aStr = JavaString2String(t.pEnv,out); + } + + // und aufraeumen + } //t.pEnv + return aStr; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL java_sql_ResultSetMetaData::isCurrency( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[1]; + // Parameter konvertieren + args[0].i = (sal_Int32)column; + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "isCurrency"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + out = (sal_Bool)t.pEnv->CallIntMethod( object, mID, column ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL java_sql_ResultSetMetaData::isAutoIncrement( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[1]; + // Parameter konvertieren + args[0].i = (sal_Int32)column; + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "isAutoIncrement"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + out = (sal_Bool)t.pEnv->CallIntMethod( object, mID, column); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- + + +sal_Bool SAL_CALL java_sql_ResultSetMetaData::isSigned( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[1]; + // Parameter konvertieren + args[0].i = (sal_Int32)column; + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "isSigned"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ) + out = (sal_Bool)t.pEnv->CallIntMethod( object, mID, column); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_ResultSetMetaData::getPrecision( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[1]; + // Parameter konvertieren + args[0].i = (sal_Int32)column; + // temporaere Variable initialisieren + char * cSignature = "(I)I"; + char * cMethodName = "getPrecision"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID, column ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_ResultSetMetaData::getScale( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[1]; + // Parameter konvertieren + args[0].i = (sal_Int32)column; + // temporaere Variable initialisieren + char * cSignature = "(I)I"; + char * cMethodName = "getScale"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID, column ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL java_sql_ResultSetMetaData::isNullable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + jvalue args[1]; + // Parameter konvertieren + args[0].i = (sal_Int32)column; + // temporaere Variable initialisieren + char * cSignature = "(I)I"; + char * cMethodName = "isNullable"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID, column ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return (sal_Int32)out; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL java_sql_ResultSetMetaData::isSearchable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "isSearchable"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID, column ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL java_sql_ResultSetMetaData::isReadOnly( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "isReadOnly"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID, column ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL java_sql_ResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "isDefinitelyWritable"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID, column ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL java_sql_ResultSetMetaData::isWritable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + jboolean out(sal_False); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "(I)Z"; + char * cMethodName = "isWritable"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallBooleanMethod( object, mID, column ); + ThrowSQLException(t.pEnv,*this); + // und aufraeumen + } //mID + } //t.pEnv + return out; +} +// ------------------------------------------------------------------------- + diff --git a/connectivity/source/drivers/jdbc/SQLException.cxx b/connectivity/source/drivers/jdbc/SQLException.cxx new file mode 100644 index 000000000000..1a83ce996314 --- /dev/null +++ b/connectivity/source/drivers/jdbc/SQLException.cxx @@ -0,0 +1,186 @@ +/************************************************************************* + * + * $RCSfile: SQLException.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:22 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_JAVA_SQL_SQLEXCEPTION_HXX_ +#include "java/sql/SQLException.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_ +#include "java/tools.hxx" +#endif + +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; +using namespace ::com::sun::star::lang; +//************************************************************** +//************ Class: java.sql.SQLException +//************************************************************** +java_sql_SQLException::java_sql_SQLException( const java_sql_SQLException_BASE& _rException,const Reference< XInterface> & _rContext) + : starsdbc::SQLException( _rException.getMessage(), + _rContext, + _rException.getSQLState(), + _rException.getErrorCode(), + makeAny(_rException.getNextException()) + ) +{ +} + +java_sql_SQLException_BASE::java_sql_SQLException_BASE( JNIEnv * pEnv, jobject myObj ) : java_lang_Exception( pEnv, myObj ) +{ +} + +jclass java_sql_SQLException_BASE::theClass = 0; + +java_sql_SQLException_BASE::~java_sql_SQLException_BASE() +{} + + +jclass java_sql_SQLException_BASE::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; + if( !t.pEnv ) return (jclass)NULL; + jclass tempClass = t.pEnv->FindClass("java/sql/SQLException"); + OSL_ENSHURE(tempClass,"Java : FindClass nicht erfolgreich!"); + if(!tempClass) + { + t.pEnv->ExceptionDescribe(); + t.pEnv->ExceptionClear(); + } + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} + +void java_sql_SQLException_BASE::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==NULL ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} + +starsdbc::SQLException java_sql_SQLException_BASE::getNextException() const +{ + jobject out = NULL; + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Ljava/sql/Exception;"; + char * cMethodName = "getNextException"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,0); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return out ? (starsdbc::SQLException)java_sql_SQLException(java_sql_SQLException_BASE(t.pEnv,out),0) : starsdbc::SQLException(); +} + +::rtl::OUString java_sql_SQLException_BASE::getSQLState() const +{ + jstring out = (jstring)NULL; + SDBThreadAttach t; + ::rtl::OUString aStr; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getSQLState"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = (jstring) t.pEnv->CallObjectMethod( object, mID); + ThrowSQLException(t.pEnv,0); + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} +sal_Int32 java_sql_SQLException_BASE::getErrorCode() const +{ + jint out(0); + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getErrorCode"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + ThrowSQLException(t.pEnv,0); + } //mID + } //t.pEnv + return (sal_Int32)out; +} + diff --git a/connectivity/source/drivers/jdbc/SQLWarning.cxx b/connectivity/source/drivers/jdbc/SQLWarning.cxx new file mode 100644 index 000000000000..aec20eeeb495 --- /dev/null +++ b/connectivity/source/drivers/jdbc/SQLWarning.cxx @@ -0,0 +1,95 @@ +/************************************************************************* + * + * $RCSfile: SQLWarning.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_JAVA_SQL_SQLWARNING_HXX_ +#include "java/sql/SQLWarning.hxx" +#endif +using namespace connectivity; +//************************************************************** +//************ Class: java.sql.SQLWarning +//************************************************************** + +jclass java_sql_SQLWarning_BASE::theClass = 0; + +java_sql_SQLWarning_BASE::~java_sql_SQLWarning_BASE() +{} + +jclass java_sql_SQLWarning_BASE::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; + if( !t.pEnv ) return (jclass)NULL; + jclass tempClass = t.pEnv->FindClass( "java/sql/SQLWarning" ); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} + +void java_sql_SQLWarning_BASE::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==NULL ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} + diff --git a/connectivity/source/drivers/jdbc/String.cxx b/connectivity/source/drivers/jdbc/String.cxx new file mode 100644 index 000000000000..a25472d00a52 --- /dev/null +++ b/connectivity/source/drivers/jdbc/String.cxx @@ -0,0 +1,126 @@ +/************************************************************************* + * + * $RCSfile: String.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_JAVA_LANG_STRING_HXX_ +#include "java/lang/String.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_ +#include "java/tools.hxx" +#endif +using namespace connectivity; +//************************************************************** +//************ Class: java.lang.String +//************************************************************** + +jclass java_lang_String::theClass = 0; + +java_lang_String::~java_lang_String() +{} + +jclass java_lang_String::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; + if( !t.pEnv ) return (jclass)NULL; + jclass tempClass = t.pEnv->FindClass("java/lang/String"); + OSL_ENSHURE(tempClass,"Java : FindClass nicht erfolgreich!"); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} +//-------------------------------------------------------------------------- +void java_lang_String::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==NULL ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} +//-------------------------------------------------------------------------- +java_lang_String::java_lang_String( const ::rtl::OUString& _par0 ): java_lang_Object( NULL, (jobject)NULL ) +{ + SDBThreadAttach t; + if( !t.pEnv ) + return; + jvalue args[1]; + // Parameter konvertieren + args[0].l = convertwchar_tToJavaString(t.pEnv,_par0); + // Java-Call fuer den Konstruktor absetzen + // temporaere Variable initialisieren + char * cSignature = "(Ljava/lang/String;)V"; + jobject tempObj; + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), "<init>", cSignature ); + tempObj = t.pEnv->NewObjectA( getMyClass(), mID, args ); + saveRef( t.pEnv, tempObj ); + t.pEnv->DeleteLocalRef( tempObj ); + t.pEnv->DeleteLocalRef((jstring)args[0].l); +} +//-------------------------------------------------------------------------- +java_lang_String::operator ::rtl::OUString() +{ + SDBThreadAttach t; + if(!t.pEnv) + return ::rtl::OUString(); + return JavaString2String(t.pEnv,(jstring)object); +} + diff --git a/connectivity/source/drivers/jdbc/Throwable.cxx b/connectivity/source/drivers/jdbc/Throwable.cxx new file mode 100644 index 000000000000..336425836cb6 --- /dev/null +++ b/connectivity/source/drivers/jdbc/Throwable.cxx @@ -0,0 +1,160 @@ +/************************************************************************* + * + * $RCSfile: Throwable.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_JAVA_LANG_THROWABLE_HXX_ +#include "java/lang/Throwable.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_ +#include "java/tools.hxx" +#endif +using namespace connectivity; +//************************************************************** +//************ Class: java.lang.Throwable +//************************************************************** + +jclass java_lang_Throwable::theClass = 0; + +java_lang_Throwable::~java_lang_Throwable() +{} + +jclass java_lang_Throwable::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; + if( !t.pEnv ) return (jclass)NULL; + jclass tempClass = t.pEnv->FindClass("java/lang/Throwable"); OSL_ENSHURE(tempClass,"Java : FindClass nicht erfolgreich!"); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} + +void java_lang_Throwable::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==NULL ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} + +::rtl::OUString java_lang_Throwable::getMessage() const +{ + ::rtl::OUString aStr; + SDBThreadAttach t; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getMessage"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + jstring out = (jstring)t.pEnv->CallObjectMethod( object, mID); + + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} + +::rtl::OUString java_lang_Throwable::getLocalizedMessage() const +{ + ::rtl::OUString aStr; + SDBThreadAttach t; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "getLocalizedMessage"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + jstring out = (jstring)t.pEnv->CallObjectMethod( object, mID); + + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} +::rtl::OUString java_lang_Throwable::toString() const +{ + ::rtl::OUString aStr; + SDBThreadAttach t; + if( t.pEnv ){ + // temporaere Variable initialisieren + char * cSignature = "()Ljava/lang/String;"; + char * cMethodName = "toString"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + jstring out = (jstring)t.pEnv->CallObjectMethod( object, mID); + + if(out) + aStr = JavaString2String(t.pEnv,out); + } //mID + } //t.pEnv + // ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!! + return aStr; +} + diff --git a/connectivity/source/drivers/jdbc/Timestamp.cxx b/connectivity/source/drivers/jdbc/Timestamp.cxx new file mode 100644 index 000000000000..6da40bc40653 --- /dev/null +++ b/connectivity/source/drivers/jdbc/Timestamp.cxx @@ -0,0 +1,240 @@ +/************************************************************************* + * + * $RCSfile: Timestamp.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_JAVA_SQL_TIMESTAMP_HXX_ +#include "java/sql/Timestamp.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_ +#include "java/tools.hxx" +#endif +#ifndef _CONNECTIVITY_DATECONVERSION_HXX_ +#include "DateConversion.hxx" +#endif +using namespace connectivity; +//************************************************************** +//************ Class: java.sql.Date +//************************************************************** + +jclass java_sql_Date::theClass = 0; + +java_sql_Date::~java_sql_Date() +{} + +jclass java_sql_Date::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( !t.pEnv ) return (jclass)0; + jclass tempClass = t.pEnv->FindClass("java/sql/Date"); OSL_ENSHURE(tempClass,"Java : FindClass nicht erfolgreich!"); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} + +void java_sql_Date::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==0 ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} + +//************************************************************** +//************ Class: java.sql.Time +//************************************************************** + +jclass java_sql_Time::theClass = 0; + +java_sql_Time::~java_sql_Time() +{} + +jclass java_sql_Time::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( !t.pEnv ) return (jclass)0; + jclass tempClass = t.pEnv->FindClass("java/sql/Time"); OSL_ENSHURE(tempClass,"Java : FindClass nicht erfolgreich!"); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} + +void java_sql_Time::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==0 ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} + +java_sql_Time::java_sql_Time( const ::com::sun::star::util::Time& _rOut ): java_util_Date( NULL, (jobject)NULL ) +{ + SDBThreadAttach t; + if( !t.pEnv ) + return; + jvalue args[1]; + // Parameter konvertieren + args[0].j = DateConversion::toINT32(_rOut); + // Java-Call fuer den Konstruktor absetzen + // temporaere Variable initialisieren + char * cSignature = "(J)V"; + jobject tempObj; + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), "<init>", cSignature ); + tempObj = t.pEnv->NewObjectA( getMyClass(), mID, args ); + saveRef( t.pEnv, tempObj ); + t.pEnv->DeleteLocalRef( tempObj ); + // und aufraeumen +} + +//************************************************************** +//************ Class: java.sql.Timestamp +//************************************************************** + +jclass java_sql_Timestamp::theClass = 0; + +java_sql_Timestamp::~java_sql_Timestamp() +{} + +jclass java_sql_Timestamp::getMyClass() +{ + // die Klasse muss nur einmal geholt werden, daher statisch + if( !theClass ){ + SDBThreadAttach t; OSL_ENSHURE(t.pEnv,"Java Enviroment gelscht worden!"); + if( !t.pEnv ) return (jclass)0; + jclass tempClass = t.pEnv->FindClass("java/sql/Timestamp"); OSL_ENSHURE(tempClass,"Java : FindClass nicht erfolgreich!"); + jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass ); + t.pEnv->DeleteLocalRef( tempClass ); + saveClassRef( globClass ); + } + return theClass; +} + +void java_sql_Timestamp::saveClassRef( jclass pClass ) +{ + if( SDBThreadAttach::IsJavaErrorOccured() || pClass==0 ) + return; + // der uebergebe Klassen-Handle ist schon global, daher einfach speichern + theClass = pClass; +} + +java_sql_Timestamp::java_sql_Timestamp(const ::com::sun::star::util::DateTime& _rOut) + :java_util_Date( NULL, (jobject)NULL ) +{ + SDBThreadAttach t; + if( !t.pEnv ) + return; + jvalue args[1]; + // Parameter konvertieren + args[0].j = (jlong)DateConversion::toINT64(_rOut); + // Java-Call fuer den Konstruktor absetzen + // temporaere Variable initialisieren + char * cSignature = "(J)V"; + jobject tempObj; + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), "<init>", cSignature ); + tempObj = t.pEnv->NewObjectA( getMyClass(), mID, args ); + saveRef( t.pEnv, tempObj ); + t.pEnv->DeleteLocalRef( tempObj ); + // und aufraeumen +} + +sal_Int32 java_sql_Timestamp::getNanos() +{ + jint out(0); + SDBThreadAttach t; + if( t.pEnv ){ + + // temporaere Variable initialisieren + char * cSignature = "()I"; + char * cMethodName = "getNanos"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + out = t.pEnv->CallIntMethod( object, mID); + } //mID + } //t.pEnv + return (sal_Int32)out; +} + +void java_sql_Timestamp::setNanos( sal_Int32 _par0 ) +{ + SDBThreadAttach t; + if( t.pEnv ){ + jvalue args[1]; + // Parameter konvertieren + args[0].i = (sal_Int32)_par0; + // temporaere Variable initialisieren + char * cSignature = "(I)V"; + char * cMethodName = "setNanos"; + // Java-Call absetzen + jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); + if( mID ){ + t.pEnv->CallVoidMethod( object, mID, args[0].i ); + // und aufraeumen + } //mID + } //t.pEnv +} + diff --git a/connectivity/source/drivers/jdbc/exports.dxp b/connectivity/source/drivers/jdbc/exports.dxp new file mode 100644 index 000000000000..9630d7e06768 --- /dev/null +++ b/connectivity/source/drivers/jdbc/exports.dxp @@ -0,0 +1,3 @@ +component_getImplementationEnvironment +component_writeInfo +component_getFactory diff --git a/connectivity/source/drivers/jdbc/jdbc.xml b/connectivity/source/drivers/jdbc/jdbc.xml new file mode 100644 index 000000000000..5ed71581fd54 --- /dev/null +++ b/connectivity/source/drivers/jdbc/jdbc.xml @@ -0,0 +1,69 @@ +<?xml version='1.0' encoding="UTF-8"?> +<!DOCTYPE COMPONENTDESCRIPTION PUBLIC "-//W3C//DTD HTML 3.2//EN" "componentdependencies.dtd"> +<COMPONENTDESCRIPTION> + +<Name> com.sun.star.sdbc.JDBCDriver </Name> + +<Description> + This component provides ... +</Description> + +<ModuleName> jdbc </ModuleName> + +<LoaderName> com.sun.star.loader.SharedLibrary </LoaderName> + +<SupportedService> com.sun.star.sdbc.Driver </SupportedService> + +<ServiceDependency> ... </ServiceDependency> + +<ProjectBuildDependency> cppuhelper </ProjectBuildDependency> +<ProjectBuildDependency> cppu </ProjectBuildDependency> +<ProjectBuildDependency> sal </ProjectBuildDependency> +<ProjectBuildDependency> vos </ProjectBuildDependency> + +<RuntimeModuleDependency> cppuhelper </RuntimeModuleDependency> +<RuntimeModuleDependency> cppu1 </RuntimeModuleDependency> +<RuntimeModuleDependency> sal1 </RuntimeModuleDependency> +<RuntimeModuleDependency> vos </RuntimeModuleDependency> + +<Language> c++ </Language> + +<Status StatusValue="final"/> + +<Type> com.sun.star.util.XCancellable </Type> +<Type> com.sun.star.util.XNumberFormatter </Type> +<Type> com.sun.star.uno.TypeClass </Type> +<Type> com.sun.star.uno.XWeak </Type> +<Type> com.sun.star.uno.XAggregation </Type> +<Type> com.sun.star.beans.XPropertyState </Type> +<Type> com.sun.star.beans.XPropertySet </Type> +<Type> com.sun.star.beans.PropertyValue </Type> +<Type> com.sun.star.beans.XMultiPropertySet </Type> +<Type> com.sun.star.beans.XFastPropertySet </Type> +<Type> com.sun.star.lang.XTypeProvider </Type> +<Type> com.sun.star.lang.EventObject </Type> +<Type> com.sun.star.lang.XComponent </Type> +<Type> com.sun.star.lang.IllegalArgumentException </Type> +<Type> com.sun.star.lang.XMultiServiceFactory </Type> +<Type> com.sun.star.java.XJavaThreadRegister_11 </Type> +<Type> com.sun.star.java.XJavaVM </Type> +<Type> com.sun.star.sdbc.XConnection </Type> +<Type> com.sun.star.sdbc.XStatement </Type> +<Type> com.sun.star.sdbc.XResultSet </Type> +<Type> com.sun.star.sdbc.XResultSetMetaDataSupplier</Type> +<Type> com.sun.star.sdbc.XColumnLocate </Type> +<Type> com.sun.star.sdbc.XResultSetUpdate </Type> +<Type> com.sun.star.sdbc.XWarningsSupplier </Type> +<Type> com.sun.star.sdbc.XRowUpdate </Type> +<Type> com.sun.star.sdbc.XMultipleResults </Type> +<Type> com.sun.star.sdbc.XBatchExecution </Type> +<Type> com.sun.star.sdbc.XPreparedBatchExecution </Type> +<Type> com.sun.star.sdbc.XParameters </Type> +<Type> com.sun.star.sdbc.XOutParameters </Type> +<Type> com.sun.star.sdbc.DriverPropertyInfo </Type> +<Type> com.sun.star.sdbc.XRow </Type> +<Type> com.sun.star.sdb.XColumnUpdate </Type> +<Type> com.sun.star.sdb.XColumn </Type> + +</COMPONENTDESCRIPTION> + diff --git a/connectivity/source/drivers/jdbc/jservices.cxx b/connectivity/source/drivers/jdbc/jservices.cxx new file mode 100644 index 000000000000..a24b49c290ec --- /dev/null +++ b/connectivity/source/drivers/jdbc/jservices.cxx @@ -0,0 +1,209 @@ +/************************************************************************* + * + * $RCSfile: jservices.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_JAVA_SQL_DRIVER_HXX_ +#include "java/sql/Driver.hxx" +#endif +#ifndef _CPPUHELPER_FACTORY_HXX_ +#include <cppuhelper/factory.hxx> +#endif + +using namespace connectivity; +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 + ); + +//*************************************************************************************** +// +// 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_ENSHURE(xNewKey.is(), "SBA::component_writeInfo : could not create a registry key !"); + + for (sal_uInt32 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); + } + catch(...) + { + } + return xRet.is(); + } + + void* getProvider() const { return xRet.get(); } +}; + +//--------------------------------------------------------------------------------------- + +extern "C" void SAL_CALL component_getImplementationEnvironment( + const sal_Char **ppEnvTypeName, + uno_Environment **ppEnv + ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +//--------------------------------------------------------------------------------------- +extern "C" 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( + java_sql_Driver::getImplementationName_Static(), + java_sql_Driver::getSupportedServiceNames_Static(), xKey); + + return sal_True; + } + catch (::com::sun::star::registry::InvalidRegistryException& ) + { + OSL_ENSHURE(sal_False, "SBA::component_writeInfo : could not create a registry key ! ## InvalidRegistryException !"); + } + + return sal_False; +} + +//--------------------------------------------------------------------------------------- +extern "C" 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( + java_sql_Driver::getImplementationName_Static(), + java_sql_Driver::getSupportedServiceNames_Static(), + java_sql_Driver_CreateInstance, + ::cppu::createSingleFactory); + + if(aReq.xRet.is()) + aReq.xRet->acquire(); + pRet = aReq.getProvider(); + } + + return pRet; +}; + + + diff --git a/connectivity/source/drivers/jdbc/makefile.mk b/connectivity/source/drivers/jdbc/makefile.mk new file mode 100644 index 000000000000..00621c73d2ee --- /dev/null +++ b/connectivity/source/drivers/jdbc/makefile.mk @@ -0,0 +1,187 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 16:14:23 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/..$/.. +PRJINC=..$/.. +PRJNAME=connectivity +TARGET=jdbc + +USE_DEFFILE=TRUE +NO_BSYMBOLIC=TRUE + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ---------------------------------- +.IF "$(DBGUTIL_OJ)"!="" +ENVCFLAGS+=/FR$(SLO)$/ +.ENDIF + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/version.mk + +# --- Types ------------------------------------- + + +UNOUCRDEP=$(SOLARBINDIR)$/applicat.rdb +UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb + +UNOUCROUT=$(OUT)$/inc +INCPRE+=$(UNOUCROUT) + +# --- Types ------------------------------------- + +UNOTYPES+= \ + com.sun.star.util.XCancellable \ + com.sun.star.util.XNumberFormatter \ + com.sun.star.uno.TypeClass \ + com.sun.star.uno.XWeak \ + com.sun.star.uno.XAggregation \ + com.sun.star.beans.XPropertyState \ + com.sun.star.beans.XPropertySet \ + com.sun.star.beans.PropertyValue \ + com.sun.star.beans.XMultiPropertySet \ + com.sun.star.beans.XFastPropertySet \ + com.sun.star.lang.XTypeProvider \ + com.sun.star.lang.EventObject \ + com.sun.star.lang.XComponent \ + com.sun.star.lang.IllegalArgumentException \ + com.sun.star.lang.XMultiServiceFactory \ + com.sun.star.java.XJavaThreadRegister_11 \ + com.sun.star.java.XJavaVM \ + com.sun.star.sdbc.XConnection \ + com.sun.star.sdbc.XStatement \ + com.sun.star.sdbc.XResultSet \ + com.sun.star.sdbc.XResultSetMetaDataSupplier \ + com.sun.star.sdbc.XColumnLocate \ + com.sun.star.sdbc.XResultSetUpdate \ + com.sun.star.sdbc.XWarningsSupplier \ + com.sun.star.sdbc.XRowUpdate \ + com.sun.star.sdbc.XMultipleResults \ + com.sun.star.sdbc.XBatchExecution \ + com.sun.star.sdbc.XPreparedBatchExecution \ + com.sun.star.sdbc.XParameters \ + com.sun.star.sdbc.XOutParameters \ + com.sun.star.sdbc.DriverPropertyInfo \ + com.sun.star.sdbc.XRow \ + com.sun.star.sdb.XColumnUpdate \ + com.sun.star.sdb.XColumn + + + +# --- Files ------------------------------------- + +SLOFILES=\ + $(SLO)$/Array.obj \ + $(SLO)$/Blob.obj \ + $(SLO)$/Boolean.obj \ + $(SLO)$/CallableStatement.obj \ + $(SLO)$/Class.obj \ + $(SLO)$/Clob.obj \ + $(SLO)$/Connection.obj \ + $(SLO)$/DatabaseMetaData.obj \ + $(SLO)$/Date.obj \ + $(SLO)$/DriverManager.obj \ + $(SLO)$/DriverPropertyInfo.obj \ + $(SLO)$/Exception.obj \ + $(SLO)$/InputStream.obj \ + $(SLO)$/JDriver.obj \ + $(SLO)$/Object.obj \ + $(SLO)$/PreparedStatement.obj \ + $(SLO)$/Reader.obj \ + $(SLO)$/Ref.obj \ + $(SLO)$/ResultSet.obj \ + $(SLO)$/ResultSetMetaData.obj \ + $(SLO)$/SQLException.obj \ + $(SLO)$/SQLWarning.obj \ + $(SLO)$/Statement.obj \ + $(SLO)$/String.obj \ + $(SLO)$/Throwable.obj \ + $(SLO)$/Timestamp.obj \ + $(SLO)$/tools.obj \ + $(SLO)$/jservices.obj + +# --- Library ----------------------------------- + +SHL1TARGET= $(JDBC_TARGET)$(JDBC_MAJOR) +SHL1STDLIBS=\ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(VOSLIB) \ + $(OSLLIB) \ + $(SALLIB) + +SHL1DEPN= +SHL1IMPLIB= i$(SHL1TARGET) +SHL1LIBS= $(SLB)$/$(TARGET).lib \ + $(SLB)$/commontools.lib \ + $(SLB)$/resource.lib + +SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME= $(SHL1TARGET) +DEF1EXPORTFILE= exports.dxp + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + + diff --git a/connectivity/source/drivers/jdbc/tools.cxx b/connectivity/source/drivers/jdbc/tools.cxx new file mode 100644 index 000000000000..c8e0f97c351c --- /dev/null +++ b/connectivity/source/drivers/jdbc/tools.cxx @@ -0,0 +1,159 @@ +/************************************************************************* + * + * $RCSfile: tools.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_ +#include "java/tools.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_LANG_STRING_HXX_ +#include "java/lang/String.hxx" +#endif +#ifndef _CONNECTIVITY_JAVA_LANG_CLASS_HXX_ +#include "java/lang/Class.hxx" +#endif + +#ifndef _COM_SUN_STAR_SDBC_DRIVERPROPERTYINFO_HPP_ +#include <com/sun/star/sdbc/DriverPropertyInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_ +#include <com/sun/star/container/XNameAccess.hpp> +#endif + +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; +using namespace ::com::sun::star::lang; + +// -------------------------------------------------------------------------------- +jstring connectivity::convertwchar_tToJavaString(JNIEnv *pEnv,const ::rtl::OUString& Temp) +{ + if (pEnv) + { + ::rtl::OString aT = ::rtl::OUStringToOString(Temp,RTL_TEXTENCODING_UTF8); + return pEnv->NewString((const unsigned short *)aT.getStr(), aT.getLength()); + } + return NULL; +} + +// -------------------------------------------------------------------------------- +jobjectArray connectivity::createStringPropertyArray(JNIEnv *pEnv,const Sequence< ::com::sun::star::beans::PropertyValue >& info ) throw(starsdbc::SQLException, RuntimeException) +{ + jobjectArray aArray = pEnv->NewObjectArray(info.getLength(),java_lang_String::getMyClass(),pEnv->NewStringUTF("")); + + const ::com::sun::star::beans::PropertyValue* pBegin = info.getConstArray(); + const ::com::sun::star::beans::PropertyValue* pEnd = pBegin + info.getLength(); + + sal_Bool bFound = sal_False; + for(jsize i=0;pBegin != pEnd;++pBegin) + { + if(!bFound || pBegin->Name.compareToAscii("JDBCDRV")) + { + java_sql_SQLException_BASE::getMyClass(); + java_lang_Throwable::getMyClass(); + + ::rtl::OUString aStr; + pBegin->Value >>= aStr; + //Datenbanktreiber wird ueber einen Klassennamen erzeugt + java_lang_Class *pDrvClass = java_lang_Class::forName(aStr); + bFound = sal_True; + } + else + { + ::rtl::OUString aStr; + pBegin->Value >>= aStr; + jstring a = convertwchar_tToJavaString(pEnv,aStr.getStr()); + pEnv->SetObjectArrayElement(aArray,i++,a); + } + } + return aArray; +} +// -------------------------------------------------------------------------------- +::rtl::OUString connectivity::JavaString2String(JNIEnv *pEnv,jstring _Str) +{ + ::rtl::OUString aStr; + if(_Str) + { + jboolean bCopy(sal_True); + const jchar* pChar = pEnv->GetStringChars(_Str,&bCopy); + jsize len = pEnv->GetStringLength(_Str); + aStr = ::rtl::OUString(pChar,RTL_TEXTENCODING_UTF8); + + if(bCopy) + pEnv->ReleaseStringChars(_Str,pChar); + pEnv->DeleteLocalRef(_Str); + } + return aStr; +} +// -------------------------------------------------------------------------------- +jobject connectivity::XNameAccess2Map(JNIEnv *pEnv,const Reference< ::com::sun::star::container::XNameAccess > & _rMap) +{ + ::com::sun::star::uno::Sequence< ::rtl::OUString > aSeq = _rMap->getElementNames(); + const ::rtl::OUString *pBegin = aSeq.getConstArray(); + const ::rtl::OUString *pEnd = pBegin + aSeq.getLength(); + for(;pBegin != pEnd;++pBegin) + { + } + return 0; +} + + diff --git a/connectivity/source/drivers/odbc/OConnection.cxx b/connectivity/source/drivers/odbc/OConnection.cxx new file mode 100644 index 000000000000..db68e9948559 --- /dev/null +++ b/connectivity/source/drivers/odbc/OConnection.cxx @@ -0,0 +1,539 @@ +/************************************************************************* + * + * $RCSfile: OConnection.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_OTOOLS_HXX_ +#include "odbc/OTools.hxx" +#endif +#ifndef _CONNECTIVITY_ODBC_OCONNECTION_HXX_ +#include "odbc/OConnection.hxx" +#endif +#ifndef _CONNECTIVITY_ODBC_ODATABASEMETADATA_HXX_ +#include "odbc/ODatabaseMetaData.hxx" +#endif +#ifndef _CONNECTIVITY_RESOURCE_HRC_ +#include "Resource.hrc" +#endif +#ifndef _CONNECTIVITY_MODULECONTEXT_HXX_ +#include "ModuleContext.hxx" +#endif +#ifndef _CONNECTIVITY_ODBC_OFUNCTIONS_HXX_ +#include "odbc/OFunctions.hxx" +#endif +#ifndef _CONNECTIVITY_ODBC_ODRIVER_HXX_ +#include "odbc/ODriver.hxx" +#endif +#ifndef _CONNECTIVITY_ODBC_OSTATEMENT_HXX_ +#include "odbc/OStatement.hxx" +#endif +#ifndef _CONNECTIVITY_ODBC_OPREPAREDSTATEMENT_HXX_ +#include "odbc/OPreparedStatement.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ +#include <com/sun/star/sdbc/ColumnValue.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif + +using namespace connectivity::odbc; + +//------------------------------------------------------------------------------ +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::sdbc; +// -------------------------------------------------------------------------------- +OConnection::OConnection(const SQLHANDLE _pDriverHandle,ODBCDriver* _pDriver) + : OConnection_BASE(m_aMutex), + OSubComponent<OConnection>((::cppu::OWeakObject*)_pDriver), + m_pDriverHandleCopy(_pDriverHandle), + m_pDriver(_pDriver), + m_bClosed(sal_False), + m_xMetaData(NULL) +{ + ModuleContext::AddRef(); +} +//----------------------------------------------------------------------------- +OConnection::~OConnection() +{ + if(!isClosed( )) + close(); + ModuleContext::ReleaseRef(); +} +//----------------------------------------------------------------------------- +void SAL_CALL OConnection::release() throw(RuntimeException) +{ + relase_ChildImpl(); + OConnection_BASE::release(); +} + +//----------------------------------------------------------------------------- +SQLRETURN OConnection::OpenConnection(const ::rtl::OUString& aConnectStr,sal_Int32 nTimeOut, sal_Bool bSilent) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + if (m_aConnectionHandle == SQL_NULL_HANDLE) + return -1; + + sal_Bool bReadOnly; //weil Methode statisch hier noch einmal ein lokales bReadOnly + SQLRETURN nSQLRETURN = 0; + SDB_ODBC_CHAR szConnStrOut[4096]; + SDB_ODBC_CHAR szConnStrIn[2048]; + SWORD cbConnStrOut; + memset(szConnStrOut,'\0',4096); + memset(szConnStrIn,'\0',2048); + ::rtl::OString aConStr(::rtl::OUStringToOString(aConnectStr,osl_getThreadTextEncoding())); + memcpy(szConnStrIn, (SDB_ODBC_CHAR*) aConStr.getStr(), ::std::min<sal_Int32>((sal_Int32)2048,aConStr.getLength())); + + + N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_LOGIN_TIMEOUT,(SQLPOINTER)nTimeOut,SQL_IS_INTEGER); + // Verbindung aufbauen + +#ifdef LINUX + + nSQLRETURN = N3SQLDriverConnect(m_aConnectionHandle, + NULL, + szConnStrIn, + (SQLSMALLINT) ::std::min((sal_Int32)2048,aConStr.getLength()), + szConnStrOut, + (SQLSMALLINT) sizeof szConnStrOut, + &cbConnStrOut, + SQL_DRIVER_NOPROMPT); + if (nSQLRETURN == SQL_ERROR || nSQLRETURN == SQL_NO_DATA || SQL_SUCCESS_WITH_INFO == nSQLRETURN) + return nSQLRETURN; +#else + + SQLUSMALLINT nSilent = bSilent ? SQL_DRIVER_NOPROMPT : SQL_DRIVER_COMPLETE; + nSQLRETURN = N3SQLDriverConnect(m_aConnectionHandle, + NULL, + szConnStrIn, + (SQLSMALLINT) ::std::min<sal_Int32>((sal_Int32)2048,aConStr.getLength()), + szConnStrOut, + (SQLSMALLINT) sizeof szConnStrOut, + &cbConnStrOut, + nSilent); + if (nSQLRETURN == SQL_ERROR || nSQLRETURN == SQL_NO_DATA) + return nSQLRETURN; + +#endif //LINUX + + try + { + ::rtl::OUString aVal; + OTools::GetInfo(m_aConnectionHandle,SQL_DATA_SOURCE_READ_ONLY,aVal,*this); + bReadOnly = !aVal.compareToAscii("Y"); + } + catch(...) + { + bReadOnly = sal_True; + } + +#ifndef MAC + // autocoomit ist immer default + + if (!bReadOnly) + N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_AUTOCOMMIT,(SQLPOINTER)SQL_AUTOCOMMIT_ON,SQL_IS_INTEGER); +#endif + + return nSQLRETURN; +} +//----------------------------------------------------------------------------- +SQLRETURN OConnection::Construct(const ::rtl::OUString& url,const Sequence< PropertyValue >& info) throw(SQLException) +{ + osl_incrementInterlockedCount( &m_refCount ); + m_aConnectionHandle = SQL_NULL_HANDLE; + + // Connection allozieren + N3SQLAllocHandle(SQL_HANDLE_DBC,m_pDriverHandleCopy,&m_aConnectionHandle); + if(m_aConnectionHandle == SQL_NULL_HANDLE) + throw SQLException(); + + sal_Int32 nLen = url.indexOf(':'); + nLen = url.indexOf(':',nLen+1); + ::rtl::OUString aDSN(url.copy(nLen+1)),aUID,aPWD; + + sal_Int32 nTimeout = 20; + sal_Bool bSilent = sal_True; + const PropertyValue *pBegin = info.getConstArray(); + const PropertyValue *pEnd = pBegin + info.getLength(); + for(;pBegin != pEnd;++pBegin) + { + if(!pBegin->Name.compareToAscii("Timeout")) + pBegin->Value >>= nTimeout; + else if(!pBegin->Name.compareToAscii("Silent")) + pBegin->Value >>= bSilent; + else if(!pBegin->Name.compareToAscii("user")) + { + pBegin->Value >>= aUID; + aDSN = aDSN + ::rtl::OUString::createFromAscii(";UID=") + aUID; + } + else if(!pBegin->Name.compareToAscii("password")) + { + pBegin->Value >>= aPWD; + aDSN = aDSN + ::rtl::OUString::createFromAscii(";PWD=") + aPWD; + } + } + + SQLRETURN nSQLRETURN = OpenConnection(aDSN,nTimeout, bSilent); + if (nSQLRETURN == SQL_ERROR || nSQLRETURN == SQL_NO_DATA) + { + OTools::ThrowException(nSQLRETURN,m_aConnectionHandle,SQL_HANDLE_DBC,*this); + } + else if(SQL_SUCCESS_WITH_INFO == nSQLRETURN) // this driver does not support odbc3 + { + } + osl_decrementInterlockedCount( &m_refCount ); + return nSQLRETURN; +} +// XServiceInfo +// -------------------------------------------------------------------------------- +IMPLEMENT_SERVICE_INFO(OConnection, "com.sun.star.sdbc.drivers.odbc.OConnection", "com.sun.star.sdbc.Connection") + +// -------------------------------------------------------------------------------- +Reference< XStatement > SAL_CALL OConnection::createStatement( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + OStatement* pStmt = new OStatement(this); + m_aStatements.push_back(WeakReferenceHelper(*pStmt)); + return pStmt; +} +// -------------------------------------------------------------------------------- +Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + if(m_aTypeInfo.empty()) + buildTypeInfo(); + OPreparedStatement* pStmt = new OPreparedStatement(this,m_aTypeInfo,sql); + m_aStatements.push_back(WeakReferenceHelper(*pStmt)); + return pStmt; +} +// -------------------------------------------------------------------------------- +Reference< XPreparedStatement > SAL_CALL OConnection::prepareCall( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + return NULL; +} +// -------------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OConnection::nativeSQL( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + ::rtl::OString aSql(::rtl::OUStringToOString(sql.getStr(),osl_getThreadTextEncoding())); + char pOut[2048]; + SQLINTEGER nOutLen; + OTools::ThrowException(N3SQLNativeSql(m_aConnectionHandle,(SDB_ODBC_CHAR*)aSql.getStr(),aSql.getLength(),(SDB_ODBC_CHAR*)pOut,2048,&nOutLen),m_aConnectionHandle,SQL_HANDLE_DBC,*this); + return ::rtl::OUString(pOut,nOutLen,osl_getThreadTextEncoding()); +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::setAutoCommit( sal_Bool autoCommit ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + OTools::ThrowException(N3SQLSetConnectAttr(m_aConnectionHandle, + SQL_ATTR_AUTOCOMMIT, + (SQLPOINTER)((autoCommit) ? SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF) ,SQL_IS_INTEGER), + m_aConnectionHandle,SQL_HANDLE_DBC,*this); +} +// -------------------------------------------------------------------------------- +sal_Bool SAL_CALL OConnection::getAutoCommit( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_uInt32 nOption = 0; + OTools::ThrowException(N3SQLGetConnectAttr(m_aConnectionHandle, + SQL_ATTR_AUTOCOMMIT, &nOption,0,0),m_aConnectionHandle,SQL_HANDLE_DBC,*this); + return nOption == SQL_AUTOCOMMIT_ON ; +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::commit( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + OTools::ThrowException(N3SQLEndTran(SQL_HANDLE_DBC,m_aConnectionHandle,SQL_COMMIT),m_aConnectionHandle,SQL_HANDLE_DBC,*this); +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::rollback( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + OTools::ThrowException(N3SQLEndTran(SQL_HANDLE_DBC,m_aConnectionHandle,SQL_ROLLBACK),m_aConnectionHandle,SQL_HANDLE_DBC,*this); +} +// -------------------------------------------------------------------------------- +sal_Bool SAL_CALL OConnection::isClosed( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + return OConnection_BASE::rBHelper.bDisposed; +} +// -------------------------------------------------------------------------------- +Reference< XDatabaseMetaData > SAL_CALL OConnection::getMetaData( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(!m_xMetaData.is()) + m_xMetaData = new ODatabaseMetaData(m_aConnectionHandle,this); + + return m_xMetaData; +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::setReadOnly( sal_Bool readOnly ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + OTools::ThrowException( + N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_ACCESS_MODE,(SQLPOINTER)readOnly,SQL_IS_INTEGER), + m_aConnectionHandle,SQL_HANDLE_DBC,*this); +} +// -------------------------------------------------------------------------------- +sal_Bool SAL_CALL OConnection::isReadOnly( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_DATA_SOURCE_READ_ONLY,aValue,*this); + return aValue == ::rtl::OUString::createFromAscii("Y"); +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::setCatalog( const ::rtl::OUString& catalog ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + ::rtl::OString aCat(::rtl::OUStringToOString(catalog.getStr(),osl_getThreadTextEncoding())); + OTools::ThrowException( + N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_CURRENT_CATALOG,(SDB_ODBC_CHAR*)aCat.getStr(),SQL_NTS), + m_aConnectionHandle,SQL_HANDLE_DBC,*this); +} +// -------------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OConnection::getCatalog( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_Int32 nValueLen; + char pCat[1024]; + OTools::ThrowException( + N3SQLGetConnectAttr(m_aConnectionHandle,SQL_ATTR_CURRENT_CATALOG,(SDB_ODBC_CHAR*)pCat,1024,&nValueLen), + m_aConnectionHandle,SQL_HANDLE_DBC,*this); + + return ::rtl::OUString(pCat,nValueLen,osl_getThreadTextEncoding()); +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::setTransactionIsolation( sal_Int32 level ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + OTools::ThrowException(N3SQLSetConnectAttr(m_aConnectionHandle, + SQL_ATTR_TXN_ISOLATION, + (SQLPOINTER)level,SQL_IS_INTEGER), + m_aConnectionHandle,SQL_HANDLE_DBC,*this); +} +// -------------------------------------------------------------------------------- +sal_Int32 SAL_CALL OConnection::getTransactionIsolation( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_Int32 nTxn = 0; + SQLINTEGER nValueLen; + OTools::ThrowException( + N3SQLGetConnectAttr(m_aConnectionHandle,SQL_ATTR_TXN_ISOLATION,&nTxn,sizeof nTxn,&nValueLen), + m_aConnectionHandle,SQL_HANDLE_DBC,*this); + return nTxn; +} +// -------------------------------------------------------------------------------- +Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OConnection::getTypeMap( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return NULL; +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::setTypeMap( const Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(SQLException, RuntimeException) +{ +} +// -------------------------------------------------------------------------------- +// XCloseable +void SAL_CALL OConnection::close( ) throw(SQLException, RuntimeException) +{ + { + ::osl::MutexGuard aGuard( m_aMutex ); + if (OConnection_BASE::rBHelper.bDisposed) + throw DisposedException(); + } + dispose(); +} +// -------------------------------------------------------------------------------- +// XWarningsSupplier +Any SAL_CALL OConnection::getWarnings( ) throw(SQLException, RuntimeException) +{ + return Any(); +} +// -------------------------------------------------------------------------------- +void SAL_CALL OConnection::clearWarnings( ) throw(SQLException, RuntimeException) +{ +} +//-------------------------------------------------------------------- +void OConnection::buildTypeInfo() throw( SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + + Reference< XResultSet> xRs = getMetaData ()->getTypeInfo (); + Reference< XRow> xRow(xRs,UNO_QUERY); + // Information for a single SQL type + + // Loop on the result set until we reach end of file + + while (xRs->next ()) + { + OTypeInfo aInfo; + aInfo.aTypeName = xRow->getString (1); + aInfo.nType = xRow->getShort (2); + aInfo.nPrecision = xRow->getInt (3); + aInfo.aLiteralPrefix = xRow->getString (4); + aInfo.aLiteralSuffix = xRow->getString (5); + aInfo.aCreateParams = xRow->getString (6); + aInfo.bNullable = xRow->getBoolean (7) == ColumnValue::NULLABLE; + aInfo.bCaseSensitive = xRow->getBoolean (8); + aInfo.nSearchType = xRow->getShort (9); + aInfo.bUnsigned = xRow->getBoolean (10); + aInfo.bCurrency = xRow->getBoolean (11); + aInfo.bAutoIncrement = xRow->getBoolean (12); + aInfo.aLocalTypeName = xRow->getString (13); + aInfo.nMinimumScale = xRow->getShort (14); + aInfo.nMaximumScale = xRow->getShort (15); + aInfo.nNumPrecRadix = xRow->getInt (18); + + + + // Now that we have the type info, save it + // in the Hashtable if we don't already have an + // entry for this SQL type. + + m_aTypeInfo.push_back(aInfo); + } + + // Close the result set/statement. + + Reference< XCloseable> xClose(xRs,UNO_QUERY); + xClose->close(); +} +//------------------------------------------------------------------------------ +void OConnection::disposing() +{ + ::osl::MutexGuard aGuard(m_aMutex); + + + // m_aTables.disposing(); + for (OWeakRefArray::iterator i = m_aStatements.begin(); m_aStatements.end() != i; ++i) + { + Reference< XComponent > xComp(i->get(), UNO_QUERY); + if (xComp.is()) + xComp->dispose(); + } + m_aStatements.clear(); + + OTools::ThrowException(N3SQLDisconnect(m_aConnectionHandle),m_aConnectionHandle,SQL_HANDLE_DBC,*this); + m_bClosed = sal_True; + m_xMetaData = NULL; + + dispose_ChildImpl(); + OConnection_BASE::disposing(); + +// for (OWeakRefArray::iterator j = m_aComposers.begin(); m_aComposers.end() != j; j++) +// { +// Reference< XComponent > xComp(j->get(), UNO_QUERY); +// if (xComp.is()) +// xComp->dispose(); +// } +// m_aComposers.clear(); +} + + diff --git a/connectivity/source/drivers/odbc/ODatabaseMetaData.cxx b/connectivity/source/drivers/odbc/ODatabaseMetaData.cxx new file mode 100644 index 000000000000..e9b81e3dd70f --- /dev/null +++ b/connectivity/source/drivers/odbc/ODatabaseMetaData.cxx @@ -0,0 +1,1593 @@ +/************************************************************************* + * + * $RCSfile: ODatabaseMetaData.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ODBC_ODATABASEMETADATA_HXX_ +#include "odbc/ODatabaseMetaData.hxx" +#endif +#ifndef _CONNECTIVITY_OTOOLS_HXX_ +#include "odbc/OTools.hxx" +#endif +#ifndef _CONNECTIVITY_ODBC_ORESULTSET_HXX_ +#include "odbc/OResultSet.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_RESULTSETTYPE_HPP_ +#include <com/sun/star/sdbc/ResultSetType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_RESULTSETCONCURRENCY_HPP_ +#include <com/sun/star/sdbc/ResultSetConcurrency.hpp> +#endif +#ifndef _CONNECTIVITY_OFUNCTIONDEFS_HXX_ +#include "odbc/OFunctiondefs.hxx" +#endif + + +using namespace connectivity::odbc; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::sdbc; + +ODatabaseMetaData::ODatabaseMetaData(const SQLHANDLE _pHandle,OConnection* _pCon) + : m_aConnectionHandle(_pHandle),m_pConnection(_pCon) +{ + m_pConnection->acquire(); +} +// ------------------------------------------------------------------------- +ODatabaseMetaData::~ODatabaseMetaData() +{ + if (m_pConnection) + m_pConnection->release(); +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo( ) throw(SQLException, RuntimeException) +{ + SQLHANDLE hStmt; + N3SQLAllocHandle(SQL_HANDLE_STMT,m_pConnection->getConnection(),&hStmt); + + OResultSet* pResult = new OResultSet(hStmt); + Reference< XResultSet > xRef = pResult; + pResult->openTypeInfo(); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getCatalogs( ) throw(SQLException, RuntimeException) +{ + SQLHANDLE hStmt; + N3SQLAllocHandle(SQL_HANDLE_STMT,m_pConnection->getConnection(),&hStmt); + + OResultSet* pResult = new OResultSet(hStmt); + Reference< XResultSet > xRef = pResult; + pResult->openCatalogs(); + return xRef; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getCatalogSeparator( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aVal; + OTools::GetInfo(m_aConnectionHandle,SQL_CATALOG_NAME_SEPARATOR,aVal,*this); + + return aVal; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getSchemas( ) throw(SQLException, RuntimeException) +{ + SQLHANDLE hStmt; + N3SQLAllocHandle(SQL_HANDLE_STMT,m_pConnection->getConnection(),&hStmt); + + OResultSet* pResult = new OResultSet(hStmt); + Reference< XResultSet > xRef = pResult; + pResult->openSchemas(); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumnPrivileges( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, + const ::rtl::OUString& columnNamePattern ) throw(SQLException, RuntimeException) +{ + SQLHANDLE hStmt; + N3SQLAllocHandle(SQL_HANDLE_STMT,m_pConnection->getConnection(),&hStmt); + + OResultSet* pResult = new OResultSet(hStmt); + Reference< XResultSet > xRef = pResult; + pResult->openColumnPrivileges(catalog,schema,table,columnNamePattern); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns( + const Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& tableNamePattern, + const ::rtl::OUString& columnNamePattern ) throw(SQLException, RuntimeException) +{ + SQLHANDLE hStmt; + N3SQLAllocHandle(SQL_HANDLE_STMT,m_pConnection->getConnection(),&hStmt); + + OResultSet* pResult = new OResultSet(hStmt); + Reference< XResultSet > xRef = pResult; + pResult->openColumns(catalog,schemaPattern,tableNamePattern,columnNamePattern); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables( + const Any& catalog, const ::rtl::OUString& schemaPattern, + const ::rtl::OUString& tableNamePattern, const Sequence< ::rtl::OUString >& types ) throw(SQLException, RuntimeException) +{ + SQLHANDLE hStmt; + N3SQLAllocHandle(SQL_HANDLE_STMT,m_pConnection->getConnection(),&hStmt); + + OResultSet* pResult = new OResultSet(hStmt); + Reference< XResultSet > xRef = pResult; + pResult->openTables(catalog,schemaPattern,tableNamePattern,types); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getProcedureColumns( + const Any& catalog, const ::rtl::OUString& schemaPattern, + const ::rtl::OUString& procedureNamePattern, const ::rtl::OUString& columnNamePattern ) throw(SQLException, RuntimeException) +{ + SQLHANDLE hStmt; + N3SQLAllocHandle(SQL_HANDLE_STMT,m_pConnection->getConnection(),&hStmt); + + OResultSet* pResult = new OResultSet(hStmt); + Reference< XResultSet > xRef = pResult; + pResult->openProcedureColumns(catalog,schemaPattern,procedureNamePattern,columnNamePattern); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getProcedures( + const Any& catalog, const ::rtl::OUString& schemaPattern, + const ::rtl::OUString& procedureNamePattern ) throw(SQLException, RuntimeException) +{ + SQLHANDLE hStmt; + N3SQLAllocHandle(SQL_HANDLE_STMT,m_pConnection->getConnection(),&hStmt); + + OResultSet* pResult = new OResultSet(hStmt); + Reference< XResultSet > xRef = pResult; + pResult->openProcedures(catalog,schemaPattern,procedureNamePattern); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getVersionColumns( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + SQLHANDLE hStmt; + N3SQLAllocHandle(SQL_HANDLE_STMT,m_pConnection->getConnection(),&hStmt); + + OResultSet* pResult = new OResultSet(hStmt); + Reference< XResultSet > xRef = pResult; + pResult->openVersionColumns(catalog,schema,table); + return xRef; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxBinaryLiteralLength( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_MAX_BINARY_LITERAL_LEN,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxRowSize( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_MAX_ROW_SIZE,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxCatalogNameLength( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_MAX_CATALOG_NAME_LEN,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxCharLiteralLength( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_MAX_CHAR_LITERAL_LEN,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnNameLength( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_MAX_COLUMN_NAME_LEN,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInIndex( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_MAX_COLUMNS_IN_INDEX,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxCursorNameLength( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_MAX_CURSOR_NAME_LEN,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxConnections( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_ACTIVE_CONNECTIONS,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInTable( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_MAX_COLUMNS_IN_TABLE,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxStatementLength( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_MAX_STATEMENT_LEN,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxTableNameLength( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_MAX_TABLE_NAME_LEN,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxTablesInSelect( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_MAX_TABLES_IN_SELECT,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getExportedKeys( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + SQLHANDLE hStmt; + N3SQLAllocHandle(SQL_HANDLE_STMT,m_pConnection->getConnection(),&hStmt); + + OResultSet* pResult = new OResultSet(hStmt); + Reference< XResultSet > xRef = pResult; + pResult->openExportedKeys(catalog,schema,table); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getImportedKeys( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + SQLHANDLE hStmt; + N3SQLAllocHandle(SQL_HANDLE_STMT,m_pConnection->getConnection(),&hStmt); + + OResultSet* pResult = new OResultSet(hStmt); + Reference< XResultSet > xRef = pResult; + pResult->openImportedKeys(catalog,schema,table); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getPrimaryKeys( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(SQLException, RuntimeException) +{ + SQLHANDLE hStmt; + N3SQLAllocHandle(SQL_HANDLE_STMT,m_pConnection->getConnection(),&hStmt); + + OResultSet* pResult = new OResultSet(hStmt); + Reference< XResultSet > xRef = pResult; + pResult->openPrimaryKeys(catalog,schema,table); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getIndexInfo( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, + sal_Bool unique, sal_Bool approximate ) throw(SQLException, RuntimeException) +{ + SQLHANDLE hStmt; + N3SQLAllocHandle(SQL_HANDLE_STMT,m_pConnection->getConnection(),&hStmt); + + OResultSet* pResult = new OResultSet(hStmt); + Reference< XResultSet > xRef = pResult; + pResult->openIndexInfo(catalog,schema,table,unique,approximate); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getBestRowIdentifier( + const Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, sal_Int32 scope, + sal_Bool nullable ) throw(SQLException, RuntimeException) +{ + SQLHANDLE hStmt; + N3SQLAllocHandle(SQL_HANDLE_STMT,m_pConnection->getConnection(),&hStmt); + + OResultSet* pResult = new OResultSet(hStmt); + Reference< XResultSet > xRef = pResult; + pResult->openBestRowIdentifier(catalog,schema,table,scope,nullable); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges( + const Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& tableNamePattern ) throw(SQLException, RuntimeException) +{ + SQLHANDLE hStmt; + N3SQLAllocHandle(SQL_HANDLE_STMT,m_pConnection->getConnection(),&hStmt); + + OResultSet* pResult = new OResultSet(hStmt); + Reference< XResultSet > xRef = pResult; + pResult->openTablePrivileges(catalog,schemaPattern,tableNamePattern); + return xRef; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getCrossReference( + const Any& primaryCatalog, const ::rtl::OUString& primarySchema, + const ::rtl::OUString& primaryTable, const Any& foreignCatalog, + const ::rtl::OUString& foreignSchema, const ::rtl::OUString& foreignTable ) throw(SQLException, RuntimeException) +{ + SQLHANDLE hStmt; + N3SQLAllocHandle(SQL_HANDLE_STMT,m_pConnection->getConnection(),&hStmt); + + OResultSet* pResult = new OResultSet(hStmt); + Reference< XResultSet > xRef = pResult; + pResult->openForeignKeys(primaryCatalog,primarySchema.toChar() == '%' ? &primarySchema : NULL,&primaryTable, + foreignCatalog, foreignSchema.toChar() == '%' ? &foreignSchema : NULL,&foreignTable); + return xRef; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::doesMaxRowSizeIncludeBlobs( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aVal; + OTools::GetInfo(m_aConnectionHandle,SQL_MAX_ROW_SIZE_INCLUDES_LONG,aVal,*this); + return aVal.toChar() == 'Y'; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesLowerCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_QUOTED_IDENTIFIER_CASE,nValue,*this); + return nValue == SQL_IC_LOWER; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesLowerCaseIdentifiers( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_IDENTIFIER_CASE,nValue,*this); + return nValue == SQL_IC_LOWER; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesMixedCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_QUOTED_IDENTIFIER_CASE,nValue,*this); + return nValue == SQL_IC_MIXED; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesMixedCaseIdentifiers( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_IDENTIFIER_CASE,nValue,*this); + return nValue == SQL_IC_MIXED; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesUpperCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_QUOTED_IDENTIFIER_CASE,nValue,*this); + return nValue == SQL_IC_UPPER; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::storesUpperCaseIdentifiers( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_IDENTIFIER_CASE,nValue,*this); + return nValue == SQL_IC_UPPER; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsAlterTableWithAddColumn( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_ALTER_TABLE,nValue,*this); + return nValue == SQL_AT_ADD_COLUMN; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsAlterTableWithDropColumn( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_ALTER_TABLE,nValue,*this); + return nValue == SQL_AT_DROP_COLUMN; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxIndexLength( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_MAX_INDEX_SIZE,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsNonNullableColumns( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_NON_NULLABLE_COLUMNS,nValue,*this); + return nValue == SQL_NNC_NON_NULL; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getCatalogTerm( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aVal; + OTools::GetInfo(m_aConnectionHandle,SQL_CATALOG_TERM,aVal,*this); + return aVal; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getIdentifierQuoteString( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aVal; + OTools::GetInfo(m_aConnectionHandle,SQL_IDENTIFIER_QUOTE_CHAR,aVal,*this); + return aVal; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getExtraNameCharacters( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aVal; + OTools::GetInfo(m_aConnectionHandle,SQL_SPECIAL_CHARACTERS,aVal,*this); + return aVal; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsDifferentTableCorrelationNames( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_CORRELATION_NAME,nValue,*this); + return nValue != SQL_CN_NONE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::isCatalogAtStart( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_CATALOG_LOCATION,nValue,*this); + return nValue == SQL_CL_START; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::dataDefinitionIgnoredInTransactions( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_TXN_CAPABLE,nValue,*this); + return nValue == SQL_TC_DDL_IGNORE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::dataDefinitionCausesTransactionCommit( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_TXN_CAPABLE,nValue,*this); + return nValue == SQL_TC_DDL_COMMIT; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsDataManipulationTransactionsOnly( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_TXN_CAPABLE,nValue,*this); + return nValue == SQL_TC_DML; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsDataDefinitionAndDataManipulationTransactions( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_TXN_CAPABLE,nValue,*this); + return nValue == SQL_TC_ALL; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsPositionedDelete( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_DYNAMIC_CURSOR_ATTRIBUTES1,nValue,*this); + return (nValue & SQL_CA1_POS_DELETE) == SQL_CA1_POS_DELETE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsPositionedUpdate( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_DYNAMIC_CURSOR_ATTRIBUTES1,nValue,*this); + return (nValue & SQL_CA1_POS_UPDATE) == SQL_CA1_POS_UPDATE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenStatementsAcrossRollback( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_CURSOR_ROLLBACK_BEHAVIOR,nValue,*this); + return nValue == SQL_CB_PRESERVE || nValue == SQL_CB_CLOSE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenStatementsAcrossCommit( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_CURSOR_COMMIT_BEHAVIOR,nValue,*this); + return nValue == SQL_CB_PRESERVE || nValue == SQL_CB_CLOSE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenCursorsAcrossCommit( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_CURSOR_COMMIT_BEHAVIOR,nValue,*this); + return nValue == SQL_CB_PRESERVE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenCursorsAcrossRollback( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_CURSOR_ROLLBACK_BEHAVIOR,nValue,*this); + return nValue == SQL_CB_PRESERVE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsTransactionIsolationLevel( sal_Int32 level ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_TXN_ISOLATION_OPTION,nValue,*this); + return (nValue & level) == level; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInDataManipulation( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_SCHEMA_USAGE,nValue,*this); + return (nValue & SQL_SU_DML_STATEMENTS) == SQL_SU_DML_STATEMENTS; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsANSI92FullSQL( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_SQL_CONFORMANCE,nValue,*this); + return nValue == SQL_SC_SQL92_FULL; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsANSI92EntryLevelSQL( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_SQL_CONFORMANCE,nValue,*this); + return nValue == SQL_SC_SQL92_ENTRY; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsIntegrityEnhancementFacility( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aStr; + OTools::GetInfo(m_aConnectionHandle,SQL_INTEGRITY,aStr,*this); + return aStr.toChar() == 'Y'; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInIndexDefinitions( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_SCHEMA_USAGE,nValue,*this); + return (nValue & SQL_SU_INDEX_DEFINITION) == SQL_SU_INDEX_DEFINITION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInTableDefinitions( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_SCHEMA_USAGE,nValue,*this); + return (nValue & SQL_SU_TABLE_DEFINITION) == SQL_SU_TABLE_DEFINITION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInTableDefinitions( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_CATALOG_USAGE,nValue,*this); + return (nValue & SQL_CU_TABLE_DEFINITION) == SQL_CU_TABLE_DEFINITION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInIndexDefinitions( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_CATALOG_USAGE,nValue,*this); + return (nValue & SQL_CU_INDEX_DEFINITION) == SQL_CU_INDEX_DEFINITION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInDataManipulation( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_CATALOG_USAGE,nValue,*this); + return (nValue & SQL_CU_DML_STATEMENTS) == SQL_CU_DML_STATEMENTS; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOuterJoins( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_OJ_CAPABILITIES,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTableTypes( ) throw(SQLException, RuntimeException) +{ + SQLHANDLE hStmt; + N3SQLAllocHandle(SQL_HANDLE_STMT,m_pConnection->getConnection(),&hStmt); + + OResultSet* pResult = new OResultSet(hStmt); + Reference< XResultSet > xRef = pResult; + pResult->openTablesTypes(); + return xRef; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxStatements( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_MAX_CONCURRENT_ACTIVITIES,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxProcedureNameLength( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_MAX_PROCEDURE_NAME_LEN,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxSchemaNameLength( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_MAX_SCHEMA_NAME_LEN,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsTransactions( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_TXN_CAPABLE,nValue,*this); + return nValue != SQL_TC_NONE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::allProceduresAreCallable( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_ACCESSIBLE_PROCEDURES,aValue,*this); + return aValue.toChar() == 'Y'; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsStoredProcedures( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_PROCEDURES,aValue,*this); + return aValue.toChar() == 'Y'; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSelectForUpdate( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_DYNAMIC_CURSOR_ATTRIBUTES1,nValue,*this); + return (nValue & SQL_CA1_POSITIONED_UPDATE) == SQL_CA1_POSITIONED_UPDATE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::allTablesAreSelectable( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_ACCESSIBLE_TABLES,aValue,*this); + return aValue.toChar() == 'Y'; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::isReadOnly( ) throw(SQLException, RuntimeException) +{ + sal_Bool bValue; + OTools::GetInfo(m_aConnectionHandle,SQL_DATA_SOURCE_READ_ONLY,bValue,*this); + return bValue; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::usesLocalFiles( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_FILE_USAGE,nValue,*this); + return nValue == SQL_FILE_CATALOG; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::usesLocalFilePerTable( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_FILE_USAGE,nValue,*this); + return nValue == SQL_FILE_TABLE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsTypeConversion( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_CONVERT_FUNCTIONS,nValue,*this); + return (nValue & SQL_FN_CVT_CONVERT) == SQL_FN_CVT_CONVERT; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::nullPlusNonNullIsNull( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_CONCAT_NULL_BEHAVIOR,nValue,*this); + return nValue == SQL_CB_NULL; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsColumnAliasing( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_COLUMN_ALIAS,aValue,*this); + return aValue.toChar() == 'Y'; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsTableCorrelationNames( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_CORRELATION_NAME,nValue,*this); + return nValue != SQL_CN_NONE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsConvert( sal_Int32 fromType, sal_Int32 toType ) throw(SQLException, RuntimeException) +{ + if(fromType == toType) + return sal_True; + + sal_Int32 nValue=0; + switch(fromType) + { + case DataType::BIT: + OTools::GetInfo(m_aConnectionHandle,SQL_CONVERT_BIT,nValue,*this); + break; + case DataType::TINYINT: + OTools::GetInfo(m_aConnectionHandle,SQL_CONVERT_TINYINT,nValue,*this); + break; + case DataType::SMALLINT: + OTools::GetInfo(m_aConnectionHandle,SQL_CONVERT_SMALLINT,nValue,*this); + break; + case DataType::INTEGER: + OTools::GetInfo(m_aConnectionHandle,SQL_CONVERT_INTEGER,nValue,*this); + break; + case DataType::BIGINT: + OTools::GetInfo(m_aConnectionHandle,SQL_CONVERT_BIGINT,nValue,*this); + break; + case DataType::FLOAT: + OTools::GetInfo(m_aConnectionHandle,SQL_CONVERT_FLOAT,nValue,*this); + break; + case DataType::REAL: + OTools::GetInfo(m_aConnectionHandle,SQL_CONVERT_REAL,nValue,*this); + break; + case DataType::DOUBLE: + OTools::GetInfo(m_aConnectionHandle,SQL_CONVERT_DOUBLE,nValue,*this); + break; + case DataType::NUMERIC: + OTools::GetInfo(m_aConnectionHandle,SQL_CONVERT_NUMERIC,nValue,*this); + break; + case DataType::DECIMAL: + OTools::GetInfo(m_aConnectionHandle,SQL_CONVERT_DECIMAL,nValue,*this); + break; + case DataType::CHAR: + OTools::GetInfo(m_aConnectionHandle,SQL_CONVERT_CHAR,nValue,*this); + break; + case DataType::VARCHAR: + OTools::GetInfo(m_aConnectionHandle,SQL_CONVERT_VARCHAR,nValue,*this); + break; + case DataType::LONGVARCHAR: + OTools::GetInfo(m_aConnectionHandle,SQL_CONVERT_LONGVARCHAR,nValue,*this); + break; + case DataType::DATE: + OTools::GetInfo(m_aConnectionHandle,SQL_CONVERT_DATE,nValue,*this); + break; + case DataType::TIME: + OTools::GetInfo(m_aConnectionHandle,SQL_CONVERT_TIME,nValue,*this); + break; + case DataType::TIMESTAMP: + OTools::GetInfo(m_aConnectionHandle,SQL_CONVERT_TIMESTAMP,nValue,*this); + break; + case DataType::BINARY: + OTools::GetInfo(m_aConnectionHandle,SQL_CONVERT_BINARY,nValue,*this); + break; + case DataType::VARBINARY: + OTools::GetInfo(m_aConnectionHandle,SQL_CONVERT_VARBINARY,nValue,*this); + break; + case DataType::LONGVARBINARY: + OTools::GetInfo(m_aConnectionHandle,SQL_CONVERT_LONGVARBINARY,nValue,*this); + break; + case DataType::SQLNULL: + // OTools::GetInfo(m_aConnectionHandle,SQL_CORRELATION_NAME,nValue,*this); + break; + case DataType::OTHER: + // OTools::GetInfo(m_aConnectionHandle,SQL_CORRELATION_NAME,nValue,*this); + break; + case DataType::OBJECT: + // OTools::GetInfo(m_aConnectionHandle,SQL_CORRELATION_NAME,nValue,*this); + break; + case DataType::DISTINCT: + // OTools::GetInfo(m_aConnectionHandle,SQL_CORRELATION_NAME,nValue,*this); + break; + case DataType::STRUCT: + // OTools::GetInfo(m_aConnectionHandle,SQL_CORRELATION_NAME,nValue,*this); + break; + case DataType::ARRAY: + // OTools::GetInfo(m_aConnectionHandle,SQL_CORRELATION_NAME,nValue,*this); + break; + case DataType::BLOB: + // OTools::GetInfo(m_aConnectionHandle,SQL_CORRELATION_NAME,nValue,*this); + break; + case DataType::CLOB: + // OTools::GetInfo(m_aConnectionHandle,SQL_CORRELATION_NAME,nValue,*this); + break; + case DataType::REF: + // OTools::GetInfo(m_aConnectionHandle,SQL_CORRELATION_NAME,nValue,*this); + break; + } + sal_Bool bConvert = sal_False; + switch(toType) + { + case DataType::BIT: + bConvert = (nValue & SQL_CVT_BIT) == SQL_CVT_BIT; + break; + case DataType::TINYINT: + bConvert = (nValue & SQL_CVT_TINYINT) == SQL_CVT_TINYINT; + break; + case DataType::SMALLINT: + bConvert = (nValue & SQL_CVT_SMALLINT) == SQL_CVT_SMALLINT; + break; + case DataType::INTEGER: + bConvert = (nValue & SQL_CVT_INTEGER) == SQL_CVT_INTEGER; + break; + case DataType::BIGINT: + bConvert = (nValue & SQL_CVT_BIGINT) == SQL_CVT_BIGINT; + break; + case DataType::FLOAT: + bConvert = (nValue & SQL_CVT_FLOAT) == SQL_CVT_FLOAT; + break; + case DataType::REAL: + bConvert = (nValue & SQL_CVT_REAL) == SQL_CVT_REAL; + break; + case DataType::DOUBLE: + bConvert = (nValue & SQL_CVT_DOUBLE) == SQL_CVT_DOUBLE; + break; + case DataType::NUMERIC: + bConvert = (nValue & SQL_CVT_NUMERIC) == SQL_CVT_NUMERIC; + break; + case DataType::DECIMAL: + bConvert = (nValue & SQL_CVT_DECIMAL) == SQL_CVT_DECIMAL; + break; + case DataType::CHAR: + bConvert = (nValue & SQL_CVT_CHAR) == SQL_CVT_CHAR; + break; + case DataType::VARCHAR: + bConvert = (nValue & SQL_CVT_VARCHAR) == SQL_CVT_VARCHAR; + break; + case DataType::LONGVARCHAR: + bConvert = (nValue & SQL_CVT_LONGVARCHAR) == SQL_CVT_LONGVARCHAR; + break; + case DataType::DATE: + bConvert = (nValue & SQL_CVT_DATE) == SQL_CVT_DATE; + break; + case DataType::TIME: + bConvert = (nValue & SQL_CVT_TIME) == SQL_CVT_TIME; + break; + case DataType::TIMESTAMP: + bConvert = (nValue & SQL_CVT_TIMESTAMP) == SQL_CVT_TIMESTAMP; + break; + case DataType::BINARY: + bConvert = (nValue & SQL_CVT_BINARY) == SQL_CVT_BINARY; + break; + case DataType::VARBINARY: + bConvert = (nValue & SQL_CVT_VARBINARY) == SQL_CVT_VARBINARY; + break; + case DataType::LONGVARBINARY: + bConvert = (nValue & SQL_CVT_LONGVARBINARY) == SQL_CVT_LONGVARBINARY; + break; + } + + return bConvert; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsExpressionsInOrderBy( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_EXPRESSIONS_IN_ORDERBY,aValue,*this); + return aValue.toChar() == 'Y'; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsGroupBy( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_GROUP_BY,nValue,*this); + return nValue != SQL_GB_NOT_SUPPORTED; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsGroupByBeyondSelect( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_GROUP_BY,nValue,*this); + return nValue != SQL_GB_GROUP_BY_CONTAINS_SELECT; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsGroupByUnrelated( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_GROUP_BY,nValue,*this); + return nValue == SQL_GB_NO_RELATION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsMultipleTransactions( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_MULTIPLE_ACTIVE_TXN,aValue,*this); + return aValue.toChar() == 'Y'; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsMultipleResultSets( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_MULT_RESULT_SETS,aValue,*this); + return aValue.toChar() == 'Y'; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsLikeEscapeClause( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_LIKE_ESCAPE_CLAUSE,aValue,*this); + return aValue.toChar() == 'Y'; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsOrderByUnrelated( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_ORDER_BY_COLUMNS_IN_SELECT,aValue,*this); + return aValue.toChar() == 'N'; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsUnion( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_UNION,nValue,*this); + return (nValue & SQL_U_UNION) == SQL_U_UNION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsUnionAll( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_UNION,nValue,*this); + return (nValue & SQL_U_UNION_ALL) == SQL_U_UNION_ALL; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsMixedCaseIdentifiers( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_IDENTIFIER_CASE,nValue,*this); + return nValue == SQL_IC_MIXED; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsMixedCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_QUOTED_IDENTIFIER_CASE,nValue,*this); + return nValue == SQL_IC_MIXED; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedAtEnd( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_NULL_COLLATION,nValue,*this); + return nValue == SQL_NC_END; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedAtStart( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_NULL_COLLATION,nValue,*this); + return nValue == SQL_NC_START; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedHigh( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_NULL_COLLATION,nValue,*this); + return nValue == SQL_NC_HIGH; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedLow( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_NULL_COLLATION,nValue,*this); + return nValue == SQL_NC_LOW; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInProcedureCalls( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_SCHEMA_USAGE,nValue,*this); + return nValue & SQL_SU_PROCEDURE_INVOCATION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInPrivilegeDefinitions( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_SCHEMA_USAGE,nValue,*this); + return nValue & SQL_SU_PRIVILEGE_DEFINITION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInProcedureCalls( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_CATALOG_USAGE,nValue,*this); + return nValue & SQL_CU_PROCEDURE_INVOCATION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInPrivilegeDefinitions( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_CATALOG_USAGE,nValue,*this); + return nValue & SQL_CU_PRIVILEGE_DEFINITION; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCorrelatedSubqueries( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_SUBQUERIES,nValue,*this); + return (nValue & SQL_SQ_CORRELATED_SUBQUERIES) == SQL_SQ_CORRELATED_SUBQUERIES; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInComparisons( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_SUBQUERIES,nValue,*this); + return (nValue & SQL_SQ_COMPARISON) == SQL_SQ_COMPARISON; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInExists( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_SUBQUERIES,nValue,*this); + return (nValue & SQL_SQ_EXISTS) == SQL_SQ_EXISTS; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInIns( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_SUBQUERIES,nValue,*this); + return (nValue & SQL_SQ_IN) == SQL_SQ_IN; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInQuantifieds( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_SUBQUERIES,nValue,*this); + return (nValue & SQL_SQ_QUANTIFIED) == SQL_SQ_QUANTIFIED; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsANSI92IntermediateSQL( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_SQL_CONFORMANCE,nValue,*this); + return nValue == SQL_SC_SQL92_INTERMEDIATE; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getURL( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue = ::rtl::OUString::createFromAscii("sdbc:odbc:"); + OTools::GetInfo(m_aConnectionHandle,SQL_DATA_SOURCE_NAME,aValue,*this); + return aValue; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getUserName( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_USER_NAME,aValue,*this); + return aValue; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getDriverName( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_DRIVER_NAME,aValue,*this); + return aValue; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getDriverVersion( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_DRIVER_ODBC_VER,aValue,*this); + return aValue; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getDatabaseProductVersion( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_DRIVER_VER,aValue,*this); + return aValue; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getDatabaseProductName( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_DBMS_NAME,aValue,*this); + return aValue; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getProcedureTerm( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_PROCEDURE_TERM,aValue,*this); + return aValue; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getSchemaTerm( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_SCHEMA_TERM,aValue,*this); + return aValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getDriverMajorVersion( ) throw(RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_DRIVER_VER,aValue,*this); + return aValue.copy(0,aValue.indexOf('.')).toInt32(); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getDefaultTransactionIsolation( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_SUBQUERIES,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getDriverMinorVersion( ) throw(RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_DRIVER_VER,aValue,*this); + return aValue.copy(0,aValue.lastIndexOf('.')).toInt32(); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getSQLKeywords( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_KEYWORDS,aValue,*this); + return aValue; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getSearchStringEscape( ) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_SEARCH_PATTERN_ESCAPE,aValue,*this); + return aValue; +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getStringFunctions( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_STRING_FUNCTIONS,nValue,*this); + if(nValue & SQL_FN_STR_ASCII) + aValue = ::rtl::OUString::createFromAscii("ASCII,"); + if(nValue & SQL_FN_STR_BIT_LENGTH) + aValue += ::rtl::OUString::createFromAscii("BIT_LENGTH,"); + if(nValue & SQL_FN_STR_CHAR) + aValue += ::rtl::OUString::createFromAscii("CHAR,"); + if(nValue & SQL_FN_STR_CHAR_LENGTH) + aValue += ::rtl::OUString::createFromAscii("CHAR_LENGTH,"); + if(nValue & SQL_FN_STR_CHARACTER_LENGTH) + aValue += ::rtl::OUString::createFromAscii("CHARACTER_LENGTH,"); + if(nValue & SQL_FN_STR_CONCAT) + aValue += ::rtl::OUString::createFromAscii("CONCAT,"); + if(nValue & SQL_FN_STR_DIFFERENCE) + aValue += ::rtl::OUString::createFromAscii("DIFFERENCE,"); + if(nValue & SQL_FN_STR_INSERT) + aValue += ::rtl::OUString::createFromAscii("INSERT,"); + if(nValue & SQL_FN_STR_LCASE) + aValue += ::rtl::OUString::createFromAscii("LCASE,"); + if(nValue & SQL_FN_STR_LEFT) + aValue += ::rtl::OUString::createFromAscii("LEFT,"); + if(nValue & SQL_FN_STR_LENGTH) + aValue += ::rtl::OUString::createFromAscii("LENGTH,"); + if(nValue & SQL_FN_STR_LOCATE) + aValue += ::rtl::OUString::createFromAscii("LOCATE,"); + if(nValue & SQL_FN_STR_LOCATE_2) + aValue += ::rtl::OUString::createFromAscii("LOCATE_2,"); + if(nValue & SQL_FN_STR_LTRIM) + aValue += ::rtl::OUString::createFromAscii("LTRIM,"); + if(nValue & SQL_FN_STR_OCTET_LENGTH) + aValue += ::rtl::OUString::createFromAscii("OCTET_LENGTH,"); + if(nValue & SQL_FN_STR_POSITION) + aValue += ::rtl::OUString::createFromAscii("POSITION,"); + if(nValue & SQL_FN_STR_REPEAT) + aValue += ::rtl::OUString::createFromAscii("REPEAT,"); + if(nValue & SQL_FN_STR_REPLACE) + aValue += ::rtl::OUString::createFromAscii("REPLACE,"); + if(nValue & SQL_FN_STR_RIGHT) + aValue += ::rtl::OUString::createFromAscii("RIGHT,"); + if(nValue & SQL_FN_STR_RTRIM) + aValue += ::rtl::OUString::createFromAscii("RTRIM,"); + if(nValue & SQL_FN_STR_SOUNDEX) + aValue += ::rtl::OUString::createFromAscii("SOUNDEX,"); + if(nValue & SQL_FN_STR_SPACE) + aValue += ::rtl::OUString::createFromAscii("SPACE,"); + if(nValue & SQL_FN_STR_SUBSTRING) + aValue += ::rtl::OUString::createFromAscii("SUBSTRING,"); + if(nValue & SQL_FN_STR_UCASE) + aValue += ::rtl::OUString::createFromAscii("UCASE,"); + + + return aValue.copy(0,aValue.lastIndexOf(',')); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getTimeDateFunctions( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_TIMEDATE_FUNCTIONS,nValue,*this); + + if(nValue & SQL_FN_TD_CURRENT_DATE) + aValue = ::rtl::OUString::createFromAscii("CURRENT_DATE,"); + if(nValue & SQL_FN_TD_CURRENT_TIME) + aValue += ::rtl::OUString::createFromAscii("CURRENT_TIME,"); + if(nValue & SQL_FN_TD_CURRENT_TIMESTAMP) + aValue += ::rtl::OUString::createFromAscii("CURRENT_TIMESTAMP,"); + if(nValue & SQL_FN_TD_CURDATE) + aValue += ::rtl::OUString::createFromAscii("CURDATE,"); + if(nValue & SQL_FN_TD_CURTIME) + aValue += ::rtl::OUString::createFromAscii("CURTIME,"); + if(nValue & SQL_FN_TD_DAYNAME) + aValue += ::rtl::OUString::createFromAscii("DAYNAME,"); + if(nValue & SQL_FN_TD_DAYOFMONTH) + aValue += ::rtl::OUString::createFromAscii("DAYOFMONTH,"); + if(nValue & SQL_FN_TD_DAYOFWEEK) + aValue += ::rtl::OUString::createFromAscii("DAYOFWEEK,"); + if(nValue & SQL_FN_TD_DAYOFYEAR) + aValue += ::rtl::OUString::createFromAscii("DAYOFYEAR,"); + if(nValue & SQL_FN_TD_EXTRACT) + aValue += ::rtl::OUString::createFromAscii("EXTRACT,"); + if(nValue & SQL_FN_TD_HOUR) + aValue += ::rtl::OUString::createFromAscii("HOUR,"); + if(nValue & SQL_FN_TD_MINUTE) + aValue += ::rtl::OUString::createFromAscii("MINUTE,"); + if(nValue & SQL_FN_TD_MONTH) + aValue += ::rtl::OUString::createFromAscii("MONTH,"); + if(nValue & SQL_FN_TD_MONTHNAME) + aValue += ::rtl::OUString::createFromAscii("MONTHNAME,"); + if(nValue & SQL_FN_TD_NOW) + aValue += ::rtl::OUString::createFromAscii("NOW,"); + if(nValue & SQL_FN_TD_QUARTER) + aValue += ::rtl::OUString::createFromAscii("QUARTER,"); + if(nValue & SQL_FN_TD_SECOND) + aValue += ::rtl::OUString::createFromAscii("SECOND,"); + if(nValue & SQL_FN_TD_TIMESTAMPADD) + aValue += ::rtl::OUString::createFromAscii("TIMESTAMPADD,"); + if(nValue & SQL_FN_TD_TIMESTAMPDIFF) + aValue += ::rtl::OUString::createFromAscii("TIMESTAMPDIFF,"); + if(nValue & SQL_FN_TD_WEEK) + aValue += ::rtl::OUString::createFromAscii("WEEK,"); + if(nValue & SQL_FN_TD_YEAR) + aValue += ::rtl::OUString::createFromAscii("YEAR,"); + + return aValue.copy(0,aValue.lastIndexOf(',')); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getSystemFunctions( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_SYSTEM_FUNCTIONS,nValue,*this); + + if(nValue & SQL_FN_SYS_DBNAME) + aValue += ::rtl::OUString::createFromAscii("DBNAME,"); + if(nValue & SQL_FN_SYS_IFNULL) + aValue += ::rtl::OUString::createFromAscii("IFNULL,"); + if(nValue & SQL_FN_SYS_USERNAME) + aValue += ::rtl::OUString::createFromAscii("USERNAME,"); + + return aValue.copy(0,aValue.lastIndexOf(',')); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ODatabaseMetaData::getNumericFunctions( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + ::rtl::OUString aValue; + OTools::GetInfo(m_aConnectionHandle,SQL_NUMERIC_FUNCTIONS,nValue,*this); + + if(nValue & SQL_FN_NUM_ABS) + aValue += ::rtl::OUString::createFromAscii("ABS,"); + if(nValue & SQL_FN_NUM_ACOS) + aValue += ::rtl::OUString::createFromAscii("ACOS,"); + if(nValue & SQL_FN_NUM_ASIN) + aValue += ::rtl::OUString::createFromAscii("ASIN,"); + if(nValue & SQL_FN_NUM_ATAN) + aValue += ::rtl::OUString::createFromAscii("ATAN,"); + if(nValue & SQL_FN_NUM_ATAN2) + aValue += ::rtl::OUString::createFromAscii("ATAN2,"); + if(nValue & SQL_FN_NUM_CEILING) + aValue += ::rtl::OUString::createFromAscii("CEILING,"); + if(nValue & SQL_FN_NUM_COS) + aValue += ::rtl::OUString::createFromAscii("COS,"); + if(nValue & SQL_FN_NUM_COT) + aValue += ::rtl::OUString::createFromAscii("COT,"); + if(nValue & SQL_FN_NUM_DEGREES) + aValue += ::rtl::OUString::createFromAscii("DEGREES,"); + if(nValue & SQL_FN_NUM_EXP) + aValue += ::rtl::OUString::createFromAscii("EXP,"); + if(nValue & SQL_FN_NUM_FLOOR) + aValue += ::rtl::OUString::createFromAscii("FLOOR,"); + if(nValue & SQL_FN_NUM_LOG) + aValue += ::rtl::OUString::createFromAscii("LOGF,"); + if(nValue & SQL_FN_NUM_LOG10) + aValue += ::rtl::OUString::createFromAscii("LOG10,"); + if(nValue & SQL_FN_NUM_MOD) + aValue += ::rtl::OUString::createFromAscii("MOD,"); + if(nValue & SQL_FN_NUM_PI) + aValue += ::rtl::OUString::createFromAscii("PI,"); + if(nValue & SQL_FN_NUM_POWER) + aValue += ::rtl::OUString::createFromAscii("POWER,"); + if(nValue & SQL_FN_NUM_RADIANS) + aValue += ::rtl::OUString::createFromAscii("RADIANS,"); + if(nValue & SQL_FN_NUM_RAND) + aValue += ::rtl::OUString::createFromAscii("RAND,"); + if(nValue & SQL_FN_NUM_ROUND) + aValue += ::rtl::OUString::createFromAscii("ROUND,"); + if(nValue & SQL_FN_NUM_SIGN) + aValue += ::rtl::OUString::createFromAscii("SIGN,"); + if(nValue & SQL_FN_NUM_SIN) + aValue += ::rtl::OUString::createFromAscii("SIN,"); + if(nValue & SQL_FN_NUM_SQRT) + aValue += ::rtl::OUString::createFromAscii("SQRT,"); + if(nValue & SQL_FN_NUM_TAN) + aValue += ::rtl::OUString::createFromAscii("TAN,"); + if(nValue & SQL_FN_NUM_TRUNCATE) + aValue += ::rtl::OUString::createFromAscii("TRUNCATE,"); + + + return aValue.copy(0,aValue.lastIndexOf(',')); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsExtendedSQLGrammar( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_ODBC_INTERFACE_CONFORMANCE,nValue,*this); + return nValue == SQL_OIC_LEVEL2; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsCoreSQLGrammar( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_ODBC_INTERFACE_CONFORMANCE,nValue,*this); + return nValue == SQL_OIC_CORE; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsMinimumSQLGrammar( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_ODBC_INTERFACE_CONFORMANCE,nValue,*this); + return nValue == SQL_OIC_LEVEL1; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsFullOuterJoins( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_OJ_CAPABILITIES,nValue,*this); + return (nValue & SQL_OJ_FULL) == SQL_OJ_FULL; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsLimitedOuterJoins( ) throw(SQLException, RuntimeException) +{ + return supportsFullOuterJoins( ); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInGroupBy( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_MAX_COLUMNS_IN_GROUP_BY,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInOrderBy( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_MAX_COLUMNS_IN_ORDER_BY,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInSelect( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_MAX_COLUMNS_IN_SELECT,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODatabaseMetaData::getMaxUserNameLength( ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_MAX_USER_NAME_LEN,nValue,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsResultSetType( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + OTools::GetInfo(m_aConnectionHandle,SQL_CURSOR_SENSITIVITY,nValue,*this); + return (nValue & setType) == setType; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsResultSetConcurrency( sal_Int32 setType, sal_Int32 concurrency ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + SQLUSMALLINT nAskFor; + switch(setType) + { + case ResultSetType::FORWARD_ONLY: + nAskFor = SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2; + break; + case ResultSetType::SCROLL_INSENSITIVE: + nAskFor = SQL_STATIC_CURSOR_ATTRIBUTES2; + break; + case ResultSetType::SCROLL_SENSITIVE: + nAskFor = SQL_DYNAMIC_CURSOR_ATTRIBUTES2; + break; + } + + OTools::GetInfo(m_aConnectionHandle,nAskFor,nValue,*this); + sal_Bool bRet = sal_False; + switch(concurrency) + { + case ResultSetConcurrency::READ_ONLY: + bRet = (nValue & SQL_CA2_READ_ONLY_CONCURRENCY) == SQL_CA2_READ_ONLY_CONCURRENCY; + break; + case ResultSetConcurrency::UPDATABLE: + bRet = (nValue & SQL_CA2_OPT_VALUES_CONCURRENCY) == SQL_CA2_OPT_VALUES_CONCURRENCY; + break; + } + return bRet; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::ownUpdatesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + SQLUSMALLINT nAskFor; + switch(setType) + { + case ResultSetType::FORWARD_ONLY: + nAskFor = SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2; + break; + case ResultSetType::SCROLL_INSENSITIVE: + nAskFor = SQL_STATIC_CURSOR_ATTRIBUTES2; + break; + case ResultSetType::SCROLL_SENSITIVE: + nAskFor = SQL_DYNAMIC_CURSOR_ATTRIBUTES2; + break; + } + + OTools::GetInfo(m_aConnectionHandle,nAskFor,nValue,*this); + return (nValue & SQL_CA2_SENSITIVITY_UPDATES) == SQL_CA2_SENSITIVITY_UPDATES; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::ownDeletesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + SQLUSMALLINT nAskFor; + switch(setType) + { + case ResultSetType::FORWARD_ONLY: + nAskFor = SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2; + break; + case ResultSetType::SCROLL_INSENSITIVE: + nAskFor = SQL_STATIC_CURSOR_ATTRIBUTES2; + break; + case ResultSetType::SCROLL_SENSITIVE: + nAskFor = SQL_DYNAMIC_CURSOR_ATTRIBUTES2; + break; + } + + OTools::GetInfo(m_aConnectionHandle,nAskFor,nValue,*this); + return (nValue & SQL_CA2_SENSITIVITY_DELETIONS) == SQL_CA2_SENSITIVITY_DELETIONS; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::ownInsertsAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + sal_Int32 nValue; + SQLUSMALLINT nAskFor; + switch(setType) + { + case ResultSetType::FORWARD_ONLY: + nAskFor = SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2; + break; + case ResultSetType::SCROLL_INSENSITIVE: + nAskFor = SQL_STATIC_CURSOR_ATTRIBUTES2; + break; + case ResultSetType::SCROLL_SENSITIVE: + nAskFor = SQL_DYNAMIC_CURSOR_ATTRIBUTES2; + break; + } + + OTools::GetInfo(m_aConnectionHandle,nAskFor,nValue,*this); + return (nValue & SQL_CA2_SENSITIVITY_ADDITIONS) == SQL_CA2_SENSITIVITY_ADDITIONS; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::othersUpdatesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + return ownUpdatesAreVisible(setType); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::othersDeletesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + return ownDeletesAreVisible(setType); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::othersInsertsAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + return ownInsertsAreVisible(setType); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::updatesAreDetected( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::deletesAreDetected( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::insertsAreDetected( sal_Int32 setType ) throw(SQLException, RuntimeException) +{ + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL ODatabaseMetaData::supportsBatchUpdates( ) throw(SQLException, RuntimeException) +{ + return sal_False; +} +// ------------------------------------------------------------------------- +Reference< XResultSet > SAL_CALL ODatabaseMetaData::getUDTs( const Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& typeNamePattern, const Sequence< sal_Int32 >& types ) throw(SQLException, RuntimeException) +{ + return NULL; +} +// ------------------------------------------------------------------------- +Reference< XConnection > SAL_CALL ODatabaseMetaData::getConnection( ) throw(SQLException, RuntimeException) +{ + return (Reference< XConnection >)m_pConnection;//new OConnection(m_aConnectionHandle); +} +// ------------------------------------------------------------------------- + + diff --git a/connectivity/source/drivers/odbc/ODriver.cxx b/connectivity/source/drivers/odbc/ODriver.cxx new file mode 100644 index 000000000000..c3f1c3489082 --- /dev/null +++ b/connectivity/source/drivers/odbc/ODriver.cxx @@ -0,0 +1,209 @@ +/************************************************************************* + * + * $RCSfile: ODriver.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ODBC_ODRIVER_HXX_ +#include "odbc/ODriver.hxx" +#endif +#ifndef _CONNECTIVITY_ODBC_OCONNECTION_HXX_ +#include "odbc/OConnection.hxx" +#endif +#ifndef _CONNECTIVITY_ODBC_OFUNCTIONS_HXX_ +#include "odbc/OFunctions.hxx" +#endif + +using namespace connectivity::odbc; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::sdbc; +// -------------------------------------------------------------------------------- +ODBCDriver::ODBCDriver() : ODriver_BASE(m_aMutex),m_pDriverHandle(SQL_NULL_HANDLE) +{ +} +// -------------------------------------------------------------------------------- +void ODBCDriver::disposing() +{ + ::osl::MutexGuard aGuard(m_aMutex); + + + for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i) + { + Reference< XComponent > xComp(i->get(), UNO_QUERY); + if (xComp.is()) + xComp->dispose(); + } + m_xConnections.clear(); + + ODriver_BASE::disposing(); +} + +// static ServiceInfo +//------------------------------------------------------------------------------ +rtl::OUString ODBCDriver::getImplementationName_Static( ) throw(RuntimeException) +{ + return rtl::OUString::createFromAscii("com.sun.star.sdbc.ODBCDriver"); +} +//------------------------------------------------------------------------------ +Sequence< ::rtl::OUString > ODBCDriver::getSupportedServiceNames_Static( ) throw (RuntimeException) +{ + Sequence< ::rtl::OUString > aSNS( 1 ); + aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver"); + return aSNS; +} + +//------------------------------------------------------------------ +::rtl::OUString SAL_CALL ODBCDriver::getImplementationName( ) throw(RuntimeException) +{ + return getImplementationName_Static(); +} + +//------------------------------------------------------------------ +sal_Bool SAL_CALL ODBCDriver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException) +{ + Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); + const ::rtl::OUString* pSupported = aSupported.getConstArray(); + for (sal_Int32 i=0; i<aSupported.getLength(); ++i, ++pSupported) + if (pSupported->equals(_rServiceName)) + return sal_True; + + return sal_False; +} + +//------------------------------------------------------------------ +Sequence< ::rtl::OUString > SAL_CALL ODBCDriver::getSupportedServiceNames( ) throw(RuntimeException) +{ + return getSupportedServiceNames_Static(); +} + +//------------------------------------------------------------------ +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL connectivity::odbc::ODBCDriver_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception ) +{ + return *(new ODBCDriver()); +} +// -------------------------------------------------------------------------------- +Reference< XConnection > SAL_CALL ODBCDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException) +{ + if(!m_pDriverHandle) + { + ::rtl::OUString aPath; + if(!EnvironmentHandle(aPath)) + throw SQLException(aPath,*this,::rtl::OUString(),1000,Any()); + } + OConnection* pCon = new OConnection(m_pDriverHandle,this); + pCon->Construct(url,info); + Reference< XConnection > xCon = pCon; + m_xConnections.push_back(WeakReferenceHelper(*pCon)); + + return xCon; +} +// -------------------------------------------------------------------------------- +sal_Bool SAL_CALL ODBCDriver::acceptsURL( const ::rtl::OUString& url ) + throw(SQLException, RuntimeException) +{ + if(!url.compareTo(::rtl::OUString::createFromAscii("sdbc:odbc:"),10)) + { + return sal_True; + } + return sal_False; +} +// -------------------------------------------------------------------------------- +Sequence< DriverPropertyInfo > SAL_CALL ODBCDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException) +{ + return Sequence< DriverPropertyInfo >(); +} +// -------------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODBCDriver::getMajorVersion( ) throw(RuntimeException) +{ + return 1; +} +// -------------------------------------------------------------------------------- +sal_Int32 SAL_CALL ODBCDriver::getMinorVersion( ) throw(RuntimeException) +{ + return 0; +} +// -------------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +// ODBC Environment (gemeinsam fuer alle Connections): +SQLHANDLE ODBCDriver::EnvironmentHandle(::rtl::OUString &_rPath) +{ + // Ist (fuer diese Instanz) bereits ein Environment erzeugt worden? + if (!m_pDriverHandle) + { + SQLHANDLE h = SQL_NULL_HANDLE; + // Environment allozieren + + // ODBC-DLL jetzt laden: + if (!LoadLibrary_ODBC3(_rPath)) + return SQL_NULL_HANDLE; + + if (N3SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&h) != SQL_SUCCESS) + return SQL_NULL_HANDLE; + + // In globaler Struktur merken ... + m_pDriverHandle = (void *) h; + SQLRETURN nError = N3SQLSetEnvAttr(h, SQL_ATTR_ODBC_VERSION,(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER); + //N3SQLSetEnvAttr(h, SQL_ATTR_CONNECTION_POOLING,(SQLPOINTER) SQL_CP_ONE_PER_HENV, SQL_IS_INTEGER); + } + + return m_pDriverHandle; +} + + diff --git a/connectivity/source/drivers/odbc/OFunctions.cxx b/connectivity/source/drivers/odbc/OFunctions.cxx new file mode 100644 index 000000000000..5a50bf38bc7d --- /dev/null +++ b/connectivity/source/drivers/odbc/OFunctions.cxx @@ -0,0 +1,338 @@ +/************************************************************************* + * + * $RCSfile: OFunctions.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +//-------------------------------------------------------------------------- +#ifndef _CONNECTIVITY_ODBC_OFUNCTIONS_HXX_ +#include "odbc/OFunctions.hxx" +#endif + +// Implib-Definitionen fuer ODBC-DLL/shared library: + +using namespace connectivity; + +// ------------------------------------------------------------------------- +sal_Bool connectivity::LoadLibrary_ADABAS(::rtl::OUString &_rPath) +{ + static sal_Bool bLoaded = sal_False; + static oslModule pODBCso = NULL; + + if (bLoaded) + return TRUE; + + char *pPath =getenv("DBROOT"); + if(pPath) + { + +#if ( defined(SOLARIS) && defined(SPARC)) || defined(LINUX) + _rPath = ::rtl::OUString::createFromAscii(pPath); + _rPath += ::rtl::OUString::createFromAscii("/lib/"); +#endif + } +#if defined(WIN) || defined(WNT) + _rPath += ::rtl::OUString::createFromAscii("SQLOD32.DLL"); +#elif ( defined(SOLARIS) && defined(SPARC)) || defined(LINUX) + _rPath += ::rtl::OUString::createFromAscii("odbclib.so"); +#else + return sal_False; +#endif + + pODBCso = osl_loadModule( _rPath.pData,SAL_LOADMODULE_NOW ); + if( !pODBCso) + return sal_False; + + + return bLoaded = LoadFunctions(pODBCso,sal_False); +} +// ------------------------------------------------------------------------- +// Dynamisches Laden der DLL/shared lib und Adressen der Funktionen besorgen: +// Liefert TRUE bei Erfolg. +sal_Bool connectivity::LoadLibrary_ODBC3(::rtl::OUString &_rPath) +{ + static sal_Bool bLoaded = sal_False; + static oslModule pODBCso = NULL; + + if (bLoaded) + return TRUE; +#ifdef WIN + _rPath = ::rtl::OUString::createFromAscii("ODBC.DLL"); + +#endif +#ifdef WNT + _rPath = ::rtl::OUString::createFromAscii("ODBC32.DLL"); +#endif +#ifdef UNX + _rPath = ::rtl::OUString::createFromAscii("libodbc.so"); +#endif +#ifdef OS2 + _rPath = ::rtl::OUString::createFromAscii("ODBC"); +#endif + + pODBCso = osl_loadModule( _rPath.pData,SAL_LOADMODULE_NOW ); + if( !pODBCso) +#ifdef OS2 + { + delete pODBCso; + _rPath = ::rtl::OUString::createFromAscii("WOD402"); + pODBCso = osl_loadModule( _rPath.pData,SAL_LOADMODULE_NOW ); + if( !pODBCso) + return sal_False; + } +#else + return sal_False; +#endif + + return bLoaded = connectivity::LoadFunctions(pODBCso); +} +// ------------------------------------------------------------------------- + +sal_Bool connectivity::LoadFunctions(oslModule pODBCso, sal_Bool _bDS) +{ + + if( ( connectivity::pODBC3SQLAllocHandle = (T3SQLAllocHandle)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLAllocHandle").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLConnect = (T3SQLConnect)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLConnect").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLDriverConnect = (T3SQLDriverConnect)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLDriverConnect").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLBrowseConnect = (T3SQLBrowseConnect)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLBrowseConnect").pData )) == NULL ) + return sal_False; + if(_bDS && ( connectivity::pODBC3SQLDataSources = (T3SQLDataSources)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLDataSources").pData )) == NULL ) + return sal_False; + if(_bDS && ( connectivity::pODBC3SQLDrivers = (T3SQLDrivers)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLDrivers").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLGetInfo = (T3SQLGetInfo)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetInfo").pData )) == NULL ) + return sal_False; + if(_bDS && ( connectivity::pODBC3SQLGetFunctions = (T3SQLGetFunctions)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetFunctions").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLGetTypeInfo = (T3SQLGetTypeInfo)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetTypeInfo").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLSetConnectAttr = (T3SQLSetConnectAttr)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLSetConnectAttr").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLGetConnectAttr = (T3SQLGetConnectAttr)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetConnectAttr").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLSetEnvAttr = (T3SQLSetEnvAttr)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLSetEnvAttr").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLGetEnvAttr = (T3SQLGetEnvAttr)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetEnvAttr").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLSetStmtAttr = (T3SQLSetStmtAttr)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLSetStmtAttr").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLGetStmtAttr = (T3SQLGetStmtAttr)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetStmtAttr").pData )) == NULL ) + return sal_False; + /*if( ( connectivity::pODBC3SQLSetDescField = (T3SQLSetDescField)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLSetDescField").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLGetDescField = (T3SQLGetDescField)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetDescField").pData )) == NULL ) + return sal_False;*/ + /*if( ( connectivity::pODBC3SQLGetDescRec = (T3SQLGetDescRec)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetDescRec").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLSetDescRec = (T3SQLSetDescRec)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLSetDescRec").pData )) == NULL ) + return sal_False;*/ + if( ( connectivity::pODBC3SQLPrepare = (T3SQLPrepare)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLPrepare").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLBindParameter = (T3SQLBindParameter)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLBindParameter").pData )) == NULL ) + return sal_False; +// if( ( connectivity::pODBC3SQLGetCursorName = (T3SQLGetCursorName)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetCursorName").pData )) == NULL ) +// return sal_False; + if( ( connectivity::pODBC3SQLSetCursorName = (T3SQLSetCursorName)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLSetCursorName").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLExecute = (T3SQLExecute)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLExecute").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLExecDirect = (T3SQLExecDirect)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLExecDirect").pData )) == NULL ) + return sal_False; + /*if( ( connectivity::pODBC3SQLNativeSql = (T3SQLNativeSql)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLNativeSql").pData )) == NULL ) + return sal_False;*/ + if( ( connectivity::pODBC3SQLDescribeParam = (T3SQLDescribeParam)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLDescribeParam").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLNumParams = (T3SQLNumParams)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLNumParams").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLParamData = (T3SQLParamData)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLParamData").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLPutData = (T3SQLPutData)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLPutData").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLRowCount = (T3SQLRowCount)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLRowCount").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLNumResultCols = (T3SQLNumResultCols)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLNumResultCols").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLDescribeCol = (T3SQLDescribeCol)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLDescribeCol").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLColAttribute = (T3SQLColAttribute)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLColAttribute").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLBindCol = (T3SQLBindCol)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLBindCol").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLFetch = (T3SQLFetch)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLFetch").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLFetchScroll = (T3SQLFetchScroll)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLFetchScroll").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLGetData = (T3SQLGetData)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetData").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLSetPos = (T3SQLSetPos)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLSetPos").pData )) == NULL ) + return sal_False; + if( _bDS && ( connectivity::pODBC3SQLBulkOperations = (T3SQLBulkOperations)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLBulkOperations").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLMoreResults = (T3SQLMoreResults)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLMoreResults").pData )) == NULL ) + return sal_False; + /*if( ( connectivity::pODBC3SQLGetDiagField = (T3SQLGetDiagField)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetDiagField").pData )) == NULL ) + return sal_False;*/ + if( ( connectivity::pODBC3SQLGetDiagRec = (T3SQLGetDiagRec)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetDiagRec").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLColumnPrivileges = (T3SQLColumnPrivileges)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLColumnPrivileges").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLColumns = (T3SQLColumns)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLColumns").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLForeignKeys = (T3SQLForeignKeys)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLForeignKeys").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLPrimaryKeys = (T3SQLPrimaryKeys)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLPrimaryKeys").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLProcedureColumns = (T3SQLProcedureColumns)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLProcedureColumns").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLProcedures = (T3SQLProcedures)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLProcedures").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLSpecialColumns = (T3SQLSpecialColumns)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLSpecialColumns").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLStatistics = (T3SQLStatistics)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLStatistics").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLTablePrivileges = (T3SQLTablePrivileges)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLTablePrivileges").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLTables = (T3SQLTables)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLTables").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLFreeStmt = (T3SQLFreeStmt)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLFreeStmt").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLCloseCursor = (T3SQLCloseCursor)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLCloseCursor").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLCancel = (T3SQLCancel)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLCancel").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLEndTran = (T3SQLEndTran)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLEndTran").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLDisconnect = (T3SQLDisconnect)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLDisconnect").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLFreeHandle = (T3SQLFreeHandle)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLFreeHandle").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLGetCursorName = (T3SQLGetCursorName)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetCursorName").pData )) == NULL ) + return sal_False; + if( ( connectivity::pODBC3SQLNativeSql = (T3SQLNativeSql)osl_getSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLNativeSql").pData )) == NULL ) + return sal_False; + + return sal_True; +} +// ------------------------------------------------------------------------- + +connectivity::T3SQLAllocHandle connectivity::pODBC3SQLAllocHandle; +connectivity::T3SQLConnect connectivity::pODBC3SQLConnect; +connectivity::T3SQLDriverConnect connectivity::pODBC3SQLDriverConnect; +connectivity::T3SQLBrowseConnect connectivity::pODBC3SQLBrowseConnect; +connectivity::T3SQLDataSources connectivity::pODBC3SQLDataSources; +connectivity::T3SQLDrivers connectivity::pODBC3SQLDrivers; +connectivity::T3SQLGetInfo connectivity::pODBC3SQLGetInfo; +connectivity::T3SQLGetFunctions connectivity::pODBC3SQLGetFunctions; +connectivity::T3SQLGetTypeInfo connectivity::pODBC3SQLGetTypeInfo; +connectivity::T3SQLSetConnectAttr connectivity::pODBC3SQLSetConnectAttr; +connectivity::T3SQLGetConnectAttr connectivity::pODBC3SQLGetConnectAttr; +connectivity::T3SQLSetEnvAttr connectivity::pODBC3SQLSetEnvAttr; +connectivity::T3SQLGetEnvAttr connectivity::pODBC3SQLGetEnvAttr; +connectivity::T3SQLSetStmtAttr connectivity::pODBC3SQLSetStmtAttr; +connectivity::T3SQLGetStmtAttr connectivity::pODBC3SQLGetStmtAttr; +//connectivity::T3SQLSetDescField connectivity::pODBC3SQLSetDescField; +//connectivity::T3SQLGetDescField connectivity::pODBC3SQLGetDescField; +//connectivity::T3SQLGetDescRec connectivity::pODBC3SQLGetDescRec; +//connectivity::T3SQLSetDescRec connectivity::pODBC3SQLSetDescRec; +connectivity::T3SQLPrepare connectivity::pODBC3SQLPrepare; +connectivity::T3SQLBindParameter connectivity::pODBC3SQLBindParameter; +//connectivity::T3SQLGetCursorName connectivity::pODBC3SQLGetCursorName; +connectivity::T3SQLSetCursorName connectivity::pODBC3SQLSetCursorName; +connectivity::T3SQLExecute connectivity::pODBC3SQLExecute; +connectivity::T3SQLExecDirect connectivity::pODBC3SQLExecDirect; +//connectivity::T3SQLNativeSql connectivity::pODBC3SQLNativeSql; +connectivity::T3SQLDescribeParam connectivity::pODBC3SQLDescribeParam; +connectivity::T3SQLNumParams connectivity::pODBC3SQLNumParams; +connectivity::T3SQLParamData connectivity::pODBC3SQLParamData; +connectivity::T3SQLPutData connectivity::pODBC3SQLPutData; +connectivity::T3SQLRowCount connectivity::pODBC3SQLRowCount; +connectivity::T3SQLNumResultCols connectivity::pODBC3SQLNumResultCols; +connectivity::T3SQLDescribeCol connectivity::pODBC3SQLDescribeCol; +connectivity::T3SQLColAttribute connectivity::pODBC3SQLColAttribute; +connectivity::T3SQLBindCol connectivity::pODBC3SQLBindCol; +connectivity::T3SQLFetch connectivity::pODBC3SQLFetch; +connectivity::T3SQLFetchScroll connectivity::pODBC3SQLFetchScroll; +connectivity::T3SQLGetData connectivity::pODBC3SQLGetData; +connectivity::T3SQLSetPos connectivity::pODBC3SQLSetPos; +connectivity::T3SQLBulkOperations connectivity::pODBC3SQLBulkOperations; +connectivity::T3SQLMoreResults connectivity::pODBC3SQLMoreResults; +//connectivity::T3SQLGetDiagField connectivity::pODBC3SQLGetDiagField; +connectivity::T3SQLGetDiagRec connectivity::pODBC3SQLGetDiagRec; +connectivity::T3SQLColumnPrivileges connectivity::pODBC3SQLColumnPrivileges; +connectivity::T3SQLColumns connectivity::pODBC3SQLColumns; +connectivity::T3SQLForeignKeys connectivity::pODBC3SQLForeignKeys; +connectivity::T3SQLPrimaryKeys connectivity::pODBC3SQLPrimaryKeys; +connectivity::T3SQLProcedureColumns connectivity::pODBC3SQLProcedureColumns; +connectivity::T3SQLProcedures connectivity::pODBC3SQLProcedures; +connectivity::T3SQLSpecialColumns connectivity::pODBC3SQLSpecialColumns; +connectivity::T3SQLStatistics connectivity::pODBC3SQLStatistics; +connectivity::T3SQLTablePrivileges connectivity::pODBC3SQLTablePrivileges; +connectivity::T3SQLTables connectivity::pODBC3SQLTables; +connectivity::T3SQLFreeStmt connectivity::pODBC3SQLFreeStmt; +connectivity::T3SQLCloseCursor connectivity::pODBC3SQLCloseCursor; +connectivity::T3SQLCancel connectivity::pODBC3SQLCancel; +connectivity::T3SQLEndTran connectivity::pODBC3SQLEndTran; +connectivity::T3SQLDisconnect connectivity::pODBC3SQLDisconnect; +connectivity::T3SQLFreeHandle connectivity::pODBC3SQLFreeHandle; +connectivity::T3SQLGetCursorName connectivity::pODBC3SQLGetCursorName; +connectivity::T3SQLNativeSql connectivity::pODBC3SQLNativeSql; + + diff --git a/connectivity/source/drivers/odbc/OPreparedStatement.cxx b/connectivity/source/drivers/odbc/OPreparedStatement.cxx new file mode 100644 index 000000000000..40da2368fb93 --- /dev/null +++ b/connectivity/source/drivers/odbc/OPreparedStatement.cxx @@ -0,0 +1,1063 @@ +/************************************************************************* + * + * $RCSfile: OPreparedStatement.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif +#ifndef _CONNECTIVITY_ODBC_OPREPAREDSTATEMENT_HXX_ +#include "odbc/OPreparedStatement.hxx" +#endif +#ifndef _CONNECTIVITY_OBOUNPARAM_HXX_ +#include "odbc/OBoundParam.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif +#ifndef _CONNECTIVITY_OTOOLS_HXX_ +#include "odbc/OTools.hxx" +#endif +#ifndef _CONNECTIVITY_ODBC_ORESULTSETMETADATA_HXX_ +#include "odbc/OResultSetMetaData.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif + +using namespace connectivity; +using namespace connectivity::odbc; +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::io; +using namespace com::sun::star::util; + +int OBoundParam::ASCII = 1; +int OBoundParam::UNICODE = 2; +int OBoundParam::BINARY = 3; + +IMPLEMENT_SERVICE_INFO(OPreparedStatement,"com.sun.star.sdbcx.OPreparedStatement","com.sun.star.sdbc.PreparedStatement"); + +OPreparedStatement::OPreparedStatement( OConnection* _pConnection,const ::std::vector<OTypeInfo>& _TypeInfo,const ::rtl::OUString& sql) + : OStatement_BASE2( _pConnection ),m_aTypeInfo(_TypeInfo) +{ + ::rtl::OString aSql(::rtl::OUStringToOString(sql,osl_getThreadTextEncoding())); + N3SQLPrepare(m_aStatementHandle,(SDB_ODBC_CHAR *) aSql.getStr(),aSql.getLength()); + initBoundParam(); +} +// ------------------------------------------------------------------------- + +Any SAL_CALL OPreparedStatement::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = OStatement_BASE2::queryInterface(rType); + if(!aRet.hasValue()) + aRet = ::cppu::queryInterface( rType, + static_cast< XPreparedStatement*>(this), + static_cast< XParameters*>(this), + static_cast< XPreparedBatchExecution*>(this), + static_cast< XResultSetMetaDataSupplier*>(this)); + return aRet; +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OPreparedStatement::getTypes( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< XPreparedStatement > *)0 ), + ::getCppuType( (const ::com::sun::star::uno::Reference< XParameters > *)0 ), + ::getCppuType( (const ::com::sun::star::uno::Reference< XResultSetMetaDataSupplier > *)0 ), + ::getCppuType( (const ::com::sun::star::uno::Reference< XPreparedBatchExecution > *)0 )); + + return ::utl::concatSequences(aTypes.getTypes(),OStatement_BASE2::getTypes()); +} +// ------------------------------------------------------------------------- + +Reference< XResultSetMetaData > SAL_CALL OPreparedStatement::getMetaData( ) throw(SQLException, RuntimeException) +{ + if(m_xMetaData.is()) + m_xMetaData = new OResultSetMetaData(m_aStatementHandle); + return m_xMetaData; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::close( ) throw(SQLException, RuntimeException) +{ + // Close/clear our result set + clearMyResultSet (); + + // Reset last warning message + + try { + clearWarnings (); + if (m_aStatementHandle != SQL_NULL_HSTMT) + { + N3SQLFreeStmt (m_aStatementHandle, SQL_DROP); + m_aStatementHandle = SQL_NULL_HSTMT; + FreeParams(); + } + } + catch (SQLException & ex) { + // If we get an error, ignore + } + + // Remove this Statement object from the Connection object's + // list +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OPreparedStatement::execute( ) throw(SQLException, RuntimeException) +{ + sal_Bool hasResultSet = sal_False; + SQLWarning warning; + sal_Bool needData = sal_False; + + // Reset warnings + + clearWarnings (); + + // Reset the statement handle, warning and saved Resultset + + reset(); + + // Call SQLExecute + + try + { + SQLRETURN nReturn = N3SQLExecute(m_aStatementHandle); + + OTools::ThrowException(nReturn,m_aStatementHandle,SQL_HANDLE_STMT,*this); + needData = nReturn == SQL_NEED_DATA; + + // Now loop while more data is needed (i.e. a data-at- + // execution parameter was given). For each parameter + // that needs data, put the data from the input stream. + + while (needData) { + + // Get the parameter number that requires data + + sal_Int32* paramIndex = 0; + nReturn = N3SQLParamData(m_aStatementHandle,(SQLPOINTER*)¶mIndex); + + // If the parameter index is -1, there is no + // more data required + + if (*paramIndex == -1) + needData = sal_False; + else + { + // Now we have the proper parameter + // index, get the data from the input + // stream and do a SQLPutData + putParamData (*paramIndex); + } + } + + } + catch (SQLWarning& ex) + { + + // Save pointer to warning and save with ResultSet + // object once it is created. + + warning = ex; + } + + // Now loop while more data is needed (i.e. a data-at- + // execution parameter was given). For each parameter + // that needs data, put the data from the input stream. + + while (needData) { + + // Get the parameter number that requires data + + sal_Int32* paramIndex = 0; + N3SQLParamData (m_aStatementHandle,(SQLPOINTER*)¶mIndex); + + // If the parameter index is -1, there is no more + // data required + + if (*paramIndex == -1) { + needData = sal_False; + } + else { + // Now we have the proper parameter index, + // get the data from the input stream + // and do a SQLPutData + putParamData(*paramIndex); + } + } + + // Now determine if there is a result set associated with + // the SQL statement that was executed. Get the column + // count, and if it is not zero, there is a result set. + + if (getColumnCount () > 0) + hasResultSet = sal_True; + + + return hasResultSet; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OPreparedStatement::executeUpdate( ) throw(SQLException, RuntimeException) +{ + sal_Int32 numRows = -1; + + // Execute the statement. If execute returns sal_False, a + // row count exists. + + if (!execute()) + numRows = getUpdateCount (); + else { + + // No update count was produced (a ResultSet was). Raise + // an exception + + throw SQLException(::rtl::OUString::createFromAscii("No row count was produced"), + *this, + ::rtl::OUString(),0,Any()); + } + return numRows; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setString( sal_Int32 parameterIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException) +{ + setChar(parameterIndex, DataType::CHAR, 0, x); +} +// ------------------------------------------------------------------------- + +Reference< XConnection > SAL_CALL OPreparedStatement::getConnection( ) throw(SQLException, RuntimeException) +{ + return (Reference< XConnection >)m_pConnection; +} +// ------------------------------------------------------------------------- + +Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery( ) throw(SQLException, RuntimeException) +{ + Reference< XResultSet > rs = NULL; + + if (execute()) + rs = getResultSet(sal_False); + + else { + + // No ResultSet was produced. Raise an exception + + throw SQLException(::rtl::OUString::createFromAscii("No ResultSet was produced"), + *this, + ::rtl::OUString(),0,Any()); + } + return rs; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setBoolean( sal_Int32 parameterIndex, sal_Bool x ) throw(SQLException, RuntimeException) +{ + sal_Int32 value = 0; + + // If the parameter is sal_True, set the value to 1 + if (x) { + value = 1; + } + + // Set the parameter as if it were an integer + setInt (parameterIndex, value); +} +// ------------------------------------------------------------------------- +#define PREP_BIND_PARAM(_ty,_jt) \ + bindParameter( m_aStatementHandle, \ + parameterIndex, \ + bindBuf,getLengthBuf(parameterIndex), \ + _jt, \ + sal_False,sal_False,&x,(Reference <XInterface>)*this) + + + +void SAL_CALL OPreparedStatement::setByte( sal_Int32 parameterIndex, sal_Int8 x ) throw(SQLException, RuntimeException) +{ + // Allocate a buffer to be used in binding. This will be + // a 'permanent' buffer that the bridge will fill in with + // the bound data in native format. + if( !parameterIndex || parameterIndex > numParams) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + + sal_Int8* bindBuf = allocBindBuf(parameterIndex, 4); + PREP_BIND_PARAM(sal_Int8,SQL_TINYINT); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setDate( sal_Int32 parameterIndex, const Date& aData ) throw(SQLException, RuntimeException) +{ + // Allocate a buffer to be used in binding. This will be + // a 'permanent' buffer that the bridge will fill in with + // the bound data in native format. + + if( !parameterIndex || parameterIndex > numParams) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + + sal_Int8* bindBuf = allocBindBuf (parameterIndex, 32); + + + DATE_STRUCT x = OTools::DateToOdbcDate(aData); + PREP_BIND_PARAM(DATE_STRUCT,DataType::DATE); +} +// ------------------------------------------------------------------------- + + +void SAL_CALL OPreparedStatement::setTime( sal_Int32 parameterIndex, const Time& aVal ) throw(SQLException, RuntimeException) +{ + // Allocate a buffer to be used in binding. This will be + // a 'permanent' buffer that the bridge will fill in with + // the bound data in native format. + if( !parameterIndex || parameterIndex > numParams) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + + sal_Int8* bindBuf = allocBindBuf (parameterIndex, 32); + + TIME_STRUCT x = OTools::TimeToOdbcTime(aVal); + PREP_BIND_PARAM(TIME_STRUCT,DataType::TIME); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setTimestamp( sal_Int32 parameterIndex, const DateTime& aVal ) throw(SQLException, RuntimeException) +{ + // Allocate a buffer to be used in binding. This will be + // a 'permanent' buffer that the bridge will fill in with + // the bound data in native format. + if( !parameterIndex || parameterIndex > numParams) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + + sal_Int8* bindBuf = allocBindBuf (parameterIndex, 32); + + TIMESTAMP_STRUCT x = OTools::DateTimeToTimestamp(aVal); + PREP_BIND_PARAM(TIMESTAMP_STRUCT,DataType::TIMESTAMP); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setDouble( sal_Int32 parameterIndex, double x ) throw(SQLException, RuntimeException) +{ + // Allocate a buffer to be used in binding. This will be + // a 'permanent' buffer that the bridge will fill in with + // the bound data in native format. + if( !parameterIndex || parameterIndex > numParams) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + + sal_Int8* bindBuf = allocBindBuf (parameterIndex, 8); + PREP_BIND_PARAM(double,DataType::DOUBLE); +} + +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setFloat( sal_Int32 parameterIndex, float x ) throw(SQLException, RuntimeException) +{ + // Allocate a buffer to be used in binding. This will be + // a 'permanent' buffer that the bridge will fill in with + // the bound data in native format. + if( !parameterIndex || parameterIndex > numParams) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + + sal_Int8* bindBuf = allocBindBuf (parameterIndex, 8); + PREP_BIND_PARAM(float,DataType::FLOAT); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setInt( sal_Int32 parameterIndex, sal_Int32 x ) throw(SQLException, RuntimeException) +{ + // Allocate a buffer to be used in binding. This will be + // a 'permanent' buffer that the bridge will fill in with + // the bound data in native format. + if( !parameterIndex || parameterIndex > numParams) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + + sal_Int8* bindBuf = allocBindBuf (parameterIndex, 4); + PREP_BIND_PARAM(sal_Int32,DataType::INTEGER); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setLong( sal_Int32 parameterIndex, sal_Int64 aVal ) throw(SQLException, RuntimeException) +{ + // Allocate a buffer to be used in binding. This will be + // a 'permanent' buffer that the bridge will fill in with + // the bound data in native format. + + if( !parameterIndex || parameterIndex > numParams) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + + sal_Int8 *bindBuf = allocBindBuf (parameterIndex, 8); + float x = (float)aVal; + PREP_BIND_PARAM(float,DataType::BIGINT); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setNull( sal_Int32 parameterIndex, sal_Int32 sqlType ) throw(SQLException, RuntimeException) +{ + // Get the buffer needed for the length + if( !parameterIndex || parameterIndex > numParams) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + + sal_Int8* lenBuf = getLengthBuf (parameterIndex); + *lenBuf = SQL_NULL_DATA; + UDWORD prec = 0; + if (sqlType == SQL_CHAR) + prec = 1; + + N3SQLBindParameter(m_aStatementHandle, + parameterIndex, + SQL_PARAM_INPUT, + SQL_C_DEFAULT, + sqlType, + prec, + 0, + NULL, + 0, + (SDWORD*)lenBuf + ); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setClob( sal_Int32 parameterIndex, const Reference< XClob >& x ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setBlob( sal_Int32 parameterIndex, const Reference< XBlob >& x ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setArray( sal_Int32 parameterIndex, const Reference< XArray >& x ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setRef( sal_Int32 parameterIndex, const Reference< XRef >& x ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setObjectWithInfo( sal_Int32 parameterIndex, const Any& x, sal_Int32 sqlType, sal_Int32 scale ) throw(SQLException, RuntimeException) +{ + // For each known SQL Type, call the appropriate + // set routine + + switch (sqlType) + { + case DataType::CHAR: + setString (parameterIndex, *(::rtl::OUString*) x.getValue()); + break; + + case DataType::VARCHAR: + setChar (parameterIndex, sqlType, 0, *(::rtl::OUString*) x.getValue()); + break; + + case DataType::LONGVARCHAR: + setChar (parameterIndex, sqlType, 0, *(::rtl::OUString*) x.getValue()); + break; + + case DataType::BIT: + setBoolean (parameterIndex,*(sal_Bool*) x.getValue()); + break; + + case DataType::TINYINT: + setByte (parameterIndex, *(sal_Int8*)x.getValue()); + break; + + case DataType::SMALLINT: + setShort (parameterIndex, *(short*)x.getValue()); + break; + + case DataType::INTEGER: + setInt (parameterIndex,*(sal_Int32*)x.getValue ()); + break; + + case DataType::BIGINT: + // setLong (parameterIndex,((sal_Int32) x).longValue ()); + break; + + case DataType::REAL: + setFloat (parameterIndex, *(float*)x.getValue ()); + break; + + case DataType::FLOAT: + setFloat (parameterIndex, *(float*)x.getValue ()); + break; + + case DataType::DOUBLE: + setDouble (parameterIndex,*(double*)x.getValue ()); + break; + + case DataType::BINARY: + setBytes (parameterIndex, *(Sequence<sal_Int8>*)x.getValue()); + break; + + case DataType::VARBINARY: + case DataType::LONGVARBINARY: + { + Sequence<sal_Int8> y; + x >>= y; + + if ( y.getLength() > 2000 ) + { + // setBinaryStream (parameterIndex, y, y.getLength()); + } + else + { + setBinary (parameterIndex, sqlType, y); + } + } + + break; + + case DataType::DATE: + setDate (parameterIndex,*(Date*) x.getValue()); + break; + + case DataType::TIME: + setTime (parameterIndex, *(Time*)x.getValue()); + break; + + case DataType::TIMESTAMP: + setTimestamp (parameterIndex,*(DateTime*)x.getValue()); + break; + + default: + { + ::rtl::OUString aVal = ::rtl::OUString::createFromAscii("Unknown SQL Type for PreparedStatement.setObject (SQL Type="); + aVal += ::rtl::OUString::valueOf(sqlType); + throw SQLException( aVal, + *this, + ::rtl::OUString(),0,Any()); + } + + } +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& typeName ) throw(SQLException, RuntimeException) +{ + setNull(parameterIndex,sqlType); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setObject( sal_Int32 parameterIndex, const Any& x ) throw(SQLException, RuntimeException) +{ + // setObject (parameterIndex, x, sqlType, 0); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setShort( sal_Int32 parameterIndex, sal_Int16 x ) throw(SQLException, RuntimeException) +{ + // Allocate a buffer to be used in binding. This will be + // a 'permanent' buffer that the bridge will fill in with + // the bound data in native format. + if( !parameterIndex || parameterIndex > numParams) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + + sal_Int8* bindBuf = allocBindBuf (parameterIndex, 4); + PREP_BIND_PARAM(sal_Int16,DataType::SMALLINT); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setBytes( sal_Int32 parameterIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException) +{ + if ( x.getLength() > 2000 ) + { + // setBinaryStream (parameterIndex, new java.io.ByteArrayInputStream(x), x.length); + } + else + { + setBinary (parameterIndex, DataType::BINARY, x); + } +} +// ------------------------------------------------------------------------- + + +void SAL_CALL OPreparedStatement::setCharacterStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException) +{ + setStream (parameterIndex, x, length, DataType::LONGVARCHAR,OBoundParam::ASCII); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::setBinaryStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException) +{ + setStream (parameterIndex, x, length, DataType::LONGVARBINARY,OBoundParam::BINARY); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::clearParameters( ) throw(SQLException, RuntimeException) +{ + N3SQLFreeStmt (m_aStatementHandle, SQL_RESET_PARAMS); +} +// ------------------------------------------------------------------------- +void SAL_CALL OPreparedStatement::clearBatch( ) throw(SQLException, RuntimeException) +{ + // clearParameters( ); + // m_aBatchList.erase(); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OPreparedStatement::addBatch( ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +Sequence< sal_Int32 > SAL_CALL OPreparedStatement::executeBatch( ) throw(SQLException, RuntimeException) +{ + return Sequence< sal_Int32 > (); +} +// ------------------------------------------------------------------------- + +//==================================================================== +// methods +//==================================================================== + +//-------------------------------------------------------------------- +// initBoundParam +// Initialize the bound parameter objects +//-------------------------------------------------------------------- + +void OPreparedStatement::initBoundParam () throw(SQLException) +{ + // Get the number of parameters + numParams = 0; + N3SQLNumParams (m_aStatementHandle,(short*)&numParams); + + // There are parameter markers, allocate the bound + // parameter objects + + if (numParams > 0) + { + // Allocate an array of bound parameter objects + + boundParams = new OBoundParam[numParams]; + + // Allocate and initialize each bound parameter + + for (sal_Int32 i = 0; i < numParams; i++) + { + boundParams[i] = OBoundParam(); + boundParams[i].initialize (); + } + } +} +// ------------------------------------------------------------------------- + +//-------------------------------------------------------------------- +// allocBindBuf +// Allocate storage for the permanent data buffer for the bound +// parameter. +//-------------------------------------------------------------------- + +sal_Int8* OPreparedStatement::allocBindBuf( sal_Int32 index,sal_Int32 bufLen) +{ + sal_Int8* b = NULL; + + // Sanity check the parameter number + + if ((index >= 1) && + (index <= numParams)) + { + b = boundParams[index - 1].allocBindDataBuffer(bufLen); + } + + return b; +} +// ------------------------------------------------------------------------- + +//-------------------------------------------------------------------- +// getDataBuf +// Gets the data buffer for the given parameter index +//-------------------------------------------------------------------- + +sal_Int8* OPreparedStatement::getDataBuf (sal_Int32 index) +{ + sal_Int8* b = NULL; + + // Sanity check the parameter number + + if ((index >= 1) && + (index <= numParams)) + { + b = boundParams[index - 1].getBindDataBuffer (); + } + + return b; +} +// ------------------------------------------------------------------------- + +//-------------------------------------------------------------------- +// getLengthBuf +// Gets the length buffer for the given parameter index +//-------------------------------------------------------------------- + +sal_Int8* OPreparedStatement::getLengthBuf (sal_Int32 index) +{ + sal_Int8* b = NULL; + + // Sanity check the parameter number + + if ((index >= 1) && + (index <= numParams)) + { + b = boundParams[index - 1].getBindLengthBuffer (); + } + + return b; +} +// ------------------------------------------------------------------------- + +//-------------------------------------------------------------------- +// getParamLength +// Returns the length of the given parameter number. When each +// parameter was bound, a 4-sal_Int8 buffer was given to hold the +// length (stored in native format). Get the buffer, convert the +// buffer from native format, and return it. If the length is -1, +// the column is considered to be NULL. +//-------------------------------------------------------------------- + +sal_Int32 OPreparedStatement::getParamLength ( sal_Int32 index) +{ + sal_Int32 paramLen = SQL_NULL_DATA; + + // Sanity check the parameter number + + if ((index >= 1) && + (index <= numParams)) { + + // Now get the length of the parameter from the + // bound param array. -1 is returned if it is NULL. + long n = 0; + memcpy (&n, boundParams[index -1].getBindLengthBuffer (), sizeof (n)); + paramLen = n; + } + return paramLen; +} +// ------------------------------------------------------------------------- + +//-------------------------------------------------------------------- +// putParamData +// Puts parameter data from a previously bound input stream. The +// input stream was bound using SQL_LEN_DATA_AT_EXEC. +//-------------------------------------------------------------------- + +void OPreparedStatement::putParamData (sal_Int32 index) throw(SQLException) +{ + // We'll transfer up to maxLen at a time + sal_Int32 maxLen = MAX_PUT_DATA_LENGTH; + sal_Int32 bufLen; + sal_Int32 realLen; + // sal_Int8* buf = new sal_Int8[maxLen]; + Sequence< sal_Int8 > buf(maxLen); + sal_Bool endOfStream = sal_False; + + // Sanity check the parameter index + if ((index < 1) || + (index > numParams)) + { + return; + } + + // Get the information about the input stream + + Reference< XInputStream> inputStream = boundParams[index - 1].getInputStream (); + sal_Int32 inputStreamLen = boundParams[index - 1].getInputStreamLen (); + sal_Int32 inputStreamType = boundParams[index - 1].getStreamType (); + + // Loop while more data from the input stream + + while (!endOfStream) + { + + // Read some data from the input stream + + try { + bufLen = inputStream->readBytes(buf,maxLen); + } + catch (IOException& ex) { + + // If an I/O exception was generated, turn + // it into a SQLException + + throw SQLException(ex.Message,*this,::rtl::OUString(),0,Any()); + } + + // -1 as the number of bytes read indicates that + // there is no more data in the input stream + + if (bufLen == -1) + { + + // Sanity check to ensure that all the data we said we + // had was read. If not, raise an exception + + if (inputStreamLen != 0) { + throw SQLException (::rtl::OUString::createFromAscii("End of InputStream reached before satisfying length specified when InputStream was set"), + *this, + ::rtl::OUString(),0,Any()); + } + endOfStream = sal_True; + break; + } + + // If we got more bytes than necessary, truncate + // the buffer by re-setting the buffer length. Also, + // indicate that we don't need to read any more. + + if (bufLen > inputStreamLen) + { + bufLen = inputStreamLen; + endOfStream = sal_True; + } + + realLen = bufLen; + + // For UNICODE streams, strip off the high sal_Int8 and set the + // number of actual bytes present. It is assumed that + // there are 2 bytes present for every UNICODE character - if + // not, then that's not our problem + + if (inputStreamType == OBoundParam::UNICODE) + { + realLen = bufLen / 2; + + for (sal_Int32 ii = 0; ii < realLen; ii++) + buf[ii] = buf[(ii * 2) + 1]; + } + + // Put the data + + N3SQLPutData (m_aStatementHandle, buf.getArray(), realLen); + + // Decrement the number of bytes still needed + + inputStreamLen -= bufLen; + + + // If there is no more data to be read, exit loop + + if (inputStreamLen == 0) + endOfStream = sal_True; + } +} +// ------------------------------------------------------------------------- +//-------------------------------------------------------------------- +// getPrecision +// Given a SQL type, return the maximum precision for the column. +// Returns -1 if not known +//-------------------------------------------------------------------- + +sal_Int32 OPreparedStatement::getPrecision ( sal_Int32 sqlType) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_Int32 prec = -1; + OTypeInfo aInfo; + aInfo.nType = sqlType; + if (m_aTypeInfo.size()) + { + ::std::vector<OTypeInfo>::const_iterator aIter = ::std::find(m_aTypeInfo.begin(),m_aTypeInfo.end(),aInfo); + if(aIter != m_aTypeInfo.end()) + prec = (*aIter).nPrecision; + } + return prec; +} + +//-------------------------------------------------------------------- +// setStream +// Sets an input stream as a parameter, using the given SQL type +//-------------------------------------------------------------------- + +void OPreparedStatement::setStream ( + sal_Int32 ParameterIndex, + const Reference< XInputStream>& x, + sal_Int32 length, + sal_Int32 SQLtype, + sal_Int32 streamType) + throw(SQLException) +{ + if( !ParameterIndex || ParameterIndex > numParams) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + // Get the buffer needed for the length + + sal_Int8* lenBuf = getLengthBuf(ParameterIndex); + + // Allocate a new buffer for the parameter data. This buffer + // will be returned by SQLParamData (it is set to the parameter + // number, a 4-sal_Int8 integer) + + sal_Int8* dataBuf = allocBindBuf (ParameterIndex, 4); + + // Bind the parameter with SQL_LEN_DATA_AT_EXEC + SWORD Ctype = SQL_C_CHAR; + SDWORD atExec = SQL_LEN_DATA_AT_EXEC (length); + memcpy (dataBuf, &ParameterIndex, sizeof(ParameterIndex)); + memcpy (lenBuf, &atExec, sizeof (atExec)); + + if ((SQLtype == SQL_BINARY) || (SQLtype == SQL_VARBINARY) || (SQLtype == SQL_LONGVARBINARY)) + Ctype = SQL_C_BINARY; + + + N3SQLBindParameter(m_aStatementHandle, ParameterIndex,SQL_PARAM_INPUT,Ctype, + SQLtype, length,0, dataBuf, sizeof(ParameterIndex),(SDWORD*)lenBuf); + + // Save the input stream + + boundParams[ParameterIndex - 1].setInputStream (x, length); + + // Set the stream type + + boundParams[ParameterIndex - 1].setStreamType (streamType); +} +// ------------------------------------------------------------------------- + +//-------------------------------------------------------------------- +// setChar +// Binds the given string to the given SQL type +//-------------------------------------------------------------------- +void OPreparedStatement::setChar(sal_Int32 parameterIndex, + sal_Int32 SQLtype, + sal_Int32 scale, + const ::rtl::OUString& x) + throw(SQLException) +{ + // ::rtl::OString x1(::rtl::OUStringToOString(x,osl_getThreadTextEncoding())); + + if( !parameterIndex || parameterIndex > numParams) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + + sal_Int8* bindBuf = allocBindBuf (parameterIndex,x.getLength()); + + // Get the precision for this SQL type. If the precision + // is out of bounds, set it to our default + +// sal_Int32 precision = getPrecision (SQLtype); +// +// if ((precision < 0) || (precision > 2000)) +// precision = 2000; +// + // bindParameter(m_aStatementHandle,parameterIndex,bindBuf); + PREP_BIND_PARAM(char*,SQLtype); + +// // Make a copy of the data +// SDWORD lBuf = x.getLength(); +// memcpy (bindBuf, x.getStr(), lBuf); +// bindBuf[lBuf] = '\0'; +// precision = lBuf; +// +// SQLINTEGER nNTS = SQL_NTS; +// +// SQLRETURN nRet = N3SQLBindParameter(m_aStatementHandle, parameterIndex,SQL_PARAM_INPUT, +// SQLtype,SQL_C_CHAR, precision, scale, bindBuf,lBuf, &nNTS); +// +} +// ------------------------------------------------------------------------- + +//-------------------------------------------------------------------- +// setBinary +// Binds the given sal_Int8 array to the given SQL type +//-------------------------------------------------------------------- + +void OPreparedStatement::setBinary (sal_Int32 parameterIndex,sal_Int32 SQLtype, + const Sequence< sal_Int8 >& x) throw(SQLException) +{ + // Allocate a buffer to be used in binding. This will be + // a 'permanent' buffer that the bridge will fill in with + // the bound data in native format. + if( !parameterIndex || parameterIndex > numParams) + throw SQLException(STAT_INVALID_INDEX,*this,::rtl::OUString::createFromAscii("07009"),0,Any()); + + sal_Int8* bindBuf = allocBindBuf (parameterIndex,x.getLength()); + + // Get the buffer needed for the length + + // sal_Int8* lenBuf = getLengthBuf (parameterIndex); + bindParameter< Sequence< sal_Int8 > >( m_aStatementHandle, + parameterIndex, + bindBuf,getLengthBuf(parameterIndex), + SQLtype, + sal_False,sal_False,&x,(Reference <XInterface>)*this); + + + // N3SQLBindInParameterBinary (m_aStatementHandle, parameterIndex, + // SQLtype, x.getConstArray(), bindBuf, lenBuf, buffers); + +} +// ------------------------------------------------------------------------- + +void OPreparedStatement::FreeParams() +{ + delete boundParams; +} +// ------------------------------------------------------------------------- + + diff --git a/connectivity/source/drivers/odbc/OResultSet.cxx b/connectivity/source/drivers/odbc/OResultSet.cxx new file mode 100644 index 000000000000..fbf4538f6d56 --- /dev/null +++ b/connectivity/source/drivers/odbc/OResultSet.cxx @@ -0,0 +1,2051 @@ +/************************************************************************* + * + * $RCSfile: OResultSet.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _CONNECTIVITY_ODBC_ORESULTSET_HXX_ +#include "odbc/OResultSet.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +#ifndef _CONNECTIVITY_OTOOLS_HXX_ +#include "odbc/OTools.hxx" +#endif +#ifndef _CONNECTIVITY_ODBC_ORESULTSETMETADATA_HXX_ +#include "odbc/OResultSetMetaData.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBCX_COMPAREBOOKMARK_HPP_ +#include <com/sun/star/sdbcx/CompareBookmark.hpp> +#endif +#ifndef _UTL_PROPERTY_HXX_ +#include <unotools/property.hxx> +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _CPPUHELPER_EXTRACT_HXX_ +#include <cppuhelper/extract.hxx> +#endif +//#ifndef _CONNECTIVITY_OTOOLS_HXX_ +//#include "odbc/OTools.hxx" +//#endif + +using namespace connectivity::odbc; +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::io; +using namespace com::sun::star::util; +//------------------------------------------------------------------------------ +// IMPLEMENT_SERVICE_INFO(OResultSet,"com.sun.star.sdbcx.OResultSet","com.sun.star.sdbc.ResultSet"); +::rtl::OUString SAL_CALL OResultSet::getImplementationName( ) throw ( RuntimeException) \ +{ + return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.odbc.ResultSet"); +} +// ------------------------------------------------------------------------- + Sequence< ::rtl::OUString > SAL_CALL OResultSet::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 OResultSet::supportsService( const ::rtl::OUString& _rServiceName ) throw( RuntimeException) +{ + Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); + const ::rtl::OUString* pSupported = aSupported.getConstArray(); + for (sal_Int32 i=0; i<aSupported.getLength(); ++i, ++pSupported) + if (pSupported->equals(_rServiceName)) + return sal_True; + + return sal_False; +} + +// ------------------------------------------------------------------------- +OResultSet::OResultSet(SQLHANDLE _pStatementHandle ,OStatement_Base* pStmt) : OResultSet_BASE(m_aMutex) + ,OPropertySetHelper(OResultSet_BASE::rBHelper) + ,m_aStatement((OWeakObject*)pStmt) + ,m_aStatementHandle(_pStatementHandle) + ,m_aConnectionHandle(pStmt->getConnectionHandle()) + ,m_nRowPos(0) + ,m_bLastRecord(sal_False) + ,m_bEOF(sal_False) + ,m_bFreeHandle(sal_False) + ,m_xMetaData(NULL) + ,m_bInserting(sal_False) + ,m_nLastColumnPos(0) +{ + osl_incrementInterlockedCount( &m_refCount ); + m_pRowStatusArray = new SQLUSMALLINT[1]; // the default value + N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_STATUS_PTR,m_pRowStatusArray,SQL_IS_POINTER); + + SQLSMALLINT nValueLen = 0; + N3SQLGetInfo(m_aConnectionHandle,SQL_GETDATA_EXTENSIONS,&nValueLen,sizeof nValueLen,&nValueLen); + SQLINTEGER nCurType = 0; + N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,&nCurType,SQL_IS_UINTEGER,0); + + allocBuffer((SQL_GD_ANY_ORDER & nValueLen) != SQL_GD_ANY_ORDER && nCurType != SQL_CURSOR_FORWARD_ONLY); + osl_decrementInterlockedCount( &m_refCount ); +} +// ------------------------------------------------------------------------- +OResultSet::OResultSet(SQLHANDLE _pStatementHandle ) : OResultSet_BASE(m_aMutex) + ,OPropertySetHelper(OResultSet_BASE::rBHelper) + ,m_aStatement(NULL) + ,m_aStatementHandle(_pStatementHandle) + ,m_aConnectionHandle(NULL) + ,m_nRowPos(0) + ,m_bLastRecord(sal_False) + ,m_bEOF(sal_False) + ,m_bFreeHandle(sal_False) + ,m_xMetaData(NULL) + ,m_bInserting(sal_False) + ,m_nLastColumnPos(0) +{ + osl_incrementInterlockedCount( &m_refCount ); + m_pRowStatusArray = new SQLUSMALLINT[1]; // the default value + osl_decrementInterlockedCount( &m_refCount ); + // allocBuffer(); +} + +// ------------------------------------------------------------------------- +OResultSet::~OResultSet() +{ + delete m_pRowStatusArray; + if(m_aBindVector.size()) + releaseBuffer(); +} +// ------------------------------------------------------------------------- +void OResultSet::disposing(void) +{ + OPropertySetHelper::disposing(); + + ::osl::MutexGuard aGuard(m_aMutex); + if(m_bFreeHandle) + { + N3SQLFreeStmt(m_aStatementHandle,SQL_CLOSE); + N3SQLFreeHandle(SQL_HANDLE_STMT,m_aStatementHandle); + m_aStatementHandle = NULL; + } + m_aStatement = NULL; + m_xMetaData = NULL; +} +// ------------------------------------------------------------------------- +void OResultSet::allocBuffer(sal_Bool _bAllocRow) +{ + m_bFetchData = !_bAllocRow; + m_aBindVector.push_back(NULL); // the first is reserved for the bookmark + Reference< XResultSetMetaData > xMeta = getMetaData(); + sal_Int32 nLen = xMeta->getColumnCount(); + for(sal_Int32 i = 1;i<=nLen;++i) + { + switch (xMeta->getColumnType(i)) + { + case DataType::CHAR: + case DataType::VARCHAR: + m_aBindVector.push_back(new ::rtl::OString()); + break; + case DataType::DECIMAL: + case DataType::NUMERIC: + case DataType::BIGINT: + m_aBindVector.push_back(new ::rtl::OString()); + break; + case DataType::DOUBLE: + m_aBindVector.push_back(new double(0.0)); + break; + case DataType::LONGVARCHAR: + m_aBindVector.push_back(new char[2]); // dient nur zum auffinden + break; + case DataType::LONGVARBINARY: + m_aBindVector.push_back(new char[2]); // dient nur zum auffinden + break; + case DataType::DATE: + m_aBindVector.push_back(new DATE_STRUCT); + break; + case DataType::TIME: + m_aBindVector.push_back(new TIME_STRUCT); + break; + case DataType::TIMESTAMP: + m_aBindVector.push_back(new TIMESTAMP_STRUCT); + break; + case DataType::BIT: + m_aBindVector.push_back(new sal_Int8(0)); + break; + case DataType::TINYINT: + case DataType::SMALLINT: + m_aBindVector.push_back(new sal_Int16(0)); + break; + case DataType::INTEGER: + m_aBindVector.push_back(new sal_Int32(0)); + break; + case DataType::REAL: + m_aBindVector.push_back(new float(0)); + break; + case DataType::BINARY: + case DataType::VARBINARY: + m_aBindVector.push_back(new sal_Int8[xMeta->getPrecision(i)]); + break; + } + } + m_aLengthVector.resize(nLen + 1); +// if(_bAllocRow) +// m_aRow.resize(nLen + 1); +} +// ------------------------------------------------------------------------- +void OResultSet::releaseBuffer() +{ + Reference< XResultSetMetaData > xMeta = getMetaData(); + sal_Int32 nLen = xMeta->getColumnCount(); + for(sal_Int32 i = 0;i<nLen;++i) + { + switch (xMeta->getColumnType(i+1)) + { + case DataType::CHAR: + case DataType::VARCHAR: + delete (::rtl::OString*) m_aBindVector[i]; + break; + case DataType::DECIMAL: + case DataType::NUMERIC: + case DataType::BIGINT: + delete (::rtl::OString*) m_aBindVector[i]; + break; + case DataType::DOUBLE: + m_aBindVector.push_back(new double(0.0)); + break; + case DataType::LONGVARCHAR: + delete (char*) m_aBindVector[i]; + break; + case DataType::LONGVARBINARY: + delete (char*) m_aBindVector[i]; + break; + case DataType::DATE: + delete (DATE_STRUCT*) m_aBindVector[i]; + break; + case DataType::TIME: + delete (TIME_STRUCT*) m_aBindVector[i]; + break; + case DataType::TIMESTAMP: + delete (TIMESTAMP_STRUCT*) m_aBindVector[i]; + break; + case DataType::BIT: + delete (sal_Int8*) m_aBindVector[i]; + break; + case DataType::TINYINT: + case DataType::SMALLINT: + delete (sal_Int16*) m_aBindVector[i]; + break; + case DataType::INTEGER: + delete (sal_Int32*) m_aBindVector[i]; + break; + case DataType::REAL: + delete (float*) m_aBindVector[i]; + break; + case DataType::BINARY: + case DataType::VARBINARY: + delete (sal_Int8*) m_aBindVector[i]; + break; + } + } + m_aLengthVector.clear(); +} +// ------------------------------------------------------------------------- +Any SAL_CALL OResultSet::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = OPropertySetHelper::queryInterface(rType); + if(!aRet.hasValue()) + aRet = OResultSet_BASE::queryInterface(rType); + return aRet; +} +// ------------------------------------------------------------------------- + Sequence< Type > SAL_CALL OResultSet::getTypes( ) throw( RuntimeException) +{ + OTypeCollection aTypes( ::getCppuType( (const Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ), + ::getCppuType( (const Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ), + ::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet > *)0 )); + + return ::utl::concatSequences(aTypes.getTypes(),OResultSet_BASE::getTypes()); +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSet::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + Reference< XResultSetMetaData > xMeta = getMetaData(); + sal_Int32 nLen = xMeta->getColumnCount(); + sal_Int32 i = 1; + for(;i<=nLen;++i) + if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) : columnName.equalsIgnoreCase(xMeta->getColumnName(i))) + break; + return i; +} +// ------------------------------------------------------------------------- +Reference< XInputStream > SAL_CALL OResultSet::getBinaryStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + // TODO use getBytes instead of + return NULL; +} +// ------------------------------------------------------------------------- +Reference< XInputStream > SAL_CALL OResultSet::getCharacterStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + // TODO use getBytes instead of + return NULL; +} + +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + +// if(m_bFetchData) +// { +// if(columnIndex > m_nLastColumnPos) +// fillRow(columnIndex); +// return any2bool(m_aRow[columnIndex]); +// } + + + return getValue(m_aStatementHandle,columnIndex,SQL_C_BIT,m_bWasNull,**this,sal_Int8(0)); +} +// ------------------------------------------------------------------------- + +sal_Int8 SAL_CALL OResultSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); +// if(!m_bFetchData) +// { +// if(columnIndex > m_nLastColumnPos) +// fillRow(columnIndex); +// return getINT16(m_aRow[columnIndex]); +// } + + + return getValue(m_aStatementHandle,columnIndex,SQL_C_CHAR,m_bWasNull,**this,sal_Int8(0)); +} +// ------------------------------------------------------------------------- + +Sequence< sal_Int8 > SAL_CALL OResultSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); +// if(!m_bFetchData) +// { +// if(columnIndex > m_nLastColumnPos) +// fillRow(columnIndex); +// return *(Sequence< sal_Int8 >*)m_aRow[columnIndex].getValue(); // no assignment because this is very expensive +// } + return OTools::getBytesValue(m_aStatementHandle,columnIndex,getMetaData()->getColumnType(columnIndex),m_bWasNull,**this); +} +// ------------------------------------------------------------------------- + +Date SAL_CALL OResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); +// if(!m_bFetchData) +// { +// if(columnIndex > m_nLastColumnPos) +// fillRow(columnIndex); +// Date aRet; +// m_aRow[columnIndex] >>= aRet; +// return aRet; +// } + + DATE_STRUCT aDate; + aDate.day = 0; + aDate.month = 0; + aDate.year = 0; + aDate = getValue(m_aStatementHandle,columnIndex,SQL_C_DATE,m_bWasNull,**this,aDate); + return Date(aDate.day,aDate.month,aDate.year); +} +// ------------------------------------------------------------------------- + +double SAL_CALL OResultSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); +// if(!m_bFetchData) +// { +// if(columnIndex > m_nLastColumnPos) +// fillRow(columnIndex); +// return connectivity::getDouble(m_aRow[columnIndex]); +// } + return getValue(m_aStatementHandle,columnIndex,SQL_C_DOUBLE,m_bWasNull,**this,double(0.0)); +} +// ------------------------------------------------------------------------- + +float SAL_CALL OResultSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); +// if(!m_bFetchData) +// { +// if(columnIndex > m_nLastColumnPos) +// fillRow(columnIndex); +// float nRet = 0.0; +// m_aRow[columnIndex] >>= nRet; +// return nRet; +// } + return getValue(m_aStatementHandle,columnIndex,SQL_C_FLOAT,m_bWasNull,**this,float(0)); +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); +// if(!m_bFetchData) +// { +// if(columnIndex > m_nLastColumnPos) +// fillRow(columnIndex); +// return getINT32(m_aRow[columnIndex]); +// } + return getValue(m_aStatementHandle,columnIndex,SQL_C_LONG,m_bWasNull,**this,sal_Int32(0)); +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSet::getRow( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_Int32 nValue = 0; + N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_NUMBER,&nValue,SQL_IS_UINTEGER,0); + return nValue; +} +// ------------------------------------------------------------------------- + +sal_Int64 SAL_CALL OResultSet::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + return sal_Int64(); +} +// ------------------------------------------------------------------------- + +Reference< XResultSetMetaData > SAL_CALL OResultSet::getMetaData( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(!m_xMetaData.is()) + m_xMetaData = new OResultSetMetaData(m_aStatementHandle); + return m_xMetaData; +} +// ------------------------------------------------------------------------- +Reference< XArray > SAL_CALL OResultSet::getArray( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + return NULL; +} + +// ------------------------------------------------------------------------- + +Reference< XClob > SAL_CALL OResultSet::getClob( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + return NULL; +} +// ------------------------------------------------------------------------- +Reference< XBlob > SAL_CALL OResultSet::getBlob( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + return NULL; +} +// ------------------------------------------------------------------------- + +Reference< XRef > SAL_CALL OResultSet::getRef( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + return NULL; +} +// ------------------------------------------------------------------------- + +Any SAL_CALL OResultSet::getObject( sal_Int32 columnIndex, const Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + return Any(); +} +// ------------------------------------------------------------------------- + +sal_Int16 SAL_CALL OResultSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); +// if(!m_bFetchData) +// { +// if(columnIndex > m_nLastColumnPos) +// fillRow(columnIndex); +// return getINT16(m_aRow[columnIndex]); +// } + return getValue(m_aStatementHandle,columnIndex,SQL_C_SHORT,m_bWasNull,**this,sal_Int16(0)); +} +// ------------------------------------------------------------------------- + + +::rtl::OUString SAL_CALL OResultSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); +// if(!m_bFetchData) +// { +// if(columnIndex > m_nLastColumnPos) +// fillRow(columnIndex); +// ::rtl::OUString aRet; +// m_aRow[columnIndex] >>= aRet; +// return aRet; +// } + return OTools::getStringValue(m_aStatementHandle,columnIndex,getMetaData()->getColumnType(columnIndex),m_bWasNull,**this); +} +// ------------------------------------------------------------------------- + + +Time SAL_CALL OResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); +// if(!m_bFetchData) +// { +// if(columnIndex > m_nLastColumnPos) +// fillRow(columnIndex); +// Time aRet; +// m_aRow[columnIndex] >>= aRet; +// return aRet; +// } + TIME_STRUCT aTime={0,0,0}; + aTime = getValue(m_aStatementHandle,columnIndex,SQL_C_TIME,m_bWasNull,**this,aTime); + return Time(0,aTime.second,aTime.minute,aTime.hour); +} +// ------------------------------------------------------------------------- + + +DateTime SAL_CALL OResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); +// if(!m_bFetchData) +// { +// if(columnIndex > m_nLastColumnPos) +// fillRow(columnIndex); +// DateTime aRet; +// m_aRow[columnIndex] >>= aRet; +// return aRet; +// } + TIMESTAMP_STRUCT aTime={0,0,0,0,0,0,0}; + aTime = getValue(m_aStatementHandle,columnIndex,SQL_C_TIMESTAMP,m_bWasNull,**this,aTime); + return DateTime(aTime.fraction*1000,aTime.second,aTime.minute,aTime.hour,aTime.day,aTime.month,aTime.year); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::isAfterLast( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return m_nCurrentFetchState == SQL_NO_DATA; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::isFirst( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return m_nRowPos == 1; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::isLast( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return m_bEOF && m_nCurrentFetchState != SQL_NO_DATA; +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::beforeFirst( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(first()) + previous(); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::afterLast( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(last()) + next(); + m_bEOF = sal_True; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::close( ) throw(SQLException, RuntimeException) +{ + { + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + } + dispose(); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::first( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_FIRST,0); + OTools::ThrowException(m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this); + sal_Bool bRet; + if(bRet = (m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO)) + m_nRowPos = 1; + return bRet; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::last( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_LAST,0); + OTools::ThrowException(m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this); + // here I know definitely that I stand on the last record + return m_bLastRecord = (m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_ABSOLUTE,row); + OTools::ThrowException(m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this); + sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO; + if(bRet) + m_nRowPos = row; + return bRet; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::relative( sal_Int32 row ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_RELATIVE,row); + OTools::ThrowException(m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this); + sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO; + if(bRet) + m_nRowPos += row; + return bRet; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::previous( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0); + OTools::ThrowException(m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this); + sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO; + if(bRet) + --m_nRowPos; + return bRet; +} +// ------------------------------------------------------------------------- +Reference< XInterface > SAL_CALL OResultSet::getStatement( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return m_aStatement.get(); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::rowDeleted( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return m_pRowStatusArray[0] == SQL_ROW_DELETED; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::rowInserted( ) throw(SQLException, RuntimeException) +{ ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return m_pRowStatusArray[0] == SQL_ROW_ADDED; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::rowUpdated( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return m_pRowStatusArray[0] == SQL_ROW_UPDATED; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::isBeforeFirst( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return m_nRowPos == 0; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::next( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + // m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_NEXT,0); + m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle); + OTools::ThrowException(m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this); + return m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSet::wasNull( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if(!m_bFetchData) + return !m_aRow[m_nLastColumnPos].hasValue(); + + return m_bWasNull; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::cancel( ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + OTools::ThrowException(N3SQLCancel(m_aStatementHandle),m_aStatementHandle,SQL_HANDLE_STMT,*this); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::clearWarnings( ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- +Any SAL_CALL OResultSet::getWarnings( ) throw(SQLException, RuntimeException) +{ + return Any(); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::insertRow( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + SQLRETURN nRet; + if(pODBC3SQLBulkOperations) + nRet = N3SQLBulkOperations(m_aStatementHandle, SQL_ADD); + else + { + if(isBeforeFirst()) + next(); // must be done + nRet = N3SQLSetPos(m_aStatementHandle,1,SQL_ADD,SQL_LOCK_NO_CHANGE); + } + OTools::ThrowException(nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this); + nRet = N3SQLFreeStmt(m_aStatementHandle,SQL_UNBIND); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateRow( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + SQLRETURN nRet; + nRet = N3SQLSetPos(m_aStatementHandle,1,SQL_UPDATE,SQL_LOCK_NO_CHANGE); + if( nRet == SQL_NEED_DATA) + { + void * pData = NULL; + nRet = N3SQLParamData(m_aStatementHandle,&pData); + do + { + if (nRet != SQL_SUCCESS && nRet != SQL_SUCCESS_WITH_INFO && nRet != SQL_NEED_DATA) + break; + + ::std::vector<void*>::const_iterator aFound = ::std::find(m_aBindVector.begin(),m_aBindVector.end(),pData); + sal_Int32 nPos = m_aBindVector.size() - (m_aBindVector.end() - aFound); + + // TODO transfer long data + // N3SQLPutData(m_aStatementHandle,,); + nRet = N3SQLParamData(m_aStatementHandle,&pData); + } + while (nRet == SQL_NEED_DATA); + + } + OTools::ThrowException(nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this); + // now unbind all columns so we can fetch all columns again with SQLGetData + nRet = N3SQLFreeStmt(m_aStatementHandle,SQL_UNBIND); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::deleteRow( ) throw(SQLException, RuntimeException) +{ + SQLRETURN nRet = N3SQLSetPos(m_aStatementHandle,1,SQL_DELETE,SQL_LOCK_NO_CHANGE); + OTools::ThrowException(nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::cancelRowUpdates( ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::moveToInsertRow( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + // first unbound all columns + N3SQLFreeStmt(m_aStatementHandle,SQL_UNBIND); + // SQLRETURN nRet = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE ,(SQLPOINTER)1,SQL_IS_INTEGER); + m_bInserting = sal_True; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::moveToCurrentRow( ) throw(SQLException, RuntimeException) +{ +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateNull( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + bindValue(m_aStatementHandle,columnIndex,SQL_CHAR,0,0,(sal_Int8*)NULL,NULL,&m_aLengthVector[columnIndex],**this); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateBoolean( sal_Int32 columnIndex, sal_Bool x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + void* pData = m_aBindVector[columnIndex]; + bindValue<sal_Bool>(m_aStatementHandle,columnIndex,SQL_BIT,0,0,&x,pData,&m_aLengthVector[columnIndex],**this); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateByte( sal_Int32 columnIndex, sal_Int8 x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + void* pData = m_aBindVector[columnIndex]; + bindValue(m_aStatementHandle,columnIndex,SQL_CHAR,0,0,&x,pData,&m_aLengthVector[columnIndex],**this); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateShort( sal_Int32 columnIndex, sal_Int16 x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + void* pData = m_aBindVector[columnIndex]; + bindValue(m_aStatementHandle,columnIndex,SQL_TINYINT,0,0,&x,pData,&m_aLengthVector[columnIndex],**this); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateInt( sal_Int32 columnIndex, sal_Int32 x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + void* pData = m_aBindVector[columnIndex]; + bindValue(m_aStatementHandle,columnIndex,SQL_INTEGER,0,0,&x,pData,&m_aLengthVector[columnIndex],**this); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateLong( sal_Int32 columnIndex, sal_Int64 x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + throw RuntimeException(); +} +// ----------------------------------------------------------------------- +void SAL_CALL OResultSet::updateFloat( sal_Int32 columnIndex, float x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + void* pData = m_aBindVector[columnIndex]; + bindValue(m_aStatementHandle,columnIndex,SQL_REAL,0,0,&x,pData,&m_aLengthVector[columnIndex],**this); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateDouble( sal_Int32 columnIndex, double x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + void* pData = m_aBindVector[columnIndex]; + bindValue(m_aStatementHandle,columnIndex,SQL_DOUBLE,0,0,&x,pData,&m_aLengthVector[columnIndex],**this); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateString( sal_Int32 columnIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + void* pData = m_aBindVector[columnIndex]; + bindValue(m_aStatementHandle,columnIndex,SQL_VARCHAR,0,0,&x,pData,&m_aLengthVector[columnIndex],**this); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateBytes( sal_Int32 columnIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + void* pData = m_aBindVector[columnIndex]; + bindValue(m_aStatementHandle,columnIndex,SQL_BINARY,0,0,&x,pData,&m_aLengthVector[columnIndex],**this); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateDate( sal_Int32 columnIndex, const Date& x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + void* pData = m_aBindVector[columnIndex]; + DATE_STRUCT aVal = OTools::DateToOdbcDate(x); + bindValue(m_aStatementHandle,columnIndex,SQL_DATE,0,0,&aVal,pData,&m_aLengthVector[columnIndex],**this); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateTime( sal_Int32 columnIndex, const Time& x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + void* pData = m_aBindVector[columnIndex]; + TIME_STRUCT aVal = OTools::TimeToOdbcTime(x); + bindValue(m_aStatementHandle,columnIndex,SQL_TIME,0,0,&aVal,pData,&m_aLengthVector[columnIndex],**this); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateTimestamp( sal_Int32 columnIndex, const DateTime& x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + void* pData = m_aBindVector[columnIndex]; + TIMESTAMP_STRUCT aVal = OTools::DateTimeToTimestamp(x); + bindValue(m_aStatementHandle,columnIndex,SQL_TIMESTAMP,0,0,&aVal,pData,&m_aLengthVector[columnIndex],**this); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateBinaryStream( sal_Int32 columnIndex, const Reference< XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateCharacterStream( sal_Int32 columnIndex, const Reference< XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::refreshRow( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + SQLRETURN nRet = N3SQLSetPos(m_aStatementHandle,1,SQL_REFRESH,SQL_LOCK_NO_CHANGE); + // m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_RELATIVE,0); + OTools::ThrowException(nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this); +} +// ------------------------------------------------------------------------- +void SAL_CALL OResultSet::updateObject( sal_Int32 columnIndex, const Any& x ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); +// switch(x.getValueTypeClass()) +// { +// case TypeClass_VOID: +// args[0].l = NULL; +// break; +// +// case TypeClass_BOOLEAN: +// { +// sal_Bool f; +// x >>= f; +// updateBoolean(columnIndex,f); +// } +// break; +// case TypeClass_BYTE: +// { +// sal_Int8 f; +// x >>= f; +// updateByte(columnIndex,f); +// } +// break; +// case TypeClass_SHORT: +// case TypeClass_UNSIGNED_SHORT: +// { +// sal_Int16 f; +// x >>= f; +// updateShort(columnIndex,f); +// } +// break; +// case TypeClass_LONG: +// case TypeClass_UNSIGNED_LONG: +// { +// sal_Int32 f; +// x >>= f; +// updateInt(columnIndex,f); +// } +// break; +// case TypeClass_HYPER: +// case TypeClass_UNSIGNED_HYPER: +// { +// sal_Int64 f; +// x >>= f; +// updateLong(columnIndex,f); +// } +// break; +// case TypeClass_FLOAT: +// { +// float f; +// x >>= f; +// updateFloat(columnIndex,f); +// } +// break; +// case TypeClass_DOUBLE: +// updateDouble(columnIndex,::utl::getDouble(x)); +// break; +// case TypeClass_CHAR: +// case TypeClass_STRING: +// updateString(columnIndex,::utl::getString(x)); +// break; +// case TypeClass_ENUM: +// default: +// OSL_ENSHURE(0,"UNKOWN TYPE for OResultSet::updateObject"); +// } +// return; +// // Parameter konvertieren +// // temporaere Variable initialisieren +// char * cSignature = "(ILjava/lang/Object;)V"; +// char * cMethodName = "updateObject"; +// // Java-Call absetzen +// } +} +// ------------------------------------------------------------------------- + +void SAL_CALL OResultSet::updateNumericObject( sal_Int32 columnIndex, const Any& x, sal_Int32 scale ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + columnIndex = mapColumn(columnIndex); + OSL_ENSHURE(0,"OResultSet::updateNumericObject: NYI"); +// SDBThreadAttach t; +// if( t.pEnv ) +// { +// jvalue args[1]; +// // Parameter konvertieren +// args[0].l = +// // temporaere Variable initialisieren +// char * cSignature = "(I;Ljava/lang/Object;I)V"; +// char * cMethodName = "updateObject"; +// // Java-Call absetzen +// jmethodID mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature ); +// if( mID ){ +// t.pEnv->CallVoidMethod( object, mID,columnIndex,args[0].l,scale); + // ThrowSQLException(t.pEnv,*this); +// t.pEnv->DeleteLocalRef((jobject)args[0].l); +// } +// } +} +// ------------------------------------------------------------------------- +// XRowLocate +Any SAL_CALL OResultSet::getBookmark( ) throw( SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_uInt32 nValue = SQL_UB_OFF; + N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_USE_BOOKMARKS,&nValue,SQL_IS_UINTEGER,NULL); + if(nValue == SQL_UB_OFF) + throw SQLException(); + + + return makeAny(OTools::getBytesValue(m_aStatementHandle,0,SQL_BINARY,m_bWasNull,**this)); +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::moveToBookmark( const Any& bookmark ) throw( SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + Sequence<sal_Int8> aBookmark; + bookmark >>= aBookmark; + SQLRETURN nReturn = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_FETCH_BOOKMARK_PTR,aBookmark.getArray(),SQL_IS_POINTER); + + m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_BOOKMARK,0); + OTools::ThrowException(m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this); + return m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw( SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + Sequence<sal_Int8> aBookmark; + bookmark >>= aBookmark; + SQLRETURN nReturn = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_FETCH_BOOKMARK_PTR,aBookmark.getArray(),SQL_IS_POINTER); + + m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_BOOKMARK,rows); + OTools::ThrowException(m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this); + return m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OResultSet::compareBookmarks( const Any& first, const Any& second ) throw( SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return (first == second) ? CompareBookmark::EQUAL : CompareBookmark::NOT_EQUAL; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSet::hasOrderedBookmarks( ) throw( SQLException, RuntimeException) +{ + return sal_False; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OResultSet::hashBookmark( const Any& bookmark ) throw( SQLException, RuntimeException) +{ + throw SQLException(); +} +// ------------------------------------------------------------------------- +// XDeleteRows +Sequence< sal_Int32 > SAL_CALL OResultSet::deleteRows( const Sequence< Any >& rows ) throw( SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OResultSet_BASE::rBHelper.bDisposed) + throw DisposedException(); + + SQLRETURN nReturn; + + const Any* pBegin = rows.getConstArray(); + const Any* pEnd = pBegin + rows.getLength(); + + typedef sal_Int8* sal_INT8; + sal_Int8** pArray = new sal_INT8[rows.getLength()]; + for(sal_Int32 i=0;pBegin != pEnd;++i,++pBegin) + { + pArray[i] = ((Sequence<sal_Int8>*)pBegin->getValue())->getArray(); + } + + sal_Int32* pStatusArray = new sal_Int32[rows.getLength()]; + + + nReturn = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_STATUS_PTR ,(SQLPOINTER)pStatusArray,SQL_IS_POINTER); + nReturn = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE ,(SQLPOINTER)rows.getLength(),SQL_IS_INTEGER); + sal_Int32 nLen = rows.getLength(); + nReturn = N3SQLBindCol(m_aStatementHandle,0,SQL_C_VARBOOKMARK,pArray,rows.getLength(),&nLen); + nReturn = N3SQLBulkOperations(m_aStatementHandle,SQL_DELETE_BY_BOOKMARK); + + delete [] pArray; + + Sequence< sal_Int32 > aRet(rows.getLength()); + for(sal_Int32 j=0;j<rows.getLength();++j) + { + aRet.getArray()[j] = pStatusArray[j] == SQL_ROW_SUCCESS; + } + delete pStatusArray; + delete pArray; + return aRet; +} +//------------------------------------------------------------------------------ +sal_Int32 OResultSet::getResultSetConcurrency() const throw( SQLException, RuntimeException) +{ + sal_uInt32 nValue; + N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CONCURRENCY,&nValue,SQL_IS_UINTEGER,0); + return nValue; +} +//------------------------------------------------------------------------------ +sal_Int32 OResultSet::getResultSetType() const throw( SQLException, RuntimeException) +{ + sal_uInt32 nValue; + N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_SENSITIVITY,&nValue,SQL_IS_UINTEGER,0); + return nValue; +} +//------------------------------------------------------------------------------ +sal_Int32 OResultSet::getFetchDirection() const throw( SQLException, RuntimeException) +{ + sal_uInt32 nValue; + N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,&nValue,SQL_IS_UINTEGER,0); + return nValue; +} +//------------------------------------------------------------------------------ +sal_Int32 OResultSet::getFetchSize() const throw( SQLException, RuntimeException) +{ + sal_uInt32 nValue; + N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE,&nValue,SQL_IS_UINTEGER,0); + return nValue; +} +//------------------------------------------------------------------------------ +::rtl::OUString OResultSet::getCursorName() const throw( SQLException, RuntimeException) +{ + SQLCHAR pName[258]; + SQLSMALLINT nRealLen = 0; + N3SQLGetCursorName(m_aStatementHandle,(SQLCHAR*)pName,256,&nRealLen); + return ::rtl::OUString::createFromAscii((const char*)pName); +} +// ------------------------------------------------------------------------- +sal_Bool OResultSet::isBookmarkable() const throw( SQLException, RuntimeException) +{ + if(!m_aConnectionHandle) + return sal_False; + + sal_uInt32 nValue; + N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,&nValue,SQL_IS_UINTEGER,0); + + sal_Int32 nAttr = 0; + switch(nValue) + { + case SQL_CURSOR_FORWARD_ONLY: + return sal_False; + break; + case SQL_CURSOR_STATIC: + OTools::GetInfo(m_aConnectionHandle,SQL_STATIC_CURSOR_ATTRIBUTES1,nAttr,*(Reference< XInterface >*)this); + break; + case SQL_CURSOR_KEYSET_DRIVEN: + OTools::GetInfo(m_aConnectionHandle,SQL_KEYSET_CURSOR_ATTRIBUTES1,nAttr,*(Reference< XInterface >*)this); + break; + case SQL_CURSOR_DYNAMIC: + OTools::GetInfo(m_aConnectionHandle,SQL_DYNAMIC_CURSOR_ATTRIBUTES1,nAttr,*(Reference< XInterface >*)this); + break; + } + sal_uInt32 nUseBookmark = SQL_UB_OFF; + N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_USE_BOOKMARKS,&nUseBookmark,SQL_IS_UINTEGER,NULL); + + return (nUseBookmark != SQL_UB_OFF) && (nAttr & SQL_CA1_BOOKMARK) == SQL_CA1_BOOKMARK; +} +//------------------------------------------------------------------------------ +void OResultSet::setFetchDirection(sal_Int32 _par0) throw( SQLException, RuntimeException) +{ + N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,(SQLPOINTER)_par0,SQL_IS_UINTEGER); +} +//------------------------------------------------------------------------------ +void OResultSet::setFetchSize(sal_Int32 _par0) throw( SQLException, RuntimeException) +{ + N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE,(SQLPOINTER)_par0,SQL_IS_UINTEGER); + delete m_pRowStatusArray; + m_pRowStatusArray = new SQLUSMALLINT[_par0]; + N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_STATUS_PTR,m_pRowStatusArray,SQL_IS_POINTER); +} +// ------------------------------------------------------------------------- +IPropertyArrayHelper* OResultSet::createArrayHelper( ) const +{ + Sequence< Property > aProps(6); + Property* pProperties = aProps.getArray(); + sal_Int32 nPos = 0; + DECL_PROP1IMPL(CURSORNAME, ::rtl::OUString) PropertyAttribute::READONLY); + DECL_PROP0(FETCHDIRECTION, sal_Int32); + DECL_PROP0(FETCHSIZE, sal_Int32); + DECL_BOOL_PROP1IMPL(ISBOOKMARKABLE) PropertyAttribute::READONLY); + DECL_PROP1IMPL(RESULTSETCONCURRENCY,sal_Int32) PropertyAttribute::READONLY); + DECL_PROP1IMPL(RESULTSETTYPE, sal_Int32) PropertyAttribute::READONLY); + + return new OPropertyArrayHelper(aProps); +} +// ------------------------------------------------------------------------- +IPropertyArrayHelper & OResultSet::getInfoHelper() +{ + return *const_cast<OResultSet*>(this)->getArrayHelper(); +} +// ------------------------------------------------------------------------- +sal_Bool OResultSet::convertFastPropertyValue( + Any & rConvertedValue, + Any & rOldValue, + sal_Int32 nHandle, + const Any& rValue ) + throw (::com::sun::star::lang::IllegalArgumentException) +{ + switch(nHandle) + { + case PROPERTY_ID_ISBOOKMARKABLE: + case PROPERTY_ID_CURSORNAME: + case PROPERTY_ID_RESULTSETCONCURRENCY: + case PROPERTY_ID_RESULTSETTYPE: + throw ::com::sun::star::lang::IllegalArgumentException(); + break; + case PROPERTY_ID_FETCHDIRECTION: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection()); + case PROPERTY_ID_FETCHSIZE: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize()); + default: + ; + } + return sal_False; +} +// ------------------------------------------------------------------------- +void OResultSet::setFastPropertyValue_NoBroadcast( + sal_Int32 nHandle, + const Any& rValue + ) + throw (Exception) +{ + switch(nHandle) + { + case PROPERTY_ID_ISBOOKMARKABLE: + case PROPERTY_ID_CURSORNAME: + case PROPERTY_ID_RESULTSETCONCURRENCY: + case PROPERTY_ID_RESULTSETTYPE: + throw Exception(); + break; + case PROPERTY_ID_FETCHDIRECTION: + setFetchDirection(getINT32(rValue)); + break; + case PROPERTY_ID_FETCHSIZE: + setFetchSize(getINT32(rValue)); + break; + default: + ; + } +} +// ------------------------------------------------------------------------- +void OResultSet::getFastPropertyValue( + Any& rValue, + sal_Int32 nHandle + ) const +{ + switch(nHandle) + { + case PROPERTY_ID_ISBOOKMARKABLE: + rValue = bool2any(isBookmarkable()); + break; + case PROPERTY_ID_CURSORNAME: + rValue <<= getCursorName(); + break; + case PROPERTY_ID_RESULTSETCONCURRENCY: + rValue <<= getResultSetConcurrency(); + break; + case PROPERTY_ID_RESULTSETTYPE: + rValue <<= getResultSetType(); + break; + case PROPERTY_ID_FETCHDIRECTION: + rValue <<= getFetchDirection(); + break; + case PROPERTY_ID_FETCHSIZE: + rValue <<= getFetchSize(); + break; + } +} +// ------------------------------------------------------------------------- +void OResultSet::openTypeInfo() throw(SQLException, RuntimeException) +{ + m_bFreeHandle = sal_True; + OTools::ThrowException(N3SQLGetTypeInfo(m_aStatementHandle, SQL_ALL_TYPES),m_aStatementHandle,SQL_HANDLE_STMT,*this); +} +//----------------------------------------------------------------------------- +void OResultSet::openTables(const Any& catalog, const ::rtl::OUString& schemaPattern, + const ::rtl::OUString& tableNamePattern, + const Sequence< ::rtl::OUString >& types ) throw(SQLException, RuntimeException) +{ + m_bFreeHandle = sal_True; + ::rtl::OString aPKQ,aPKO,aPKN,aCOL; + const ::rtl::OUString *pSchemaPat = NULL; + + if(schemaPattern.toChar() != '%') + pSchemaPat = &schemaPattern; + else + pSchemaPat = NULL; + + const char *pPKQ = catalog.hasValue() ? (aPKQ = ::rtl::OUStringToOString(connectivity::getString(catalog), + osl_getThreadTextEncoding() + )).getStr() : NULL, + *pPKO = pSchemaPat ? (aPKO = ::rtl::OUStringToOString(schemaPattern, + osl_getThreadTextEncoding() + )).getStr() : NULL, + *pPKN = aPKN = ::rtl::OUStringToOString(tableNamePattern, + osl_getThreadTextEncoding() + ).getStr(); + + + const char *pCOL = NULL; + const ::rtl::OUString* pBegin = types.getConstArray(); + const ::rtl::OUString* pEnd = pBegin + types.getLength(); + for(;pBegin != pEnd;++pBegin) + { + aCOL += ::rtl::OUStringToOString(*pBegin, + osl_getThreadTextEncoding() + ); + aCOL += ","; + } + if(aCOL.getLength()) + pCOL = aCOL.getStr(); + + SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle, + (SDB_ODBC_CHAR *) pPKQ, catalog.hasValue() ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKO, SQL_NTS , + (SDB_ODBC_CHAR *) pPKN, SQL_NTS, + (SDB_ODBC_CHAR *) pCOL, pCOL ? SQL_NTS : 0); + OTools::ThrowException(nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); + +} +//----------------------------------------------------------------------------- +void OResultSet::openTablesTypes( ) throw(SQLException, RuntimeException) +{ + m_bFreeHandle = sal_True; + SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle, + 0,0, + 0,0, + 0,0, + (SDB_ODBC_CHAR *) SQL_ALL_TABLE_TYPES,SQL_NTS); + OTools::ThrowException(nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); + + m_aColMapping.clear(); + m_aColMapping.push_back(-1); + m_aColMapping.push_back(4); + m_xMetaData = new OResultSetMetaData(m_aStatementHandle,m_aColMapping); +} +// ------------------------------------------------------------------------- +void OResultSet::openCatalogs() throw(SQLException, RuntimeException) +{ + m_bFreeHandle = sal_True; + SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle, + (SDB_ODBC_CHAR *) SQL_ALL_CATALOGS,SQL_NTS, + 0,0, + 0,0, + (SDB_ODBC_CHAR *) "",SQL_NTS); + + OTools::ThrowException(nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); + + m_aColMapping.clear(); + m_aColMapping.push_back(-1); + m_aColMapping.push_back(1); + m_xMetaData = new OResultSetMetaData(m_aStatementHandle,m_aColMapping); +} +// ------------------------------------------------------------------------- +void OResultSet::openSchemas() throw(SQLException, RuntimeException) +{ + m_bFreeHandle = sal_True; + SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle, + 0,0, + (SDB_ODBC_CHAR *) SQL_ALL_SCHEMAS,SQL_NTS, + 0,0, + (SDB_ODBC_CHAR *) "",SQL_NTS); + OTools::ThrowException(nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); + + m_aColMapping.clear(); + m_aColMapping.push_back(-1); + m_aColMapping.push_back(2); + m_xMetaData = new OResultSetMetaData(m_aStatementHandle,m_aColMapping); +} +// ------------------------------------------------------------------------- +void OResultSet::openColumnPrivileges( const Any& catalog, const ::rtl::OUString& schema, + const ::rtl::OUString& table, const ::rtl::OUString& columnNamePattern ) + throw(SQLException, RuntimeException) +{ + const ::rtl::OUString *pSchemaPat = NULL; + + if(schema.toChar() != '%') + pSchemaPat = &schema; + else + pSchemaPat = NULL; + + m_bFreeHandle = sal_True; + ::rtl::OString aPKQ,aPKO,aPKN,aCOL; + + const char *pPKQ = catalog.hasValue() ? (aPKQ = ::rtl::OUStringToOString(connectivity::getString(catalog), + osl_getThreadTextEncoding() + )).getStr() : NULL, + *pPKO = pSchemaPat ? (aPKO = ::rtl::OUStringToOString(schema, + osl_getThreadTextEncoding() + )).getStr() : NULL, + *pPKN = aPKN = ::rtl::OUStringToOString(table, + osl_getThreadTextEncoding() + ).getStr(), + *pCOL = aCOL = ::rtl::OUStringToOString(columnNamePattern, + osl_getThreadTextEncoding() + ).getStr(); + + + SQLRETURN nRetcode = N3SQLColumnPrivileges(m_aStatementHandle, + (SDB_ODBC_CHAR *) pPKQ, catalog.hasValue() ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKO, SQL_NTS , + (SDB_ODBC_CHAR *) pPKN, SQL_NTS, + (SDB_ODBC_CHAR *) pCOL, SQL_NTS); + OTools::ThrowException(nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); + + +} +// ------------------------------------------------------------------------- +void OResultSet::openColumns( const Any& catalog, const ::rtl::OUString& schemaPattern, + const ::rtl::OUString& tableNamePattern, const ::rtl::OUString& columnNamePattern ) + throw(SQLException, RuntimeException) +{ + const ::rtl::OUString *pSchemaPat = NULL; + + if(schemaPattern.toChar() != '%') + pSchemaPat = &schemaPattern; + else + pSchemaPat = NULL; + + m_bFreeHandle = sal_True; + ::rtl::OString aPKQ,aPKO,aPKN,aCOL; + + const char *pPKQ = catalog.hasValue() ? (aPKQ = ::rtl::OUStringToOString(connectivity::getString(catalog), + osl_getThreadTextEncoding() + )).getStr() : NULL, + *pPKO = pSchemaPat ? (aPKO = ::rtl::OUStringToOString(schemaPattern, + osl_getThreadTextEncoding() + )).getStr() : NULL, + *pPKN = aPKN = ::rtl::OUStringToOString(tableNamePattern, + osl_getThreadTextEncoding() + ).getStr(), + *pCOL = aCOL = ::rtl::OUStringToOString(columnNamePattern, + osl_getThreadTextEncoding() + ).getStr(); + + + SQLRETURN nRetcode = N3SQLColumns(m_aStatementHandle, + (SDB_ODBC_CHAR *) pPKQ, catalog.hasValue() ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKO, SQL_NTS , + (SDB_ODBC_CHAR *) pPKN, SQL_NTS, + (SDB_ODBC_CHAR *) pCOL, SQL_NTS); + + OTools::ThrowException(nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); +} +// ------------------------------------------------------------------------- +void OResultSet::openProcedureColumns( const Any& catalog, const ::rtl::OUString& schemaPattern, + const ::rtl::OUString& procedureNamePattern,const ::rtl::OUString& columnNamePattern ) + throw(SQLException, RuntimeException) +{ + const ::rtl::OUString *pSchemaPat = NULL; + + if(schemaPattern.toChar() != '%') + pSchemaPat = &schemaPattern; + else + pSchemaPat = NULL; + + m_bFreeHandle = sal_True; + ::rtl::OString aPKQ,aPKO,aPKN,aCOL; + + const char *pPKQ = catalog.hasValue() ? (aPKQ = ::rtl::OUStringToOString(connectivity::getString(catalog), + osl_getThreadTextEncoding() + )).getStr() : NULL, + *pPKO = pSchemaPat ? (aPKO = ::rtl::OUStringToOString(schemaPattern, + osl_getThreadTextEncoding() + )).getStr() : NULL, + *pPKN = aPKN = ::rtl::OUStringToOString(procedureNamePattern, + osl_getThreadTextEncoding() + ).getStr(), + *pCOL = aCOL = ::rtl::OUStringToOString(columnNamePattern, + osl_getThreadTextEncoding() + ).getStr(); + + + SQLRETURN nRetcode = N3SQLProcedureColumns(m_aStatementHandle, + (SDB_ODBC_CHAR *) pPKQ, catalog.hasValue() ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKO, SQL_NTS , + (SDB_ODBC_CHAR *) pPKN, SQL_NTS, + (SDB_ODBC_CHAR *) pCOL, SQL_NTS); + + OTools::ThrowException(nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); +} +// ------------------------------------------------------------------------- +void OResultSet::openProcedures(const Any& catalog, const ::rtl::OUString& schemaPattern, + const ::rtl::OUString& procedureNamePattern) + throw(SQLException, RuntimeException) +{ + const ::rtl::OUString *pSchemaPat = NULL; + + if(schemaPattern.toChar() != '%') + pSchemaPat = &schemaPattern; + else + pSchemaPat = NULL; + + m_bFreeHandle = sal_True; + ::rtl::OString aPKQ,aPKO,aPKN,aCOL; + + const char *pPKQ = catalog.hasValue() ? (aPKQ = ::rtl::OUStringToOString(connectivity::getString(catalog), + osl_getThreadTextEncoding() + )).getStr() : NULL, + *pPKO = pSchemaPat ? (aPKO = ::rtl::OUStringToOString(schemaPattern, + osl_getThreadTextEncoding() + )).getStr() : NULL, + *pPKN = aPKN = ::rtl::OUStringToOString(procedureNamePattern, + osl_getThreadTextEncoding() + ).getStr(); + + + SQLRETURN nRetcode = N3SQLProcedures(m_aStatementHandle, + (SDB_ODBC_CHAR *) pPKQ, catalog.hasValue() ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKO, SQL_NTS , + (SDB_ODBC_CHAR *) pPKN, SQL_NTS); + OTools::ThrowException(nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); +} +// ------------------------------------------------------------------------- +void OResultSet::openSpecialColumns(sal_Bool _bRowVer,const Any& catalog, const ::rtl::OUString& schema, + const ::rtl::OUString& table,sal_Int32 scope, sal_Bool nullable ) + throw(SQLException, RuntimeException) +{ + const ::rtl::OUString *pSchemaPat = NULL; + + if(schema.toChar() != '%') + pSchemaPat = &schema; + else + pSchemaPat = NULL; + + m_bFreeHandle = sal_True; + ::rtl::OString aPKQ,aPKO,aPKN,aCOL; + + const char *pPKQ = catalog.hasValue() ? (aPKQ = ::rtl::OUStringToOString(connectivity::getString(catalog), + osl_getThreadTextEncoding() + )).getStr() : NULL, + *pPKO = pSchemaPat ? (aPKO = ::rtl::OUStringToOString(schema, + osl_getThreadTextEncoding() + )).getStr() : NULL, + *pPKN = aPKN = ::rtl::OUStringToOString(table, + osl_getThreadTextEncoding() + ).getStr(); + + + SQLRETURN nRetcode = N3SQLSpecialColumns(m_aStatementHandle,_bRowVer ? SQL_ROWVER : SQL_BEST_ROWID, + (SDB_ODBC_CHAR *) pPKQ, catalog.hasValue() ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKO, SQL_NTS , + (SDB_ODBC_CHAR *) pPKN, SQL_NTS, + scope, + nullable ? SQL_NULLABLE : SQL_NO_NULLS); + OTools::ThrowException(nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); +} +// ------------------------------------------------------------------------- +void OResultSet::openVersionColumns(const Any& catalog, const ::rtl::OUString& schema, + const ::rtl::OUString& table) throw(SQLException, RuntimeException) +{ + openSpecialColumns(sal_True,catalog,schema,table,SQL_SCOPE_TRANSACTION,sal_False); +} +// ------------------------------------------------------------------------- +void OResultSet::openBestRowIdentifier( const Any& catalog, const ::rtl::OUString& schema, + const ::rtl::OUString& table,sal_Int32 scope,sal_Bool nullable ) throw(SQLException, RuntimeException) +{ + openSpecialColumns(sal_False,catalog,schema,table,scope,nullable); +} +// ------------------------------------------------------------------------- +void OResultSet::openForeignKeys( const Any& catalog, const ::rtl::OUString* schema, + const ::rtl::OUString* table, + const Any& catalog2, const ::rtl::OUString* schema2, + const ::rtl::OUString* table2) throw(SQLException, RuntimeException) +{ + m_bFreeHandle = sal_True; + + ::rtl::OString aPKQ,aPKO,aPKN, aFKQ, aFKO, aFKN; + + const char *pPKQ = catalog.hasValue() ? (aPKQ = ::rtl::OUStringToOString(connectivity::getString(catalog), + osl_getThreadTextEncoding() + )).getStr() : NULL, + *pPKO = schema ? (aPKO = ::rtl::OUStringToOString(*schema, + osl_getThreadTextEncoding() + )).getStr() : NULL, + *pPKN = table ? (aPKN = ::rtl::OUStringToOString(*table, + osl_getThreadTextEncoding() + )).getStr(): NULL, + *pFKQ = catalog2.hasValue() ? (aFKQ = ::rtl::OUStringToOString(connectivity::getString(catalog), + osl_getThreadTextEncoding() + )).getStr() : NULL, + *pFKO = schema2 ? (aFKO = ::rtl::OUStringToOString(*schema2, + osl_getThreadTextEncoding() + )).getStr() : NULL, + *pFKN = table2 ? (aFKN = ::rtl::OUStringToOString(*table2, + osl_getThreadTextEncoding() + )).getStr() : NULL; + + + SQLRETURN nRetcode = N3SQLForeignKeys(m_aStatementHandle, + (SDB_ODBC_CHAR *) pPKQ, catalog.hasValue() ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKO, SQL_NTS , + (SDB_ODBC_CHAR *) pPKN, pPKN ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pFKQ, catalog2.hasValue() ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pFKO, SQL_NTS , + (SDB_ODBC_CHAR *) pFKN, SQL_NTS + ); + OTools::ThrowException(nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); +} +// ------------------------------------------------------------------------- +void OResultSet::openImportedKeys(const Any& catalog, const ::rtl::OUString& schema, + const ::rtl::OUString& table) throw(SQLException, RuntimeException) +{ + openForeignKeys(catalog,!schema.compareToAscii("%") ? &schema : NULL,&table,Any(),NULL,NULL); +} +// ------------------------------------------------------------------------- +void OResultSet::openExportedKeys(const Any& catalog, const ::rtl::OUString& schema, + const ::rtl::OUString& table) throw(SQLException, RuntimeException) +{ + openForeignKeys(Any(),NULL,NULL,catalog,!schema.compareToAscii("%") ? &schema : NULL,&table); +} +// ------------------------------------------------------------------------- +void OResultSet::openPrimaryKeys(const Any& catalog, const ::rtl::OUString& schema, + const ::rtl::OUString& table) throw(SQLException, RuntimeException) +{ + const ::rtl::OUString *pSchemaPat = NULL; + + if(schema.toChar() != '%') + pSchemaPat = &schema; + else + pSchemaPat = NULL; + + m_bFreeHandle = sal_True; + ::rtl::OString aPKQ,aPKO,aPKN,aCOL; + + const char *pPKQ = catalog.hasValue() ? (aPKQ = ::rtl::OUStringToOString(connectivity::getString(catalog), + osl_getThreadTextEncoding() + )).getStr() : NULL, + *pPKO = pSchemaPat ? (aPKO = ::rtl::OUStringToOString(schema, + osl_getThreadTextEncoding() + )).getStr() : NULL, + *pPKN = (aPKN = ::rtl::OUStringToOString(table, + osl_getThreadTextEncoding() + )).getStr(); + + + SQLRETURN nRetcode = N3SQLPrimaryKeys(m_aStatementHandle, + (SDB_ODBC_CHAR *) pPKQ, catalog.hasValue() ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKO, SQL_NTS , + (SDB_ODBC_CHAR *) pPKN, SQL_NTS); + OTools::ThrowException(nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); +} +// ------------------------------------------------------------------------- +void OResultSet::openTablePrivileges(const Any& catalog, const ::rtl::OUString& schemaPattern, + const ::rtl::OUString& tableNamePattern) throw(SQLException, RuntimeException) +{ + const ::rtl::OUString *pSchemaPat = NULL; + + if(schemaPattern.toChar() != '%') + pSchemaPat = &schemaPattern; + else + pSchemaPat = NULL; + + m_bFreeHandle = sal_True; + ::rtl::OString aPKQ,aPKO,aPKN; + + const char *pPKQ = catalog.hasValue() ? (aPKQ = ::rtl::OUStringToOString(connectivity::getString(catalog), + osl_getThreadTextEncoding() + )).getStr() : NULL, + *pPKO = pSchemaPat ? (aPKO = ::rtl::OUStringToOString(schemaPattern, + osl_getThreadTextEncoding() + )).getStr() : NULL, + *pPKN = (aPKN = ::rtl::OUStringToOString(tableNamePattern, + osl_getThreadTextEncoding() + )).getStr(); + + + SQLRETURN nRetcode = N3SQLTablePrivileges(m_aStatementHandle, + (SDB_ODBC_CHAR *) pPKQ, catalog.hasValue() ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKO, SQL_NTS , + (SDB_ODBC_CHAR *) pPKN, SQL_NTS); + OTools::ThrowException(nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); +} +// ------------------------------------------------------------------------- +void OResultSet::openIndexInfo( const Any& catalog, const ::rtl::OUString& schema, + const ::rtl::OUString& table,sal_Bool unique,sal_Bool approximate ) + throw(SQLException, RuntimeException) +{ + const ::rtl::OUString *pSchemaPat = NULL; + + if(schema.toChar() != '%') + pSchemaPat = &schema; + else + pSchemaPat = NULL; + + m_bFreeHandle = sal_True; + ::rtl::OString aPKQ,aPKO,aPKN; + + const char *pPKQ = catalog.hasValue() ? (aPKQ = ::rtl::OUStringToOString(connectivity::getString(catalog), + osl_getThreadTextEncoding() + )).getStr() : NULL, + *pPKO = pSchemaPat ? (aPKO = ::rtl::OUStringToOString(schema, + osl_getThreadTextEncoding() + )).getStr() : NULL, + *pPKN = (aPKN = ::rtl::OUStringToOString(table, + osl_getThreadTextEncoding() + )).getStr(); + + + SQLRETURN nRetcode = N3SQLStatistics(m_aStatementHandle, + (SDB_ODBC_CHAR *) pPKQ, catalog.hasValue() ? SQL_NTS : 0, + (SDB_ODBC_CHAR *) pPKO, SQL_NTS , + (SDB_ODBC_CHAR *) pPKN, SQL_NTS, + unique, + approximate); + OTools::ThrowException(nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this); +} +// ------------------------------------------------------------------------- +void OResultSet::fillRow(sal_Int32 _nToColumn) +{ + m_bFetchData = sal_True; + Reference< XResultSetMetaData > xMeta = getMetaData(); + for(sal_Int32 i=m_nLastColumnPos+1;i <= _nToColumn; ++i) + { + switch (xMeta->getColumnType(i)) + { + case DataType::CHAR: + case DataType::VARCHAR: + m_aRow[i] <<= getString(i); + break; + case DataType::DECIMAL: + case DataType::NUMERIC: + case DataType::BIGINT: + m_aRow[i] <<= getString(i); + break; + case DataType::DOUBLE: + m_aRow[i] <<= getDouble(i); + break; + case DataType::LONGVARCHAR: + m_aRow[i] <<= getString(i); + break; + case DataType::LONGVARBINARY: + m_aRow[i] <<= getBytes(i); + break; + case DataType::DATE: + m_aRow[i] <<= getDate(i); + break; + case DataType::TIME: + m_aRow[i] <<= getTime(i); + break; + case DataType::TIMESTAMP: + m_aRow[i] <<= getTimestamp(i); + break; + case DataType::BIT: + m_aRow[i] = bool2any(getBoolean(i)); + break; + case DataType::TINYINT: + m_aRow[i] <<= getByte(i); + break; + case DataType::SMALLINT: + m_aRow[i] <<= getShort(i); + break; + case DataType::INTEGER: + m_aRow[i] <<= getInt(i); + break; + case DataType::REAL: + m_aRow[i] <<= getFloat(i); + break; + case DataType::BINARY: + case DataType::VARBINARY: + m_aRow[i] <<= getBytes(i); + break; + } + } + m_nLastColumnPos = _nToColumn; + m_bFetchData = sal_False; +} + + diff --git a/connectivity/source/drivers/odbc/OResultSetMetaData.cxx b/connectivity/source/drivers/odbc/OResultSetMetaData.cxx new file mode 100644 index 000000000000..ae35669da768 --- /dev/null +++ b/connectivity/source/drivers/odbc/OResultSetMetaData.cxx @@ -0,0 +1,254 @@ +/************************************************************************* + * + * $RCSfile: OResultSetMetaData.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ODBC_ORESULTSETMETADATA_HXX_ +#include "odbc/OResultSetMetaData.hxx" +#endif +#ifndef _CONNECTIVITY_OTOOLS_HXX_ +#include "odbc/OTools.hxx" +#endif + +using namespace connectivity::odbc; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::sdbc; + +// ------------------------------------------------------------------------- +OResultSetMetaData::~OResultSetMetaData() +{ +} +// ------------------------------------------------------------------------- +::rtl::OUString OResultSetMetaData::getCharColAttrib(sal_Int32 _column,sal_Int32 ident) throw(SQLException, RuntimeException) +{ + sal_Int32 column = _column; + if(_column < m_vMapping.size()) // use mapping + column = m_vMapping[_column]; + + sal_Int32 BUFFER_LEN = 128; + char *pName = new char[BUFFER_LEN]; + SQLSMALLINT nRealLen=0; + OTools::ThrowException(N3SQLColAttribute(m_aStatementHandle, + column, + ident, + (SQLPOINTER)pName, + BUFFER_LEN, + &nRealLen, + NULL + ),m_aStatementHandle,SQL_HANDLE_STMT,*this); + if(nRealLen > BUFFER_LEN) + { + delete pName; + pName = new char[nRealLen]; + OTools::ThrowException(N3SQLColAttribute(m_aStatementHandle, + column, + ident, + (SQLPOINTER)pName, + nRealLen, + &nRealLen, + NULL + ),m_aStatementHandle,SQL_HANDLE_STMT,*this); + } + + return ::rtl::OUString::createFromAscii(pName); +} +// ------------------------------------------------------------------------- +sal_Int32 OResultSetMetaData::getNumColAttrib(sal_Int32 _column,sal_Int32 ident) throw(SQLException, RuntimeException) +{ + sal_Int32 column = _column; + if(_column < m_vMapping.size()) // use mapping + column = m_vMapping[_column]; + + sal_Int32 nValue=0; + sal_Int16 nLen = sizeof(nValue); + OTools::ThrowException(N3SQLColAttribute(m_aStatementHandle, + column, + ident, + NULL, + NULL, + NULL, + &nValue),m_aStatementHandle,SQL_HANDLE_STMT,*this); + return nValue; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_DISPLAY_SIZE); +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSetMetaData::getColumnType( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return OTools::MapOdbcType2Jdbc(getNumColAttrib(column,SQL_DESC_TYPE)); +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount( ) throw(SQLException, RuntimeException) +{ + if(m_nColCount != -1) + return m_nColCount; + sal_Int16 nNumResultCols=0; + OTools::ThrowException(N3SQLNumResultCols(m_aStatementHandle,&nNumResultCols),m_aStatementHandle,SQL_HANDLE_STMT,*this); + return m_nColCount = nNumResultCols; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_CASE_SENSITIVE) == SQL_TRUE; +} +// ------------------------------------------------------------------------- + +::rtl::OUString SAL_CALL OResultSetMetaData::getSchemaName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getCharColAttrib(column,SQL_DESC_SCHEMA_NAME); +} +// ------------------------------------------------------------------------- + +::rtl::OUString SAL_CALL OResultSetMetaData::getColumnName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getCharColAttrib(column,SQL_DESC_NAME); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getTableName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getCharColAttrib(column,SQL_DESC_TABLE_NAME); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getCatalogName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getCharColAttrib(column,SQL_DESC_CATALOG_NAME); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getColumnTypeName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getCharColAttrib(column,SQL_DESC_TYPE_NAME +); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getColumnLabel( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getCharColAttrib(column,SQL_DESC_LABEL); +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OResultSetMetaData::getColumnServiceName( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isCurrency( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_FIXED_PREC_SCALE) == SQL_TRUE; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_AUTO_UNIQUE_VALUE) == SQL_TRUE; +} +// ------------------------------------------------------------------------- + + +sal_Bool SAL_CALL OResultSetMetaData::isSigned( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_UNSIGNED) == SQL_FALSE; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OResultSetMetaData::getPrecision( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_PRECISION); +} +sal_Int32 SAL_CALL OResultSetMetaData::getScale( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_SCALE); +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OResultSetMetaData::isNullable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_NULLABLE); +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isSearchable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_SEARCHABLE) != SQL_PRED_NONE; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isReadOnly( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_UPDATABLE) == SQL_ATTR_READONLY; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_UPDATABLE) == SQL_ATTR_WRITE; +; +} +// ------------------------------------------------------------------------- +sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 column ) throw(SQLException, RuntimeException) +{ + return getNumColAttrib(column,SQL_DESC_UPDATABLE) == SQL_ATTR_WRITE; +} +// ------------------------------------------------------------------------- + diff --git a/connectivity/source/drivers/odbc/OStatement.cxx b/connectivity/source/drivers/odbc/OStatement.cxx new file mode 100644 index 000000000000..3fa896cdfece --- /dev/null +++ b/connectivity/source/drivers/odbc/OStatement.cxx @@ -0,0 +1,1004 @@ +/************************************************************************* + * + * $RCSfile: OStatement.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif +#ifndef _CONNECTIVITY_ODBC_OSTATEMENT_HXX_ +#include "odbc/OStatement.hxx" +#endif +#ifndef _CONNECTIVITY_ODBC_OCONNECTION_HXX_ +#include "odbc/OConnection.hxx" +#endif +#ifndef _CONNECTIVITY_ODBC_ORESULTSET_HXX_ +#include "odbc/OResultSet.hxx" +#endif +#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ +#include "propertyids.hxx" +#endif +#ifndef _UTL_PROPERTY_HXX_ +#include <unotools/property.hxx> +#endif +#ifndef _CONNECTIVITY_OTOOLS_HXX_ +#include "odbc/OTools.hxx" +#endif +#ifndef _UTL_UNO3_HXX_ +#include <unotools/uno3.hxx> +#endif +#ifndef _OSL_THREAD_H_ +#include <osl/thread.h> +#endif + +#ifndef _COM_SUN_STAR_SDBC_RESULTSETCONCURRENCY_HPP_ +#include <com/sun/star/sdbc/ResultSetConcurrency.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_RESULTSETTYPE_HPP_ +#include <com/sun/star/sdbc/ResultSetType.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif +#ifndef _UTL_SEQUENCE_HXX_ +#include <unotools/sequence.hxx> +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _CPPUHELPER_EXTRACT_HXX_ +#include <cppuhelper/extract.hxx> +#endif + +#define THROW_SQL(x) \ + OTools::ThrowException(x,m_aStatementHandle,SQL_HANDLE_STMT,*this) + +#ifdef DEBUG +#define DEBUG_THROW \ + try \ + { \ + THROW_SQL(nRetCode); \ + } \ + catch(...) \ + { \ + } +#endif + +using namespace connectivity::odbc; +//------------------------------------------------------------------------------ +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::io; +using namespace com::sun::star::util; +//------------------------------------------------------------------------------ +OStatement_Base::OStatement_Base(OConnection* _pConnection ) : OStatement_BASE(m_aMutex), + OPropertySetHelper(OStatement_BASE::rBHelper), + rBHelper(OStatement_BASE::rBHelper), + m_pConnection(_pConnection), + m_pRowStatusArray(0) +{ + m_pConnection->acquire(); + N3SQLAllocHandle(SQL_HANDLE_STMT,m_pConnection->getConnection(),&m_aStatementHandle); +} +//------------------------------------------------------------------------------ +void OStatement_Base::disposeResultSet() +{ + // free the cursor if alive + Reference< XComponent > xComp(m_xResultSet.get(), UNO_QUERY); + if (xComp.is()) + xComp->dispose(); + m_xResultSet = Reference< XResultSet>(); +} +//------------------------------------------------------------------------------ +void OStatement_BASE2::disposing() +{ + ::osl::MutexGuard aGuard(m_aMutex); + + disposeResultSet(); + + if (N3SQLFreeStmt(m_aStatementHandle,SQL_RESET_PARAMS) || + N3SQLFreeStmt(m_aStatementHandle,SQL_UNBIND) || + N3SQLFreeStmt(m_aStatementHandle,SQL_CLOSE)) + OTools::ThrowException(N3SQLFreeStmt(m_aStatementHandle,SQL_DROP),m_aStatementHandle,SQL_HANDLE_STMT,*this); + + if (m_pConnection) + m_pConnection->release(); + + dispose_ChildImpl(); + OStatement_Base::disposing(); +} +//----------------------------------------------------------------------------- +void SAL_CALL OStatement_BASE2::release() throw(RuntimeException) +{ + relase_ChildImpl(); +} +//----------------------------------------------------------------------------- +Any SAL_CALL OStatement_Base::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = OStatement_BASE::queryInterface(rType); + if(!aRet.hasValue()) + aRet = OPropertySetHelper::queryInterface(rType); + return aRet; +} +// ------------------------------------------------------------------------- +Sequence< Type > SAL_CALL OStatement_Base::getTypes( ) throw(RuntimeException) +{ + ::cppu::OTypeCollection aTypes( ::getCppuType( (const Reference< XMultiPropertySet > *)0 ), + ::getCppuType( (const Reference< XFastPropertySet > *)0 ), + ::getCppuType( (const Reference< XPropertySet > *)0 )); + + return ::utl::concatSequences(aTypes.getTypes(),OStatement_BASE::getTypes()); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OStatement_Base::cancel( ) throw(RuntimeException) +{ + OTools::ThrowException(N3SQLCancel(m_aStatementHandle),m_aStatementHandle,SQL_HANDLE_STMT,*this); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OStatement_Base::close( ) throw(SQLException, RuntimeException) +{ + { + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + } + dispose(); +} +// ------------------------------------------------------------------------- + +void SAL_CALL OStatement::clearBatch( ) throw(SQLException, RuntimeException) +{ + +} +// ------------------------------------------------------------------------- + +void OStatement_Base::reset() throw (SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + clearWarnings (); + + if (m_xResultSet.get().is()) + { + clearMyResultSet(); + THROW_SQL(N3SQLFreeStmt(m_aStatementHandle, SQL_CLOSE)); + } +} +//-------------------------------------------------------------------- +// clearMyResultSet +// If a ResultSet was created for this Statement, close it +//-------------------------------------------------------------------- + +void OStatement_Base::clearMyResultSet () throw (SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + Reference<XCloseable> xCloseable; + if(::utl::query_interface(m_xResultSet.get(),xCloseable)) + xCloseable->close(); + m_xResultSet = Reference< XResultSet>(); +} +//-------------------------------------------------------------------- +sal_Int32 OStatement_Base::getRowCount () throw( SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_Int32 numRows = 0; + + try { + THROW_SQL(N3SQLRowCount(m_aStatementHandle,&numRows)); + } + catch (...) + { + } + return numRows; +} +//-------------------------------------------------------------------- +// lockIfNecessary +// If the given SQL statement contains a 'FOR UPDATE' clause, change +// the concurrency to lock so that the row can then be updated. Returns +// true if the concurrency has been changed +//-------------------------------------------------------------------- + +sal_Bool OStatement_Base::lockIfNecessary (const ::rtl::OUString& sql) throw( SQLException) +{ + sal_Bool rc = sal_False; + + // First, convert the statement to upper case + + ::rtl::OUString sqlStatement = sql.toUpperCase (); + + // Now, look for the FOR UPDATE keywords. If there is any extra white + // space between the FOR and UPDATE, this will fail. + + sal_Int32 index = sqlStatement.indexOf(::rtl::OUString::createFromAscii(" FOR UPDATE")); + + // We found it. Change our concurrency level to ensure that the + // row can be updated. + + if (index > 0) + { + try + { + SQLINTEGER nLock = SQL_CONCUR_LOCK; + THROW_SQL(N3SQLSetStmtAttr(m_aStatementHandle, SQL_CONCURRENCY,(SQLPOINTER)nLock,SQL_IS_UINTEGER)); + } + catch (SQLWarning& warn) + { + // Catch any warnings and place on the warning stack + setWarning (warn); + } + rc = sal_True; + } + + return rc; +} +//-------------------------------------------------------------------- +// setWarning +// Sets the warning +//-------------------------------------------------------------------- + +void OStatement_Base::setWarning (const SQLWarning &ex) throw( SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_aLastWarning = ex; +} + +//-------------------------------------------------------------------- +// getColumnCount +// Return the number of columns in the ResultSet +//-------------------------------------------------------------------- + +sal_Int32 OStatement_Base::getColumnCount () throw( SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_Int16 numCols = 0; + + try { + THROW_SQL(N3SQLNumResultCols(m_aStatementHandle,&numCols)); + } + catch (...) + { + } + return numCols; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OStatement_Base::execute( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + ::rtl::OString aSql(::rtl::OUStringToOString(sql, + osl_getThreadTextEncoding() + )); + + sal_Bool hasResultSet = sal_False; + SQLWarning aWarning; + + // Reset the statement handle and warning + + reset(); + + // Check for a 'FOR UPDATE' statement. If present, change + // the concurrency to lock + + lockIfNecessary (sql); + + // Call SQLExecDirect + + try { + THROW_SQL(N3SQLExecDirect(m_aStatementHandle, (SDB_ODBC_CHAR*)aSql.getStr(),aSql.getLength())); + } + catch (SQLWarning& ex) { + + // Save pointer to warning and save with ResultSet + // object once it is created. + + aWarning = ex; + } + + // Now determine if there is a result set associated with + // the SQL statement that was executed. Get the column + // count, and if it is not zero, there is a result set. + + if (getColumnCount () > 0) + { + hasResultSet = sal_True; + } + + return hasResultSet; +} +//-------------------------------------------------------------------- +// getResultSet +// getResultSet returns the current result as a ResultSet. It +// returns NULL if the current result is not a ResultSet. +//-------------------------------------------------------------------- +Reference< XResultSet > OStatement_Base::getResultSet (sal_Bool checkCount) throw( SQLException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + if (m_xResultSet.get().is()) // if resultset already retrieved, + { + // throw exception to avoid sequence error + throw SQLException(::rtl::OUString::createFromAscii("Invalid state for getResultSet"),*this, + ::rtl::OUString(),0,Any()); + } + + OResultSet* pRs = NULL; + sal_Int32 numCols = 1; + + // If we already know we have result columns, checkCount + // is false. This is an optimization to prevent unneeded + // calls to getColumnCount + + if (checkCount) + numCols = getColumnCount (); + + // Only return a result set if there are result columns + + if (numCols > 0) + { + pRs = new OResultSet(m_aStatementHandle,this); + + // Save a copy of our last result set + // Changed to save copy at getResultSet. + //m_xResultSet = rs; + } + else + clearMyResultSet (); + + return pRs; +} +//-------------------------------------------------------------------- +// getStmtOption +// Invoke SQLGetStmtOption with the given option. +//-------------------------------------------------------------------- + +sal_Int32 OStatement_Base::getStmtOption (short fOption) const throw( SQLException) +{ + sal_Int32 result = 0; + + // Reset last warning message + + // clearWarnings(); + + try { + N3SQLGetStmtAttr(m_aStatementHandle, fOption,&result,SQL_IS_INTEGER,NULL); + } + catch (...) + { + } + return result; +} +// ------------------------------------------------------------------------- + +Reference< XResultSet > SAL_CALL OStatement_Base::executeQuery( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + Reference< XResultSet > xRS = NULL; + + // Execute the statement. If execute returns true, a result + // set exists. + + if (execute (sql)) + { + xRS = getResultSet (sal_False); + } + else + { + // No ResultSet was produced. Raise an exception + throw SQLException(::rtl::OUString::createFromAscii("No ResultSet was produced"),*this, + ::rtl::OUString(),0,Any()); + } + return xRS; +} +// ------------------------------------------------------------------------- + +Reference< XConnection > SAL_CALL OStatement_Base::getConnection( ) throw(SQLException, RuntimeException) +{ + return (Reference< XConnection >)m_pConnection; +} +// ------------------------------------------------------------------------- + +Any SAL_CALL OStatement::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = ::cppu::queryInterface(rType,static_cast< XBatchExecution*> (this)); + if(!aRet.hasValue()) + aRet = OStatement_Base::queryInterface(rType); + return aRet; +} +// ------------------------------------------------------------------------- + +void SAL_CALL OStatement::addBatch( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_aBatchList.push_back(sql); +} +// ------------------------------------------------------------------------- +Sequence< sal_Int32 > SAL_CALL OStatement::executeBatch( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + ::rtl::OString aBatchSql; + sal_Int32 nLen = 0; + for(::std::list< ::rtl::OUString>::const_iterator i=m_aBatchList.begin();i != m_aBatchList.end();++i,++nLen) + { + aBatchSql += ::rtl::OUStringToOString(*i, + osl_getThreadTextEncoding() + ); + aBatchSql += ";"; + } + + THROW_SQL(N3SQLExecDirect(m_aStatementHandle, (SDB_ODBC_CHAR*)aBatchSql.getStr(),aBatchSql.getLength())); + + Sequence< sal_Int32 > aRet(nLen); + sal_Int32* pArray = aRet.getArray(); + for(sal_Int32 j=0;j<nLen;++j) + { + SQLRETURN nError = N3SQLMoreResults(m_aStatementHandle); + if(nError == SQL_SUCCESS) + { + N3SQLRowCount(m_aStatementHandle,&pArray[j]); + } + } + return aRet; +} +// ------------------------------------------------------------------------- + + +sal_Int32 SAL_CALL OStatement_Base::executeUpdate( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_Int32 numRows = -1; + + // Execute the statement. If execute returns false, a + // row count exists. + + if (!execute (sql)) { + numRows = getUpdateCount(); + } + else { + + // No update count was produced (a ResultSet was). Raise + // an exception + + throw new SQLException (::rtl::OUString::createFromAscii("No row count was produced"),*this, + ::rtl::OUString(),0,Any()); + } + return numRows; + +} +// ------------------------------------------------------------------------- + +Reference< XResultSet > SAL_CALL OStatement_Base::getResultSet( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_xResultSet = getResultSet(sal_True); + return m_xResultSet; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OStatement_Base::getUpdateCount( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_Int32 rowCount = -1; + + // Only return a row count for SQL statements that did not + // return a result set. + + if (getColumnCount () == 0) + rowCount = getRowCount (); + + return rowCount; +} +// ------------------------------------------------------------------------- + +sal_Bool SAL_CALL OStatement_Base::getMoreResults( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + OResultSet* pRS = NULL; + SQLWarning warning; + sal_Bool hasResultSet = sal_False; + + // clear previous warnings + + clearWarnings (); + + // Call SQLMoreResults + + try { + hasResultSet = N3SQLMoreResults(m_aStatementHandle) == SQL_SUCCESS; + } + catch (SQLWarning &ex) { + + // Save pointer to warning and save with ResultSet + // object once it is created. + + warning = ex; + } + + // There are more results (it may not be a result set, though) + + if (hasResultSet) + { + + // Now determine if there is a result set associated + // with the SQL statement that was executed. Get the + // column count, and if it is zero, there is not a + // result set. + + if (getColumnCount () == 0) + hasResultSet = sal_False; + } + + // Set the warning for the statement, if one was generated + + setWarning (warning); + + // Return the result set indicator + + return hasResultSet; +} +// ------------------------------------------------------------------------- + +// ------------------------------------------------------------------------- +Any SAL_CALL OStatement_Base::getWarnings( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + return makeAny(m_aLastWarning); +} +// ------------------------------------------------------------------------- + +// ------------------------------------------------------------------------- +void SAL_CALL OStatement_Base::clearWarnings( ) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + m_aLastWarning = SQLWarning(); +} +// ------------------------------------------------------------------------- +//------------------------------------------------------------------------------ +sal_Int32 OStatement_Base::getQueryTimeOut() const throw(SQLException, RuntimeException) +{ + return getStmtOption(SQL_ATTR_QUERY_TIMEOUT); +} +//------------------------------------------------------------------------------ +sal_Int32 OStatement_Base::getMaxRows() const throw(SQLException, RuntimeException) +{ + return getStmtOption(SQL_ATTR_MAX_ROWS); +} +//------------------------------------------------------------------------------ +sal_Int32 OStatement_Base::getResultSetConcurrency() const throw(SQLException, RuntimeException) +{ + sal_uInt32 nValue; + SQLRETURN nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CONCURRENCY,&nValue,SQL_IS_UINTEGER,0); + return nValue; +} +//------------------------------------------------------------------------------ +sal_Int32 OStatement_Base::getResultSetType() const throw(SQLException, RuntimeException) +{ + sal_uInt32 nValue=0; + SQLRETURN nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_SENSITIVITY,&nValue,SQL_IS_UINTEGER,0); + nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,&nValue,SQL_IS_UINTEGER,0); + return nValue; +} +//------------------------------------------------------------------------------ +sal_Int32 OStatement_Base::getFetchDirection() const throw(SQLException, RuntimeException) +{ + sal_uInt32 nValue; + SQLRETURN nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,&nValue,SQL_IS_UINTEGER,0); + return nValue; +} +//------------------------------------------------------------------------------ +sal_Int32 OStatement_Base::getFetchSize() const throw(SQLException, RuntimeException) +{ + sal_uInt32 nValue; + SQLRETURN nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE,&nValue,SQL_IS_UINTEGER,0); + return nValue; +} +//------------------------------------------------------------------------------ +sal_Int32 OStatement_Base::getMaxFieldSize() const throw(SQLException, RuntimeException) +{ + return getStmtOption(SQL_ATTR_MAX_LENGTH); +} +//------------------------------------------------------------------------------ +::rtl::OUString OStatement_Base::getCursorName() const throw(SQLException, RuntimeException) +{ + SQLCHAR pName[258]; + SQLSMALLINT nRealLen = 0; + SQLRETURN nRetCode = N3SQLGetCursorName(m_aStatementHandle,(SQLCHAR*)pName,256,&nRealLen); + return ::rtl::OUString::createFromAscii((const char*)pName); +} +//------------------------------------------------------------------------------ +void OStatement_Base::setQueryTimeOut(sal_Int32 seconds) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_QUERY_TIMEOUT,(SQLPOINTER)seconds,SQL_IS_UINTEGER); +#ifdef DEBUG + DEBUG_THROW +#endif +} +//------------------------------------------------------------------------------ +void OStatement_Base::setMaxRows(sal_Int32 _par0) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_MAX_ROWS, (SQLPOINTER)_par0,SQL_IS_UINTEGER); +#ifdef DEBUG + DEBUG_THROW +#endif + +} +//------------------------------------------------------------------------------ +void OStatement_Base::setResultSetConcurrency(sal_Int32 _par0) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + SQLINTEGER nSet; + if(_par0 == ResultSetConcurrency::READ_ONLY) + nSet = SQL_CONCUR_READ_ONLY; + else + nSet = SQL_CONCUR_VALUES; + + THROW_SQL(N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CONCURRENCY,(SQLPOINTER)nSet,SQL_IS_UINTEGER)); + +} +//------------------------------------------------------------------------------ +void OStatement_Base::setResultSetType(sal_Int32 _par0) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_ROW_BIND_TYPE,(SQLPOINTER)SQL_BIND_BY_COLUMN,SQL_IS_UINTEGER); + + SQLUINTEGER nSet; + switch(_par0) + { + case ResultSetType::FORWARD_ONLY: + nSet = SQL_UNSPECIFIED; + break; + case ResultSetType::SCROLL_INSENSITIVE: + nSet = SQL_INSENSITIVE; + THROW_SQL(N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CURSOR_TYPE,(SQLPOINTER)SQL_CURSOR_KEYSET_DRIVEN,SQL_IS_UINTEGER)); + break; + case ResultSetType::SCROLL_SENSITIVE: + nSet = SQL_CURSOR_DYNAMIC; + if(N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CURSOR_TYPE,(SQLPOINTER)nSet,SQL_IS_UINTEGER) != SQL_SUCCESS) + { + nSet = SQL_CURSOR_KEYSET_DRIVEN; + THROW_SQL(N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CURSOR_TYPE,(SQLPOINTER)nSet,SQL_IS_UINTEGER)); + } + nSet = SQL_SENSITIVE; + break; + } + + + if(nRetCode = N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CURSOR_SENSITIVITY,(SQLPOINTER)nSet,SQL_IS_UINTEGER) != SQL_SUCCESS) + { + } +} +//------------------------------------------------------------------------------ +void OStatement_Base::setFetchDirection(sal_Int32 _par0) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,(SQLPOINTER)_par0,SQL_IS_UINTEGER); +} +//------------------------------------------------------------------------------ +void OStatement_Base::setFetchSize(sal_Int32 _par0) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE,(SQLPOINTER)_par0,SQL_IS_UINTEGER); + +#ifdef DEBUG + DEBUG_THROW +#endif + + delete m_pRowStatusArray; + m_pRowStatusArray = new SQLUSMALLINT[_par0]; + nRetCode = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_STATUS_PTR,m_pRowStatusArray,SQL_IS_POINTER); +#ifdef DEBUG + DEBUG_THROW +#endif + +} +//------------------------------------------------------------------------------ +void OStatement_Base::setMaxFieldSize(sal_Int32 _par0) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + THROW_SQL(N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_MAX_LENGTH,(SQLPOINTER)_par0,SQL_IS_UINTEGER)); +} +//------------------------------------------------------------------------------ +void OStatement_Base::setCursorName(const ::rtl::OUString &_par0) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + ::rtl::OString aName(::rtl::OUStringToOString(_par0, + osl_getThreadTextEncoding() + )); + THROW_SQL(N3SQLSetCursorName(m_aStatementHandle,(SDB_ODBC_CHAR*)aName.getStr(),aName.getLength())); +} +// ------------------------------------------------------------------------- +sal_Bool OStatement_Base::isUsingBookmarks() const throw(SQLException, RuntimeException) +{ + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_uInt32 nValue = SQL_UB_OFF; + SQLRETURN nRet = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_USE_BOOKMARKS,&nValue,SQL_IS_UINTEGER,NULL); + // THROW_SQL(nRet); + return nValue != SQL_UB_OFF; +} +// ------------------------------------------------------------------------- +void OStatement_Base::setUsingBookmarks(sal_Bool _bUseBookmark) throw(SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (OStatement_BASE::rBHelper.bDisposed) + throw DisposedException(); + + sal_uInt32 nValue = _bUseBookmark ? SQL_UB_VARIABLE : SQL_UB_OFF; + SQLRETURN nRet = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_USE_BOOKMARKS,(SQLPOINTER)nValue,SQL_IS_UINTEGER); + THROW_SQL(nRet); +} +// ------------------------------------------------------------------------- +::cppu::IPropertyArrayHelper* OStatement_Base::createArrayHelper( ) const +{ + Sequence< Property > aProps(10); + Property* pProperties = aProps.getArray(); + sal_Int32 nPos = 0; + DECL_PROP0(CURSORNAME, ::rtl::OUString); + DECL_BOOL_PROP0(ESCAPEPROCESSING); + DECL_PROP0(FETCHDIRECTION,sal_Int32); + DECL_PROP0(FETCHSIZE, sal_Int32); + DECL_PROP0(MAXFIELDSIZE,sal_Int32); + DECL_PROP0(MAXROWS, sal_Int32); + DECL_PROP0(QUERYTIMEOUT,sal_Int32); + DECL_PROP0(RESULTSETCONCURRENCY,sal_Int32); + DECL_PROP0(RESULTSETTYPE,sal_Int32); + DECL_BOOL_PROP0(USEBOOKMARKS); + + return new ::cppu::OPropertyArrayHelper(aProps); +} + +// ------------------------------------------------------------------------- +::cppu::IPropertyArrayHelper & OStatement_Base::getInfoHelper() +{ + return *const_cast<OStatement_Base*>(this)->getArrayHelper(); +} +// ------------------------------------------------------------------------- +sal_Bool OStatement_Base::convertFastPropertyValue( + Any & rConvertedValue, + Any & rOldValue, + sal_Int32 nHandle, + const Any& rValue ) + throw (::com::sun::star::lang::IllegalArgumentException) +{ + switch(nHandle) + { + case PROPERTY_ID_QUERYTIMEOUT: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getQueryTimeOut()); + case PROPERTY_ID_MAXFIELDSIZE: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxFieldSize()); + case PROPERTY_ID_MAXROWS: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxRows()); + case PROPERTY_ID_CURSORNAME: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getCursorName()); + case PROPERTY_ID_RESULTSETCONCURRENCY: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetConcurrency()); + case PROPERTY_ID_RESULTSETTYPE: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetType()); + case PROPERTY_ID_FETCHDIRECTION: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection()); + case PROPERTY_ID_FETCHSIZE: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize()); + case PROPERTY_ID_ESCAPEPROCESSING: + // return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink); + break; + case PROPERTY_ID_USEBOOKMARKS: + return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, isUsingBookmarks()); + + default: + ; + } + return sal_False; +} +// ------------------------------------------------------------------------- +void OStatement_Base::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception) +{ + switch(nHandle) + { + case PROPERTY_ID_QUERYTIMEOUT: + setQueryTimeOut(connectivity::getINT32(rValue)); + break; + case PROPERTY_ID_MAXFIELDSIZE: + setMaxFieldSize(connectivity::getINT32(rValue)); + break; + case PROPERTY_ID_MAXROWS: + setMaxRows(connectivity::getINT32(rValue)); + break; + case PROPERTY_ID_CURSORNAME: + setCursorName(connectivity::getString(rValue)); + break; + case PROPERTY_ID_RESULTSETCONCURRENCY: + setResultSetConcurrency(connectivity::getINT32(rValue)); + break; + case PROPERTY_ID_RESULTSETTYPE: + setResultSetType(connectivity::getINT32(rValue)); + break; + case PROPERTY_ID_FETCHDIRECTION: + setFetchDirection(connectivity::getINT32(rValue)); + break; + case PROPERTY_ID_FETCHSIZE: + setFetchSize(connectivity::getINT32(rValue)); + break; + case PROPERTY_ID_ESCAPEPROCESSING: + // return ::utl::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink); + break; + case PROPERTY_ID_USEBOOKMARKS: + setUsingBookmarks(connectivity::getBOOL(rValue)); + break; + default: + ; + } +} +// ------------------------------------------------------------------------- +void OStatement_Base::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const +{ + switch(nHandle) + { + case PROPERTY_ID_QUERYTIMEOUT: + rValue <<= getQueryTimeOut(); + break; + case PROPERTY_ID_MAXFIELDSIZE: + rValue <<= getMaxFieldSize(); + break; + case PROPERTY_ID_MAXROWS: + rValue <<= getMaxRows(); + break; + case PROPERTY_ID_CURSORNAME: + rValue <<= getCursorName(); + break; + case PROPERTY_ID_RESULTSETCONCURRENCY: + rValue <<= getResultSetConcurrency(); + break; + case PROPERTY_ID_RESULTSETTYPE: + rValue <<= getResultSetType(); + break; + case PROPERTY_ID_FETCHDIRECTION: + rValue <<= getFetchDirection(); + break; + case PROPERTY_ID_FETCHSIZE: + rValue <<= getFetchSize(); + break; + case PROPERTY_ID_ESCAPEPROCESSING: + break; + case PROPERTY_ID_USEBOOKMARKS: + rValue <<= cppu::bool2any(isUsingBookmarks()); + break; + default: + ; + } +} +// ------------------------------------------------------------------------- +IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbcx.OStatement","com.sun.star.sdbc.Statement"); + diff --git a/connectivity/source/drivers/odbc/OTools.cxx b/connectivity/source/drivers/odbc/OTools.cxx new file mode 100644 index 000000000000..23d3589ac0f3 --- /dev/null +++ b/connectivity/source/drivers/odbc/OTools.cxx @@ -0,0 +1,545 @@ +/************************************************************************* + * + * $RCSfile: OTools.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_OTOOLS_HXX_ +#include "odbc/OTools.hxx" +#endif + +#define __STL_IMPORT_VENDOR_CSTD +#include <cstring> +#ifndef _CONNECTIVITY_ODBC_OFUNCTIONS_HXX_ +#include "odbc/OFunctions.hxx" +#endif +#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +using namespace connectivity::odbc; +using namespace com::sun::star::uno; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::util; +#ifndef min +#define min(x,y) (x) < ( y) ? (x) : (y) +#endif +// ------------------------------------------------------------------------- +void OTools::ThrowException(SQLRETURN _rRetCode,SQLHANDLE _pContext,SQLSMALLINT _nHandleType,const Reference< XInterface >& _xInterface,sal_Bool _bNoFound) throw(SQLException, RuntimeException) +{ + switch(_rRetCode) + { + case SQL_NEED_DATA: + case SQL_STILL_EXECUTING: + case SQL_SUCCESS: + + case SQL_SUCCESS_WITH_INFO: + return; + case SQL_NO_DATA_FOUND: + if(_bNoFound) + return; // no need to throw a exception + case SQL_ERROR: break; + + + case SQL_INVALID_HANDLE: OSL_ENSHURE(0,"SdbODBC3_SetStatus: SQL_INVALID_HANDLE"); + throw RuntimeException(); + break; + } + + + // Zusaetliche Informationen zum letzten ODBC-Funktionsaufruf vorhanden. + // SQLError liefert diese Informationen. + + SDB_ODBC_CHAR szSqlState[5]; + SDWORD pfNativeError; + SDB_ODBC_CHAR szErrorMessage[SQL_MAX_MESSAGE_LENGTH]; + SWORD pcbErrorMsg; + + // Informationen zur letzten Operation: + // wenn hstmt != SQL_NULL_HSTMT ist (Benutzung von SetStatus in SdbCursor, SdbTable, ...), + // dann wird der Status des letzten Statements erfragt, sonst der Status des letzten + // Statements zu dieser Verbindung [was in unserem Fall wahrscheinlich gleichbedeutend ist, + // aber das Reference Manual drueckt sich da nicht so klar aus ...]. + // Entsprechend bei hdbc. + SQLRETURN n = N3SQLGetDiagRec(_nHandleType,_pContext,1, + szSqlState, + &pfNativeError, + szErrorMessage,sizeof szErrorMessage - 1,&pcbErrorMsg); + OSL_ENSHURE(n != SQL_INVALID_HANDLE,"SdbODBC3_SetStatus: SQLError returned SQL_INVALID_HANDLE"); + OSL_ENSHURE(n == SQL_SUCCESS || n == SQL_SUCCESS_WITH_INFO || n == SQL_NO_DATA_FOUND || n == SQL_ERROR,"SdbODBC3_SetStatus: SQLError failed"); + + // Zum Return Code von SQLError siehe ODBC 2.0 Programmer's Reference Seite 287ff + throw SQLException( ::rtl::OUString((char *)szErrorMessage,pcbErrorMsg,RTL_TEXTENCODING_MS_1252), + _xInterface, + ::rtl::OUString((char *)szSqlState,5,RTL_TEXTENCODING_MS_1252), + pfNativeError, + Any() + ); + +} +// ------------------------------------------------------------------------- +Sequence<sal_Int8> OTools::getBytesValue(SQLHANDLE _aStatementHandle,sal_Int32 columnIndex,SWORD _fSqlType,sal_Bool &_bWasNull, + const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException) +{ + char aCharArray[2048]; + // Erstmal versuchen, die Daten mit dem kleinen Puffer + // abzuholen: + SQLINTEGER nMaxLen = sizeof aCharArray - 1; + // GETDATA(SQL_C_CHAR,aCharArray,nMaxLen); + SQLINTEGER pcbValue = 0; + OTools::ThrowException(N3SQLGetData(_aStatementHandle, + (SQLUSMALLINT)columnIndex, + SQL_C_BINARY, + &aCharArray, + (SQLINTEGER)nMaxLen, + &pcbValue), + _aStatementHandle,SQL_HANDLE_STMT,_xInterface); + + _bWasNull = pcbValue == SQL_NULL_DATA; + if(_bWasNull) + return Sequence<sal_Int8>(); + + SQLINTEGER nBytes = pcbValue != SQL_NO_TOTAL ? min(pcbValue, nMaxLen) : nMaxLen; + Sequence<sal_Int8> aData((sal_Int8*)aCharArray, nBytes); + + + // Es handelt sich um Binaerdaten, um einen String, der fuer + // StarView zu lang ist oder der Treiber kann die Laenge der + // Daten nicht im voraus bestimmen - also als MemoryStream + // speichern. + while ((pcbValue == SQL_NO_TOTAL) || pcbValue > nMaxLen) + { + // Bei Strings wird der Puffer nie ganz ausgenutzt + // (das letzte Byte ist immer ein NULL-Byte, das + // aber bei pcbValue nicht mitgezaehlt wird) + if (pcbValue != SQL_NO_TOTAL && (pcbValue - nMaxLen) < nMaxLen) + nBytes = pcbValue - nMaxLen; + else + nBytes = nMaxLen; + + // Solange eine "truncation"-Warnung vorliegt, weiter Daten abholen + // GETDATA(SQL_C_CHAR,aCharArray, nLen + 1); + OTools::ThrowException(N3SQLGetData(_aStatementHandle, + (SQLUSMALLINT)columnIndex, + SQL_C_BINARY, + &aCharArray, + (SQLINTEGER)nBytes, + &pcbValue), + _aStatementHandle,SQL_HANDLE_STMT,_xInterface); + sal_Int32 nLen = aData.getLength(); + aData.realloc(nLen + nBytes); + ::std::memcpy(aData.getArray() + nLen, aCharArray, nBytes); + } + return aData; +} +// ------------------------------------------------------------------------- +::rtl::OUString OTools::getStringValue(SQLHANDLE _aStatementHandle,sal_Int32 columnIndex,SWORD _fSqlType,sal_Bool &_bWasNull, + const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException) +{ + ::rtl::OUString aData; + switch(_fSqlType) + { + case SQL_WVARCHAR: + case SQL_WCHAR: + case SQL_WLONGVARCHAR: + { + sal_Unicode waCharArray[2048]; + // read the unicode data + sal_Int32 nMaxLen = sizeof(waCharArray) - sizeof(sal_Unicode); + // GETDATA(SQL_C_WCHAR, waCharArray, nMaxLen + sizeof(sal_Unicode)); + + SQLINTEGER pcbValue=0; + OTools::ThrowException(N3SQLGetData(_aStatementHandle, + (SQLUSMALLINT)columnIndex, + SQL_C_WCHAR, + &waCharArray, + (SQLINTEGER)nMaxLen*sizeof(sal_Unicode), + &pcbValue), + _aStatementHandle,SQL_HANDLE_STMT,_xInterface); + _bWasNull = pcbValue == SQL_NULL_DATA; + if(_bWasNull) + return ::rtl::OUString(); + // Bei Fehler bricht der GETDATA-Makro mit return ab, + // bei NULL mit break! + SQLINTEGER nLen = pcbValue != SQL_NO_TOTAL ? min(pcbValue, nMaxLen) : nMaxLen; + waCharArray[nLen] = 0; + aData = ::rtl::OUString(waCharArray); + + // Es handelt sich um Binaerdaten, um einen String, der fuer + // StarView zu lang ist oder der Treiber kann die Laenge der + // Daten nicht im voraus bestimmen - also als MemoryStream + // speichern. + while ((pcbValue == SQL_NO_TOTAL ) || pcbValue > nMaxLen) + { + // Bei Strings wird der Puffer nie ganz ausgenutzt + // (das letzte Byte ist immer ein NULL-Byte, das + // aber bei pcbValue nicht mitgezaehlt wird) + if (pcbValue != SQL_NO_TOTAL && (pcbValue - nMaxLen) < nMaxLen) + nLen = pcbValue - nMaxLen; + else + nLen = nMaxLen; + + // Solange eine "truncation"-Warnung vorliegt, weiter Daten abholen + // GETDATA(SQL_C_CHAR,waCharArray, nLen + 1); + OTools::ThrowException(N3SQLGetData(_aStatementHandle, + (SQLUSMALLINT)columnIndex, + SQL_C_WCHAR, + &waCharArray, + (SQLINTEGER)nLen+1, + &pcbValue), + _aStatementHandle,SQL_HANDLE_STMT,_xInterface); + waCharArray[nLen] = 0; + + aData += ::rtl::OUString(waCharArray); + } + } + break; + default: + { + char aCharArray[2048]; + // Erstmal versuchen, die Daten mit dem kleinen Puffer + // abzuholen: + SDWORD nMaxLen = sizeof aCharArray - 1; + // GETDATA(SQL_C_CHAR,aCharArray,nMaxLen); + SQLINTEGER pcbValue = 0; + OTools::ThrowException(N3SQLGetData(_aStatementHandle, + (SQLUSMALLINT)columnIndex, + SQL_C_CHAR, + &aCharArray, + (SQLINTEGER)nMaxLen, + &pcbValue), + _aStatementHandle,SQL_HANDLE_STMT,_xInterface); + _bWasNull = pcbValue == SQL_NULL_DATA; + if(_bWasNull) + return ::rtl::OUString(); + + SQLINTEGER nLen = pcbValue != SQL_NO_TOTAL ? min(pcbValue, nMaxLen) : nMaxLen; + aCharArray[nLen] = 0; + aData = ::rtl::OUString((const sal_Char*)aCharArray,nLen, osl_getThreadTextEncoding()); + + // Es handelt sich um Binaerdaten, um einen String, der fuer + // StarView zu lang ist oder der Treiber kann die Laenge der + // Daten nicht im voraus bestimmen - also als MemoryStream + // speichern. + while ((pcbValue == SQL_NO_TOTAL) || pcbValue > nMaxLen) + { + // Bei Strings wird der Puffer nie ganz ausgenutzt + // (das letzte Byte ist immer ein NULL-Byte, das + // aber bei pcbValue nicht mitgezaehlt wird) + if (pcbValue != SQL_NO_TOTAL && (pcbValue - nMaxLen) < nMaxLen) + nLen = pcbValue - nMaxLen; + else + nLen = nMaxLen; + + // Solange eine "truncation"-Warnung vorliegt, weiter Daten abholen + // GETDATA(SQL_C_CHAR,aCharArray, nLen + 1); + OTools::ThrowException(N3SQLGetData(_aStatementHandle, + (SQLUSMALLINT)columnIndex, + SQL_C_CHAR, + &aCharArray, + (SQLINTEGER)nLen +1, + &pcbValue), + _aStatementHandle,SQL_HANDLE_STMT,_xInterface); + aCharArray[nLen] = 0; + + aData += ::rtl::OUString((const sal_Char*)aCharArray,nLen,osl_getThreadTextEncoding()); + } + + // delete all blanks + // aData.EraseTrailingChars(); + } + } + + return aData; +} +// ------------------------------------------------------------------------- +void OTools::GetInfo(SQLHANDLE _aConnectionHandle,SQLUSMALLINT _nInfo,::rtl::OUString &_rValue,const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException) +{ + char aValue[512]; + SQLSMALLINT nValueLen; + OTools::ThrowException( + N3SQLGetInfo(_aConnectionHandle,_nInfo,aValue,sizeof aValue,&nValueLen), + _aConnectionHandle,SQL_HANDLE_DBC,_xInterface); + + _rValue = ::rtl::OUString(aValue,nValueLen,RTL_TEXTENCODING_MS_1252); +} +// ------------------------------------------------------------------------- +void OTools::GetInfo(SQLHANDLE _aConnectionHandle,SQLUSMALLINT _nInfo,sal_Int32 &_rValue,const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException) +{ + SQLSMALLINT nValueLen; + _rValue = 0; // in case the driver uses only 16 of the 32 bits (as it does, for example, for SQL_CATALOG_LOCATION) + OTools::ThrowException( + N3SQLGetInfo(_aConnectionHandle,_nInfo,&_rValue,sizeof _rValue,&nValueLen), + _aConnectionHandle,SQL_HANDLE_DBC,_xInterface); +} +// ------------------------------------------------------------------------- +void OTools::GetInfo(SQLHANDLE _aConnectionHandle,SQLUSMALLINT _nInfo,sal_Bool &_rValue,const Reference< XInterface >& _xInterface) throw(SQLException, RuntimeException) +{ + SQLSMALLINT nValueLen; + OTools::ThrowException( + N3SQLGetInfo(_aConnectionHandle,_nInfo,&_rValue,sizeof _rValue,&nValueLen), + _aConnectionHandle,SQL_HANDLE_DBC,_xInterface); +} +// ------------------------------------------------------------------------- +sal_Int32 OTools::MapOdbcType2Jdbc(sal_Int32 _nType) +{ + sal_Int32 nValue; + switch(_nType) + { + case SQL_BIT: + nValue = DataType::BIT; + break; + case SQL_TINYINT: + nValue = DataType::TINYINT; + break; + case SQL_SMALLINT: + nValue = DataType::SMALLINT; + break; + case SQL_INTEGER: + nValue = DataType::INTEGER; + break; + case SQL_BIGINT: + nValue = DataType::BIGINT; + break; + case SQL_FLOAT: + nValue = DataType::FLOAT; + break; + case SQL_REAL: + nValue = DataType::REAL; + break; + case SQL_DOUBLE: + nValue = DataType::DOUBLE; + break; + case SQL_NUMERIC: + nValue = DataType::NUMERIC; + break; + case SQL_DECIMAL: + nValue = DataType::DECIMAL; + break; + case SQL_WCHAR: + case SQL_CHAR: + nValue = DataType::CHAR; + break; + case SQL_WVARCHAR: + case SQL_VARCHAR: + nValue = DataType::VARCHAR; + break; + case SQL_WLONGVARCHAR: + case SQL_LONGVARCHAR: + nValue = DataType::LONGVARCHAR; + break; + case SQL_TYPE_DATE: + case SQL_DATE: + nValue = DataType::DATE; + break; + case SQL_TYPE_TIME: + case SQL_TIME: + nValue = DataType::TIME; + break; + case SQL_TYPE_TIMESTAMP: + case SQL_TIMESTAMP: + nValue = DataType::TIMESTAMP; + break; + case SQL_BINARY: + nValue = DataType::BINARY; + break; + case SQL_VARBINARY: + nValue = DataType::VARBINARY; + break; + case SQL_LONGVARBINARY: + nValue = DataType::LONGVARBINARY; + break; + } + return nValue; +} +//-------------------------------------------------------------------- +// jdbcTypeToOdbc +// Convert the JDBC SQL type to the correct ODBC type +//-------------------------------------------------------------------- +sal_Int32 OTools::jdbcTypeToOdbc(sal_Int32 jdbcType) +{ + // For the most part, JDBC types match ODBC types. We'll + // just convert the ones that we know are different + + sal_Int32 odbcType = jdbcType; + + switch (jdbcType) + { + case DataType::DATE: + odbcType = SQL_DATE; + break; + case DataType::TIME: + odbcType = SQL_TIME; + break; + case DataType::TIMESTAMP: + odbcType = SQL_TIMESTAMP; + break; + } + + return odbcType; +} +//----------------------------------------------------------------------------- +void OTools::getBindTypes(sal_Bool _bUseWChar,sal_Bool _bUseOldTimeDate, + sal_Int32 jdbcType,SQLSMALLINT& fCType,SQLSMALLINT& fSqlType, + SQLUINTEGER& nColumnSize,SQLSMALLINT& nDecimalDigits) +{ + switch(jdbcTypeToOdbc(jdbcType)) + { + case SQL_CHAR: if(_bUseWChar) + { + fCType = SQL_C_WCHAR; + fSqlType = SQL_WCHAR; + } + else + { + fCType = SQL_C_CHAR; + fSqlType = SQL_CHAR; + } + break; + case SQL_VARCHAR: if(_bUseWChar) + { + fCType = SQL_C_WCHAR; + fSqlType = SQL_WVARCHAR; + } + else + { + fCType = SQL_C_CHAR; + fSqlType = SQL_VARCHAR; + } + break; + case SQL_LONGVARCHAR: if(_bUseWChar) + { + fCType = SQL_C_WCHAR; + fSqlType = SQL_WLONGVARCHAR; + } + else + { + fCType = SQL_C_CHAR; + fSqlType = SQL_LONGVARCHAR; + } + break; + case SQL_DECIMAL: fCType = _bUseWChar ? SQL_C_WCHAR : SQL_C_CHAR; + fSqlType = SQL_DECIMAL; break; + case SQL_NUMERIC: fCType = _bUseWChar ? SQL_C_WCHAR : SQL_C_CHAR; + fSqlType = SQL_NUMERIC; break; + case SQL_BIT: fCType = SQL_C_TINYINT; + fSqlType = SQL_INTEGER; break; + case SQL_TINYINT: fCType = SQL_C_SHORT; + fSqlType = SQL_TINYINT; break; + case SQL_SMALLINT: fCType = SQL_C_SHORT; + fSqlType = SQL_SMALLINT; break; + case SQL_INTEGER: fCType = SQL_C_LONG; + fSqlType = SQL_INTEGER; break; + case SQL_BIGINT: fCType = _bUseWChar ? SQL_C_WCHAR : SQL_C_CHAR; + fSqlType = SQL_BIGINT; break; + case SQL_REAL: fCType = SQL_C_FLOAT; + fSqlType = SQL_REAL; break; + case SQL_DOUBLE: fCType = SQL_C_DOUBLE; + fSqlType = SQL_DOUBLE; break; + case SQL_BINARY: fCType = SQL_C_BINARY; + fSqlType = SQL_BINARY; break; + case SQL_VARBINARY: + fCType = SQL_C_BINARY; + fSqlType = SQL_VARBINARY; break; + case SQL_LONGVARBINARY: fCType = SQL_C_BINARY; + fSqlType = SQL_LONGVARBINARY; break; + case SQL_DATE: + if(_bUseOldTimeDate) + { + fCType = SQL_C_DATE; + fSqlType = SQL_DATE; + } + else + { + fCType = SQL_C_TYPE_DATE; + fSqlType = SQL_TYPE_DATE; + } + break; + case SQL_TIME: + if(_bUseOldTimeDate) + { + fCType = SQL_C_TIME; + fSqlType = SQL_TIME; + } + else + { + fCType = SQL_C_TYPE_TIME; + fSqlType = SQL_TYPE_TIME; + } + break; + case SQL_TIMESTAMP: + if(_bUseOldTimeDate) + { + fCType = SQL_C_TIMESTAMP; + fSqlType = SQL_TIMESTAMP; + } + else + { + fCType = SQL_C_TYPE_TIMESTAMP; + fSqlType = SQL_TYPE_TIMESTAMP; + } + break; + default: fCType = SQL_C_BINARY; + fSqlType = SQL_LONGVARBINARY; break; + } +} + + diff --git a/connectivity/source/drivers/odbc/makefile.mk b/connectivity/source/drivers/odbc/makefile.mk new file mode 100644 index 000000000000..dd1cef6b9938 --- /dev/null +++ b/connectivity/source/drivers/odbc/makefile.mk @@ -0,0 +1,177 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 16:14:23 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library 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 for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/..$/.. +PRJINC=..$/.. +PRJNAME=connectivity +TARGET=odbc + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ---------------------------------- +.IF "$(DBGUTIL_OJ)"!="" +ENVCFLAGS+=/FR$(SLO)$/ +.ENDIF + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/version.mk + +# --- Types ------------------------------------- + + +UNOUCRDEP=$(SOLARBINDIR)$/applicat.rdb +UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb + +UNOUCROUT=$(OUT)$/inc +INCPRE+=$(UNOUCROUT) + +# --- Types ------------------------------------- + +UNOTYPES+= \ + com.sun.star.util.XCancellable \ + com.sun.star.util.XNumberFormatter \ + com.sun.star.uno.TypeClass \ + com.sun.star.uno.XWeak \ + com.sun.star.uno.XAggregation \ + com.sun.star.beans.XPropertyState \ + com.sun.star.beans.XPropertySet \ + com.sun.star.beans.PropertyValue \ + com.sun.star.beans.XMultiPropertySet \ + com.sun.star.beans.XFastPropertySet \ + com.sun.star.lang.XTypeProvider \ + com.sun.star.lang.EventObject \ + com.sun.star.lang.XComponent \ + com.sun.star.lang.IllegalArgumentException \ + com.sun.star.lang.DisposedException \ + com.sun.star.lang.XMultiServiceFactory \ + com.sun.star.lang.XSingleServiceFactory \ + com.sun.star.registry.XRegistryKey \ + com.sun.star.java.XJavaThreadRegister_11 \ + com.sun.star.java.XJavaVM \ + com.sun.star.sdbc.XConnection \ + com.sun.star.sdbc.XStatement \ + com.sun.star.sdbc.XResultSet \ + com.sun.star.sdbc.XResultSetMetaDataSupplier \ + com.sun.star.sdbc.XColumnLocate \ + com.sun.star.sdbc.XResultSetUpdate \ + com.sun.star.sdbc.XWarningsSupplier \ + com.sun.star.sdbc.XRowUpdate \ + com.sun.star.sdbc.XMultipleResults \ + com.sun.star.sdbc.XBatchExecution \ + com.sun.star.sdbc.XPreparedBatchExecution \ + com.sun.star.sdbc.XParameters \ + com.sun.star.sdbc.XOutParameters \ + com.sun.star.sdbc.DriverPropertyInfo \ + com.sun.star.sdbc.XDriver \ + com.sun.star.sdbc.XRow \ + com.sun.star.sdbc.SQLWarning \ + com.sun.star.sdbc.ColumnSearch \ + com.sun.star.sdbc.DataType \ + com.sun.star.sdbc.ResultSetConcurrency \ + com.sun.star.sdbc.ResultSetType \ + com.sun.star.sdbc.ColumnValue \ + com.sun.star.sdb.XColumnUpdate \ + com.sun.star.sdb.XColumn \ + com.sun.star.lang.XServiceInfo \ + + +# --- Files ------------------------------------- + +SLOFILES=\ + $(SLO)$/OPreparedStatement.obj \ + $(SLO)$/OStatement.obj \ + $(SLO)$/OResultSetMetaData.obj \ + $(SLO)$/OResultSet.obj \ + $(SLO)$/OTools.obj \ + $(SLO)$/ODatabaseMetaData.obj \ + $(SLO)$/ODriver.obj \ + $(SLO)$/OFunctions.obj \ + $(SLO)$/oservices.obj \ + $(SLO)$/OConnection.obj + +# --- Library ----------------------------------- + +SHL1TARGET= $(ODBC_TARGET)$(ODBC_MAJOR) +SHL1OBJS=$(SLOFILES) +SHL1STDLIBS=\ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(VOSLIB) \ + $(OSLLIB) \ + $(SALLIB) + +SHL1DEPN= +SHL1IMPLIB= i$(ODBC_TARGET) +SHL1LIBS= $(SLB)$/commontools.lib \ + $(SLB)$/resource.lib + +SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME= $(SHL1TARGET) +DEF1EXPORTFILE= exports.dxp + + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + + diff --git a/connectivity/source/drivers/odbc/odbc.map b/connectivity/source/drivers/odbc/odbc.map new file mode 100644 index 000000000000..becb2594a6a3 --- /dev/null +++ b/connectivity/source/drivers/odbc/odbc.map @@ -0,0 +1,8 @@ +ODBC_2_0 { + global: + component_getImplementationEnvironment + component_writeInfo + component_getFactory + local: + *; +}; diff --git a/connectivity/source/drivers/odbc/odbc.xml b/connectivity/source/drivers/odbc/odbc.xml new file mode 100644 index 000000000000..253bccb84c4c --- /dev/null +++ b/connectivity/source/drivers/odbc/odbc.xml @@ -0,0 +1,70 @@ +<?xml version='1.0' encoding="UTF-8"?> +<!DOCTYPE COMPONENTDESCRIPTION PUBLIC "-//W3C//DTD HTML 3.2//EN" "componentdependencies.dtd"> +<COMPONENTDESCRIPTION> + +<Name> com.sun.star.sdbc.ODBCDriver </Name> + +<Description> + This is the implementation of the sdbc-odbc bridge. +</Description> + +<ModuleName> odbc </ModuleName> + +<LoaderName> com.sun.star.loader.SharedLibrary </LoaderName> + +<SupportedService> com.sun.star.sdbc.Driver </SupportedService> + +<ServiceDependency> ... </ServiceDependency> + +<ProjectBuildDependency> cppuhelper </ProjectBuildDependency> +<ProjectBuildDependency> cppu </ProjectBuildDependency> +<ProjectBuildDependency> sal </ProjectBuildDependency> +<ProjectBuildDependency> vos </ProjectBuildDependency> + +<RuntimeModuleDependency> cppuhelper </RuntimeModuleDependency> +<RuntimeModuleDependency> cppu1 </RuntimeModuleDependency> +<RuntimeModuleDependency> sal1 </RuntimeModuleDependency> +<RuntimeModuleDependency> vos </RuntimeModuleDependency> + +<Language> c++ </Language> + +<Status StatusValue="final"/> + +<Type> com.sun.star.util.XCancellable </Type> +<Type> com.sun.star.util.XNumberFormatter </Type> +<Type> com.sun.star.uno.TypeClass </Type> +<Type> com.sun.star.uno.XWeak </Type> +<Type> com.sun.star.uno.XAggregation </Type> +<Type> com.sun.star.beans.XPropertyState </Type> +<Type> com.sun.star.beans.XPropertySet </Type> +<Type> com.sun.star.beans.PropertyValue </Type> +<Type> com.sun.star.beans.XMultiPropertySet </Type> +<Type> com.sun.star.beans.XFastPropertySet </Type> +<Type> com.sun.star.lang.XTypeProvider </Type> +<Type> com.sun.star.lang.EventObject </Type> +<Type> com.sun.star.lang.XComponent </Type> +<Type> com.sun.star.lang.IllegalArgumentException </Type> +<Type> com.sun.star.lang.XMultiServiceFactory </Type> +<Type> com.sun.star.java.XJavaThreadRegister_11 </Type> +<Type> com.sun.star.java.XJavaVM </Type> +<Type> com.sun.star.sdbc.XConnection </Type> +<Type> com.sun.star.sdbc.XStatement </Type> +<Type> com.sun.star.sdbc.XResultSet </Type> +<Type> com.sun.star.sdbc.XResultSetMetaDataSupplier</Type> +<Type> com.sun.star.sdbc.XColumnLocate </Type> +<Type> com.sun.star.sdbc.XResultSetUpdate </Type> +<Type> com.sun.star.sdbc.XWarningsSupplier </Type> +<Type> com.sun.star.sdbc.XRowUpdate </Type> +<Type> com.sun.star.sdbc.XMultipleResults </Type> +<Type> com.sun.star.sdbc.XBatchExecution </Type> +<Type> com.sun.star.sdbc.XPreparedBatchExecution </Type> +<Type> com.sun.star.sdbc.XParameters </Type> +<Type> com.sun.star.sdbc.XOutParameters </Type> +<Type> com.sun.star.sdbc.DriverPropertyInfo </Type> +<Type> com.sun.star.sdbc.XRow </Type> +<Type> com.sun.star.sdb.XColumnUpdate </Type> +<Type> com.sun.star.sdb.XColumn </Type> + +</COMPONENTDESCRIPTION> + + diff --git a/connectivity/source/drivers/odbc/oservices.cxx b/connectivity/source/drivers/odbc/oservices.cxx new file mode 100644 index 000000000000..7e6bf4bc118a --- /dev/null +++ b/connectivity/source/drivers/odbc/oservices.cxx @@ -0,0 +1,212 @@ +/************************************************************************* + * + * $RCSfile: oservices.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:14:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONNECTIVITY_ODBC_ODRIVER_HXX_ +#include "odbc/ODriver.hxx" +#endif +#ifndef _CPPUHELPER_FACTORY_HXX_ +#include <cppuhelper/factory.hxx> +#endif +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +using namespace connectivity::odbc; +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 + ); + +//*************************************************************************************** +// +// 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_ENSHURE(xNewKey.is(), "ODBC::component_writeInfo : could not create a registry key !"); + + for (sal_uInt32 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); + } + catch(...) + { + } + return xRet.is(); + } + + void* getProvider() const { return xRet.get(); } +}; + +//--------------------------------------------------------------------------------------- + +extern "C" void SAL_CALL component_getImplementationEnvironment( + const sal_Char **ppEnvTypeName, + uno_Environment **ppEnv + ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +//--------------------------------------------------------------------------------------- +extern "C" 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( + ODBCDriver::getImplementationName_Static(), + ODBCDriver::getSupportedServiceNames_Static(), xKey); + + return sal_True; + } + catch (::com::sun::star::registry::InvalidRegistryException& ) + { + OSL_ENSHURE(sal_False, "ODBC::component_writeInfo : could not create a registry key ! ## InvalidRegistryException !"); + } + + return sal_False; +} + +//--------------------------------------------------------------------------------------- +extern "C" 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( + ODBCDriver::getImplementationName_Static(), + ODBCDriver::getSupportedServiceNames_Static(), + ODBCDriver_CreateInstance, ::cppu::createSingleFactory) + ; + + if(aReq.xRet.is()) + aReq.xRet->acquire(); + + pRet = aReq.getProvider(); + } + + return pRet; +}; + + |