diff options
Diffstat (limited to '')
179 files changed, 17464 insertions, 0 deletions
diff --git a/connectivity/source/inc/AutoRetrievingBase.hxx b/connectivity/source/inc/AutoRetrievingBase.hxx new file mode 100644 index 0000000000..a85b92c636 --- /dev/null +++ b/connectivity/source/inc/AutoRetrievingBase.hxx @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <rtl/ustring.hxx> +#include <connectivity/dbtoolsdllapi.hxx> + +namespace connectivity +{ + class OOO_DLLPUBLIC_DBTOOLS OAutoRetrievingBase + { + OUString m_sGeneratedValueStatement; // contains the statement which should be used when query for automatically generated values + bool m_bAutoRetrievingEnabled; // set to when we should allow to query for generated values + protected: + OAutoRetrievingBase() : m_bAutoRetrievingEnabled(false) {} + virtual ~OAutoRetrievingBase(){} + + void enableAutoRetrievingEnabled(bool _bAutoEnable) { m_bAutoRetrievingEnabled = _bAutoEnable; } + void setAutoRetrievingStatement(const OUString& _sStmt) { m_sGeneratedValueStatement = _sStmt; } + public: + bool isAutoRetrievingEnabled() const { return m_bAutoRetrievingEnabled; } + + /** transform the statement to query for auto generated values + @param _sInsertStatement + The "INSERT" statement, is used to query for column and table names + @return + The transformed generated statement. + */ + OUString getTransformedGeneratedStatement(const OUString& _sInsertStatement) const; + }; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/FDatabaseMetaDataResultSet.hxx b/connectivity/source/inc/FDatabaseMetaDataResultSet.hxx new file mode 100644 index 0000000000..c469f06716 --- /dev/null +++ b/connectivity/source/inc/FDatabaseMetaDataResultSet.hxx @@ -0,0 +1,270 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sal/config.h> + +#include <vector> + +#include <com/sun/star/sdbc/XResultSet.hpp> +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> +#include <com/sun/star/sdbc/XCloseable.hpp> +#include <com/sun/star/sdbc/XColumnLocate.hpp> +#include <com/sun/star/util/XCancellable.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/sdbc/XWarningsSupplier.hpp> +#include <cppuhelper/compbase.hxx> +#include <cppuhelper/basemutex.hxx> +#include <comphelper/proparrhlp.hxx> +#include <comphelper/propertycontainer.hxx> +#include <connectivity/FValue.hxx> +#include <connectivity/dbtoolsdllapi.hxx> + +namespace connectivity +{ + typedef ::cppu::WeakComponentImplHelper< css::sdbc::XResultSet, + css::sdbc::XRow, + css::sdbc::XResultSetMetaDataSupplier, + css::util::XCancellable, + css::sdbc::XWarningsSupplier, + css::sdbc::XCloseable, + css::lang::XInitialization, + css::lang::XServiceInfo, + css::sdbc::XColumnLocate> ODatabaseMetaDataResultSet_BASE; + + // typedef ORefVector<ORowSetValue> ORow; + // typedef ORefVector<ORow> ORows; + + class OOO_DLLPUBLIC_DBTOOLS ODatabaseMetaDataResultSet : + public cppu::BaseMutex, + public ODatabaseMetaDataResultSet_BASE, + public ::comphelper::OPropertyContainer, + public ::comphelper::OPropertyArrayUsageHelper<ODatabaseMetaDataResultSet> + { + + public: + typedef std::vector<ORowSetValueDecoratorRef> ORow; + typedef std::vector<ORow> ORows; + + enum MetaDataResultSetType + { + /// describes a result set as expected by XDatabaseMetaData::getCatalogs + eCatalogs = 0, + /// describes a result set as expected by XDatabaseMetaData::getSchemas + eSchemas = 1, + /// describes a result set as expected by XDatabaseMetaData::getColumnPrivileges + eColumnPrivileges = 2, + /// describes a result set as expected by XDatabaseMetaData::getColumns + eColumns = 3, + /// describes a result set as expected by XDatabaseMetaData::getTables + eTables = 4, + /// describes a result set as expected by XDatabaseMetaData::getTableTypes + eTableTypes = 5, + /// describes a result set as expected by XDatabaseMetaData::getProcedureColumns + eProcedureColumns = 6, + /// describes a result set as expected by XDatabaseMetaData::getProcedures + eProcedures = 7, + /// describes a result set as expected by XDatabaseMetaData::getExportedKeys + eExportedKeys = 8, + /// describes a result set as expected by XDatabaseMetaData::getImportedKeys + eImportedKeys = 9, + /// describes a result set as expected by XDatabaseMetaData::getPrimaryKeys + ePrimaryKeys = 10, + /// describes a result set as expected by XDatabaseMetaData::getIndexInfo + eIndexInfo = 11, + /// describes a result set as expected by XDatabaseMetaData::getTablePrivileges + eTablePrivileges = 12, + /// describes a result set as expected by XDatabaseMetaData::getCrossReference + eCrossReference = 13, + /// describes a result set as expected by XDatabaseMetaData::getTypeInfo + eTypeInfo = 14, + /// describes a result set as expected by XDatabaseMetaData::getBestRowIdentifier + eBestRowIdentifier = 15, + /// describes a result set as expected by XDatabaseMetaData::getVersionColumns + eVersionColumns = 16, + /// describes a result set as expected by XDatabaseMetaData::getUDTs + eUDTs = 17 + }; + + private: + ORowSetValue m_aEmptyValue; + css::uno::WeakReferenceHelper m_aStatement; + css::uno::Reference< css::sdbc::XResultSetMetaData> m_xMetaData; + sal_Int32 m_nColPos; + + sal_Int32 m_nFetchSize; + sal_Int32 m_nResultSetType; + sal_Int32 m_nFetchDirection; + sal_Int32 m_nResultSetConcurrency; + + void construct(); + /// @throws css::sdbc::SQLException + void checkIndex(sal_Int32 columnIndex ); + void setType(MetaDataResultSetType _eType); + + protected: + ORows m_aRows; + ORows::iterator m_aRowsIter; + bool m_bBOF; + bool m_bEOF; + + virtual const ORowSetValue& getValue(sal_Int32 columnIndex); + + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override; + // OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + + virtual ~ODatabaseMetaDataResultSet() override; + public: + + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + + /// default construction + ODatabaseMetaDataResultSet(); + /// construction of a pre-defined result set type + ODatabaseMetaDataResultSet( MetaDataResultSetType _eType ); + + void setRows(ORows&& _rRows); + + // XServiceInfo + + protected: + virtual OUString SAL_CALL getImplementationName( ) override; + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; + // ::cppu::OComponentHelper + virtual void SAL_CALL disposing() override; + // XInterface + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + // XPropertySet + virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; + // XResultSet + virtual sal_Bool SAL_CALL next( ) override; + virtual sal_Bool SAL_CALL isBeforeFirst( ) override; + virtual sal_Bool SAL_CALL isAfterLast( ) override; + virtual sal_Bool SAL_CALL isFirst( ) override; + virtual sal_Bool SAL_CALL isLast( ) override; + virtual void SAL_CALL beforeFirst( ) override; + virtual void SAL_CALL afterLast( ) override; + virtual sal_Bool SAL_CALL first( ) override; + virtual sal_Bool SAL_CALL last( ) override; + virtual sal_Int32 SAL_CALL getRow( ) override; + virtual sal_Bool SAL_CALL absolute( sal_Int32 row ) override; + virtual sal_Bool SAL_CALL relative( sal_Int32 rows ) override; + virtual sal_Bool SAL_CALL previous( ) override; + virtual void SAL_CALL refreshRow( ) override; + virtual sal_Bool SAL_CALL rowUpdated( ) override; + virtual sal_Bool SAL_CALL rowInserted( ) override; + virtual sal_Bool SAL_CALL rowDeleted( ) override; + virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getStatement( ) override; + // XRow + virtual sal_Bool SAL_CALL wasNull( ) override; + virtual OUString SAL_CALL getString( sal_Int32 columnIndex ) override; + virtual sal_Bool SAL_CALL getBoolean( sal_Int32 columnIndex ) override; + virtual sal_Int8 SAL_CALL getByte( sal_Int32 columnIndex ) override; + virtual sal_Int16 SAL_CALL getShort( sal_Int32 columnIndex ) override; + virtual sal_Int32 SAL_CALL getInt( sal_Int32 columnIndex ) override; + virtual sal_Int64 SAL_CALL getLong( sal_Int32 columnIndex ) override; + virtual float SAL_CALL getFloat( sal_Int32 columnIndex ) override; + virtual double SAL_CALL getDouble( sal_Int32 columnIndex ) override; + virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes( sal_Int32 columnIndex ) override; + virtual css::util::Date SAL_CALL getDate( sal_Int32 columnIndex ) override; + virtual css::util::Time SAL_CALL getTime( sal_Int32 columnIndex ) override; + virtual css::util::DateTime SAL_CALL getTimestamp( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream( sal_Int32 columnIndex ) override; + virtual css::uno::Any SAL_CALL getObject( sal_Int32 columnIndex, const css::uno::Reference< css::container::XNameAccess >& typeMap ) override; + virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray( sal_Int32 columnIndex ) override; + // XResultSetMetaDataSupplier + virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData( ) override; + // XCancellable + virtual void SAL_CALL cancel( ) override; + // XCloseable + virtual void SAL_CALL close( ) override; + // XWarningsSupplier + virtual css::uno::Any SAL_CALL getWarnings( ) override; + virtual void SAL_CALL clearWarnings( ) override; + // XColumnLocate + virtual sal_Int32 SAL_CALL findColumn( const OUString& columnName ) override; + + // XInitialization + virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override; + + void setCatalogsMap(); + void setSchemasMap(); + void setColumnPrivilegesMap(); + void setColumnsMap(); + void setTablesMap(); + void setTableTypes(); + void setProcedureColumnsMap(); + void setProceduresMap(); + void setExportedKeysMap(); + void setImportedKeysMap(); + void setPrimaryKeysMap(); + void setIndexInfoMap(); + void setTablePrivilegesMap(); + void setCrossReferenceMap(); + void setTypeInfoMap(); + void setBestRowIdentifierMap(); + void setVersionColumnsMap(); + void setUDTsMap(); + public: + // some methods to get already defined ORowSetValues + // this increase the reuse of ORowSetValues + /// return an empty ORowSetValueDecorator + static ORowSetValueDecoratorRef const & getEmptyValue(); + /// return an ORowSetValueDecorator with 0 as value + static ORowSetValueDecoratorRef const & get0Value(); + /// return an ORowSetValueDecorator with 1 as value + static ORowSetValueDecoratorRef const & get1Value(); + /// return an ORowSetValueDecorator with ColumnSearch::BASIC as value + static ORowSetValueDecoratorRef const & getBasicValue(); + /// return an ORowSetValueDecorator with string SELECT as value + static ORowSetValueDecoratorRef const & getSelectValue(); + /// return an ORowSetValueDecorator with string INSERT as value + static ORowSetValueDecoratorRef const & getInsertValue(); + /// return an ORowSetValueDecorator with string DELETE as value + static ORowSetValueDecoratorRef const & getDeleteValue(); + /// return an ORowSetValueDecorator with string UPDATE as value + static ORowSetValueDecoratorRef const & getUpdateValue(); + /// return an ORowSetValueDecorator with string CREATE as value + static ORowSetValueDecoratorRef const & getCreateValue(); + /// return an ORowSetValueDecorator with string READ as value + static ORowSetValueDecoratorRef const & getReadValue(); + /// return an ORowSetValueDecorator with string ALTER as value + static ORowSetValueDecoratorRef const & getAlterValue(); + /// return an ORowSetValueDecorator with string DROP as value + static ORowSetValueDecoratorRef const & getDropValue(); + /// return an ORowSetValueDecorator with string ' as value + static ORowSetValueDecoratorRef const & getQuoteValue(); + + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/FDatabaseMetaDataResultSetMetaData.hxx b/connectivity/source/inc/FDatabaseMetaDataResultSetMetaData.hxx new file mode 100644 index 0000000000..9de1226722 --- /dev/null +++ b/connectivity/source/inc/FDatabaseMetaDataResultSetMetaData.hxx @@ -0,0 +1,96 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/sdbc/XResultSetMetaData.hpp> +#include <cppuhelper/implbase.hxx> +#include <map> +#include <vector> +#include "OColumn.hxx" + +namespace connectivity +{ + + //************ Class: ODatabaseMetaDataResultSetMetaData + + typedef ::cppu::WeakImplHelper< css::sdbc::XResultSetMetaData> ODatabaseMetaResultSetMetaData_BASE; + + class ODatabaseMetaDataResultSetMetaData : public ODatabaseMetaResultSetMetaData_BASE + { + std::map<sal_Int32,connectivity::OColumn> m_mColumns; + std::map<sal_Int32,connectivity::OColumn>::const_iterator m_mColumnsIter; + + protected: + virtual ~ODatabaseMetaDataResultSetMetaData() override; + public: + // a Constructor, that is needed for when returning the object is needed: + ODatabaseMetaDataResultSetMetaData( ) + { + } + + virtual sal_Int32 SAL_CALL getColumnCount( ) override; + virtual sal_Bool SAL_CALL isAutoIncrement( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isCaseSensitive( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isSearchable( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isCurrency( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL isNullable( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isSigned( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getColumnDisplaySize( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnLabel( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnName( sal_Int32 column ) override; + virtual OUString SAL_CALL getSchemaName( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getPrecision( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getScale( sal_Int32 column ) override; + virtual OUString SAL_CALL getTableName( sal_Int32 column ) override; + virtual OUString SAL_CALL getCatalogName( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getColumnType( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnTypeName( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isReadOnly( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isWritable( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isDefinitelyWritable( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnServiceName( sal_Int32 column ) override; + + // methods to set the right column mapping + void setColumnPrivilegesMap(); + void setColumnMap(); + void setColumnsMap(); + void setTableNameMap(); + void setTablesMap(); + void setProcedureColumnsMap(); + void setPrimaryKeysMap(); + void setIndexInfoMap(); + void setTablePrivilegesMap(); + void setCrossReferenceMap(); + void setTypeInfoMap(); + void setProcedureNameMap(); + void setProceduresMap(); + void setTableTypes(); + void setBestRowIdentifierMap() { setVersionColumnsMap();} + void setVersionColumnsMap(); + void setExportedKeysMap() { setCrossReferenceMap(); } + void setImportedKeysMap() { setCrossReferenceMap(); } + void setCatalogsMap(); + void setSchemasMap(); + void setUDTsMap(); + }; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/OColumn.hxx b/connectivity/source/inc/OColumn.hxx new file mode 100644 index 0000000000..2131b3e152 --- /dev/null +++ b/connectivity/source/inc/OColumn.hxx @@ -0,0 +1,119 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <connectivity/dbtoolsdllapi.hxx> +#include <utility> + +namespace connectivity +{ + class OOO_DLLPUBLIC_DBTOOLS OColumn + { + OUString m_TableName; + OUString m_ColumnName; + OUString m_ColumnLabel; + + sal_Int32 m_Nullable; + sal_Int32 m_ColumnDisplaySize; + sal_Int32 m_Precision; + sal_Int32 m_Scale; + sal_Int32 m_ColumnType; + + bool m_AutoIncrement; + bool m_CaseSensitive; + bool m_Searchable; + bool m_Currency; + bool m_Signed; + bool m_ReadOnly; + bool m_Writable; + bool m_DefinitelyWritable; + + public: + OColumn() + : m_Nullable(0) + , m_ColumnDisplaySize(0) + , m_Precision(0) + , m_Scale(0) + , m_ColumnType(0) + + , m_AutoIncrement(false) + , m_CaseSensitive(false) + , m_Searchable(true) + , m_Currency(false) + , m_Signed(false) + , m_ReadOnly(true) + , m_Writable(false) + , m_DefinitelyWritable(false) + {} + + OColumn(OUString _aTableName, + const OUString &_aColumnName, + sal_Int32 _aNullable, + sal_Int32 _aColumnDisplaySize, + sal_Int32 _aPrecision, + sal_Int32 _aScale, + sal_Int32 _aColumnType) + : m_TableName(std::move(_aTableName)), + m_ColumnName(_aColumnName), + m_ColumnLabel(), + + m_Nullable(_aNullable), + m_ColumnDisplaySize(_aColumnDisplaySize), + m_Precision(_aPrecision), + m_Scale(_aScale), + m_ColumnType(_aColumnType), + + m_AutoIncrement(false), + m_CaseSensitive(false), + m_Searchable(true), + m_Currency(false), + m_Signed(false), + m_ReadOnly(true), + m_Writable(false), + m_DefinitelyWritable(false) + { + if(m_ColumnLabel.isEmpty()) + m_ColumnLabel = _aColumnName; + } + + bool isAutoIncrement() const { return m_AutoIncrement; } + bool isCaseSensitive() const { return m_CaseSensitive; } + bool isSearchable() const { return m_Searchable; } + bool isCurrency() const { return m_Currency; } + bool isSigned() const { return m_Signed; } + bool isReadOnly() const { return m_ReadOnly; } + bool isWritable() const { return m_Writable; } + bool isDefinitelyWritable() const { return m_DefinitelyWritable; } + + sal_Int32 isNullable() const { return m_Nullable; } + sal_Int32 getColumnDisplaySize() const { return m_ColumnDisplaySize; } + sal_Int32 getPrecision() const { return m_Precision; } + sal_Int32 getScale() const { return m_Scale; } + sal_Int32 getColumnType() const { return m_ColumnType; } + + const OUString& getColumnLabel() const { return m_ColumnLabel; } + const OUString& getColumnName() const { return m_ColumnName; } + const OUString& getTableName() const { return m_TableName; } + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/OTypeInfo.hxx b/connectivity/source/inc/OTypeInfo.hxx new file mode 100644 index 0000000000..4e9cbdf05e --- /dev/null +++ b/connectivity/source/inc/OTypeInfo.hxx @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/sdbc/DataType.hpp> + +#include <rtl/ustring.hxx> + +namespace connectivity +{ + struct OTypeInfo + { + OUString aTypeName; // Name of the type in the database + OUString aLocalTypeName; + + sal_Int32 nPrecision; // Length of the type + + sal_Int16 nMaximumScale; // Decimal places + + sal_Int16 nType; // Database type + + OTypeInfo() + :nPrecision(0) + ,nMaximumScale(0) + ,nType( css::sdbc::DataType::OTHER) + {} + + bool operator == (const OTypeInfo& lh) const { return lh.nType == nType; } + bool operator != (const OTypeInfo& lh) const { return lh.nType != nType; } + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ParameterSubstitution.hxx b/connectivity/source/inc/ParameterSubstitution.hxx new file mode 100644 index 0000000000..a76bd09398 --- /dev/null +++ b/connectivity/source/inc/ParameterSubstitution.hxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/util/XStringSubstitution.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/sdbc/XConnection.hpp> +#include <cppuhelper/implbase.hxx> +#include <cppuhelper/weakref.hxx> + +namespace connectivity +{ + typedef ::cppu::WeakImplHelper< css::util::XStringSubstitution + ,css::lang::XServiceInfo + ,css::lang::XInitialization > ParameterSubstitution_BASE; + class ParameterSubstitution final : public ParameterSubstitution_BASE + { + ::osl::Mutex m_aMutex; + css::uno::Reference< css::uno::XComponentContext > m_xContext; + css::uno::WeakReference< css::sdbc::XConnection > m_xConnection; + + ParameterSubstitution( const ParameterSubstitution& ) = delete; + ParameterSubstitution& operator=( const ParameterSubstitution& ) = delete; + public: + ParameterSubstitution(css::uno::Reference< css::uno::XComponentContext > _rContext ); + private: + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName( ) override; + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; + // XInitialization + virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override; + + // XStringSubstitution + virtual OUString SAL_CALL substituteVariables( const OUString& aText, sal_Bool bSubstRequired ) override; + virtual OUString SAL_CALL reSubstituteVariables( const OUString& aText ) override; + virtual OUString SAL_CALL getSubstituteVariableValue( const OUString& variable ) override; + }; + +} // connectivity + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/RowFunctionParser.hxx b/connectivity/source/inc/RowFunctionParser.hxx new file mode 100644 index 0000000000..059544e51f --- /dev/null +++ b/connectivity/source/inc/RowFunctionParser.hxx @@ -0,0 +1,109 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sal/config.h> +#include "FDatabaseMetaDataResultSet.hxx" +#include <connectivity/dbtoolsdllapi.hxx> +#include <memory> + +namespace connectivity +{ +enum class ExpressionFunct +{ + Equation, + And, + Or +}; + +#define EXPRESSION_FLAG_SUMANGLE_MODE 1 + +class OOO_DLLPUBLIC_DBTOOLS SAL_NO_VTABLE ExpressionNode +{ +public: + virtual ~ExpressionNode() {} + + /** Operator to calculate function value. + + This method calculates the function value. + */ + virtual ORowSetValueDecoratorRef + evaluate(const ODatabaseMetaDataResultSet::ORow& _aRow) const = 0; + + virtual void fill(const ODatabaseMetaDataResultSet::ORow& _aRow) const = 0; +}; + +/** This exception is thrown, when the arithmetic expression + parser failed to parse a string. + */ +struct OOO_DLLPUBLIC_DBTOOLS ParseError +{ + ParseError(const char*) {} +}; + +class FunctionParser +{ +public: + /** Parse a string + + The following grammar is accepted by this method: + <code> + + number_digit = '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9' + + number = number number_digit | number_digit + + equal_function = '=' + ternary_function = 'if' + + string_reference = 'a-z,A-Z,0-9' ' ' + modifier_reference = '$' '0-9' ' ' + + basic_expression = + number | + string_reference | + additive_expression equal_function additive_expression | + unary_function '(' number_digit ')' + ternary_function '(' additive_expression ',' additive_expression ', + ' additive_expression ')' | '(' additive_expression ')' + + </code> + + @param rFunction + The string to parse + + @throws ParseError if an invalid expression is given. + + @return the generated function object. + */ + + static std::shared_ptr<ExpressionNode> const& parseFunction(const OUString& _sFunction); + +private: + // disabled constructor/destructor, since this is + // supposed to be a singleton + FunctionParser() = delete; + FunctionParser(const FunctionParser&) = delete; + FunctionParser& operator=(const FunctionParser&) = delete; +}; + +} // namespace connectivity + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/TConnection.hxx b/connectivity/source/inc/TConnection.hxx new file mode 100644 index 0000000000..2dbe2ef6a7 --- /dev/null +++ b/connectivity/source/inc/TConnection.hxx @@ -0,0 +1,81 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <rtl/textenc.h> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include <com/sun/star/sdbc/XWarningsSupplier.hpp> +#include <com/sun/star/sdbc/XConnection.hpp> +#include <cppuhelper/compbase.hxx> +#include "propertyids.hxx" +#include <connectivity/CommonTools.hxx> +#include <connectivity/dbtoolsdllapi.hxx> +#include "resource/sharedresources.hxx" + +namespace connectivity +{ + typedef ::cppu::WeakComponentImplHelper< css::sdbc::XConnection, + css::sdbc::XWarningsSupplier, + css::lang::XServiceInfo, + css::lang::XUnoTunnel + > OMetaConnection_BASE; + + class OOO_DLLPUBLIC_DBTOOLS OMetaConnection : public OMetaConnection_BASE + { + protected: + ::osl::Mutex m_aMutex; + css::uno::Sequence< css::beans::PropertyValue > + m_aConnectionInfo; + connectivity::OWeakRefArray m_aStatements; // vector containing a list + // of all the Statement objects + // for this Connection + OUString m_sURL; + rtl_TextEncoding m_nTextEncoding; // the encoding which is used for all text conversions + css::uno::WeakReference< css::sdbc::XDatabaseMetaData > + m_xMetaData; + SharedResources m_aResources; + public: + + static ::dbtools::OPropertyMap& getPropMap(); + + OMetaConnection(); + + rtl_TextEncoding getTextEncoding() const { return m_nTextEncoding; } + const OUString& getURL() const { return m_sURL; } + void setURL(const OUString& _rsUrl) { m_sURL = _rsUrl; } + void throwGenericSQLException(TranslateId pErrorResourceId, const css::uno::Reference< css::uno::XInterface>& _xContext); + const SharedResources& getResources() const { return m_aResources;} + + void setConnectionInfo(const css::uno::Sequence< css::beans::PropertyValue >& _aInfo) { m_aConnectionInfo = _aInfo; } + const css::uno::Sequence< css::beans::PropertyValue >& + getConnectionInfo() const { return m_aConnectionInfo; } + + // OComponentHelper + virtual void SAL_CALL disposing() override; + + //XUnoTunnel + virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; + static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId(); + }; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/TDatabaseMetaDataBase.hxx b/connectivity/source/inc/TDatabaseMetaDataBase.hxx new file mode 100644 index 0000000000..4d8c7715ca --- /dev/null +++ b/connectivity/source/inc/TDatabaseMetaDataBase.hxx @@ -0,0 +1,133 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/sdbc/XDatabaseMetaData2.hpp> +#include <cppuhelper/implbase.hxx> +#include <cppuhelper/basemutex.hxx> +#include <com/sun/star/lang/XEventListener.hpp> +#include "FDatabaseMetaDataResultSet.hxx" +#include <functional> +#include <connectivity/dbtoolsdllapi.hxx> + +namespace connectivity +{ + class OOO_DLLPUBLIC_DBTOOLS ODatabaseMetaDataBase : + public cppu::BaseMutex, + public ::cppu::WeakImplHelper< css::sdbc::XDatabaseMetaData2, + css::lang::XEventListener> + { + private: + css::uno::Sequence< css::beans::PropertyValue > m_aConnectionInfo; + ::connectivity::ODatabaseMetaDataResultSet::ORows m_aTypeInfoRows; + + // cached database information + std::pair<bool,bool> m_isCatalogAtStart; + std::pair<bool,OUString> m_sCatalogSeparator; + std::pair<bool,OUString> m_sIdentifierQuoteString; + std::pair<bool,bool> m_supportsCatalogsInTableDefinitions; + std::pair<bool,bool> m_supportsSchemasInTableDefinitions; + std::pair<bool,bool> m_supportsCatalogsInDataManipulation; + std::pair<bool,bool> m_supportsSchemasInDataManipulation; + std::pair<bool,bool> m_supportsMixedCaseQuotedIdentifiers; + std::pair<bool,bool> m_supportsAlterTableWithAddColumn; + std::pair<bool,bool> m_supportsAlterTableWithDropColumn; + std::pair<bool,sal_Int32> m_MaxStatements; + std::pair<bool,sal_Int32> m_MaxTablesInSelect; + std::pair<bool,bool> m_storesMixedCaseQuotedIdentifiers; + + template <typename T> T callImplMethod(std::pair<bool,T>& _rCache,const std::function<T(ODatabaseMetaDataBase *)>& _pImplMethod) + { + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !_rCache.first ) + { + _rCache.second = _pImplMethod(this); + _rCache.first = true; + } + return _rCache.second; + } + protected: + css::uno::Reference< css::sdbc::XConnection > m_xConnection; + css::uno::Reference< css::lang::XEventListener> m_xListenerHelper; // forward the calls from the connection to me + + virtual ~ODatabaseMetaDataBase() override; + + protected: + virtual css::uno::Reference< css::sdbc::XResultSet > impl_getTypeInfo_throw() = 0; + // cached database information + virtual OUString impl_getIdentifierQuoteString_throw( ) = 0; + virtual bool impl_isCatalogAtStart_throw( ) = 0; + virtual OUString impl_getCatalogSeparator_throw( ) = 0; + virtual bool impl_supportsCatalogsInTableDefinitions_throw( ) = 0; + virtual bool impl_supportsSchemasInTableDefinitions_throw( ) = 0; + virtual bool impl_supportsCatalogsInDataManipulation_throw( ) = 0; + virtual bool impl_supportsSchemasInDataManipulation_throw( ) = 0; + virtual bool impl_supportsMixedCaseQuotedIdentifiers_throw( ) = 0; + virtual bool impl_supportsAlterTableWithAddColumn_throw( ) = 0; + virtual bool impl_supportsAlterTableWithDropColumn_throw( ) = 0; + virtual sal_Int32 impl_getMaxStatements_throw( ) = 0; + virtual sal_Int32 impl_getMaxTablesInSelect_throw( ) = 0; + virtual bool impl_storesMixedCaseQuotedIdentifiers_throw( ) = 0; + + + public: + + ODatabaseMetaDataBase(const css::uno::Reference< css::sdbc::XConnection >& _rxConnection,const css::uno::Sequence< css::beans::PropertyValue >& _rInfo); + + // XDatabaseMetaData2 + virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getConnectionInfo( ) override; + + // XEventListener + virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override; + + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTypeInfo( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getProcedures( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& procedureNamePattern ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getProcedureColumns( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& procedureNamePattern, const OUString& columnNamePattern ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getSchemas( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getCatalogs( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getColumnPrivileges( const css::uno::Any& catalog, const OUString& schema, const OUString& table, const OUString& columnNamePattern ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTablePrivileges( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getBestRowIdentifier( const css::uno::Any& catalog, const OUString& schema, const OUString& table, sal_Int32 scope, sal_Bool nullable ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getVersionColumns( const css::uno::Any& catalog, const OUString& schema, const OUString& table ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getPrimaryKeys( const css::uno::Any& catalog, const OUString& schema, const OUString& table ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getImportedKeys( const css::uno::Any& catalog, const OUString& schema, const OUString& table ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getExportedKeys( const css::uno::Any& catalog, const OUString& schema, const OUString& table ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getCrossReference( const css::uno::Any& primaryCatalog, const OUString& primarySchema, const OUString& primaryTable, const css::uno::Any& foreignCatalog, const OUString& foreignSchema, const OUString& foreignTable ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getIndexInfo( const css::uno::Any& catalog, const OUString& schema, const OUString& table, sal_Bool unique, sal_Bool approximate ) override; + + virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( ) override; + // cached database information + virtual OUString SAL_CALL getIdentifierQuoteString( ) override; + virtual sal_Bool SAL_CALL isCatalogAtStart( ) override; + virtual OUString SAL_CALL getCatalogSeparator( ) override; + virtual sal_Bool SAL_CALL supportsCatalogsInTableDefinitions( ) override; + virtual sal_Bool SAL_CALL supportsSchemasInTableDefinitions( ) override; + virtual sal_Bool SAL_CALL supportsCatalogsInDataManipulation( ) override; + virtual sal_Bool SAL_CALL supportsSchemasInDataManipulation( ) override; + virtual sal_Bool SAL_CALL supportsMixedCaseQuotedIdentifiers( ) override; + virtual sal_Bool SAL_CALL supportsAlterTableWithAddColumn( ) override; + virtual sal_Bool SAL_CALL supportsAlterTableWithDropColumn( ) override; + virtual sal_Int32 SAL_CALL getMaxStatements( ) override; + virtual sal_Int32 SAL_CALL getMaxTablesInSelect( ) override; + virtual sal_Bool SAL_CALL storesMixedCaseQuotedIdentifiers( ) override; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/TKeyValue.hxx b/connectivity/source/inc/TKeyValue.hxx new file mode 100644 index 0000000000..49d41e0144 --- /dev/null +++ b/connectivity/source/inc/TKeyValue.hxx @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <connectivity/FValue.hxx> +#include <connectivity/dbtoolsdllapi.hxx> +#include <osl/diagnose.h> + +namespace connectivity +{ + class OOO_DLLPUBLIC_DBTOOLS OKeyValue final + { + std::vector<ORowSetValueDecoratorRef> m_aKeys; + sal_Int32 m_nValue; + + OKeyValue(sal_Int32 nVal); + public: + + ~OKeyValue(); + + static std::unique_ptr<OKeyValue> createKeyValue(sal_Int32 nVal); + + void pushKey(const ORowSetValueDecoratorRef& _aValueRef) + { + m_aKeys.push_back(_aValueRef); + } + + OUString getKeyString(std::vector<ORowSetValueDecoratorRef>::size_type i) const + { + OSL_ENSURE(m_aKeys.size() > i,"Wrong index for KEyValue"); + return m_aKeys[i]->getValue().getString(); + } + double getKeyDouble(std::vector<ORowSetValueDecoratorRef>::size_type i) const + { + OSL_ENSURE(m_aKeys.size() > i,"Wrong index for KEyValue"); + return m_aKeys[i]->getValue().getDouble(); + } + + sal_Int32 getValue() const { return m_nValue; } + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/TPrivilegesResultSet.hxx b/connectivity/source/inc/TPrivilegesResultSet.hxx new file mode 100644 index 0000000000..b7206b7de4 --- /dev/null +++ b/connectivity/source/inc/TPrivilegesResultSet.hxx @@ -0,0 +1,46 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include "FDatabaseMetaDataResultSet.hxx" +#include <com/sun/star/sdbc/XDatabaseMetaData.hpp> +#include <connectivity/dbtoolsdllapi.hxx> + +namespace connectivity +{ + class OOO_DLLPUBLIC_DBTOOLS OResultSetPrivileges : + public ODatabaseMetaDataResultSet + { + css::uno::Reference< css::sdbc::XResultSet> m_xTables; + css::uno::Reference< css::sdbc::XRow> m_xRow; + bool m_bResetValues; + protected: + virtual const ORowSetValue& getValue(sal_Int32 columnIndex) override; + public: + OResultSetPrivileges(const css::uno::Reference< css::sdbc::XDatabaseMetaData>& _rxMeta + ,const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern); + + // ::cppu::OComponentHelper + virtual void SAL_CALL disposing() override; + // XResultSet + virtual sal_Bool SAL_CALL next( ) override; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/TResultSetHelper.hxx b/connectivity/source/inc/TResultSetHelper.hxx new file mode 100644 index 0000000000..cedea10272 --- /dev/null +++ b/connectivity/source/inc/TResultSetHelper.hxx @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sal/types.h> +#include <connectivity/dbtoolsdllapi.hxx> + +namespace connectivity +{ + class OOO_DLLPUBLIC_DBTOOLS SAL_NO_VTABLE IResultSetHelper + { + public: + enum Movement + { + NEXT = 0, + PRIOR, + FIRST, + LAST, + // Named like this to avoid conflict with a #define in the Windows system ODBC headers. + RELATIVE1, + ABSOLUTE1, + BOOKMARK, + }; + public: + virtual bool move(Movement _eCursorPosition, sal_Int32 _nOffset, bool _bRetrieveData) = 0; + virtual sal_Int32 getDriverPos() const = 0; + virtual bool isRowDeleted() const = 0; + + protected: + ~IResultSetHelper() {} + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/TSkipDeletedSet.hxx b/connectivity/source/inc/TSkipDeletedSet.hxx new file mode 100644 index 0000000000..efe142af54 --- /dev/null +++ b/connectivity/source/inc/TSkipDeletedSet.hxx @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include "TResultSetHelper.hxx" +#include <vector> +#include <connectivity/dbtoolsdllapi.hxx> + +namespace connectivity +{ + /** + the class OSkipDeletedSet supports a general method to skip deleted rows + */ + class OOO_DLLPUBLIC_DBTOOLS OSkipDeletedSet + { + std::vector<sal_Int32> m_aBookmarksPositions;// vector of iterators to position map, the order is the logical position + IResultSetHelper* m_pHelper; // used for moving in the resultset + bool m_bDeletedVisible; + + bool moveAbsolute(sal_Int32 _nOffset,bool _bRetrieveData); + public: + OSkipDeletedSet(IResultSetHelper* _pHelper); + ~OSkipDeletedSet(); + + /** + skipDeleted moves the resultset to the position defined by the parameters + it guarantees that the row isn't deleted + @param + IResultSetHelper::Movement _eCursorPosition in which direction the resultset should be moved + sal_Int32 _nOffset the position relative to the movement + sal_Bool _bRetrieveData is true when the current row should be filled which data + @return + true when the movement was successful otherwise false + */ + bool skipDeleted(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset, bool _bRetrieveData); + /** + clear the map and the vector used in this class + */ + void clear(); + /** + getMappedPosition returns the mapped position of a logical position + @param + sal_Int32 _nBookmark the logical position + + @return the mapped position + */ + sal_Int32 getMappedPosition(sal_Int32 _nBookmark) const; + /** + insertNewPosition adds a new position to the map + @param + sal_Int32 _nPos the logical position + */ + void insertNewPosition(sal_Int32 _nPos); + /** + deletePosition deletes this position from the map and decrement all following positions + @param + sal_Int32 _nPos the logical position + */ + void deletePosition(sal_Int32 _nPos); + void SetDeletedVisible(bool _bDeletedVisible) { m_bDeletedVisible = _bDeletedVisible; } + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/TSortIndex.hxx b/connectivity/source/inc/TSortIndex.hxx new file mode 100644 index 0000000000..3ac339f7e9 --- /dev/null +++ b/connectivity/source/inc/TSortIndex.hxx @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <connectivity/dbtoolsdllapi.hxx> +#include "TKeyValue.hxx" + +namespace connectivity +{ + enum class OKeyType + { + NONE, // do not sort + Double, // numeric key + String // String Key + }; + + enum class TAscendingOrder + { + ASC = 1, // ascending + DESC = -1 // otherwise + }; + + class OKeySet; + class OKeyValue; // simple class which holds a sal_Int32 and a std::vector<ORowSetValueDecoratorRef> + + /** + The class OSortIndex can be used to implement a sorted index. + This can depend on the fields which should be sorted. + */ + class OOO_DLLPUBLIC_DBTOOLS OSortIndex + { + public: + typedef std::vector<std::pair<sal_Int32, std::unique_ptr<OKeyValue>>> TIntValuePairVector; + typedef std::vector<OKeyType> TKeyTypeVector; + + private: + TIntValuePairVector m_aKeyValues; + TKeyTypeVector m_aKeyType; + std::vector<TAscendingOrder> m_aAscending; + bool m_bFrozen; + + public: + + OSortIndex( std::vector<OKeyType>&& _aKeyType, + std::vector<TAscendingOrder>&& _aAscending); + OSortIndex(OSortIndex const &) = delete; // MSVC2015 workaround + OSortIndex& operator=(OSortIndex const &) = delete; // MSVC2015 workaround + + ~OSortIndex(); + + /** + AddKeyValue appends a new value. + @param + pKeyValue the keyvalue to be appended + ATTENTION: when the sortindex is already frozen the parameter will be deleted + */ + void AddKeyValue(std::unique_ptr<OKeyValue> pKeyValue); + + /** + Freeze freezes the sortindex so that new values could only be appended by their value + */ + void Freeze(); + + /** + CreateKeySet creates the keyset which values could be used to travel in your table/result + The returned keyset is frozen. + */ + ::rtl::Reference<OKeySet> CreateKeySet(); + + const std::vector<OKeyType>& getKeyType() const { return m_aKeyType; } + TAscendingOrder getAscending(std::vector<TAscendingOrder>::size_type _nPos) const { return m_aAscending[_nPos]; } + + }; + + // MSVC hack to avoid multiply defined std::vector-related symbols: + class OKeySet_Base: public ORefVector<sal_Int32> {}; + + /** + The class OKeySet is a refcountable vector which also has a state. + This state gives information about if the keyset is fixed. + */ + class OOO_DLLPUBLIC_DBTOOLS OKeySet : public OKeySet_Base + { + bool m_bFrozen; + public: + OKeySet() + : m_bFrozen(false){} + + bool isFrozen() const { return m_bFrozen; } + void setFrozen() { m_bFrozen = true; } + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/ACallableStatement.hxx b/connectivity/source/inc/ado/ACallableStatement.hxx new file mode 100644 index 0000000000..e58617b3b0 --- /dev/null +++ b/connectivity/source/inc/ado/ACallableStatement.hxx @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <ado/APreparedStatement.hxx> +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/sdbc/XOutParameters.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> + +namespace connectivity::ado +{ + + //************ Class: java.sql.CallableStatement + + + class OCallableStatement : public OPreparedStatement, + public css::sdbc::XRow, + public css::sdbc::XOutParameters + { + OLEVariant m_aValue; + public: + DECLARE_SERVICE_INFO(); + + // a Constructor, that is needed for when Returning the Object is needed: + OCallableStatement( OConnection* _pConnection, const OUString& sql ); + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + + // XRow + virtual sal_Bool SAL_CALL wasNull( ) override; + virtual OUString SAL_CALL getString( sal_Int32 columnIndex ) override; + virtual sal_Bool SAL_CALL getBoolean( sal_Int32 columnIndex ) override; + virtual sal_Int8 SAL_CALL getByte( sal_Int32 columnIndex ) override; + virtual sal_Int16 SAL_CALL getShort( sal_Int32 columnIndex ) override; + virtual sal_Int32 SAL_CALL getInt( sal_Int32 columnIndex ) override; + virtual sal_Int64 SAL_CALL getLong( sal_Int32 columnIndex ) override; + virtual float SAL_CALL getFloat( sal_Int32 columnIndex ) override; + virtual double SAL_CALL getDouble( sal_Int32 columnIndex ) override; + virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes( sal_Int32 columnIndex ) override; + virtual css::util::Date SAL_CALL getDate( sal_Int32 columnIndex ) override; + virtual css::util::Time SAL_CALL getTime( sal_Int32 columnIndex ) override; + virtual css::util::DateTime SAL_CALL getTimestamp( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream( sal_Int32 columnIndex ) override; + virtual css::uno::Any SAL_CALL getObject( sal_Int32 columnIndex, const css::uno::Reference< css::container::XNameAccess >& typeMap ) override; + virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray( sal_Int32 columnIndex ) override; + // XOutParameters + virtual void SAL_CALL registerOutParameter( sal_Int32 parameterIndex, sal_Int32 sqlType, const OUString& typeName ) override; + virtual void SAL_CALL registerNumericOutParameter( sal_Int32 parameterIndex, sal_Int32 sqlType, sal_Int32 scale ) override; + }; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/ACatalog.hxx b/connectivity/source/inc/ado/ACatalog.hxx new file mode 100644 index 0000000000..fd09e9ad3c --- /dev/null +++ b/connectivity/source/inc/ado/ACatalog.hxx @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <sdbcx/VCatalog.hxx> +#include <ado/Awrapadox.hxx> + +namespace connectivity::ado +{ + class OConnection; + + class OCatalog : public connectivity::sdbcx::OCatalog + { + WpADOCatalog m_aCatalog; + OConnection* m_pConnection; + + public: + virtual void refreshTables() override; + virtual void refreshViews() override; + virtual void refreshGroups() override; + virtual void refreshUsers() override; + + public: + OCatalog(_ADOCatalog* _pCatalog,OConnection* _pCon); + ~OCatalog() override; + + OConnection* getConnection() const { return m_pConnection; } + sdbcx::OCollection* getPrivateTables() const { return m_pTables.get(); } + WpADOCatalog getCatalog() const { return m_aCatalog; } + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AColumn.hxx b/connectivity/source/inc/ado/AColumn.hxx new file mode 100644 index 0000000000..f297964820 --- /dev/null +++ b/connectivity/source/inc/ado/AColumn.hxx @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <connectivity/sdbcx/VColumn.hxx> +#include <ado/Awrapadox.hxx> + +namespace connectivity::ado +{ + class OConnection; + typedef sdbcx::OColumn OColumn_ADO; + class OAdoColumn : public OColumn_ADO + { + WpADOColumn m_aColumn; + OConnection* m_pConnection; + OUString m_ReferencedColumn; + bool m_IsAscending; + + void fillPropertyValues(); + protected: + virtual void SAL_CALL setFastPropertyValue_NoBroadcast( + sal_Int32 nHandle, + const css::uno::Any& rValue + ) override; + public: + OAdoColumn(bool _bCase,OConnection* _pConnection,_ADOColumn* _pColumn); + OAdoColumn(bool _bCase,OConnection* _pConnection); + // ODescriptor + virtual void construct() override; + + WpADOColumn getColumnImpl() const; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AColumns.hxx b/connectivity/source/inc/ado/AColumns.hxx new file mode 100644 index 0000000000..25decfa687 --- /dev/null +++ b/connectivity/source/inc/ado/AColumns.hxx @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <connectivity/sdbcx/VCollection.hxx> +#include <com/sun/star/sdbc/XDatabaseMetaData.hpp> +#include <connectivity/sdbcx/IRefreshable.hxx> +#include <ado/Awrapadox.hxx> + +namespace connectivity::ado +{ + class OConnection; + class OColumns : public sdbcx::OCollection + { + protected: + WpADOColumns m_aCollection; + OConnection* m_pConnection; + + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void dropObject(sal_Int32 _nPos,const OUString& _sElementName) override; + public: + OColumns( ::cppu::OWeakObject& _rParent, + ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector, + const WpADOColumns& _rCollection, + bool _bCase, + OConnection* _pConnection) : sdbcx::OCollection(_rParent,_bCase,_rMutex,_rVector) + ,m_aCollection(_rCollection) + ,m_pConnection(_pConnection) + { + } + + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AConnection.hxx b/connectivity/source/inc/ado/AConnection.hxx new file mode 100644 index 0000000000..c2c8210036 --- /dev/null +++ b/connectivity/source/inc/ado/AConnection.hxx @@ -0,0 +1,134 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <com/sun/star/sdbc/SQLWarning.hpp> +#include <com/sun/star/sdbcx/XTablesSupplier.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <map> +#include <string_view> +#include <connectivity/CommonTools.hxx> +#include <OTypeInfo.hxx> +#include <TConnection.hxx> +#include <ado/Awrapado.hxx> + +namespace connectivity::ado +{ + struct OExtendedTypeInfo + { + ::connectivity::OTypeInfo aSimpleType; // the general type info + DataTypeEnum eType; + + OUString getDBName() const { return aSimpleType.aTypeName; } + }; + + class WpADOConnection; + class ODriver; + class OCatalog; + typedef std::multimap<DataTypeEnum, OExtendedTypeInfo*> OTypeInfoMap; + typedef connectivity::OMetaConnection OConnection_BASE; + + + class OConnection : public OConnection_BASE + { + protected: + + // Data attributes + + OTypeInfoMap m_aTypeInfo; // vector containing an entry + // for each row returned by + // DatabaseMetaData.getTypeInfo. + css::uno::WeakReference< css::sdbcx::XTablesSupplier> m_xCatalog; + ODriver* m_pDriver; + private: + WpADOConnection m_aAdoConnection; + OCatalog* m_pCatalog; + sal_Int32 m_nEngineType; + bool m_bClosed; + bool m_bAutocommit; + + protected: + /// @throws css::sdbc::SQLException + void buildTypeInfo(); + public: + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + OConnection(ODriver* _pDriver); + // OConnection(const SQLHANDLE _pConnectionHandle); + ~OConnection() override; + void construct(std::u16string_view url,const css::uno::Sequence< css::beans::PropertyValue >& info); + + //XUnoTunnel + virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; + static css::uno::Sequence< sal_Int8 > getUnoTunnelId(); + // XServiceInfo + DECLARE_SERVICE_INFO(); + // OComponentHelper + virtual void SAL_CALL disposing() override; + + // XConnection + virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement( ) override; + virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const OUString& sql ) override; + virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall( const OUString& sql ) override; + virtual OUString SAL_CALL nativeSQL( const OUString& sql ) override; + virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) override; + virtual sal_Bool SAL_CALL getAutoCommit( ) override; + virtual void SAL_CALL commit( ) override; + virtual void SAL_CALL rollback( ) override; + virtual sal_Bool SAL_CALL isClosed( ) override; + virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( ) override; + virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) override; + virtual sal_Bool SAL_CALL isReadOnly( ) override; + virtual void SAL_CALL setCatalog( const OUString& catalog ) override; + virtual OUString SAL_CALL getCatalog( ) override; + virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) override; + virtual sal_Int32 SAL_CALL getTransactionIsolation( ) override; + virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTypeMap( ) override; + virtual void SAL_CALL setTypeMap( const css::uno::Reference< css::container::XNameAccess >& typeMap ) override; + // XCloseable + virtual void SAL_CALL close( ) override; + // XWarningsSupplier + virtual css::uno::Any SAL_CALL getWarnings( ) override; + virtual void SAL_CALL clearWarnings( ) override; + + WpADOConnection& getConnection() { return m_aAdoConnection; } + void setCatalog(const css::uno::WeakReference< css::sdbcx::XTablesSupplier>& _xCat) { m_xCatalog = _xCat; } + void setCatalog(OCatalog* _pCatalog) { m_pCatalog = _pCatalog; } + + const OTypeInfoMap* getTypeInfo() const { return &m_aTypeInfo;} + OCatalog* getAdoCatalog() const + { + if ( m_xCatalog.get().is() ) + return m_pCatalog; + return nullptr; + } + + sal_Int32 getEngineType() const { return m_nEngineType; } + ODriver* getDriver() const { return m_pDriver; } + + static const OExtendedTypeInfo* getTypeInfoFromType(const OTypeInfoMap& _rTypeInfo, + DataTypeEnum _nType, + const OUString& _sTypeName, + sal_Int32 _nPrecision, + sal_Int32 _nScale, + bool& _brForceToType); + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/ADatabaseMetaData.hxx b/connectivity/source/inc/ado/ADatabaseMetaData.hxx new file mode 100644 index 0000000000..1661ca4418 --- /dev/null +++ b/connectivity/source/inc/ado/ADatabaseMetaData.hxx @@ -0,0 +1,221 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <TDatabaseMetaDataBase.hxx> +#include <map> + +namespace connectivity::ado +{ + class WpADOConnection; + class OConnection; + + //************ Class: ODatabaseMetaData + + + class ODatabaseMetaData : public ODatabaseMetaDataBase + { + struct LiteralInfo + { + OUString pwszLiteralValue; + sal_uInt32 cchMaxLen; + bool fSupported; + }; + + std::map<sal_uInt32,LiteralInfo> m_aLiteralInfo; + WpADOConnection& m_rADOConnection; + OConnection* m_pConnection; + + void fillLiterals(); + // get information out of rowset + sal_Int32 getMaxSize(sal_uInt32 _nId); + bool isCapable(sal_uInt32 _nId); + OUString getLiteral(sal_uInt32 _nProperty); + + // get info out of properties + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + OUString getStringProperty(const OUString& _aProperty); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getInt32Property(const OUString& _aProperty); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + bool getBoolProperty(const OUString& _aProperty); + + virtual css::uno::Reference< css::sdbc::XResultSet > impl_getTypeInfo_throw() override; + // cached database information + virtual OUString impl_getIdentifierQuoteString_throw( ) override; + virtual bool impl_isCatalogAtStart_throw( ) override; + virtual OUString impl_getCatalogSeparator_throw( ) override; + virtual bool impl_supportsCatalogsInTableDefinitions_throw( ) override; + virtual bool impl_supportsSchemasInTableDefinitions_throw( ) override; + virtual bool impl_supportsCatalogsInDataManipulation_throw( ) override; + virtual bool impl_supportsSchemasInDataManipulation_throw( ) override; + virtual bool impl_supportsMixedCaseQuotedIdentifiers_throw( ) override; + virtual bool impl_supportsAlterTableWithAddColumn_throw( ) override; + virtual bool impl_supportsAlterTableWithDropColumn_throw( ) override; + virtual sal_Int32 impl_getMaxStatements_throw( ) override; + virtual sal_Int32 impl_getMaxTablesInSelect_throw( ) override; + virtual bool impl_storesMixedCaseQuotedIdentifiers_throw( ) override; + public: + + ODatabaseMetaData(OConnection* _pCon); + + // XDatabaseMetaData + virtual sal_Bool SAL_CALL allProceduresAreCallable( ) override; + virtual sal_Bool SAL_CALL allTablesAreSelectable( ) override; + virtual OUString SAL_CALL getURL( ) override; + virtual OUString SAL_CALL getUserName( ) override; + virtual sal_Bool SAL_CALL isReadOnly( ) override; + virtual sal_Bool SAL_CALL nullsAreSortedHigh( ) override; + virtual sal_Bool SAL_CALL nullsAreSortedLow( ) override; + virtual sal_Bool SAL_CALL nullsAreSortedAtStart( ) override; + virtual sal_Bool SAL_CALL nullsAreSortedAtEnd( ) override; + virtual OUString SAL_CALL getDatabaseProductName( ) override; + virtual OUString SAL_CALL getDatabaseProductVersion( ) override; + virtual OUString SAL_CALL getDriverName( ) override; + virtual OUString SAL_CALL getDriverVersion( ) override; + virtual sal_Int32 SAL_CALL getDriverMajorVersion( ) override; + virtual sal_Int32 SAL_CALL getDriverMinorVersion( ) override; + virtual sal_Bool SAL_CALL usesLocalFiles( ) override; + virtual sal_Bool SAL_CALL usesLocalFilePerTable( ) override; + virtual sal_Bool SAL_CALL supportsMixedCaseIdentifiers( ) override; + virtual sal_Bool SAL_CALL storesUpperCaseIdentifiers( ) override; + virtual sal_Bool SAL_CALL storesLowerCaseIdentifiers( ) override; + virtual sal_Bool SAL_CALL storesMixedCaseIdentifiers( ) override; + + virtual sal_Bool SAL_CALL storesUpperCaseQuotedIdentifiers( ) override; + virtual sal_Bool SAL_CALL storesLowerCaseQuotedIdentifiers( ) override; + + virtual OUString SAL_CALL getSQLKeywords( ) override; + virtual OUString SAL_CALL getNumericFunctions( ) override; + virtual OUString SAL_CALL getStringFunctions( ) override; + virtual OUString SAL_CALL getSystemFunctions( ) override; + virtual OUString SAL_CALL getTimeDateFunctions( ) override; + virtual OUString SAL_CALL getSearchStringEscape( ) override; + virtual OUString SAL_CALL getExtraNameCharacters( ) override; + virtual sal_Bool SAL_CALL supportsColumnAliasing( ) override; + virtual sal_Bool SAL_CALL nullPlusNonNullIsNull( ) override; + virtual sal_Bool SAL_CALL supportsTypeConversion( ) override; + virtual sal_Bool SAL_CALL supportsConvert( sal_Int32 fromType, sal_Int32 toType ) override; + virtual sal_Bool SAL_CALL supportsTableCorrelationNames( ) override; + virtual sal_Bool SAL_CALL supportsDifferentTableCorrelationNames( ) override; + virtual sal_Bool SAL_CALL supportsExpressionsInOrderBy( ) override; + virtual sal_Bool SAL_CALL supportsOrderByUnrelated( ) override; + virtual sal_Bool SAL_CALL supportsGroupBy( ) override; + virtual sal_Bool SAL_CALL supportsGroupByUnrelated( ) override; + virtual sal_Bool SAL_CALL supportsGroupByBeyondSelect( ) override; + virtual sal_Bool SAL_CALL supportsLikeEscapeClause( ) override; + virtual sal_Bool SAL_CALL supportsMultipleResultSets( ) override; + virtual sal_Bool SAL_CALL supportsMultipleTransactions( ) override; + virtual sal_Bool SAL_CALL supportsNonNullableColumns( ) override; + virtual sal_Bool SAL_CALL supportsMinimumSQLGrammar( ) override; + virtual sal_Bool SAL_CALL supportsCoreSQLGrammar( ) override; + virtual sal_Bool SAL_CALL supportsExtendedSQLGrammar( ) override; + virtual sal_Bool SAL_CALL supportsANSI92EntryLevelSQL( ) override; + virtual sal_Bool SAL_CALL supportsANSI92IntermediateSQL( ) override; + virtual sal_Bool SAL_CALL supportsANSI92FullSQL( ) override; + virtual sal_Bool SAL_CALL supportsIntegrityEnhancementFacility( ) override; + virtual sal_Bool SAL_CALL supportsOuterJoins( ) override; + virtual sal_Bool SAL_CALL supportsFullOuterJoins( ) override; + virtual sal_Bool SAL_CALL supportsLimitedOuterJoins( ) override; + virtual OUString SAL_CALL getSchemaTerm( ) override; + virtual OUString SAL_CALL getProcedureTerm( ) override; + virtual OUString SAL_CALL getCatalogTerm( ) override; + virtual sal_Bool SAL_CALL supportsSchemasInProcedureCalls( ) override; + virtual sal_Bool SAL_CALL supportsSchemasInIndexDefinitions( ) override; + virtual sal_Bool SAL_CALL supportsSchemasInPrivilegeDefinitions( ) override; + virtual sal_Bool SAL_CALL supportsCatalogsInProcedureCalls( ) override; + virtual sal_Bool SAL_CALL supportsCatalogsInIndexDefinitions( ) override; + virtual sal_Bool SAL_CALL supportsCatalogsInPrivilegeDefinitions( ) override; + virtual sal_Bool SAL_CALL supportsPositionedDelete( ) override; + virtual sal_Bool SAL_CALL supportsPositionedUpdate( ) override; + virtual sal_Bool SAL_CALL supportsSelectForUpdate( ) override; + virtual sal_Bool SAL_CALL supportsStoredProcedures( ) override; + virtual sal_Bool SAL_CALL supportsSubqueriesInComparisons( ) override; + virtual sal_Bool SAL_CALL supportsSubqueriesInExists( ) override; + virtual sal_Bool SAL_CALL supportsSubqueriesInIns( ) override; + virtual sal_Bool SAL_CALL supportsSubqueriesInQuantifieds( ) override; + virtual sal_Bool SAL_CALL supportsCorrelatedSubqueries( ) override; + virtual sal_Bool SAL_CALL supportsUnion( ) override; + virtual sal_Bool SAL_CALL supportsUnionAll( ) override; + virtual sal_Bool SAL_CALL supportsOpenCursorsAcrossCommit( ) override; + virtual sal_Bool SAL_CALL supportsOpenCursorsAcrossRollback( ) override; + virtual sal_Bool SAL_CALL supportsOpenStatementsAcrossCommit( ) override; + virtual sal_Bool SAL_CALL supportsOpenStatementsAcrossRollback( ) override; + virtual sal_Int32 SAL_CALL getMaxBinaryLiteralLength( ) override; + virtual sal_Int32 SAL_CALL getMaxCharLiteralLength( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInGroupBy( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInIndex( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInOrderBy( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInSelect( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInTable( ) override; + virtual sal_Int32 SAL_CALL getMaxConnections( ) override; + virtual sal_Int32 SAL_CALL getMaxCursorNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxIndexLength( ) override; + virtual sal_Int32 SAL_CALL getMaxSchemaNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxProcedureNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxCatalogNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxRowSize( ) override; + virtual sal_Bool SAL_CALL doesMaxRowSizeIncludeBlobs( ) override; + virtual sal_Int32 SAL_CALL getMaxStatementLength( ) override; + virtual sal_Int32 SAL_CALL getMaxTableNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxUserNameLength( ) override; + virtual sal_Int32 SAL_CALL getDefaultTransactionIsolation( ) override; + virtual sal_Bool SAL_CALL supportsTransactions( ) override; + virtual sal_Bool SAL_CALL supportsTransactionIsolationLevel( sal_Int32 level ) override; + virtual sal_Bool SAL_CALL supportsDataDefinitionAndDataManipulationTransactions( ) override; + virtual sal_Bool SAL_CALL supportsDataManipulationTransactionsOnly( ) override; + virtual sal_Bool SAL_CALL dataDefinitionCausesTransactionCommit( ) override; + virtual sal_Bool SAL_CALL dataDefinitionIgnoredInTransactions( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getProcedures( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& procedureNamePattern ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getProcedureColumns( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& procedureNamePattern, const OUString& columnNamePattern ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTables( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern, const css::uno::Sequence< OUString >& types ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getSchemas( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getCatalogs( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTableTypes( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getColumns( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern, const OUString& columnNamePattern ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getColumnPrivileges( const css::uno::Any& catalog, const OUString& schema, const OUString& table, const OUString& columnNamePattern ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTablePrivileges( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getPrimaryKeys( const css::uno::Any& catalog, const OUString& schema, const OUString& table ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getImportedKeys( const css::uno::Any& catalog, const OUString& schema, const OUString& table ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getExportedKeys( const css::uno::Any& catalog, const OUString& schema, const OUString& table ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getCrossReference( const css::uno::Any& primaryCatalog, const OUString& primarySchema, const OUString& primaryTable, const css::uno::Any& foreignCatalog, const OUString& foreignSchema, const OUString& foreignTable ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getIndexInfo( const css::uno::Any& catalog, const OUString& schema, const OUString& table, sal_Bool unique, sal_Bool approximate ) override; + virtual sal_Bool SAL_CALL supportsResultSetType( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL supportsResultSetConcurrency( sal_Int32 setType, sal_Int32 concurrency ) override; + virtual sal_Bool SAL_CALL ownUpdatesAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL ownDeletesAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL ownInsertsAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL othersUpdatesAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL othersDeletesAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL othersInsertsAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL updatesAreDetected( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL deletesAreDetected( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL insertsAreDetected( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL supportsBatchUpdates( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getUDTs( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& typeNamePattern, const css::uno::Sequence< sal_Int32 >& types ) override; + }; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/ADatabaseMetaDataResultSet.hxx b/connectivity/source/inc/ado/ADatabaseMetaDataResultSet.hxx new file mode 100644 index 0000000000..dce6971658 --- /dev/null +++ b/connectivity/source/inc/ado/ADatabaseMetaDataResultSet.hxx @@ -0,0 +1,225 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/sdbc/XResultSet.hpp> +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> +#include <com/sun/star/sdbc/XCloseable.hpp> +#include <com/sun/star/sdbc/XColumnLocate.hpp> +#include <com/sun/star/util/XCancellable.hpp> +#include <com/sun/star/sdbc/XWarningsSupplier.hpp> +#include <com/sun/star/sdbc/XResultSetUpdate.hpp> +#include <com/sun/star/sdbc/XRowUpdate.hpp> +#include <cppuhelper/compbase.hxx> +#include <cppuhelper/basemutex.hxx> +#include <comphelper/proparrhlp.hxx> +#include <ado/AStatement.hxx> + +namespace connectivity::ado +{ + /* + ** java_sql_ResultSet + */ + typedef ::cppu::WeakComponentImplHelper< css::sdbc::XResultSet, + css::sdbc::XRow, + css::sdbc::XResultSetMetaDataSupplier, + css::util::XCancellable, + css::sdbc::XWarningsSupplier, + css::sdbc::XCloseable, + css::sdbc::XColumnLocate> ODatabaseMetaDataResultSet_BASE; + + class ODatabaseMetaDataResultSet : public cppu::BaseMutex, + public ODatabaseMetaDataResultSet_BASE, + public ::cppu::OPropertySetHelper, + public ::comphelper::OPropertyArrayUsageHelper<ODatabaseMetaDataResultSet> + { + std::vector<sal_Int32> m_aColMapping; // pos 0 is unused so we don't have to decrement 1 every time + + std::map<sal_Int32, ::std::map<sal_Int32,sal_Int32> > m_aValueRange; + std::map<sal_Int32, ::std::map<sal_Int32,sal_Int32> >::iterator m_aValueRangeIter; + + std::map<sal_Int32, std::map< OUString,sal_Int32> > m_aStrValueRange; + std::map<sal_Int32, std::map< OUString,sal_Int32> >::iterator m_aStrValueRangeIter; + + std::map<sal_Int32, std::map< sal_Int32,OUString> > m_aIntValueRange; + std::map<sal_Int32, std::map< sal_Int32,OUString> >::iterator m_aIntValueRangeIter; + + ADORecordset* m_pRecordSet; + css::uno::WeakReferenceHelper m_aStatement; + css::uno::Reference< css::sdbc::XResultSetMetaData> m_xMetaData; + OLEVariant m_aValue; + sal_Int32 m_nRowPos; + bool m_bWasNull; + bool m_bEOF; + bool m_bOnFirstAfterOpen; + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + static sal_Int32 getResultSetConcurrency(); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + static sal_Int32 getResultSetType(); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + static sal_Int32 getFetchDirection(); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getFetchSize() const; + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + static OUString getCursorName(); + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setFetchDirection(sal_Int32 _par0); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setFetchSize(sal_Int32 _par0); + + + inline sal_Int32 mapColumn (sal_Int32 column); + /// @throws css::sdbc::SQLException + void checkRecordSet(); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + OLEVariant getValue(sal_Int32 columnIndex ); + + protected: + + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override; + // OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + + virtual sal_Bool SAL_CALL convertFastPropertyValue( + css::uno::Any & rConvertedValue, + css::uno::Any & rOldValue, + sal_Int32 nHandle, + const css::uno::Any& rValue ) override; + virtual void SAL_CALL setFastPropertyValue_NoBroadcast( + sal_Int32 nHandle, + const css::uno::Any& rValue + ) override; + virtual void SAL_CALL getFastPropertyValue( + css::uno::Any& rValue, + sal_Int32 nHandle + ) const override; + public: + // a Constructor, that is needed for when Returning the Object is needed: + ODatabaseMetaDataResultSet( ADORecordset* _pRecordSet); + ~ODatabaseMetaDataResultSet() override; + + // ::cppu::OComponentHelper + virtual void SAL_CALL disposing() override; + // XInterface + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + // XPropertySet + virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; + // XResultSet + virtual sal_Bool SAL_CALL next( ) override; + virtual sal_Bool SAL_CALL isBeforeFirst( ) override; + virtual sal_Bool SAL_CALL isAfterLast( ) override; + virtual sal_Bool SAL_CALL isFirst( ) override; + virtual sal_Bool SAL_CALL isLast( ) override; + virtual void SAL_CALL beforeFirst( ) override; + virtual void SAL_CALL afterLast( ) override; + virtual sal_Bool SAL_CALL first( ) override; + virtual sal_Bool SAL_CALL last( ) override; + virtual sal_Int32 SAL_CALL getRow( ) override; + virtual sal_Bool SAL_CALL absolute( sal_Int32 row ) override; + virtual sal_Bool SAL_CALL relative( sal_Int32 rows ) override; + virtual sal_Bool SAL_CALL previous( ) override; + virtual void SAL_CALL refreshRow( ) override; + virtual sal_Bool SAL_CALL rowUpdated( ) override; + virtual sal_Bool SAL_CALL rowInserted( ) override; + virtual sal_Bool SAL_CALL rowDeleted( ) override; + virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getStatement( ) override; + // XRow + virtual sal_Bool SAL_CALL wasNull( ) override; + virtual OUString SAL_CALL getString( sal_Int32 columnIndex ) override; + virtual sal_Bool SAL_CALL getBoolean( sal_Int32 columnIndex ) override; + virtual sal_Int8 SAL_CALL getByte( sal_Int32 columnIndex ) override; + virtual sal_Int16 SAL_CALL getShort( sal_Int32 columnIndex ) override; + virtual sal_Int32 SAL_CALL getInt( sal_Int32 columnIndex ) override; + virtual sal_Int64 SAL_CALL getLong( sal_Int32 columnIndex ) override; + virtual float SAL_CALL getFloat( sal_Int32 columnIndex ) override; + virtual double SAL_CALL getDouble( sal_Int32 columnIndex ) override; + virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes( sal_Int32 columnIndex ) override; + virtual css::util::Date SAL_CALL getDate( sal_Int32 columnIndex ) override; + virtual css::util::Time SAL_CALL getTime( sal_Int32 columnIndex ) override; + virtual css::util::DateTime SAL_CALL getTimestamp( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream( sal_Int32 columnIndex ) override; + virtual css::uno::Any SAL_CALL getObject( sal_Int32 columnIndex, const css::uno::Reference< css::container::XNameAccess >& typeMap ) override; + virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray( sal_Int32 columnIndex ) override; + // XResultSetMetaDataSupplier + virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData( ) override; + // XCancellable + virtual void SAL_CALL cancel( ) override; + // XCloseable + virtual void SAL_CALL close( ) override; + // XWarningsSupplier + virtual css::uno::Any SAL_CALL getWarnings( ) override; + virtual void SAL_CALL clearWarnings( ) override; + // XColumnLocate + virtual sal_Int32 SAL_CALL findColumn( const OUString& columnName ) override; + + const std::vector<sal_Int32>& getColumnMapping() { return m_aColMapping; } + + void setCatalogsMap(); + void setSchemasMap(); + void setColumnPrivilegesMap(); + void setColumnsMap(); + void setTablesMap(); + void setProcedureColumnsMap(); + void setProceduresMap(); + void setExportedKeysMap(); + void setImportedKeysMap(); + void setPrimaryKeysMap(); + void setIndexInfoMap(); + void setTablePrivilegesMap(); + void setCrossReferenceMap(); + void setTypeInfoMap(bool _bJetEngine); + }; + + inline sal_Int32 ODatabaseMetaDataResultSet::mapColumn (sal_Int32 column) + { + sal_Int32 map = column; + + if (!m_aColMapping.empty()) + { + // Validate column number + map = m_aColMapping[column]; + } + + return map; + } + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/ADatabaseMetaDataResultSetMetaData.hxx b/connectivity/source/inc/ado/ADatabaseMetaDataResultSetMetaData.hxx new file mode 100644 index 0000000000..abac49ba1d --- /dev/null +++ b/connectivity/source/inc/ado/ADatabaseMetaDataResultSetMetaData.hxx @@ -0,0 +1,102 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/sdbc/XResultSetMetaData.hpp> +#include <cppuhelper/implbase.hxx> +#include <vector> +#include <ado/Awrapado.hxx> +#include <ado/ADatabaseMetaDataResultSet.hxx> +#include <OColumn.hxx> + +namespace connectivity::ado +{ + + //************ Class: ResultSetMetaData + + typedef ::cppu::WeakImplHelper< css::sdbc::XResultSetMetaData> ODatabaseMetaResultSetMetaData_BASE; + + class ODatabaseMetaDataResultSetMetaData : public ODatabaseMetaResultSetMetaData_BASE + { + friend class ODatabaseMetaDataResultSet; + + const std::vector<sal_Int32> &m_vMapping; // when not every column is needed + std::map<sal_Int32,connectivity::OColumn> m_mColumns; + std::map<sal_Int32,connectivity::OColumn>::const_iterator m_mColumnsIter; + + ADORecordset* m_pRecordSet; + sal_Int32 m_nColCount; + + private: + ODatabaseMetaDataResultSetMetaData( const ODatabaseMetaDataResultSetMetaData& ); // never implemented + ODatabaseMetaDataResultSetMetaData& operator=( const ODatabaseMetaDataResultSetMetaData& ); // never implemented + + protected: + void setColumnPrivilegesMap(); + void setColumnsMap(); + void setTablesMap(); + void setProcedureColumnsMap(); + void setPrimaryKeysMap(); + void setIndexInfoMap(); + void setTablePrivilegesMap(); + void setCrossReferenceMap(); + void setTypeInfoMap(); + void setProceduresMap(); + public: + // a Constructor, that is needed for when Returning the Object is needed: + ODatabaseMetaDataResultSetMetaData( ADORecordset* _pRecordSet ,ODatabaseMetaDataResultSet* _pRes) + : m_vMapping(_pRes->getColumnMapping()), + m_pRecordSet(_pRecordSet), + m_nColCount(m_vMapping.size()-1) + { + if(m_pRecordSet) + m_pRecordSet->AddRef(); + } + ~ODatabaseMetaDataResultSetMetaData() override; + + /// Avoid ambiguous cast error from the compiler. + operator css::uno::Reference< css::sdbc::XResultSetMetaData > () noexcept + { return this; } + + virtual sal_Int32 SAL_CALL getColumnCount( ) override; + virtual sal_Bool SAL_CALL isAutoIncrement( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isCaseSensitive( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isSearchable( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isCurrency( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL isNullable( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isSigned( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getColumnDisplaySize( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnLabel( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnName( sal_Int32 column ) override; + virtual OUString SAL_CALL getSchemaName( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getPrecision( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getScale( sal_Int32 column ) override; + virtual OUString SAL_CALL getTableName( sal_Int32 column ) override; + virtual OUString SAL_CALL getCatalogName( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getColumnType( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnTypeName( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isReadOnly( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isWritable( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isDefinitelyWritable( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnServiceName( sal_Int32 column ) override; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/ADriver.hxx b/connectivity/source/inc/ado/ADriver.hxx new file mode 100644 index 0000000000..8542e03f6d --- /dev/null +++ b/connectivity/source/inc/ado/ADriver.hxx @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/sdbc/XDriver.hpp> +#include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <cppuhelper/compbase.hxx> +#include <connectivity/CommonTools.hxx> + +namespace com::sun::star::uno { class XComponentContext; } + +namespace connectivity::ado +{ + typedef ::cppu::WeakComponentImplHelper< css::sdbc::XDriver, + css::sdbcx::XDataDefinitionSupplier, + css::lang::XServiceInfo + > ODriver_BASE; + class ODriver : public ODriver_BASE + { + ::osl::Mutex m_aMutex; + + connectivity::OWeakRefArray m_xConnections; // vector containing a list + // of all the Connection objects + // for this Driver + css::uno::Reference< css::uno::XComponentContext > m_xContext; + + // to put back all the inits with COINIT_MULTITHREADED if needed + int mnNbCallCoInitializeExForReinit; + + public: + ODriver(const css::uno::Reference< css::uno::XComponentContext >& xContext); + ~ODriver() override; + + // OComponentHelper + virtual void SAL_CALL disposing() override; + + css::uno::Reference< css::uno::XComponentContext > getContext() const { return m_xContext; } + + private: + void impl_checkURL_throw(const OUString& _sUrl); + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName( ) override; + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; + + // XDriver + virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL connect( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + virtual sal_Bool SAL_CALL acceptsURL( const OUString& url ) override; + virtual css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + virtual sal_Int32 SAL_CALL getMajorVersion( ) override; + virtual sal_Int32 SAL_CALL getMinorVersion( ) override; + + // XDataDefinitionSupplier + virtual css::uno::Reference< css::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByConnection( const css::uno::Reference< css::sdbc::XConnection >& connection ) override; + virtual css::uno::Reference< css::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByURL( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + }; + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AGroup.hxx b/connectivity/source/inc/ado/AGroup.hxx new file mode 100644 index 0000000000..00207a5fa2 --- /dev/null +++ b/connectivity/source/inc/ado/AGroup.hxx @@ -0,0 +1,58 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sdbcx/VGroup.hxx> +#include <ado/Awrapadox.hxx> + +namespace connectivity::ado +{ + typedef sdbcx::OGroup OGroup_ADO; + class OCatalog; + + class OAdoGroup : public OGroup_ADO + { + WpADOGroup m_aGroup; + OCatalog* m_pCatalog; + + static sal_Int32 MapRight(RightsEnum _eNum); + static RightsEnum Map2Right(sal_Int32 _eNum); + static ObjectTypeEnum MapObjectType(sal_Int32 ObjType); + protected: + virtual void SAL_CALL getFastPropertyValue(css::uno::Any& rValue,sal_Int32 nHandle) const override; + virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const css::uno::Any& rValue) override; + + public: + virtual void refreshUsers() override; + public: + OAdoGroup(OCatalog* _pParent,bool _bCase, ADOGroup* _pGroup=nullptr); + OAdoGroup(OCatalog* _pParent,bool _bCase, const OUString& Name); + + // XAuthorizable + virtual sal_Int32 SAL_CALL getPrivileges( const OUString& objName, sal_Int32 objType ) override; + virtual sal_Int32 SAL_CALL getGrantablePrivileges( const OUString& objName, sal_Int32 objType ) override; + virtual void SAL_CALL grantPrivileges( const OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) override; + virtual void SAL_CALL revokePrivileges( const OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) override; + + WpADOGroup getImpl() const { return m_aGroup; } + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AGroups.hxx b/connectivity/source/inc/ado/AGroups.hxx new file mode 100644 index 0000000000..85817cec84 --- /dev/null +++ b/connectivity/source/inc/ado/AGroups.hxx @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <connectivity/sdbcx/VCollection.hxx> +#include <ado/Awrapadox.hxx> +#include <ado/ACatalog.hxx> + +namespace connectivity::ado +{ + class OGroups : public sdbcx::OCollection + { + WpADOGroups m_aCollection; + OCatalog* m_pCatalog; + protected: + + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void dropObject(sal_Int32 _nPos,const OUString& _sElementName) override; + public: + OGroups(OCatalog* _pParent, + ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector, + const WpADOGroups& _rCollection,bool _bCase) : sdbcx::OCollection(*_pParent,_bCase,_rMutex,_rVector) + ,m_aCollection(_rCollection) + ,m_pCatalog(_pParent) + { + } + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AIndex.hxx b/connectivity/source/inc/ado/AIndex.hxx new file mode 100644 index 0000000000..98c3a77d1c --- /dev/null +++ b/connectivity/source/inc/ado/AIndex.hxx @@ -0,0 +1,46 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sdbcx/VIndex.hxx> +#include <com/sun/star/sdbc/XDatabaseMetaData.hpp> +#include <ado/Awrapadox.hxx> + +namespace connectivity::ado +{ + class OConnection; + class OAdoIndex : public sdbcx::OIndex + { + WpADOIndex m_aIndex; + OConnection* m_pConnection; + protected: + void fillPropertyValues(); + virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const css::uno::Any& rValue) override; + public: + virtual void refreshColumns() override; + public: + OAdoIndex(bool _bCase, OConnection* _pConnection,ADOIndex* _pIndex); + OAdoIndex(bool _bCase, OConnection* _pConnection); + + WpADOIndex getImpl() const { return m_aIndex;} + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AIndexes.hxx b/connectivity/source/inc/ado/AIndexes.hxx new file mode 100644 index 0000000000..48c2d1abee --- /dev/null +++ b/connectivity/source/inc/ado/AIndexes.hxx @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <connectivity/sdbcx/VCollection.hxx> +#include <com/sun/star/sdbc/XDatabaseMetaData.hpp> +#include <ado/Awrapadox.hxx> + +namespace connectivity::ado +{ + class OConnection; + class OIndexes : public sdbcx::OCollection + { + WpADOIndexes m_aCollection; + OConnection* m_pConnection; + protected: + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void dropObject(sal_Int32 _nPos,const OUString& _sElementName) override; + public: + OIndexes(::cppu::OWeakObject& _rParent, + ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector, + const WpADOIndexes& _rCollection, + bool _bCase, + OConnection* _pConnection) + : sdbcx::OCollection(_rParent,_bCase,_rMutex,_rVector) + , m_aCollection(_rCollection) + , m_pConnection(_pConnection) + { + } + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AKey.hxx b/connectivity/source/inc/ado/AKey.hxx new file mode 100644 index 0000000000..5ec3fa972b --- /dev/null +++ b/connectivity/source/inc/ado/AKey.hxx @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sdbcx/VKey.hxx> +#include <com/sun/star/sdbc/XDatabaseMetaData.hpp> +#include <ado/Awrapadox.hxx> + +namespace connectivity::ado +{ + typedef sdbcx::OKey OKey_ADO; + + class OConnection; + class OAdoKey : public OKey_ADO + { + WpADOKey m_aKey; + OConnection* m_pConnection; + protected: + void fillPropertyValues(); + virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const css::uno::Any& rValue) override; + public: + virtual void refreshColumns() override; + public: + OAdoKey(bool _bCase,OConnection* _pConnection,ADOKey* _pKey); + OAdoKey(bool _bCase,OConnection* _pConnection); + + WpADOKey getImpl() const { return m_aKey;} + // map the update/delete rules + static RuleEnum Map2Rule(sal_Int32 _eNum); + static sal_Int32 MapRule(const RuleEnum& _eNum); + + // map the keytypes + static sal_Int32 MapKeyRule(const KeyTypeEnum& _eNum); + static KeyTypeEnum Map2KeyRule(sal_Int32 _eNum); + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AKeys.hxx b/connectivity/source/inc/ado/AKeys.hxx new file mode 100644 index 0000000000..45e127e29b --- /dev/null +++ b/connectivity/source/inc/ado/AKeys.hxx @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <connectivity/sdbcx/VCollection.hxx> +#include <ado/Awrapadox.hxx> + +namespace connectivity::ado +{ + class OConnection; + class OKeys : public sdbcx::OCollection + { + WpADOKeys m_aCollection; + OConnection* m_pConnection; + + protected: + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void dropObject(sal_Int32 _nPos,const OUString& _sElementName) override; + public: + OKeys(::cppu::OWeakObject& _rParent, + ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector, + const WpADOKeys& _rCollection, + bool _bCase, + OConnection* _pConnection) : sdbcx::OCollection(_rParent,_bCase,_rMutex,_rVector) + ,m_aCollection(_rCollection) + ,m_pConnection(_pConnection) + { + } + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/APreparedStatement.hxx b/connectivity/source/inc/ado/APreparedStatement.hxx new file mode 100644 index 0000000000..2ce394dbde --- /dev/null +++ b/connectivity/source/inc/ado/APreparedStatement.hxx @@ -0,0 +1,113 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <ado/AStatement.hxx> +#include <com/sun/star/sdbc/XPreparedStatement.hpp> +#include <com/sun/star/sdbc/XParameters.hpp> +#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> + +// TODO: implement css::sdbc::XPreparedBatchExecution +// (empty implementations removed on 2014-06-16) + +namespace connectivity +{ + class OSQLParseNode; + namespace ado + { + + class OPreparedStatement : public OStatement_Base, + public css::sdbc::XPreparedStatement, + public css::sdbc::XParameters, + public css::sdbc::XResultSetMetaDataSupplier, + public css::lang::XServiceInfo + + { + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setParameter(sal_Int32 parameterIndex, const DataTypeEnum& _eType, sal_Int32 _nSize,const OLEVariant& Val); + void replaceParameterNodeName( OSQLParseNode const * _pNode, + const OUString& _sDefaultName, + sal_Int32& _nParameterCount); + protected: + + // Data attributes + + css::uno::Reference< css::sdbc::XResultSetMetaData > m_xMetaData; + ADOParameters* m_pParameters; + + virtual ~OPreparedStatement() override; + + public: + DECLARE_SERVICE_INFO(); + // a Constructor, that is needed for when Returning the Object is needed: + OPreparedStatement( OConnection* _pConnection, const OUString& sql); + + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + + // XPreparedStatement + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL executeQuery( ) override; + using OStatement_Base::executeQuery; + virtual sal_Int32 SAL_CALL executeUpdate( ) override; + using OStatement_Base::executeUpdate; + virtual sal_Bool SAL_CALL execute( ) override; + using OStatement_Base::execute; + virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( ) override; + // XParameters + virtual void SAL_CALL setNull( sal_Int32 parameterIndex, sal_Int32 sqlType ) override; + virtual void SAL_CALL setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const OUString& typeName ) override; + virtual void SAL_CALL setBoolean( sal_Int32 parameterIndex, sal_Bool x ) override; + virtual void SAL_CALL setByte( sal_Int32 parameterIndex, sal_Int8 x ) override; + virtual void SAL_CALL setShort( sal_Int32 parameterIndex, sal_Int16 x ) override; + virtual void SAL_CALL setInt( sal_Int32 parameterIndex, sal_Int32 x ) override; + virtual void SAL_CALL setLong( sal_Int32 parameterIndex, sal_Int64 x ) override; + virtual void SAL_CALL setFloat( sal_Int32 parameterIndex, float x ) override; + virtual void SAL_CALL setDouble( sal_Int32 parameterIndex, double x ) override; + virtual void SAL_CALL setString( sal_Int32 parameterIndex, const OUString& x ) override; + virtual void SAL_CALL setBytes( sal_Int32 parameterIndex, const css::uno::Sequence< sal_Int8 >& x ) override; + virtual void SAL_CALL setDate( sal_Int32 parameterIndex, const css::util::Date& x ) override; + virtual void SAL_CALL setTime( sal_Int32 parameterIndex, const css::util::Time& x ) override; + virtual void SAL_CALL setTimestamp( sal_Int32 parameterIndex, const css::util::DateTime& x ) override; + virtual void SAL_CALL setBinaryStream( sal_Int32 parameterIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override; + virtual void SAL_CALL setCharacterStream( sal_Int32 parameterIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override; + virtual void SAL_CALL setObject( sal_Int32 parameterIndex, const css::uno::Any& x ) override; + virtual void SAL_CALL setObjectWithInfo( sal_Int32 parameterIndex, const css::uno::Any& x, sal_Int32 targetSqlType, sal_Int32 scale ) override; + virtual void SAL_CALL setRef( sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XRef >& x ) override; + virtual void SAL_CALL setBlob( sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XBlob >& x ) override; + virtual void SAL_CALL setClob( sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XClob >& x ) override; + virtual void SAL_CALL setArray( sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XArray >& x ) override; + virtual void SAL_CALL clearParameters( ) override; + // XCloseable + virtual void SAL_CALL close( ) override; + // XResultSetMetaDataSupplier + virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData( ) override; + // OComponentHelper + virtual void SAL_CALL disposing() override; + }; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AResultSet.hxx b/connectivity/source/inc/ado/AResultSet.hxx new file mode 100644 index 0000000000..58de2baeb5 --- /dev/null +++ b/connectivity/source/inc/ado/AResultSet.hxx @@ -0,0 +1,234 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/sdbc/XResultSet.hpp> +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> +#include <com/sun/star/sdbc/XCloseable.hpp> +#include <com/sun/star/sdbc/XColumnLocate.hpp> +#include <com/sun/star/util/XCancellable.hpp> +#include <com/sun/star/sdbc/XWarningsSupplier.hpp> +#include <com/sun/star/sdbc/XResultSetUpdate.hpp> +#include <com/sun/star/sdbcx/XRowLocate.hpp> +#include <com/sun/star/sdbcx/XDeleteRows.hpp> +#include <com/sun/star/sdbc/XRowUpdate.hpp> +#include <cppuhelper/compbase.hxx> +#include <comphelper/proparrhlp.hxx> +#include <ado/AStatement.hxx> +#include <cppuhelper/basemutex.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> + +namespace connectivity::ado +{ + /* + ** java_sql_ResultSet + */ + typedef ::cppu::WeakComponentImplHelper< css::sdbc::XResultSet, + css::sdbc::XRow, + css::sdbc::XResultSetMetaDataSupplier, + css::util::XCancellable, + css::sdbc::XWarningsSupplier, + css::sdbc::XResultSetUpdate, + css::sdbc::XRowUpdate, + css::sdbc::XCloseable, + css::sdbc::XColumnLocate, + css::sdbcx::XRowLocate, + css::sdbcx::XDeleteRows, + css::lang::XServiceInfo> OResultSet_BASE; + + class OResultSet : public cppu::BaseMutex, + public OResultSet_BASE, + public ::cppu::OPropertySetHelper, + public ::comphelper::OPropertyArrayUsageHelper<OResultSet> + { + + ADORecordset* m_pRecordSet; + OStatement_Base* m_pStmt; + css::uno::Reference< css::uno::XInterface> m_xStatement; + css::uno::Reference< css::sdbc::XResultSetMetaData> m_xMetaData; + std::vector<OLEVariant> m_aBookmarks; + OLEVariant m_aValue; + ADO_LONGPTR m_nRowPos; + bool m_bEOF; + bool m_bOnFirstAfterOpen; + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getResultSetConcurrency() const; + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getResultSetType() const; + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + static sal_Int32 getFetchDirection(); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getFetchSize() const; + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + static OUString getCursorName(); + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setFetchDirection(sal_Int32 _par0); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setFetchSize(sal_Int32 _par0); + void updateValue(sal_Int32 columnIndex,const OLEVariant& x); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + OLEVariant getValue(sal_Int32 columnIndex ); + + protected: + + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override; + // OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + virtual sal_Bool SAL_CALL convertFastPropertyValue( + css::uno::Any & rConvertedValue, + css::uno::Any & rOldValue, + sal_Int32 nHandle, + const css::uno::Any& rValue ) override; + virtual void SAL_CALL setFastPropertyValue_NoBroadcast( + sal_Int32 nHandle, + const css::uno::Any& rValue + ) override; + virtual void SAL_CALL getFastPropertyValue( + css::uno::Any& rValue, + sal_Int32 nHandle + ) const override; + virtual ~OResultSet() override; + public: + // a Constructor, that is needed for when Returning the Object is needed: + OResultSet( ADORecordset* _pRecordSet,OStatement_Base* pStmt); + OResultSet( ADORecordset* _pRecordSet); + + // late constructor + void construct(); + void setMetaData(const css::uno::Reference< css::sdbc::XResultSetMetaData>& _xMetaData) { m_xMetaData = _xMetaData;} + + virtual OUString SAL_CALL getImplementationName( ) override; + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; + + // ::cppu::OComponentHelper + virtual void SAL_CALL disposing() override; + // XInterface + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + // XPropertySet + virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; + // XResultSet + virtual sal_Bool SAL_CALL next( ) override; + virtual sal_Bool SAL_CALL isBeforeFirst( ) override; + virtual sal_Bool SAL_CALL isAfterLast( ) override; + virtual sal_Bool SAL_CALL isFirst( ) override; + virtual sal_Bool SAL_CALL isLast( ) override; + virtual void SAL_CALL beforeFirst( ) override; + virtual void SAL_CALL afterLast( ) override; + virtual sal_Bool SAL_CALL first( ) override; + virtual sal_Bool SAL_CALL last( ) override; + virtual sal_Int32 SAL_CALL getRow( ) override; + virtual sal_Bool SAL_CALL absolute( sal_Int32 row ) override; + virtual sal_Bool SAL_CALL relative( sal_Int32 rows ) override; + virtual sal_Bool SAL_CALL previous( ) override; + virtual void SAL_CALL refreshRow( ) override; + virtual sal_Bool SAL_CALL rowUpdated( ) override; + virtual sal_Bool SAL_CALL rowInserted( ) override; + virtual sal_Bool SAL_CALL rowDeleted( ) override; + virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getStatement( ) override; + // XRow + virtual sal_Bool SAL_CALL wasNull( ) override; + virtual OUString SAL_CALL getString( sal_Int32 columnIndex ) override; + virtual sal_Bool SAL_CALL getBoolean( sal_Int32 columnIndex ) override; + virtual sal_Int8 SAL_CALL getByte( sal_Int32 columnIndex ) override; + virtual sal_Int16 SAL_CALL getShort( sal_Int32 columnIndex ) override; + virtual sal_Int32 SAL_CALL getInt( sal_Int32 columnIndex ) override; + virtual sal_Int64 SAL_CALL getLong( sal_Int32 columnIndex ) override; + virtual float SAL_CALL getFloat( sal_Int32 columnIndex ) override; + virtual double SAL_CALL getDouble( sal_Int32 columnIndex ) override; + virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes( sal_Int32 columnIndex ) override; + virtual css::util::Date SAL_CALL getDate( sal_Int32 columnIndex ) override; + virtual css::util::Time SAL_CALL getTime( sal_Int32 columnIndex ) override; + virtual css::util::DateTime SAL_CALL getTimestamp( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream( sal_Int32 columnIndex ) override; + virtual css::uno::Any SAL_CALL getObject( sal_Int32 columnIndex, const css::uno::Reference< css::container::XNameAccess >& typeMap ) override; + virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray( sal_Int32 columnIndex ) override; + // XResultSetMetaDataSupplier + virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData( ) override; + // XCancellable + virtual void SAL_CALL cancel( ) override; + // XCloseable + virtual void SAL_CALL close( ) override; + // XWarningsSupplier + virtual css::uno::Any SAL_CALL getWarnings( ) override; + virtual void SAL_CALL clearWarnings( ) override; + // XResultSetUpdate + virtual void SAL_CALL insertRow( ) override; + virtual void SAL_CALL updateRow( ) override; + virtual void SAL_CALL deleteRow( ) override; + virtual void SAL_CALL cancelRowUpdates( ) override; + virtual void SAL_CALL moveToInsertRow( ) override; + virtual void SAL_CALL moveToCurrentRow( ) override; + // XRowUpdate + virtual void SAL_CALL updateNull( sal_Int32 columnIndex ) override; + virtual void SAL_CALL updateBoolean( sal_Int32 columnIndex, sal_Bool x ) override; + virtual void SAL_CALL updateByte( sal_Int32 columnIndex, sal_Int8 x ) override; + virtual void SAL_CALL updateShort( sal_Int32 columnIndex, sal_Int16 x ) override; + virtual void SAL_CALL updateInt( sal_Int32 columnIndex, sal_Int32 x ) override; + virtual void SAL_CALL updateLong( sal_Int32 columnIndex, sal_Int64 x ) override; + virtual void SAL_CALL updateFloat( sal_Int32 columnIndex, float x ) override; + virtual void SAL_CALL updateDouble( sal_Int32 columnIndex, double x ) override; + virtual void SAL_CALL updateString( sal_Int32 columnIndex, const OUString& x ) override; + virtual void SAL_CALL updateBytes( sal_Int32 columnIndex, const css::uno::Sequence< sal_Int8 >& x ) override; + virtual void SAL_CALL updateDate( sal_Int32 columnIndex, const css::util::Date& x ) override; + virtual void SAL_CALL updateTime( sal_Int32 columnIndex, const css::util::Time& x ) override; + virtual void SAL_CALL updateTimestamp( sal_Int32 columnIndex, const css::util::DateTime& x ) override; + virtual void SAL_CALL updateBinaryStream( sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override; + virtual void SAL_CALL updateCharacterStream( sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override; + virtual void SAL_CALL updateObject( sal_Int32 columnIndex, const css::uno::Any& x ) override; + virtual void SAL_CALL updateNumericObject( sal_Int32 columnIndex, const css::uno::Any& x, sal_Int32 scale ) override; + // XColumnLocate + virtual sal_Int32 SAL_CALL findColumn( const OUString& columnName ) override; + // XRowLocate + virtual css::uno::Any SAL_CALL getBookmark( ) override; + virtual sal_Bool SAL_CALL moveToBookmark( const css::uno::Any& bookmark ) override; + virtual sal_Bool SAL_CALL moveRelativeToBookmark( const css::uno::Any& bookmark, sal_Int32 rows ) override; + virtual sal_Int32 SAL_CALL compareBookmarks( const css::uno::Any& first, const css::uno::Any& second ) override; + virtual sal_Bool SAL_CALL hasOrderedBookmarks( ) override; + virtual sal_Int32 SAL_CALL hashBookmark( const css::uno::Any& bookmark ) override; + // XDeleteRows + virtual css::uno::Sequence< sal_Int32 > SAL_CALL deleteRows( const css::uno::Sequence< css::uno::Any >& rows ) override; + + }; + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AResultSetMetaData.hxx b/connectivity/source/inc/ado/AResultSetMetaData.hxx new file mode 100644 index 0000000000..1eeb226562 --- /dev/null +++ b/connectivity/source/inc/ado/AResultSetMetaData.hxx @@ -0,0 +1,79 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/sdbc/XResultSetMetaData.hpp> +#include <cppuhelper/implbase.hxx> +#include <vector> +#include <ado/Awrapado.hxx> +#include <ado/AResultSet.hxx> +#include <OColumn.hxx> + +namespace connectivity::ado +{ + + + //************ Class: ResultSetMetaData + + typedef ::cppu::WeakImplHelper<css::sdbc::XResultSetMetaData> OResultSetMetaData_BASE; + + class OResultSetMetaData : public OResultSetMetaData_BASE + { + friend class OResultSet; + + ADORecordset* m_pRecordSet; + sal_Int32 m_nColCount; + + sal_Int32 MapADOType2Jdbc(DataTypeEnum eType); + private: + OResultSetMetaData( const OResultSetMetaData& ); // never implemented + OResultSetMetaData& operator=( const OResultSetMetaData& ); // never implemented + + protected: + virtual ~OResultSetMetaData() override; + public: + // a Constructor, that is needed for when Returning the Object is needed: + OResultSetMetaData( ADORecordset* _pRecordSet); + + virtual sal_Int32 SAL_CALL getColumnCount( ) override; + virtual sal_Bool SAL_CALL isAutoIncrement( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isCaseSensitive( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isSearchable( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isCurrency( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL isNullable( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isSigned( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getColumnDisplaySize( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnLabel( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnName( sal_Int32 column ) override; + virtual OUString SAL_CALL getSchemaName( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getPrecision( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getScale( sal_Int32 column ) override; + virtual OUString SAL_CALL getTableName( sal_Int32 column ) override; + virtual OUString SAL_CALL getCatalogName( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getColumnType( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnTypeName( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isReadOnly( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isWritable( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isDefinitelyWritable( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnServiceName( sal_Int32 column ) override; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AStatement.hxx b/connectivity/source/inc/ado/AStatement.hxx new file mode 100644 index 0000000000..6253399175 --- /dev/null +++ b/connectivity/source/inc/ado/AStatement.hxx @@ -0,0 +1,217 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/sdbc/XStatement.hpp> +#include <com/sun/star/sdbc/XWarningsSupplier.hpp> +#include <com/sun/star/sdbc/XMultipleResults.hpp> +#include <com/sun/star/sdbc/XBatchExecution.hpp> +#include <com/sun/star/sdbc/XCloseable.hpp> +#include <com/sun/star/sdbc/SQLWarning.hpp> +#include <com/sun/star/util/XCancellable.hpp> +#include <cppuhelper/compbase.hxx> +#include <cppuhelper/basemutex.hxx> +#include <comphelper/proparrhlp.hxx> +#include <ado/AConnection.hxx> +#include <string_view> +#include <vector> +#include <ado/Awrapado.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> + +namespace connectivity::ado +{ + typedef ::cppu::WeakComponentImplHelper< css::sdbc::XStatement, + css::sdbc::XWarningsSupplier, + css::util::XCancellable, + css::sdbc::XCloseable, + css::sdbc::XMultipleResults> OStatement_BASE; + + + //************ Class: java.sql.Statement + + class OStatement_Base : public cppu::BaseMutex, + public OStatement_BASE, + public ::cppu::OPropertySetHelper, + public ::comphelper::OPropertyArrayUsageHelper<OStatement_Base> + + { + friend class OResultSet; + + css::sdbc::SQLWarning m_aLastWarning; + + protected: + std::vector< OUString> m_aBatchVector; + + css::uno::WeakReference< css::sdbc::XResultSet> m_xResultSet; // The last ResultSet created + // for this Statement + + OConnection* m_pConnection;// The owning Connection object + WpADOCommand m_Command; + WpADORecordset m_RecordSet; + OLEVariant m_RecordsAffected; + OLEVariant m_Parameters; + std::vector<connectivity::OTypeInfo> m_aTypeInfo; // Hashtable containing an entry + // for each row returned by + // DatabaseMetaData.getTypeInfo. + ADO_LONGPTR m_nMaxRows; + sal_Int32 m_nFetchSize; + LockTypeEnum m_eLockType; + CursorTypeEnum m_eCursorType; + + using OStatement_BASE::rBHelper; + private: + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getQueryTimeOut() const; + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + static sal_Int32 getMaxFieldSize(); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getMaxRows() const; + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getResultSetConcurrency() const; + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getResultSetType() const; + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + static sal_Int32 getFetchDirection(); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getFetchSize() const; + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + OUString getCursorName() const; + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setQueryTimeOut(sal_Int32 _par0); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setMaxFieldSize(sal_Int32 _par0); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setMaxRows(sal_Int32 _par0); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setResultSetConcurrency(sal_Int32 _par0); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setResultSetType(sal_Int32 _par0); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setFetchDirection(sal_Int32 _par0); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setFetchSize(sal_Int32 _par0); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setCursorName(std::u16string_view _par0); + + protected: + + void assignRecordSet( ADORecordset* _pRS ); + + /// @throws css::sdbc::SQLException + void reset (); + /// @throws css::sdbc::SQLException + void clearMyResultSet (); + /// @throws css::sdbc::SQLException + void setWarning (const css::sdbc::SQLWarning &ex); + /// @throws css::sdbc::SQLException + sal_Int32 getRowCount (); + sal_Int32 getPrecision ( sal_Int32 sqlType); + + void disposeResultSet(); + + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override; + // OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + virtual sal_Bool SAL_CALL convertFastPropertyValue( + css::uno::Any & rConvertedValue, + css::uno::Any & rOldValue, + sal_Int32 nHandle, + const css::uno::Any& rValue ) override; + virtual void SAL_CALL setFastPropertyValue_NoBroadcast( + sal_Int32 nHandle, + const css::uno::Any& rValue + ) override; + virtual void SAL_CALL getFastPropertyValue( + css::uno::Any& rValue, + sal_Int32 nHandle + ) const override; + public: + OStatement_Base(OConnection* _pConnection ); + + using OStatement_BASE::operator css::uno::Reference< css::uno::XInterface >; + // OComponentHelper + virtual void SAL_CALL disposing() override; + // XInterface + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + + // XPropertySet + virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; + // XStatement + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL executeQuery( const OUString& sql ) override; + virtual sal_Int32 SAL_CALL executeUpdate( const OUString& sql ) override; + virtual sal_Bool SAL_CALL execute( const OUString& sql ) override; + virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( ) override; + // XWarningsSupplier + virtual css::uno::Any SAL_CALL getWarnings( ) override; + virtual void SAL_CALL clearWarnings( ) override; + // XCancellable + virtual void SAL_CALL cancel( ) override; + // XCloseable + virtual void SAL_CALL close( ) override; + // XMultipleResults + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getResultSet( ) override; + virtual sal_Int32 SAL_CALL getUpdateCount( ) override; + virtual sal_Bool SAL_CALL getMoreResults( ) override; + }; + + class OStatement : public OStatement_Base, + public css::sdbc::XBatchExecution, + public css::lang::XServiceInfo + { + public: + // a Constructor, that is needed for when Returning the Object is needed: + OStatement( OConnection* _pConnection) : OStatement_Base( _pConnection){}; + ~OStatement() override; + + DECLARE_SERVICE_INFO(); + + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + // XBatchExecution + virtual void SAL_CALL addBatch( const OUString& sql ) override; + virtual void SAL_CALL clearBatch( ) override; + virtual css::uno::Sequence< sal_Int32 > SAL_CALL executeBatch( ) override; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/ATable.hxx b/connectivity/source/inc/ado/ATable.hxx new file mode 100644 index 0000000000..827485a6b4 --- /dev/null +++ b/connectivity/source/inc/ado/ATable.hxx @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <connectivity/sdbcx/VTable.hxx> +#include <ado/Awrapadox.hxx> +#include <ado/ACatalog.hxx> + +namespace connectivity::ado +{ + typedef connectivity::sdbcx::OTable OTable_TYPEDEF; + typedef connectivity::sdbcx::OTableDescriptor_BASE OTableDescriptor_BASE_TYPEDEF; + + class OAdoTable : public OTable_TYPEDEF + { + WpADOTable m_aTable; + OCatalog* m_pCatalog; + + protected: + void fillPropertyValues(); + virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const css::uno::Any& rValue) override; + + public: + virtual void refreshColumns() override; + virtual void refreshKeys() override; + virtual void refreshIndexes() override; + + // ::cppu::OComponentHelper + virtual void SAL_CALL disposing() override; + + public: + OAdoTable(sdbcx::OCollection* _pTables,bool _bCase,OCatalog* _pCatalog,_ADOTable* _pTable); + OAdoTable(sdbcx::OCollection* _pTables,bool _bCase,OCatalog* _pCatalog); + + + virtual OUString SAL_CALL getName() override; + OUString getSchema() const { return m_SchemaName; } + virtual css::uno::Reference< css::sdbc::XDatabaseMetaData> getMetaData() const override; + + // XRename + virtual void SAL_CALL rename( const OUString& newName ) override; + + // XAlterTable + virtual void SAL_CALL alterColumnByName( const OUString& colName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void SAL_CALL alterColumnByIndex( sal_Int32 index, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + + WpADOTable getImpl() const { return m_aTable;} + OCatalog* getCatalog() const { return m_pCatalog; } + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/ATables.hxx b/connectivity/source/inc/ado/ATables.hxx new file mode 100644 index 0000000000..4fff5b9795 --- /dev/null +++ b/connectivity/source/inc/ado/ATables.hxx @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <connectivity/sdbcx/VCollection.hxx> +#include <ado/Awrapadox.hxx> +#include <ado/ACatalog.hxx> + +namespace connectivity::ado +{ + class OCatalog; + class OTables : public sdbcx::OCollection + { + WpADOTables m_aCollection; + OCatalog* m_pCatalog; + protected: + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void dropObject(sal_Int32 _nPos,const OUString& _sElementName) override; + public: + OTables(OCatalog* _pParent, ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector, + const WpADOTables& _rCollection, + bool _bCase) : sdbcx::OCollection(*_pParent,_bCase,_rMutex,_rVector) + ,m_aCollection(_rCollection) + ,m_pCatalog(_pParent) + { + OSL_ENSURE(m_aCollection.IsValid(),"Collection isn't valid"); + } + void appendNew(const OUString& _rsNewTable); + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AUser.hxx b/connectivity/source/inc/ado/AUser.hxx new file mode 100644 index 0000000000..8d0c0f7321 --- /dev/null +++ b/connectivity/source/inc/ado/AUser.hxx @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sdbcx/VUser.hxx> +#include <ado/Awrapadox.hxx> + +namespace connectivity::ado +{ + class OCatalog; + typedef connectivity::sdbcx::OUser OUser_TYPEDEF; + typedef connectivity::sdbcx::OUser_BASE OUser_BASE_TYPEDEF; + + class OAdoUser : public OUser_TYPEDEF + { + protected: + WpADOUser m_aUser; + OCatalog* m_pCatalog; + + virtual void SAL_CALL setFastPropertyValue_NoBroadcast( + sal_Int32 nHandle, + const css::uno::Any& rValue + ) override; + virtual void SAL_CALL getFastPropertyValue( + css::uno::Any& rValue, + sal_Int32 nHandle + ) const override; + public: + virtual void refreshGroups() override; + public: + OAdoUser(OCatalog* _pParent,bool _bCase, ADOUser* _pUser=nullptr); + OAdoUser(OCatalog* _pParent,bool _bCase, const OUString& Name); + + // XUser + virtual void SAL_CALL changePassword( const OUString& objPassword, const OUString& newPassword ) override; + // XAuthorizable + virtual sal_Int32 SAL_CALL getPrivileges( const OUString& objName, sal_Int32 objType ) override; + virtual sal_Int32 SAL_CALL getGrantablePrivileges( const OUString& objName, sal_Int32 objType ) override; + virtual void SAL_CALL grantPrivileges( const OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) override; + virtual void SAL_CALL revokePrivileges( const OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) override; + + WpADOUser getImpl() const { return m_aUser;} + }; + + class OUserExtend; + typedef ::comphelper::OPropertyArrayUsageHelper<OUserExtend> OUserExtend_PROP; + + class OUserExtend : public OAdoUser, + public OUserExtend_PROP + { + protected: + OUString m_Password; + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const override; + // OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + public: + OUserExtend(OCatalog* _pParent,bool _bCase,ADOUser* _pUser=nullptr); + OUserExtend(OCatalog* _pParent,bool _bCase,const OUString& Name); + + virtual void construct() override; + OUString getPassword() const { return m_Password;} + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AUsers.hxx b/connectivity/source/inc/ado/AUsers.hxx new file mode 100644 index 0000000000..1ec0bd5ad8 --- /dev/null +++ b/connectivity/source/inc/ado/AUsers.hxx @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <connectivity/sdbcx/VCollection.hxx> +#include <ado/Awrapadox.hxx> +#include <ado/ACatalog.hxx> + +namespace connectivity::ado +{ + + class OUsers : public sdbcx::OCollection + { + WpADOUsers m_aCollection; + OCatalog* m_pCatalog; + public: + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual void impl_refresh() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void dropObject(sal_Int32 _nPos,const OUString& _sElementName) override; + public: + OUsers( OCatalog* _pParent, + ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector, + const WpADOUsers& _rCollection, + bool _bCase) + :sdbcx::OCollection(*_pParent,_bCase,_rMutex,_rVector) + ,m_aCollection(_rCollection) + ,m_pCatalog(_pParent) + { + } + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AView.hxx b/connectivity/source/inc/ado/AView.hxx new file mode 100644 index 0000000000..db81c4e70b --- /dev/null +++ b/connectivity/source/inc/ado/AView.hxx @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <connectivity/sdbcx/VView.hxx> +#include <ado/Awrapadox.hxx> + +namespace connectivity::ado +{ + + typedef sdbcx::OView OView_ADO; + + class OAdoView : public OView_ADO + { + WpADOView m_aView; + + protected: + // OPropertySetHelper + virtual void SAL_CALL getFastPropertyValue( + css::uno::Any& rValue, + sal_Int32 nHandle + ) const override; + public: + OAdoView(bool _bCase, ADOView* _pView=nullptr); + + WpADOView getImpl() const { return m_aView;} + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AViews.hxx b/connectivity/source/inc/ado/AViews.hxx new file mode 100644 index 0000000000..ef0c692fdf --- /dev/null +++ b/connectivity/source/inc/ado/AViews.hxx @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <connectivity/sdbcx/VCollection.hxx> +#include <ado/Awrapadox.hxx> +#include <ado/ACatalog.hxx> + + +namespace connectivity::ado +{ + + class OViews : public sdbcx::OCollection + { + WpADOViews m_aCollection; + OCatalog* m_pCatalog; + protected: + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void dropObject(sal_Int32 _nPos,const OUString& _sElementName) override; + public: + OViews(OCatalog* _pParent, ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector, + WpADOViews const & _rCollection,bool _bCase) : sdbcx::OCollection(*_pParent,_bCase,_rMutex,_rVector) + ,m_aCollection(_rCollection) + ,m_pCatalog(_pParent) + { + } + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/Aolevariant.hxx b/connectivity/source/inc/ado/Aolevariant.hxx new file mode 100644 index 0000000000..ba0653156a --- /dev/null +++ b/connectivity/source/inc/ado/Aolevariant.hxx @@ -0,0 +1,123 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <sal/types.h> +#include <rtl/ustring.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <oaidl.h> + +namespace com::sun::star::util +{ + struct Date; + struct Time; + struct DateTime; +} + +namespace connectivity::ado +{ + class OLEVariant : public ::tagVARIANT + { + public: + OLEVariant(); + OLEVariant(const VARIANT& varSrc); + OLEVariant(const OLEVariant& varSrc) ; + OLEVariant(bool x) ; + OLEVariant(sal_Bool) = delete; + OLEVariant(sal_Int8 n) ; + OLEVariant(sal_Int16 n) ; + OLEVariant(sal_Int32 n) ; + OLEVariant(sal_Int64 x) ; + + OLEVariant(std::u16string_view us); + OLEVariant(const OUString& us) + : OLEVariant(std::u16string_view(us)) + { + } + ~OLEVariant() ; + OLEVariant(const css::util::Date& x ); + OLEVariant(const css::util::Time& x ); + OLEVariant(const css::util::DateTime& x ); + OLEVariant(float x); + OLEVariant(const double &x); + OLEVariant(IDispatch* pDispInterface); + OLEVariant(const css::uno::Sequence< sal_Int8 >& x); + OLEVariant& operator=(const OLEVariant& varSrc); + // Assign a const VARIANT& (::VariantCopy handles everything) + + OLEVariant& operator=(const tagVARIANT& varSrc); + // Assign a const VARIANT* (::VariantCopy handles everything) + + OLEVariant& operator=(const VARIANT* pSrc); + void setByte(sal_uInt8 n) ; + void setInt16(sal_Int16 n) ; + void setInt32(sal_Int32 n) ; + void setFloat(float f) ; + void setDouble(double d) ; + void setDate(DATE d) ; + void setChar(unsigned char a) ; + void setCurrency(double aCur) ; + void setBool(bool b) ; + void setString(std::u16string_view us); + void setNoArg() ; + + void setIDispatch(IDispatch* pDispInterface); + void setNull() ; + void setEmpty() ; + + void setUI1SAFEARRAYPtr(SAFEARRAY* pSafeAr); + void setArray(SAFEARRAY* pSafeArray, VARTYPE vtType); + bool isNull() const ; + bool isEmpty() const ; + + VARTYPE getType() const ; + void ChangeType(VARTYPE vartype, const OLEVariant* pSrc); + + OUString getString() const; + bool getBool() const; + IUnknown* getIUnknown() const; + IDispatch* getIDispatch() const; + sal_uInt8 getByte() const; + sal_Int16 getInt16() const; + sal_Int8 getInt8() const; + sal_Int32 getInt32() const; + sal_uInt32 getUInt32() const; + float getFloat() const; + double getDouble() const; + double getDateAsDouble() const; + CY getCurrency() const; + css::util::Date getDate() const; + css::util::Time getTime() const; + css::util::DateTime getDateTime() const; + css::uno::Sequence<sal_Int8> getByteSequence() const; + SAFEARRAY* getUI1SAFEARRAYPtr() const; + css::uno::Any makeAny() const; + + static VARIANT_BOOL VariantBool(bool bEinBoolean); + + private: + void CHS(); + + void set(double n); + + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/Aolewrap.hxx b/connectivity/source/inc/ado/Aolewrap.hxx new file mode 100644 index 0000000000..9d402fcf21 --- /dev/null +++ b/connectivity/source/inc/ado/Aolewrap.hxx @@ -0,0 +1,174 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <osl/diagnose.h> +#include <osl/thread.h> +#include <systools/win32/comtools.hxx> + +#include <map> +#include <vector> + +#include "Aolevariant.hxx" + +namespace rtl +{ + class OUString; +} +namespace connectivity::ado +{ + // Template class WpOLEBase<class T> + // ================================== + // + // Objects of this class contain a pointer to an interface of the type T. + + template<class T> class WpOLEBase + { + protected: + sal::systools::COMReference<T> pInterface; + + public: + WpOLEBase(T* pInt = nullptr) : pInterface(pInt){} + + WpOLEBase(const WpOLEBase<T>& aWrapper) + : pInterface( aWrapper.pInterface ) + { + } + + //inline + WpOLEBase<T>& operator=(const WpOLEBase<T>& rhs) + { + pInterface = rhs.pInterface; + return *this; + }; + + operator T*() const { return pInterface.get(); } + T** operator&() { return &pInterface; } + bool IsValid() const { return pInterface.is(); } + void set(T* p) { pInterface = p; } + void clear() { pInterface.clear(); } + }; + + + // Template class WpOLECollection<class Ts, class WrapT> + // =============================================================== + // + // This class (derived from WpOLEBase<Ts>), abstracts away the properties + // common to DAO collections: + // + // They are accessed via an interface Ts (e.g. DAOFields) and can return + // Items of the type wrapped by WrapT (actually: with the interface, e.g. + // DAOField) via get_Item (here GetItem). + // + // This wrapper class exposes an object of the class WrapT. + + template<class Ts, class WrapT> class WpOLECollection : public WpOLEBase<Ts> + { + public: + using WpOLEBase<Ts>::pInterface; + using WpOLEBase<Ts>::IsValid; + // Ctors, operator= + // They only call the superclass + WpOLECollection() = default; + WpOLECollection(const WpOLECollection& rhs) : WpOLEBase<Ts>(rhs) {} + WpOLECollection& operator=(const WpOLECollection& rhs) + {WpOLEBase<Ts>::operator=(rhs); return *this;}; + + + void Refresh(){pInterface->Refresh();} + + sal_Int32 GetItemCount() const + { + sal_Int32 nCount = 0; + return pInterface ? (SUCCEEDED(pInterface->get_Count(&nCount)) ? nCount : sal_Int32(0)) : sal_Int32(0); + } + + WrapT GetItem(sal_Int32 index) const + { + OSL_ENSURE(index >= 0 && index<GetItemCount(),"Wrong index for field!"); + WrapT aRet; + pInterface->get_Item(OLEVariant(index), &aRet); + return aRet; + } + + WrapT GetItem(const OLEVariant& index) const + { + WrapT aRet; + pInterface->get_Item(index, &aRet); + return aRet; + } + + WrapT GetItem(const OUString& sStr) const + { + WrapT aRet; + if (FAILED(pInterface->get_Item(OLEVariant(sStr), &aRet))) + { +#if OSL_DEBUG_LEVEL > 0 + OString sTemp("Unknown Item: " + OString(sStr.getStr(),sStr.getLength(),osl_getThreadTextEncoding())); + OSL_FAIL(sTemp.getStr()); +#endif + } + return aRet; + } + void fillElementNames(::std::vector< OUString>& _rVector) + { + if(IsValid()) + { + Refresh(); + sal_Int32 nCount = GetItemCount(); + _rVector.reserve(nCount); + for(sal_Int32 i=0;i< nCount;++i) + { + WrapT aElement = GetItem(i); + if(aElement.IsValid()) + _rVector.push_back(aElement.get_Name()); + } + } + } + }; + + template<class Ts, class WrapT> class WpOLEAppendCollection: + public WpOLECollection<Ts,WrapT> + { + + public: + // Ctors, operator= + // They only call the superclass + using WpOLEBase<Ts>::pInterface; + WpOLEAppendCollection() = default; + WpOLEAppendCollection(const WpOLEAppendCollection& rhs) : WpOLECollection<Ts, WrapT>(rhs) {} + WpOLEAppendCollection& operator=(const WpOLEAppendCollection& rhs) + {WpOLEBase<Ts>::operator=(rhs); return *this;}; + + + bool Append(const WrapT& aWrapT) + { + return SUCCEEDED(pInterface->Append(OLEVariant(aWrapT))); + }; + + bool Delete(const OUString& sName) + { + return SUCCEEDED(pInterface->Delete(OLEVariant(sName))); + }; + + + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/Awrapado.hxx b/connectivity/source/inc/ado/Awrapado.hxx new file mode 100644 index 0000000000..507b855226 --- /dev/null +++ b/connectivity/source/inc/ado/Awrapado.hxx @@ -0,0 +1,372 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <sal/config.h> + +#include <string_view> + +#include <com/sun/star/beans/PropertyAttribute.hpp> + +// Includes for ADO +#include <oledb.h> +#include <ocidl.h> +#include <adoint.h> +#include <ado/adoimp.hxx> +#include <ado/Aolewrap.hxx> +#include <ado/Aolevariant.hxx> + +namespace connectivity::ado +{ + class WpADOConnection; + class WpADOCommand; + class WpADORecordset; + class WpADOField; + class WpADOParameter; + class WpADOError; + class WpADOProperty; + + typedef WpOLEAppendCollection< ADOFields, WpADOField> WpADOFields; + typedef WpOLECollection< ADOProperties, WpADOProperty> WpADOProperties; + + + class WpADOConnection : public WpOLEBase<ADOConnection> + { + public: + + WpADOConnection() = default; + + WpADOConnection(const WpADOConnection& rhs) : WpOLEBase<ADOConnection>(rhs) {} + + WpADOConnection& operator=(const WpADOConnection& rhs) + {WpOLEBase<ADOConnection>::operator=(rhs); return *this;} + + + WpADOProperties get_Properties() const; + + OUString GetConnectionString() const; + bool PutConnectionString(std::u16string_view aCon) const; + sal_Int32 GetCommandTimeout() const; + void PutCommandTimeout(sal_Int32 nRet); + sal_Int32 GetConnectionTimeout() const ; + void PutConnectionTimeout(sal_Int32 nRet); + + bool Close( ) ; + bool Execute(std::u16string_view CommandText,OLEVariant& RecordsAffected,long Options, WpADORecordset** ppiRset); + bool BeginTrans(); + bool CommitTrans( ) ; + bool RollbackTrans( ); + bool Open(std::u16string_view ConnectionString, std::u16string_view UserID,std::u16string_view Password,long Options); + bool GetErrors(ADOErrors** pErrors); + + OUString GetDefaultDatabase() const; + bool PutDefaultDatabase(std::u16string_view _bstr); + + IsolationLevelEnum get_IsolationLevel() const ; + bool put_IsolationLevel(const IsolationLevelEnum& eNum) ; + + sal_Int32 get_Attributes() const; + bool put_Attributes(sal_Int32 nRet); + + CursorLocationEnum get_CursorLocation() const; + bool put_CursorLocation(const CursorLocationEnum &eNum) ; + + ConnectModeEnum get_Mode() const; + bool put_Mode(const ConnectModeEnum &eNum) ; + + OUString get_Provider() const; + bool put_Provider(std::u16string_view _bstr); + + sal_Int32 get_State() const; + + bool OpenSchema(SchemaEnum eNum,OLEVariant const & Restrictions,OLEVariant const & SchemaID,ADORecordset**pprset); + + OUString get_Version() const; + + // special methods + ADORecordset* getExportedKeys( const css::uno::Any& catalog, const OUString& schema, std::u16string_view table ); + ADORecordset* getImportedKeys( const css::uno::Any& catalog, const OUString& schema, std::u16string_view table ); + ADORecordset* getPrimaryKeys( const css::uno::Any& catalog, const OUString& schema, std::u16string_view table ); + ADORecordset* getIndexInfo( const css::uno::Any& catalog, const OUString& schema, std::u16string_view table, bool unique, bool approximate ); + ADORecordset* getTablePrivileges( const css::uno::Any& catalog, + const OUString& schemaPattern, + std::u16string_view tableNamePattern ); + ADORecordset* getCrossReference( const css::uno::Any& primaryCatalog, + const OUString& primarySchema, + std::u16string_view primaryTable, + const css::uno::Any& foreignCatalog, + const OUString& foreignSchema, + std::u16string_view foreignTable); + ADORecordset* getProcedures( const css::uno::Any& catalog, + const OUString& schemaPattern, + std::u16string_view procedureNamePattern ); + ADORecordset* getProcedureColumns( const css::uno::Any& catalog, + const OUString& schemaPattern, + std::u16string_view procedureNamePattern, + std::u16string_view columnNamePattern ); + ADORecordset* getTables( const css::uno::Any& catalog, + const OUString& schemaPattern, + std::u16string_view tableNamePattern, + const css::uno::Sequence< OUString >& types ); + ADORecordset* getColumns( const css::uno::Any& catalog, + const OUString& schemaPattern, + std::u16string_view tableNamePattern, + std::u16string_view columnNamePattern ); + ADORecordset* getColumnPrivileges( const css::uno::Any& catalog, + const OUString& schemaPattern, + std::u16string_view table, + std::u16string_view columnNamePattern ); + ADORecordset* getTypeInfo(DataTypeEnum _eType = adEmpty ); + }; + + + class WpADOCommand : public WpOLEBase<ADOCommand> + { + public: + WpADOCommand() = default; + // Ctors, operator= + // They only call the superclass + WpADOCommand(const WpADOCommand& rhs) : WpOLEBase<ADOCommand>(rhs) {} + + WpADOCommand& operator=(const WpADOCommand& rhs) + { + WpOLEBase<ADOCommand>::operator=(rhs); return *this;} + + + bool putref_ActiveConnection(const WpADOConnection& rCon); + + void put_ActiveConnection(/* [in] */ const OLEVariant& vConn); + void Create(); + sal_Int32 get_State() const; + OUString get_CommandText() const; + bool put_CommandText(std::u16string_view aCon) ; + sal_Int32 get_CommandTimeout() const; + void put_CommandTimeout(sal_Int32 nRet); + bool get_Prepared() const; + bool put_Prepared(VARIANT_BOOL bPrepared) const; + bool Execute(OLEVariant& RecordsAffected,OLEVariant& Parameters,long Options, ADORecordset** ppiRset); + ADOParameter* CreateParameter(std::u16string_view _bstr,DataTypeEnum Type,ParameterDirectionEnum Direction,long nSize,const OLEVariant &Value); + + ADOParameters* get_Parameters() const; + bool put_CommandType( /* [in] */ CommandTypeEnum lCmdType); + CommandTypeEnum get_CommandType( ) const ; + // Returns the field's name + OUString GetName() const ; + bool put_Name(std::u16string_view Name); + bool Cancel(); + }; + + class WpADOError : public WpOLEBase<ADOError> + { + public: + + // Ctors, operator= + // They only call the superclass + WpADOError() = default; + + WpADOError(const WpADOError& rhs) : WpOLEBase<ADOError>(rhs) {} + + WpADOError& operator=(const WpADOError& rhs) + {WpOLEBase<ADOError>::operator=(rhs); return *this;} + + + OUString GetDescription() const; + OUString GetSource() const ; + sal_Int32 GetNumber() const ; + OUString GetSQLState() const ; + sal_Int32 GetNativeError() const ; + }; + + + class WpADOField : public WpOLEBase<ADOField> + { + // friend class WpADOFields; + public: + + // Ctors, operator= + // They only call the superclass + WpADOField() = default; + WpADOField(const WpADOField& rhs) : WpOLEBase<ADOField>(rhs) {} + + WpADOField& operator=(const WpADOField& rhs) + {WpOLEBase<ADOField>::operator=(rhs); return *this;} + + + WpADOProperties get_Properties(); + sal_Int32 GetActualSize() const ; + sal_Int32 GetAttributes() const ; + sal_Int32 GetStatus() const ; + sal_Int32 GetDefinedSize() const ; + // Returns the field's name + OUString GetName() const ; + DataTypeEnum GetADOType() const ; + void get_Value(OLEVariant& aValVar) const ; + OLEVariant get_Value() const; + bool PutValue(const OLEVariant& aVariant); + sal_Int32 GetPrecision() const ; + sal_Int32 GetNumericScale() const ; + bool AppendChunk(const OLEVariant& Variant); + OLEVariant GetChunk(long Length) const; + void GetChunk(long Length,OLEVariant &aValVar) const; + OLEVariant GetOriginalValue() const; + void GetOriginalValue(OLEVariant &aValVar) const; + OLEVariant GetUnderlyingValue() const; + + void GetUnderlyingValue(OLEVariant &aValVar) const; + + bool PutPrecision(sal_Int8 _prec); + + bool PutNumericScale(sal_Int8 _prec); + + void PutADOType(DataTypeEnum eType) ; + + bool PutDefinedSize(sal_Int32 _nDefSize); + + bool PutAttributes(sal_Int32 _nDefSize); + }; + + + class WpADOProperty: public WpOLEBase<ADOProperty> + { + public: + // Ctors, operator= + // They only call the superclass + WpADOProperty() = default; + WpADOProperty(const WpADOProperty& rhs) : WpOLEBase<ADOProperty>(rhs) {} + WpADOProperty& operator=(const WpADOProperty& rhs) + {WpOLEBase<ADOProperty>::operator=(rhs); return *this;} + + + OLEVariant GetValue() const; + void GetValue(OLEVariant &aValVar) const; + bool PutValue(const OLEVariant &aValVar) ; + OUString GetName() const ; + DataTypeEnum GetADOType() const ; + sal_Int32 GetAttributes() const ; + bool PutAttributes(sal_Int32 _nDefSize); + }; + + + class WpADORecordset : public WpOLEBase<ADORecordset> + { + + public: + // Ctors, operator= + // They only call the superclass + WpADORecordset() = default; + WpADORecordset(const WpADORecordset& rhs) : WpOLEBase<ADORecordset>() {operator=(rhs);} + WpADORecordset& operator=(const WpADORecordset& rhs) + { + WpOLEBase<ADORecordset>::operator=(rhs); + return *this; + } + + void Create(); + bool Open( + /* [optional][in] */ VARIANT Source, + /* [optional][in] */ VARIANT ActiveConnection, + /* [defaultvalue][in] */ CursorTypeEnum CursorType, + /* [defaultvalue][in] */ LockTypeEnum LockType, + /* [defaultvalue][in] */ sal_Int32 Options); + LockTypeEnum GetLockType(); + void Close(); + bool Cancel() const; + sal_Int32 get_State( ); + bool Supports( /* [in] */ CursorOptionEnum CursorOptions); + PositionEnum_Param get_AbsolutePosition(); + void GetDataSource(IUnknown** pIUnknown) const ; + void PutRefDataSource(IUnknown* pIUnknown); + void GetBookmark(VARIANT& var); + OLEVariant GetBookmark(); + CompareEnum CompareBookmarks(const OLEVariant& left,const OLEVariant& right); + bool SetBookmark(const OLEVariant &pSafeAr); + WpADOFields GetFields() const; + bool Move(sal_Int32 nRows, VARIANT aBmk); + bool MoveNext(); + bool MovePrevious(); + bool MoveFirst(); + bool MoveLast(); + + bool IsAtBOF() const; + bool IsAtEOF() const; + bool Delete(AffectEnum eNum); + bool AddNew(const OLEVariant &FieldList,const OLEVariant &Values); + bool Update(const OLEVariant &FieldList,const OLEVariant &Values); + bool CancelUpdate(); + WpADOProperties get_Properties() const; + bool NextRecordset(OLEVariant& RecordsAffected,ADORecordset** ppiRset); + bool get_RecordCount(ADO_LONGPTR &_nRet) const; + bool get_MaxRecords(ADO_LONGPTR &_nRet) const; + bool put_MaxRecords(ADO_LONGPTR _nRet); + bool get_CursorType(CursorTypeEnum &_nRet) const; + bool put_CursorType(CursorTypeEnum _nRet); + bool get_LockType(LockTypeEnum &_nRet) const; + bool put_LockType(LockTypeEnum _nRet); + bool get_CacheSize(sal_Int32 &_nRet) const; + bool put_CacheSize(sal_Int32 _nRet); + bool UpdateBatch(AffectEnum AffectRecords); + }; + + + class WpADOParameter:public WpOLEBase<ADOParameter> + { + public: + // Ctors, operator= + // They only call the superclass + WpADOParameter() = default; + WpADOParameter(const WpADOParameter& rhs):WpOLEBase<ADOParameter>(rhs){} + WpADOParameter& operator=(const WpADOParameter& rhs) + {WpOLEBase<ADOParameter>::operator=(rhs); return *this;} + + + OUString GetName() const ; + DataTypeEnum GetADOType() const ; + void put_Type(const DataTypeEnum& _eType); + bool put_Size(sal_Int32 _nSize); + sal_Int32 GetAttributes() const ; + sal_Int32 GetPrecision() const ; + sal_Int32 GetNumericScale() const ; + ParameterDirectionEnum get_Direction() const; + void GetValue(OLEVariant& aValVar) const ; + OLEVariant GetValue() const; + bool PutValue(const OLEVariant& aVariant); + bool AppendChunk(const OLEVariant& aVariant); + }; + + class OTools + { + public: + /** putValue set the property value at the ado column + @param _rProps the properties where to set + @param _aPosition which property to set + @param _aValVar the value to set + */ + static void putValue(const WpADOProperties& _rProps,const OLEVariant &_aPosition,const OLEVariant &_aValVar); + + /** getValue returns a specific property value + @param _rProps the properties where to set + @param _aPosition the property + + @return the property value + */ + static OLEVariant getValue(const WpADOProperties& _rProps,const OLEVariant &_aPosition); + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/Awrapadox.hxx b/connectivity/source/inc/ado/Awrapadox.hxx new file mode 100644 index 0000000000..ba91422a1d --- /dev/null +++ b/connectivity/source/inc/ado/Awrapadox.hxx @@ -0,0 +1,139 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sal/config.h> + +#include <string_view> + +#include <com/sun/star/beans/PropertyAttribute.hpp> + +#ifndef __User_FWD_DEFINED__ +#define __User_FWD_DEFINED__ +typedef struct _ADOUser User; +#endif + +#ifndef __Group_FWD_DEFINED__ +#define __Group_FWD_DEFINED__ +typedef struct _ADOGroup Group; +#endif + +#ifndef __Column_FWD_DEFINED__ +#define __Column_FWD_DEFINED__ +typedef struct _ADOColumn Column; +#endif + +#ifndef __Index_FWD_DEFINED__ +#define __Index_FWD_DEFINED__ +typedef struct _ADOIndex Index; +#endif + +#ifndef __Key_FWD_DEFINED__ +#define __Key_FWD_DEFINED__ +typedef struct _ADOKey Key; +#endif + +#ifndef __Table_FWD_DEFINED__ +#define __Table_FWD_DEFINED__ +typedef struct _ADOTable Table; +#endif + + +#include <adoint.h> +#include <adoctint.h> + + +#include <ado/Aolewrap.hxx> +#include <ado/Aolevariant.hxx> +#include <ado/adoimp.hxx> +#include <ado/Awrapado.hxx> +#include <ado/WrapColumn.hxx> +#include <ado/WrapIndex.hxx> +#include <ado/WrapKey.hxx> +#include <ado/WrapTable.hxx> +#include <ado/WrapCatalog.hxx> + +namespace connectivity::ado +{ + class WpADOView : public WpOLEBase<ADOView> + { + public: + WpADOView(ADOView* pInt=nullptr) : WpOLEBase<ADOView>(pInt){} + WpADOView(const WpADOView& rhs) : WpOLEBase<ADOView>(rhs) {} + + WpADOView& operator=(const WpADOView& rhs) + {WpOLEBase<ADOView>::operator=(rhs); return *this;} + + OUString get_Name() const; + void get_Command(OLEVariant& _rVar) const; + void put_Command(OLEVariant const & _rVar); + }; + + class WpADOGroup : public WpOLEBase<ADOGroup> + { + public: + WpADOGroup() = default; + WpADOGroup(const WpADOGroup& rhs) : WpOLEBase<ADOGroup>(rhs) {} + + WpADOGroup& operator=(const WpADOGroup& rhs) + {WpOLEBase<ADOGroup>::operator=(rhs); return *this;} + + void Create(); + + OUString get_Name() const; + void put_Name(std::u16string_view _rName); + RightsEnum GetPermissions( + /* [in] */ const OLEVariant& Name, + /* [in] */ ObjectTypeEnum ObjectType); + bool SetPermissions( + /* [in] */ const OLEVariant& Name, + /* [in] */ ObjectTypeEnum ObjectType, + /* [in] */ ActionEnum Action, + /* [in] */ RightsEnum Rights); + WpADOUsers get_Users( ); + }; + + class WpADOUser : public WpOLEBase<_ADOUser> + { + public: + WpADOUser() = default; + WpADOUser(const WpADOUser& rhs) : WpOLEBase<_ADOUser>(rhs) {} + + WpADOUser& operator=(const WpADOUser& rhs) + {WpOLEBase<_ADOUser>::operator=(rhs); return *this;} + + void Create(); + + OUString get_Name() const; + void put_Name(std::u16string_view _rName); + bool ChangePassword(std::u16string_view _rPwd,std::u16string_view _rNewPwd); + WpADOGroups get_Groups(); + RightsEnum GetPermissions( + /* [in] */ const OLEVariant& Name, + /* [in] */ ObjectTypeEnum ObjectType); + bool SetPermissions( + /* [in] */ const OLEVariant& Name, + /* [in] */ ObjectTypeEnum ObjectType, + /* [in] */ ActionEnum Action, + /* [in] */ RightsEnum Rights); + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/WrapCatalog.hxx b/connectivity/source/inc/ado/WrapCatalog.hxx new file mode 100644 index 0000000000..0bcff441c2 --- /dev/null +++ b/connectivity/source/inc/ado/WrapCatalog.hxx @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <sal/config.h> + +#include <string_view> + +#include <ado/WrapTypeDefs.hxx> + +namespace connectivity::ado +{ + class WpADOCatalog : public WpOLEBase<_ADOCatalog> + { + public: + WpADOCatalog(_ADOCatalog* pInt = nullptr) : WpOLEBase<_ADOCatalog>(pInt){} + WpADOCatalog(const WpADOCatalog& rhs) : WpOLEBase<_ADOCatalog>(rhs) {} + + WpADOCatalog& operator=(const WpADOCatalog& rhs) + {WpOLEBase<_ADOCatalog>::operator=(rhs); return *this;} + + OUString GetObjectOwner(std::u16string_view _rName, ObjectTypeEnum _eNum); + + void putref_ActiveConnection(IDispatch* pCon); + WpADOTables get_Tables(); + WpADOViews get_Views(); + WpADOGroups get_Groups(); + WpADOUsers get_Users(); + ADOProcedures* get_Procedures(); + void Create(); + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/WrapColumn.hxx b/connectivity/source/inc/ado/WrapColumn.hxx new file mode 100644 index 0000000000..f1b73585fb --- /dev/null +++ b/connectivity/source/inc/ado/WrapColumn.hxx @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <sal/config.h> + +#include <string_view> + +#include <ado/Aolewrap.hxx> + +#include <adoint.h> + +namespace connectivity::ado +{ + class WpADOColumn : public WpOLEBase<_ADOColumn> + { + public: + WpADOColumn() = default; + WpADOColumn(const WpADOColumn& rhs) : WpOLEBase<_ADOColumn>(rhs) {} + + void Create(); + + WpADOColumn& operator=(const WpADOColumn& rhs) + {WpOLEBase<_ADOColumn>::operator=(rhs); return *this;} + + OUString get_Name() const; + OUString get_RelatedColumn() const; + void put_Name(std::u16string_view _rName); + void put_RelatedColumn(std::u16string_view _rName); + DataTypeEnum get_Type() const; + void put_Type(const DataTypeEnum& _eNum) ; + sal_Int32 get_Precision() const; + void put_Precision(sal_Int32 _nPre) ; + sal_uInt8 get_NumericScale() const; + void put_NumericScale(sal_Int8 _nScale); + SortOrderEnum get_SortOrder() const; + void put_SortOrder(SortOrderEnum _nScale); + sal_Int32 get_DefinedSize() const; + ColumnAttributesEnum get_Attributes() const; + bool put_Attributes(const ColumnAttributesEnum& _eNum); + WpADOProperties get_Properties() const; + void put_ParentCatalog(/* [in] */ _ADOCatalog __RPC_FAR *ppvObject); + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/WrapIndex.hxx b/connectivity/source/inc/ado/WrapIndex.hxx new file mode 100644 index 0000000000..4444bb340a --- /dev/null +++ b/connectivity/source/inc/ado/WrapIndex.hxx @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <sal/config.h> + +#include <string_view> + +#include <ado/WrapTypeDefs.hxx> + +namespace connectivity::ado +{ + class WpADOIndex : public WpOLEBase<_ADOIndex> + { + public: + WpADOIndex() = default; + WpADOIndex(const WpADOIndex& rhs) : WpOLEBase<_ADOIndex>(rhs) {} + + WpADOIndex& operator=(const WpADOIndex& rhs) + {WpOLEBase<_ADOIndex>::operator=(rhs); return *this;} + + void Create(); + + OUString get_Name() const; + void put_Name(std::u16string_view _rName); + bool get_Clustered() const; + void put_Clustered(bool _b); + bool get_Unique() const; + void put_Unique(bool _b); + bool get_PrimaryKey() const; + void put_PrimaryKey(bool _b); + WpADOColumns get_Columns() const; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/WrapKey.hxx b/connectivity/source/inc/ado/WrapKey.hxx new file mode 100644 index 0000000000..1f984445b8 --- /dev/null +++ b/connectivity/source/inc/ado/WrapKey.hxx @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <sal/config.h> + +#include <string_view> + +#include <ado/WrapTypeDefs.hxx> + +namespace connectivity::ado +{ + class WpADOKey : public WpOLEBase<ADOKey> + { + public: + WpADOKey() = default; + WpADOKey(const WpADOKey& rhs) : WpOLEBase<ADOKey>(rhs) {} + + WpADOKey& operator=(const WpADOKey& rhs) + {WpOLEBase<ADOKey>::operator=(rhs); return *this;} + + void Create(); + + OUString get_Name() const; + void put_Name(std::u16string_view _rName); + KeyTypeEnum get_Type() const; + void put_Type(const KeyTypeEnum& _eNum) ; + OUString get_RelatedTable() const; + void put_RelatedTable(std::u16string_view _rName); + RuleEnum get_DeleteRule() const; + void put_DeleteRule(const RuleEnum& _eNum) ; + RuleEnum get_UpdateRule() const; + void put_UpdateRule(const RuleEnum& _eNum) ; + WpADOColumns get_Columns() const; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/WrapTable.hxx b/connectivity/source/inc/ado/WrapTable.hxx new file mode 100644 index 0000000000..dc06dbc03a --- /dev/null +++ b/connectivity/source/inc/ado/WrapTable.hxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <sal/config.h> + +#include <string_view> + +#include <ado/WrapTypeDefs.hxx> + +namespace connectivity::ado +{ + class WpADOCatalog; + + class WpADOTable : public WpOLEBase<_ADOTable> + { + public: + WpADOTable() = default; + WpADOTable(const WpADOTable& rhs) : WpOLEBase<_ADOTable>(rhs) {} + + WpADOTable& operator=(const WpADOTable& rhs) + {WpOLEBase<_ADOTable>::operator=(rhs); return *this;} + + void Create(); + + OUString get_Name() const; + void put_Name(std::u16string_view _rName); + OUString get_Type() const; + WpADOColumns get_Columns() const; + WpADOIndexes get_Indexes() const; + WpADOKeys get_Keys() const; + WpADOCatalog get_ParentCatalog() const; + WpADOProperties get_Properties() const; + void putref_ParentCatalog(/* [in] */ _ADOCatalog __RPC_FAR *ppvObject); + }; + + + typedef WpOLEAppendCollection<ADOTables, WpADOTable> WpADOTables; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/WrapTypeDefs.hxx b/connectivity/source/inc/ado/WrapTypeDefs.hxx new file mode 100644 index 0000000000..91bea84534 --- /dev/null +++ b/connectivity/source/inc/ado/WrapTypeDefs.hxx @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + + +namespace connectivity::ado +{ + class WpADOTable; + class WpADOKey; + class WpADOIndex; + class WpADOColumn; + class WpADOGroup; + class WpADOView; + class WpADOUser; + + typedef WpOLEAppendCollection<ADOTables, WpADOTable> WpADOTables; + typedef WpOLEAppendCollection<ADOKeys, WpADOKey> WpADOKeys; + typedef WpOLEAppendCollection<ADOIndexes, WpADOIndex> WpADOIndexes; + typedef WpOLEAppendCollection<ADOColumns, WpADOColumn> WpADOColumns; + typedef WpOLEAppendCollection<ADOGroups, WpADOGroup> WpADOGroups; + typedef WpOLEAppendCollection<ADOViews, WpADOView> WpADOViews; + typedef WpOLEAppendCollection<ADOUsers, WpADOUser> WpADOUsers; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/adoimp.hxx b/connectivity/source/inc/ado/adoimp.hxx new file mode 100644 index 0000000000..60c6fd313d --- /dev/null +++ b/connectivity/source/inc/ado/adoimp.hxx @@ -0,0 +1,103 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <com/sun/star/sdbc/SQLException.hpp> + +#include <adoctint.h> + +struct ADOConnection; + +namespace sal::systools { class BStr; }; + +namespace connectivity::ado +{ + + class WpADOField; + class ADOS + { + public: + // Also here: Free BSTR with SysFreeString()! + static sal::systools::BStr& GetKeyStr(); + + static const CLSID CLSID_ADOCATALOG_25; + static const IID IID_ADOCATALOG_25; + + static const CLSID CLSID_ADOCONNECTION_21; + static const IID IID_ADOCONNECTION_21; + + static const CLSID CLSID_ADOCOMMAND_21; + static const IID IID_ADOCOMMAND_21; + + static const CLSID CLSID_ADORECORDSET_21; + static const IID IID_ADORECORDSET_21; + + static const CLSID CLSID_ADOINDEX_25; + static const IID IID_ADOINDEX_25; + + static const CLSID CLSID_ADOCOLUMN_25; + static const IID IID_ADOCOLUMN_25; + + static const CLSID CLSID_ADOKEY_25; + static const IID IID_ADOKEY_25; + + static const CLSID CLSID_ADOTABLE_25; + static const IID IID_ADOTABLE_25; + + static const CLSID CLSID_ADOGROUP_25; + static const IID IID_ADOGROUP_25; + + static const CLSID CLSID_ADOUSER_25; + static const IID IID_ADOUSER_25; + + static const CLSID CLSID_ADOVIEW_25; + static const IID IID_ADOVIEW_25; + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + static void ThrowException(ADOConnection* _pAdoCon,const css::uno::Reference< css::uno::XInterface >& _xInterface); + static sal_Int32 MapADOType2Jdbc(DataTypeEnum eType); + static DataTypeEnum MapJdbc2ADOType(sal_Int32 _nType,sal_Int32 _nJetEngine); + static bool isJetEngine(sal_Int32 _nEngineType); + + static ObjectTypeEnum mapObjectType2Ado(sal_Int32 objType); + static sal_Int32 mapAdoType2Object(ObjectTypeEnum objType); + static sal_Int32 mapAdoRights2Sdbc(RightsEnum eRights); + static sal_Int32 mapRights2Ado(sal_Int32 nRights); + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + static WpADOField getField(ADORecordset* _pRecordSet,sal_Int32 _nColumnIndex); + }; + + +} + + +#define ADO_PROP(ItemName) \ + WpADOProperty aProp(aProps.GetItem(ItemName)); \ + OLEVariant aVar; \ + if(aProp.IsValid()) \ + aVar = aProp.GetValue(); \ + else \ + ADOS::ThrowException(m_rADOConnection,*this); + + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/calc/CCatalog.hxx b/connectivity/source/inc/calc/CCatalog.hxx new file mode 100644 index 0000000000..466e96ece8 --- /dev/null +++ b/connectivity/source/inc/calc/CCatalog.hxx @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FCatalog.hxx> + +namespace connectivity::calc +{ + class OCalcConnection; + class OCalcCatalog : public file::OFileCatalog + { + public: + virtual void refreshTables() override; + + public: + OCalcCatalog(OCalcConnection* _pCon); + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/calc/CConnection.hxx b/connectivity/source/inc/calc/CConnection.hxx new file mode 100644 index 0000000000..6eabeccef5 --- /dev/null +++ b/connectivity/source/inc/calc/CConnection.hxx @@ -0,0 +1,149 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <memory> +#include <file/FConnection.hxx> +#include <com/sun/star/frame/XDesktop2.hpp> +#include <com/sun/star/frame/XTerminateListener.hpp> +#include <rtl/ref.hxx> +#include <unotools/closeveto.hxx> + +namespace com::sun::star { + namespace sheet { class XSpreadsheetDocument; } +} + +namespace utl { class CloseVeto; } + + +namespace connectivity::calc + { + class ODriver; + class OCalcConnection : public file::OConnection + { + // the spreadsheet document: + css::uno::Reference< css::sheet::XSpreadsheetDocument > m_xDoc; + OUString m_sPassword; + OUString m_aFileName; + oslInterlockedCount m_nDocCount; + + class CloseVetoButTerminateListener : public cppu::WeakComponentImplHelper<css::frame::XTerminateListener> + { + private: + /// close listener that vetoes so nobody else disposes m_xDoc + std::unique_ptr<utl::CloseVeto> m_pCloseListener; + /// but also listen to XDesktop and if app is terminating anyway, dispose m_xDoc while + /// its still possible to do so properly + css::uno::Reference<css::frame::XDesktop2> m_xDesktop; + osl::Mutex m_aMutex; + public: + CloseVetoButTerminateListener() + : cppu::WeakComponentImplHelper<css::frame::XTerminateListener>(m_aMutex) + { + } + + void start(const css::uno::Reference<css::uno::XInterface>& rCloseable, + const css::uno::Reference<css::frame::XDesktop2>& rDesktop) + { + m_xDesktop = rDesktop; + m_xDesktop->addTerminateListener(this); + m_pCloseListener.reset(new utl::CloseVeto(rCloseable, true)); + } + + void stop() + { + m_pCloseListener.reset(); + if (!m_xDesktop.is()) + return; + m_xDesktop->removeTerminateListener(this); + m_xDesktop.clear(); + } + + // XTerminateListener + virtual void SAL_CALL queryTermination(const css::lang::EventObject& /*rEvent*/) override + { + } + + virtual void SAL_CALL notifyTermination(const css::lang::EventObject& /*rEvent*/) override + { + stop(); + } + + virtual void SAL_CALL disposing() override + { + stop(); + cppu::WeakComponentImplHelperBase::disposing(); + } + + virtual void SAL_CALL disposing(const css::lang::EventObject& rEvent) override + { + const bool bShutDown = (rEvent.Source == m_xDesktop); + if (bShutDown) + stop(); + } + }; + + rtl::Reference<CloseVetoButTerminateListener> m_xCloseVetoButTerminateListener; + + public: + OCalcConnection(ODriver* _pDriver); + virtual ~OCalcConnection() override; + + virtual void construct(const OUString& _rUrl, + const css::uno::Sequence< css::beans::PropertyValue >& _rInfo ) override; + + // XServiceInfo + DECLARE_SERVICE_INFO(); + + // OComponentHelper + virtual void SAL_CALL disposing() override; + + // XConnection + virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( ) override; + virtual css::uno::Reference< css::sdbcx::XTablesSupplier > createCatalog() override; + virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement( ) override; + virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const OUString& sql ) override; + virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall( const OUString& sql ) override; + + // no interface methods + css::uno::Reference< css::sheet::XSpreadsheetDocument> const & acquireDoc(); + void releaseDoc(); + + class ODocHolder + { + OCalcConnection* m_pConnection; + css::uno::Reference< css::sheet::XSpreadsheetDocument> m_xDoc; + public: + ODocHolder(OCalcConnection* _pConnection) : m_pConnection(_pConnection) + { + m_xDoc = m_pConnection->acquireDoc(); + } + ~ODocHolder() + { + m_xDoc.clear(); + m_pConnection->releaseDoc(); + } + const css::uno::Reference< css::sheet::XSpreadsheetDocument>& getDoc() const { return m_xDoc; } + }; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/calc/CDatabaseMetaData.hxx b/connectivity/source/inc/calc/CDatabaseMetaData.hxx new file mode 100644 index 0000000000..61f9f6aa7e --- /dev/null +++ b/connectivity/source/inc/calc/CDatabaseMetaData.hxx @@ -0,0 +1,42 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <component/CDatabaseMetaData.hxx> + +namespace connectivity::calc + { + + //************ Class: java.sql.DatabaseMetaDataDate + + + class OCalcDatabaseMetaData : public component::OComponentDatabaseMetaData + { + virtual OUString SAL_CALL getURL( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTables( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern, const css::uno::Sequence< OUString >& types ) override; + protected: + virtual ~OCalcDatabaseMetaData() override; + public: + OCalcDatabaseMetaData(file::OConnection* _pCon); + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/calc/CDriver.hxx b/connectivity/source/inc/calc/CDriver.hxx new file mode 100644 index 0000000000..99200d23ee --- /dev/null +++ b/connectivity/source/inc/calc/CDriver.hxx @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FDriver.hxx> + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +namespace connectivity::calc + { + /// @throws css::uno::Exception + css::uno::Reference< css::uno::XInterface > + ODriver_CreateInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory); + + class ODriver : public file::OFileDriver + { + public: + ODriver(const css::uno::Reference< + css::uno::XComponentContext >& _rxContext) : + file::OFileDriver(_rxContext) {} + + OUString SAL_CALL getImplementationName( ) override; + + // XDriver + virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL + connect( const OUString& url, const css::uno::Sequence< + css::beans::PropertyValue >& info ) override; + virtual sal_Bool SAL_CALL acceptsURL( const OUString& url ) override; + virtual css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/calc/CTable.hxx b/connectivity/source/inc/calc/CTable.hxx new file mode 100644 index 0000000000..b4751fd876 --- /dev/null +++ b/connectivity/source/inc/calc/CTable.hxx @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <component/CTable.hxx> +#include <tools/date.hxx> + +namespace com::sun::star::sheet { + class XSpreadsheet; +} + +namespace com::sun::star::util { + class XNumberFormats; +} + + +namespace connectivity::calc + { + typedef component::OComponentTable OCalcTable_BASE; + class OCalcConnection; + + class OCalcTable : public OCalcTable_BASE + { + private: + std::vector<sal_Int32> m_aTypes; // holds all type for columns just to avoid to ask the propertyset + css::uno::Reference< css::sheet::XSpreadsheet > m_xSheet; + OCalcConnection* m_pCalcConnection; + sal_Int32 m_nStartCol; + sal_Int32 m_nStartRow; + sal_Int32 m_nDataCols; + bool m_bHasHeaders; + css::uno::Reference< css::util::XNumberFormats > m_xFormats; + ::Date m_aNullDate; + + void fillColumns(); + + public: + OCalcTable( sdbcx::OCollection* _pTables,OCalcConnection* _pConnection, + const OUString& Name, + const OUString& Type, + const OUString& Description = OUString(), + const OUString& SchemaName = OUString(), + const OUString& CatalogName = OUString() + ); + + virtual bool fetchRow(OValueRefRow& _rRow, const OSQLColumns& _rCols, bool bRetrieveData) override; + + virtual void SAL_CALL disposing() override; + + void construct() override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/calc/CTables.hxx b/connectivity/source/inc/calc/CTables.hxx new file mode 100644 index 0000000000..0b88592a2e --- /dev/null +++ b/connectivity/source/inc/calc/CTables.hxx @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FTables.hxx> + +namespace connectivity::calc + { + typedef file::OTables OCalcTables_BASE; + + class OCalcTables : public OCalcTables_BASE + { + protected: + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + public: + OCalcTables(const css::uno::Reference< css::sdbc::XDatabaseMetaData >& _rMetaData,::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector) : OCalcTables_BASE(_rMetaData,_rParent,_rMutex,_rVector) + {} + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/component/CColumns.hxx b/connectivity/source/inc/component/CColumns.hxx new file mode 100644 index 0000000000..a63cae4bde --- /dev/null +++ b/connectivity/source/inc/component/CColumns.hxx @@ -0,0 +1,42 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FColumns.hxx> + +namespace connectivity::component + { + /// Columns implementation for Writer tables and Calc sheets. + class OComponentColumns : public file::OColumns + { + protected: + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + public: + OComponentColumns(file::OFileTable* _pTable, + ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector + ) : file::OColumns(_pTable,_rMutex,_rVector) + {} + + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/component/CDatabaseMetaData.hxx b/connectivity/source/inc/component/CDatabaseMetaData.hxx new file mode 100644 index 0000000000..c4721ecadb --- /dev/null +++ b/connectivity/source/inc/component/CDatabaseMetaData.hxx @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FDatabaseMetaData.hxx> + +namespace connectivity::component + { + + //************ Class: java.sql.DatabaseMetaDataDate + + + class OOO_DLLPUBLIC_FILE OComponentDatabaseMetaData : public file::ODatabaseMetaData + { + virtual css::uno::Reference< css::sdbc::XResultSet > impl_getTypeInfo_throw() override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getColumns( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern, const OUString& columnNamePattern ) override; + virtual sal_Int32 SAL_CALL getMaxBinaryLiteralLength( ) override; + virtual sal_Int32 SAL_CALL getMaxCharLiteralLength( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInIndex( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInTable( ) override; + protected: + virtual ~OComponentDatabaseMetaData() override; + public: + OComponentDatabaseMetaData(file::OConnection* _pCon); + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/component/CPreparedStatement.hxx b/connectivity/source/inc/component/CPreparedStatement.hxx new file mode 100644 index 0000000000..d39a3edad1 --- /dev/null +++ b/connectivity/source/inc/component/CPreparedStatement.hxx @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FPreparedStatement.hxx> + +namespace connectivity::component + { + class OConnection; + /// Prepared statement implementation for Writer tables and Calc sheets. + class OOO_DLLPUBLIC_FILE OComponentPreparedStatement : public file::OPreparedStatement + { + protected: + virtual rtl::Reference<file::OResultSet> createResultSet() override; + public: + OComponentPreparedStatement( file::OConnection* _pConnection) : file::OPreparedStatement( _pConnection){} + DECLARE_SERVICE_INFO(); + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/component/CResultSet.hxx b/connectivity/source/inc/component/CResultSet.hxx new file mode 100644 index 0000000000..4874f22151 --- /dev/null +++ b/connectivity/source/inc/component/CResultSet.hxx @@ -0,0 +1,79 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <file/FResultSet.hxx> +#include <com/sun/star/sdbcx/XRowLocate.hpp> +#include <com/sun/star/sdbcx/XDeleteRows.hpp> +#include <cppuhelper/implbase2.hxx> + +namespace connectivity::component + { + class OComponentResultSet; + // these typedef's are only necessary for the compiler + typedef ::cppu::ImplHelper2< css::sdbcx::XRowLocate, + css::sdbcx::XDeleteRows> OComponentResultSet_BASE; + typedef file::OResultSet OComponentResultSet_BASE2; + typedef ::comphelper::OPropertyArrayUsageHelper<OComponentResultSet> OComponentResultSet_BASE3; + + + /// ResultSet implementation for Writer tables and Calc sheets. + class OComponentResultSet : public OComponentResultSet_BASE2, + public OComponentResultSet_BASE, + public OComponentResultSet_BASE3 + { + bool m_bBookmarkable; + protected: + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const override; + // OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + virtual bool fillIndexValues(const css::uno::Reference< css::sdbcx::XColumnsSupplier> &_xIndex) override; + public: + DECLARE_SERVICE_INFO(); + + OComponentResultSet( file::OStatement_Base* pStmt,connectivity::OSQLParseTreeIterator& _aSQLIterator); + + private: + // XInterface + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + // XPropertySet + virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; + + // XRowLocate + virtual css::uno::Any SAL_CALL getBookmark( ) override; + virtual sal_Bool SAL_CALL moveToBookmark( const css::uno::Any& bookmark ) override; + virtual sal_Bool SAL_CALL moveRelativeToBookmark( const css::uno::Any& bookmark, sal_Int32 rows ) override; + virtual sal_Int32 SAL_CALL compareBookmarks( const css::uno::Any& first, const css::uno::Any& second ) override; + virtual sal_Bool SAL_CALL hasOrderedBookmarks( ) override; + virtual sal_Int32 SAL_CALL hashBookmark( const css::uno::Any& bookmark ) override; + // XDeleteRows + virtual css::uno::Sequence< sal_Int32 > SAL_CALL deleteRows( const css::uno::Sequence< css::uno::Any >& rows ) override; + + virtual bool isRowDeleted() const override { return false; } + + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/component/CStatement.hxx b/connectivity/source/inc/component/CStatement.hxx new file mode 100644 index 0000000000..10346e7c85 --- /dev/null +++ b/connectivity/source/inc/component/CStatement.hxx @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FStatement.hxx> + +namespace connectivity::component + { + class OConnection; + /// Statement implementation for Writer tables and Calc sheets. + class OOO_DLLPUBLIC_FILE OComponentStatement : public file::OStatement + { + protected: + virtual rtl::Reference<file::OResultSet> createResultSet() override; + public: + OComponentStatement( file::OConnection* _pConnection) : file::OStatement( _pConnection){} + DECLARE_SERVICE_INFO(); + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/component/CTable.hxx b/connectivity/source/inc/component/CTable.hxx new file mode 100644 index 0000000000..3ace6f922a --- /dev/null +++ b/connectivity/source/inc/component/CTable.hxx @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FTable.hxx> + +namespace com::sun::star::sheet { + class XSpreadsheet; +} + +namespace com::sun::star::util { + class XNumberFormats; +} + + +namespace connectivity::component + { + typedef file::OFileTable OComponentTable_BASE; + + /// Shared Table base class for Writer tables and Calc sheets. + class OOO_DLLPUBLIC_FILE OComponentTable : public OComponentTable_BASE + { + protected: + sal_Int32 m_nDataRows; + + virtual void FileClose() override; + public: + OComponentTable( sdbcx::OCollection* _pTables,file::OConnection* _pConnection, + const OUString& Name, + const OUString& Type, + const OUString& Description, + const OUString& SchemaName, + const OUString& CatalogName + ); + + virtual void refreshColumns() override; + virtual void refreshIndexes() override; + + virtual sal_Int32 getCurrentLastPos() const override; + virtual bool seekRow(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOffset, sal_Int32& nCurPos) override; + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DCatalog.hxx b/connectivity/source/inc/dbase/DCatalog.hxx new file mode 100644 index 0000000000..f8954d0122 --- /dev/null +++ b/connectivity/source/inc/dbase/DCatalog.hxx @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FCatalog.hxx> + +namespace connectivity::dbase + { + class ODbaseConnection; + class ODbaseCatalog : public file::OFileCatalog + { + public: + virtual void refreshTables() override; + + public: + ODbaseCatalog(ODbaseConnection* _pCon); + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DColumns.hxx b/connectivity/source/inc/dbase/DColumns.hxx new file mode 100644 index 0000000000..dbbbbec90a --- /dev/null +++ b/connectivity/source/inc/dbase/DColumns.hxx @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FColumns.hxx> + +namespace connectivity::dbase + { + class ODbaseColumns : public file::OColumns + { + protected: + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void dropObject(sal_Int32 _nPos, const OUString& _sElementName) override; + public: + ODbaseColumns(file::OFileTable* _pTable, + ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector + ) : file::OColumns(_pTable,_rMutex,_rVector) + {} + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DConnection.hxx b/connectivity/source/inc/dbase/DConnection.hxx new file mode 100644 index 0000000000..864e9a22c8 --- /dev/null +++ b/connectivity/source/inc/dbase/DConnection.hxx @@ -0,0 +1,46 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FConnection.hxx> + +namespace connectivity::dbase + { + class ODriver; + class ODbaseConnection : public file::OConnection + { + protected: + virtual ~ODbaseConnection() override; + public: + ODbaseConnection(ODriver* _pDriver); + // XServiceInfo + DECLARE_SERVICE_INFO(); + + // XConnection + virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( ) override; + virtual css::uno::Reference< css::sdbcx::XTablesSupplier > createCatalog() override; + virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement( ) override; + virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const OUString& sql ) override; + virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall( const OUString& sql ) override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DDatabaseMetaData.hxx b/connectivity/source/inc/dbase/DDatabaseMetaData.hxx new file mode 100644 index 0000000000..fed3fcc70e --- /dev/null +++ b/connectivity/source/inc/dbase/DDatabaseMetaData.hxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FDatabaseMetaData.hxx> + +namespace connectivity::dbase + { + + //************ Class: java.sql.DatabaseMetaDataDate + + + class ODbaseDatabaseMetaData : public file::ODatabaseMetaData + { + virtual css::uno::Reference< css::sdbc::XResultSet > impl_getTypeInfo_throw() override; + virtual sal_Bool SAL_CALL isReadOnly( ) override; + virtual OUString SAL_CALL getURL( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getColumns( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern, const OUString& columnNamePattern ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getIndexInfo( const css::uno::Any& catalog, const OUString& schema, const OUString& table, sal_Bool unique, sal_Bool approximate ) override; + + virtual sal_Int32 SAL_CALL getMaxBinaryLiteralLength( ) override; + virtual sal_Int32 SAL_CALL getMaxCharLiteralLength( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInIndex( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInTable( ) override; + + virtual sal_Bool SAL_CALL supportsAlterTableWithAddColumn( ) override; + virtual sal_Bool SAL_CALL supportsAlterTableWithDropColumn( ) override; + + virtual bool impl_storesMixedCaseQuotedIdentifiers_throw( ) override; + virtual bool impl_supportsMixedCaseQuotedIdentifiers_throw( ) override; + protected: + virtual ~ODbaseDatabaseMetaData() override; + public: + ODbaseDatabaseMetaData(file::OConnection* _pCon); + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DDriver.hxx b/connectivity/source/inc/dbase/DDriver.hxx new file mode 100644 index 0000000000..310f9b1dc8 --- /dev/null +++ b/connectivity/source/inc/dbase/DDriver.hxx @@ -0,0 +1,46 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <connectivity/CommonTools.hxx> +#include <file/FDriver.hxx> + +namespace connectivity::dbase + { + /// @throws css::uno::Exception + css::uno::Reference< css::uno::XInterface > ODriver_CreateInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory); + + class ODriver : public file::OFileDriver + { + public: + ODriver(const css::uno::Reference< css::uno::XComponentContext >& _rxContext) : file::OFileDriver(_rxContext){} + + OUString SAL_CALL getImplementationName( ) override; + + // XDriver + virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL connect( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + virtual sal_Bool SAL_CALL acceptsURL( const OUString& url ) override; + virtual css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DIndex.hxx b/connectivity/source/inc/dbase/DIndex.hxx new file mode 100644 index 0000000000..3cc7da9ad1 --- /dev/null +++ b/connectivity/source/inc/dbase/DIndex.hxx @@ -0,0 +1,135 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sdbcx/VIndex.hxx> +#include <dbase/DTable.hxx> +#include <dbase/dindexnode.hxx> + +inline constexpr OString dBASE_III_GROUP = "dBase III"_ostr; + +namespace connectivity::dbase + { + class OIndexIterator; + class ONDXKey; + + typedef sdbcx::OIndex ODbaseIndex_BASE; + + class ODbaseIndex : public ODbaseIndex_BASE + { + friend SvStream& WriteODbaseIndex(SvStream &rStream, const ODbaseIndex&); + friend SvStream& operator >> (SvStream &rStream, ODbaseIndex&); + + friend class ONDXNode; + friend class ONDXPage; + friend class ONDXPagePtr; + friend class OIndexIterator; + + public: + + // Header struct - stays in memory + + struct NDXHeader + { + sal_uInt32 db_rootpage; /* Rootpage position */ + sal_uInt32 db_pagecount; /* Page count */ + sal_uInt8 db_free[4]; /* Reserved */ + sal_uInt16 db_keylen; /* Key length */ + sal_uInt16 db_maxkeys; /* Maximum number of keys per page */ + sal_uInt16 db_keytype; /* Type of key: + 0 = Text + 1 = Numerical */ + sal_uInt16 db_keyrec; /* Length of an index record + RecordNumber + keylen */ + sal_uInt8 db_free1[3]; /* Reserved */ + sal_uInt8 db_unique; /* Unique */ + char db_name[488]; /* index_name (field name) */ + }; + + private: + std::unique_ptr<SvStream> m_pFileStream; // Stream to read/write the index + NDXHeader m_aHeader = {}; + std::vector<ONDXPage*> + m_aCollector; // Pool of obsolete pages + ONDXPagePtr m_aRoot, // Root of the B+ tree + m_aCurLeaf; // Current leaf + sal_uInt16 m_nCurNode; // Position of the current node + + sal_uInt32 m_nPageCount, + m_nRootPage; + + ODbaseTable* m_pTable; + bool m_bUseCollector : 1; // Use the Garbage Collector + + OUString getCompletePath() const; + void closeImpl(); + // Closes and kills the index file and throws an error + void impl_killFileAndthrowError_throw(TranslateId pErrorId, const OUString& _sFile); + protected: + virtual ~ODbaseIndex() override; + public: + ODbaseIndex(ODbaseTable* _pTable); + ODbaseIndex(ODbaseTable* _pTable,const NDXHeader& _aHeader,const OUString& Name); + + void openIndexFile(); + virtual void refreshColumns() override; + + const ODbaseTable* getTable() const { return m_pTable; } + const NDXHeader& getHeader() const { return m_aHeader; } + std::unique_ptr<OIndexIterator> createIterator(); + + void SetRootPos(sal_uInt32 nPos) {m_nRootPage = nPos;} + void SetPageCount(sal_uInt32 nCount) {m_nPageCount = nCount;} + + sal_uInt32 GetPageCount() const {return m_nPageCount;} + + sal_uInt16 GetMaxNodes() const {return m_aHeader.db_maxkeys;} + + bool Insert(sal_uInt32 nRec, const ORowSetValue& rValue); + bool Update(sal_uInt32 nRec, const ORowSetValue&, const ORowSetValue&); + bool Delete(sal_uInt32 nRec, const ORowSetValue& rValue); + bool Find(sal_uInt32 nRec, const ORowSetValue& rValue); + + void createINFEntry(); + void CreateImpl(); + void DropImpl(); + + DECLARE_SERVICE_INFO(); + protected: + + ONDXPage* CreatePage(sal_uInt32 nPagePos, ONDXPage* pParent = nullptr, bool bLoad = false); + void Collect(ONDXPage*); + ONDXPagePtr const & getRoot(); + + bool isUnique() const { return m_IsUnique; } + bool UseCollector() const {return m_bUseCollector;} + // Tree operations + void Release(bool bSave = true); + bool ConvertToKey(ONDXKey* rKey, sal_uInt32 nRec, const ORowSetValue& rValue); + }; + + SvStream& WriteODbaseIndex(SvStream &rStream, const ODbaseIndex&); + SvStream& operator >> (SvStream &rStream, ODbaseIndex&); + + void ReadHeader(SvStream & rStream, ODbaseIndex::NDXHeader & rHeader); +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DIndexColumns.hxx b/connectivity/source/inc/dbase/DIndexColumns.hxx new file mode 100644 index 0000000000..8f7a895b95 --- /dev/null +++ b/connectivity/source/inc/dbase/DIndexColumns.hxx @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <connectivity/sdbcx/VCollection.hxx> +#include <dbase/DIndex.hxx> +#include <dbase/DTable.hxx> + +namespace connectivity::dbase + { + class ODbaseIndexColumns : public sdbcx::OCollection + { + ODbaseIndex* m_pIndex; + protected: + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + public: + ODbaseIndexColumns( ODbaseIndex* _pIndex, + ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector) + : sdbcx::OCollection(*_pIndex,_pIndex->getTable()->getConnection()->getMetaData()->supportsMixedCaseQuotedIdentifiers(),_rMutex,_rVector) + , m_pIndex(_pIndex) + {} + + }; + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DIndexIter.hxx b/connectivity/source/inc/dbase/DIndexIter.hxx new file mode 100644 index 0000000000..2de327be11 --- /dev/null +++ b/connectivity/source/inc/dbase/DIndexIter.hxx @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/fcode.hxx> +#include <dbase/DIndex.hxx> +#include <dbase/dindexnode.hxx> + +namespace connectivity::dbase + { + + // IndexIterator + + class OIndexIterator final + { + file::OBoolOperator* m_pOperator; + const file::OOperand* m_pOperand; + rtl::Reference<ODbaseIndex> m_xIndex; + ONDXPagePtr m_aRoot, + m_aCurLeaf; + sal_uInt16 m_nCurNode; + + sal_uInt32 Find(bool bFirst); + sal_uInt32 GetCompare(bool bFirst); + sal_uInt32 GetLike(bool bFirst); + sal_uInt32 GetNull(bool bFirst); + sal_uInt32 GetNotNull(bool bFirst); + + ONDXKey* GetFirstKey(ONDXPage* pPage, + const file::OOperand& rKey); + ONDXKey* GetNextKey(); + + public: + OIndexIterator(ODbaseIndex* pInd) + :m_pOperator(nullptr) + ,m_pOperand(nullptr) + ,m_xIndex(pInd) + ,m_nCurNode(NODE_NOTFOUND) + { + } + + ~OIndexIterator(); + sal_uInt32 First(); + sal_uInt32 Next(); + + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DIndexes.hxx b/connectivity/source/inc/dbase/DIndexes.hxx new file mode 100644 index 0000000000..a5b1c27e67 --- /dev/null +++ b/connectivity/source/inc/dbase/DIndexes.hxx @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <connectivity/sdbcx/VCollection.hxx> +#include <dbase/DTable.hxx> + +namespace connectivity::dbase + { + class ODbaseTable; + + typedef sdbcx::OCollection ODbaseIndexes_BASE; + + class ODbaseIndexes : public ODbaseIndexes_BASE + { + ODbaseTable* m_pTable; + protected: + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void dropObject(sal_Int32 _nPos, const OUString& _sElementName) override; + public: + ODbaseIndexes(ODbaseTable* _pTable, ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector) : ODbaseIndexes_BASE(*_pTable,_pTable->getConnection()->getMetaData()->supportsMixedCaseQuotedIdentifiers(),_rMutex,_rVector) + , m_pTable(_pTable) + {} + + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DPreparedStatement.hxx b/connectivity/source/inc/dbase/DPreparedStatement.hxx new file mode 100644 index 0000000000..a2a792f623 --- /dev/null +++ b/connectivity/source/inc/dbase/DPreparedStatement.hxx @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FPreparedStatement.hxx> + +namespace connectivity::dbase + { + class OConnection; + class ODbasePreparedStatement : public file::OPreparedStatement + { + protected: + virtual rtl::Reference<file::OResultSet> createResultSet() override; + public: + ODbasePreparedStatement( file::OConnection* _pConnection) : file::OPreparedStatement( _pConnection){} + DECLARE_SERVICE_INFO(); + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DResultSet.hxx b/connectivity/source/inc/dbase/DResultSet.hxx new file mode 100644 index 0000000000..106a63cbb8 --- /dev/null +++ b/connectivity/source/inc/dbase/DResultSet.hxx @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <file/FResultSet.hxx> +#include <com/sun/star/sdbcx/XRowLocate.hpp> +#include <com/sun/star/sdbcx/XDeleteRows.hpp> +#include <cppuhelper/implbase2.hxx> + +namespace connectivity::dbase + { + class ODbaseResultSet; + // these typedef's are only necessary for the compiler + typedef ::cppu::ImplHelper2< css::sdbcx::XRowLocate, + css::sdbcx::XDeleteRows> ODbaseResultSet_BASE; + typedef file::OResultSet ODbaseResultSet_BASE2; + typedef ::comphelper::OPropertyArrayUsageHelper<ODbaseResultSet> ODbaseResultSet_BASE3; + + + class ODbaseResultSet : public ODbaseResultSet_BASE2, + public ODbaseResultSet_BASE, + public ODbaseResultSet_BASE3 + { + bool m_bBookmarkable; + protected: + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const override; + // OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + virtual bool fillIndexValues(const css::uno::Reference< css::sdbcx::XColumnsSupplier> &_xIndex) override; + public: + DECLARE_SERVICE_INFO(); + + ODbaseResultSet( file::OStatement_Base* pStmt,connectivity::OSQLParseTreeIterator& _aSQLIterator); + + // XInterface + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + // XPropertySet + virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; + + // XRowLocate + virtual css::uno::Any SAL_CALL getBookmark( ) override; + virtual sal_Bool SAL_CALL moveToBookmark( const css::uno::Any& bookmark ) override; + virtual sal_Bool SAL_CALL moveRelativeToBookmark( const css::uno::Any& bookmark, sal_Int32 rows ) override; + virtual sal_Int32 SAL_CALL compareBookmarks( const css::uno::Any& first, const css::uno::Any& second ) override; + virtual sal_Bool SAL_CALL hasOrderedBookmarks( ) override; + virtual sal_Int32 SAL_CALL hashBookmark( const css::uno::Any& bookmark ) override; + // XDeleteRows + virtual css::uno::Sequence< sal_Int32 > SAL_CALL deleteRows( const css::uno::Sequence< css::uno::Any >& rows ) override; + + // own methods + sal_Int32 getCurrentFilePos() const; + + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DStatement.hxx b/connectivity/source/inc/dbase/DStatement.hxx new file mode 100644 index 0000000000..cb4b1d8e4a --- /dev/null +++ b/connectivity/source/inc/dbase/DStatement.hxx @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FStatement.hxx> + +namespace connectivity::dbase + { + class OConnection; + class ODbaseStatement : public file::OStatement + { + protected: + virtual rtl::Reference<file::OResultSet> createResultSet() override; + public: + ODbaseStatement( file::OConnection* _pConnection) : file::OStatement( _pConnection){} + DECLARE_SERVICE_INFO(); + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DTable.hxx b/connectivity/source/inc/dbase/DTable.hxx new file mode 100644 index 0000000000..bb0b6baa5f --- /dev/null +++ b/connectivity/source/inc/dbase/DTable.hxx @@ -0,0 +1,191 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FTable.hxx> +#include <connectivity/CommonTools.hxx> +#include <tools/urlobj.hxx> + + +namespace connectivity::dbase + { + typedef file::OFileTable ODbaseTable_BASE; + class ODbaseConnection; + + class ODbaseTable : public ODbaseTable_BASE + { + // The first byte of a dBase file specifies its type + public: + enum DBFType { dBaseIII = 0x03, + dBaseIV = 0x04, + dBaseV = 0x05, + VisualFoxPro = 0x30, + VisualFoxProAuto = 0x31, // Visual FoxPro with AutoIncrement field + dBaseFS = 0x43, + dBaseFSMemo = 0xB3, + dBaseIIIMemo = 0x83, + dBaseIVMemo = 0x8B, + dBaseIVMemoSQL = 0x8E, + FoxProMemo = 0xF5 + }; + enum DBFMemoType { MemodBaseIII = 0, + MemodBaseIV, + MemoFoxPro + }; + + private: + // sources: https://www.clicketyclick.dk/databases/xbase/format/dbf.html (dBASE III and 5) + // http://www.dbase.com/KnowledgeBase/int/db7_file_fmt.htm (dBASE 7) which is similar at least for this part + struct DBFHeader { // address/pos in trailer + DBFType type; // dBASE/xBASE type, see DBFType 00h + sal_uInt8 dateElems[3]; // Date of last change (YYMMDD) 01h + sal_uInt32 nbRecords; // Number of records 04h + sal_uInt16 headerLength; // 08h + sal_uInt16 recordLength; // Length of 1 record 10h + sal_uInt8 trailer[20]; + // this last field contains these data: + // - reserved:2 bytes:should be filled with 0 12h/0 + // - incomplete transaction:1 byte:dBASE IV 14h/2 + // 00h Transaction ended (or rolled back) + // 01h Transaction started + // - encryptionFlag:1 byte: dBASE IV 15h/3 + // 00h not encrypted + // 01h for encrypted + // - freeRecordThread:4 bytes:reserved for LAN only 16h/4 + // - multiUserdBASE:8 bytes:reserved for multi-user dBASE (dBASE III+) 20h/8 + // - MDXFlag:1 byte:dBASE IV 28h/16 + // 0x01 if a production .MDX file exists for this table + // 0x00 if no .MDX file exists + // - languageDriver:1 byte:codepage (from Foxpro) 29h/17 + // - reserved:2 bytes: should be filled with 0 30h/18 + }; + struct DBFColumn { /* Column descriptors */ + sal_uInt8 db_fnm[11]; /* Field name */ + sal_uInt8 db_typ; /* Field type */ + sal_uInt32 db_adr; /* Field address */ + sal_uInt8 db_flng; /* Field length */ + sal_uInt8 db_dez; /* Decimal places for N */ + sal_uInt8 db_free2[14]; /* Reserved */ + }; + struct DBFMemoHeader + { + DBFMemoType db_typ; /* File type */ + sal_uInt32 db_next; /* Next free block */ + sal_uInt16 db_size; /* Block size: dBase 3 fixed */ + DBFMemoHeader() + : db_typ(MemodBaseIII) + , db_next(0) + , db_size(0) + { + } + }; + + std::vector<sal_Int32> m_aTypes; // holds all types for columns just to avoid to ask the propertyset + std::vector<sal_Int32> m_aPrecisions; // same as above + std::vector<sal_Int32> m_aScales; + std::vector<sal_Int32> m_aRealFieldLengths; + DBFHeader m_aHeader = {}; + DBFMemoHeader m_aMemoHeader; + std::unique_ptr<SvStream> m_pMemoStream; + rtl_TextEncoding m_eEncoding; + + void alterColumn(sal_Int32 index, + const css::uno::Reference< css::beans::XPropertySet>& descriptor , + const css::uno::Reference< css::sdbcx::XDataDescriptorFactory>& xOldColumn ); + void readHeader(); + void fillColumns(); + OUString createTempFile(); + void copyData(ODbaseTable* _pNewTable,sal_Int32 _nPos); + bool CreateFile(const INetURLObject& aFile, bool& bCreateMemo); + bool CreateMemoFile(const INetURLObject& aFile); + bool HasMemoFields() const; + void ReadMemoHeader(); + bool ReadMemo(std::size_t nBlockNo, ORowSetValue& aVariable); + + void WriteMemo(const ORowSetValue& aVariable, std::size_t& rBlockNr); + bool WriteBuffer(); + bool UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRow, const css::uno::Reference< css::container::XIndexAccess>& _xCols, bool bForceAllFields); + css::uno::Reference< css::beans::XPropertySet> isUniqueByColumnName(sal_Int32 _nColumnPos); + bool AllocBuffer(); + + void throwInvalidDbaseFormat(); + /// @throws css::sdbc::SQLException + /// @throws css::container::ElementExistException + /// @throws css::uno::RuntimeException + void renameImpl( const OUString& newName ); + void throwInvalidColumnType(TranslateId pErrorId, const OUString& _sColumnName); + + protected: + virtual void FileClose() override; +// using ::connectivity::sdbcx::OTableDescriptor_BASE::rBHelper; + + public: + virtual void refreshColumns() override; + virtual void refreshIndexes() override; + + public: + ODbaseTable( sdbcx::OCollection* _pTables,ODbaseConnection* _pConnection); + ODbaseTable( sdbcx::OCollection* _pTables,ODbaseConnection* _pConnection, + const OUString& Name, + const OUString& Type, + const OUString& Description = OUString(), + const OUString& SchemaName = OUString(), + const OUString& CatalogName = OUString() + ); + + void construct() override; // can throw any exception + + virtual sal_Int32 getCurrentLastPos() const override; + virtual bool seekRow(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOffset, sal_Int32& nCurPos) override; + virtual bool fetchRow(OValueRefRow& _rRow,const OSQLColumns& _rCols, bool bRetrieveData) override; + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + virtual void SAL_CALL disposing() override; + + // XAlterTable + virtual void SAL_CALL alterColumnByName( const OUString& colName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void SAL_CALL alterColumnByIndex( sal_Int32 index, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + // XRename + virtual void SAL_CALL rename( const OUString& newName ) override; + + bool DropImpl(); + bool CreateImpl(); + + + virtual bool InsertRow(OValueRefVector& rRow, const css::uno::Reference< css::container::XIndexAccess>& _xCols) override; + virtual bool DeleteRow(const OSQLColumns& _rCols) override; + virtual bool UpdateRow(OValueRefVector& rRow, OValueRefRow& pOrgRow,const css::uno::Reference< css::container::XIndexAccess>& _xCols) override; + + virtual void addColumn(const css::uno::Reference< css::beans::XPropertySet>& descriptor) override; + virtual void dropColumn(sal_Int32 _nPos) override; + + static OUString getEntry(file::OConnection const * _pConnection, std::u16string_view _sURL ); + static bool Drop_Static(std::u16string_view _sUrl, bool _bHasMemoFields, sdbcx::OCollection* _pIndexes ); + + virtual void refreshHeader() override; + + virtual css::uno::Reference< css::sdbc::XDatabaseMetaData> getMetaData() const override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DTables.hxx b/connectivity/source/inc/dbase/DTables.hxx new file mode 100644 index 0000000000..c85a1ab3cd --- /dev/null +++ b/connectivity/source/inc/dbase/DTables.hxx @@ -0,0 +1,46 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FTables.hxx> + +namespace connectivity::dbase + { + typedef file::OTables ODbaseTables_BASE; + + class ODbaseTables : public ODbaseTables_BASE + { + protected: + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void dropObject(sal_Int32 _nPos, const OUString& _sElementName) override; + public: + ODbaseTables(const css::uno::Reference< css::sdbc::XDatabaseMetaData >& _rMetaData,::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector) : ODbaseTables_BASE(_rMetaData,_rParent,_rMutex,_rVector) + {} + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/dindexnode.hxx b/connectivity/source/inc/dbase/dindexnode.hxx new file mode 100644 index 0000000000..85666f9e52 --- /dev/null +++ b/connectivity/source/inc/dbase/dindexnode.hxx @@ -0,0 +1,307 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <file/fcode.hxx> +#include <connectivity/FValue.hxx> +#include <memory> + +#define NODE_NOTFOUND 0xFFFF +#define DINDEX_PAGE_SIZE 512 + +class SvStream; + +namespace connectivity::dbase + { + + class ONDXNode; + class ODbaseIndex; + + // Index Key + + typedef file::OOperand ONDXKey_BASE; + class ONDXKey : public ONDXKey_BASE + { + friend class ONDXNode; + sal_uInt32 nRecord; /* Record pointer */ + ORowSetValue xValue; /* Key values */ + + public: + ONDXKey(); + ONDXKey(ORowSetValue aVal, sal_Int32 eType, sal_uInt32 nRec); + ONDXKey(const OUString& aStr, sal_uInt32 nRec); + ONDXKey(double aVal, sal_uInt32 nRec); + + inline ONDXKey(const ONDXKey& rKey); + + inline ONDXKey& operator= (const ONDXKey& rKey); + virtual void setValue(const ORowSetValue& _rVal) override; + + virtual const ORowSetValue& getValue() const override; + + sal_uInt32 GetRecord() const { return nRecord; } + void setRecord(sal_uInt32 _nRec) { nRecord = _nRec; } + void ResetRecord() { nRecord = 0; } + + bool operator == (const ONDXKey& rKey) const; + bool operator != (const ONDXKey& rKey) const; + bool operator < (const ONDXKey& rKey) const; + bool operator <= (const ONDXKey& rKey) const; + bool operator > (const ONDXKey& rKey) const; + + static bool IsText(sal_Int32 eType); + + private: + int Compare(const ONDXKey& rKey) const; + }; + + + class ONDXPage; + + // Index Page Pointer + // This is ref-count pointer class + class ONDXPagePtr + { + friend SvStream& WriteONDXPagePtr(SvStream &rStream, const ONDXPagePtr&); + friend SvStream& operator >> (SvStream &rStream, ONDXPagePtr&); + + ONDXPage* mpPage; + sal_uInt32 nPagePos; // Position in the index file + + public: + ONDXPagePtr(); + ONDXPagePtr(ONDXPagePtr&& rObj) noexcept; + ONDXPagePtr(ONDXPagePtr const & rRef); + ONDXPagePtr(ONDXPage* pRefPage); + ~ONDXPagePtr(); + void Clear(); + ONDXPagePtr& operator=(ONDXPagePtr const & rRef); + ONDXPagePtr& operator=(ONDXPagePtr && rRef); + bool Is() const { return mpPage != nullptr; } + + ONDXPage * operator ->() const { assert(mpPage != nullptr); return mpPage; } + operator ONDXPage *() const { return mpPage; } + + sal_uInt32 GetPagePos() const {return nPagePos;} + bool HasPage() const {return nPagePos != 0;} + }; + + // Index Page + // This is a ref-counted class, with re-cycling + class ONDXPage + { + friend class ODbaseIndex; + friend class ONDXPagePtr; + + friend SvStream& WriteONDXPage(SvStream &rStream, const ONDXPage&); + friend SvStream& operator >> (SvStream &rStream, ONDXPage&); + + // work around a clang 3.5 optimization bug: if the bNoDelete is *first* + // it mis-compiles "if (--nRefCount == 0)" and never deletes any object + unsigned int nRefCount : 31; + // the only reason this is not bool is because MSVC cannot handle mixed type bitfields + unsigned int bNoDelete : 1; + sal_uInt32 nPagePos; // Position in the index file + bool bModified : 1; + sal_uInt16 nCount; + + ONDXPagePtr aParent, // Parent page + aChild; // Pointer to the right child page + ODbaseIndex& rIndex; + std::unique_ptr<ONDXNode[]> + ppNodes; // Array of nodes + + public: + // Node operations + sal_uInt16 Count() const {return nCount;} + + bool Insert(ONDXNode& rNode, sal_uInt32 nRowsLeft = 0); + bool Insert(sal_uInt16 nIndex, ONDXNode& rNode); + bool Append(ONDXNode& rNode); + void Delete(sal_uInt16); + void Remove(sal_uInt16); + void Release(bool bSave = true); + void ReleaseFull(); + + // Split and merge + ONDXNode Split(ONDXPage& rPage); + void Merge(sal_uInt16 nParentNodePos, const ONDXPagePtr& xPage); + + // Access operators + ONDXNode& operator[] (sal_uInt16 nPos); + const ONDXNode& operator[] (sal_uInt16 nPos) const; + + bool IsRoot() const; + bool IsLeaf() const; + bool IsModified() const; + bool HasParent() const; + + bool IsFull() const; + + sal_uInt32 GetPagePos() const {return nPagePos;} + ONDXPagePtr& GetChild(ODbaseIndex const * pIndex = nullptr); + + // Parent does not need to be reloaded + const ONDXPagePtr& GetParent() const; + ODbaseIndex& GetIndex() {return rIndex;} + const ODbaseIndex& GetIndex() const {return rIndex;} + + // Setting the child, via reference to retain the PagePos + void SetChild(ONDXPagePtr aCh); + void SetParent(ONDXPagePtr aPa); + + sal_uInt16 Search(const ONDXKey& rSearch); + sal_uInt16 Search(const ONDXPage* pPage); + void SearchAndReplace(const ONDXKey& rSearch, ONDXKey const & rReplace); + + protected: + ONDXPage(ODbaseIndex& rIndex, sal_uInt32 nPos, ONDXPage*); + ~ONDXPage(); + + void ReleaseRef(); + void QueryDelete(); + void AddNextRef() + { + assert( nRefCount < (1 << 30) && "Do not add refs to dead objects" ); + ++nRefCount; + } + void AddFirstRef() + { + assert( nRefCount < (1 << 30) && "Do not add refs to dead objects" ); + if( bNoDelete ) + bNoDelete = 0; + ++nRefCount; + } + + void SetModified(bool bMod) {bModified = bMod;} + void SetPagePos(sal_uInt32 nPage) {nPagePos = nPage;} + + bool Find(const ONDXKey&); // Descend recursively + sal_uInt16 FindPos(const ONDXKey& rKey) const; + +#if OSL_DEBUG_LEVEL > 1 + void PrintPage(); +#endif + }; + + SvStream& WriteONDXPagePtr(SvStream &rStream, const ONDXPagePtr&); + SvStream& operator >> (SvStream &rStream, ONDXPagePtr&); + + inline bool ONDXPage::IsRoot() const {return !aParent.Is();} + inline bool ONDXPage::IsLeaf() const {return !aChild.HasPage();} + inline bool ONDXPage::IsModified() const {return bModified;} + inline bool ONDXPage::HasParent() const {return aParent.Is();} + inline const ONDXPagePtr& ONDXPage::GetParent() const {return aParent;} + + inline void ONDXPage::SetParent(ONDXPagePtr aPa = ONDXPagePtr()) + { + aParent = aPa; + } + + inline void ONDXPage::SetChild(ONDXPagePtr aCh = ONDXPagePtr()) + { + aChild = aCh; + if (aChild.Is()) + aChild->SetParent(this); + } + SvStream& operator >> (SvStream &rStream, ONDXPage& rPage); + SvStream& WriteONDXPage(SvStream &rStream, const ONDXPage& rPage); + + + // Index Node + + class ONDXNode + { + friend class ONDXPage; + ONDXPagePtr aChild; /* Next page reference */ + ONDXKey aKey; + + public: + ONDXNode(){} + ONDXNode(const ONDXKey& rKey) + :aKey(rKey) {} + + // Does the node point to a page? + bool HasChild() const {return aChild.HasPage();} + // If an index is provided, we may be able to retrieve the page + ONDXPagePtr& GetChild(ODbaseIndex* pIndex = nullptr, ONDXPage* = nullptr); + + const ONDXKey& GetKey() const { return aKey;} + ONDXKey& GetKey() { return aKey;} + + // Setting the child, via reference to retain the PagePos + void SetChild(ONDXPagePtr aCh = ONDXPagePtr(), ONDXPage* = nullptr); + + void Write(SvStream &rStream, const ONDXPage& rPage) const; + void Read(SvStream &rStream, ODbaseIndex const &); + }; + + inline ONDXKey::ONDXKey(const ONDXKey& rKey) + : ONDXKey_BASE(rKey.getDBType()) + ,nRecord(rKey.nRecord) + ,xValue(rKey.xValue) + { + } + + inline ONDXKey& ONDXKey::operator=(const ONDXKey& rKey) + { + if(&rKey == this) + return *this; + + xValue = rKey.xValue; + nRecord = rKey.nRecord; + m_eDBType = rKey.getDBType(); + return *this; + } + + inline bool ONDXKey::operator == (const ONDXKey& rKey) const + { + if(&rKey == this) + return true; + return Compare(rKey) == 0; + } + inline bool ONDXKey::operator != (const ONDXKey& rKey) const + { + return !operator== (rKey); + } + inline bool ONDXKey::operator < (const ONDXKey& rKey) const + { + return Compare(rKey) < 0; + } + inline bool ONDXKey::operator > (const ONDXKey& rKey) const + { + return Compare(rKey) > 0; + } + inline bool ONDXKey::operator <= (const ONDXKey& rKey) const + { + return !operator > (rKey); + } + + inline void ONDXNode::SetChild(ONDXPagePtr aCh, ONDXPage* pParent) + { + aChild = aCh; + if (aChild.Is()) + aChild->SetParent(pParent); + } + +} + + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FCatalog.hxx b/connectivity/source/inc/file/FCatalog.hxx new file mode 100644 index 0000000000..2bcf82df2a --- /dev/null +++ b/connectivity/source/inc/file/FCatalog.hxx @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sdbcx/VCatalog.hxx> + +#include <file/filedllapi.hxx> + +namespace connectivity::file + { + class OConnection; + class OOO_DLLPUBLIC_FILE SAL_NO_VTABLE OFileCatalog : + public connectivity::sdbcx::OCatalog + { + protected: + OConnection* m_pConnection; + + /** builds the name which should be used to access the object later on in the collection. + Will only be called in fillNames. + @param _xRow + The current row from the resultset given to fillNames. + */ + virtual OUString buildName( const css::uno::Reference< css::sdbc::XRow >& _xRow) override; + + public: + virtual void refreshTables() override; + virtual void refreshViews() override; + virtual void refreshGroups() override; + virtual void refreshUsers() override; + + public: + OFileCatalog(OConnection* _pCon); + OConnection* getConnection() { return m_pConnection; } + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + // ::cppu::OComponentHelper + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + virtual void SAL_CALL disposing() override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FColumns.hxx b/connectivity/source/inc/file/FColumns.hxx new file mode 100644 index 0000000000..f5fce16b6f --- /dev/null +++ b/connectivity/source/inc/file/FColumns.hxx @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <connectivity/sdbcx/VCollection.hxx> +#include <com/sun/star/sdbc/XDatabaseMetaData.hpp> +#include <file/FTable.hxx> +#include <file/filedllapi.hxx> + +namespace connectivity::file + { + class OOO_DLLPUBLIC_FILE OColumns : public sdbcx::OCollection + { + protected: + OFileTable* m_pTable; + + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + public: + OColumns( OFileTable* _pTable, + ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector + ) : sdbcx::OCollection(*_pTable,_pTable->getConnection()->getMetaData()->supportsMixedCaseQuotedIdentifiers(),_rMutex,_rVector) + ,m_pTable(_pTable) + {} + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FConnection.hxx b/connectivity/source/inc/file/FConnection.hxx new file mode 100644 index 0000000000..e6412992ab --- /dev/null +++ b/connectivity/source/inc/file/FConnection.hxx @@ -0,0 +1,131 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <com/sun/star/ucb/XContent.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <connectivity/CommonTools.hxx> +#include <rtl/ustring.hxx> +#include <com/sun/star/sdbcx/XTablesSupplier.hpp> +#include <com/sun/star/ucb/XDynamicResultSet.hpp> +#include <TConnection.hxx> +#include <file/filedllapi.hxx> + +namespace connectivity::file + { + class ODatabaseMetaData; + class OFileDriver; + + class OOO_DLLPUBLIC_FILE OConnection : public connectivity::OMetaConnection + { + protected: + + // Data attributes + + css::uno::WeakReference< css::sdbcx::XTablesSupplier> m_xCatalog; + + OUString m_aFilenameExtension; + OFileDriver* m_pDriver; // Pointer to the owning + // driver object + css::uno::Reference< css::ucb::XDynamicResultSet > m_xDir; // directory + css::uno::Reference< css::ucb::XContent> m_xContent; + + bool m_bAutoCommit; + bool m_bReadOnly; + bool m_bShowDeleted; + bool m_bCaseSensitiveExtension; + bool m_bCheckSQL92; + bool m_bDefaultTextEncoding; + + + void throwUrlNotValid(const OUString & _rsUrl,const OUString & _rsMessage); + + virtual ~OConnection() override; + public: + + OConnection(OFileDriver* _pDriver); + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + /// @throws css::uno::DeploymentException + virtual void construct(const OUString& _rUrl, const css::uno::Sequence< css::beans::PropertyValue >& _rInfo ); + + // OComponentHelper + virtual void SAL_CALL disposing() override; + + // XServiceInfo + DECLARE_SERVICE_INFO(); + + // XConnection + virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement( ) override; + virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const OUString& sql ) override; + virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall( const OUString& sql ) override; + virtual OUString SAL_CALL nativeSQL( const OUString& sql ) override; + virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) override; + virtual sal_Bool SAL_CALL getAutoCommit( ) override; + virtual void SAL_CALL commit( ) override; + virtual void SAL_CALL rollback( ) override; + virtual sal_Bool SAL_CALL isClosed( ) override final; + virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( ) override; + virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) override; + virtual sal_Bool SAL_CALL isReadOnly( ) override; + virtual void SAL_CALL setCatalog( const OUString& catalog ) override; + virtual OUString SAL_CALL getCatalog( ) override; + virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) override; + virtual sal_Int32 SAL_CALL getTransactionIsolation( ) override; + virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTypeMap( ) override; + virtual void SAL_CALL setTypeMap( const css::uno::Reference< css::container::XNameAccess >& typeMap ) override; + // XCloseable + virtual void SAL_CALL close( ) override final; + // XWarningsSupplier + virtual css::uno::Any SAL_CALL getWarnings( ) override; + virtual void SAL_CALL clearWarnings( ) override; + //XUnoTunnel + virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; + static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId(); + + // no interface methods + css::uno::Reference< css::ucb::XDynamicResultSet > getDir() const; + const css::uno::Reference< css::ucb::XContent>& getContent() const { return m_xContent; } + // create a catalog or return the catalog already created + virtual css::uno::Reference< css::sdbcx::XTablesSupplier > createCatalog(); + + bool matchesExtension( const OUString& _rExt ) const; + + const OUString& getExtension() const { return m_aFilenameExtension; } + bool isCaseSensitiveExtension() const { return m_bCaseSensitiveExtension; } + OFileDriver* getDriver() const { return m_pDriver; } + bool showDeleted() const { return m_bShowDeleted; } + bool isCheckEnabled() const { return m_bCheckSQL92; } + bool isTextEncodingDefaulted() const { return m_bDefaultTextEncoding; } + + public: + struct GrantAccess + { + friend class ODatabaseMetaData; + private: + GrantAccess() { } + }; + + void setCaseSensitiveExtension( bool _bIsCS, GrantAccess ) { m_bCaseSensitiveExtension = _bIsCS; } + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FDatabaseMetaData.hxx b/connectivity/source/inc/file/FDatabaseMetaData.hxx new file mode 100644 index 0000000000..5c766c31d1 --- /dev/null +++ b/connectivity/source/inc/file/FDatabaseMetaData.hxx @@ -0,0 +1,186 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <TDatabaseMetaDataBase.hxx> +#include <file/FConnection.hxx> +#include <file/filedllapi.hxx> + +namespace connectivity::file + { + + //************ Class: ODatabaseMetaData + + + class OOO_DLLPUBLIC_FILE SAL_NO_VTABLE ODatabaseMetaData : + public ODatabaseMetaDataBase + { + virtual css::uno::Reference< css::sdbc::XResultSet > impl_getTypeInfo_throw() override; + // cached database information + virtual OUString impl_getIdentifierQuoteString_throw( ) override; + virtual bool impl_isCatalogAtStart_throw( ) override; + virtual OUString impl_getCatalogSeparator_throw( ) override; + virtual bool impl_supportsCatalogsInTableDefinitions_throw( ) override; + virtual bool impl_supportsSchemasInTableDefinitions_throw( ) override ; + virtual bool impl_supportsCatalogsInDataManipulation_throw( ) override; + virtual bool impl_supportsSchemasInDataManipulation_throw( ) override ; + virtual bool impl_supportsMixedCaseQuotedIdentifiers_throw( ) override; + virtual bool impl_supportsAlterTableWithAddColumn_throw( ) override; + virtual bool impl_supportsAlterTableWithDropColumn_throw( ) override; + virtual sal_Int32 impl_getMaxStatements_throw( ) override; + virtual sal_Int32 impl_getMaxTablesInSelect_throw( ) override; + virtual bool impl_storesMixedCaseQuotedIdentifiers_throw( ) override; + protected: + OConnection* m_pConnection; // I need the native class not only the interface + virtual ~ODatabaseMetaData() override; + public: + + ODatabaseMetaData(OConnection* _pCon); + // XDatabaseMetaData + virtual sal_Bool SAL_CALL allProceduresAreCallable( ) override; + virtual sal_Bool SAL_CALL allTablesAreSelectable( ) override; + virtual OUString SAL_CALL getURL( ) override; + virtual OUString SAL_CALL getUserName( ) override; + virtual sal_Bool SAL_CALL isReadOnly( ) override; + virtual sal_Bool SAL_CALL nullsAreSortedHigh( ) override; + virtual sal_Bool SAL_CALL nullsAreSortedLow( ) override; + virtual sal_Bool SAL_CALL nullsAreSortedAtStart( ) override; + virtual sal_Bool SAL_CALL nullsAreSortedAtEnd( ) override; + virtual OUString SAL_CALL getDatabaseProductName( ) override; + virtual OUString SAL_CALL getDatabaseProductVersion( ) override; + virtual OUString SAL_CALL getDriverName( ) override; + virtual OUString SAL_CALL getDriverVersion( ) override; + virtual sal_Int32 SAL_CALL getDriverMajorVersion( ) override; + virtual sal_Int32 SAL_CALL getDriverMinorVersion( ) override; + virtual sal_Bool SAL_CALL usesLocalFiles( ) override; + virtual sal_Bool SAL_CALL usesLocalFilePerTable( ) override; + virtual sal_Bool SAL_CALL supportsMixedCaseIdentifiers( ) override; + virtual sal_Bool SAL_CALL storesUpperCaseIdentifiers( ) override; + virtual sal_Bool SAL_CALL storesLowerCaseIdentifiers( ) override; + virtual sal_Bool SAL_CALL storesMixedCaseIdentifiers( ) override; + virtual sal_Bool SAL_CALL storesUpperCaseQuotedIdentifiers( ) override; + virtual sal_Bool SAL_CALL storesLowerCaseQuotedIdentifiers( ) override; + virtual OUString SAL_CALL getSQLKeywords( ) override; + virtual OUString SAL_CALL getNumericFunctions( ) override; + virtual OUString SAL_CALL getStringFunctions( ) override; + virtual OUString SAL_CALL getSystemFunctions( ) override; + virtual OUString SAL_CALL getTimeDateFunctions( ) override; + virtual OUString SAL_CALL getSearchStringEscape( ) override; + virtual OUString SAL_CALL getExtraNameCharacters( ) override; + virtual sal_Bool SAL_CALL supportsColumnAliasing( ) override; + virtual sal_Bool SAL_CALL nullPlusNonNullIsNull( ) override; + virtual sal_Bool SAL_CALL supportsTypeConversion( ) override; + virtual sal_Bool SAL_CALL supportsConvert( sal_Int32 fromType, sal_Int32 toType ) override; + virtual sal_Bool SAL_CALL supportsTableCorrelationNames( ) override; + virtual sal_Bool SAL_CALL supportsDifferentTableCorrelationNames( ) override; + virtual sal_Bool SAL_CALL supportsExpressionsInOrderBy( ) override; + virtual sal_Bool SAL_CALL supportsOrderByUnrelated( ) override; + virtual sal_Bool SAL_CALL supportsGroupBy( ) override; + virtual sal_Bool SAL_CALL supportsGroupByUnrelated( ) override; + virtual sal_Bool SAL_CALL supportsGroupByBeyondSelect( ) override; + virtual sal_Bool SAL_CALL supportsLikeEscapeClause( ) override; + virtual sal_Bool SAL_CALL supportsMultipleResultSets( ) override; + virtual sal_Bool SAL_CALL supportsMultipleTransactions( ) override; + virtual sal_Bool SAL_CALL supportsNonNullableColumns( ) override; + virtual sal_Bool SAL_CALL supportsMinimumSQLGrammar( ) override; + virtual sal_Bool SAL_CALL supportsCoreSQLGrammar( ) override; + virtual sal_Bool SAL_CALL supportsExtendedSQLGrammar( ) override; + virtual sal_Bool SAL_CALL supportsANSI92EntryLevelSQL( ) override; + virtual sal_Bool SAL_CALL supportsANSI92IntermediateSQL( ) override; + virtual sal_Bool SAL_CALL supportsANSI92FullSQL( ) override; + virtual sal_Bool SAL_CALL supportsIntegrityEnhancementFacility( ) override; + virtual sal_Bool SAL_CALL supportsOuterJoins( ) override; + virtual sal_Bool SAL_CALL supportsFullOuterJoins( ) override; + virtual sal_Bool SAL_CALL supportsLimitedOuterJoins( ) override; + virtual OUString SAL_CALL getSchemaTerm( ) override; + virtual OUString SAL_CALL getProcedureTerm( ) override; + virtual OUString SAL_CALL getCatalogTerm( ) override; + virtual sal_Bool SAL_CALL supportsSchemasInProcedureCalls( ) override; + virtual sal_Bool SAL_CALL supportsSchemasInIndexDefinitions( ) override; + virtual sal_Bool SAL_CALL supportsSchemasInPrivilegeDefinitions( ) override; + virtual sal_Bool SAL_CALL supportsCatalogsInProcedureCalls( ) override; + virtual sal_Bool SAL_CALL supportsCatalogsInIndexDefinitions( ) override; + virtual sal_Bool SAL_CALL supportsCatalogsInPrivilegeDefinitions( ) override; + virtual sal_Bool SAL_CALL supportsPositionedDelete( ) override; + virtual sal_Bool SAL_CALL supportsPositionedUpdate( ) override; + virtual sal_Bool SAL_CALL supportsSelectForUpdate( ) override; + virtual sal_Bool SAL_CALL supportsStoredProcedures( ) override; + virtual sal_Bool SAL_CALL supportsSubqueriesInComparisons( ) override; + virtual sal_Bool SAL_CALL supportsSubqueriesInExists( ) override; + virtual sal_Bool SAL_CALL supportsSubqueriesInIns( ) override; + virtual sal_Bool SAL_CALL supportsSubqueriesInQuantifieds( ) override; + virtual sal_Bool SAL_CALL supportsCorrelatedSubqueries( ) override; + virtual sal_Bool SAL_CALL supportsUnion( ) override; + virtual sal_Bool SAL_CALL supportsUnionAll( ) override; + virtual sal_Bool SAL_CALL supportsOpenCursorsAcrossCommit( ) override; + virtual sal_Bool SAL_CALL supportsOpenCursorsAcrossRollback( ) override; + virtual sal_Bool SAL_CALL supportsOpenStatementsAcrossCommit( ) override; + virtual sal_Bool SAL_CALL supportsOpenStatementsAcrossRollback( ) override; + virtual sal_Int32 SAL_CALL getMaxBinaryLiteralLength( ) override; + virtual sal_Int32 SAL_CALL getMaxCharLiteralLength( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInGroupBy( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInIndex( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInOrderBy( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInSelect( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInTable( ) override; + virtual sal_Int32 SAL_CALL getMaxConnections( ) override; + virtual sal_Int32 SAL_CALL getMaxCursorNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxIndexLength( ) override; + virtual sal_Int32 SAL_CALL getMaxSchemaNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxProcedureNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxCatalogNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxRowSize( ) override; + virtual sal_Bool SAL_CALL doesMaxRowSizeIncludeBlobs( ) override; + virtual sal_Int32 SAL_CALL getMaxStatementLength( ) override; + virtual sal_Int32 SAL_CALL getMaxTableNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxUserNameLength( ) override; + virtual sal_Int32 SAL_CALL getDefaultTransactionIsolation( ) override; + virtual sal_Bool SAL_CALL supportsTransactions( ) override; + virtual sal_Bool SAL_CALL supportsTransactionIsolationLevel( sal_Int32 level ) override; + virtual sal_Bool SAL_CALL supportsDataDefinitionAndDataManipulationTransactions( ) override; + virtual sal_Bool SAL_CALL supportsDataManipulationTransactionsOnly( ) override; + virtual sal_Bool SAL_CALL dataDefinitionCausesTransactionCommit( ) override; + virtual sal_Bool SAL_CALL dataDefinitionIgnoredInTransactions( ) override; + + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTables( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern, const css::uno::Sequence< OUString >& types ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTableTypes( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTablePrivileges( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getColumns( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern, const OUString& columnNamePattern ) override; + + virtual sal_Bool SAL_CALL supportsResultSetType( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL supportsResultSetConcurrency( sal_Int32 setType, sal_Int32 concurrency ) override; + virtual sal_Bool SAL_CALL ownUpdatesAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL ownDeletesAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL ownInsertsAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL othersUpdatesAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL othersDeletesAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL othersInsertsAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL updatesAreDetected( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL deletesAreDetected( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL insertsAreDetected( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL supportsBatchUpdates( ) override; + + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getUDTs( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& typeNamePattern, const css::uno::Sequence< sal_Int32 >& types ) override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FDateFunctions.hxx b/connectivity/source/inc/file/FDateFunctions.hxx new file mode 100644 index 0000000000..e8eb12d0cf --- /dev/null +++ b/connectivity/source/inc/file/FDateFunctions.hxx @@ -0,0 +1,228 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/fcode.hxx> + +namespace connectivity::file + { + /** DAYOFWEEK(date) + Returns the weekday index for date (1 = Sunday, 2 = Monday, ... 7 = Saturday). These index values correspond to the ODBC standard. + + > SELECT DAYOFWEEK('1998-02-03'); + -> 3 + */ + class OOp_DayOfWeek : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** DAYOFMONTH(date) + Returns the day of the month for date, in the range 1 to 31: + + > SELECT DAYOFMONTH('1998-02-03'); + -> 3 + */ + class OOp_DayOfMonth : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** DAYOFYEAR(date) + Returns the day of the year for date, in the range 1 to 366: + + > SELECT DAYOFYEAR('1998-02-03'); + -> 34 + + */ + class OOp_DayOfYear : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** MONTH(date) + Returns the month for date, in the range 1 to 12: + + > SELECT MONTH('1998-02-03'); + -> 2 + */ + class OOp_Month : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** DAYNAME(date) + Returns the name of the weekday for date: + + > SELECT DAYNAME('1998-02-05'); + -> 'Thursday' + + */ + class OOp_DayName : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** MONTHNAME(date) + Returns the name of the month for date: + + > SELECT MONTHNAME('1998-02-05'); + -> 'February' + + */ + class OOp_MonthName : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** QUARTER(date) + Returns the quarter of the year for date, in the range 1 to 4: + + > SELECT QUARTER('98-04-01'); + -> 2 + + */ + class OOp_Quarter : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** WEEK(date) + WEEK(date,first) + With a single argument, returns the week for date, in the range 0 to 53 (yes, there may be the beginnings of a week 53), for locations where Sunday is the first day of the week. The two-argument form of WEEK() allows you to specify whether the week starts on Sunday or Monday and whether the return value should be in the range 0-53 or 1-52. Here is a table for how the second argument works: + Value Meaning + 0 Week starts on Sunday and return value is in range 0-53 + 1 Week starts on Monday and return value is in range 0-53 + 2 Week starts on Sunday and return value is in range 1-53 + 3 Week starts on Monday and return value is in range 1-53 (ISO 8601) + + > SELECT WEEK('1998-02-20'); + -> 7 + > SELECT WEEK('1998-02-20',0); + -> 7 + > SELECT WEEK('1998-02-20',1); + -> 8 + > SELECT WEEK('1998-12-31',1); + -> 53 + + */ + class OOp_Week : public ONthOperator + { + protected: + virtual ORowSetValue operate(const std::vector<ORowSetValue>& lhs) const override; + }; + + /** YEAR(date) + Returns the year for date, in the range 1000 to 9999: + + > SELECT YEAR('98-02-03'); + -> 1998 + */ + class OOp_Year : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** HOUR(time) + Returns the hour for time, in the range 0 to 23: + + > SELECT HOUR('10:05:03'); + -> 10 + */ + class OOp_Hour : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** MINUTE(time) + Returns the minute for time, in the range 0 to 59: + + > SELECT MINUTE('98-02-03 10:05:03'); + -> 5 + + */ + class OOp_Minute : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** SECOND(time) + Returns the second for time, in the range 0 to 59: + + > SELECT SECOND('10:05:03'); + -> 3 + */ + class OOp_Second : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** CURDATE() + CURRENT_DATE + Returns today's date as a value in 'YYYY-MM-DD' or YYYYMMDD format, depending on whether the function is used in a string or numeric context: + + > SELECT CURDATE(); + -> '1997-12-15' + */ + class OOp_CurDate : public ONthOperator + { + protected: + virtual ORowSetValue operate(const std::vector<ORowSetValue>& lhs) const override; + }; + + /** CURTIME() + CURRENT_TIME + Returns the current time as a value in 'HH:MM:SS' or HHMMSS format, depending on whether the function is used in a string or numeric context: + + > SELECT CURTIME(); + -> '23:50:26' + */ + class OOp_CurTime : public ONthOperator + { + protected: + virtual ORowSetValue operate(const std::vector<ORowSetValue>& lhs) const override; + }; + + /** NOW() + Returns the current date and time as a value in 'YYYY-MM-DD HH:MM:SS' or YYYYMMDDHHMMSS format, depending on whether the function is used in a string or numeric context: + + > SELECT NOW(); + -> '1997-12-15 23:50:26' + */ + class OOp_Now : public ONthOperator + { + protected: + virtual ORowSetValue operate(const std::vector<ORowSetValue>& lhs) const override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FDriver.hxx b/connectivity/source/inc/file/FDriver.hxx new file mode 100644 index 0000000000..0351c59ca2 --- /dev/null +++ b/connectivity/source/inc/file/FDriver.hxx @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/sdbc/XDriver.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp> +#include <cppuhelper/compbase.hxx> +#include <connectivity/CommonTools.hxx> +#include <file/filedllapi.hxx> + +namespace connectivity::file + { + typedef ::cppu::WeakComponentImplHelper< css::sdbc::XDriver, + css::lang::XServiceInfo, + css::sdbcx::XDataDefinitionSupplier> ODriver_BASE; + + class OOO_DLLPUBLIC_FILE SAL_NO_VTABLE OFileDriver : public ODriver_BASE + { + protected: + ::osl::Mutex m_aMutex; + + connectivity::OWeakRefArray m_xConnections; // vector containing a list + // of all the Connection objects + // for this Driver + css::uno::Reference< css::uno::XComponentContext > m_xContext; + public: + OFileDriver(css::uno::Reference< css::uno::XComponentContext > _xContext); + + // OComponentHelper + virtual void SAL_CALL disposing() override; + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName( ) override; + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; + + // XDriver + virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL connect( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + virtual sal_Bool SAL_CALL acceptsURL( const OUString& url ) override; + virtual css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + virtual sal_Int32 SAL_CALL getMajorVersion( ) override; + virtual sal_Int32 SAL_CALL getMinorVersion( ) override; + + // XDataDefinitionSupplier + virtual css::uno::Reference< css::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByConnection( const css::uno::Reference< css::sdbc::XConnection >& connection ) override; + virtual css::uno::Reference< css::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByURL( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + + const css::uno::Reference< css::uno::XComponentContext >& getComponentContext() const { return m_xContext; } + }; + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FNumericFunctions.hxx b/connectivity/source/inc/file/FNumericFunctions.hxx new file mode 100644 index 0000000000..765f2cde82 --- /dev/null +++ b/connectivity/source/inc/file/FNumericFunctions.hxx @@ -0,0 +1,362 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/fcode.hxx> + +namespace connectivity::file + { + /** ABS(X) + Returns the absolute value of X: + + > SELECT ABS(2); + -> 2 + > SELECT ABS(-32); + -> 32 + + */ + class OOp_Abs : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** SIGN(X) + Returns the sign of the argument as -1, 0, or 1, depending on whether X is negative, zero, or positive: + + > SELECT SIGN(-32); + -> -1 + > SELECT SIGN(0); + -> 0 + > SELECT SIGN(234); + -> 1 + + */ + class OOp_Sign : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** MOD(N,M) + % + Modulo (like the % operator in C). Returns the remainder of N divided by M: + + > SELECT MOD(234, 10); + -> 4 + > SELECT 253 % 7; + -> 1 + > SELECT MOD(29,9); + -> 2 + > SELECT 29 MOD 9; + -> 2 + */ + class OOp_Mod : public OBinaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const override; + }; + + /** FLOOR(X) + Returns the largest integer value not greater than X: + + > SELECT FLOOR(1.23); + -> 1 + > SELECT FLOOR(-1.23); + -> -2 + + */ + class OOp_Floor : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** CEILING(X) + Returns the smallest integer value not less than X: + + > SELECT CEILING(1.23); + -> 2 + > SELECT CEILING(-1.23); + -> -1 + + */ + class OOp_Ceiling : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** ROUND(X) + ROUND(X,D) + Returns the argument X, rounded to the nearest integer. With two arguments rounded to a number to D decimals. + + > SELECT ROUND(-1.23); + -> -1 + > SELECT ROUND(-1.58); + -> -2 + > SELECT ROUND(1.58); + -> 2 + > SELECT ROUND(1.298, 1); + -> 1.3 + > SELECT ROUND(1.298, 0); + -> 1 + > SELECT ROUND(23.298, -1); + -> 20 + */ + class OOp_Round : public ONthOperator + { + protected: + virtual ORowSetValue operate(const std::vector<ORowSetValue>& lhs) const override; + }; + + /** EXP(X) + Returns the value of e (the base of natural logarithms) raised to the power of X: + + > SELECT EXP(2); + -> 7.389056 + > SELECT EXP(-2); + -> 0.135335 + */ + class OOp_Exp : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** LN(X) + Returns the natural logarithm of X: + + > SELECT LN(2); + -> 0.693147 + > SELECT LN(-2); + -> NULL + + */ + class OOp_Ln : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** LOG(X) + LOG(B,X) + If called with one parameter, this function returns the natural logarithm of X: + + > SELECT LOG(2); + -> 0.693147 + > SELECT LOG(-2); + -> NULL + + If called with two parameters, this function returns the logarithm of X for an arbitrary base B: + + > SELECT LOG(2,65536); + -> 16.000000 + > SELECT LOG(1,100); + -> NULL + */ + class OOp_Log : public ONthOperator + { + protected: + virtual ORowSetValue operate(const std::vector<ORowSetValue>& lhs) const override; + }; + + /** LOG10(X) + Returns the base-10 logarithm of X: + + > SELECT LOG10(2); + -> 0.301030 + > SELECT LOG10(100); + -> 2.000000 + > SELECT LOG10(-100); + -> NULL + */ + class OOp_Log10 : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** POWER(X,Y) + Returns the value of X raised to the power of Y: + + > SELECT POW(2,2); + -> 4.000000 + > SELECT POW(2,-2); + -> 0.250000 + */ + class OOp_Pow : public OBinaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const override; + }; + + /** SQRT(X) + Returns the non-negative square root of X: + + > SELECT SQRT(4); + -> 2.000000 + > SELECT SQRT(20); + -> 4.472136 + */ + class OOp_Sqrt : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** PI() + Returns the value of PI. The default shown number of decimals is 5, but internally uses the full double precision for PI. + + > SELECT PI(); + -> 3.141593 + > SELECT PI()+0.000000000000000000; + -> 3.141592653589793238 + + */ + class OOp_Pi : public ONthOperator + { + protected: + virtual ORowSetValue operate(const std::vector<ORowSetValue>& lhs) const override; + }; + + /** COS(X) + Returns the cosine of X, where X is given in radians: + + > SELECT COS(PI()); + -> -1.000000 + */ + class OOp_Cos : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** SIN(X) + Returns the sine of X, where X is given in radians: + + > SELECT SIN(PI()); + -> 0.000000 + + */ + class OOp_Sin : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + /** TAN(X) + Returns the tangent of X, where X is given in radians: + + > SELECT TAN(PI()+1); + -> 1.557408 + */ + class OOp_Tan : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** ACOS(X) + Returns the arc cosine of X, that is, the value whose cosine is X. Returns NULL if X is not in the range -1 to 1: + + > SELECT ACOS(1); + -> 0.000000 + > SELECT ACOS(1.0001); + -> NULL + > SELECT ACOS(0); + -> 1.570796 + */ + class OOp_ACos : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** ASIN(X) + Returns the arc sine of X, that is, the value whose sine is X. Returns NULL if X is not in the range -1 to 1: + + > SELECT ASIN(0.2); + -> 0.201358 + > SELECT ASIN('foo'); + -> 0.000000 + */ + class OOp_ASin : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** ATAN(X) + Returns the arc tangent of X, that is, the value whose tangent is X: + + > SELECT ATAN(2); + -> 1.107149 + > SELECT ATAN(-2); + -> -1.107149 + */ + class OOp_ATan : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** ATAN2(Y,X) + Returns the arc tangent of the two variables X and Y. It is similar to calculating the arc tangent of Y / X, except that the signs of both arguments are used to determine the quadrant of the result: + + > SELECT ATAN2(-2,2); + -> -0.785398 + > SELECT ATAN2(PI(),0); + -> 1.570796 + + */ + class OOp_ATan2 : public OBinaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const override; + }; + + /** DEGREES(X) + Returns the argument X, converted from radians to degrees: + + > SELECT DEGREES(PI()); + -> 180.000000 + */ + class OOp_Degrees : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** RADIANS(X) + Returns the argument X, converted from degrees to radians: + + > SELECT RADIANS(90); + -> 1.570796 + + */ + class OOp_Radians : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FPreparedStatement.hxx b/connectivity/source/inc/file/FPreparedStatement.hxx new file mode 100644 index 0000000000..f83d74a6d0 --- /dev/null +++ b/connectivity/source/inc/file/FPreparedStatement.hxx @@ -0,0 +1,121 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/filedllapi.hxx> +#include <file/FStatement.hxx> +#include <com/sun/star/sdbc/XPreparedStatement.hpp> +#include <com/sun/star/sdbc/XParameters.hpp> +#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <file/FResultSet.hxx> + +namespace connectivity::file + { + + class OOO_DLLPUBLIC_FILE SAL_NO_VTABLE OPreparedStatement : public OStatement_BASE2, + public css::sdbc::XPreparedStatement, + public css::sdbc::XParameters, + public css::sdbc::XResultSetMetaDataSupplier, + public css::lang::XServiceInfo + + { + protected: + + // Data attributes + + OValueRefRow m_aParameterRow; + css::uno::Reference< css::sdbc::XResultSetMetaData> m_xMetaData; + + ::rtl::Reference<connectivity::OSQLColumns> m_xParamColumns; // the parameter columns + + // factory method for resultset's + virtual rtl::Reference<OResultSet> createResultSet() override; + ::rtl::Reference< OResultSet > makeResultSet(); + void initResultSet(OResultSet*); + + void checkAndResizeParameters(sal_Int32 parameterIndex); + void setParameter(sal_Int32 parameterIndex, const ORowSetValue& x); + + sal_uInt32 AddParameter(connectivity::OSQLParseNode const * pParameter, + const css::uno::Reference< css::beans::XPropertySet>& _xCol); + void scanParameter(OSQLParseNode* pParseNode,std::vector< OSQLParseNode*>& _rParaNodes); + void describeColumn(OSQLParseNode const * _pParameter, OSQLParseNode const * _pNode, const OSQLTable& _xTable); + void describeParameter(); + + virtual void parseParamterElem(const OUString& _sColumnName,OSQLParseNode* pRow_Value_Constructor_Elem) override; + virtual void initializeResultSet(OResultSet* _pResult) override; + + virtual ~OPreparedStatement() override; + public: + DECLARE_SERVICE_INFO(); + // a Constructor, that is needed for when Returning the Object is needed: + OPreparedStatement( OConnection* _pConnection); + + virtual void construct(const OUString& sql) override; + + // OComponentHelper + virtual void SAL_CALL disposing() override; + //XInterface + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + + // XPreparedStatement + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL executeQuery( ) override; + virtual sal_Int32 SAL_CALL executeUpdate( ) override; + virtual sal_Bool SAL_CALL execute( ) override; + virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( ) override; + // XParameters + virtual void SAL_CALL setNull( sal_Int32 parameterIndex, sal_Int32 sqlType ) override; + virtual void SAL_CALL setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const OUString& typeName ) override; + virtual void SAL_CALL setBoolean( sal_Int32 parameterIndex, sal_Bool x ) override; + virtual void SAL_CALL setByte( sal_Int32 parameterIndex, sal_Int8 x ) override; + virtual void SAL_CALL setShort( sal_Int32 parameterIndex, sal_Int16 x ) override; + virtual void SAL_CALL setInt( sal_Int32 parameterIndex, sal_Int32 x ) override; + virtual void SAL_CALL setLong( sal_Int32 parameterIndex, sal_Int64 x ) override; + virtual void SAL_CALL setFloat( sal_Int32 parameterIndex, float x ) override; + virtual void SAL_CALL setDouble( sal_Int32 parameterIndex, double x ) override; + virtual void SAL_CALL setString( sal_Int32 parameterIndex, const OUString& x ) override; + virtual void SAL_CALL setBytes( sal_Int32 parameterIndex, const css::uno::Sequence< sal_Int8 >& x ) override; + virtual void SAL_CALL setDate( sal_Int32 parameterIndex, const css::util::Date& x ) override; + virtual void SAL_CALL setTime( sal_Int32 parameterIndex, const css::util::Time& x ) override; + virtual void SAL_CALL setTimestamp( sal_Int32 parameterIndex, const css::util::DateTime& x ) override; + virtual void SAL_CALL setBinaryStream( sal_Int32 parameterIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override; + virtual void SAL_CALL setCharacterStream( sal_Int32 parameterIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override; + virtual void SAL_CALL setObject( sal_Int32 parameterIndex, const css::uno::Any& x ) override; + virtual void SAL_CALL setObjectWithInfo( sal_Int32 parameterIndex, const css::uno::Any& x, sal_Int32 targetSqlType, sal_Int32 scale ) override; + virtual void SAL_CALL setRef( sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XRef >& x ) override; + virtual void SAL_CALL setBlob( sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XBlob >& x ) override; + virtual void SAL_CALL setClob( sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XClob >& x ) override; + virtual void SAL_CALL setArray( sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XArray >& x ) override; + virtual void SAL_CALL clearParameters( ) override; + // XCloseable + virtual void SAL_CALL close( ) override; + // XResultSetMetaDataSupplier + virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData( ) override; + }; + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FResultSet.hxx b/connectivity/source/inc/file/FResultSet.hxx new file mode 100644 index 0000000000..16371531fb --- /dev/null +++ b/connectivity/source/inc/file/FResultSet.hxx @@ -0,0 +1,301 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/sdbc/XResultSet.hpp> +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> +#include <com/sun/star/sdbc/XCloseable.hpp> +#include <com/sun/star/sdbc/XColumnLocate.hpp> +#include <com/sun/star/util/XCancellable.hpp> +#include <com/sun/star/sdbc/XWarningsSupplier.hpp> +#include <com/sun/star/sdbc/XResultSetUpdate.hpp> +#include <com/sun/star/sdbc/XRowUpdate.hpp> +#include <cppuhelper/compbase.hxx> +#include <cppuhelper/basemutex.hxx> +#include <comphelper/proparrhlp.hxx> +#include <file/FStatement.hxx> +#include <connectivity/CommonTools.hxx> +#include <comphelper/propertycontainer.hxx> +#include <file/fanalyzer.hxx> +#include <file/FTable.hxx> +#include <file/filedllapi.hxx> +#include <TSortIndex.hxx> +#include <TSkipDeletedSet.hxx> +#include <com/sun/star/lang/XEventListener.hpp> +#include <o3tl/safeint.hxx> + +namespace connectivity::file + { + typedef ::cppu::WeakComponentImplHelper< css::sdbc::XResultSet, + css::sdbc::XRow, + css::sdbc::XResultSetMetaDataSupplier, + css::util::XCancellable, + css::sdbc::XWarningsSupplier, + css::sdbc::XResultSetUpdate, + css::sdbc::XRowUpdate, + css::sdbc::XCloseable, + css::sdbc::XColumnLocate, + css::lang::XServiceInfo, + css::lang::XEventListener> OResultSet_BASE; + + class OOO_DLLPUBLIC_FILE OResultSet : + public cppu::BaseMutex, + public ::connectivity::IResultSetHelper, + public OResultSet_BASE, + public ::comphelper::OPropertyContainer, + public ::comphelper::OPropertyArrayUsageHelper<OResultSet> + { + + protected: + std::vector<sal_Int32> m_aColMapping; // pos 0 is unused so we don't have to decrement 1 every time + + std::vector<sal_Int32> m_aOrderbyColumnNumber; + std::vector<TAscendingOrder> m_aOrderbyAscending; + + OValueRefRow m_aSelectRow; + OValueRefRow m_aRow; + OValueRefRow m_aEvaluateRow; // contains all values of a row + OValueRefRow m_aInsertRow; // needed for insert by cursor + ORefAssignValues m_aAssignValues; // needed for insert,update and parameters + // to compare with the restrictions + OSkipDeletedSet m_aSkipDeletedSet; + + ::rtl::Reference<OKeySet> m_pFileSet; + OKeySet::iterator m_aFileSetIter; + + + std::unique_ptr<OSortIndex> m_pSortIndex; + ::rtl::Reference<connectivity::OSQLColumns> m_xColumns; // this are the select columns + rtl::Reference<OFileTable> m_pTable; + connectivity::OSQLParseNode* m_pParseTree; + + OSQLAnalyzer* m_pSQLAnalyzer; + connectivity::OSQLParseTreeIterator& m_aSQLIterator; + + sal_Int32 m_nFetchSize; + sal_Int32 m_nResultSetType; + sal_Int32 m_nFetchDirection; + sal_Int32 m_nResultSetConcurrency; + + css::uno::Reference< css::uno::XInterface> m_xStatement; + css::uno::Reference< css::sdbc::XResultSetMetaData> m_xMetaData; + css::uno::Reference< css::container::XNameAccess> m_xColNames; // table columns + css::uno::Reference< css::container::XIndexAccess> m_xColsIdx; // table columns + + + sal_Int32 m_nRowPos; + sal_Int32 m_nFilePos; + sal_Int32 m_nLastVisitedPos; + sal_Int32 m_nRowCountResult; + sal_Int32 m_nColumnCount; + bool m_bWasNull; + bool m_bInserted; // true when moveToInsertRow was called + // set to false when cursor moved or cancel + bool m_bRowUpdated; + bool m_bRowInserted; + bool m_bRowDeleted; + bool m_bShowDeleted; + bool m_bIsCount; + + static void initializeRow(OValueRefRow& _rRow,sal_Int32 _nColumnCount); + void construct(); + //sal_Bool evaluate(); + + bool ExecuteRow(IResultSetHelper::Movement eFirstCursorPosition, + sal_Int32 nOffset = 1, + bool bEvaluate = true, + bool bRetrieveData = true); + + std::unique_ptr<OKeyValue> GetOrderbyKeyValue(OValueRefRow const & _rRow); + bool IsSorted() const { return !m_aOrderbyColumnNumber.empty() && m_aOrderbyColumnNumber[0] >= 0;} + + // return true when the select statement is "select count(*) from table" + bool isCount() const { return m_bIsCount; } + /// @throws css::sdbc::SQLException + void checkIndex(sal_Int32 columnIndex ); + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + const ORowSetValue& getValue(sal_Int32 columnIndex); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void updateValue(sal_Int32 columnIndex,const ORowSetValue& x ); + // clear insert row + void clearInsertRow(); + void sortRows(); + protected: + + using OResultSet_BASE::rBHelper; + + bool Move(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOffset, bool bRetrieveData); + virtual bool fillIndexValues(const css::uno::Reference< css::sdbcx::XColumnsSupplier> &_xIndex); + + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override; + // OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + + virtual ~OResultSet() override; + public: + DECLARE_SERVICE_INFO(); + // a Constructor, that is needed for when Returning the Object is needed: + OResultSet( OStatement_Base* pStmt,connectivity::OSQLParseTreeIterator& _aSQLIterator); + + // ::cppu::OComponentHelper + virtual void SAL_CALL disposing() override final; + // XInterface + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + // XPropertySet + virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; + // XResultSet + virtual sal_Bool SAL_CALL next( ) override; + virtual sal_Bool SAL_CALL isBeforeFirst( ) override; + virtual sal_Bool SAL_CALL isAfterLast( ) override; + virtual sal_Bool SAL_CALL isFirst( ) override; + virtual sal_Bool SAL_CALL isLast( ) override; + virtual void SAL_CALL beforeFirst( ) override; + virtual void SAL_CALL afterLast( ) override; + virtual sal_Bool SAL_CALL first( ) override; + virtual sal_Bool SAL_CALL last( ) override; + virtual sal_Int32 SAL_CALL getRow( ) override; + virtual sal_Bool SAL_CALL absolute( sal_Int32 row ) override; + virtual sal_Bool SAL_CALL relative( sal_Int32 rows ) override; + virtual sal_Bool SAL_CALL previous( ) override; + virtual void SAL_CALL refreshRow( ) override; + virtual sal_Bool SAL_CALL rowUpdated( ) override; + virtual sal_Bool SAL_CALL rowInserted( ) override; + virtual sal_Bool SAL_CALL rowDeleted( ) override; + virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getStatement( ) override; + // XRow + virtual sal_Bool SAL_CALL wasNull( ) override; + virtual OUString SAL_CALL getString( sal_Int32 columnIndex ) override; + virtual sal_Bool SAL_CALL getBoolean( sal_Int32 columnIndex ) override; + virtual sal_Int8 SAL_CALL getByte( sal_Int32 columnIndex ) override; + virtual sal_Int16 SAL_CALL getShort( sal_Int32 columnIndex ) override; + virtual sal_Int32 SAL_CALL getInt( sal_Int32 columnIndex ) override; + virtual sal_Int64 SAL_CALL getLong( sal_Int32 columnIndex ) override; + virtual float SAL_CALL getFloat( sal_Int32 columnIndex ) override; + virtual double SAL_CALL getDouble( sal_Int32 columnIndex ) override; + virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes( sal_Int32 columnIndex ) override; + virtual css::util::Date SAL_CALL getDate( sal_Int32 columnIndex ) override; + virtual css::util::Time SAL_CALL getTime( sal_Int32 columnIndex ) override; + virtual css::util::DateTime SAL_CALL getTimestamp( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream( sal_Int32 columnIndex ) override; + virtual css::uno::Any SAL_CALL getObject( sal_Int32 columnIndex, const css::uno::Reference< css::container::XNameAccess >& typeMap ) override; + virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray( sal_Int32 columnIndex ) override; + // XResultSetMetaDataSupplier + virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData( ) override; + // XCancellable + virtual void SAL_CALL cancel( ) override; + // XCloseable + virtual void SAL_CALL close( ) override; + // XWarningsSupplier + virtual css::uno::Any SAL_CALL getWarnings( ) override; + virtual void SAL_CALL clearWarnings( ) override; + // XResultSetUpdate + virtual void SAL_CALL insertRow( ) override; + virtual void SAL_CALL updateRow( ) override; + virtual void SAL_CALL deleteRow( ) override; + virtual void SAL_CALL cancelRowUpdates( ) override; + virtual void SAL_CALL moveToInsertRow( ) override; + virtual void SAL_CALL moveToCurrentRow( ) override; + // XRowUpdate + virtual void SAL_CALL updateNull( sal_Int32 columnIndex ) override; + virtual void SAL_CALL updateBoolean( sal_Int32 columnIndex, sal_Bool x ) override; + virtual void SAL_CALL updateByte( sal_Int32 columnIndex, sal_Int8 x ) override; + virtual void SAL_CALL updateShort( sal_Int32 columnIndex, sal_Int16 x ) override; + virtual void SAL_CALL updateInt( sal_Int32 columnIndex, sal_Int32 x ) override; + virtual void SAL_CALL updateLong( sal_Int32 columnIndex, sal_Int64 x ) override; + virtual void SAL_CALL updateFloat( sal_Int32 columnIndex, float x ) override; + virtual void SAL_CALL updateDouble( sal_Int32 columnIndex, double x ) override; + virtual void SAL_CALL updateString( sal_Int32 columnIndex, const OUString& x ) override; + virtual void SAL_CALL updateBytes( sal_Int32 columnIndex, const css::uno::Sequence< sal_Int8 >& x ) override; + virtual void SAL_CALL updateDate( sal_Int32 columnIndex, const css::util::Date& x ) override; + virtual void SAL_CALL updateTime( sal_Int32 columnIndex, const css::util::Time& x ) override; + virtual void SAL_CALL updateTimestamp( sal_Int32 columnIndex, const css::util::DateTime& x ) override; + virtual void SAL_CALL updateBinaryStream( sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override; + virtual void SAL_CALL updateCharacterStream( sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override; + virtual void SAL_CALL updateObject( sal_Int32 columnIndex, const css::uno::Any& x ) override; + virtual void SAL_CALL updateNumericObject( sal_Int32 columnIndex, const css::uno::Any& x, sal_Int32 scale ) override; + // XColumnLocate + virtual sal_Int32 SAL_CALL findColumn( const OUString& columnName ) override; + //XEventlistener + virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override; + + // special methods + inline sal_Int32 mapColumn(sal_Int32 column); + void OpenImpl(); + void doTableSpecials(const OSQLTable& _xTable); + + sal_Int32 getRowCountResult() const { return m_nRowCountResult; } + void setEvaluationRow(const OValueRefRow& _aRow) { m_aEvaluateRow = _aRow; } + void setAssignValues(const ORefAssignValues& _aAssignValues) { m_aAssignValues = _aAssignValues; } + void setBindingRow(const OValueRefRow& _aRow) { m_aRow = _aRow; } + void setSelectRow(const OValueRefRow& _rRow) + { + m_aSelectRow = _rRow; + m_nColumnCount = m_aSelectRow->size(); + } + void setColumnMapping(std::vector<sal_Int32>&& _aColumnMapping) { m_aColMapping = std::move(_aColumnMapping); } + void setSqlAnalyzer(OSQLAnalyzer* _pSQLAnalyzer) { m_pSQLAnalyzer = _pSQLAnalyzer; } + + void setOrderByColumns(std::vector<sal_Int32>&& _aColumnOrderBy) { m_aOrderbyColumnNumber = std::move(_aColumnOrderBy); } + void setOrderByAscending(std::vector<TAscendingOrder>&& _aOrderbyAsc) { m_aOrderbyAscending = std::move(_aOrderbyAsc); } + void setMetaData(const css::uno::Reference< css::sdbc::XResultSetMetaData>& _xMetaData) { m_xMetaData = _xMetaData;} + + static void setBoundedColumns(const OValueRefRow& _rRow, + const OValueRefRow& _rSelectRow, + const ::rtl::Reference<connectivity::OSQLColumns>& _rxColumns, + const css::uno::Reference< css::container::XIndexAccess>& _xNames, + bool _bSetColumnMapping, + const css::uno::Reference< css::sdbc::XDatabaseMetaData>& _xMetaData, + std::vector<sal_Int32>& _rColMapping); + + // IResultSetHelper + virtual bool move(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset, bool _bRetrieveData) override; + virtual sal_Int32 getDriverPos() const override; + virtual bool isRowDeleted() const override; + }; + + inline sal_Int32 OResultSet::mapColumn(sal_Int32 column) + { + sal_Int32 map = column; + + OSL_ENSURE(column > 0, "file::OResultSet::mapColumn: invalid column index!"); + // the first column (index 0) is for convenience only. The first real select column is number 1. + if ((column > 0) && (o3tl::make_unsigned(column) < m_aColMapping.size())) + map = m_aColMapping[column]; + + return map; + } + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FResultSetMetaData.hxx b/connectivity/source/inc/file/FResultSetMetaData.hxx new file mode 100644 index 0000000000..dee656a915 --- /dev/null +++ b/connectivity/source/inc/file/FResultSetMetaData.hxx @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/sdbc/XResultSetMetaData.hpp> +#include <cppuhelper/implbase.hxx> +#include <connectivity/CommonTools.hxx> +#include <rtl/ref.hxx> + +namespace connectivity::file + { + class OFileTable; + + //************ Class: ResultSetMetaData + + typedef ::cppu::WeakImplHelper< css::sdbc::XResultSetMetaData> OResultSetMetaData_BASE; + + class OResultSetMetaData : + public OResultSetMetaData_BASE + { + OUString m_aTableName; + ::rtl::Reference<connectivity::OSQLColumns> m_xColumns; + OFileTable* m_pTable; + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void checkColumnIndex(sal_Int32 column); + protected: + virtual ~OResultSetMetaData() override; + public: + // a Constructor, that is needed for when Returning the Object is needed: + OResultSetMetaData(::rtl::Reference<connectivity::OSQLColumns> _xColumns, OUString _aTableName, OFileTable* _pTable); + + virtual sal_Int32 SAL_CALL getColumnCount( ) override; + virtual sal_Bool SAL_CALL isAutoIncrement( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isCaseSensitive( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isSearchable( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isCurrency( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL isNullable( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isSigned( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getColumnDisplaySize( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnLabel( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnName( sal_Int32 column ) override; + virtual OUString SAL_CALL getSchemaName( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getPrecision( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getScale( sal_Int32 column ) override; + virtual OUString SAL_CALL getTableName( sal_Int32 column ) override; + virtual OUString SAL_CALL getCatalogName( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getColumnType( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnTypeName( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isReadOnly( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isWritable( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isDefinitelyWritable( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnServiceName( sal_Int32 column ) override; + }; + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FStatement.hxx b/connectivity/source/inc/file/FStatement.hxx new file mode 100644 index 0000000000..57ce0a2fc0 --- /dev/null +++ b/connectivity/source/inc/file/FStatement.hxx @@ -0,0 +1,196 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/sdbc/XStatement.hpp> +#include <com/sun/star/sdbc/XWarningsSupplier.hpp> +#include <com/sun/star/sdbc/XCloseable.hpp> +#include <com/sun/star/sdbc/SQLWarning.hpp> +#include <com/sun/star/util/XCancellable.hpp> +#include <comphelper/proparrhlp.hxx> +#include <cppuhelper/compbase.hxx> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/basemutex.hxx> +#include <connectivity/CommonTools.hxx> +#include <connectivity/sqlparse.hxx> +#include <file/FConnection.hxx> +#include <file/filedllapi.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <comphelper/propertycontainer.hxx> +#include <file/fanalyzer.hxx> +#include <TSortIndex.hxx> + +namespace connectivity::file + { + class OResultSet; + class OFileTable; + typedef ::cppu::WeakComponentImplHelper< css::sdbc::XWarningsSupplier, + css::util::XCancellable, + css::sdbc::XCloseable> OStatement_BASE; + + + //************ Class: java.sql.Statement + + class OOO_DLLPUBLIC_FILE OStatement_Base : + public cppu::BaseMutex, + public OStatement_BASE, + public ::comphelper::OPropertyContainer, + public ::comphelper::OPropertyArrayUsageHelper<OStatement_Base> + + { + protected: + std::vector<sal_Int32> m_aColMapping; // pos 0 is unused so we don't have to decrement 1 every time + std::vector<sal_Int32> m_aParameterIndexes; // maps the parameter index to column index + std::vector<sal_Int32> m_aOrderbyColumnNumber; + std::vector<TAscendingOrder> m_aOrderbyAscending; + + css::sdbc::SQLWarning m_aLastWarning; + css::uno::WeakReference< css::sdbc::XResultSet> m_xResultSet; // The last ResultSet created + css::uno::Reference< css::sdbc::XDatabaseMetaData> m_xDBMetaData; + css::uno::Reference< css::container::XNameAccess> m_xColNames; // table columns // for this Statement + + + connectivity::OSQLParser m_aParser; + connectivity::OSQLParseTreeIterator m_aSQLIterator; + + rtl::Reference<OConnection> m_pConnection;// The owning Connection object + connectivity::OSQLParseNode* m_pParseTree; + std::unique_ptr<OSQLAnalyzer> m_pSQLAnalyzer; //the sql analyzer used by the resultset + + rtl::Reference<OFileTable> m_pTable; // the current table + OValueRefRow m_aSelectRow; + OValueRefRow m_aRow; + OValueRefRow m_aEvaluateRow; // contains all values of a row + ORefAssignValues m_aAssignValues; // needed for insert,update and parameters + // to compare with the restrictions + + OUString m_aCursorName; + sal_Int32 m_nMaxFieldSize; + sal_Int32 m_nMaxRows; + sal_Int32 m_nQueryTimeOut; + sal_Int32 m_nFetchSize; + sal_Int32 m_nResultSetType; + sal_Int32 m_nFetchDirection; + sal_Int32 m_nResultSetConcurrency; + bool m_bEscapeProcessing; + + protected: + // initialize the column index map (mapping select columns to table columns) + void createColumnMapping(); + // searches the statement for sort criteria + void analyzeSQL(); + void setOrderbyColumn( connectivity::OSQLParseNode const * pColumnRef, + connectivity::OSQLParseNode const * pAscendingDescending); + + virtual void initializeResultSet(OResultSet* _pResult); + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void closeResultSet(); + + void disposeResultSet(); + void GetAssignValues(); + void SetAssignValue(const OUString& aColumnName, + const OUString& aValue, + bool bSetNull = false, + sal_uInt32 nParameter=SQL_NO_PARAMETER); + void ParseAssignValues( const std::vector< OUString>& aColumnNameList, + connectivity::OSQLParseNode* pRow_Value_Constructor_Elem, sal_Int32 nIndex); + + virtual void parseParamterElem(const OUString& _sColumnName,OSQLParseNode* pRow_Value_Constructor_Elem); + // factory method for resultset's + virtual rtl::Reference<OResultSet> createResultSet() = 0; + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override; + // OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + virtual ~OStatement_Base() override; + public: + connectivity::OSQLParseNode* getParseTree() const { return m_pParseTree;} + + OStatement_Base(OConnection* _pConnection ); + + OConnection* getOwnConnection() const { return m_pConnection.get(); } + + using OStatement_BASE::operator css::uno::Reference< css::uno::XInterface >; + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + virtual void construct(const OUString& sql); + + // OComponentHelper + virtual void SAL_CALL disposing() override; + // XInterface + // virtual void SAL_CALL release() throw(css::uno::RuntimeException) = 0; + virtual void SAL_CALL acquire() noexcept override; + // XInterface + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + + // XPropertySet + virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; + // XWarningsSupplier + virtual css::uno::Any SAL_CALL getWarnings( ) override; + virtual void SAL_CALL clearWarnings( ) override; + // XCancellable + virtual void SAL_CALL cancel( ) override; + // XCloseable + virtual void SAL_CALL close( ) override; + }; + + class OOO_DLLPUBLIC_FILE OStatement_BASE2 : public OStatement_Base + + { + public: + OStatement_BASE2(OConnection* _pConnection ) : OStatement_Base(_pConnection ) {} + // OComponentHelper + virtual void SAL_CALL disposing() override; + // XInterface + virtual void SAL_CALL release() noexcept override; + }; + + typedef ::cppu::ImplHelper2< css::sdbc::XStatement,css::lang::XServiceInfo > OStatement_XStatement; + class OOO_DLLPUBLIC_FILE OStatement : + public OStatement_BASE2, + public OStatement_XStatement + { + protected: + // factory method for resultset's + virtual rtl::Reference<OResultSet> createResultSet() override; + public: + // a Constructor, that is needed for when Returning the Object is needed: + OStatement( OConnection* _pConnection) : OStatement_BASE2( _pConnection){} + DECLARE_SERVICE_INFO(); + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + + // XStatement + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL executeQuery( const OUString& sql ) override ; + virtual sal_Int32 SAL_CALL executeUpdate( const OUString& sql ) override ; + virtual sal_Bool SAL_CALL execute( const OUString& sql ) override ; + virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( ) override ; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FStringFunctions.hxx b/connectivity/source/inc/file/FStringFunctions.hxx new file mode 100644 index 0000000000..b3d72294fa --- /dev/null +++ b/connectivity/source/inc/file/FStringFunctions.hxx @@ -0,0 +1,269 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/fcode.hxx> + +namespace connectivity::file + { + /** UCASE(str) + UPPER(str) + Returns the string str with all characters changed to uppercase according to the current character set mapping (the default is ISO-8859-1 Latin1): + + > SELECT UCASE('Hej'); + -> 'HEJ' + + */ + class OOp_Upper : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** LCASE(str) + LOWER(str) + Returns the string str with all characters changed to lowercase according to the current character set mapping (the default is ISO-8859-1 Latin1): + + > SELECT LCASE('QUADRATICALLY'); + -> 'quadratically' + + */ + class OOp_Lower : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** ASCII(str) + Returns the ASCII code value of the leftmost character of the string str. Returns 0 if str is the empty string. Returns NULL if str is NULL: + + > SELECT ASCII('2'); + -> 50 + > SELECT ASCII(2); + -> 50 + > SELECT ASCII('dx'); + -> 100 + + */ + class OOp_Ascii : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** LENGTH(str) + OCTET_LENGTH(str) + CHAR_LENGTH(str) + CHARACTER_LENGTH(str) + Returns the length of the string str: + + > SELECT LENGTH('text'); + -> 4 + > SELECT OCTET_LENGTH('text'); + -> 4 + + */ + class OOp_CharLength : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** CHAR(N,...) + CHAR() interprets the arguments as integers and returns a string consisting of the characters given by the ASCII code values of those integers. NULL values are skipped: + + > SELECT CHAR(ascii('t'),ascii('e'),ascii('s'),ascii('t')); + -> 'test' + > SELECT CHAR(77,77.3,'77.3'); + -> 'MMM' + + */ + class OOp_Char : public ONthOperator + { + protected: + virtual ORowSetValue operate(const std::vector<ORowSetValue>& lhs) const override; + }; + + /** CONCAT(str1,str2,...) + Returns the string that results from concatenating the arguments. Returns NULL if any argument is NULL. May have more than 2 arguments. A numeric argument is converted to the equivalent string form: + + > SELECT CONCAT('OO', 'o', 'OO'); + -> 'OOoOO' + > SELECT CONCAT('OO', NULL, 'OO'); + -> NULL + > SELECT CONCAT(14.3); + -> '14.3' + + */ + class OOp_Concat : public ONthOperator + { + protected: + virtual ORowSetValue operate(const std::vector<ORowSetValue>& lhs) const override; + }; + + /** LOCATE(substr,str) + POSITION(substr IN str) + Returns the position of the first occurrence of substring substr in string str. Returns 0 if substr is not in str: + + > SELECT LOCATE('bar', 'foobarbar'); + -> 4 + > SELECT LOCATE('xbar', 'foobar'); + -> 0 + LOCATE(substr,str,pos) + Returns the position of the first occurrence of substring substr in string str, starting at position pos. Returns 0 if substr is not in str: + + > SELECT LOCATE('bar', 'foobarbar',5); + -> 7 + + */ + class OOp_Locate : public ONthOperator + { + protected: + virtual ORowSetValue operate(const std::vector<ORowSetValue>& lhs) const override; + }; + + /** SUBSTRING(str,pos) + SUBSTRING(str FROM pos) + Returns a substring from string str starting at position pos: + + > SELECT SUBSTRING('Quadratically',5); + -> 'ratically' + > SELECT SUBSTRING('foobarbar' FROM 4); + -> 'barbar' + SUBSTRING(str,pos,len) + SUBSTRING(str FROM pos FOR len) + Returns a substring len characters long from string str, starting at position pos. The variant form that uses FROM is SQL-92 syntax: + + > SELECT SUBSTRING('Quadratically',5,6); + -> 'ratica' + + */ + class OOp_SubString : public ONthOperator + { + protected: + virtual ORowSetValue operate(const std::vector<ORowSetValue>& lhs) const override; + }; + + /** LTRIM(str) + Returns the string str with leading space characters removed: + + > SELECT LTRIM(' barbar'); + -> 'barbar' + + */ + class OOp_LTrim : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** RTRIM(str) + Returns the string str with trailing space characters removed: + + > SELECT RTRIM('barbar '); + -> 'barbar' + + */ + class OOp_RTrim : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** SPACE(N) + Returns a string consisting of N space characters: + + > SELECT SPACE(6); + -> ' ' + + */ + class OOp_Space : public OUnaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs) const override; + }; + + /** REPLACE(str,from_str,to_str) + Returns the string str with all occurrences of the string from_str replaced by the string to_str: + + > SELECT REPLACE('www.OOo.com', 'w', 'Ww'); + -> 'WwWwWw.OOo.com' + + */ + class OOp_Replace : public ONthOperator + { + protected: + virtual ORowSetValue operate(const std::vector<ORowSetValue>& lhs) const override; + }; + + /** REPEAT(str,count) + Returns a string consisting of the string str repeated count times. If count <= 0, returns an empty string. Returns NULL if str or count are NULL: + + > SELECT REPEAT('OOo', 3); + -> 'OOoOOoOOo' + + */ + class OOp_Repeat : public OBinaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const override; + }; + + /** INSERT(str,pos,len,newstr) + Returns the string str, with the substring beginning at position pos and len characters long replaced by the string newstr: + + > SELECT INSERT('Quadratic', 3, 4, 'What'); + -> 'QuWhattic' + + */ + class OOp_Insert : public ONthOperator + { + protected: + virtual ORowSetValue operate(const std::vector<ORowSetValue>& lhs) const override; + }; + + /** LEFT(str,len) + Returns the leftmost len characters from the string str: + + > SELECT LEFT('foobarbar', 5); + -> 'fooba' + + */ + class OOp_Left : public OBinaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const override; + }; + + /** RIGHT(str,len) + Returns the rightmost len characters from the string str: + + > SELECT RIGHT('foobarbar', 4); + -> 'rbar' + */ + class OOp_Right : public OBinaryOperator + { + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FTable.hxx b/connectivity/source/inc/file/FTable.hxx new file mode 100644 index 0000000000..d8bbd92d6c --- /dev/null +++ b/connectivity/source/inc/file/FTable.hxx @@ -0,0 +1,99 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <connectivity/sdbcx/VTable.hxx> +#include <file/FConnection.hxx> +#include <file/filedllapi.hxx> +#include <tools/stream.hxx> +#include <connectivity/FValue.hxx> +#include <TResultSetHelper.hxx> + +namespace connectivity::file + { + typedef connectivity::sdbcx::OTable OTable_TYPEDEF; + + class OOO_DLLPUBLIC_FILE OFileTable : public OTable_TYPEDEF + { + protected: + OConnection* m_pConnection; + std::unique_ptr<SvStream> m_pFileStream; + ::rtl::Reference<OSQLColumns> m_aColumns; + sal_Int32 m_nFilePos; // current IResultSetHelper::Movement + std::unique_ptr<sal_uInt8[]> m_pBuffer; + sal_uInt16 m_nBufferSize; // size of the ReadBuffer, if pBuffer != NULL + bool m_bWriteable; // svstream can't say if we are writeable + // so we have to + + virtual void FileClose(); + virtual ~OFileTable( ) override; + public: + virtual void refreshColumns() override; + virtual void refreshKeys() override; + virtual void refreshIndexes() override; + public: + OFileTable( sdbcx::OCollection* _pTables,OConnection* _pConnection); + OFileTable( sdbcx::OCollection* _pTables,OConnection* _pConnection, + const OUString& Name, + const OUString& Type, + const OUString& Description, + const OUString& SchemaName, + const OUString& CatalogName + ); + + //XInterface + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + // ::cppu::OComponentHelper + virtual void SAL_CALL disposing() override; + + OConnection* getConnection() const { return m_pConnection;} + virtual sal_Int32 getCurrentLastPos() const {return -1;} + + virtual bool seekRow(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOffset, sal_Int32& nCurPos) = 0; + virtual bool fetchRow(OValueRefRow& _rRow, const OSQLColumns& _rCols, bool bRetrieveData) = 0; + + const ::rtl::Reference<OSQLColumns>& getTableColumns() const {return m_aColumns;} + virtual bool InsertRow(OValueRefVector& rRow, const css::uno::Reference< css::container::XIndexAccess>& _xCols); + virtual bool DeleteRow(const OSQLColumns& _rCols); + virtual bool UpdateRow(OValueRefVector& rRow, OValueRefRow& pOrgRow,const css::uno::Reference< css::container::XIndexAccess>& _xCols); + virtual void addColumn(const css::uno::Reference< css::beans::XPropertySet>& descriptor); + virtual void dropColumn(sal_Int32 _nPos); + // refresh the header of file based tables to see changes done by someone + virtual void refreshHeader(); + + OUString SAL_CALL getName() override { return m_Name; } + + const OUString& getSchema() const { return m_SchemaName; } + bool isReadOnly() const { return !m_bWriteable; } + // m_pFileStream && !m_pFileStream->IsWritable(); } + + sal_Int32 getFilePos() const { return m_nFilePos; } + + public: + // helper + + // creates a stream using ::utl::UcbStreamHelper::CreateStream, but the error is simplified + // (NULL or non-NULL is returned) + static std::unique_ptr<SvStream> createStream_simpleError( const OUString& _rFileName, StreamMode _eOpenMode); + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FTables.hxx b/connectivity/source/inc/file/FTables.hxx new file mode 100644 index 0000000000..9d14c36279 --- /dev/null +++ b/connectivity/source/inc/file/FTables.hxx @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/filedllapi.hxx> +#include <connectivity/sdbcx/VCollection.hxx> +#include <com/sun/star/sdbc/XDatabaseMetaData.hpp> + +namespace connectivity::file + { + class OOO_DLLPUBLIC_FILE SAL_NO_VTABLE OTables : + public sdbcx::OCollection + { + protected: + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + public: + OTables(const css::uno::Reference< css::sdbc::XDatabaseMetaData >& _rMetaData,::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector) : sdbcx::OCollection(_rParent,_rMetaData->supportsMixedCaseQuotedIdentifiers(),_rMutex,_rVector) + {} + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/fanalyzer.hxx b/connectivity/source/inc/file/fanalyzer.hxx new file mode 100644 index 0000000000..f913529d26 --- /dev/null +++ b/connectivity/source/inc/file/fanalyzer.hxx @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/fcomp.hxx> + +namespace connectivity::file + { + class OConnection; + class OSQLAnalyzer final + { + typedef std::pair< ::rtl::Reference<OPredicateCompiler>,::rtl::Reference<OPredicateInterpreter> > TPredicates; + + std::vector< TPredicates > m_aSelectionEvaluations; + ::rtl::Reference<OPredicateCompiler> m_aCompiler; + ::rtl::Reference<OPredicateInterpreter> m_aInterpreter; + OConnection* m_pConnection; + + mutable bool m_bHasSelectionCode; + mutable bool m_bSelectionFirstTime; + + static void bindRow(OCodeList& rCodeList,const OValueRefRow& _pRow); + + public: + OSQLAnalyzer(OConnection* _pConnection); + ~OSQLAnalyzer(); + + OConnection* getConnection() const { return m_pConnection; } + void bindEvaluationRow(OValueRefRow const & _pRow); // Bind an evaluation row to the restriction + /** bind the select columns if they contain a function which needs a row value + @param _pRow the result row + */ + void bindSelectRow(const OValueRefRow& _pRow); + + /** binds the row to parameter for the restrictions + @param _pRow the parameter row + */ + void bindParameterRow(OValueRefRow const & _pRow); + + void dispose(); + void start(OSQLParseNode const * pSQLParseNode); + bool hasRestriction() const; + bool hasFunctions() const; + bool evaluateRestriction() { return m_aInterpreter->start(); } + void setSelectionEvaluationResult(OValueRefRow const & _pRow,const std::vector<sal_Int32>& _rColumnMapping); + void setOrigColumns(const css::uno::Reference< css::container::XNameAccess>& rCols); + static OOperandAttr* createOperandAttr(sal_Int32 _nPos, + const css::uno::Reference< css::beans::XPropertySet>& _xCol); + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/fcode.hxx b/connectivity/source/inc/file/fcode.hxx new file mode 100644 index 0000000000..daadbf880f --- /dev/null +++ b/connectivity/source/inc/file/fcode.hxx @@ -0,0 +1,331 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <connectivity/sqliterator.hxx> +#include <com/sun/star/sdbc/DataType.hpp> +#include <connectivity/FValue.hxx> +#include <file/filedllapi.hxx> + +#include <stack> +#include <utility> + +namespace connectivity +{ + class OSQLParseNode; + namespace file + { + + class OOperand; + typedef std::stack<OOperand*> OCodeStack; + + class OOO_DLLPUBLIC_FILE OCode + { + public: + //virtual dtor to allow this to be the root of the class hierarchy + virtual ~OCode(); + //but that disables the default move ctor + OCode(OCode&&) = default; + //but that disables the rest of default ctors + OCode(const OCode&) = default; + OCode() = default; + //and same issue for the assignment operators + OCode& operator=(const OCode&) = default; + OCode& operator=(OCode&&) = default; + }; + + + // operands that the parsetree generate + class OOO_DLLPUBLIC_FILE OOperand : public OCode + { + protected: + sal_Int32 m_eDBType; + + OOperand(sal_Int32 _rType) : m_eDBType(_rType){} + OOperand() : m_eDBType(css::sdbc::DataType::OTHER){} + + public: + virtual const ORowSetValue& getValue() const = 0; + virtual void setValue(const ORowSetValue& _rVal) = 0; + + sal_Int32 getDBType() const {return m_eDBType;} + inline bool isValid() const; + + }; + + class OOperandRow : public OOperand + { + sal_uInt16 m_nRowPos; + OValueRefRow m_pRow; + + protected: + OOperandRow(sal_uInt16 _nPos, sal_Int32 _rType); + public: + virtual const ORowSetValue& getValue() const override; + virtual void setValue(const ORowSetValue& _rVal) override; + void bindValue(const OValueRefRow& _pRow); // Bind to the value that the operand represents + + }; + + // Attributes from a result row + class OOperandAttr : public OOperandRow + { + public: + OOperandAttr(sal_uInt16 _nPos, + const css::uno::Reference< css::beans::XPropertySet>& _xColumn); + + }; + + // Parameter for a predicate + class OOperandParam : public OOperandRow + { + public: + OOperandParam(sal_Int32 _nPos); + }; + + // Value operands + class OOperandValue : public OOperand + { + protected: + ORowSetValue m_aValue; + + protected: + OOperandValue(){} + OOperandValue(ORowSetValue _aVar, sal_Int32 eDbType) + : OOperand(eDbType) + , m_aValue(std::move(_aVar)) + {} + + OOperandValue(sal_Int32 eDbType) :OOperand(eDbType){} + public: + virtual const ORowSetValue& getValue() const override; + virtual void setValue(const ORowSetValue& _rVal) override; + + }; + + + // Constants + class OOperandConst : public OOperandValue + { + public: + OOperandConst(const connectivity::OSQLParseNode& rColumnRef, const OUString& aStrValue); + + }; + + + // Result operands + class OOperandResult : public OOperandValue + { + protected: + OOperandResult(sal_Int32 eDbType) + :OOperandValue(eDbType) {} + public: + OOperandResult(const ORowSetValue& _rVar) + :OOperandValue(_rVar, _rVar.getTypeKind()) {} + }; + + + class OOperandResultBOOL : public OOperandResult + { + public: + OOperandResultBOOL(bool bResult) : OOperandResult(css::sdbc::DataType::BIT) + { + m_aValue = bResult ? 1.0 : 0.0; + m_aValue.setBound(true); + } + }; + + class OOperandResultNUM : public OOperandResult + { + public: + OOperandResultNUM(double fNum) : OOperandResult(css::sdbc::DataType::DOUBLE) + { + m_aValue = fNum; + m_aValue.setBound(true); + } + }; + + /** special stop operand + is appended when a list of arguments ends + */ + class OStopOperand : public OOperandValue + { + public: + OStopOperand(){} + }; + + // Operators + class OOO_DLLPUBLIC_FILE OOperator : public OCode + { + public: + virtual void Exec(OCodeStack&) = 0; + }; + + + // Boolean operators + class OOO_DLLPUBLIC_FILE OBoolOperator : public OOperator + { + public: + virtual void Exec(OCodeStack&) override; + virtual bool operate(const OOperand*, const OOperand*) const; + }; + + class OOp_NOT : public OBoolOperator + { + public: + + protected: + virtual void Exec(OCodeStack&) override; + virtual bool operate(const OOperand*, const OOperand*) const override; + }; + + class OOp_AND : public OBoolOperator + { + public: + + protected: + virtual bool operate(const OOperand*, const OOperand*) const override; + }; + + class OOp_OR : public OBoolOperator + { + public: + protected: + virtual bool operate(const OOperand*, const OOperand*) const override; + }; + + class OOO_DLLPUBLIC_FILE OOp_ISNULL : public OBoolOperator + { + public: + public: + virtual void Exec(OCodeStack&) override; + virtual bool operate(const OOperand*, const OOperand*) const override; + }; + + class OOO_DLLPUBLIC_FILE OOp_ISNOTNULL : public OOp_ISNULL + { + public: + virtual bool operate(const OOperand*, const OOperand*) const override; + }; + + class OOO_DLLPUBLIC_FILE OOp_LIKE : public OBoolOperator + { + const sal_Unicode cEscape; + + public: + OOp_LIKE(const sal_Unicode cEsc):cEscape(cEsc){}; + + virtual bool operate(const OOperand*, const OOperand*) const override; + }; + + class OOp_NOTLIKE : public OOp_LIKE + { + public: + public: + OOp_NOTLIKE(const sal_Unicode cEsc):OOp_LIKE(cEsc){}; + + virtual bool operate(const OOperand*, const OOperand*) const override; + }; + + class OOO_DLLPUBLIC_FILE OOp_COMPARE : public OBoolOperator + { + sal_Int32 aPredicateType; + + public: + OOp_COMPARE(sal_Int32 aPType) + :aPredicateType(aPType) {} + + sal_Int32 getPredicateType() const { return aPredicateType; } + virtual bool operate(const OOperand*, const OOperand*) const override; + }; + + // Numerical operators + class ONumOperator : public OOperator + { + public: + virtual void Exec(OCodeStack&) override; + + + protected: + virtual double operate(const double& fLeft,const double& fRight) const = 0; + }; + + class OOp_ADD : public ONumOperator + { + protected: + virtual double operate(const double& fLeft,const double& fRight) const override; + }; + + class OOp_SUB : public ONumOperator + { + protected: + virtual double operate(const double& fLeft,const double& fRight) const override; + }; + + class OOp_MUL : public ONumOperator + { + protected: + virtual double operate(const double& fLeft,const double& fRight) const override; + }; + + class OOp_DIV : public ONumOperator + { + protected: + virtual double operate(const double& fLeft,const double& fRight) const override; + }; + + inline bool OOperand::isValid() const + { + return getValue().getDouble() != 0.0; + } + + // Operator + class ONthOperator : public OOperator + { + public: + virtual void Exec(OCodeStack&) override; + + + protected: + virtual ORowSetValue operate(const std::vector<ORowSetValue>& lhs) const = 0; + }; + + class OBinaryOperator : public OOperator + { + public: + virtual void Exec(OCodeStack&) override; + + + protected: + virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const = 0; + }; + + class OUnaryOperator : public OOperator + { + public: + virtual void Exec(OCodeStack&) override; + virtual ORowSetValue operate(const ORowSetValue& lhs) const = 0; + + + }; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/fcomp.hxx b/connectivity/source/inc/file/fcomp.hxx new file mode 100644 index 0000000000..72afcdb0a8 --- /dev/null +++ b/connectivity/source/inc/file/fcomp.hxx @@ -0,0 +1,111 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <file/fcode.hxx> +#include <utility> + +namespace connectivity +{ + class OSQLParseNode; + namespace file + { + class OCode; + class OOperand; + class OSQLAnalyzer; + typedef std::vector<std::unique_ptr<OCode>> OCodeList; + + class OPredicateCompiler final : public ::salhelper::SimpleReferenceObject + { + friend class OPredicateInterpreter; + friend class OSQLAnalyzer; + + OCodeList m_aCodeList; + css::uno::Reference< css::container::XNameAccess> m_orgColumns; // in filecurs this are the filecolumns + OSQLAnalyzer* m_pAnalyzer; + sal_Int32 m_nParamCounter; + public: + OPredicateCompiler(OSQLAnalyzer* pAnalyzer); + + virtual ~OPredicateCompiler() override; + + void dispose(); + + void start(connectivity::OSQLParseNode const * pSQLParseNode); + OOperand* execute(connectivity::OSQLParseNode const * pPredicateNode); + + void Clean(); + bool isClean() const {return m_aCodeList.empty();} + bool hasCode() const {return !isClean();} + void setOrigColumns(const css::uno::Reference< css::container::XNameAccess>& rCols) { m_orgColumns = rCols; } + const css::uno::Reference< css::container::XNameAccess>& getOrigColumns() const { return m_orgColumns; } + private: + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void execute_COMPARE(connectivity::OSQLParseNode const * pPredicateNode); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void execute_LIKE(connectivity::OSQLParseNode const * pPredicateNode); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void execute_BETWEEN(connectivity::OSQLParseNode const * pPredicateNode); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void execute_ISNULL(connectivity::OSQLParseNode const * pPredicateNode); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + OOperand* execute_Operand(connectivity::OSQLParseNode const * pPredicateNode); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void execute_Fold(OSQLParseNode const * pPredicateNode); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void executeFunction(OSQLParseNode const * pPredicateNode); + }; + + + class OPredicateInterpreter : + public ::salhelper::SimpleReferenceObject + { + OCodeStack m_aStack; + ::rtl::Reference<OPredicateCompiler> m_rCompiler; + + public: + OPredicateInterpreter(::rtl::Reference<OPredicateCompiler> xComp) : m_rCompiler(std::move(xComp)){} + virtual ~OPredicateInterpreter() override; + + bool evaluate(OCodeList& rCodeList); + void evaluateSelection(OCodeList& rCodeList, ORowSetValueDecoratorRef const & _rVal); + + bool start() + { + return evaluate(m_rCompiler->m_aCodeList); + } + + void startSelection(ORowSetValueDecoratorRef const & _rVal) + { + evaluateSelection(m_rCompiler->m_aCodeList,_rVal); + } + + + }; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/filedllapi.hxx b/connectivity/source/inc/file/filedllapi.hxx new file mode 100644 index 0000000000..e32f5f17cb --- /dev/null +++ b/connectivity/source/inc/file/filedllapi.hxx @@ -0,0 +1,32 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sal/config.h> + +#include <sal/types.h> + +#if defined OOO_DLLIMPLEMENTATION_FILE +#define OOO_DLLPUBLIC_FILE SAL_DLLPUBLIC_EXPORT +#else +#define OOO_DLLPUBLIC_FILE SAL_DLLPUBLIC_IMPORT +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/quotedstring.hxx b/connectivity/source/inc/file/quotedstring.hxx new file mode 100644 index 0000000000..7c6becc37f --- /dev/null +++ b/connectivity/source/inc/file/quotedstring.hxx @@ -0,0 +1,46 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <rtl/ustring.hxx> +#include <file/filedllapi.hxx> + +namespace connectivity +{ + + // Derived from String, overriding GetToken/GetTokenCount methods + // Especially true for the flat file format: Strings can be quoted + + class OOO_DLLPUBLIC_FILE QuotedTokenizedString + { + OUString m_sString; + public: + QuotedTokenizedString() {} + + sal_Int32 GetTokenCount( sal_Unicode cTok , sal_Unicode cStrDel ) const; + OUString GetTokenSpecial(sal_Int32& nStartPos, sal_Unicode cTok, sal_Unicode cStrDel = '\0') const; + OUString& GetString() { return m_sString; } + void SetString(const OUString& aStr) { m_sString = aStr;} + sal_Int32 Len() const { return m_sString.getLength(); } + operator OUString&() { return m_sString; } + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/flat/ECatalog.hxx b/connectivity/source/inc/flat/ECatalog.hxx new file mode 100644 index 0000000000..d1252e464c --- /dev/null +++ b/connectivity/source/inc/flat/ECatalog.hxx @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FCatalog.hxx> + +namespace connectivity::flat + { + class OFlatConnection; + class OFlatCatalog : public file::OFileCatalog + { + public: + virtual void refreshTables() override; + + public: + OFlatCatalog(OFlatConnection* _pCon); + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/flat/EColumns.hxx b/connectivity/source/inc/flat/EColumns.hxx new file mode 100644 index 0000000000..d25f79aae2 --- /dev/null +++ b/connectivity/source/inc/flat/EColumns.hxx @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FColumns.hxx> + +namespace connectivity::flat + { + class OFlatColumns : public file::OColumns + { + protected: + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + public: + OFlatColumns(file::OFileTable* _pTable, + ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector + ) : file::OColumns(_pTable,_rMutex,_rVector) + {} + + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/flat/EConnection.hxx b/connectivity/source/inc/flat/EConnection.hxx new file mode 100644 index 0000000000..be7c3596d4 --- /dev/null +++ b/connectivity/source/inc/flat/EConnection.hxx @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FConnection.hxx> + +namespace connectivity::flat + { + class ODriver; + class OFlatConnection : public file::OConnection + { + private: + sal_Int32 m_nMaxRowsToScan; + bool m_bHeaderLine; // column names in first row + sal_Unicode m_cFieldDelimiter; // look at the name + sal_Unicode m_cStringDelimiter; + sal_Unicode m_cDecimalDelimiter; + sal_Unicode m_cThousandDelimiter; + public: + OFlatConnection(ODriver* _pDriver); + virtual ~OFlatConnection() override; + + virtual void construct(const OUString& _rUrl,const css::uno::Sequence< css::beans::PropertyValue >& _rInfo ) override; + + // own methods + bool isHeaderLine() const { return m_bHeaderLine; } + sal_Unicode getFieldDelimiter() const { return m_cFieldDelimiter; } + sal_Unicode getStringDelimiter() const { return m_cStringDelimiter; } + sal_Unicode getDecimalDelimiter() const { return m_cDecimalDelimiter; } + sal_Unicode getThousandDelimiter() const { return m_cThousandDelimiter;} + sal_Int32 getMaxRowsToScan() const { return m_nMaxRowsToScan;} + // XServiceInfo + DECLARE_SERVICE_INFO(); + + // XConnection + virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( ) override; + virtual css::uno::Reference< css::sdbcx::XTablesSupplier > createCatalog() override; + virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement( ) override; + virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const OUString& sql ) override; + virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall( const OUString& sql ) override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/flat/EDatabaseMetaData.hxx b/connectivity/source/inc/flat/EDatabaseMetaData.hxx new file mode 100644 index 0000000000..bd6ce77581 --- /dev/null +++ b/connectivity/source/inc/flat/EDatabaseMetaData.hxx @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FDatabaseMetaData.hxx> + +namespace connectivity::flat + { + + //************ Class: java.sql.DatabaseMetaDataDate + + + class OFlatDatabaseMetaData : public file::ODatabaseMetaData + { + virtual css::uno::Reference< css::sdbc::XResultSet > impl_getTypeInfo_throw() override; + protected: + virtual ~OFlatDatabaseMetaData() override; + public: + OFlatDatabaseMetaData(file::OConnection* _pCon); + + virtual OUString SAL_CALL getURL( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getColumns( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern, const OUString& columnNamePattern ) override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/flat/EDriver.hxx b/connectivity/source/inc/flat/EDriver.hxx new file mode 100644 index 0000000000..7ed2718f20 --- /dev/null +++ b/connectivity/source/inc/flat/EDriver.hxx @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <connectivity/CommonTools.hxx> +#include <file/FDriver.hxx> + +namespace connectivity::flat + { + /// @throws css::uno::Exception + css::uno::Reference< css::uno::XInterface > ODriver_CreateInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory); + + class ODriver : public file::OFileDriver + { + public: + ODriver(const css::uno::Reference< css::uno::XComponentContext >& _rxContext) : file::OFileDriver(_rxContext){} + + OUString SAL_CALL getImplementationName( ) override; + // XDriver + virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL connect( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + virtual sal_Bool SAL_CALL acceptsURL( const OUString& url ) override; + virtual css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/flat/EPreparedStatement.hxx b/connectivity/source/inc/flat/EPreparedStatement.hxx new file mode 100644 index 0000000000..ca164be8d5 --- /dev/null +++ b/connectivity/source/inc/flat/EPreparedStatement.hxx @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FPreparedStatement.hxx> + +namespace connectivity::flat + { + class OConnection; + class OFlatPreparedStatement : public file::OPreparedStatement + { + protected: + virtual rtl::Reference<file::OResultSet> createResultSet() override; + public: + OFlatPreparedStatement( file::OConnection* _pConnection) : file::OPreparedStatement( _pConnection){} + DECLARE_SERVICE_INFO(); + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/flat/EResultSet.hxx b/connectivity/source/inc/flat/EResultSet.hxx new file mode 100644 index 0000000000..8d99ed55da --- /dev/null +++ b/connectivity/source/inc/flat/EResultSet.hxx @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FResultSet.hxx> +#include <com/sun/star/sdbcx/XRowLocate.hpp> +#include <cppuhelper/implbase1.hxx> + +namespace connectivity::flat + { + class OFlatResultSet; + // these typedef's are only necessary for the compiler + typedef ::cppu::ImplHelper1< css::sdbcx::XRowLocate> OFlatResultSet_BASE; + typedef file::OResultSet OFlatResultSet_BASE2; + typedef ::comphelper::OPropertyArrayUsageHelper<OFlatResultSet> OFlatResultSet_BASE3; + + + class OFlatResultSet : public OFlatResultSet_BASE2, + public OFlatResultSet_BASE, + public OFlatResultSet_BASE3 + { + bool m_bBookmarkable; + protected: + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override; + // OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + public: + DECLARE_SERVICE_INFO(); + + OFlatResultSet( file::OStatement_Base* pStmt,connectivity::OSQLParseTreeIterator& _aSQLIterator); + + // XInterface + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + // XPropertySet + virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; + + // XRowLocate + virtual css::uno::Any SAL_CALL getBookmark( ) override; + virtual sal_Bool SAL_CALL moveToBookmark( const css::uno::Any& bookmark ) override; + virtual sal_Bool SAL_CALL moveRelativeToBookmark( const css::uno::Any& bookmark, sal_Int32 rows ) override; + virtual sal_Int32 SAL_CALL compareBookmarks( const css::uno::Any& first, const css::uno::Any& second ) override; + virtual sal_Bool SAL_CALL hasOrderedBookmarks( ) override; + virtual sal_Int32 SAL_CALL hashBookmark( const css::uno::Any& bookmark ) override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/flat/EStatement.hxx b/connectivity/source/inc/flat/EStatement.hxx new file mode 100644 index 0000000000..d30bfc7097 --- /dev/null +++ b/connectivity/source/inc/flat/EStatement.hxx @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FStatement.hxx> + +namespace connectivity::flat + { + class OConnection; + class OFlatStatement : public file::OStatement + { + protected: + virtual rtl::Reference<file::OResultSet> createResultSet() override; + public: + OFlatStatement( file::OConnection* _pConnection) : file::OStatement( _pConnection){} + DECLARE_SERVICE_INFO(); + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/flat/ETable.hxx b/connectivity/source/inc/flat/ETable.hxx new file mode 100644 index 0000000000..99359edfdd --- /dev/null +++ b/connectivity/source/inc/flat/ETable.hxx @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FTable.hxx> +#include <flat/EConnection.hxx> +#include <connectivity/CommonTools.hxx> +#include <file/quotedstring.hxx> +#include <unotools/syslocale.hxx> +#include <com/sun/star/util/XNumberFormatter.hpp> + +namespace connectivity::flat + { + typedef file::OFileTable OFlatTable_BASE; + class OFlatConnection; + + typedef std::pair<sal_Int32, sal_Int32> TRowPositionInFile; + + class OFlatTable : public OFlatTable_BASE + { + // maps a row position to a file position + // row n is positions [m_aRowPosToFilePos[n]->first, m_aRowPosToFilePos[n]->second) in file + // "real" row indexes start at 1; for the purposes of m_aRowPosToFilePos, row 0 is headers + std::vector<TRowPositionInFile> + m_aRowPosToFilePos; + std::vector<sal_Int32> m_aTypes; // holds all type for columns just to avoid to ask the propertyset + std::vector<sal_Int32> m_aPrecisions; // same as aboth + std::vector<sal_Int32> m_aScales; + QuotedTokenizedString m_aCurrentLine; + css::uno::Reference< css::util::XNumberFormatter > m_xNumberFormatter; + css::util::Date m_aNullDate; + sal_Int32 m_nRowPos; + sal_Int32 m_nMaxRowCount; // will be set if stream is once eof + sal_Unicode m_cStringDelimiter; // delimiter for strings m_cStringDelimiter blabla m_cStringDelimiter + sal_Unicode m_cFieldDelimiter; // look at the name + bool m_bNeedToReadLine; + private: + void fillColumns(const css::lang::Locale& _aLocale); + bool readLine(sal_Int32 *pEndPos, sal_Int32 *pStartPos, bool nonEmpty = false); + void setRowPos(std::vector<TRowPositionInFile>::size_type rowNum, const TRowPositionInFile &rowPos); + void impl_fillColumnInfo_nothrow(QuotedTokenizedString const & aFirstLine, sal_Int32& nStartPosFirstLine, sal_Int32& nStartPosFirstLine2, + sal_Int32& io_nType, sal_Int32& io_nPrecisions, sal_Int32& io_nScales, OUString& o_sTypeName, + const sal_Unicode cDecimalDelimiter, const sal_Unicode cThousandDelimiter, const CharClass& aCharClass); + OFlatConnection* getFlatConnection() + { +#if OSL_DEBUG_LEVEL > 0 + OFlatConnection* pConnection = dynamic_cast<OFlatConnection*>(m_pConnection); + assert(pConnection); +#else + OFlatConnection* pConnection = static_cast<OFlatConnection*>(m_pConnection); +#endif + return pConnection; + } + public: + virtual void refreshColumns() override; + + public: + // DECLARE_CTY_DEFAULTS( OFlatTable_BASE); + OFlatTable( sdbcx::OCollection* _pTables,OFlatConnection* _pConnection, + const OUString& Name, + const OUString& Type, + const OUString& Description = OUString(), + const OUString& SchemaName = OUString(), + const OUString& CatalogName = OUString() + ); + + void construct() override; // can throw any exception + + virtual bool seekRow(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOffset, sal_Int32& nCurPos) override; + virtual bool fetchRow(OValueRefRow& _rRow, const OSQLColumns& _rCols, bool bRetrieveData) override; + virtual void refreshHeader() override; + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + virtual void SAL_CALL disposing() override; + + OUString getEntry() const; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/flat/ETables.hxx b/connectivity/source/inc/flat/ETables.hxx new file mode 100644 index 0000000000..cb9b032dbc --- /dev/null +++ b/connectivity/source/inc/flat/ETables.hxx @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FTables.hxx> + +namespace connectivity::flat + { + typedef file::OTables OFlatTables_BASE; + + class OFlatTables : public OFlatTables_BASE + { + protected: + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + public: + OFlatTables(const css::uno::Reference< css::sdbc::XDatabaseMetaData >& _rMetaData,::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector) : OFlatTables_BASE(_rMetaData,_rParent,_rMutex,_rVector) + {} + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HCatalog.hxx b/connectivity/source/inc/hsqldb/HCatalog.hxx new file mode 100644 index 0000000000..8d1da42de1 --- /dev/null +++ b/connectivity/source/inc/hsqldb/HCatalog.hxx @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <sdbcx/VCatalog.hxx> + +namespace connectivity::hsqldb + { + // please don't name the class the same name as in another namespaces + // some compilers have problems with this task as I noticed on windows + class OHCatalog : public connectivity::sdbcx::OCatalog + { + css::uno::Reference< css::sdbc::XConnection > m_xConnection; + + /** calls XDatabaseMetaData::getTables. + @param _sKindOfObject + The type of tables to be fetched. + @param _rNames + The container for the names to be filled. + */ + void refreshObjects(const css::uno::Sequence< OUString >& _sKindOfObject,::std::vector< OUString>& _rNames); + + public: + // implementation of the pure virtual methods + virtual void refreshTables() override; + virtual void refreshViews() override ; + virtual void refreshGroups() override; + virtual void refreshUsers() override ; + + public: + OHCatalog(const css::uno::Reference< css::sdbc::XConnection >& _xConnection); + + sdbcx::OCollection* getPrivateTables() const { return m_pTables.get(); } + sdbcx::OCollection* getPrivateViews() const { return m_pViews.get(); } + const css::uno::Reference< css::sdbc::XConnection >& getConnection() const { return m_xConnection; } + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + // ::cppu::OComponentHelper + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HColumns.hxx b/connectivity/source/inc/hsqldb/HColumns.hxx new file mode 100644 index 0000000000..c27645f458 --- /dev/null +++ b/connectivity/source/inc/hsqldb/HColumns.hxx @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once +#include <connectivity/TColumnsHelper.hxx> +#include <connectivity/sdbcx/VColumn.hxx> + +namespace connectivity::hsqldb + { + class OHSQLColumns : public OColumnsHelper + { + protected: + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + public: + OHSQLColumns( ::cppu::OWeakObject& _rParent + ,::osl::Mutex& _rMutex + ,const ::std::vector< OUString> &_rVector + ); + }; + + class OHSQLColumn; + typedef ::comphelper::OIdPropertyArrayUsageHelper<OHSQLColumn> OHSQLColumn_PROP; + + class OHSQLColumn : public sdbcx::OColumn, + public OHSQLColumn_PROP + { + OUString m_sAutoIncrement; + protected: + virtual ::cppu::IPropertyArrayHelper* createArrayHelper( sal_Int32 _nId) const override; + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + + public: + OHSQLColumn(); + virtual void construct() override; + + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HConnection.hxx b/connectivity/source/inc/hsqldb/HConnection.hxx new file mode 100644 index 0000000000..6e2a54c9ce --- /dev/null +++ b/connectivity/source/inc/hsqldb/HConnection.hxx @@ -0,0 +1,142 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <connectivity/ConnectionWrapper.hxx> +#include <com/sun/star/util/XFlushable.hpp> +#include <com/sun/star/sdbc/XDriver.hpp> +#include <com/sun/star/sdb/application/XTableUIProvider.hpp> +#include <cppuhelper/compbase.hxx> +#include <cppuhelper/basemutex.hxx> +#include <comphelper/uno3.hxx> +#include <comphelper/interfacecontainer2.hxx> + +namespace connectivity::hsqldb + { + class SAL_NO_VTABLE IMethodGuardAccess + { + public: + virtual ::osl::Mutex& getMutex() const = 0; + virtual void checkDisposed() const = 0; + + protected: + ~IMethodGuardAccess() {} + }; + + + // OHsqlConnection - wraps all methods to the real connection from the driver + // but when disposed it doesn't dispose the real connection + + typedef ::cppu::WeakComponentImplHelper< css::util::XFlushable + , css::sdb::application::XTableUIProvider + > OHsqlConnection_BASE; + + class OHsqlConnection :public cppu::BaseMutex + ,public OHsqlConnection_BASE + ,public OConnectionWrapper + ,public IMethodGuardAccess + { + private: + ::comphelper::OInterfaceContainerHelper2 m_aFlushListeners; + css::uno::Reference< css::sdbc::XDriver > m_xDriver; + css::uno::Reference< css::uno::XComponentContext > m_xContext; + bool m_bIni; + bool m_bReadOnly; + + protected: + virtual void SAL_CALL disposing() override; + virtual ~OHsqlConnection() override; + + public: + OHsqlConnection( + const css::uno::Reference< css::sdbc::XDriver >& _rxDriver, + const css::uno::Reference< css::sdbc::XConnection >& _xConnection, + const css::uno::Reference< css::uno::XComponentContext>& _rxContext + ); + + // XServiceInfo + DECLARE_SERVICE_INFO(); + DECLARE_XTYPEPROVIDER() + DECLARE_XINTERFACE( ) + + // IMethodGuardAccess + virtual ::osl::Mutex& getMutex() const override; + virtual void checkDisposed() const override; + + // XFlushable + virtual void SAL_CALL flush( ) override; + virtual void SAL_CALL addFlushListener( const css::uno::Reference< css::util::XFlushListener >& l ) override; + virtual void SAL_CALL removeFlushListener( const css::uno::Reference< css::util::XFlushListener >& l ) override; + + // XTableUIProvider + virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL getTableIcon( const OUString& TableName, ::sal_Int32 ColorMode ) override; + virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getTableEditor( const css::uno::Reference< css::sdb::application::XDatabaseDocumentUI >& DocumentUI, const OUString& TableName ) override; + + private: + + /** retrieves our table container + @return + our table container. Guaranteed to not be <NULL/>. + @throws css::lang::WrappedTargetException + if a non-RuntimeException is caught during obtaining the container. + @throws css::uno::RuntimeException + if a serious error occurs + @precond + We're not disposed. + */ + css::uno::Reference< css::container::XNameAccess > + impl_getTableContainer_throw(); + + /** checks whether the given table name denotes an existing table + @param _rTableName + the fully name of the table to check for existence + @throws css::lang::IllegalArgumentException + if the name does not denote an existing table + @precond + We're not disposed. + */ + void impl_checkExistingTable_throw( const OUString& _rTableName ); + + /** checks whether the given table name refers to a HSQL TEXT TABLE + */ + bool impl_isTextTable_nothrow( const OUString& _rTableName ); + + /** retrieves the icon for HSQL TEXT TABLEs + */ + css::uno::Reference< css::graphic::XGraphic > + impl_getTextTableIcon_nothrow(); + }; + + + // OHsqlConnection + + class MethodGuard : public ::osl::MutexGuard + { + public: + MethodGuard( const IMethodGuardAccess& _rComponent ) + : ::osl::MutexGuard( _rComponent.getMutex() ) + { + _rComponent.checkDisposed(); + } + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HDriver.hxx b/connectivity/source/inc/hsqldb/HDriver.hxx new file mode 100644 index 0000000000..0dda7e5e0f --- /dev/null +++ b/connectivity/source/inc/hsqldb/HDriver.hxx @@ -0,0 +1,123 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <com/sun/star/sdbc/XDriver.hpp> +#include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp> +#include <com/sun/star/sdbcx/XCreateCatalog.hpp> +#include <com/sun/star/embed/XTransactionListener.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <cppuhelper/compbase.hxx> +#include <cppuhelper/basemutex.hxx> +#include <connectivity/CommonTools.hxx> + + +namespace connectivity::hsqldb + { + typedef ::cppu::WeakComponentImplHelper< css::sdbc::XDriver + , css::sdbcx::XDataDefinitionSupplier + , css::lang::XServiceInfo + , css::sdbcx::XCreateCatalog + , css::embed::XTransactionListener + > ODriverDelegator_BASE; + + typedef std::pair< css::uno::WeakReferenceHelper,css::uno::WeakReferenceHelper> TWeakRefPair; + typedef std::pair< OUString ,TWeakRefPair > TWeakConnectionPair; + + typedef std::pair< css::uno::WeakReferenceHelper,TWeakConnectionPair> TWeakPair; + typedef std::vector< TWeakPair > TWeakPairVector; + + + /** delegates all calls to the original driver and extend the existing one with the SDBCX layer. + + */ + class ODriverDelegator final : public ::cppu::BaseMutex + ,public ODriverDelegator_BASE + { + TWeakPairVector m_aConnections; // vector containing a list + // of all the Connection objects + // for this Driver + css::uno::Reference< css::sdbc::XDriver > m_xDriver; + css::uno::Reference< css::uno::XComponentContext > m_xContext; + bool m_bInShutDownConnections; + + /** load the driver we want to delegate. + The <member>m_xDriver</member> may be <NULL/> if the driver could not be loaded. + @return + The driver which was currently selected. + */ + css::uno::Reference< css::sdbc::XDriver > const & loadDriver( ); + + /** shut down the connection and revoke the storage from the map + @param _aIter + The connection to shut down and storage to revoke. + */ + void shutdownConnection(const TWeakPairVector::iterator& _aIter); + + public: + /** creates a new delegator for a HSQLDB driver + */ + ODriverDelegator(const css::uno::Reference< css::uno::XComponentContext >& _rxContext); + + // XServiceInfo + DECLARE_SERVICE_INFO(); + + // XDriver + virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL connect( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + virtual sal_Bool SAL_CALL acceptsURL( const OUString& url ) override; + virtual css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + virtual sal_Int32 SAL_CALL getMajorVersion( ) override; + virtual sal_Int32 SAL_CALL getMinorVersion( ) override; + + // XDataDefinitionSupplier + virtual css::uno::Reference< css::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByConnection( const css::uno::Reference< css::sdbc::XConnection >& connection ) override; + virtual css::uno::Reference< css::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByURL( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + + // XCreateCatalog + virtual void SAL_CALL createCatalog( const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + + // XEventListener + virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override; + + // XTransactionListener + virtual void SAL_CALL preCommit( const css::lang::EventObject& aEvent ) override; + virtual void SAL_CALL commited( const css::lang::EventObject& aEvent ) override; + virtual void SAL_CALL preRevert( const css::lang::EventObject& aEvent ) override; + virtual void SAL_CALL reverted( const css::lang::EventObject& aEvent ) override; + + void shutdownConnections(); + void flushConnections(); + private: + /// dtor + virtual ~ODriverDelegator() override; + // OComponentHelper + virtual void SAL_CALL disposing() override; + + /** called when we connected to a newly created embedded database + */ + void onConnectedNewDatabase( + const css::uno::Reference< css::sdbc::XConnection >& _rxConnection + ); + }; + + +} // namespace connectivity::hsqldb + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HStorageAccess.hxx b/connectivity/source/inc/hsqldb/HStorageAccess.hxx new file mode 100644 index 0000000000..5a49162c2e --- /dev/null +++ b/connectivity/source/inc/hsqldb/HStorageAccess.hxx @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sal/config.h> + +#if defined __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-attributes" +#endif +#include <jni.h> +#if defined __clang__ +#pragma clang diagnostic pop +#endif + +namespace connectivity::hsqldb +{ + class DataLogFile; +} + +jint read_from_storage_stream( JNIEnv * env, jstring name, jstring key ); +jint read_from_storage_stream_into_buffer( JNIEnv * env, jstring name, jstring key, jbyteArray buffer, jint off, jint len ); +void write_to_storage_stream_from_buffer( JNIEnv* env, jstring name, jstring key, jbyteArray buffer, jint off, jint len ); +void write_to_storage_stream( JNIEnv* env, jstring name, jstring key, jint v ); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HStorageMap.hxx b/connectivity/source/inc/hsqldb/HStorageMap.hxx new file mode 100644 index 0000000000..1186c680ac --- /dev/null +++ b/connectivity/source/inc/hsqldb/HStorageMap.hxx @@ -0,0 +1,97 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <sal/config.h> + +#include <map> +#include <memory> + +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/embed/XTransactionListener.hpp> +#include <com/sun/star/io/XStream.hpp> +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XSeekable.hpp> + +#if defined __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-attributes" +#endif +#include <jni.h> +#if defined __clang__ +#pragma clang diagnostic pop +#endif + +#include <uno/environment.hxx> + +namespace connectivity::hsqldb + { + class StreamHelper + { + css::uno::Reference< css::io::XStream> m_xStream; + css::uno::Reference< css::io::XSeekable> m_xSeek; + css::uno::Reference< css::io::XOutputStream> m_xOutputStream; + css::uno::Reference< css::io::XInputStream> m_xInputStream; + public: + StreamHelper(const css::uno::Reference< css::io::XStream>& _xStream); + ~StreamHelper(); + + css::uno::Reference< css::io::XInputStream> const & getInputStream(); + css::uno::Reference< css::io::XOutputStream> const & getOutputStream(); + css::uno::Reference< css::io::XSeekable> const & getSeek(); + }; + + + typedef std::map< OUString, std::shared_ptr<StreamHelper> > TStreamMap; + + struct StorageData { + css::uno::Reference<css::embed::XStorage> storage; + css::uno::Environment storageEnvironment; + OUString url; + TStreamMap streams; + + css::uno::Reference<css::embed::XStorage> mapStorage() const; + }; + + typedef std::map<OUString, StorageData> TStorages; + /** contains all storages so far accessed. + */ + class StorageContainer + { + public: + static OUString registerStorage(const css::uno::Reference< css::embed::XStorage>& _xStorage,const OUString& _sURL); + static TStorages::mapped_type getRegisteredStorage(const OUString& _sKey); + static OUString getRegisteredKey(const css::uno::Reference< css::embed::XStorage>& _xStorage); + static void revokeStorage(const OUString& _sKey,const css::uno::Reference< css::embed::XTransactionListener>& _xListener); + + static TStreamMap::mapped_type registerStream(JNIEnv * env,jstring name, jstring key,sal_Int32 _nMode); + static void revokeStream(JNIEnv * env,jstring name, jstring key); + static TStreamMap::mapped_type getRegisteredStream( JNIEnv * env, jstring name, jstring key); + + static OUString jstring2ustring(JNIEnv * env, jstring jstr); + static OUString removeURLPrefix(std::u16string_view _sURL, std::u16string_view _sFileURL); + static OUString removeOldURLPrefix(const OUString& _sURL); + static void throwJavaException(const css::uno::Exception& _aException,JNIEnv * env); + }; + +} // namespace connectivity::hsqldb + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HTable.hxx b/connectivity/source/inc/hsqldb/HTable.hxx new file mode 100644 index 0000000000..d6ac5ced76 --- /dev/null +++ b/connectivity/source/inc/hsqldb/HTable.hxx @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sal/config.h> + +#include <string_view> + +#include <connectivity/TTableHelper.hxx> +#include <comphelper/IdPropArrayHelper.hxx> + +namespace connectivity::hsqldb + { + + class OHSQLTable; + typedef ::comphelper::OIdPropertyArrayUsageHelper< OHSQLTable > OHSQLTable_PROP; + class OHSQLTable : public OTableHelper + ,public OHSQLTable_PROP + { + sal_Int32 m_nPrivileges; // we have to set our privileges by our own + + /** executes the statement. + @param _rStatement + The statement to execute. + */ + void executeStatement(const OUString& _rStatement ); + protected: + + /** creates the column collection for the table + @param _rNames + The column names. + */ + virtual sdbcx::OCollection* createColumns(const ::std::vector< OUString>& _rNames) override; + + /** creates the key collection for the table + @param _rNames + The key names. + */ + virtual sdbcx::OCollection* createKeys(const ::std::vector< OUString>& _rNames) override; + + /** creates the index collection for the table + @param _rNames + The index names. + */ + virtual sdbcx::OCollection* createIndexes(const ::std::vector< OUString>& _rNames) override; + + /** used to implement the creation of the array helper which is shared amongst all instances of the class. + This method needs to be implemented in derived classes. + <BR> + The method gets called with s_aMutex acquired. + @return a pointer to the newly created array helper. Must not be NULL. + */ + virtual ::cppu::IPropertyArrayHelper* createArrayHelper(sal_Int32 nId) const override; + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + + public: + OHSQLTable( sdbcx::OCollection* _pTables, + const css::uno::Reference< css::sdbc::XConnection >& _xConnection); + OHSQLTable( sdbcx::OCollection* _pTables, + const css::uno::Reference< css::sdbc::XConnection >& _xConnection, + const OUString& Name, + const OUString& Type, + const OUString& Description, + const OUString& SchemaName, + const OUString& CatalogName, + sal_Int32 _nPrivileges + ); + + // ODescriptor + virtual void construct() override; + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + // XAlterTable + virtual void SAL_CALL alterColumnByName( const OUString& colName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + + // XRename + virtual void SAL_CALL rename( const OUString& newName ) override; + + /** + returns the ALTER TABLE XXX COLUMN statement + */ + OUString getAlterTableColumnPart() const; + + // some methods to alter table structures + void alterColumnType(sal_Int32 nNewType,const OUString& _rColName,const css::uno::Reference< css::beans::XPropertySet >& _xDescriptor); + void alterDefaultValue(std::u16string_view _sNewDefault,const OUString& _rColName); + void dropDefaultValue(const OUString& _sNewDefault); + + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HTables.hxx b/connectivity/source/inc/hsqldb/HTables.hxx new file mode 100644 index 0000000000..bff5e0e642 --- /dev/null +++ b/connectivity/source/inc/hsqldb/HTables.hxx @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <connectivity/sdbcx/VCollection.hxx> +#include <com/sun/star/sdbc/XDatabaseMetaData.hpp> +#include <utility> +namespace connectivity::hsqldb + { + class OTables final : public sdbcx::OCollection + { + css::uno::Reference< css::sdbc::XDatabaseMetaData > m_xMetaData; + + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void dropObject(sal_Int32 _nPos, const OUString& _sElementName) override; + + void createTable( const css::uno::Reference< css::beans::XPropertySet >& descriptor ); + virtual OUString getNameForObject(const sdbcx::ObjectType& _xObject) override; + public: + OTables(css::uno::Reference< css::sdbc::XDatabaseMetaData > _xMetaData, ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector) : sdbcx::OCollection(_rParent, true, _rMutex, _rVector) + ,m_xMetaData(std::move(_xMetaData)) + {} + + // only the name is identical to ::cppu::OComponentHelper + virtual void disposing() override; + + // XDrop + void appendNew(const OUString& _rsNewTable); + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HTools.hxx b/connectivity/source/inc/hsqldb/HTools.hxx new file mode 100644 index 0000000000..a847b2d9a5 --- /dev/null +++ b/connectivity/source/inc/hsqldb/HTools.hxx @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <rtl/ustrbuf.hxx> + + +namespace connectivity::hsqldb +{ + + class HTools + { + public: + /** appends a proper WHERE clause to the given buffer, which filters + for a given table name + + @param _bShortForm + <TRUE/> if the column names of the system table which is being asked + have the short form (TABLE_CAT instead of TABLE_CATALOG, and so on) + */ + static void appendTableFilterCrit( + OUStringBuffer& _inout_rBuffer, std::u16string_view _rCatalog, + std::u16string_view _rSchema, std::u16string_view _rName, + bool _bShortForm + ); + }; + + +} // namespace connectivity::hsqldb + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HUser.hxx b/connectivity/source/inc/hsqldb/HUser.hxx new file mode 100644 index 0000000000..67c44e185b --- /dev/null +++ b/connectivity/source/inc/hsqldb/HUser.hxx @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sdbcx/VUser.hxx> +#include <com/sun/star/sdbc/XConnection.hpp> + +namespace connectivity::hsqldb + { + typedef connectivity::sdbcx::OUser OUser_TYPEDEF; + + class OHSQLUser : public OUser_TYPEDEF + { + css::uno::Reference< css::sdbc::XConnection > m_xConnection; + + static OUString getPrivilegeString(sal_Int32 nRights); + // return the privileges and additional the grant rights + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void findPrivilegesAndGrantPrivileges(const OUString& objName, sal_Int32 objType,sal_Int32& nRights,sal_Int32& nRightsWithGrant); + public: + virtual void refreshGroups() override; + public: + OHSQLUser( css::uno::Reference< css::sdbc::XConnection > _xConnection); + OHSQLUser( css::uno::Reference< css::sdbc::XConnection > _xConnection, const OUString& Name); + + // XUser + virtual void SAL_CALL changePassword( const OUString& objPassword, const OUString& newPassword ) override; + // XAuthorizable + virtual sal_Int32 SAL_CALL getPrivileges( const OUString& objName, sal_Int32 objType ) override; + virtual sal_Int32 SAL_CALL getGrantablePrivileges( const OUString& objName, sal_Int32 objType ) override; + virtual void SAL_CALL grantPrivileges( const OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) override; + virtual void SAL_CALL revokePrivileges( const OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) override; + }; + + class OUserExtend; + typedef ::comphelper::OPropertyArrayUsageHelper<OUserExtend> OUserExtend_PROP; + + class OUserExtend : public OHSQLUser, + public OUserExtend_PROP + { + OUString m_Password; + protected: + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const override; + // OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + public: + OUserExtend(const css::uno::Reference< css::sdbc::XConnection >& _xConnection); + + virtual void construct() override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HUsers.hxx b/connectivity/source/inc/hsqldb/HUsers.hxx new file mode 100644 index 0000000000..a5a099e992 --- /dev/null +++ b/connectivity/source/inc/hsqldb/HUsers.hxx @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <connectivity/sdbcx/VCollection.hxx> +#include <com/sun/star/sdbc/XConnection.hpp> +namespace connectivity +{ + namespace sdbcx + { + class IRefreshableUsers; + } + namespace hsqldb + { + class OUsers : public sdbcx::OCollection + { + css::uno::Reference< css::sdbc::XConnection > m_xConnection; + connectivity::sdbcx::IRefreshableUsers* m_pParent; + public: + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual void impl_refresh() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void dropObject(sal_Int32 _nPos, const OUString& _sElementName) override; + public: + OUsers( ::cppu::OWeakObject& _rParent, + ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector, + css::uno::Reference< css::sdbc::XConnection > _xConnection, + connectivity::sdbcx::IRefreshableUsers* _pParent); + }; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HView.hxx b/connectivity/source/inc/hsqldb/HView.hxx new file mode 100644 index 0000000000..62e8e5f456 --- /dev/null +++ b/connectivity/source/inc/hsqldb/HView.hxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <connectivity/sdbcx/VView.hxx> + +#include <com/sun/star/sdbcx/XAlterView.hpp> +#include <com/sun/star/sdbc/XConnection.hpp> + +#include <comphelper/uno3.hxx> +#include <cppuhelper/implbase1.hxx> + + +namespace connectivity::hsqldb +{ + + typedef ::connectivity::sdbcx::OView HView_Base; + typedef ::cppu::ImplHelper1< css::sdbcx::XAlterView > HView_IBASE; + class HView :public HView_Base + ,public HView_IBASE + { + public: + HView( + const css::uno::Reference< css::sdbc::XConnection >& _rxConnection, + bool _bCaseSensitive, + const OUString& _rSchemaName, + const OUString& _rName + ); + + // UNO + DECLARE_XINTERFACE() + DECLARE_XTYPEPROVIDER() + + // XAlterView + virtual void SAL_CALL alterCommand( const OUString& NewCommand ) override; + + protected: + virtual ~HView() override; + + protected: + // OPropertyContainer + virtual void SAL_CALL getFastPropertyValue( css::uno::Any& _rValue, sal_Int32 _nHandle ) const override; + + private: + /** retrieves the current command of the View */ + OUString impl_getCommand() const; + + /** retrieves the current command of the View + + @throws css::lang::WrappedTargetException + if an error occurs while retrieving the command from the database. + */ + OUString impl_getCommand_wrapSQLException() const; + /** retrieves the current command of the View + + @throws css::sdbc::SQLException + if an error occurs while retrieving the command from the database. + */ + OUString impl_getCommand_throwSQLException() const; + + private: + css::uno::Reference< css::sdbc::XConnection > m_xConnection; + private: + using HView_Base::getFastPropertyValue; + }; + + +} // namespace connectivity::hsqldb + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HViews.hxx b/connectivity/source/inc/hsqldb/HViews.hxx new file mode 100644 index 0000000000..cb2041524e --- /dev/null +++ b/connectivity/source/inc/hsqldb/HViews.hxx @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <connectivity/sdbcx/VCollection.hxx> +#include <com/sun/star/sdbc/XDatabaseMetaData.hpp> +namespace connectivity::hsqldb + { + class HViews final : public sdbcx::OCollection + { + css::uno::Reference< css::sdbc::XConnection > m_xConnection; + css::uno::Reference< css::sdbc::XDatabaseMetaData > m_xMetaData; + bool m_bInDrop; + + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void dropObject(sal_Int32 _nPos, const OUString& _sElementName) override; + + void createView( const css::uno::Reference< css::beans::XPropertySet >& descriptor ); + public: + HViews( + const css::uno::Reference< css::sdbc::XConnection >& _rxConnection, + ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, const ::std::vector< OUString> &_rVector ); + + // only the name is identical to ::cppu::OComponentHelper + virtual void disposing() override; + + void dropByNameImpl(const OUString& elementName); + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/ContextClassLoader.hxx b/connectivity/source/inc/java/ContextClassLoader.hxx new file mode 100644 index 0000000000..e7079239aa --- /dev/null +++ b/connectivity/source/inc/java/ContextClassLoader.hxx @@ -0,0 +1,79 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <java/GlobalRef.hxx> + +namespace comphelper +{ + class EventLogger; +} + + +namespace connectivity::jdbc +{ + class ContextClassLoaderScope + { + public: + /** creates the instance. If isActive returns <FALSE/> afterwards, then an exception + happened in the JVM, which should be raised as UNO exception by the caller + + @param environment + the current JNI environment + @param newClassLoader + the new class loader to set at the current thread + @param _rLoggerForErrors + the logger which should be passed to java_lang_object::ThrowLoggedSQLException in case + an error occurs + @param _rxErrorContext + the context which should be passed to java_lang_object::ThrowLoggedSQLException in case + an error occurs + + */ + ContextClassLoaderScope( + JNIEnv& environment, + const GlobalRef< jobject >& newClassLoader, + const ::comphelper::EventLogger& _rLoggerForErrors, + const css::uno::Reference< css::uno::XInterface >& _rxErrorContext + ); + + ~ContextClassLoaderScope(); + + bool isActive() const + { + return ( m_currentThread.is() ) + && ( m_setContextClassLoaderMethod != nullptr ); + } + + private: + ContextClassLoaderScope(ContextClassLoaderScope const &) = delete; + ContextClassLoaderScope& operator =(ContextClassLoaderScope const &) = delete; + + JNIEnv& m_environment; + LocalRef< jobject > m_currentThread; + LocalRef< jobject > m_oldContextClassLoader; + jmethodID m_setContextClassLoaderMethod; + }; + + +} // namespace connectivity::jdbc + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/GlobalRef.hxx b/connectivity/source/inc/java/GlobalRef.hxx new file mode 100644 index 0000000000..1a97bfb33a --- /dev/null +++ b/connectivity/source/inc/java/GlobalRef.hxx @@ -0,0 +1,102 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <java/LocalRef.hxx> +#include <java/lang/Object.hxx> + + +namespace connectivity::jdbc +{ + /** helper class to hold a local ref to a JNI object + */ + template< typename T > + class GlobalRef + { + public: + GlobalRef() + :m_object( nullptr ) + { + } + + GlobalRef( const GlobalRef& _source ) + :m_object( nullptr ) + { + *this = _source; + } + + GlobalRef& operator=( const GlobalRef& _source ) + { + if ( &_source == this ) + return *this; + + SDBThreadAttach t; + set( t.env(), _source.get() ); + return *this; + } + + ~GlobalRef() COVERITY_NOEXCEPT_FALSE + { + reset(); + } + + void reset() + { + if ( m_object != nullptr ) + { + SDBThreadAttach t; + t.env().DeleteGlobalRef( m_object ); + m_object = nullptr; + } + } + + void set( JNIEnv& _environment, T _object ) + { + if ( m_object != nullptr ) + _environment.DeleteGlobalRef( m_object ); + m_object = _object; + if ( m_object ) + m_object = static_cast< T >( _environment.NewGlobalRef( m_object ) ); + } + + void set( LocalRef< T >& _object ) + { + set( _object.env(), _object.release() ); + } + + T get() const + { + return m_object; + } + + bool is() const + { + return m_object != nullptr; + } + + private: + T m_object; + }; + + +} // namespace connectivity::jdbc + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/LocalRef.hxx b/connectivity/source/inc/java/LocalRef.hxx new file mode 100644 index 0000000000..ad40737f86 --- /dev/null +++ b/connectivity/source/inc/java/LocalRef.hxx @@ -0,0 +1,95 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if defined __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-attributes" +#endif +#include <jni.h> +#if defined __clang__ +#pragma clang diagnostic pop +#endif + +namespace connectivity::jdbc +{ + + /** helper class to hold a local ref to a JNI object + + Note that this class never actually calls NewLocalRef. It is assumed that all objects + passed are already acquired with a local ref (as it usually is the case if you obtain + the object from a JNI method). + */ + template< typename T > + class LocalRef final + { + public: + explicit LocalRef( JNIEnv& environment ) + :m_environment( environment ) + ,m_object( nullptr ) + { + } + + LocalRef( JNIEnv& environment, T object ) + :m_environment( environment ) + ,m_object( object ) + { + } + + ~LocalRef() + { + reset(); + } + + T release() + { + T t = m_object; + m_object = nullptr; + return t; + } + + void set( T object ) { reset(); m_object = object; } + + void reset() + { + if ( m_object != nullptr ) + { + m_environment.DeleteLocalRef( m_object ); + m_object = nullptr; + } + } + + JNIEnv& env() const { return m_environment; } + T get() const { return m_object; } + bool is() const { return m_object != nullptr; } + + private: + LocalRef(LocalRef const &) = delete; + LocalRef& operator =(LocalRef const &) = delete; + + JNIEnv& m_environment; + T m_object; + }; + + +} // namespace connectivity::jdbc + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/io/InputStream.hxx b/connectivity/source/inc/java/io/InputStream.hxx new file mode 100644 index 0000000000..4a0b5788f1 --- /dev/null +++ b/connectivity/source/inc/java/io/InputStream.hxx @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <java/lang/Object.hxx> +#include <cppuhelper/implbase.hxx> +#include <com/sun/star/io/XInputStream.hpp> + +namespace connectivity +{ + + + //************ Class: java.io.InputStream + + class java_io_InputStream : public java_lang_Object, + public ::cppu::WeakImplHelper< css::io::XInputStream> + { + protected: + // static Data for the Class + static jclass theClass; + virtual ~java_io_InputStream() override; + public: + virtual jclass getMyClass() const override; + // a Constructor, that is needed for when Returning the Object is needed: + java_io_InputStream( JNIEnv * pEnv, jobject myObj ); + // XInputStream + virtual sal_Int32 SAL_CALL readBytes( css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) override; + virtual sal_Int32 SAL_CALL readSomeBytes( css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) override; + virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) override; + virtual sal_Int32 SAL_CALL available( ) override; + virtual void SAL_CALL closeInput( ) override; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/io/Reader.hxx b/connectivity/source/inc/java/io/Reader.hxx new file mode 100644 index 0000000000..8386eda449 --- /dev/null +++ b/connectivity/source/inc/java/io/Reader.hxx @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <java/lang/Object.hxx> +#include <cppuhelper/implbase.hxx> +#include <com/sun/star/io/XInputStream.hpp> +#include <optional> + +namespace connectivity +{ + + //************ Class: java.io.InputStream + + class java_io_Reader final : public java_lang_Object, + public ::cppu::WeakImplHelper< css::io::XInputStream> + { + // static Data for the Class + static jclass theClass; + virtual ~java_io_Reader() override; + std::optional<char> m_buf; + public: + virtual jclass getMyClass() const override; + // a Constructor, that is needed for when Returning the Object is needed: + java_io_Reader( JNIEnv * pEnv, jobject myObj ); + // XInputStream + virtual sal_Int32 SAL_CALL readBytes( css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) override; + virtual sal_Int32 SAL_CALL readSomeBytes( css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) override; + virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) override; + virtual sal_Int32 SAL_CALL available( ) override; + virtual void SAL_CALL closeInput( ) override; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/lang/Boolean.hxx b/connectivity/source/inc/java/lang/Boolean.hxx new file mode 100644 index 0000000000..536ba5de31 --- /dev/null +++ b/connectivity/source/inc/java/lang/Boolean.hxx @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <java/lang/Object.hxx> + +//************ Class: java.lang.Boolean + +namespace connectivity +{ + class java_lang_Boolean : public java_lang_Object + { + protected: + // static Data for the class + static jclass theClass; + public: + virtual jclass getMyClass() const override; + virtual ~java_lang_Boolean() override; + // a Constructor, that is needed for when Returning the Object is needed: + java_lang_Boolean( JNIEnv * pEnv, jobject myObj ) : java_lang_Object( pEnv, myObj ){} + + static jclass st_getMyClass(); + }; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/lang/Class.hxx b/connectivity/source/inc/java/lang/Class.hxx new file mode 100644 index 0000000000..bcd5628c1d --- /dev/null +++ b/connectivity/source/inc/java/lang/Class.hxx @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +//************ Class: java.lang.Class + +#include <sal/config.h> + +#include <string_view> + +#include <java/lang/Object.hxx> + +namespace connectivity +{ + class java_lang_Class : public java_lang_Object + { + protected: + // static Data for the Class + static jclass theClass; + public: + virtual jclass getMyClass() const override; + virtual ~java_lang_Class() override; + // a Constructor, that is needed for when Returning the Object is needed: + java_lang_Class( JNIEnv * pEnv, jobject myObj ) : java_lang_Object( pEnv, myObj ){} + + static java_lang_Class * forName( std::u16string_view _par0 ); + // return the jre object + jobject newInstanceObject(); + + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/lang/Exception.hxx b/connectivity/source/inc/java/lang/Exception.hxx new file mode 100644 index 0000000000..28b2d56dc9 --- /dev/null +++ b/connectivity/source/inc/java/lang/Exception.hxx @@ -0,0 +1,42 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <java/lang/Throwable.hxx> + +namespace connectivity +{ + + + //************ Class: java.lang.Exception + + class java_lang_Exception : public java_lang_Throwable{ + protected: + // statis Data for the class + static jclass theClass; + public: + virtual jclass getMyClass() const override; + virtual ~java_lang_Exception() override; + // a Constructor, that is needed for when Returning the Object is needed: + java_lang_Exception( JNIEnv * pEnv, jobject myObj ) : java_lang_Throwable( pEnv, myObj ){} + + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/lang/Object.hxx b/connectivity/source/inc/java/lang/Object.hxx new file mode 100644 index 0000000000..63d7af3f59 --- /dev/null +++ b/connectivity/source/inc/java/lang/Object.hxx @@ -0,0 +1,147 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <com/sun/star/uno/XComponentContext.hpp> +#include <jvmaccess/virtualmachine.hxx> + +#ifdef HAVE_64BIT_POINTERS +#error "no 64 bit pointer" +#endif //HAVE_64BIT_POINTERS + +namespace comphelper +{ + class EventLogger; +} + +namespace connectivity +{ + class SDBThreadAttach + { + jvmaccess::VirtualMachine::AttachGuard m_aGuard; + SDBThreadAttach(SDBThreadAttach const &) = delete; + SDBThreadAttach& operator= (SDBThreadAttach const &) = delete; + public: + SDBThreadAttach(); + ~SDBThreadAttach(); + + JNIEnv* pEnv; + static void addRef(); + static void releaseRef(); + + public: + JNIEnv& env() const + { + // according to the documentation of jvmaccess::VirtualMachine::AttachGuard, our env is never + // NULL, so why bothering with pointer checks? + return *pEnv; + } + }; + + + class java_lang_Object + { + java_lang_Object& operator= (java_lang_Object const &) = delete; + java_lang_Object(java_lang_Object const &) = delete; + + protected: + // The Java handle to this class + jobject object; + + // Class definition + // New in SJ2: + static jclass theClass; // The class needs to be requested only once! + + virtual jclass getMyClass() const; + + public: + // Ctor that should be used for the derived classes + java_lang_Object( JNIEnv * pEnv, jobject myObj ); + + // The actual ctor + java_lang_Object(); + + virtual ~java_lang_Object() COVERITY_NOEXCEPT_FALSE; + + void saveRef( JNIEnv * pEnv, jobject myObj ); + jobject getJavaObject() const { return object; } + void clearObject(JNIEnv& rEnv); + void clearObject(); + + OUString toString() const; + + static void ThrowSQLException(JNIEnv * pEnv,const css::uno::Reference< css::uno::XInterface> & _rContext); + static void ThrowLoggedSQLException( + const ::comphelper::EventLogger& _rLogger, + JNIEnv* pEnvironment, + const css::uno::Reference< css::uno::XInterface >& _rxContext + ); + static void ThrowRuntimeException(JNIEnv * pEnv,const css::uno::Reference< css::uno::XInterface> & _rContext); + + static ::rtl::Reference< jvmaccess::VirtualMachine > getVM(const css::uno::Reference< css::uno::XComponentContext >& _rxContext=nullptr); + + static jclass findMyClass(const char* _pClassName); + void obtainMethodId_throwSQL(JNIEnv* _pEnv, const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID) const; + void obtainMethodId_throwRuntime(JNIEnv* _pEnv, const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID) const; + + bool callBooleanMethod( const char* _pMethodName, jmethodID& _inout_MethodID ) const; + bool callBooleanMethodWithIntArg( const char* _pMethodName, jmethodID& _inout_MethodID, sal_Int32 _nArgument ) const; + jobject callResultSetMethod( JNIEnv& _rEnv, const char* _pMethodName, jmethodID& _inout_MethodID ) const; + sal_Int32 callIntMethod_ThrowSQL(const char* _pMethodName, jmethodID& _inout_MethodID) const; + sal_Int32 callIntMethod_ThrowRuntime(const char* _pMethodName, jmethodID& _inout_MethodID) const; + sal_Int32 callIntMethodWithIntArg_ThrowSQL( const char* _pMethodName, jmethodID& _inout_MethodID, sal_Int32 _nArgument ) const; + sal_Int32 callIntMethodWithIntArg_ThrowRuntime( const char* _pMethodName, jmethodID& _inout_MethodID, sal_Int32 _nArgument ) const; + sal_Int32 callIntMethodWithStringArg( const char* _pMethodName, jmethodID& _inout_MethodID,const OUString& _nArgument ) const; + OUString callStringMethod( const char* _pMethodName, jmethodID& _inout_MethodID ) const; + OUString callStringMethodWithIntArg( const char* _pMethodName, jmethodID& _inout_MethodID , sal_Int32 _nArgument) const; + void callVoidMethod_ThrowSQL( const char* _pMethodName, jmethodID& _inout_MethodID) const; + void callVoidMethod_ThrowRuntime( const char* _pMethodName, jmethodID& _inout_MethodID) const; + void callVoidMethodWithIntArg_ThrowSQL( const char* _pMethodName, jmethodID& _inout_MethodID, sal_Int32 _nArgument ) const; + void callVoidMethodWithIntArg_ThrowRuntime( const char* _pMethodName, jmethodID& _inout_MethodID, sal_Int32 _nArgument ) const; + void callVoidMethodWithBoolArg_ThrowSQL( const char* _pMethodName, jmethodID& _inout_MethodID, bool _nArgument ) const; + void callVoidMethodWithBoolArg_ThrowRuntime( const char* _pMethodName, jmethodID& _inout_MethodID, bool _nArgument ) const; + void callVoidMethodWithStringArg( const char* _pMethodName, jmethodID& _inout_MethodID, const OUString& _nArgument ) const; + jobject callObjectMethod( JNIEnv * pEnv, const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID ) const; + jobject callObjectMethodWithIntArg( JNIEnv * pEnv, const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID , sal_Int32 _nArgument) const; + + template< typename T > + T callMethodWithIntArg(T (JNIEnv::*pCallMethod)( jobject obj, jmethodID methodID, ... ) ,const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID , sal_Int32 _nArgument) const + { + SDBThreadAttach t; + obtainMethodId_throwSQL(t.pEnv, _pMethodName,_pSignature, _inout_MethodID); + T out = (t.pEnv->*pCallMethod)( object, _inout_MethodID,_nArgument); + ThrowSQLException( t.pEnv, nullptr ); + return out; + } + + template< typename T > + void callVoidMethod_ThrowSQL(const char* _pMethodName, const char* _pSignature, jmethodID& _inout_MethodID,sal_Int32 _nArgument, const T& _aValue) const + { + SDBThreadAttach t; + obtainMethodId_throwSQL(t.pEnv, _pMethodName,_pSignature, _inout_MethodID); + t.pEnv->CallVoidMethod( object, _inout_MethodID,_nArgument,_aValue); + ThrowSQLException( t.pEnv, nullptr ); + } + + + }; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/lang/String.hxx b/connectivity/source/inc/java/lang/String.hxx new file mode 100644 index 0000000000..2783b6eeb9 --- /dev/null +++ b/connectivity/source/inc/java/lang/String.hxx @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <java/lang/Object.hxx> + +namespace connectivity +{ + class java_lang_String : public java_lang_Object + { + protected: + // statis Data for the Class + static jclass theClass; + public: + virtual jclass getMyClass() const override; + virtual ~java_lang_String() override; + // a Constructor, that is needed for when Returning the Object is needed: + java_lang_String( JNIEnv * pEnv, jobject myObj ) : java_lang_Object( pEnv, myObj ){} + + operator OUString(); + + static jclass st_getMyClass(); + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/lang/Throwable.hxx b/connectivity/source/inc/java/lang/Throwable.hxx new file mode 100644 index 0000000000..65cfc24fe7 --- /dev/null +++ b/connectivity/source/inc/java/lang/Throwable.hxx @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <java/lang/Object.hxx> + +namespace connectivity +{ + + //************ Class: java.lang.Throwable + + class java_lang_Throwable : public java_lang_Object + { + protected: + // static Data for the class + static jclass theClass; + public: + virtual jclass getMyClass() const override; + virtual ~java_lang_Throwable() override; + // a Constructor, that is needed for when Returning the Object is needed: + java_lang_Throwable( JNIEnv * pEnv, jobject myObj ) : java_lang_Object( pEnv, myObj ){} + OUString getMessage() const; + OUString getLocalizedMessage() const; + +#if OSL_DEBUG_LEVEL > 0 + void printStackTrace() const; +#endif + + static jclass st_getMyClass(); + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/math/BigDecimal.hxx b/connectivity/source/inc/java/math/BigDecimal.hxx new file mode 100644 index 0000000000..f4fb684b87 --- /dev/null +++ b/connectivity/source/inc/java/math/BigDecimal.hxx @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <java/lang/Object.hxx> + +//************ Class: java.lang.Boolean + +namespace connectivity +{ + class java_math_BigDecimal : public java_lang_Object + { + // static Data for the class + static jclass theClass; + public: + virtual jclass getMyClass() const override; + virtual ~java_math_BigDecimal() override; + + java_math_BigDecimal( const OUString& _par0 ); + java_math_BigDecimal( const double& _par0 ); + }; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/Array.hxx b/connectivity/source/inc/java/sql/Array.hxx new file mode 100644 index 0000000000..93cce69386 --- /dev/null +++ b/connectivity/source/inc/java/sql/Array.hxx @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <java/lang/Object.hxx> +#include <com/sun/star/sdbc/XArray.hpp> +#include <cppuhelper/implbase.hxx> + +namespace connectivity +{ + + + //************ Class: java.sql.SQLWarning + + class java_sql_Array : public java_lang_Object, + public ::cppu::WeakImplHelper< css::sdbc::XArray> + { + protected: + // Static data for the class + static jclass theClass; + public: + virtual jclass getMyClass() const override; + virtual ~java_sql_Array() override; + // A ctor that is needed for returning the object + java_sql_Array( JNIEnv * pEnv, jobject myObj ) : java_lang_Object( pEnv, myObj ){} + + // XArray + virtual OUString SAL_CALL getBaseTypeName( ) override; + virtual sal_Int32 SAL_CALL getBaseType( ) override; + virtual css::uno::Sequence< css::uno::Any > SAL_CALL getArray( const css::uno::Reference< css::container::XNameAccess >& typeMap ) override; + virtual css::uno::Sequence< css::uno::Any > SAL_CALL getArrayAtIndex( sal_Int32 index, sal_Int32 count, const css::uno::Reference< css::container::XNameAccess >& typeMap ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getResultSet( const css::uno::Reference< css::container::XNameAccess >& typeMap ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getResultSetAtIndex( sal_Int32 index, sal_Int32 count, const css::uno::Reference< css::container::XNameAccess >& typeMap ) override; + + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/Blob.hxx b/connectivity/source/inc/java/sql/Blob.hxx new file mode 100644 index 0000000000..02ac0df134 --- /dev/null +++ b/connectivity/source/inc/java/sql/Blob.hxx @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <java/lang/Object.hxx> +#include <com/sun/star/sdbc/XBlob.hpp> +#include <cppuhelper/implbase.hxx> + +namespace connectivity +{ + + + //************ Class: java.sql.SQLWarning + + class java_sql_Blob : public java_lang_Object, + public ::cppu::WeakImplHelper< css::sdbc::XBlob> + { + protected: + // Static data for the class + static jclass theClass; + virtual ~java_sql_Blob() override; + public: + virtual jclass getMyClass() const override; + + // A ctor that is needed for returning the object + java_sql_Blob( JNIEnv * pEnv, jobject myObj ); + + // XBlob + virtual sal_Int64 SAL_CALL length( ) override; + virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes( sal_Int64 pos, sal_Int32 length ) override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream( ) override; + virtual sal_Int64 SAL_CALL position( const css::uno::Sequence< sal_Int8 >& pattern, sal_Int64 start ) override; + virtual sal_Int64 SAL_CALL positionOfBlob( const css::uno::Reference< css::sdbc::XBlob >& pattern, sal_Int64 start ) override; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/CallableStatement.hxx b/connectivity/source/inc/java/sql/CallableStatement.hxx new file mode 100644 index 0000000000..7391837741 --- /dev/null +++ b/connectivity/source/inc/java/sql/CallableStatement.hxx @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <java/sql/PreparedStatement.hxx> +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/sdbc/XOutParameters.hpp> + +namespace connectivity +{ + + + //************ Class: java.sql.CallableStatement + + + class java_sql_CallableStatement : public java_sql_PreparedStatement, + public css::sdbc::XRow, + public css::sdbc::XOutParameters + { + protected: + // Static data for the class + static jclass theClass; + virtual void createStatement(JNIEnv* _pEnv) override; + + virtual ~java_sql_CallableStatement() override; + public: + DECLARE_SERVICE_INFO(); + virtual jclass getMyClass() const override; + + // A ctor that is needed for returning the object + java_sql_CallableStatement( JNIEnv * pEnv, java_sql_Connection& _rCon, const OUString& sql ); + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + + // XRow + virtual sal_Bool SAL_CALL wasNull( ) override; + virtual OUString SAL_CALL getString( sal_Int32 columnIndex ) override; + virtual sal_Bool SAL_CALL getBoolean( sal_Int32 columnIndex ) override; + virtual sal_Int8 SAL_CALL getByte( sal_Int32 columnIndex ) override; + virtual sal_Int16 SAL_CALL getShort( sal_Int32 columnIndex ) override; + virtual sal_Int32 SAL_CALL getInt( sal_Int32 columnIndex ) override; + virtual sal_Int64 SAL_CALL getLong( sal_Int32 columnIndex ) override; + virtual float SAL_CALL getFloat( sal_Int32 columnIndex ) override; + virtual double SAL_CALL getDouble( sal_Int32 columnIndex ) override; + virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes( sal_Int32 columnIndex ) override; + virtual css::util::Date SAL_CALL getDate( sal_Int32 columnIndex ) override; + virtual css::util::Time SAL_CALL getTime( sal_Int32 columnIndex ) override; + virtual css::util::DateTime SAL_CALL getTimestamp( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream( sal_Int32 columnIndex ) override; + virtual css::uno::Any SAL_CALL getObject( sal_Int32 columnIndex, const css::uno::Reference< css::container::XNameAccess >& typeMap ) override; + virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray( sal_Int32 columnIndex ) override; + // XOutParameters + virtual void SAL_CALL registerOutParameter( sal_Int32 parameterIndex, sal_Int32 sqlType, const OUString& typeName ) override; + virtual void SAL_CALL registerNumericOutParameter( sal_Int32 parameterIndex, sal_Int32 sqlType, sal_Int32 scale ) override; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/Clob.hxx b/connectivity/source/inc/java/sql/Clob.hxx new file mode 100644 index 0000000000..67a69bb6db --- /dev/null +++ b/connectivity/source/inc/java/sql/Clob.hxx @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <java/lang/Object.hxx> +#include <com/sun/star/sdbc/XClob.hpp> +#include <cppuhelper/implbase.hxx> + +namespace connectivity +{ + + + //************ Class: java.sql.SQLWarning + + class java_sql_Clob : public java_lang_Object, + public ::cppu::WeakImplHelper< css::sdbc::XClob> + { + protected: + // Static data for the class + static jclass theClass; + virtual ~java_sql_Clob() override; + public: + virtual jclass getMyClass() const override; + + // A ctor that is needed for returning the object + java_sql_Clob( JNIEnv * pEnv, jobject myObj ); + + // XClob + virtual sal_Int64 SAL_CALL length( ) override; + virtual OUString SAL_CALL getSubString( sal_Int64 pos, sal_Int32 length ) override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream( ) override; + virtual sal_Int64 SAL_CALL position( const OUString& searchstr, sal_Int32 start ) override; + virtual sal_Int64 SAL_CALL positionOfClob( const css::uno::Reference< css::sdbc::XClob >& pattern, sal_Int64 start ) override; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/Connection.hxx b/connectivity/source/inc/java/sql/Connection.hxx new file mode 100644 index 0000000000..444d44df51 --- /dev/null +++ b/connectivity/source/inc/java/sql/Connection.hxx @@ -0,0 +1,135 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <java/lang/Object.hxx> +#include <TConnection.hxx> +#include <connectivity/CommonTools.hxx> +#include <AutoRetrievingBase.hxx> +#include <java/sql/ConnectionLog.hxx> +#include <java/GlobalRef.hxx> + +#include <com/sun/star/beans/NamedValue.hpp> + +namespace connectivity +{ + class java_sql_Driver; + + typedef OMetaConnection java_sql_Connection_BASE; + + class java_sql_Connection : public java_sql_Connection_BASE, + public java_lang_Object, + public OAutoRetrievingBase + { + css::uno::Reference< css::uno::XComponentContext > m_xContext; + const java_sql_Driver* m_pDriver; + jobject m_pDriverobject; + jdbc::GlobalRef< jobject > + m_pDriverClassLoader; + + jclass m_Driver_theClass; + java::sql::ConnectionLog + m_aLogger; + bool m_bIgnoreDriverPrivileges; + bool m_bIgnoreCurrency; + css::uno::Any m_aCatalogRestriction; + css::uno::Any m_aSchemaRestriction; + + /** transform named parameter into unnamed one. + @param _sSQL + The SQL statement to transform. + @return + The new statement with unnamed parameters. + */ + OUString transFormPreparedStatement(const OUString& _sSQL); + void loadDriverFromProperties( + const OUString& _sDriverClass, + const OUString& _sDriverClassPath, + const css::uno::Sequence< css::beans::NamedValue >& _rSystemProperties + ); + /** load driver class path from system configuration. + @param _sDriverClass + The driver class name to look for in the configuration. + */ + OUString impl_getJavaDriverClassPath_nothrow(const OUString& _sDriverClass); + + protected: + // Static data for the class + static jclass theClass; + + virtual ~java_sql_Connection() override; + + public: + virtual jclass getMyClass() const override; + + DECLARE_SERVICE_INFO(); + // A ctor that is needed for returning the object + java_sql_Connection( const java_sql_Driver& _rDriver ); + bool construct( const OUString& url, + const css::uno::Sequence< css::beans::PropertyValue >& info); + + const css::uno::Sequence< css::beans::PropertyValue >& + getConnectionInfo() const { return m_aConnectionInfo; } + + bool isIgnoreDriverPrivilegesEnabled() const { return m_bIgnoreDriverPrivileges;} + bool isIgnoreCurrencyEnabled() const { return m_bIgnoreCurrency; } + const css::uno::Any& getCatalogRestriction() const { return m_aCatalogRestriction; } + const css::uno::Any& getSchemaRestriction() const { return m_aSchemaRestriction; } + + /** returns the instance used for logging events related to this connection + */ + const java::sql::ConnectionLog& getLogger() const { return m_aLogger; } + + /** returns the class loader which was used to load the driver class + + Usually used in conjunction with a ContextClassLoaderScope instance. + */ + const jdbc::GlobalRef< jobject >& getDriverClassLoader() const { return m_pDriverClassLoader; } + + // OComponentHelper + virtual void SAL_CALL disposing() override; + + // XConnection + virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement( ) override; + virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const OUString& sql ) override; + virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall( const OUString& sql ) override; + virtual OUString SAL_CALL nativeSQL( const OUString& sql ) override; + virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) override; + virtual sal_Bool SAL_CALL getAutoCommit( ) override; + virtual void SAL_CALL commit( ) override; + virtual void SAL_CALL rollback( ) override; + virtual sal_Bool SAL_CALL isClosed( ) override; + virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( ) override; + virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) override; + virtual sal_Bool SAL_CALL isReadOnly( ) override; + virtual void SAL_CALL setCatalog( const OUString& catalog ) override; + virtual OUString SAL_CALL getCatalog( ) override; + virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) override; + virtual sal_Int32 SAL_CALL getTransactionIsolation( ) override; + virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTypeMap( ) override; + virtual void SAL_CALL setTypeMap( const css::uno::Reference< css::container::XNameAccess >& typeMap ) override; + // XCloseable + virtual void SAL_CALL close( ) override; + // XWarningsSupplier + virtual css::uno::Any SAL_CALL getWarnings( ) override; + virtual void SAL_CALL clearWarnings( ) override; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/ConnectionLog.hxx b/connectivity/source/inc/java/sql/ConnectionLog.hxx new file mode 100644 index 0000000000..cea19cdff0 --- /dev/null +++ b/connectivity/source/inc/java/sql/ConnectionLog.hxx @@ -0,0 +1,127 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/logging/LogLevel.hpp> + +#include <rtl/ustring.hxx> + +// Strange enough, GCC requires the following forward declarations of the various +// convertLogArgToString flavors to be *before* the inclusion of comphelper/logging.hxx + +namespace com::sun::star::util +{ + struct Date; + struct Time; + struct DateTime; +} + + +namespace comphelper::log::convert +{ + + + // helpers for logging more data types than are defined in comphelper/logging.hxx + OUString convertLogArgToString( const css::util::Date& _rDate ); + OUString convertLogArgToString( const css::util::Time& _rTime ); + OUString convertLogArgToString( const css::util::DateTime& _rDateTime ); + + +} + + +#include <comphelper/logging.hxx> + +namespace connectivity +{ + namespace LogLevel = css::logging::LogLevel; +} + + +namespace connectivity::java::sql { + + typedef ::comphelper::EventLogger ConnectionLog_Base; + class ConnectionLog : public ConnectionLog_Base + { + public: + enum ObjectType + { + CONNECTION = 0, + STATEMENT, + RESULTSET, + + ObjectTypeCount = RESULTSET + 1 + }; + + private: + const sal_Int32 m_nObjectID; + + public: + /// will construct an instance of ObjectType CONNECTION + ConnectionLog( const ::comphelper::EventLogger & _rDriverLog ); + /// will create an instance with the same object ID / ObjectType as a given source instance + ConnectionLog( const ConnectionLog& _rSourceLog ); + /// will create an instance of arbitrary ObjectType + ConnectionLog( const ConnectionLog& _rSourceLog, ObjectType _eType ); + + sal_Int32 getObjectID() const { return m_nObjectID; } + + /// logs a given message, without any arguments, or source class/method names + void log( const sal_Int32 _nLogLevel, const OUString& rMessage ) + { + ConnectionLog_Base::log( _nLogLevel, rMessage, m_nObjectID ); + } + + template< typename ARGTYPE1 > + void log( const sal_Int32 _nLogLevel, const OUString& rMessage, ARGTYPE1 _argument1 ) const + { + ConnectionLog_Base::log( _nLogLevel, rMessage, m_nObjectID, _argument1 ); + } + + template< typename ARGTYPE1, typename ARGTYPE2 > + void log( const sal_Int32 _nLogLevel, const OUString& rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2 ) const + { + ConnectionLog_Base::log( _nLogLevel, rMessage, m_nObjectID, _argument1, _argument2 ); + } + + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3 > + void log( const sal_Int32 _nLogLevel, const OUString& rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3 ) const + { + ConnectionLog_Base::log( _nLogLevel, rMessage, m_nObjectID, _argument1, _argument2, _argument3 ); + } + + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4 > + void log( const sal_Int32 _nLogLevel, const OUString& rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4 ) const + { + ConnectionLog_Base::log( _nLogLevel, rMessage, m_nObjectID, _argument1, _argument2, _argument3, _argument4 ); + } + + template< typename ARGTYPE1, typename ARGTYPE2, typename ARGTYPE3, typename ARGTYPE4, typename ARGTYPE5 > + void log( const sal_Int32 _nLogLevel, const OUString& rMessage, ARGTYPE1 _argument1, ARGTYPE2 _argument2, ARGTYPE3 _argument3, ARGTYPE4 _argument4, ARGTYPE5 _argument5 ) const + { + ConnectionLog_Base::log( _nLogLevel, rMessage, m_nObjectID, _argument1, _argument2, _argument3, _argument4, _argument5 ); + } + }; + + +} // namespace connectivity::java::sql + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/DatabaseMetaData.hxx b/connectivity/source/inc/java/sql/DatabaseMetaData.hxx new file mode 100644 index 0000000000..eb43f2537a --- /dev/null +++ b/connectivity/source/inc/java/sql/DatabaseMetaData.hxx @@ -0,0 +1,216 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <java/lang/Object.hxx> +#include <TDatabaseMetaDataBase.hxx> + +#include <java/sql/ConnectionLog.hxx> + +namespace connectivity +{ + class java_sql_Connection; + + //************ Class: java.sql.DatabaseMetaDataDate + + + class java_sql_DatabaseMetaData : public ODatabaseMetaDataBase, + public java_lang_Object + { + java_sql_Connection* m_pConnection; + java::sql::ConnectionLog m_aLogger; + + // Static data for the class + static jclass theClass; + + public: + virtual jclass getMyClass() const override; + virtual ~java_sql_DatabaseMetaData() override; + // A ctor that is needed for returning the object + java_sql_DatabaseMetaData( JNIEnv * pEnv, jobject myObj, java_sql_Connection& _rConnection ); + + private: + + virtual css::uno::Reference< css::sdbc::XResultSet > impl_getTypeInfo_throw() override; + // cached database information + virtual OUString impl_getIdentifierQuoteString_throw( ) override; + virtual bool impl_isCatalogAtStart_throw( ) override; + virtual OUString impl_getCatalogSeparator_throw( ) override; + virtual bool impl_supportsCatalogsInTableDefinitions_throw( ) override; + virtual bool impl_supportsSchemasInTableDefinitions_throw( ) override ; + virtual bool impl_supportsCatalogsInDataManipulation_throw( ) override; + virtual bool impl_supportsSchemasInDataManipulation_throw( ) override ; + virtual bool impl_supportsMixedCaseQuotedIdentifiers_throw( ) override; + virtual bool impl_supportsAlterTableWithAddColumn_throw( ) override; + virtual bool impl_supportsAlterTableWithDropColumn_throw( ) override; + virtual sal_Int32 impl_getMaxStatements_throw( ) override; + virtual sal_Int32 impl_getMaxTablesInSelect_throw( ) override; + virtual bool impl_storesMixedCaseQuotedIdentifiers_throw( ) override; + + virtual sal_Bool SAL_CALL allProceduresAreCallable( ) override; + virtual sal_Bool SAL_CALL allTablesAreSelectable( ) override; + virtual OUString SAL_CALL getURL( ) override; + virtual OUString SAL_CALL getUserName( ) override; + virtual sal_Bool SAL_CALL isReadOnly( ) override; + virtual sal_Bool SAL_CALL nullsAreSortedHigh( ) override; + virtual sal_Bool SAL_CALL nullsAreSortedLow( ) override; + virtual sal_Bool SAL_CALL nullsAreSortedAtStart( ) override; + virtual sal_Bool SAL_CALL nullsAreSortedAtEnd( ) override; + virtual OUString SAL_CALL getDatabaseProductName( ) override; + virtual OUString SAL_CALL getDatabaseProductVersion( ) override; + virtual OUString SAL_CALL getDriverName( ) override; + virtual OUString SAL_CALL getDriverVersion( ) override; + virtual sal_Int32 SAL_CALL getDriverMajorVersion( ) override; + virtual sal_Int32 SAL_CALL getDriverMinorVersion( ) override; + virtual sal_Bool SAL_CALL usesLocalFiles( ) override; + virtual sal_Bool SAL_CALL usesLocalFilePerTable( ) override; + virtual sal_Bool SAL_CALL supportsMixedCaseIdentifiers( ) override; + virtual sal_Bool SAL_CALL storesUpperCaseIdentifiers( ) override; + virtual sal_Bool SAL_CALL storesLowerCaseIdentifiers( ) override; + virtual sal_Bool SAL_CALL storesMixedCaseIdentifiers( ) override; + virtual sal_Bool SAL_CALL storesUpperCaseQuotedIdentifiers( ) override; + virtual sal_Bool SAL_CALL storesLowerCaseQuotedIdentifiers( ) override; + virtual OUString SAL_CALL getSQLKeywords( ) override; + virtual OUString SAL_CALL getNumericFunctions( ) override; + virtual OUString SAL_CALL getStringFunctions( ) override; + virtual OUString SAL_CALL getSystemFunctions( ) override; + virtual OUString SAL_CALL getTimeDateFunctions( ) override; + virtual OUString SAL_CALL getSearchStringEscape( ) override; + virtual OUString SAL_CALL getExtraNameCharacters( ) override; + virtual sal_Bool SAL_CALL supportsColumnAliasing( ) override; + virtual sal_Bool SAL_CALL nullPlusNonNullIsNull( ) override; + virtual sal_Bool SAL_CALL supportsTypeConversion( ) override; + virtual sal_Bool SAL_CALL supportsConvert( sal_Int32 fromType, sal_Int32 toType ) override; + virtual sal_Bool SAL_CALL supportsTableCorrelationNames( ) override; + virtual sal_Bool SAL_CALL supportsDifferentTableCorrelationNames( ) override; + virtual sal_Bool SAL_CALL supportsExpressionsInOrderBy( ) override; + virtual sal_Bool SAL_CALL supportsOrderByUnrelated( ) override; + virtual sal_Bool SAL_CALL supportsGroupBy( ) override; + virtual sal_Bool SAL_CALL supportsGroupByUnrelated( ) override; + virtual sal_Bool SAL_CALL supportsGroupByBeyondSelect( ) override; + virtual sal_Bool SAL_CALL supportsLikeEscapeClause( ) override; + virtual sal_Bool SAL_CALL supportsMultipleResultSets( ) override; + virtual sal_Bool SAL_CALL supportsMultipleTransactions( ) override; + virtual sal_Bool SAL_CALL supportsNonNullableColumns( ) override; + virtual sal_Bool SAL_CALL supportsMinimumSQLGrammar( ) override; + virtual sal_Bool SAL_CALL supportsCoreSQLGrammar( ) override; + virtual sal_Bool SAL_CALL supportsExtendedSQLGrammar( ) override; + virtual sal_Bool SAL_CALL supportsANSI92EntryLevelSQL( ) override; + virtual sal_Bool SAL_CALL supportsANSI92IntermediateSQL( ) override; + virtual sal_Bool SAL_CALL supportsANSI92FullSQL( ) override; + virtual sal_Bool SAL_CALL supportsIntegrityEnhancementFacility( ) override; + virtual sal_Bool SAL_CALL supportsOuterJoins( ) override; + virtual sal_Bool SAL_CALL supportsFullOuterJoins( ) override; + virtual sal_Bool SAL_CALL supportsLimitedOuterJoins( ) override; + virtual OUString SAL_CALL getSchemaTerm( ) override; + virtual OUString SAL_CALL getProcedureTerm( ) override; + virtual OUString SAL_CALL getCatalogTerm( ) override; + virtual sal_Bool SAL_CALL supportsSchemasInProcedureCalls( ) override; + virtual sal_Bool SAL_CALL supportsSchemasInIndexDefinitions( ) override; + virtual sal_Bool SAL_CALL supportsSchemasInPrivilegeDefinitions( ) override; + virtual sal_Bool SAL_CALL supportsCatalogsInProcedureCalls( ) override; + virtual sal_Bool SAL_CALL supportsCatalogsInIndexDefinitions( ) override; + virtual sal_Bool SAL_CALL supportsCatalogsInPrivilegeDefinitions( ) override; + virtual sal_Bool SAL_CALL supportsPositionedDelete( ) override; + virtual sal_Bool SAL_CALL supportsPositionedUpdate( ) override; + virtual sal_Bool SAL_CALL supportsSelectForUpdate( ) override; + virtual sal_Bool SAL_CALL supportsStoredProcedures( ) override; + virtual sal_Bool SAL_CALL supportsSubqueriesInComparisons( ) override; + virtual sal_Bool SAL_CALL supportsSubqueriesInExists( ) override; + virtual sal_Bool SAL_CALL supportsSubqueriesInIns( ) override; + virtual sal_Bool SAL_CALL supportsSubqueriesInQuantifieds( ) override; + virtual sal_Bool SAL_CALL supportsCorrelatedSubqueries( ) override; + virtual sal_Bool SAL_CALL supportsUnion( ) override; + virtual sal_Bool SAL_CALL supportsUnionAll( ) override; + virtual sal_Bool SAL_CALL supportsOpenCursorsAcrossCommit( ) override; + virtual sal_Bool SAL_CALL supportsOpenCursorsAcrossRollback( ) override; + virtual sal_Bool SAL_CALL supportsOpenStatementsAcrossCommit( ) override; + virtual sal_Bool SAL_CALL supportsOpenStatementsAcrossRollback( ) override; + virtual sal_Int32 SAL_CALL getMaxBinaryLiteralLength( ) override; + virtual sal_Int32 SAL_CALL getMaxCharLiteralLength( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInGroupBy( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInIndex( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInOrderBy( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInSelect( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInTable( ) override; + virtual sal_Int32 SAL_CALL getMaxConnections( ) override; + virtual sal_Int32 SAL_CALL getMaxCursorNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxIndexLength( ) override; + virtual sal_Int32 SAL_CALL getMaxSchemaNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxProcedureNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxCatalogNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxRowSize( ) override; + virtual sal_Bool SAL_CALL doesMaxRowSizeIncludeBlobs( ) override; + virtual sal_Int32 SAL_CALL getMaxStatementLength( ) override; + virtual sal_Int32 SAL_CALL getMaxTableNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxUserNameLength( ) override; + virtual sal_Int32 SAL_CALL getDefaultTransactionIsolation( ) override; + virtual sal_Bool SAL_CALL supportsTransactions( ) override; + virtual sal_Bool SAL_CALL supportsTransactionIsolationLevel( sal_Int32 level ) override; + virtual sal_Bool SAL_CALL supportsDataDefinitionAndDataManipulationTransactions( ) override; + virtual sal_Bool SAL_CALL supportsDataManipulationTransactionsOnly( ) override; + virtual sal_Bool SAL_CALL dataDefinitionCausesTransactionCommit( ) override; + virtual sal_Bool SAL_CALL dataDefinitionIgnoredInTransactions( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getProcedures( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& procedureNamePattern ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getProcedureColumns( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& procedureNamePattern, const OUString& columnNamePattern ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTables( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern, const css::uno::Sequence< OUString >& types ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getSchemas( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getCatalogs( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTableTypes( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getColumns( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern, const OUString& columnNamePattern ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getColumnPrivileges( const css::uno::Any& catalog, const OUString& schema, const OUString& table, const OUString& columnNamePattern ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTablePrivileges( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getBestRowIdentifier( const css::uno::Any& catalog, const OUString& schema, const OUString& table, sal_Int32 scope, sal_Bool nullable ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getVersionColumns( const css::uno::Any& catalog, const OUString& schema, const OUString& table ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getPrimaryKeys( const css::uno::Any& catalog, const OUString& schema, const OUString& table ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getImportedKeys( const css::uno::Any& catalog, const OUString& schema, const OUString& table ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getExportedKeys( const css::uno::Any& catalog, const OUString& schema, const OUString& table ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getCrossReference( const css::uno::Any& primaryCatalog, const OUString& primarySchema, const OUString& primaryTable, const css::uno::Any& foreignCatalog, const OUString& foreignSchema, const OUString& foreignTable ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getIndexInfo( const css::uno::Any& catalog, const OUString& schema, const OUString& table, sal_Bool unique, sal_Bool approximate ) override; + virtual sal_Bool SAL_CALL supportsResultSetType( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL supportsResultSetConcurrency( sal_Int32 setType, sal_Int32 concurrency ) override; + virtual sal_Bool SAL_CALL ownUpdatesAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL ownDeletesAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL ownInsertsAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL othersUpdatesAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL othersDeletesAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL othersInsertsAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL updatesAreDetected( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL deletesAreDetected( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL insertsAreDetected( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL supportsBatchUpdates( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getUDTs( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& typeNamePattern, const css::uno::Sequence< sal_Int32 >& types ) override; + + private: + bool impl_callBooleanMethod( const char* _pMethodName, jmethodID& _inout_MethodID ); + OUString impl_callStringMethod( const char* _pMethodName, jmethodID& _inout_MethodID ); + sal_Int32 impl_callIntMethod_ThrowSQL( const char* _pMethodName, jmethodID& _inout_MethodID ); + sal_Int32 impl_callIntMethod_ThrowRuntime( const char* _pMethodName, jmethodID& _inout_MethodID ); + bool impl_callBooleanMethodWithIntArg( const char* _pMethodName, jmethodID& _inout_MethodID, sal_Int32 _nArgument ); + css::uno::Reference< css::sdbc::XResultSet > + impl_callResultSetMethod( const char* _pMethodName, jmethodID& _inout_MethodID ); + css::uno::Reference< css::sdbc::XResultSet > + impl_callResultSetMethodWithStrings( const char* _pMethodName, jmethodID& _inout_MethodID, const css::uno::Any& _rCatalog, + const OUString& _rSchemaPattern, const OUString& _rLeastPattern, + const OUString* _pOptionalAdditionalString = nullptr); + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/Driver.hxx b/connectivity/source/inc/java/sql/Driver.hxx new file mode 100644 index 0000000000..805df2ed12 --- /dev/null +++ b/connectivity/source/inc/java/sql/Driver.hxx @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/sdbc/XDriver.hpp> +#include <cppuhelper/implbase.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> + +#include <comphelper/logging.hxx> + +namespace connectivity +{ + class java_sql_Driver : public ::cppu::WeakImplHelper< css::sdbc::XDriver,css::lang::XServiceInfo> + { + css::uno::Reference<css::uno::XComponentContext> m_aContext; + ::comphelper::EventLogger m_aLogger; + + protected: + virtual ~java_sql_Driver() override; + + public: + java_sql_Driver(const css::uno::Reference< css::uno::XComponentContext >& _rxContext); + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName( ) override; + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; + + // XDriver + virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL connect( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override ; + virtual sal_Bool SAL_CALL acceptsURL( const OUString& url ) override ; + virtual css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override ; + virtual sal_Int32 SAL_CALL getMajorVersion( ) override ; + virtual sal_Int32 SAL_CALL getMinorVersion( ) override; + + const css::uno::Reference<css::uno::XComponentContext>& getContext() const { return m_aContext; } + const ::comphelper::EventLogger& getLogger() const { return m_aLogger; } + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/DriverPropertyInfo.hxx b/connectivity/source/inc/java/sql/DriverPropertyInfo.hxx new file mode 100644 index 0000000000..4bc6816226 --- /dev/null +++ b/connectivity/source/inc/java/sql/DriverPropertyInfo.hxx @@ -0,0 +1,42 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <java/lang/Object.hxx> + +namespace connectivity +{ + + +//************ Class: java.sql.DriverPropertyInfo + + class java_sql_DriverPropertyInfo : public java_lang_Object + { + protected: + // Static data for the class + static jclass theClass; + public: + virtual jclass getMyClass() const override; + virtual ~java_sql_DriverPropertyInfo() override; + }; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/JStatement.hxx b/connectivity/source/inc/java/sql/JStatement.hxx new file mode 100644 index 0000000000..89a091bd96 --- /dev/null +++ b/connectivity/source/inc/java/sql/JStatement.hxx @@ -0,0 +1,234 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <java/lang/Object.hxx> +#include <com/sun/star/sdbc/XStatement.hpp> +#include <com/sun/star/sdbc/XWarningsSupplier.hpp> +#include <com/sun/star/sdbc/XMultipleResults.hpp> +#include <com/sun/star/sdbc/XBatchExecution.hpp> +#include <com/sun/star/sdbc/XCloseable.hpp> +#include <com/sun/star/util/XCancellable.hpp> +#include <com/sun/star/sdbc/XGeneratedResultSet.hpp> +#include <comphelper/proparrhlp.hxx> +#include <cppuhelper/compbase.hxx> +#include <cppuhelper/basemutex.hxx> +#include <connectivity/CommonTools.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> + +#include <java/sql/Connection.hxx> +#include <java/sql/ConnectionLog.hxx> + +namespace connectivity +{ + + typedef ::cppu::WeakComponentImplHelper< css::sdbc::XStatement, + css::sdbc::XWarningsSupplier, + css::util::XCancellable, + css::sdbc::XCloseable, + css::sdbc::XGeneratedResultSet, + css::sdbc::XMultipleResults> java_sql_Statement_BASE; + + //************ Class: java.sql.Statement + + class java_sql_Statement_Base : public cppu::BaseMutex, + public java_sql_Statement_BASE, + public java_lang_Object, + public ::cppu::OPropertySetHelper, + public ::comphelper::OPropertyArrayUsageHelper<java_sql_Statement_Base> + + { + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getQueryTimeOut(); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getMaxFieldSize(); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getMaxRows(); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getResultSetConcurrency(); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getResultSetType(); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getFetchDirection(); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getFetchSize(); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + OUString getCursorName(); + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setQueryTimeOut(sal_Int32 _par0); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setMaxFieldSize(sal_Int32 _par0); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setMaxRows(sal_Int32 _par0); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setResultSetConcurrency(sal_Int32 _par0); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setResultSetType(sal_Int32 _par0); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setFetchDirection(sal_Int32 _par0); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setFetchSize(sal_Int32 _par0); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setCursorName(const OUString &_par0); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setEscapeProcessing(bool _par0); + + protected: + css::uno::Reference< css::sdbc::XStatement> m_xGeneratedStatement; + rtl::Reference<java_sql_Connection> m_pConnection; + java::sql::ConnectionLog m_aLogger; + OUString m_sSqlStatement; + // Properties + sal_Int32 m_nResultSetConcurrency; + sal_Int32 m_nResultSetType; + bool m_bEscapeProcessing; + + + // Static data for the class + static jclass theClass; + + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override; + // OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + + virtual sal_Bool SAL_CALL convertFastPropertyValue( + css::uno::Any & rConvertedValue, + css::uno::Any & rOldValue, + sal_Int32 nHandle, + const css::uno::Any& rValue + ) override; + + virtual void SAL_CALL setFastPropertyValue_NoBroadcast( + sal_Int32 nHandle, + const css::uno::Any& rValue + ) override; + + virtual void SAL_CALL getFastPropertyValue( + css::uno::Any& rValue, + sal_Int32 nHandle + ) const override; + + virtual void createStatement(JNIEnv* _pEnv) = 0; + + virtual ~java_sql_Statement_Base() override; + + sal_Int32 impl_getProperty(const char* _pMethodName, jmethodID& _inout_MethodID); + sal_Int32 impl_getProperty(const char* _pMethodName, jmethodID& _inout_MethodID,sal_Int32 _nDefault); + + public: + virtual jclass getMyClass() const override; + + // A ctor that is needed for returning the object + java_sql_Statement_Base( JNIEnv * pEnv, java_sql_Connection& _rCon ); + + sal_Int32 getStatementObjectID() const { return m_aLogger.getObjectID(); } + + // OComponentHelper + virtual void SAL_CALL disposing() override; + // XInterface + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + + // XPropertySet + virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; + // XStatement + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL executeQuery( const OUString& sql ) override ; + virtual sal_Int32 SAL_CALL executeUpdate( const OUString& sql ) override ; + virtual sal_Bool SAL_CALL execute( const OUString& sql ) override ; + virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( ) override ; + // XWarningsSupplier + virtual css::uno::Any SAL_CALL getWarnings( ) override; + virtual void SAL_CALL clearWarnings( ) override; + // XCancellable + virtual void SAL_CALL cancel( ) override; + // XCloseable + virtual void SAL_CALL close( ) override; + // XMultipleResults + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getResultSet( ) override; + virtual sal_Int32 SAL_CALL getUpdateCount( ) override; + virtual sal_Bool SAL_CALL getMoreResults( ) override; + //XGeneratedResultSet + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getGeneratedValues( ) override; + + public: + using ::cppu::OPropertySetHelper::getFastPropertyValue; + }; + + class OStatement_BASE2 : public java_sql_Statement_Base + + { + public: + OStatement_BASE2(JNIEnv * pEnv, java_sql_Connection& _rCon ) : java_sql_Statement_Base( pEnv, _rCon ) {} + + // OComponentHelper + virtual void SAL_CALL disposing() override; + }; + + class java_sql_Statement : public OStatement_BASE2, + public css::sdbc::XBatchExecution, + public css::lang::XServiceInfo + { + protected: + // Static data for the class + static jclass theClass; + + virtual void createStatement(JNIEnv* _pEnv) override; + + virtual ~java_sql_Statement() override; + public: + DECLARE_SERVICE_INFO(); + virtual jclass getMyClass() const override; + + // A ctor that is needed for returning the object + java_sql_Statement( JNIEnv * pEnv, java_sql_Connection& _rCon ) : OStatement_BASE2( pEnv, _rCon){}; + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + // XBatchExecution + virtual void SAL_CALL addBatch( const OUString& sql ) override; + virtual void SAL_CALL clearBatch( ) override; + virtual css::uno::Sequence< sal_Int32 > SAL_CALL executeBatch( ) override; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/PreparedStatement.hxx b/connectivity/source/inc/java/sql/PreparedStatement.hxx new file mode 100644 index 0000000000..711fd2d006 --- /dev/null +++ b/connectivity/source/inc/java/sql/PreparedStatement.hxx @@ -0,0 +1,103 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <java/sql/JStatement.hxx> +#include <com/sun/star/sdbc/XPreparedStatement.hpp> +#include <com/sun/star/sdbc/XParameters.hpp> +#include <com/sun/star/sdbc/XPreparedBatchExecution.hpp> +#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> + +namespace connectivity +{ + + //************ Class: java.sql.PreparedStatement + + + class java_sql_PreparedStatement : public OStatement_BASE2, + public css::sdbc::XPreparedStatement, + public css::sdbc::XResultSetMetaDataSupplier, + public css::sdbc::XParameters, + public css::sdbc::XPreparedBatchExecution, + public css::lang::XServiceInfo + { + protected: + // Static data for the class + static jclass theClass; + + virtual void createStatement(JNIEnv* _pEnv) override; + virtual ~java_sql_PreparedStatement() override; + public: + DECLARE_SERVICE_INFO(); + virtual jclass getMyClass() const override; + + // A ctor that is needed for returning the object + java_sql_PreparedStatement( JNIEnv * pEnv, java_sql_Connection& _rCon,const OUString& sql ); + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + + // XPreparedStatement + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL executeQuery( ) override; + virtual sal_Int32 SAL_CALL executeUpdate( ) override; + virtual sal_Bool SAL_CALL execute( ) override; + virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( ) override; + // XParameters + virtual void SAL_CALL setNull( sal_Int32 parameterIndex, sal_Int32 sqlType ) override; + virtual void SAL_CALL setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const OUString& typeName ) override; + virtual void SAL_CALL setBoolean( sal_Int32 parameterIndex, sal_Bool x ) override; + virtual void SAL_CALL setByte( sal_Int32 parameterIndex, sal_Int8 x ) override; + virtual void SAL_CALL setShort( sal_Int32 parameterIndex, sal_Int16 x ) override; + virtual void SAL_CALL setInt( sal_Int32 parameterIndex, sal_Int32 x ) override; + virtual void SAL_CALL setLong( sal_Int32 parameterIndex, sal_Int64 x ) override; + virtual void SAL_CALL setFloat( sal_Int32 parameterIndex, float x ) override; + virtual void SAL_CALL setDouble( sal_Int32 parameterIndex, double x ) override; + virtual void SAL_CALL setString( sal_Int32 parameterIndex, const OUString& x ) override; + virtual void SAL_CALL setBytes( sal_Int32 parameterIndex, const css::uno::Sequence< sal_Int8 >& x ) override; + virtual void SAL_CALL setDate( sal_Int32 parameterIndex, const css::util::Date& x ) override; + virtual void SAL_CALL setTime( sal_Int32 parameterIndex, const css::util::Time& x ) override; + virtual void SAL_CALL setTimestamp( sal_Int32 parameterIndex, const css::util::DateTime& x ) override; + virtual void SAL_CALL setBinaryStream( sal_Int32 parameterIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override; + virtual void SAL_CALL setCharacterStream( sal_Int32 parameterIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override; + virtual void SAL_CALL setObject( sal_Int32 parameterIndex, const css::uno::Any& x ) override; + virtual void SAL_CALL setObjectWithInfo( sal_Int32 parameterIndex, const css::uno::Any& x, sal_Int32 targetSqlType, sal_Int32 scale ) override; + virtual void SAL_CALL setRef( sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XRef >& x ) override; + virtual void SAL_CALL setBlob( sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XBlob >& x ) override; + virtual void SAL_CALL setClob( sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XClob >& x ) override; + virtual void SAL_CALL setArray( sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XArray >& x ) override; + virtual void SAL_CALL clearParameters( ) override; + // XPreparedBatchExecution + virtual void SAL_CALL addBatch( ) override; + virtual void SAL_CALL clearBatch( ) override; + virtual css::uno::Sequence< sal_Int32 > SAL_CALL executeBatch( ) override; + // XResultSetMetaDataSupplier + virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData( ) override; + + public: + using java_sql_Statement_Base::executeQuery; + using java_sql_Statement_Base::executeUpdate; + using java_sql_Statement_Base::execute; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/Ref.hxx b/connectivity/source/inc/java/sql/Ref.hxx new file mode 100644 index 0000000000..f127178b27 --- /dev/null +++ b/connectivity/source/inc/java/sql/Ref.hxx @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <java/lang/Object.hxx> +#include <com/sun/star/sdbc/XRef.hpp> +#include <cppuhelper/implbase.hxx> + +namespace connectivity +{ + + //************ Class: java.sql.Ref + + class java_sql_Ref : public java_lang_Object, + public ::cppu::WeakImplHelper< css::sdbc::XRef> + { + protected: + // Static data for the class + static jclass theClass; + virtual ~java_sql_Ref() override; + public: + virtual jclass getMyClass() const override; + + // A ctor that is needed for returning the object + java_sql_Ref( JNIEnv * pEnv, jobject myObj ); + + // XRef + virtual OUString SAL_CALL getBaseTypeName( ) override; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/ResultSet.hxx b/connectivity/source/inc/java/sql/ResultSet.hxx new file mode 100644 index 0000000000..183c6fa3a3 --- /dev/null +++ b/connectivity/source/inc/java/sql/ResultSet.hxx @@ -0,0 +1,210 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <java/lang/Object.hxx> +#include <com/sun/star/sdbc/XResultSet.hpp> +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> +#include <com/sun/star/sdbc/XCloseable.hpp> +#include <com/sun/star/sdbc/XColumnLocate.hpp> +#include <com/sun/star/util/XCancellable.hpp> +#include <com/sun/star/sdbc/XWarningsSupplier.hpp> +#include <com/sun/star/sdbc/XResultSetUpdate.hpp> +#include <com/sun/star/sdbc/XRowUpdate.hpp> +#include <cppuhelper/compbase.hxx> +#include <comphelper/proparrhlp.hxx> +#include <connectivity/CommonTools.hxx> +#include <java/sql/JStatement.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <java/sql/ConnectionLog.hxx> + +namespace connectivity +{ + + /* + ** java_sql_ResultSet + */ + typedef ::cppu::WeakComponentImplHelper< css::sdbc::XResultSet, + css::sdbc::XRow, + css::sdbc::XResultSetMetaDataSupplier, + css::util::XCancellable, + css::sdbc::XWarningsSupplier, + css::sdbc::XResultSetUpdate, + css::sdbc::XRowUpdate, + css::sdbc::XCloseable, + css::sdbc::XColumnLocate, + css::lang::XServiceInfo> java_sql_ResultSet_BASE; + + class java_sql_Connection; + class java_sql_ResultSet : public cppu::BaseMutex, + public java_sql_ResultSet_BASE, + public java_lang_Object, + public ::cppu::OPropertySetHelper, + public ::comphelper::OPropertyArrayUsageHelper<java_sql_ResultSet> + { + css::uno::Reference< css::uno::XInterface> m_xStatement; + java::sql::ConnectionLog m_aLogger; + java_sql_Connection* m_pConnection; + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getResultSetConcurrency() const; + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getResultSetType() const; + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getFetchDirection() const; + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getFetchSize() const; + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + OUString getCursorName() const; + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setFetchDirection(sal_Int32 _par0); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setFetchSize(sal_Int32 _par0); + protected: + // Static data for the class + static jclass theClass; + + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override; + // OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + + virtual sal_Bool SAL_CALL convertFastPropertyValue( + css::uno::Any & rConvertedValue, + css::uno::Any & rOldValue, + sal_Int32 nHandle, + const css::uno::Any& rValue ) override; + virtual void SAL_CALL setFastPropertyValue_NoBroadcast( + sal_Int32 nHandle, + const css::uno::Any& rValue + ) override; + virtual void SAL_CALL getFastPropertyValue( + css::uno::Any& rValue, + sal_Int32 nHandle + ) const override; + virtual ~java_sql_ResultSet() override; + public: + DECLARE_SERVICE_INFO(); + virtual jclass getMyClass() const override; + // A ctor that is needed for returning the object + java_sql_ResultSet( JNIEnv * pEnv, jobject myObj, const java::sql::ConnectionLog& _rParentLogger,java_sql_Connection& _rConnection, + java_sql_Statement_Base* pStmt = nullptr ); + + // ::cppu::OComponentHelper + virtual void SAL_CALL disposing() override; + // XInterface + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + // XPropertySet + virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; + // XResultSet + virtual sal_Bool SAL_CALL next( ) override; + virtual sal_Bool SAL_CALL isBeforeFirst( ) override; + virtual sal_Bool SAL_CALL isAfterLast( ) override; + virtual sal_Bool SAL_CALL isFirst( ) override; + virtual sal_Bool SAL_CALL isLast( ) override; + virtual void SAL_CALL beforeFirst( ) override; + virtual void SAL_CALL afterLast( ) override; + virtual sal_Bool SAL_CALL first( ) override; + virtual sal_Bool SAL_CALL last( ) override; + virtual sal_Int32 SAL_CALL getRow( ) override; + virtual sal_Bool SAL_CALL absolute( sal_Int32 row ) override; + virtual sal_Bool SAL_CALL relative( sal_Int32 rows ) override; + virtual sal_Bool SAL_CALL previous( ) override; + virtual void SAL_CALL refreshRow( ) override; + virtual sal_Bool SAL_CALL rowUpdated( ) override; + virtual sal_Bool SAL_CALL rowInserted( ) override; + virtual sal_Bool SAL_CALL rowDeleted( ) override; + virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getStatement( ) override; + // XRow + virtual sal_Bool SAL_CALL wasNull( ) override; + virtual OUString SAL_CALL getString( sal_Int32 columnIndex ) override; + virtual sal_Bool SAL_CALL getBoolean( sal_Int32 columnIndex ) override; + virtual sal_Int8 SAL_CALL getByte( sal_Int32 columnIndex ) override; + virtual sal_Int16 SAL_CALL getShort( sal_Int32 columnIndex ) override; + virtual sal_Int32 SAL_CALL getInt( sal_Int32 columnIndex ) override; + virtual sal_Int64 SAL_CALL getLong( sal_Int32 columnIndex ) override; + virtual float SAL_CALL getFloat( sal_Int32 columnIndex ) override; + virtual double SAL_CALL getDouble( sal_Int32 columnIndex ) override; + virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes( sal_Int32 columnIndex ) override; + virtual css::util::Date SAL_CALL getDate( sal_Int32 columnIndex ) override; + virtual css::util::Time SAL_CALL getTime( sal_Int32 columnIndex ) override; + virtual css::util::DateTime SAL_CALL getTimestamp( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream( sal_Int32 columnIndex ) override; + virtual css::uno::Any SAL_CALL getObject( sal_Int32 columnIndex, const css::uno::Reference< css::container::XNameAccess >& typeMap ) override; + virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray( sal_Int32 columnIndex ) override; + // XResultSetMetaDataSupplier + virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData( ) override; + // XCancellable + virtual void SAL_CALL cancel( ) override; + // XCloseable + virtual void SAL_CALL close( ) override; + // XWarningsSupplier + virtual css::uno::Any SAL_CALL getWarnings( ) override; + virtual void SAL_CALL clearWarnings( ) override; + // XResultSetUpdate + virtual void SAL_CALL insertRow( ) override; + virtual void SAL_CALL updateRow( ) override; + virtual void SAL_CALL deleteRow( ) override; + virtual void SAL_CALL cancelRowUpdates( ) override; + virtual void SAL_CALL moveToInsertRow( ) override; + virtual void SAL_CALL moveToCurrentRow( ) override; + // XRowUpdate + virtual void SAL_CALL updateNull( sal_Int32 columnIndex ) override; + virtual void SAL_CALL updateBoolean( sal_Int32 columnIndex, sal_Bool x ) override; + virtual void SAL_CALL updateByte( sal_Int32 columnIndex, sal_Int8 x ) override; + virtual void SAL_CALL updateShort( sal_Int32 columnIndex, sal_Int16 x ) override; + virtual void SAL_CALL updateInt( sal_Int32 columnIndex, sal_Int32 x ) override; + virtual void SAL_CALL updateLong( sal_Int32 columnIndex, sal_Int64 x ) override; + virtual void SAL_CALL updateFloat( sal_Int32 columnIndex, float x ) override; + virtual void SAL_CALL updateDouble( sal_Int32 columnIndex, double x ) override; + virtual void SAL_CALL updateString( sal_Int32 columnIndex, const OUString& x ) override; + virtual void SAL_CALL updateBytes( sal_Int32 columnIndex, const css::uno::Sequence< sal_Int8 >& x ) override; + virtual void SAL_CALL updateDate( sal_Int32 columnIndex, const css::util::Date& x ) override; + virtual void SAL_CALL updateTime( sal_Int32 columnIndex, const css::util::Time& x ) override; + virtual void SAL_CALL updateTimestamp( sal_Int32 columnIndex, const css::util::DateTime& x ) override; + virtual void SAL_CALL updateBinaryStream( sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override; + virtual void SAL_CALL updateCharacterStream( sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override; + virtual void SAL_CALL updateObject( sal_Int32 columnIndex, const css::uno::Any& x ) override; + virtual void SAL_CALL updateNumericObject( sal_Int32 columnIndex, const css::uno::Any& x, sal_Int32 scale ) override; + // XColumnLocate + virtual sal_Int32 SAL_CALL findColumn( const OUString& columnName ) override; + + public: + using ::cppu::OPropertySetHelper::getFastPropertyValue; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/ResultSetMetaData.hxx b/connectivity/source/inc/java/sql/ResultSetMetaData.hxx new file mode 100644 index 0000000000..e5017f1158 --- /dev/null +++ b/connectivity/source/inc/java/sql/ResultSetMetaData.hxx @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <java/lang/Object.hxx> +#include <com/sun/star/sdbc/XResultSetMetaData.hpp> +#include <cppuhelper/implbase.hxx> + +namespace connectivity +{ + + //************ Class: java.sql.ResultSetMetaData + + class java_sql_Connection; + class java_sql_ResultSetMetaData final : public ::cppu::WeakImplHelper< css::sdbc::XResultSetMetaData>, + public java_lang_Object + { + java_sql_Connection* m_pConnection; + sal_Int32 m_nColumnCount; + + // Static data for the class + static jclass theClass; + virtual ~java_sql_ResultSetMetaData() override; + public: + virtual jclass getMyClass() const override; + + // A ctor that is needed for returning the object + java_sql_ResultSetMetaData( JNIEnv * pEnv, jobject myObj, java_sql_Connection& _rCon ); + + virtual sal_Int32 SAL_CALL getColumnCount( ) override; + virtual sal_Bool SAL_CALL isAutoIncrement( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isCaseSensitive( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isSearchable( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isCurrency( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL isNullable( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isSigned( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getColumnDisplaySize( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnLabel( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnName( sal_Int32 column ) override; + virtual OUString SAL_CALL getSchemaName( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getPrecision( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getScale( sal_Int32 column ) override; + virtual OUString SAL_CALL getTableName( sal_Int32 column ) override; + virtual OUString SAL_CALL getCatalogName( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getColumnType( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnTypeName( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isReadOnly( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isWritable( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isDefinitelyWritable( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnServiceName( sal_Int32 column ) override; + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/SQLException.hxx b/connectivity/source/inc/java/sql/SQLException.hxx new file mode 100644 index 0000000000..cff1aad466 --- /dev/null +++ b/connectivity/source/inc/java/sql/SQLException.hxx @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <java/lang/Exception.hxx> +#include <com/sun/star/sdbc/SQLException.hpp> + +namespace connectivity +{ + //************ Class: java.sql.SQLException + + class java_sql_SQLException_BASE; + class java_sql_SQLException : public css::sdbc::SQLException + { + public: + // A ctor that is needed for returning the object + java_sql_SQLException( const java_sql_SQLException_BASE& _rException,const css::uno::Reference< css::uno::XInterface> & _rContext); + }; + + class java_sql_SQLException_BASE : public java_lang_Exception + { + protected: + // Static data for the class + static jclass theClass; + public: + virtual jclass getMyClass() const override; + virtual ~java_sql_SQLException_BASE() override; + // A ctor that is needed for returning the object + java_sql_SQLException_BASE( JNIEnv * pEnv, jobject myObj ); + + OUString getSQLState() const; + sal_Int32 getErrorCode() const; + css::sdbc::SQLException getNextException() const; + + static jclass st_getMyClass(); + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/SQLWarning.hxx b/connectivity/source/inc/java/sql/SQLWarning.hxx new file mode 100644 index 0000000000..5fd8c97943 --- /dev/null +++ b/connectivity/source/inc/java/sql/SQLWarning.hxx @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <java/sql/SQLException.hxx> + +namespace connectivity +{ + //************ Class: java.sql.SQLWarning + + class java_sql_SQLWarning_BASE : public java_sql_SQLException_BASE + { + protected: + // Static data for the class + static jclass theClass; + public: + virtual jclass getMyClass() const override; + virtual ~java_sql_SQLWarning_BASE() override; + // A ctor that is needed for returning the object + java_sql_SQLWarning_BASE( JNIEnv * pEnv, jobject myObj ) : java_sql_SQLException_BASE( pEnv, myObj ){} + + }; + + class java_sql_SQLWarning : public java_sql_SQLException + { + public: + java_sql_SQLWarning(const java_sql_SQLWarning_BASE& _rW,const css::uno::Reference< css::uno::XInterface> & _rContext) + : java_sql_SQLException(_rW,_rContext) {} + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/Timestamp.hxx b/connectivity/source/inc/java/sql/Timestamp.hxx new file mode 100644 index 0000000000..599dfb78e4 --- /dev/null +++ b/connectivity/source/inc/java/sql/Timestamp.hxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <java/util/Date.hxx> +#include <com/sun/star/util/Date.hpp> +#include <com/sun/star/util/Time.hpp> +#include <com/sun/star/util/DateTime.hpp> + + +namespace connectivity +{ + + //************ Class: java.sql.Date + + + class java_sql_Date : public java_util_Date + { + protected: + // static data for the class + static jclass theClass; + public: + virtual jclass getMyClass() const override; + virtual ~java_sql_Date() override; + // A ctor that is needed for returning the object + java_sql_Date( JNIEnv * pEnv, jobject myObj ) : java_util_Date(pEnv,myObj){} + java_sql_Date( const css::util::Date& _rOut ); + + operator css::util::Date(); + static jclass st_getMyClass(); + }; + + + //************ Class: java.sql.Time + + + class java_sql_Time : public java_util_Date + { + protected: + // static data for the class + static jclass theClass; + public: + virtual jclass getMyClass() const override; + virtual ~java_sql_Time() override; + // A ctor that is needed for returning the object + java_sql_Time( JNIEnv * pEnv, jobject myObj ) : java_util_Date( pEnv, myObj ){} + java_sql_Time( const css::util::Time& _rOut ); + operator css::util::Time(); + static jclass st_getMyClass(); + }; + + + //************ Class: java.sql.Timestamp + + class java_sql_Timestamp : public java_util_Date + { + protected: + // static data for the class + static jclass theClass; + public: + virtual jclass getMyClass() const override; + virtual ~java_sql_Timestamp() override; + // A ctor that is needed for returning the object + java_sql_Timestamp( JNIEnv * pEnv, jobject myObj ) : java_util_Date( pEnv, myObj ){} + java_sql_Timestamp( const css::util::DateTime& _rOut); + operator css::util::DateTime(); + + static jclass st_getMyClass(); + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/tools.hxx b/connectivity/source/inc/java/tools.hxx new file mode 100644 index 0000000000..44a35ecee3 --- /dev/null +++ b/connectivity/source/inc/java/tools.hxx @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sal/config.h> + +#include <memory> + +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/uno/Sequence.h> + +#if defined __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-attributes" +#endif +#include <jni.h> +#if defined __clang__ +#pragma clang diagnostic pop +#endif + +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/io/XInputStream.hpp> + + +namespace connectivity +{ + + jstring convertwchar_tToJavaString(JNIEnv *pEnv,const OUString& Temp); + OUString JavaString2String(JNIEnv *pEnv,jstring Str); + class java_util_Properties; + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + std::unique_ptr<java_util_Properties> createStringPropertyArray(const css::uno::Sequence< css::beans::PropertyValue >& info ); + + jobject convertTypeMapToJavaMap(const css::uno::Reference< css::container::XNameAccess > & _rMap); + + /** return if an exception occurred + the exception will be cleared. + @param pEnv + The native java env + */ + bool isExceptionOccurred(JNIEnv *pEnv); + + jobject createByteInputStream(const css::uno::Reference< css::io::XInputStream >& x,sal_Int32 length); + jobject createCharArrayReader(const css::uno::Reference< css::io::XInputStream >& x,sal_Int32 length); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/util/Date.hxx b/connectivity/source/inc/java/util/Date.hxx new file mode 100644 index 0000000000..fe55242867 --- /dev/null +++ b/connectivity/source/inc/java/util/Date.hxx @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <java/lang/Object.hxx> +//#include <com/sun/star/util/Date.hpp> + +namespace connectivity +{ + + + //************ Class: java.util.Date + + + class java_util_Date : public java_lang_Object + { + protected: + // Static data for the class + static jclass theClass; + public: + virtual jclass getMyClass() const override; + virtual ~java_util_Date() override; + // A ctor that is needed for returning the object + java_util_Date( JNIEnv * pEnv, jobject myObj ) : java_lang_Object( pEnv, myObj ){} + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/util/Property.hxx b/connectivity/source/inc/java/util/Property.hxx new file mode 100644 index 0000000000..628f951ba4 --- /dev/null +++ b/connectivity/source/inc/java/util/Property.hxx @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <java/lang/Object.hxx> + +namespace connectivity +{ + class java_util_Properties : public java_lang_Object + { + protected: + // Static data for the class + static jclass theClass; + public: + virtual jclass getMyClass() const override; + virtual ~java_util_Properties() override; + java_util_Properties( ); + void setProperty(const OUString& key, const OUString& value); + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/mysql/YCatalog.hxx b/connectivity/source/inc/mysql/YCatalog.hxx new file mode 100644 index 0000000000..5eb348af99 --- /dev/null +++ b/connectivity/source/inc/mysql/YCatalog.hxx @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <sdbcx/VCatalog.hxx> + +namespace connectivity::mysql + { + // please don't name the class the same name as in another namespaces + // some compilers have problems with this task as I noticed on windows + class OMySQLCatalog : public connectivity::sdbcx::OCatalog + { + css::uno::Reference< css::sdbc::XConnection > m_xConnection; + + /** calls XDatabaseMetaData::getTables. + @param _sKindOfObject + The type of tables to be fetched. + @param _rNames + The container for the names to be filled. <OUT/> + */ + void refreshObjects(const css::uno::Sequence< OUString >& _sKindOfObject,::std::vector< OUString>& _rNames); + + public: + // implementation of the pure virtual methods + virtual void refreshTables() override; + virtual void refreshViews() override ; + virtual void refreshGroups() override; + virtual void refreshUsers() override ; + + public: + OMySQLCatalog(const css::uno::Reference< css::sdbc::XConnection >& _xConnection); + + sdbcx::OCollection* getPrivateTables() const { return m_pTables.get();} + sdbcx::OCollection* getPrivateViews() const { return m_pViews.get(); } + const css::uno::Reference< css::sdbc::XConnection >& getConnection() const { return m_xConnection; } + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + // ::cppu::OComponentHelper + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/mysql/YColumns.hxx b/connectivity/source/inc/mysql/YColumns.hxx new file mode 100644 index 0000000000..1ffcfc9533 --- /dev/null +++ b/connectivity/source/inc/mysql/YColumns.hxx @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once +#include <connectivity/TColumnsHelper.hxx> +#include <connectivity/sdbcx/VColumn.hxx> + +namespace connectivity::mysql + { + class OMySQLColumns : public OColumnsHelper + { + protected: + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + public: + OMySQLColumns( ::cppu::OWeakObject& _rParent + ,::osl::Mutex& _rMutex + ,const ::std::vector< OUString> &_rVector + ); + }; + + class OMySQLColumn; + typedef ::comphelper::OIdPropertyArrayUsageHelper<OMySQLColumn> OMySQLColumn_PROP; + + class OMySQLColumn : public sdbcx::OColumn, + public OMySQLColumn_PROP + { + OUString m_sAutoIncrement; + protected: + virtual ::cppu::IPropertyArrayHelper* createArrayHelper( sal_Int32 _nId) const override; + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + + public: + OMySQLColumn(); + virtual void construct() override; + + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/mysql/YDriver.hxx b/connectivity/source/inc/mysql/YDriver.hxx new file mode 100644 index 0000000000..84fad1af1c --- /dev/null +++ b/connectivity/source/inc/mysql/YDriver.hxx @@ -0,0 +1,106 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <sal/config.h> + +#include <map> + +#include <com/sun/star/sdbc/XDriver.hpp> +#include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <cppuhelper/compbase.hxx> +#include <cppuhelper/basemutex.hxx> +#include <connectivity/CommonTools.hxx> + + +namespace connectivity +{ + + + class OMetaConnection; + + namespace mysql + { + typedef ::cppu::WeakComponentImplHelper< css::sdbc::XDriver + , css::sdbcx::XDataDefinitionSupplier + , css::lang::XServiceInfo + > ODriverDelegator_BASE; + + typedef std::pair< css::uno::WeakReferenceHelper,OMetaConnection*> TWeakConnectionPair; + typedef std::pair< css::uno::WeakReferenceHelper,TWeakConnectionPair> TWeakPair; + typedef std::vector< TWeakPair > TWeakPairVector; + typedef std::map< OUString, css::uno::Reference< css::sdbc::XDriver > > TJDBCDrivers; + + /** delegates all calls to the original driver and extend the existing one with the SDBCX layer. + + */ + class ODriverDelegator : public ::cppu::BaseMutex + ,public ODriverDelegator_BASE + { + TJDBCDrivers m_aJdbcDrivers; // all jdbc drivers + TWeakPairVector m_aConnections; // vector containing a list + // of all the Connection objects + // for this Driver + css::uno::Reference< css::sdbc::XDriver > m_xODBCDriver; + css::uno::Reference< css::sdbc::XDriver > m_xNativeDriver; + css::uno::Reference< css::uno::XComponentContext > m_xContext; + + /** load the driver we want to delegate. + The <member>m_xODBCDriver</member> or <member>m_xDBCDriver</member> may be <NULL/> if the driver could not be loaded. + @param url + The URL. + @param info + The property info contains which driver we have to delegate. + @return + The driver which was currently selected. + */ + css::uno::Reference< css::sdbc::XDriver > loadDriver( std::u16string_view url, const css::uno::Sequence< css::beans::PropertyValue >& info ); + + public: + /** creates a new delegator for a mysql driver + */ + ODriverDelegator(const css::uno::Reference< css::uno::XComponentContext >& _rxContext); + + // XServiceInfo + DECLARE_SERVICE_INFO(); + + // XDriver + virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL connect( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + virtual sal_Bool SAL_CALL acceptsURL( const OUString& url ) override; + virtual css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + virtual sal_Int32 SAL_CALL getMajorVersion( ) override; + virtual sal_Int32 SAL_CALL getMinorVersion( ) override; + + // XDataDefinitionSupplier + virtual css::uno::Reference< css::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByConnection( const css::uno::Reference< css::sdbc::XConnection >& connection ) override; + virtual css::uno::Reference< css::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByURL( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + protected: + /// dtor + virtual ~ODriverDelegator() override; + // OComponentHelper + virtual void SAL_CALL disposing() override; + }; + } + + +} // namespace connectivity + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/mysql/YTable.hxx b/connectivity/source/inc/mysql/YTable.hxx new file mode 100644 index 0000000000..c891b7d7d9 --- /dev/null +++ b/connectivity/source/inc/mysql/YTable.hxx @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sal/config.h> + +#include <string_view> + +#include <connectivity/TTableHelper.hxx> +#include <comphelper/IdPropArrayHelper.hxx> + +namespace connectivity::mysql + { + + class OMySQLTable; + typedef ::comphelper::OIdPropertyArrayUsageHelper< OMySQLTable > OMySQLTable_PROP; + class OMySQLTable : public OTableHelper + ,public OMySQLTable_PROP + { + sal_Int32 m_nPrivileges; // we have to set our privileges by our own + + /** executes the statement. + @param _rStatement + The statement to execute. + */ + void executeStatement(const OUString& _rStatement ); + protected: + + /** creates the column collection for the table + @param _rNames + The column names. + */ + virtual sdbcx::OCollection* createColumns(const ::std::vector< OUString>& _rNames) override; + + /** creates the key collection for the table + @param _rNames + The key names. + */ + virtual sdbcx::OCollection* createKeys(const ::std::vector< OUString>& _rNames) override; + + /** creates the index collection for the table + @param _rNames + The index names. + */ + virtual sdbcx::OCollection* createIndexes(const ::std::vector< OUString>& _rNames) override; + + /** Returns always "RENAME TABLE " even for views. + * + * \return The start of the rename statement. + * @see http://dev.mysql.com/doc/refman/5.1/de/rename-table.html + */ + virtual OUString getRenameStart() const override; + + /** used to implement the creation of the array helper which is shared amongst all instances of the class. + This method needs to be implemented in derived classes. + <BR> + The method gets called with s_aMutex acquired. + @return a pointer to the newly created array helper. Must not be NULL. + */ + virtual ::cppu::IPropertyArrayHelper* createArrayHelper(sal_Int32 nId) const override; + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + + public: + OMySQLTable( sdbcx::OCollection* _pTables, + const css::uno::Reference< css::sdbc::XConnection >& _xConnection); + OMySQLTable( sdbcx::OCollection* _pTables, + const css::uno::Reference< css::sdbc::XConnection >& _xConnection, + const OUString& Name, + const OUString& Type, + const OUString& Description, + const OUString& SchemaName, + const OUString& CatalogName, + sal_Int32 _nPrivileges + ); + + // ODescriptor + virtual void construct() override; + + // XAlterTable + virtual void SAL_CALL alterColumnByName( const OUString& colName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + /** returns the ALTER TABLE XXX statement + */ + OUString getAlterTableColumnPart() const; + + // some methods to alter table structures + void alterColumnType(sal_Int32 nNewType,const OUString& _rColName,const css::uno::Reference< css::beans::XPropertySet >& _xDescriptor); + void alterDefaultValue(std::u16string_view _sNewDefault,const OUString& _rColName); + void dropDefaultValue(const OUString& _sNewDefault); + + virtual OUString getTypeCreatePattern() const override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/mysql/YTables.hxx b/connectivity/source/inc/mysql/YTables.hxx new file mode 100644 index 0000000000..3e3283ca96 --- /dev/null +++ b/connectivity/source/inc/mysql/YTables.hxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <connectivity/sdbcx/VCollection.hxx> +#include <SQLStatementHelper.hxx> +#include <com/sun/star/sdbc/XDatabaseMetaData.hpp> +#include <utility> +namespace connectivity::mysql + { + class OTables final : public sdbcx::OCollection, + public ::dbtools::ISQLStatementHelper + { + css::uno::Reference< css::sdbc::XDatabaseMetaData > m_xMetaData; + + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void dropObject(sal_Int32 _nPos, const OUString& _sElementName) override; + + void createTable( const css::uno::Reference< css::beans::XPropertySet >& descriptor ); + virtual OUString getNameForObject(const sdbcx::ObjectType& _xObject) override; + public: + OTables(css::uno::Reference< css::sdbc::XDatabaseMetaData > _xMetaData, ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector) : sdbcx::OCollection(_rParent, true, _rMutex, _rVector) + ,m_xMetaData(std::move(_xMetaData)) + {} + + // only the name is identical to ::cppu::OComponentHelper + virtual void disposing() override; + + // XDrop + void appendNew(const OUString& _rsNewTable); + + /** convert the sql statement to fit MySQL notation + @param _sSql in/out + */ + static OUString adjustSQL(const OUString& _sSql); + + // ISQLStatementHelper + virtual void addComment(const css::uno::Reference< css::beans::XPropertySet >& descriptor,OUStringBuffer& _rOut) override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/mysql/YUser.hxx b/connectivity/source/inc/mysql/YUser.hxx new file mode 100644 index 0000000000..1713f63bfb --- /dev/null +++ b/connectivity/source/inc/mysql/YUser.hxx @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sdbcx/VUser.hxx> +#include <com/sun/star/sdbc/XConnection.hpp> + +namespace connectivity::mysql + { + typedef connectivity::sdbcx::OUser OUser_TYPEDEF; + + class OMySQLUser : public OUser_TYPEDEF + { + css::uno::Reference< css::sdbc::XConnection > m_xConnection; + + static OUString getPrivilegeString(sal_Int32 nRights); + // return the privileges and additional the grant rights + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void findPrivilegesAndGrantPrivileges(const OUString& objName, sal_Int32 objType,sal_Int32& nRights,sal_Int32& nRightsWithGrant); + public: + virtual void refreshGroups() override; + public: + OMySQLUser( css::uno::Reference< css::sdbc::XConnection > _xConnection); + OMySQLUser( css::uno::Reference< css::sdbc::XConnection > _xConnection, const OUString& Name); + + // XUser + virtual void SAL_CALL changePassword( const OUString& objPassword, const OUString& newPassword ) override; + // XAuthorizable + virtual sal_Int32 SAL_CALL getPrivileges( const OUString& objName, sal_Int32 objType ) override; + virtual sal_Int32 SAL_CALL getGrantablePrivileges( const OUString& objName, sal_Int32 objType ) override; + virtual void SAL_CALL grantPrivileges( const OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) override; + virtual void SAL_CALL revokePrivileges( const OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) override; + }; + + class OUserExtend; + typedef ::comphelper::OPropertyArrayUsageHelper<OUserExtend> OUserExtend_PROP; + + class OUserExtend : public OMySQLUser, + public OUserExtend_PROP + { + OUString m_Password; + protected: + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const override; + // OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + public: + OUserExtend(const css::uno::Reference< css::sdbc::XConnection >& _xConnection); + + virtual void construct() override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/mysql/YUsers.hxx b/connectivity/source/inc/mysql/YUsers.hxx new file mode 100644 index 0000000000..e4b35c12e7 --- /dev/null +++ b/connectivity/source/inc/mysql/YUsers.hxx @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <connectivity/sdbcx/VCollection.hxx> +#include <com/sun/star/sdbc/XConnection.hpp> +namespace connectivity +{ + namespace sdbcx + { + class IRefreshableUsers; + } + namespace mysql + { + class OUsers : public sdbcx::OCollection + { + css::uno::Reference< css::sdbc::XConnection > m_xConnection; + connectivity::sdbcx::IRefreshableUsers* m_pParent; + public: + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual void impl_refresh() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void dropObject(sal_Int32 _nPos,const OUString& _sElementName) override; + public: + OUsers( ::cppu::OWeakObject& _rParent, + ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector, + css::uno::Reference< css::sdbc::XConnection > _xConnection, + connectivity::sdbcx::IRefreshableUsers* _pParent); + }; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/mysql/YViews.hxx b/connectivity/source/inc/mysql/YViews.hxx new file mode 100644 index 0000000000..2e9a1b2516 --- /dev/null +++ b/connectivity/source/inc/mysql/YViews.hxx @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <connectivity/sdbcx/VCollection.hxx> +#include <com/sun/star/sdbc/XDatabaseMetaData.hpp> +#include <utility> +namespace connectivity::mysql + { + class OViews final : public sdbcx::OCollection + { + css::uno::Reference< css::sdbc::XDatabaseMetaData > m_xMetaData; + bool m_bInDrop; + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void dropObject(sal_Int32 _nPos, const OUString& _sElementName) override; + + void createView( const css::uno::Reference< css::beans::XPropertySet >& descriptor ); + public: + OViews(css::uno::Reference< css::sdbc::XDatabaseMetaData > _xMetaData, ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector) : sdbcx::OCollection(_rParent, true, _rMutex, _rVector) + ,m_xMetaData(std::move(_xMetaData)) + ,m_bInDrop(false) + {} + + // only the name is identical to ::cppu::OComponentHelper + virtual void disposing() override; + + void dropByNameImpl(const OUString& elementName); + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/OBoundParam.hxx b/connectivity/source/inc/odbc/OBoundParam.hxx new file mode 100644 index 0000000000..77d09ba297 --- /dev/null +++ b/connectivity/source/inc/odbc/OBoundParam.hxx @@ -0,0 +1,128 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/sdbc/DataType.hpp> +#include <odbc/odbcbasedllapi.hxx> +#include <connectivity/odbc.hxx> + +namespace connectivity::odbc + { + class OOO_DLLPUBLIC_ODBCBASE OBoundParam + { + + public: + OBoundParam() + : binaryData(nullptr) + , paramLength(0) + , paramInputStreamLen(0) + { + } + ~OBoundParam() + { + free(binaryData); + } + + // allocBindDataBuffer + // Allocates and returns a new bind data buffer of the specified + // length + + void* allocBindDataBuffer (sal_Int32 bufLen) + { + // Reset the input stream and sequence, we are doing a new bind + setInputStream (nullptr, 0); + aSequence.realloc(0); + + free(binaryData); + binaryData = (bufLen > 0) ? malloc(bufLen) : nullptr; + + return binaryData; + } + + + // getBindLengthBuffer + // Returns the length buffer to be used when binding to a parameter + + SQLLEN& getBindLengthBuffer () + { + return paramLength; + } + + + // setInputStream + // Sets the input stream for the bound parameter + + void setInputStream(const css::uno::Reference< css::io::XInputStream>& inputStream, + sal_Int32 len) + { + paramInputStream = inputStream; + paramInputStreamLen = len; + } + + void setSequence(const css::uno::Sequence< sal_Int8 >& _aSequence) + { + aSequence = _aSequence; + } + + + // getInputStream + // Gets the input stream for the bound parameter + + const css::uno::Reference< css::io::XInputStream>& getInputStream () const + { + return paramInputStream; + } + + + // getInputStreamLen + // Gets the input stream length for the bound parameter + + sal_Int32 getInputStreamLen () const + { + return paramInputStreamLen; + } + + + private: + + // Data attributes + + + void *binaryData; // Storage area to be used + // when binding the parameter + + SQLLEN paramLength; // Storage area to be used + // for the bound length of the + // parameter. Note that this + // data is in native format. + + css::uno::Reference< css::io::XInputStream> paramInputStream; + css::uno::Sequence< sal_Int8 > aSequence; + // When an input stream is + // bound to a parameter, a + // reference to the input stream is saved + // until not needed anymore. + + sal_Int32 paramInputStreamLen; // Length of input stream + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/OConnection.hxx b/connectivity/source/inc/odbc/OConnection.hxx new file mode 100644 index 0000000000..b08544b859 --- /dev/null +++ b/connectivity/source/inc/odbc/OConnection.hxx @@ -0,0 +1,126 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <com/sun/star/sdbc/SQLWarning.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <connectivity/odbc.hxx> +#include <odbc/odbcbasedllapi.hxx> +#include <connectivity/CommonTools.hxx> +#include <TConnection.hxx> +#include <OTypeInfo.hxx> +#include <odbc/OTools.hxx> +#include <cppuhelper/weakref.hxx> +#include <AutoRetrievingBase.hxx> +#include <osl/module.h> +#include <rtl/ref.hxx> + + +#include <map> + +namespace connectivity::odbc + { + class ODBCDriver; + + typedef connectivity::OMetaConnection OConnection_BASE; + typedef std::vector< ::connectivity::OTypeInfo> TTypeInfoVector; + + class OOO_DLLPUBLIC_ODBCBASE OConnection final : + public OConnection_BASE, + public OAutoRetrievingBase + { + // Data attributes + + std::map< SQLHANDLE, rtl::Reference<OConnection>> m_aConnections; // holds all connections which are need for several statements + + + OUString m_sUser; // the user name + rtl::Reference<ODBCDriver> + m_xDriver; // Pointer to the owning + // driver object + + SQLHANDLE m_aConnectionHandle; + SQLHANDLE m_pDriverHandleCopy; // performance reason + sal_Int32 m_nStatementCount; + bool m_bClosed; + bool m_bUseCatalog; // should we use the catalog on filebased databases + bool m_bUseOldDateFormat; + bool m_bIgnoreDriverPrivileges; + bool m_bPreventGetVersionColumns; // #i60273# + bool m_bReadOnly; + + + SQLRETURN OpenConnection(const OUString& aConnectStr,sal_Int32 nTimeOut, bool bSilent); + + public: + oslGenericFunction getOdbcFunction(ODBC3SQLFunctionId _nIndex) const; + /// @throws css::sdbc::SQLException + SQLRETURN Construct( const OUString& url,const css::uno::Sequence< css::beans::PropertyValue >& info); + + OConnection(const SQLHANDLE _pDriverHandle,ODBCDriver* _pDriver); + // OConnection(const SQLHANDLE _pConnectionHandle); + virtual ~OConnection() override; + + // OComponentHelper + virtual void SAL_CALL disposing() override; + + // XServiceInfo + DECLARE_SERVICE_INFO(); + // XConnection + virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement( ) override; + virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const OUString& sql ) override; + virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall( const OUString& sql ) override; + virtual OUString SAL_CALL nativeSQL( const OUString& sql ) override; + virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) override; + virtual sal_Bool SAL_CALL getAutoCommit( ) override; + virtual void SAL_CALL commit( ) override; + virtual void SAL_CALL rollback( ) override; + virtual sal_Bool SAL_CALL isClosed( ) override; + virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( ) override; + virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) override; + virtual sal_Bool SAL_CALL isReadOnly( ) override; + virtual void SAL_CALL setCatalog( const OUString& catalog ) override; + virtual OUString SAL_CALL getCatalog( ) override; + virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) override; + virtual sal_Int32 SAL_CALL getTransactionIsolation( ) override; + virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTypeMap( ) override; + virtual void SAL_CALL setTypeMap( const css::uno::Reference< css::container::XNameAccess >& typeMap ) override; + // XCloseable + virtual void SAL_CALL close( ) override; + // XWarningsSupplier + virtual css::uno::Any SAL_CALL getWarnings( ) override; + virtual void SAL_CALL clearWarnings( ) override; + + SQLHANDLE getConnection() { return m_aConnectionHandle; } + + // should we use the catalog on filebased databases + bool isCatalogUsed() const { return m_bUseCatalog; } + bool isIgnoreDriverPrivilegesEnabled() const { return m_bIgnoreDriverPrivileges; } + bool preventGetVersionColumns() const { return m_bPreventGetVersionColumns; } + bool useOldDateFormat() const { return m_bUseOldDateFormat; } + ODBCDriver* getDriver() const { return m_xDriver.get();} + + SQLHANDLE createStatementHandle(); + // close and free the handle and set it to SQL_NULLHANDLE + void freeStatementHandle(SQLHANDLE& _pHandle); + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/ODatabaseMetaData.hxx b/connectivity/source/inc/odbc/ODatabaseMetaData.hxx new file mode 100644 index 0000000000..b0b4a6552a --- /dev/null +++ b/connectivity/source/inc/odbc/ODatabaseMetaData.hxx @@ -0,0 +1,203 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <odbc/OConnection.hxx> +#include <odbc/odbcbasedllapi.hxx> +#include <TDatabaseMetaDataBase.hxx> + +namespace connectivity::odbc + { + + //************ Class: ODatabaseMetaData + + + class OOO_DLLPUBLIC_ODBCBASE ODatabaseMetaData final : + public ODatabaseMetaDataBase + { + SQLHANDLE m_aConnectionHandle; + OConnection* m_pConnection; + bool m_bUseCatalog; + + // cached database information + virtual OUString impl_getIdentifierQuoteString_throw( ) override; + virtual bool impl_isCatalogAtStart_throw( ) override; + virtual OUString impl_getCatalogSeparator_throw( ) override; + virtual bool impl_supportsCatalogsInTableDefinitions_throw( ) override; + virtual bool impl_supportsSchemasInTableDefinitions_throw( ) override ; + virtual bool impl_supportsCatalogsInDataManipulation_throw( ) override; + virtual bool impl_supportsSchemasInDataManipulation_throw( ) override ; + virtual bool impl_supportsMixedCaseQuotedIdentifiers_throw( ) override ; + virtual bool impl_supportsAlterTableWithAddColumn_throw( ) override; + virtual bool impl_supportsAlterTableWithDropColumn_throw( ) override; + virtual sal_Int32 impl_getMaxStatements_throw( ) override; + virtual sal_Int32 impl_getMaxTablesInSelect_throw( ) override; + virtual bool impl_storesMixedCaseQuotedIdentifiers_throw( ) override; + OUString getURLImpl(); + virtual css::uno::Reference< css::sdbc::XResultSet > impl_getTypeInfo_throw() override; + virtual ~ODatabaseMetaData() override; + + public: + ODatabaseMetaData(const SQLHANDLE _pHandle,OConnection* _pCon); + + // XDatabaseMetaData + virtual sal_Bool SAL_CALL allProceduresAreCallable( ) override; + virtual sal_Bool SAL_CALL allTablesAreSelectable( ) override; + virtual OUString SAL_CALL getURL( ) override; + virtual OUString SAL_CALL getUserName( ) override; + virtual sal_Bool SAL_CALL isReadOnly( ) override; + virtual sal_Bool SAL_CALL nullsAreSortedHigh( ) override; + virtual sal_Bool SAL_CALL nullsAreSortedLow( ) override; + virtual sal_Bool SAL_CALL nullsAreSortedAtStart( ) override; + virtual sal_Bool SAL_CALL nullsAreSortedAtEnd( ) override; + virtual OUString SAL_CALL getDatabaseProductName( ) override; + virtual OUString SAL_CALL getDatabaseProductVersion( ) override; + virtual OUString SAL_CALL getDriverName( ) override; + virtual OUString SAL_CALL getDriverVersion( ) override; + virtual sal_Int32 SAL_CALL getDriverMajorVersion( ) override; + virtual sal_Int32 SAL_CALL getDriverMinorVersion( ) override; + virtual sal_Bool SAL_CALL usesLocalFiles( ) override; + virtual sal_Bool SAL_CALL usesLocalFilePerTable( ) override; + virtual sal_Bool SAL_CALL supportsMixedCaseIdentifiers( ) override; + virtual sal_Bool SAL_CALL storesUpperCaseIdentifiers( ) override; + virtual sal_Bool SAL_CALL storesLowerCaseIdentifiers( ) override; + virtual sal_Bool SAL_CALL storesMixedCaseIdentifiers( ) override; + + virtual sal_Bool SAL_CALL storesUpperCaseQuotedIdentifiers( ) override; + virtual sal_Bool SAL_CALL storesLowerCaseQuotedIdentifiers( ) override; + + virtual OUString SAL_CALL getSQLKeywords( ) override; + virtual OUString SAL_CALL getNumericFunctions( ) override; + virtual OUString SAL_CALL getStringFunctions( ) override; + virtual OUString SAL_CALL getSystemFunctions( ) override; + virtual OUString SAL_CALL getTimeDateFunctions( ) override; + virtual OUString SAL_CALL getSearchStringEscape( ) override; + virtual OUString SAL_CALL getExtraNameCharacters( ) override; + virtual sal_Bool SAL_CALL supportsColumnAliasing( ) override; + virtual sal_Bool SAL_CALL nullPlusNonNullIsNull( ) override; + virtual sal_Bool SAL_CALL supportsTypeConversion( ) override; + virtual sal_Bool SAL_CALL supportsConvert( sal_Int32 fromType, sal_Int32 toType ) override; + virtual sal_Bool SAL_CALL supportsTableCorrelationNames( ) override; + virtual sal_Bool SAL_CALL supportsDifferentTableCorrelationNames( ) override; + virtual sal_Bool SAL_CALL supportsExpressionsInOrderBy( ) override; + virtual sal_Bool SAL_CALL supportsOrderByUnrelated( ) override; + virtual sal_Bool SAL_CALL supportsGroupBy( ) override; + virtual sal_Bool SAL_CALL supportsGroupByUnrelated( ) override; + virtual sal_Bool SAL_CALL supportsGroupByBeyondSelect( ) override; + virtual sal_Bool SAL_CALL supportsLikeEscapeClause( ) override; + virtual sal_Bool SAL_CALL supportsMultipleResultSets( ) override; + virtual sal_Bool SAL_CALL supportsMultipleTransactions( ) override; + virtual sal_Bool SAL_CALL supportsNonNullableColumns( ) override; + virtual sal_Bool SAL_CALL supportsMinimumSQLGrammar( ) override; + virtual sal_Bool SAL_CALL supportsCoreSQLGrammar( ) override; + virtual sal_Bool SAL_CALL supportsExtendedSQLGrammar( ) override; + virtual sal_Bool SAL_CALL supportsANSI92EntryLevelSQL( ) override; + virtual sal_Bool SAL_CALL supportsANSI92IntermediateSQL( ) override; + virtual sal_Bool SAL_CALL supportsANSI92FullSQL( ) override; + virtual sal_Bool SAL_CALL supportsIntegrityEnhancementFacility( ) override; + virtual sal_Bool SAL_CALL supportsOuterJoins( ) override; + virtual sal_Bool SAL_CALL supportsFullOuterJoins( ) override; + virtual sal_Bool SAL_CALL supportsLimitedOuterJoins( ) override; + virtual OUString SAL_CALL getSchemaTerm( ) override; + virtual OUString SAL_CALL getProcedureTerm( ) override; + virtual OUString SAL_CALL getCatalogTerm( ) override; + + virtual sal_Bool SAL_CALL supportsSchemasInProcedureCalls( ) override; + virtual sal_Bool SAL_CALL supportsSchemasInIndexDefinitions( ) override; + virtual sal_Bool SAL_CALL supportsSchemasInPrivilegeDefinitions( ) override; + virtual sal_Bool SAL_CALL supportsCatalogsInProcedureCalls( ) override; + + virtual sal_Bool SAL_CALL supportsCatalogsInIndexDefinitions( ) override; + virtual sal_Bool SAL_CALL supportsCatalogsInPrivilegeDefinitions( ) override; + virtual sal_Bool SAL_CALL supportsPositionedDelete( ) override; + virtual sal_Bool SAL_CALL supportsPositionedUpdate( ) override; + virtual sal_Bool SAL_CALL supportsSelectForUpdate( ) override; + virtual sal_Bool SAL_CALL supportsStoredProcedures( ) override; + virtual sal_Bool SAL_CALL supportsSubqueriesInComparisons( ) override; + virtual sal_Bool SAL_CALL supportsSubqueriesInExists( ) override; + virtual sal_Bool SAL_CALL supportsSubqueriesInIns( ) override; + virtual sal_Bool SAL_CALL supportsSubqueriesInQuantifieds( ) override; + virtual sal_Bool SAL_CALL supportsCorrelatedSubqueries( ) override; + virtual sal_Bool SAL_CALL supportsUnion( ) override; + virtual sal_Bool SAL_CALL supportsUnionAll( ) override; + virtual sal_Bool SAL_CALL supportsOpenCursorsAcrossCommit( ) override; + virtual sal_Bool SAL_CALL supportsOpenCursorsAcrossRollback( ) override; + virtual sal_Bool SAL_CALL supportsOpenStatementsAcrossCommit( ) override; + virtual sal_Bool SAL_CALL supportsOpenStatementsAcrossRollback( ) override; + virtual sal_Int32 SAL_CALL getMaxBinaryLiteralLength( ) override; + virtual sal_Int32 SAL_CALL getMaxCharLiteralLength( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInGroupBy( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInIndex( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInOrderBy( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInSelect( ) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInTable( ) override; + virtual sal_Int32 SAL_CALL getMaxConnections( ) override; + virtual sal_Int32 SAL_CALL getMaxCursorNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxIndexLength( ) override; + virtual sal_Int32 SAL_CALL getMaxSchemaNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxProcedureNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxCatalogNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxRowSize( ) override; + virtual sal_Bool SAL_CALL doesMaxRowSizeIncludeBlobs( ) override; + virtual sal_Int32 SAL_CALL getMaxStatementLength( ) override; + virtual sal_Int32 SAL_CALL getMaxTableNameLength( ) override; + virtual sal_Int32 SAL_CALL getMaxUserNameLength( ) override; + virtual sal_Int32 SAL_CALL getDefaultTransactionIsolation( ) override; + virtual sal_Bool SAL_CALL supportsTransactions( ) override; + virtual sal_Bool SAL_CALL supportsTransactionIsolationLevel( sal_Int32 level ) override; + virtual sal_Bool SAL_CALL supportsDataDefinitionAndDataManipulationTransactions( ) override; + virtual sal_Bool SAL_CALL supportsDataManipulationTransactionsOnly( ) override; + virtual sal_Bool SAL_CALL dataDefinitionCausesTransactionCommit( ) override; + virtual sal_Bool SAL_CALL dataDefinitionIgnoredInTransactions( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getProcedures( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& procedureNamePattern ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getProcedureColumns( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& procedureNamePattern, const OUString& columnNamePattern ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTables( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern, const css::uno::Sequence< OUString >& types ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getSchemas( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getCatalogs( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTableTypes( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getColumns( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern, const OUString& columnNamePattern ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getColumnPrivileges( const css::uno::Any& catalog, const OUString& schema, const OUString& table, const OUString& columnNamePattern ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTablePrivileges( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getBestRowIdentifier( const css::uno::Any& catalog, const OUString& schema, const OUString& table, sal_Int32 scope, sal_Bool nullable ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getVersionColumns( const css::uno::Any& catalog, const OUString& schema, const OUString& table ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getPrimaryKeys( const css::uno::Any& catalog, const OUString& schema, const OUString& table ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getImportedKeys( const css::uno::Any& catalog, const OUString& schema, const OUString& table ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getExportedKeys( const css::uno::Any& catalog, const OUString& schema, const OUString& table ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getCrossReference( const css::uno::Any& primaryCatalog, const OUString& primarySchema, const OUString& primaryTable, const css::uno::Any& foreignCatalog, const OUString& foreignSchema, const OUString& foreignTable ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getIndexInfo( const css::uno::Any& catalog, const OUString& schema, const OUString& table, sal_Bool unique, sal_Bool approximate ) override; + virtual sal_Bool SAL_CALL supportsResultSetType( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL supportsResultSetConcurrency( sal_Int32 setType, sal_Int32 concurrency ) override; + virtual sal_Bool SAL_CALL ownUpdatesAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL ownDeletesAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL ownInsertsAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL othersUpdatesAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL othersDeletesAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL othersInsertsAreVisible( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL updatesAreDetected( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL deletesAreDetected( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL insertsAreDetected( sal_Int32 setType ) override; + virtual sal_Bool SAL_CALL supportsBatchUpdates( ) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getUDTs( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& typeNamePattern, const css::uno::Sequence< sal_Int32 >& types ) override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/ODatabaseMetaDataResultSet.hxx b/connectivity/source/inc/odbc/ODatabaseMetaDataResultSet.hxx new file mode 100644 index 0000000000..5d6982807d --- /dev/null +++ b/connectivity/source/inc/odbc/ODatabaseMetaDataResultSet.hxx @@ -0,0 +1,259 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/sdbc/ResultSetType.hpp> +#include <com/sun/star/sdbc/FetchDirection.hpp> +#include <com/sun/star/sdbc/ResultSetConcurrency.hpp> +#include <com/sun/star/sdbc/XResultSet.hpp> +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> +#include <com/sun/star/sdbc/XCloseable.hpp> +#include <com/sun/star/sdbc/XColumnLocate.hpp> +#include <com/sun/star/util/XCancellable.hpp> +#include <com/sun/star/sdbc/XWarningsSupplier.hpp> +#include <com/sun/star/sdbc/XResultSetUpdate.hpp> +#include <com/sun/star/sdbc/XRowUpdate.hpp> +#include <cppuhelper/compbase.hxx> +#include <cppuhelper/basemutex.hxx> +#include <comphelper/proparrhlp.hxx> +#include <odbc/OStatement.hxx> +#include <odbc/ODatabaseMetaData.hxx> +#include <odbc/odbcbasedllapi.hxx> +#include <memory> +#include <string_view> + +namespace connectivity::odbc + { + /* + ** java_sql_ResultSet + */ + typedef ::cppu::WeakComponentImplHelper< css::sdbc::XResultSet, + css::sdbc::XRow, + css::sdbc::XResultSetMetaDataSupplier, + css::util::XCancellable, + css::sdbc::XWarningsSupplier, + css::sdbc::XCloseable, + css::sdbc::XColumnLocate> ODatabaseMetaDataResultSet_BASE; + + class OOO_DLLPUBLIC_ODBCBASE ODatabaseMetaDataResultSet : + public cppu::BaseMutex, + public ODatabaseMetaDataResultSet_BASE, + public ::cppu::OPropertySetHelper, + public ::comphelper::OPropertyArrayUsageHelper<ODatabaseMetaDataResultSet> + { + std::vector< sal_Int32> m_aColMapping; // pos 0 is unused so we don't have to decrement 1 every time + + std::map<sal_Int32, ::std::map<sal_Int32,sal_Int32> > + m_aValueRange; + + std::map<sal_Int32,SWORD> m_aODBCColumnTypes; + + SQLHANDLE m_aStatementHandle; // ... until freed + css::uno::WeakReferenceHelper m_aStatement; + css::uno::Reference< css::sdbc::XResultSetMetaData> + m_xMetaData; + std::unique_ptr<SQLUSMALLINT[]> m_pRowStatusArray; + rtl::Reference<OConnection> m_pConnection; + rtl_TextEncoding m_nTextEncoding; + sal_Int32 m_nRowPos; + sal_Int32 m_nDriverColumnCount; // column count of the driver which can sometimes be less than the metadata count + SQLRETURN m_nCurrentFetchState; + bool m_bWasNull; + bool m_bEOF; // after last record + + // set the columncount of the driver + void checkColumnCount(); + static sal_Int32 getFetchDirection() { return css::sdbc::FetchDirection::FORWARD; } + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + static sal_Int32 getFetchSize(); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + static OUString getCursorName(); + SWORD impl_getColumnType_nothrow(sal_Int32 columnIndex); + + sal_Int32 mapColumn (sal_Int32 column); + + protected: + + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override; + // OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + + virtual sal_Bool SAL_CALL convertFastPropertyValue( + css::uno::Any & rConvertedValue, + css::uno::Any & rOldValue, + sal_Int32 nHandle, + const css::uno::Any& rValue ) override; + virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const css::uno::Any& rValue ) override; + virtual void SAL_CALL getFastPropertyValue( css::uno::Any& rValue, sal_Int32 nHandle ) const override; + virtual ~ODatabaseMetaDataResultSet() override; + template < typename T, SQLSMALLINT sqlTypeId > T getInteger ( sal_Int32 columnIndex ); + + public: + // A ctor needed for returning the object + ODatabaseMetaDataResultSet(OConnection* _pConnection); + + + oslGenericFunction getOdbcFunction(ODBC3SQLFunctionId _nIndex) const + { + return m_pConnection->getOdbcFunction(_nIndex); + } + // ::cppu::OComponentHelper + virtual void SAL_CALL disposing() override; + // XInterface + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + // XPropertySet + virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; + css::uno::Reference< css::uno::XInterface > operator *() + { + return css::uno::Reference< css::uno::XInterface >(*static_cast<ODatabaseMetaDataResultSet_BASE*>(this)); + } + // XResultSet + virtual sal_Bool SAL_CALL next( ) override; + virtual sal_Bool SAL_CALL isBeforeFirst( ) override; + virtual sal_Bool SAL_CALL isAfterLast( ) override; + virtual sal_Bool SAL_CALL isFirst( ) override; + virtual sal_Bool SAL_CALL isLast( ) override; + virtual void SAL_CALL beforeFirst( ) override; + virtual void SAL_CALL afterLast( ) override; + virtual sal_Bool SAL_CALL first( ) override; + virtual sal_Bool SAL_CALL last( ) override; + virtual sal_Int32 SAL_CALL getRow( ) override; + virtual sal_Bool SAL_CALL absolute( sal_Int32 row ) override; + virtual sal_Bool SAL_CALL relative( sal_Int32 rows ) override; + virtual sal_Bool SAL_CALL previous( ) override; + virtual void SAL_CALL refreshRow( ) override; + virtual sal_Bool SAL_CALL rowUpdated( ) override; + virtual sal_Bool SAL_CALL rowInserted( ) override; + virtual sal_Bool SAL_CALL rowDeleted( ) override; + virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getStatement( ) override; + // XRow + virtual sal_Bool SAL_CALL wasNull( ) override; + virtual OUString SAL_CALL getString( sal_Int32 columnIndex ) override; + virtual sal_Bool SAL_CALL getBoolean( sal_Int32 columnIndex ) override; + virtual sal_Int8 SAL_CALL getByte( sal_Int32 columnIndex ) override; + virtual sal_Int16 SAL_CALL getShort( sal_Int32 columnIndex ) override; + virtual sal_Int32 SAL_CALL getInt( sal_Int32 columnIndex ) override; + virtual sal_Int64 SAL_CALL getLong( sal_Int32 columnIndex ) override; + virtual float SAL_CALL getFloat( sal_Int32 columnIndex ) override; + virtual double SAL_CALL getDouble( sal_Int32 columnIndex ) override; + virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes( sal_Int32 columnIndex ) override; + virtual css::util::Date SAL_CALL getDate( sal_Int32 columnIndex ) override; + virtual css::util::Time SAL_CALL getTime( sal_Int32 columnIndex ) override; + virtual css::util::DateTime SAL_CALL getTimestamp( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream( sal_Int32 columnIndex ) override; + virtual css::uno::Any SAL_CALL getObject( sal_Int32 columnIndex, const css::uno::Reference< css::container::XNameAccess >& typeMap ) override; + virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray( sal_Int32 columnIndex ) override; + // XResultSetMetaDataSupplier + virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData( ) override; + // XCancellable + virtual void SAL_CALL cancel( ) override; + // XCloseable + virtual void SAL_CALL close( ) override; + // XWarningsSupplier + virtual css::uno::Any SAL_CALL getWarnings( ) override; + virtual void SAL_CALL clearWarnings( ) override; + // XColumnLocate + virtual sal_Int32 SAL_CALL findColumn( const OUString& columnName ) override; + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void openTablesTypes( ); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void openTypeInfo(); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void openCatalogs(); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void openSchemas(); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void openTables(const css::uno::Any& catalog, const OUString& schemaPattern, + std::u16string_view tableNamePattern, const css::uno::Sequence< OUString >& types ); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void openColumnPrivileges( const css::uno::Any& catalog, const OUString& schema, + std::u16string_view table, std::u16string_view columnNamePattern ); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void openColumns( const css::uno::Any& catalog, const OUString& schemaPattern, + std::u16string_view tableNamePattern, std::u16string_view columnNamePattern ); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void openProcedureColumns( const css::uno::Any& catalog, const OUString& schemaPattern, + std::u16string_view procedureNamePattern,std::u16string_view columnNamePattern ); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void openProcedures( const css::uno::Any& catalog, const OUString& schemaPattern, + std::u16string_view procedureNamePattern); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void openVersionColumns(const css::uno::Any& catalog, const OUString& schema, + std::u16string_view table); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void openBestRowIdentifier( const css::uno::Any& catalog, const OUString& schema, + std::u16string_view table,sal_Int32 scope, bool nullable ); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void openForeignKeys( const css::uno::Any& catalog, const OUString* schema,const OUString* table, + const css::uno::Any& catalog2, const OUString* schema2,const OUString* table2); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void openExportedKeys(const css::uno::Any& catalog, const OUString& schema,const OUString& table); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void openImportedKeys(const css::uno::Any& catalog, const OUString& schema,const OUString& table); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void openPrimaryKeys(const css::uno::Any& catalog, const OUString& schema,std::u16string_view table); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void openTablePrivileges(const css::uno::Any& catalog, const OUString& schemaPattern, + std::u16string_view tableNamePattern); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void openSpecialColumns(bool _bRowVer,const css::uno::Any& catalog, const OUString& schema, + std::u16string_view table,sal_Int32 scope, bool nullable ); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void openIndexInfo( const css::uno::Any& catalog, const OUString& schema, + std::u16string_view table,bool unique,bool approximate ); + + protected: + using OPropertySetHelper::getFastPropertyValue; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/ODriver.hxx b/connectivity/source/inc/odbc/ODriver.hxx new file mode 100644 index 0000000000..6cba90648d --- /dev/null +++ b/connectivity/source/inc/odbc/ODriver.hxx @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/sdbc/XDriver.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <cppuhelper/compbase.hxx> +#include <connectivity/odbc.hxx> +#include <odbc/odbcbasedllapi.hxx> +#include <connectivity/CommonTools.hxx> +#include <osl/module.h> +#include <odbc/OTools.hxx> + +namespace connectivity::odbc + { + typedef ::cppu::WeakComponentImplHelper< css::sdbc::XDriver, css::lang::XServiceInfo > ODriver_BASE; + + class OOO_DLLPUBLIC_ODBCBASE SAL_NO_VTABLE ODBCDriver : public ODriver_BASE + { + protected: + ::osl::Mutex m_aMutex; + + connectivity::OWeakRefArray m_xConnections; // vector containing a list + // of all the Connection objects + // for this Driver + + css::uno::Reference< css::uno::XComponentContext > m_xContext; + SQLHANDLE m_pDriverHandle; + + virtual SQLHANDLE EnvironmentHandle(OUString &_rPath) = 0; + + public: + + ODBCDriver(css::uno::Reference< css::uno::XComponentContext > xContext); + + // only possibility to get the odbc functions + virtual oslGenericFunction getOdbcFunction(ODBC3SQLFunctionId _nIndex) const = 0; + // OComponentHelper + virtual void SAL_CALL disposing() override; + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName( ) override; + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; + + // XDriver + virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL connect( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + virtual sal_Bool SAL_CALL acceptsURL( const OUString& url ) override; + virtual css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + virtual sal_Int32 SAL_CALL getMajorVersion( ) override; + virtual sal_Int32 SAL_CALL getMinorVersion( ) override; + + const css::uno::Reference< css::uno::XComponentContext >& getContext() const { return m_xContext; } + }; + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/OFunctions.hxx b/connectivity/source/inc/odbc/OFunctions.hxx new file mode 100644 index 0000000000..a44fe5a150 --- /dev/null +++ b/connectivity/source/inc/odbc/OFunctions.hxx @@ -0,0 +1,600 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <connectivity/odbc.hxx> +#include <rtl/ustring.hxx> +#include <osl/module.h> + +namespace connectivity +{ + +// sal_Bool LoadFunctions(oslModule pODBCso, sal_Bool _bDS=sal_True); +bool LoadLibrary_ODBC3(OUString &_rPath); +// sal_Bool LoadLibrary_ADABAS(OUString &_rPath); + + // Connecting to a data source + typedef SQLRETURN (SQL_API *T3SQLAllocHandle) (SQLSMALLINT HandleType,SQLHANDLE InputHandle,SQLHANDLE * OutputHandlePtr); + + #define N3SQLAllocHandle(a,b,c) (*reinterpret_cast<T3SQLAllocHandle>(getOdbcFunction(ODBC3SQLFunctionId::AllocHandle)))(a,b,c) + + typedef SQLRETURN (SQL_API *T3SQLConnect) (SQLHDBC ConnectionHandle,SQLCHAR *ServerName,SQLSMALLINT NameLength1,SQLCHAR *UserName,SQLSMALLINT NameLength2,SQLCHAR *Authentication,SQLSMALLINT NameLength3); + + #define N3SQLConnect(a,b,c,d,e,f,g) (*reinterpret_cast<T3SQLConnect>(getOdbcFunction(ODBC3SQLFunctionId::Connect)))(a,b,c,d,e,f,g) + + typedef SQLRETURN (SQL_API *T3SQLDriverConnect) ( SQLHDBC ConnectionHandle, + HWND WindowHandle, + SQLCHAR * InConnectionString, + SQLSMALLINT StringLength1, + SQLCHAR * OutConnectionString, + SQLSMALLINT BufferLength, + SQLSMALLINT * StringLength2Ptr, + SQLUSMALLINT DriverCompletion); + + #define N3SQLDriverConnect(a,b,c,d,e,f,g,h) (*reinterpret_cast<T3SQLDriverConnect>(getOdbcFunction(ODBC3SQLFunctionId::DriverConnect)))(a,b,c,d,e,f,g,h) + + typedef SQLRETURN (SQL_API *T3SQLBrowseConnect) ( SQLHDBC ConnectionHandle, + SQLCHAR * InConnectionString, + SQLSMALLINT StringLength1, + SQLCHAR * OutConnectionString, + SQLSMALLINT BufferLength, + SQLSMALLINT * StringLength2Ptr); + + #define N3SQLBrowseConnect(a,b,c,d,e,f) (*reinterpret_cast<T3SQLBrowseConnect>(getOdbcFunction(ODBC3SQLFunctionId::BrowseConnect)))(a,b,c,d,e,f) + + // Obtaining information about a driver and data source + typedef SQLRETURN (SQL_API *T3SQLDataSources) ( SQLHENV EnvironmentHandle, + SQLUSMALLINT Direction, + SQLCHAR * ServerName, + SQLSMALLINT BufferLength1, + SQLSMALLINT * NameLength1Ptr, + SQLCHAR * Description, + SQLSMALLINT BufferLength2, + SQLSMALLINT * NameLength2Ptr); + + #define N3SQLDataSources(a,b,c,d,e,f,g,h) (*reinterpret_cast<T3SQLDataSources>(getOdbcFunction(ODBC3SQLFunctionId::DataSources)))(a,b,c,d,e,f,g,h) + + typedef SQLRETURN (SQL_API *T3SQLDrivers) ( SQLHENV EnvironmentHandle, + SQLUSMALLINT Direction, + SQLCHAR * DriverDescription, + SQLSMALLINT BufferLength1, + SQLSMALLINT * DescriptionLengthPtr, + SQLCHAR * DriverAttributes, + SQLSMALLINT BufferLength2, + SQLSMALLINT * AttributesLengthPtr); + + #define N3SQLDrivers(a,b,c,d,e,f,g,h) (*reinterpret_cast<T3SQLDrivers>(getOdbcFunction(ODBC3SQLFunctionId::Drivers)))(a,b,c,d,e,f,g,h) + + typedef SQLRETURN (SQL_API *T3SQLGetInfo) ( SQLHDBC ConnectionHandle, + SQLUSMALLINT InfoType, + SQLPOINTER InfoValuePtr, + SQLSMALLINT BufferLength, + SQLSMALLINT * StringLengthPtr); + + #define N3SQLGetInfo(a,b,c,d,e) (*reinterpret_cast<T3SQLGetInfo>(getOdbcFunction(ODBC3SQLFunctionId::GetInfo)))(a,b,c,d,e) + + typedef SQLRETURN (SQL_API *T3SQLGetFunctions) (SQLHDBC ConnectionHandle, + SQLUSMALLINT FunctionId, + SQLUSMALLINT * SupportedPtr); + + #define N3SQLGetFunctions(a,b,c) (*reinterpret_cast<T3SQLGetFunctions>(getOdbcFunction(ODBC3SQLFunctionId::GetFunctions)))(a,b,c) + + typedef SQLRETURN (SQL_API *T3SQLGetTypeInfo) ( SQLHSTMT StatementHandle, + SQLSMALLINT DataType); + + #define N3SQLGetTypeInfo(a,b) (*reinterpret_cast<T3SQLGetTypeInfo>(getOdbcFunction(ODBC3SQLFunctionId::GetTypeInfo)))(a,b) + + // Setting and retrieving driver attributes + typedef SQLRETURN (SQL_API *T3SQLSetConnectAttr)(SQLHDBC ConnectionHandle, + SQLINTEGER Attribute, + SQLPOINTER ValuePtr, + SQLINTEGER StringLength); + + #define N3SQLSetConnectAttr(a,b,c,d) (*reinterpret_cast<T3SQLSetConnectAttr>(getOdbcFunction(ODBC3SQLFunctionId::SetConnectAttr)))(a,b,c,d) + + typedef SQLRETURN (SQL_API *T3SQLGetConnectAttr) (SQLHDBC ConnectionHandle, + SQLINTEGER Attribute, + SQLPOINTER ValuePtr, + SQLINTEGER BufferLength, + SQLINTEGER* StringLength); + + #define N3SQLGetConnectAttr(a,b,c,d,e) (*reinterpret_cast<T3SQLGetConnectAttr>(getOdbcFunction(ODBC3SQLFunctionId::GetConnectAttr)))(a,b,c,d,e) + + + typedef SQLRETURN (SQL_API *T3SQLSetEnvAttr) ( SQLHENV EnvironmentHandle, + SQLINTEGER Attribute, + SQLPOINTER ValuePtr, + SQLINTEGER StringLength); + + #define N3SQLSetEnvAttr(a,b,c,d) (*reinterpret_cast<T3SQLSetEnvAttr>(getOdbcFunction(ODBC3SQLFunctionId::SetEnvAttr)))(a,b,c,d) + + typedef SQLRETURN (SQL_API *T3SQLGetEnvAttr) ( SQLHENV EnvironmentHandle, + SQLINTEGER Attribute, + SQLPOINTER ValuePtr, + SQLINTEGER BufferLength, + SQLINTEGER* StringLength); + + #define N3SQLGetEnvAttr(a,b,c,d,e) (*reinterpret_cast<T3SQLGetEnvAttr>(getOdbcFunction(ODBC3SQLFunctionId::GetEnvAttr)))(a,b,c,d,e) + + + typedef SQLRETURN (SQL_API *T3SQLSetStmtAttr) ( SQLHSTMT StatementHandle, + SQLINTEGER Attribute, + SQLPOINTER ValuePtr, + SQLINTEGER StringLength); + + #define N3SQLSetStmtAttr(a,b,c,d) (*reinterpret_cast<T3SQLSetStmtAttr>(getOdbcFunction(ODBC3SQLFunctionId::SetStmtAttr)))(a,b,c,d) + + typedef SQLRETURN (SQL_API *T3SQLGetStmtAttr) ( SQLHSTMT StatementHandle, + SQLINTEGER Attribute, + SQLPOINTER ValuePtr, + SQLINTEGER BufferLength, + SQLINTEGER* StringLength); + + #define N3SQLGetStmtAttr(a,b,c,d,e) (*reinterpret_cast<T3SQLGetStmtAttr>(getOdbcFunction(ODBC3SQLFunctionId::GetStmtAttr)))(a,b,c,d,e) + + // Setting and retrieving descriptor fields + /*typedef SQLRETURN (SQL_API *T3SQLSetDescField) (SQLHDESC DescriptorHandle, + SQLSMALLINT RecNumber, + SQLSMALLINT FieldIdentifier, + SQLPOINTER ValuePtr, + SQLINTEGER BufferLength); + + #define N3SQLSetDescField(a,b,c,d,e) (*reinterpret_cast<T3SQLSetDescField>(getOdbcFunction(ODBC3SQLFunctionId::SetDescField)))(a,b,c,d,e) + + typedef SQLRETURN (SQL_API *T3SQLGetDescField) ( SQLHDESC DescriptorHandle, + SQLSMALLINT RecNumber, + SQLSMALLINT FieldIdentifier, + SQLPOINTER ValuePtr, + SQLINTEGER BufferLength, + SQLINTEGER * StringLengthPtr); + + #define N3SQLGetDescField(a,b,c,d,e,f) (*reinterpret_cast<T3SQLGetDescField>(getOdbcFunction(ODBC3SQLFunctionId::GetDescField)))(a,b,c,d,e,f) + + + typedef SQLRETURN (SQL_API *T3SQLGetDescRec) ( SQLHDESC DescriptorHandle, + SQLSMALLINT RecNumber, + SQLCHAR * Name, + SQLSMALLINT BufferLength, + SQLSMALLINT * StringLengthPtr, + SQLSMALLINT * TypePtr, + SQLSMALLINT * SubTypePtr, + SQLLEN * LengthPtr, + SQLSMALLINT * PrecisionPtr, + SQLSMALLINT * ScalePtr, + SQLSMALLINT * NullablePtr); + + #define N3SQLGetDescRec(a,b,c,d,e,f,g,h,i,j,k) (*reinterpret_cast<T3SQLGetDescRec>(getOdbcFunction(ODBC3SQLFunctionId::GetDescRec)))(a,b,c,d,e,f,g,h,i,j,k) + + + typedef SQLRETURN (SQL_API *T3SQLSetDescRec) ( SQLHDESC DescriptorHandle, + SQLSMALLINT RecNumber, + SQLSMALLINT Type, + SQLSMALLINT SubType, + SQLLEN Length, + SQLSMALLINT Precision, + SQLSMALLINT Scale, + SQLPOINTER DataPtr, + SQLLEN * StringLengthPtr, + SQLLEN * IndicatorPtr); + + #define N3SQLSetDescRec(a,b,c,d,e,f,g,h,i,j) (*reinterpret_cast<T3SQLSetDescRec>(getOdbcFunction(ODBC3SQLFunctionId::SetDescRec)))(a,b,c,d,e,f,g,h,i,j) + */ + + // Preparing SQL requests + typedef SQLRETURN (SQL_API *T3SQLPrepare) ( SQLHSTMT StatementHandle, + SQLCHAR * StatementText, + SQLINTEGER TextLength); + + #define N3SQLPrepare(a,b,c) (*reinterpret_cast<T3SQLPrepare>(getOdbcFunction(ODBC3SQLFunctionId::Prepare)))(a,b,c) + + typedef SQLRETURN (SQL_API *T3SQLBindParameter) (SQLHSTMT StatementHandle, + SQLUSMALLINT ParameterNumber, + SQLSMALLINT InputOutputType, + SQLSMALLINT ValueType, + SQLSMALLINT ParameterType, + SQLULEN ColumnSize, + SQLSMALLINT DecimalDigits, + SQLPOINTER ParameterValuePtr, + SQLLEN BufferLength, + SQLLEN * StrLen_or_IndPtr); + + #define N3SQLBindParameter(a,b,c,d,e,f,g,h,i,j) (*reinterpret_cast<T3SQLBindParameter>(getOdbcFunction(ODBC3SQLFunctionId::BindParameter)))(a,b,c,d,e,f,g,h,i,j) + + /*typedef SQLRETURN (SQL_API *T3SQLGetCursorName) (SQLHSTMT StatementHandle, + SQLCHAR * CursorName, + SQLSMALLINT BufferLength, + SQLSMALLINT * NameLengthPtr); + + #define N3SQLGetCursorName(a,b,c,d) (*reinterpret_cast<T3SQLGetCursorName>(getOdbcFunction(ODBC3SQLFunctionId::GetCursorName)))(a,b,c,d) + */ + + typedef SQLRETURN (SQL_API *T3SQLSetCursorName) (SQLHSTMT StatementHandle, + SQLCHAR * CursorName, + SQLSMALLINT NameLength); + + #define N3SQLSetCursorName(a,b,c) (*reinterpret_cast<T3SQLSetCursorName>(getOdbcFunction(ODBC3SQLFunctionId::SetCursorName)))(a,b,c) + + // Submitting requests + typedef SQLRETURN (SQL_API *T3SQLExecute) ( SQLHSTMT StatementHandle); + + #define N3SQLExecute(a) (*reinterpret_cast<T3SQLExecute>(getOdbcFunction(ODBC3SQLFunctionId::Execute)))(a) + + typedef SQLRETURN (SQL_API *T3SQLExecDirect) ( SQLHSTMT StatementHandle, + SQLCHAR * StatementText, + SQLINTEGER TextLength); + + #define N3SQLExecDirect(a,b,c) (*reinterpret_cast<T3SQLExecDirect>(getOdbcFunction(ODBC3SQLFunctionId::ExecDirect)))(a,b,c) + + typedef SQLRETURN (SQL_API *T3SQLDescribeParam) (SQLHSTMT StatementHandle, + SQLUSMALLINT ParameterNumber, + SQLSMALLINT * DataTypePtr, + SQLULEN * ParameterSizePtr, + SQLSMALLINT * DecimalDigitsPtr, + SQLSMALLINT * NullablePtr); + + #define N3SQLDescribeParam(a,b,c,d,e,f) (*reinterpret_cast<T3SQLDescribeParam>(getOdbcFunction(ODBC3SQLFunctionId::DescribeParam)))(a,b,c,d,e,f) + + typedef SQLRETURN (SQL_API *T3SQLNumParams) ( SQLHSTMT StatementHandle, + SQLSMALLINT * ParameterCountPtr); + + #define N3SQLNumParams(a,b) (*reinterpret_cast<T3SQLNumParams>(getOdbcFunction(ODBC3SQLFunctionId::NumParams)))(a,b) + + typedef SQLRETURN (SQL_API *T3SQLParamData) ( SQLHSTMT StatementHandle, + SQLPOINTER * ValuePtrPtr); + + #define N3SQLParamData(a,b) (*reinterpret_cast<T3SQLParamData>(getOdbcFunction(ODBC3SQLFunctionId::ParamData)))(a,b) + + typedef SQLRETURN (SQL_API *T3SQLPutData) ( SQLHSTMT StatementHandle, + SQLPOINTER DataPtr, + SQLLEN StrLen_or_Ind); + + #define N3SQLPutData(a,b,c) (*reinterpret_cast<T3SQLPutData>(getOdbcFunction(ODBC3SQLFunctionId::PutData)))(a,b,c) + + // Retrieving results and information about results + typedef SQLRETURN (SQL_API *T3SQLRowCount) ( SQLHSTMT StatementHandle, + SQLLEN * RowCountPtr); + + #define N3SQLRowCount(a,b) (*reinterpret_cast<T3SQLRowCount>(getOdbcFunction(ODBC3SQLFunctionId::RowCount)))(a,b) + + typedef SQLRETURN (SQL_API *T3SQLNumResultCols) (SQLHSTMT StatementHandle, + SQLSMALLINT * ColumnCountPtr); + + #define N3SQLNumResultCols(a,b) (*reinterpret_cast<T3SQLNumResultCols>(getOdbcFunction(ODBC3SQLFunctionId::NumResultCols)))(a,b) + + typedef SQLRETURN (SQL_API *T3SQLDescribeCol) ( SQLHSTMT StatementHandle, + SQLUSMALLINT ColumnNumber, + SQLCHAR * ColumnName, + SQLSMALLINT BufferLength, + SQLSMALLINT * NameLengthPtr, + SQLSMALLINT * DataTypePtr, + SQLULEN * ColumnSizePtr, + SQLSMALLINT * DecimalDigitsPtr, + SQLSMALLINT * NullablePtr); + + #define N3SQLDescribeCol(a,b,c,d,e,f,g,h,i) (*reinterpret_cast<T3SQLDescribeCol>(getOdbcFunction(ODBC3SQLFunctionId::DescribeCol)))(a,b,c,d,e,f,g,h,i) + + typedef SQLRETURN (SQL_API *T3SQLColAttribute) (SQLHSTMT StatementHandle, + SQLUSMALLINT ColumnNumber, + SQLUSMALLINT FieldIdentifier, + SQLPOINTER CharacterAttributePtr, + SQLSMALLINT BufferLength, + SQLSMALLINT * StringLengthPtr, + SQLLEN * NumericAttributePtr); + + #define N3SQLColAttribute(a,b,c,d,e,f,g) (*reinterpret_cast<T3SQLColAttribute>(getOdbcFunction(ODBC3SQLFunctionId::ColAttribute)))(a,b,c,d,e,f,g) + + typedef SQLRETURN (SQL_API *T3SQLBindCol) ( SQLHSTMT StatementHandle, + SQLUSMALLINT ColumnNumber, + SQLSMALLINT TargetType, + SQLPOINTER TargetValuePtr, + SQLLEN BufferLength, + SQLLEN * StrLen_or_IndPtr); + + #define N3SQLBindCol(a,b,c,d,e,f) (*reinterpret_cast<T3SQLBindCol>(getOdbcFunction(ODBC3SQLFunctionId::BindCol)))(a,b,c,d,e,f) + + typedef SQLRETURN (SQL_API *T3SQLFetch) ( SQLHSTMT StatementHandle); + + #define N3SQLFetch(a) (*reinterpret_cast<T3SQLFetch>(getOdbcFunction(ODBC3SQLFunctionId::Fetch)))(a) + + typedef SQLRETURN (SQL_API *T3SQLFetchScroll) ( SQLHSTMT StatementHandle, + SQLSMALLINT FetchOrientation, + SQLLEN FetchOffset); + + #define N3SQLFetchScroll(a,b,c) (*reinterpret_cast<T3SQLFetchScroll>(getOdbcFunction(ODBC3SQLFunctionId::FetchScroll)))(a,b,c) + + typedef SQLRETURN (SQL_API *T3SQLGetData) ( SQLHSTMT StatementHandle, + SQLUSMALLINT ColumnNumber, + SQLSMALLINT TargetType, + SQLPOINTER TargetValuePtr, + SQLLEN BufferLength, + SQLLEN * StrLen_or_IndPtr); + + #define N3SQLGetData(a,b,c,d,e,f) (*reinterpret_cast<T3SQLGetData>(getOdbcFunction(ODBC3SQLFunctionId::GetData)))(a,b,c,d,e,f) + + typedef SQLRETURN (SQL_API *T3SQLSetPos) ( SQLHSTMT StatementHandle, + SQLSETPOSIROW RowNumber, + SQLUSMALLINT Operation, + SQLUSMALLINT LockType); + + #define N3SQLSetPos(a,b,c,d) (*reinterpret_cast<T3SQLSetPos>(getOdbcFunction(ODBC3SQLFunctionId::SetPos)))(a,b,c,d) + + typedef SQLRETURN (SQL_API *T3SQLBulkOperations) ( SQLHSTMT StatementHandle, + SQLSMALLINT Operation); + + #define N3SQLBulkOperations(a,b) (*reinterpret_cast<T3SQLBulkOperations>(getOdbcFunction(ODBC3SQLFunctionId::BulkOperations)))(a,b) + + typedef SQLRETURN (SQL_API *T3SQLMoreResults) ( SQLHSTMT StatementHandle); + + #define N3SQLMoreResults(a) (*reinterpret_cast<T3SQLMoreResults>(getOdbcFunction(ODBC3SQLFunctionId::MoreResults)))(a) + + /*typedef SQLRETURN (SQL_API *T3SQLGetDiagField) (SQLSMALLINT HandleType, + SQLHANDLE Handle, + SQLSMALLINT RecNumber, + SQLSMALLINT DiagIdentifier, + SQLPOINTER DiagInfoPtr, + SQLSMALLINT BufferLength, + SQLSMALLINT * StringLengthPtr); + + #define N3SQLGetDiagField(a,b,c,d,e,f,g) (*reinterpret_cast<T3SQLGetDiagField>(getOdbcFunction(ODBC3SQLFunctionId::GetDiagField)))(a,b,c,d,e,f,g)*/ + + typedef SQLRETURN (SQL_API *T3SQLGetDiagRec) ( SQLSMALLINT HandleType, + SQLHANDLE Handle, + SQLSMALLINT RecNumber, + SQLCHAR * Sqlstate, + SQLINTEGER * NativeErrorPtr, + SQLCHAR * MessageText, + SQLSMALLINT BufferLength, + SQLSMALLINT * TextLengthPtr); + + + #define N3SQLGetDiagRec(a,b,c,d,e,f,g,h) (*reinterpret_cast<T3SQLGetDiagRec>(getOdbcFunction(ODBC3SQLFunctionId::GetDiagRec)))(a,b,c,d,e,f,g,h) + + // Obtaining information about the data source's system tables (catalog functions) + typedef SQLRETURN (SQL_API *T3SQLColumnPrivileges) (SQLHSTMT StatementHandle, + SQLCHAR * CatalogName, + SQLSMALLINT NameLength1, + SQLCHAR * SchemaName, + SQLSMALLINT NameLength2, + SQLCHAR * TableName, + SQLSMALLINT NameLength3, + SQLCHAR * ColumnName, + SQLSMALLINT NameLength4); + + #define N3SQLColumnPrivileges(a,b,c,d,e,f,g,h,i) (*reinterpret_cast<T3SQLColumnPrivileges>(getOdbcFunction(ODBC3SQLFunctionId::ColumnPrivileges)))(a,b,c,d,e,f,g,h,i) + + typedef SQLRETURN (SQL_API *T3SQLColumns) ( SQLHSTMT StatementHandle, + SQLCHAR * CatalogName, + SQLSMALLINT NameLength1, + SQLCHAR * SchemaName, + SQLSMALLINT NameLength2, + SQLCHAR * TableName, + SQLSMALLINT NameLength3, + SQLCHAR * ColumnName, + SQLSMALLINT NameLength4); + + #define N3SQLColumns(a,b,c,d,e,f,g,h,i) (*reinterpret_cast<T3SQLColumns>(getOdbcFunction(ODBC3SQLFunctionId::Columns)))(a,b,c,d,e,f,g,h,i) + + typedef SQLRETURN (SQL_API *T3SQLForeignKeys) ( SQLHSTMT StatementHandle, + SQLCHAR * PKCatalogName, + SQLSMALLINT NameLength1, + SQLCHAR * PKSchemaName, + SQLSMALLINT NameLength2, + SQLCHAR * PKTableName, + SQLSMALLINT NameLength3, + SQLCHAR * FKCatalogName, + SQLSMALLINT NameLength4, + SQLCHAR * FKSchemaName, + SQLSMALLINT NameLength5, + SQLCHAR * FKTableName, + SQLSMALLINT NameLength6); + + #define N3SQLForeignKeys(a,b,c,d,e,f,g,h,i,j,k,l,m) (*reinterpret_cast<T3SQLForeignKeys>(getOdbcFunction(ODBC3SQLFunctionId::ForeignKeys)))(a,b,c,d,e,f,g,h,i,j,k,l,m) + + typedef SQLRETURN (SQL_API *T3SQLPrimaryKeys) ( SQLHSTMT StatementHandle, + SQLCHAR * CatalogName, + SQLSMALLINT NameLength1, + SQLCHAR * SchemaName, + SQLSMALLINT NameLength2, + SQLCHAR * TableName, + SQLSMALLINT NameLength3); + + #define N3SQLPrimaryKeys(a,b,c,d,e,f,g) (*reinterpret_cast<T3SQLPrimaryKeys>(getOdbcFunction(ODBC3SQLFunctionId::PrimaryKeys)))(a,b,c,d,e,f,g) + + typedef SQLRETURN (SQL_API *T3SQLProcedureColumns) (SQLHSTMT StatementHandle, + SQLCHAR * CatalogName, + SQLSMALLINT NameLength1, + SQLCHAR * SchemaName, + SQLSMALLINT NameLength2, + SQLCHAR * ProcName, + SQLSMALLINT NameLength3, + SQLCHAR * ColumnName, + SQLSMALLINT NameLength4); + + #define N3SQLProcedureColumns(a,b,c,d,e,f,g,h,i) (*reinterpret_cast<T3SQLProcedureColumns>(getOdbcFunction(ODBC3SQLFunctionId::ProcedureColumns)))(a,b,c,d,e,f,g,h,i) + + typedef SQLRETURN (SQL_API *T3SQLProcedures) ( SQLHSTMT StatementHandle, + SQLCHAR * CatalogName, + SQLSMALLINT NameLength1, + SQLCHAR * SchemaName, + SQLSMALLINT NameLength2, + SQLCHAR * ProcName, + SQLSMALLINT NameLength3); + + #define N3SQLProcedures(a,b,c,d,e,f,g) (*reinterpret_cast<T3SQLProcedures>(getOdbcFunction(ODBC3SQLFunctionId::Procedures)))(a,b,c,d,e,f,g) + + typedef SQLRETURN (SQL_API *T3SQLSpecialColumns) (SQLHSTMT StatementHandle, + SQLUSMALLINT IdentifierType, + SQLCHAR * CatalogName, + SQLSMALLINT NameLength1, + SQLCHAR * SchemaName, + SQLSMALLINT NameLength2, + SQLCHAR * TableName, + SQLSMALLINT NameLength3, + SQLUSMALLINT Scope, + SQLUSMALLINT Nullable); + + #define N3SQLSpecialColumns(a,b,c,d,e,f,g,h,i,j) (*reinterpret_cast<T3SQLSpecialColumns>(getOdbcFunction(ODBC3SQLFunctionId::SpecialColumns)))(a,b,c,d,e,f,g,h,i,j) + + typedef SQLRETURN (SQL_API *T3SQLStatistics) ( SQLHSTMT StatementHandle, + SQLCHAR * CatalogName, + SQLSMALLINT NameLength1, + SQLCHAR * SchemaName, + SQLSMALLINT NameLength2, + SQLCHAR * TableName, + SQLSMALLINT NameLength3, + SQLUSMALLINT Unique, + SQLUSMALLINT Reserved); + + #define N3SQLStatistics(a,b,c,d,e,f,g,h,i) (*reinterpret_cast<T3SQLStatistics>(getOdbcFunction(ODBC3SQLFunctionId::Statistics)))(a,b,c,d,e,f,g,h,i) + + typedef SQLRETURN (SQL_API *T3SQLTablePrivileges) (SQLHSTMT StatementHandle, + SQLCHAR * CatalogName, + SQLSMALLINT NameLength1, + SQLCHAR * SchemaName, + SQLSMALLINT NameLength2, + SQLCHAR * TableName, + SQLSMALLINT NameLength3); + + #define N3SQLTablePrivileges(a,b,c,d,e,f,g) (*reinterpret_cast<T3SQLTablePrivileges>(getOdbcFunction(ODBC3SQLFunctionId::TablePrivileges)))(a,b,c,d,e,f,g) + + typedef SQLRETURN (SQL_API *T3SQLTables) ( SQLHSTMT StatementHandle, + SQLCHAR * CatalogName, + SQLSMALLINT NameLength1, + SQLCHAR * SchemaName, + SQLSMALLINT NameLength2, + SQLCHAR * TableName, + SQLSMALLINT NameLength3, + SQLCHAR * TableType, + SQLSMALLINT NameLength4); + + #define N3SQLTables(a,b,c,d,e,f,g,h,i) (*reinterpret_cast<T3SQLTables>(getOdbcFunction(ODBC3SQLFunctionId::Tables)))(a,b,c,d,e,f,g,h,i) + + // Terminating a statement + typedef SQLRETURN (SQL_API *T3SQLFreeStmt) ( SQLHSTMT StatementHandle, + SQLUSMALLINT Option); + + #define N3SQLFreeStmt(a,b) (*reinterpret_cast<T3SQLFreeStmt>(getOdbcFunction(ODBC3SQLFunctionId::FreeStmt)))(a,b) + + typedef SQLRETURN (SQL_API *T3SQLCloseCursor) (SQLHSTMT StatementHandle); + + #define N3SQLCloseCursor(a) (*reinterpret_cast<T3SQLCloseCursor>(getOdbcFunction(ODBC3SQLFunctionId::CloseCursor)))(a) + + typedef SQLRETURN (SQL_API *T3SQLCancel) ( SQLHSTMT StatementHandle); + + #define N3SQLCancel(a) (*reinterpret_cast<T3SQLCancel>(getOdbcFunction(ODBC3SQLFunctionId::Cancel)))(a) + + typedef SQLRETURN (SQL_API *T3SQLEndTran) ( SQLSMALLINT HandleType, + SQLHANDLE Handle, + SQLSMALLINT CompletionType); + + #define N3SQLEndTran(a,b,c) (*reinterpret_cast<T3SQLEndTran>(getOdbcFunction(ODBC3SQLFunctionId::EndTran)))(a,b,c) + + // Terminating a connection + typedef SQLRETURN (SQL_API *T3SQLDisconnect) (SQLHDBC ConnectionHandle); + + #define N3SQLDisconnect(a) (*reinterpret_cast<T3SQLDisconnect>(getOdbcFunction(ODBC3SQLFunctionId::Disconnect)))(a) + + typedef SQLRETURN (SQL_API *T3SQLFreeHandle) (SQLSMALLINT HandleType, + SQLHANDLE Handle); + + #define N3SQLFreeHandle(a,b) (*reinterpret_cast<T3SQLFreeHandle>(getOdbcFunction(ODBC3SQLFunctionId::FreeHandle)))(a,b) + + typedef SQLRETURN (SQL_API *T3SQLGetCursorName) ( SQLHSTMT StatementHandle, + SQLCHAR * CursorName, + SQLSMALLINT BufferLength, + SQLSMALLINT* NameLength2); + + #define N3SQLGetCursorName(a,b,c,d) (*reinterpret_cast<T3SQLGetCursorName>(getOdbcFunction(ODBC3SQLFunctionId::GetCursorName)))(a,b,c,d) + + typedef SQLRETURN (SQL_API *T3SQLNativeSql) ( SQLHDBC ConnectionHandle, + SQLCHAR * InStatementText, + SQLINTEGER TextLength1, + SQLCHAR * OutStatementText, + SQLINTEGER BufferLength, + SQLINTEGER * TextLength2Ptr); + + #define N3SQLNativeSql(a,b,c,d,e,f) (*reinterpret_cast<T3SQLNativeSql>(getOdbcFunction(ODBC3SQLFunctionId::NativeSql)))(a,b,c,d,e,f) + + // extern declaration of the function pointer + extern T3SQLAllocHandle pODBC3SQLAllocHandle; + extern T3SQLConnect pODBC3SQLConnect; + extern T3SQLDriverConnect pODBC3SQLDriverConnect; + extern T3SQLBrowseConnect pODBC3SQLBrowseConnect; + extern T3SQLDataSources pODBC3SQLDataSources; + extern T3SQLDrivers pODBC3SQLDrivers; + extern T3SQLGetInfo pODBC3SQLGetInfo; + extern T3SQLGetFunctions pODBC3SQLGetFunctions; + extern T3SQLGetTypeInfo pODBC3SQLGetTypeInfo; + extern T3SQLSetConnectAttr pODBC3SQLSetConnectAttr; + extern T3SQLGetConnectAttr pODBC3SQLGetConnectAttr; + extern T3SQLSetEnvAttr pODBC3SQLSetEnvAttr; + extern T3SQLGetEnvAttr pODBC3SQLGetEnvAttr; + extern T3SQLSetStmtAttr pODBC3SQLSetStmtAttr; + extern T3SQLGetStmtAttr pODBC3SQLGetStmtAttr; + //extern T3SQLSetDescField pODBC3SQLSetDescField; + //extern T3SQLGetDescField pODBC3SQLGetDescField; + //extern T3SQLGetDescRec pODBC3SQLGetDescRec; + //extern T3SQLSetDescRec pODBC3SQLSetDescRec; + extern T3SQLPrepare pODBC3SQLPrepare; + extern T3SQLBindParameter pODBC3SQLBindParameter; + //extern T3SQLGetCursorName pODBC3SQLGetCursorName; + extern T3SQLSetCursorName pODBC3SQLSetCursorName; + extern T3SQLExecute pODBC3SQLExecute; + extern T3SQLExecDirect pODBC3SQLExecDirect; + //extern T3SQLNativeSql pODBC3SQLNativeSql; + extern T3SQLDescribeParam pODBC3SQLDescribeParam; + extern T3SQLNumParams pODBC3SQLNumParams; + extern T3SQLParamData pODBC3SQLParamData; + extern T3SQLPutData pODBC3SQLPutData; + extern T3SQLRowCount pODBC3SQLRowCount; + extern T3SQLNumResultCols pODBC3SQLNumResultCols; + extern T3SQLDescribeCol pODBC3SQLDescribeCol; + extern T3SQLColAttribute pODBC3SQLColAttribute; + extern T3SQLBindCol pODBC3SQLBindCol; + extern T3SQLFetch pODBC3SQLFetch; + extern T3SQLFetchScroll pODBC3SQLFetchScroll; + extern T3SQLGetData pODBC3SQLGetData; + extern T3SQLSetPos pODBC3SQLSetPos; + extern T3SQLBulkOperations pODBC3SQLBulkOperations; + extern T3SQLMoreResults pODBC3SQLMoreResults; + //extern T3SQLGetDiagField pODBC3SQLGetDiagField; + extern T3SQLGetDiagRec pODBC3SQLGetDiagRec; + extern T3SQLColumnPrivileges pODBC3SQLColumnPrivileges; + extern T3SQLColumns pODBC3SQLColumns; + extern T3SQLForeignKeys pODBC3SQLForeignKeys; + extern T3SQLPrimaryKeys pODBC3SQLPrimaryKeys; + extern T3SQLProcedureColumns pODBC3SQLProcedureColumns; + extern T3SQLProcedures pODBC3SQLProcedures; + extern T3SQLSpecialColumns pODBC3SQLSpecialColumns; + extern T3SQLStatistics pODBC3SQLStatistics; + extern T3SQLTablePrivileges pODBC3SQLTablePrivileges; + extern T3SQLTables pODBC3SQLTables; + extern T3SQLFreeStmt pODBC3SQLFreeStmt; + extern T3SQLCloseCursor pODBC3SQLCloseCursor; + extern T3SQLCancel pODBC3SQLCancel; + extern T3SQLEndTran pODBC3SQLEndTran; + extern T3SQLDisconnect pODBC3SQLDisconnect; + extern T3SQLFreeHandle pODBC3SQLFreeHandle; + extern T3SQLGetCursorName pODBC3SQLGetCursorName; + extern T3SQLNativeSql pODBC3SQLNativeSql; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/OPreparedStatement.hxx b/connectivity/source/inc/odbc/OPreparedStatement.hxx new file mode 100644 index 0000000000..37e29db9c5 --- /dev/null +++ b/connectivity/source/inc/odbc/OPreparedStatement.hxx @@ -0,0 +1,149 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <odbc/odbcbasedllapi.hxx> +#include <odbc/OStatement.hxx> +#include <com/sun/star/sdbc/XPreparedStatement.hpp> +#include <com/sun/star/sdbc/XParameters.hpp> +#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> +#include <com/sun/star/sdbc/XPreparedBatchExecution.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <cppuhelper/implbase5.hxx> + +namespace connectivity::odbc + { + + class OBoundParam; + typedef ::cppu::ImplHelper5< css::sdbc::XPreparedStatement, + css::sdbc::XParameters, + css::sdbc::XPreparedBatchExecution, + css::sdbc::XResultSetMetaDataSupplier, + css::lang::XServiceInfo> OPreparedStatement_BASE; + + class OOO_DLLPUBLIC_ODBCBASE OPreparedStatement final : + public OStatement_BASE2, + public OPreparedStatement_BASE + { + static const short invalid_scale = -1; + + // Data attributes + + SQLSMALLINT numParams; // Number of parameter markers for the prepared statement + + std::unique_ptr<OBoundParam[]> boundParams; + // Array of bound parameter objects. Each parameter marker will have a + // corresponding object to hold bind information, and resulting data. + css::uno::Reference< css::sdbc::XResultSetMetaData > m_xMetaData; + bool m_bPrepared; + + void FreeParams(); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void putParamData (sal_Int32 index); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setStream (sal_Int32 ParameterIndex,const css::uno::Reference< css::io::XInputStream>& x, + SQLLEN length,sal_Int32 SQLtype); + SQLLEN* getLengthBuf (sal_Int32 index); + void* allocBindBuf ( sal_Int32 index, sal_Int32 bufLen); + /// @throws css::sdbc::SQLException + void initBoundParam (); + void setParameterPre(sal_Int32 parameterIndex); + template <typename T> void setScalarParameter(sal_Int32 parameterIndex, sal_Int32 _nType, SQLULEN _nColumnSize, const T i_Value); + template <typename T> void setScalarParameter(sal_Int32 parameterIndex, sal_Int32 _nType, SQLULEN _nColumnSize, sal_Int32 _nScale, const T i_Value); + void setParameter(sal_Int32 parameterIndex, sal_Int32 _nType, SQLULEN _nColumnSize, sal_Int32 _nScale, const void* _pData, SQLULEN _nDataLen, SQLLEN _nDataAllocLen); + // Wrappers for special cases + void setParameter(sal_Int32 parameterIndex, sal_Int32 _nType, sal_Int16 _nScale, const OUString &_sData); + void setParameter(sal_Int32 parameterIndex, sal_Int32 _nType, const css::uno::Sequence< sal_Int8 > &Data); + + bool isPrepared() const { return m_bPrepared;} + void prepareStatement(); + void checkParameterIndex(sal_Int32 _parameterIndex); + + /** + creates the driver specific resultset (factory) + */ + virtual rtl::Reference<OResultSet> createResultSet() override; + + virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, + const css::uno::Any& rValue) override; + public: + DECLARE_SERVICE_INFO(); + // A ctor, needed to return the object + OPreparedStatement( OConnection* _pConnection,const OUString& sql); + virtual ~OPreparedStatement() override; + OPreparedStatement& operator=( OPreparedStatement const & ) = delete; // MSVC2015 workaround + OPreparedStatement( OPreparedStatement const & ) = delete; // MSVC2015 workaround + + //XInterface + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + + // XPreparedStatement + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL executeQuery( ) override; + virtual sal_Int32 SAL_CALL executeUpdate( ) override; + virtual sal_Bool SAL_CALL execute( ) override; + virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( ) override; + // XParameters + virtual void SAL_CALL setNull( sal_Int32 parameterIndex, sal_Int32 sqlType ) override; + virtual void SAL_CALL setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const OUString& typeName ) override; + virtual void SAL_CALL setBoolean( sal_Int32 parameterIndex, sal_Bool x ) override; + virtual void SAL_CALL setByte( sal_Int32 parameterIndex, sal_Int8 x ) override; + virtual void SAL_CALL setShort( sal_Int32 parameterIndex, sal_Int16 x ) override; + virtual void SAL_CALL setInt( sal_Int32 parameterIndex, sal_Int32 x ) override; + virtual void SAL_CALL setLong( sal_Int32 parameterIndex, sal_Int64 x ) override; + virtual void SAL_CALL setFloat( sal_Int32 parameterIndex, float x ) override; + virtual void SAL_CALL setDouble( sal_Int32 parameterIndex, double x ) override; + virtual void SAL_CALL setString( sal_Int32 parameterIndex, const OUString& x ) override; + virtual void SAL_CALL setBytes( sal_Int32 parameterIndex, const css::uno::Sequence< sal_Int8 >& x ) override; + virtual void SAL_CALL setDate( sal_Int32 parameterIndex, const css::util::Date& x ) override; + virtual void SAL_CALL setTime( sal_Int32 parameterIndex, const css::util::Time& x ) override; + virtual void SAL_CALL setTimestamp( sal_Int32 parameterIndex, const css::util::DateTime& x ) override; + virtual void SAL_CALL setBinaryStream( sal_Int32 parameterIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override; + virtual void SAL_CALL setCharacterStream( sal_Int32 parameterIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override; + virtual void SAL_CALL setObject( sal_Int32 parameterIndex, const css::uno::Any& x ) override; + virtual void SAL_CALL setObjectWithInfo( sal_Int32 parameterIndex, const css::uno::Any& x, sal_Int32 targetSqlType, sal_Int32 scale ) override; + virtual void SAL_CALL setRef( sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XRef >& x ) override; + virtual void SAL_CALL setBlob( sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XBlob >& x ) override; + virtual void SAL_CALL setClob( sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XClob >& x ) override; + virtual void SAL_CALL setArray( sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XArray >& x ) override; + virtual void SAL_CALL clearParameters( ) override; + // XPreparedBatchExecution + virtual void SAL_CALL addBatch( ) override; + virtual void SAL_CALL clearBatch( ) override; + virtual css::uno::Sequence< sal_Int32 > SAL_CALL executeBatch( ) override; + // XCloseable + virtual void SAL_CALL close( ) override; + // XResultSetMetaDataSupplier + virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData( ) override; + + public: + using OStatement_Base::executeQuery; + using OStatement_Base::executeUpdate; + using OStatement_Base::execute; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/OResultSet.hxx b/connectivity/source/inc/odbc/OResultSet.hxx new file mode 100644 index 0000000000..6de7adc281 --- /dev/null +++ b/connectivity/source/inc/odbc/OResultSet.hxx @@ -0,0 +1,354 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/sdbc/FetchDirection.hpp> +#include <com/sun/star/sdbc/XResultSet.hpp> +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> +#include <com/sun/star/sdbc/XCloseable.hpp> +#include <com/sun/star/sdbc/XColumnLocate.hpp> +#include <com/sun/star/util/XCancellable.hpp> +#include <com/sun/star/sdbc/XWarningsSupplier.hpp> +#include <com/sun/star/sdbc/XResultSetUpdate.hpp> +#include <com/sun/star/sdbc/XRowUpdate.hpp> +#include <com/sun/star/sdbcx/XRowLocate.hpp> +#include <com/sun/star/sdbcx/XDeleteRows.hpp> +#include <cppuhelper/compbase.hxx> +#include <comphelper/proparrhlp.hxx> +#include <odbc/OFunctions.hxx> +#include <odbc/OStatement.hxx> +#include <odbc/odbcbasedllapi.hxx> +#include <connectivity/CommonTools.hxx> +#include <connectivity/FValue.hxx> +#include <TSkipDeletedSet.hxx> +#include <memory> + +namespace connectivity::odbc + { + + /* + ** java_sql_ResultSet + */ + typedef ::cppu::WeakComponentImplHelper< css::sdbc::XResultSet, + css::sdbc::XRow, + css::sdbc::XResultSetMetaDataSupplier, + css::util::XCancellable, + css::sdbc::XWarningsSupplier, + css::sdbc::XResultSetUpdate, + css::sdbc::XRowUpdate, + css::sdbcx::XRowLocate, + css::sdbcx::XDeleteRows, + css::sdbc::XCloseable, + css::sdbc::XColumnLocate, + css::lang::XServiceInfo> OResultSet_BASE; + + + typedef std::pair<sal_Int64,sal_Int32> TVoidPtr; + typedef std::allocator< TVoidPtr > TVoidAlloc; + typedef std::vector<TVoidPtr> TVoidVector; + /// Functor object for class ZZ returntype is void + struct OOO_DLLPUBLIC_ODBCBASE TBookmarkPosMapCompare + { + bool operator()( const css::uno::Sequence<sal_Int8>& _rLH, + const css::uno::Sequence<sal_Int8>& _rRH) const + { + if(_rLH.getLength() == _rRH.getLength()) + { + sal_Int32 nCount = _rLH.getLength(); + if(nCount != 4) + { + const sal_Int8* pLHBack = _rLH.getConstArray() + nCount - 1; + const sal_Int8* pRHBack = _rRH.getConstArray() + nCount - 1; + + sal_Int32 i; + for(i=0;i < nCount;++i,--pLHBack,--pRHBack) + { + if(!(*pLHBack) && *pRHBack) + return true; + else if(*pLHBack && !(*pRHBack)) + return false; + } + for(i=0,++pLHBack,++pRHBack;i < nCount;++pLHBack,++pRHBack,++i) + if(*pLHBack < *pRHBack) + return true; + return false; + } + else + return *reinterpret_cast<const sal_Int32*>(_rLH.getConstArray()) < *reinterpret_cast<const sal_Int32*>(_rRH.getConstArray()); + + } + else + return _rLH.getLength() < _rRH.getLength(); + } + }; + + typedef std::map< css::uno::Sequence<sal_Int8>, sal_Int32,TBookmarkPosMapCompare > TBookmarkPosMap; + + class OOO_DLLPUBLIC_ODBCBASE OResultSet : + public cppu::BaseMutex, + public ::connectivity::IResultSetHelper, + public OResultSet_BASE, + public ::cppu::OPropertySetHelper, + public ::comphelper::OPropertyArrayUsageHelper<OResultSet> + { + protected: + TBookmarkPosMap m_aPosToBookmarks; + // used top hold the information about the value and the datatype to save calls to metadata + typedef std::vector<ORowSetValue> TDataRow; + + TVoidVector m_aBindVector; + std::vector<SQLLEN> m_aLengthVector; + std::map<sal_Int32,SWORD> m_aODBCColumnTypes; + + // In baseline ODBC, SQLGetData can only be called on monotonically increasing column numbers. + // additionally, any variable-length data can be fetched only once (possibly in parts); + // after that, SQLGetData returns SQL_NO_DATA. + // In order to insulate our callers from these restrictions, + // we cache the current row in m_aRow. + // If the driver claims to support the GD_ANY_ORDER extension, + // we read and cache only the columns requested by a caller. + // Else, we read and cache all columns whose number is <= a requested column. + // m_aRow[colNumber].getBound() says if it contains an up-to-date value or not. + TDataRow m_aRow; + bool m_bFetchDataInOrder; + SQLHANDLE m_aStatementHandle; + SQLHANDLE m_aConnectionHandle; + OStatement_Base* m_pStatement; + std::unique_ptr<OSkipDeletedSet> m_pSkipDeletedSet; + css::uno::Reference< css::uno::XInterface> m_xStatement; + css::uno::Reference< css::sdbc::XResultSetMetaData> m_xMetaData; + std::unique_ptr<SQLUSMALLINT[]> m_pRowStatusArray; + rtl_TextEncoding m_nTextEncoding; + sal_Int32 m_nRowPos; + mutable sal_uInt32 m_nUseBookmarks; + SQLRETURN m_nCurrentFetchState; + bool m_bWasNull; + bool m_bEOF; // after last record + bool m_bRowInserted; + bool m_bRowDeleted; + bool m_bUseFetchScroll; + + bool isBookmarkable() const; + sal_Int32 getResultSetConcurrency() const; + sal_Int32 getResultSetType() const; + static sal_Int32 getFetchDirection() { return css::sdbc::FetchDirection::FORWARD; } + sal_Int32 getFetchSize() const; + OUString getCursorName() const; + template < typename T, SQLINTEGER BufferLength > T getStmtOption (SQLINTEGER fOption) const; + + void setFetchDirection(sal_Int32 _par0); + void setFetchSize(sal_Int32 _par0); + template < typename T, SQLINTEGER BufferLength > SQLRETURN setStmtOption (SQLINTEGER fOption, T value) const; + + + void ensureCacheForColumn(sal_Int32 columnIndex); + void invalidateCache(); + void fillColumn(sal_Int32 _nToColumn); + void allocBuffer(); + void releaseBuffer(); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void updateValue(sal_Int32 columnIndex, SQLSMALLINT _nType, void const * _pValue); + void fillNeededData(SQLRETURN _nRet); + bool moveImpl(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset); + TVoidPtr allocBindColumn(sal_Int32 _nType,sal_Int32 _nColumnIndex); + SQLRETURN unbind(bool _bUnbindHandle = true); + SWORD impl_getColumnType_nothrow(sal_Int32 columnIndex); + + // helper to implement XRow::getXXX in simple cases + template < typename T > T getValue( sal_Int32 columnIndex ); + // impl_getXXX are the functions that do the actual fetching from ODBC, ignoring the cache + // for simple cases + template < typename T > T impl_getValue( const sal_Int32 _nColumnIndex, SQLSMALLINT nType ); + // these cases need some special treatment + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + bool impl_getBoolean( sal_Int32 columnIndex ); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + css::uno::Sequence< sal_Int8 > impl_getBytes( sal_Int32 columnIndex ); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + css::util::Date impl_getDate( sal_Int32 columnIndex ); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + css::util::Time impl_getTime( sal_Int32 columnIndex ); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + css::util::DateTime impl_getTimestamp( sal_Int32 columnIndex ); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int64 impl_getLong( sal_Int32 columnIndex ); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + OUString impl_getString( sal_Int32 columnIndex ); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + css::uno::Sequence<sal_Int8> impl_getBookmark( ); + + + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override; + // OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + + virtual sal_Bool SAL_CALL convertFastPropertyValue( + css::uno::Any & rConvertedValue, + css::uno::Any & rOldValue, + sal_Int32 nHandle, + const css::uno::Any& rValue ) override; + virtual void SAL_CALL setFastPropertyValue_NoBroadcast( + sal_Int32 nHandle, + const css::uno::Any& rValue + ) override; + virtual void SAL_CALL getFastPropertyValue( + css::uno::Any& rValue, + sal_Int32 nHandle + ) const override; + public: + DECLARE_SERVICE_INFO(); + // A ctor that is needed for returning the object + OResultSet( SQLHANDLE _pStatementHandle,OStatement_Base* pStmt); + virtual ~OResultSet() override; + + void construct(); + + oslGenericFunction getOdbcFunction(ODBC3SQLFunctionId _nIndex) const + { + return m_pStatement->getOdbcFunction(_nIndex); + } + + css::uno::Reference< css::uno::XInterface > operator *() + { + return css::uno::Reference< css::uno::XInterface >(*static_cast<OResultSet_BASE*>(this)); + } + + void setMetaData(const css::uno::Reference< css::sdbc::XResultSetMetaData>& _xMetaData) { m_xMetaData = _xMetaData;} + + // ::cppu::OComponentHelper + virtual void SAL_CALL disposing() override; + // XInterface + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + // XPropertySet + virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; + // XResultSet + virtual sal_Bool SAL_CALL next( ) override; + virtual sal_Bool SAL_CALL isBeforeFirst( ) override; + virtual sal_Bool SAL_CALL isAfterLast( ) override; + virtual sal_Bool SAL_CALL isFirst( ) override; + virtual sal_Bool SAL_CALL isLast( ) override; + virtual void SAL_CALL beforeFirst( ) override; + virtual void SAL_CALL afterLast( ) override; + virtual sal_Bool SAL_CALL first( ) override; + virtual sal_Bool SAL_CALL last( ) override; + virtual sal_Int32 SAL_CALL getRow( ) override; + virtual sal_Bool SAL_CALL absolute( sal_Int32 row ) override; + virtual sal_Bool SAL_CALL relative( sal_Int32 rows ) override; + virtual sal_Bool SAL_CALL previous( ) override; + virtual void SAL_CALL refreshRow( ) override; + virtual sal_Bool SAL_CALL rowUpdated( ) override; + virtual sal_Bool SAL_CALL rowInserted( ) override; + virtual sal_Bool SAL_CALL rowDeleted( ) override; + virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getStatement( ) override; + // XRow + virtual sal_Bool SAL_CALL wasNull( ) override; + virtual OUString SAL_CALL getString( sal_Int32 columnIndex ) override; + virtual sal_Bool SAL_CALL getBoolean( sal_Int32 columnIndex ) override; + virtual sal_Int8 SAL_CALL getByte( sal_Int32 columnIndex ) override; + virtual sal_Int16 SAL_CALL getShort( sal_Int32 columnIndex ) override; + virtual sal_Int32 SAL_CALL getInt( sal_Int32 columnIndex ) override; + virtual sal_Int64 SAL_CALL getLong( sal_Int32 columnIndex ) override; + virtual float SAL_CALL getFloat( sal_Int32 columnIndex ) override; + virtual double SAL_CALL getDouble( sal_Int32 columnIndex ) override; + virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes( sal_Int32 columnIndex ) override; + virtual css::util::Date SAL_CALL getDate( sal_Int32 columnIndex ) override; + virtual css::util::Time SAL_CALL getTime( sal_Int32 columnIndex ) override; + virtual css::util::DateTime SAL_CALL getTimestamp( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream( sal_Int32 columnIndex ) override; + virtual css::uno::Any SAL_CALL getObject( sal_Int32 columnIndex, const css::uno::Reference< css::container::XNameAccess >& typeMap ) override; + virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob( sal_Int32 columnIndex ) override; + virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray( sal_Int32 columnIndex ) override; + // XResultSetMetaDataSupplier + virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData( ) override; + // XCancellable + virtual void SAL_CALL cancel( ) override; + // XCloseable + virtual void SAL_CALL close( ) override; + // XWarningsSupplier + virtual css::uno::Any SAL_CALL getWarnings( ) override; + virtual void SAL_CALL clearWarnings( ) override; + // XResultSetUpdate + virtual void SAL_CALL insertRow( ) override; + virtual void SAL_CALL updateRow( ) override; + virtual void SAL_CALL deleteRow( ) override; + virtual void SAL_CALL cancelRowUpdates( ) override; + virtual void SAL_CALL moveToInsertRow( ) override; + virtual void SAL_CALL moveToCurrentRow( ) override; + // XRowUpdate + virtual void SAL_CALL updateNull( sal_Int32 columnIndex ) override; + virtual void SAL_CALL updateBoolean( sal_Int32 columnIndex, sal_Bool x ) override; + virtual void SAL_CALL updateByte( sal_Int32 columnIndex, sal_Int8 x ) override; + virtual void SAL_CALL updateShort( sal_Int32 columnIndex, sal_Int16 x ) override; + virtual void SAL_CALL updateInt( sal_Int32 columnIndex, sal_Int32 x ) override; + virtual void SAL_CALL updateLong( sal_Int32 columnIndex, sal_Int64 x ) override; + virtual void SAL_CALL updateFloat( sal_Int32 columnIndex, float x ) override; + virtual void SAL_CALL updateDouble( sal_Int32 columnIndex, double x ) override; + virtual void SAL_CALL updateString( sal_Int32 columnIndex, const OUString& x ) override; + virtual void SAL_CALL updateBytes( sal_Int32 columnIndex, const css::uno::Sequence< sal_Int8 >& x ) override; + virtual void SAL_CALL updateDate( sal_Int32 columnIndex, const css::util::Date& x ) override; + virtual void SAL_CALL updateTime( sal_Int32 columnIndex, const css::util::Time& x ) override; + virtual void SAL_CALL updateTimestamp( sal_Int32 columnIndex, const css::util::DateTime& x ) override; + virtual void SAL_CALL updateBinaryStream( sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override; + virtual void SAL_CALL updateCharacterStream( sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override; + virtual void SAL_CALL updateObject( sal_Int32 columnIndex, const css::uno::Any& x ) override; + virtual void SAL_CALL updateNumericObject( sal_Int32 columnIndex, const css::uno::Any& x, sal_Int32 scale ) override; + // XColumnLocate + virtual sal_Int32 SAL_CALL findColumn( const OUString& columnName ) override; + // XRowLocate + virtual css::uno::Any SAL_CALL getBookmark( ) override; + virtual sal_Bool SAL_CALL moveToBookmark( const css::uno::Any& bookmark ) override; + virtual sal_Bool SAL_CALL moveRelativeToBookmark( const css::uno::Any& bookmark, sal_Int32 rows ) override; + virtual sal_Int32 SAL_CALL compareBookmarks( const css::uno::Any& first, const css::uno::Any& second ) override; + virtual sal_Bool SAL_CALL hasOrderedBookmarks( ) override; + virtual sal_Int32 SAL_CALL hashBookmark( const css::uno::Any& bookmark ) override; + // XDeleteRows + virtual css::uno::Sequence< sal_Int32 > SAL_CALL deleteRows( const css::uno::Sequence< css::uno::Any >& rows ) override; + + // IResultSetHelper + virtual bool move(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset, bool _bRetrieveData) override; + virtual sal_Int32 getDriverPos() const override; + virtual bool isRowDeleted() const override; + + protected: + using OPropertySetHelper::getFastPropertyValue; + }; + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/OResultSetMetaData.hxx b/connectivity/source/inc/odbc/OResultSetMetaData.hxx new file mode 100644 index 0000000000..ea32a453e9 --- /dev/null +++ b/connectivity/source/inc/odbc/OResultSetMetaData.hxx @@ -0,0 +1,116 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/sdbc/XResultSetMetaData.hpp> +#include <cppuhelper/implbase.hxx> +#include <odbc/OFunctions.hxx> +#include <odbc/odbcbasedllapi.hxx> +#include <vector> +#include <odbc/OConnection.hxx> + +namespace connectivity::odbc + { + + //************ Class: ResultSetMetaData + + typedef ::cppu::WeakImplHelper< css::sdbc::XResultSetMetaData> OResultSetMetaData_BASE; + + class OOO_DLLPUBLIC_ODBCBASE OResultSetMetaData final : + public OResultSetMetaData_BASE + { + std::vector<sal_Int32> m_vMapping; // when not every column is needed + std::map<sal_Int32,sal_Int32> m_aColumnTypes; + + SQLHANDLE m_aStatementHandle; + OConnection* m_pConnection; + sal_Int32 m_nColCount; + bool m_bUseODBC2Types; + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + OUString getCharColAttrib(sal_Int32 column,sal_Int32 ident); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getNumColAttrib(sal_Int32 column,sal_Int32 ident); + public: + // A ctor that is needed for returning the object + OResultSetMetaData(OConnection* _pConnection, SQLHANDLE _pStmt ) + :m_aStatementHandle( _pStmt ) + ,m_pConnection(_pConnection) + ,m_nColCount(-1) + ,m_bUseODBC2Types(false) + {} + OResultSetMetaData(OConnection* _pConnection, SQLHANDLE _pStmt, std::vector<sal_Int32>&& _vMapping) + :m_vMapping(std::move(_vMapping)) + ,m_aStatementHandle( _pStmt ) + ,m_pConnection(_pConnection) + ,m_nColCount(m_vMapping.size()-1) + ,m_bUseODBC2Types(false) + {} + virtual ~OResultSetMetaData() override; + + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + static SQLLEN getNumColAttrib(OConnection const * _pConnection + ,SQLHANDLE _aStatementHandle + ,const css::uno::Reference< css::uno::XInterface >& _xInterface + ,sal_Int32 _column + ,sal_Int32 ident); + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + static SQLSMALLINT getColumnODBCType(OConnection const * _pConnection + ,SQLHANDLE _aStatementHandle + ,const css::uno::Reference< css::uno::XInterface >& _xInterface + ,sal_Int32 column); + + oslGenericFunction getOdbcFunction(ODBC3SQLFunctionId _nIndex) const + { + return m_pConnection->getOdbcFunction(_nIndex); + } + + virtual sal_Int32 SAL_CALL getColumnCount( ) override; + virtual sal_Bool SAL_CALL isAutoIncrement( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isCaseSensitive( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isSearchable( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isCurrency( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL isNullable( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isSigned( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getColumnDisplaySize( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnLabel( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnName( sal_Int32 column ) override; + virtual OUString SAL_CALL getSchemaName( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getPrecision( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getScale( sal_Int32 column ) override; + virtual OUString SAL_CALL getTableName( sal_Int32 column ) override; + virtual OUString SAL_CALL getCatalogName( sal_Int32 column ) override; + virtual sal_Int32 SAL_CALL getColumnType( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnTypeName( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isReadOnly( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isWritable( sal_Int32 column ) override; + virtual sal_Bool SAL_CALL isDefinitelyWritable( sal_Int32 column ) override; + virtual OUString SAL_CALL getColumnServiceName( sal_Int32 column ) override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/OStatement.hxx b/connectivity/source/inc/odbc/OStatement.hxx new file mode 100644 index 0000000000..1e48310873 --- /dev/null +++ b/connectivity/source/inc/odbc/OStatement.hxx @@ -0,0 +1,244 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/sdbc/XStatement.hpp> +#include <com/sun/star/sdbc/XWarningsSupplier.hpp> +#include <com/sun/star/sdbc/XMultipleResults.hpp> +#include <com/sun/star/sdbc/XBatchExecution.hpp> +#include <com/sun/star/sdbc/XCloseable.hpp> +#include <com/sun/star/sdbc/SQLWarning.hpp> +#include <com/sun/star/sdbc/XGeneratedResultSet.hpp> +#include <com/sun/star/util/XCancellable.hpp> +#include <comphelper/proparrhlp.hxx> +#include <cppuhelper/compbase.hxx> +#include <cppuhelper/basemutex.hxx> +#include <connectivity/CommonTools.hxx> +#include <odbc/OFunctions.hxx> +#include <odbc/OConnection.hxx> +#include <odbc/odbcbasedllapi.hxx> +#include <string_view> +#include <vector> +#include <com/sun/star/lang/XServiceInfo.hpp> + +namespace connectivity::odbc + { + + typedef ::cppu::WeakComponentImplHelper< css::sdbc::XStatement, + css::sdbc::XWarningsSupplier, + css::util::XCancellable, + css::sdbc::XCloseable, + css::sdbc::XGeneratedResultSet, + css::sdbc::XMultipleResults> OStatement_BASE; + + class OResultSet; + + //************ Class: java.sql.Statement + + class OOO_DLLPUBLIC_ODBCBASE OStatement_Base : + public cppu::BaseMutex, + public OStatement_BASE, + public ::cppu::OPropertySetHelper, + public ::comphelper::OPropertyArrayUsageHelper<OStatement_Base> + + { + css::sdbc::SQLWarning m_aLastWarning; + protected: + css::uno::WeakReference< css::sdbc::XResultSet> m_xResultSet; // The last ResultSet created + css::uno::Reference< css::sdbc::XStatement> m_xGeneratedStatement; + // for this Statement + + std::vector< OUString> m_aBatchVector; + OUString m_sSqlStatement; + + rtl::Reference<OConnection> m_pConnection;// The owning Connection object + SQLHANDLE m_aStatementHandle; + SQLUSMALLINT* m_pRowStatusArray; + + protected: + + sal_Int64 getQueryTimeOut() const; + sal_Int64 getMaxFieldSize() const; + sal_Int64 getMaxRows() const; + sal_Int32 getResultSetConcurrency() const; + sal_Int32 getResultSetType() const; + sal_Int32 getFetchDirection() const; + sal_Int32 getFetchSize() const; + OUString getCursorName() const; + bool isUsingBookmarks() const; + bool getEscapeProcessing() const; + template < typename T, SQLINTEGER BufferLength > T getStmtOption (SQLINTEGER fOption) const; + + void setQueryTimeOut(sal_Int64 _par0) ; + void setMaxFieldSize(sal_Int64 _par0) ; + void setMaxRows(sal_Int64 _par0) ; + void setFetchDirection(sal_Int32 _par0) ; + void setFetchSize(sal_Int32 _par0) ; + void setCursorName(std::u16string_view _par0); + void setEscapeProcessing( const bool _bEscapeProc ); + template < typename T, SQLINTEGER BufferLength > SQLRETURN setStmtOption (SQLINTEGER fOption, T value) const; + + void setResultSetConcurrency(sal_Int32 _par0) ; + void setResultSetType(sal_Int32 _par0) ; + void setUsingBookmarks(bool _bUseBookmark) ; + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void reset(); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void clearMyResultSet(); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void setWarning (const css::sdbc::SQLWarning &ex); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + bool lockIfNecessary (const OUString& sql); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + sal_Int32 getColumnCount(); + + + // getResultSet + // getResultSet returns the current result as a ResultSet. It + // returns NULL if the current result is not a ResultSet. + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + css::uno::Reference<css::sdbc::XResultSet> getResultSet(bool checkCount); + /** + creates the driver specific resultset (factory) + */ + virtual rtl::Reference<OResultSet> createResultSet(); + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + SQLLEN getRowCount(); + + + void disposeResultSet(); + + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override; + // OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + virtual sal_Bool SAL_CALL convertFastPropertyValue( + css::uno::Any & rConvertedValue, + css::uno::Any & rOldValue, + sal_Int32 nHandle, + const css::uno::Any& rValue ) override; + virtual void SAL_CALL setFastPropertyValue_NoBroadcast( + sal_Int32 nHandle, + const css::uno::Any& rValue + ) override; + virtual void SAL_CALL getFastPropertyValue( + css::uno::Any& rValue, + sal_Int32 nHandle + ) const override; + virtual ~OStatement_Base() override; + + public: + OStatement_Base(OConnection* _pConnection ); + using OStatement_BASE::operator css::uno::Reference< css::uno::XInterface >; + + oslGenericFunction getOdbcFunction(ODBC3SQLFunctionId _nIndex) const + { + return m_pConnection->getOdbcFunction(_nIndex); + } + // OComponentHelper + virtual void SAL_CALL disposing() override; + // XInterface + virtual void SAL_CALL release() noexcept override; + virtual void SAL_CALL acquire() noexcept override; + // XInterface + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + + // XPropertySet + virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; + // XStatement + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL executeQuery( const OUString& sql ) override ; + virtual sal_Int32 SAL_CALL executeUpdate( const OUString& sql ) override ; + virtual sal_Bool SAL_CALL execute( const OUString& sql ) override ; + virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( ) override ; + // XWarningsSupplier + virtual css::uno::Any SAL_CALL getWarnings( ) override; + virtual void SAL_CALL clearWarnings( ) override; + // XCancellable + virtual void SAL_CALL cancel( ) override; + // XCloseable + virtual void SAL_CALL close( ) override; + // XMultipleResults + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getResultSet( ) override; + virtual sal_Int32 SAL_CALL getUpdateCount( ) override; + virtual sal_Bool SAL_CALL getMoreResults( ) override; + //XGeneratedResultSet + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getGeneratedValues( ) override; + + // other methods + SQLHANDLE getConnectionHandle() { return m_pConnection->getConnection(); } + OConnection* getOwnConnection() const { return m_pConnection.get();} + /** getCursorProperties return the properties for a specific cursor type + @param _nCursorType the CursorType + @param bFirst when true the first property set is returned + + @return the cursor properties + */ + SQLUINTEGER getCursorProperties(SQLINTEGER _nCursorType, bool bFirst); + + protected: + using OPropertySetHelper::getFastPropertyValue; + }; + + class OOO_DLLPUBLIC_ODBCBASE OStatement_BASE2 : public OStatement_Base + { + public: + OStatement_BASE2(OConnection* _pConnection ) : + OStatement_Base(_pConnection ) + {} + // OComponentHelper + virtual void SAL_CALL disposing() override; + }; + + class OOO_DLLPUBLIC_ODBCBASE OStatement : + public OStatement_BASE2, + public css::sdbc::XBatchExecution, + public css::lang::XServiceInfo + { + protected: + virtual ~OStatement() override {} + public: + // A ctor that is needed for returning the object + OStatement( OConnection* _pConnection) : OStatement_BASE2( _pConnection){} + DECLARE_SERVICE_INFO(); + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + // XBatchExecution + virtual void SAL_CALL addBatch( const OUString& sql ) override; + virtual void SAL_CALL clearBatch( ) override; + virtual css::uno::Sequence< sal_Int32 > SAL_CALL executeBatch( ) override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/OTools.hxx b/connectivity/source/inc/odbc/OTools.hxx new file mode 100644 index 0000000000..b03db91dce --- /dev/null +++ b/connectivity/source/inc/odbc/OTools.hxx @@ -0,0 +1,245 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include <connectivity/odbc.hxx> +#include <odbc/odbcbasedllapi.hxx> +#include <com/sun/star/sdbc/SQLException.hpp> +#include <com/sun/star/util/Date.hpp> +#include <com/sun/star/util/Time.hpp> +#include <com/sun/star/util/DateTime.hpp> +#include <osl/thread.h> +#include <rtl/ustring.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <rtl/textenc.h> + +enum class ODBC3SQLFunctionId +{ + AllocHandle = 1, + Connect = 2, + DriverConnect = 3, + BrowseConnect = 4, + DataSources = 5, + Drivers = 6, + GetInfo = 7, + GetFunctions = 8, + GetTypeInfo = 9, + SetConnectAttr = 10, + GetConnectAttr = 11, + SetEnvAttr = 12, + GetEnvAttr = 13, + SetStmtAttr = 14, + GetStmtAttr = 15, + Prepare = 16, + BindParameter = 17, + SetCursorName = 18, + Execute = 19, + ExecDirect = 20, + DescribeParam = 21, + NumParams = 22, + ParamData = 23, + PutData = 24, + RowCount = 25, + NumResultCols = 26, + DescribeCol = 27, + ColAttribute = 28, + BindCol = 29, + Fetch = 30, + FetchScroll = 31, + GetData = 32, + SetPos = 33, + BulkOperations = 34, + MoreResults = 35, + GetDiagRec = 36, + ColumnPrivileges = 37, + Columns = 38, + ForeignKeys = 39, + PrimaryKeys = 40, + ProcedureColumns = 41, + Procedures = 42, + SpecialColumns = 43, + Statistics = 44, + TablePrivileges = 45, + Tables = 46, + FreeStmt = 47, + CloseCursor = 48, + Cancel = 49, + EndTran = 50, + Disconnect = 51, + FreeHandle = 52, + GetCursorName = 53, + NativeSql = 54, +}; + +namespace connectivity::odbc + { + class OConnection; + + const sal_Int32 MAX_PUT_DATA_LENGTH = 2000; + + class OOO_DLLPUBLIC_ODBCBASE OTools + { + public: + /// @throws css::sdbc::SQLException + static void ThrowException( const OConnection* _pConnection, + SQLRETURN _rRetCode, + SQLHANDLE _pContext, + SQLSMALLINT _nHandleType, + const css::uno::Reference< css::uno::XInterface >& _xInterface, + bool _bNoFound=true); + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + static void GetInfo(OConnection const * _pConnection, + SQLHANDLE _aConnectionHandle, + SQLUSMALLINT _nInfo, + OUString &_rValue, + const css::uno::Reference< css::uno::XInterface >& _xInterface, + rtl_TextEncoding _nTextEncoding); + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + static void GetInfo(OConnection const * _pConnection, + SQLHANDLE _aConnectionHandle, + SQLUSMALLINT _nInfo, + sal_Int32 &_rValue, + const css::uno::Reference< css::uno::XInterface >& _xInterface); + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + static void GetInfo(OConnection const * _pConnection, + SQLHANDLE _aConnectionHandle, + SQLUSMALLINT _nInfo, + SQLUSMALLINT &_rValue, + const css::uno::Reference< css::uno::XInterface >& _xInterface); + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + static void GetInfo(OConnection const * _pConnection, + SQLHANDLE _aConnectionHandle, + SQLUSMALLINT _nInfo, + SQLUINTEGER &_rValue, + const css::uno::Reference< css::uno::XInterface >& _xInterface); + + static sal_Int32 MapOdbcType2Jdbc(SQLSMALLINT _nType); + static SQLSMALLINT jdbcTypeToOdbc(sal_Int32 jdbcType); + + static DATE_STRUCT DateToOdbcDate(const css::util::Date& x) + { + DATE_STRUCT aVal; + aVal.year = x.Year; + aVal.month = x.Month; + aVal.day = x.Day; + return aVal; + } + static TIME_STRUCT TimeToOdbcTime(const css::util::Time& x) + { + TIME_STRUCT aVal; + aVal.hour = x.Hours; + aVal.minute = x.Minutes; + aVal.second = x.Seconds; + return aVal; + } + static TIMESTAMP_STRUCT DateTimeToTimestamp(const css::util::DateTime& x) + { + TIMESTAMP_STRUCT aVal; + aVal.year = x.Year; + aVal.month = x.Month; + aVal.day = x.Day; + aVal.hour = x.Hours; + aVal.minute = x.Minutes; + aVal.second = x.Seconds; + aVal.fraction = x.NanoSeconds; + return aVal; + } + /** + getBindTypes set the ODBC type for C + @param _bUseWChar true when Unicode should be used + @param _bUseOldTimeDate true when the old datetime format should be used + @param _nOdbcType the ODBC sql type + @param fCType the C type for the ODBC type + @param fSqlType the SQL type for the ODBC type + */ + static void getBindTypes(bool _bUseWChar, + bool _bUseOldTimeDate, + SQLSMALLINT _nOdbcType, + SQLSMALLINT& fCType, + SQLSMALLINT& fSqlType); + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + static OUString getStringValue( OConnection const * _pConnection, + SQLHANDLE _aStatementHandle, + sal_Int32 columnIndex, + SQLSMALLINT _fSqlType, + bool &_bWasNull, + const css::uno::Reference< css::uno::XInterface >& _xInterface, + rtl_TextEncoding _nTextEncoding); + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + static css::uno::Sequence<sal_Int8> getBytesValue(const OConnection* _pConnection, + SQLHANDLE _aStatementHandle, + sal_Int32 columnIndex, + SQLSMALLINT _fSqlType, + bool &_bWasNull, + const css::uno::Reference< css::uno::XInterface >& _xInterface); + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + static void getValue( OConnection const * _pConnection, + SQLHANDLE _aStatementHandle, + sal_Int32 columnIndex, + SQLSMALLINT _nType, + bool &_bWasNull, + const css::uno::Reference< css::uno::XInterface >& _xInterface, + void* _pValue, + SQLLEN _nSize); + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + static void bindValue( OConnection const * _pConnection, + SQLHANDLE _aStatementHandle, + sal_Int32 columnIndex, + SQLSMALLINT _nType, + SQLSMALLINT _nMaxLen, + const void* _pValue, + void* _pData, + SQLLEN *pLen, + const css::uno::Reference< css::uno::XInterface >& _xInterface, + rtl_TextEncoding _nTextEncoding, + bool _bUseOldTimeDate); + }; + + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + template <class T> void getValue( const OConnection* _pConnection, + SQLHANDLE _aStatementHandle, + sal_Int32 columnIndex, + SQLSMALLINT _nType, + bool &_bWasNull, + const css::uno::Reference< css::uno::XInterface >& _xInterface, + T& _rValue) + { + OTools::getValue(_pConnection,_aStatementHandle,columnIndex,_nType,_bWasNull,_xInterface,&_rValue,sizeof _rValue); + } + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/odbcbasedllapi.hxx b/connectivity/source/inc/odbc/odbcbasedllapi.hxx new file mode 100644 index 0000000000..bf7f5a486d --- /dev/null +++ b/connectivity/source/inc/odbc/odbcbasedllapi.hxx @@ -0,0 +1,32 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sal/config.h> + +#include <sal/types.h> + +#if defined OOO_DLLIMPLEMENTATION_ODBCBASE +#define OOO_DLLPUBLIC_ODBCBASE SAL_DLLPUBLIC_EXPORT +#else +#define OOO_DLLPUBLIC_ODBCBASE SAL_DLLPUBLIC_IMPORT +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/propertyids.hxx b/connectivity/source/inc/propertyids.hxx new file mode 100644 index 0000000000..1a9e3720f9 --- /dev/null +++ b/connectivity/source/inc/propertyids.hxx @@ -0,0 +1,109 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +// this define has to be set to split the names into different dll's or so's +// every dll has his own set of property names +#include <rtl/ustring.hxx> +#include <map> +#include <connectivity/dbtoolsdllapi.hxx> + +namespace dbtools +{ + class OOO_DLLPUBLIC_DBTOOLS OPropertyMap + { + std::map<sal_Int32, OUString> m_aPropertyMap; + public: + OPropertyMap(); + const OUString& getNameByIndex(sal_Int32 _nIndex) const; + }; +} + +#define PROPERTY_ID_QUERYTIMEOUT 1 +#define PROPERTY_ID_MAXFIELDSIZE 2 +#define PROPERTY_ID_MAXROWS 3 +#define PROPERTY_ID_CURSORNAME 4 +#define PROPERTY_ID_RESULTSETCONCURRENCY 5 +#define PROPERTY_ID_RESULTSETTYPE 6 +#define PROPERTY_ID_FETCHDIRECTION 7 +#define PROPERTY_ID_FETCHSIZE 8 +#define PROPERTY_ID_ESCAPEPROCESSING 9 +#define PROPERTY_ID_USEBOOKMARKS 10 +// Column +#define PROPERTY_ID_NAME 11 +#define PROPERTY_ID_TYPE 12 +#define PROPERTY_ID_TYPENAME 13 +#define PROPERTY_ID_PRECISION 14 +#define PROPERTY_ID_SCALE 15 +#define PROPERTY_ID_ISNULLABLE 16 +#define PROPERTY_ID_ISAUTOINCREMENT 17 +#define PROPERTY_ID_ISROWVERSION 18 +#define PROPERTY_ID_DESCRIPTION 19 +#define PROPERTY_ID_DEFAULTVALUE 20 + +#define PROPERTY_ID_REFERENCEDTABLE 21 +#define PROPERTY_ID_UPDATERULE 22 +#define PROPERTY_ID_DELETERULE 23 +#define PROPERTY_ID_CATALOG 24 +#define PROPERTY_ID_ISUNIQUE 25 +#define PROPERTY_ID_ISPRIMARYKEYINDEX 26 +#define PROPERTY_ID_ISCLUSTERED 27 +#define PROPERTY_ID_ISASCENDING 28 +#define PROPERTY_ID_SCHEMANAME 29 +#define PROPERTY_ID_CATALOGNAME 30 + +#define PROPERTY_ID_COMMAND 31 +#define PROPERTY_ID_CHECKOPTION 32 +#define PROPERTY_ID_PASSWORD 33 +#define PROPERTY_ID_RELATEDCOLUMN 34 + +#define PROPERTY_ID_FUNCTION 35 +#define PROPERTY_ID_TABLENAME 36 +#define PROPERTY_ID_REALNAME 37 +#define PROPERTY_ID_DBASEPRECISIONCHANGED 38 +#define PROPERTY_ID_ISCURRENCY 39 +#define PROPERTY_ID_ISBOOKMARKABLE 40 + +#define PROPERTY_ID_INVALID_INDEX 41 +#define PROPERTY_ID_HY010 43 +#define PROPERTY_ID_LABEL 44 +#define PROPERTY_ID_DELIMITER 45 +#define PROPERTY_ID_FORMATKEY 46 +#define PROPERTY_ID_LOCALE 47 +#define PROPERTY_ID_IM001 48 + +#define PROPERTY_ID_AUTOINCREMENTCREATION 49 + +#define PROPERTY_ID_PRIVILEGES 50 +#define PROPERTY_ID_HAVINGCLAUSE 51 + +#define PROPERTY_ID_ISSIGNED 52 +#define PROPERTY_ID_AGGREGATEFUNCTION 53 +#define PROPERTY_ID_ISSEARCHABLE 54 + +#define PROPERTY_ID_APPLYFILTER 55 +#define PROPERTY_ID_FILTER 56 +#define PROPERTY_ID_MASTERFIELDS 57 +#define PROPERTY_ID_DETAILFIELDS 58 +#define PROPERTY_ID_FIELDTYPE 59 +#define PROPERTY_ID_VALUE 60 +#define PROPERTY_ID_ACTIVE_CONNECTION 61 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/resource/sharedresources.hxx b/connectivity/source/inc/resource/sharedresources.hxx new file mode 100644 index 0000000000..0c439cdf24 --- /dev/null +++ b/connectivity/source/inc/resource/sharedresources.hxx @@ -0,0 +1,149 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <rtl/ustring.hxx> +#include <vector> +#include <connectivity/dbtoolsdllapi.hxx> +#include <unotools/resmgr.hxx> + +namespace connectivity +{ + + + typedef sal_uInt16 ResourceId; + + /** helper class for accessing resources shared by different libraries + in the connectivity module + */ + class OOO_DLLPUBLIC_DBTOOLS SharedResources + { + public: + SharedResources(); + ~SharedResources(); + + /** loads a string from the shared resource file + @param pResId + the resource ID of the string + @return + the string from the resource file + */ + OUString + getResourceString( + TranslateId pResId + ) const; + + /** loads a string from the shared resource file, and replaces + a given ASCII pattern with a given string + + @param pResId + the resource ID of the string to load + @param _pAsciiPatternToReplace + the ASCII string which is to search in the string. Must not be <NULL/>. + @param _rStringToSubstitute + the String which should substitute the ASCII pattern. + + @return + the string from the resource file, with applied string substitution + */ + OUString + getResourceStringWithSubstitution( + TranslateId pResId, + const char* _pAsciiPatternToReplace, + const OUString& _rStringToSubstitute + ) const; + + /** loads a string from the shared resource file, and replaces + a given ASCII pattern with a given string + + @param pResId + the resource ID of the string to load + @param _pAsciiPatternToReplace1 + the ASCII string (1) which is to search in the string. Must not be <NULL/>. + @param _rStringToSubstitute1 + the String which should substitute the ASCII pattern (1) + @param _pAsciiPatternToReplace2 + the ASCII string (2) which is to search in the string. Must not be <NULL/>. + @param _rStringToSubstitute2 + the String which should substitute the ASCII pattern (2) + + @return + the string from the resource file, with applied string substitution + */ + OUString + getResourceStringWithSubstitution( + TranslateId pResId, + const char* _pAsciiPatternToReplace1, + const OUString& _rStringToSubstitute1, + const char* _pAsciiPatternToReplace2, + const OUString& _rStringToSubstitute2 + ) const; + + /** loads a string from the shared resource file, and replaces + a given ASCII pattern with a given string + + @param pResId + the resource ID of the string to load + @param _pAsciiPatternToReplace1 + the ASCII string (1) which is to search in the string. Must not be <NULL/>. + @param _rStringToSubstitute1 + the String which should substitute the ASCII pattern (1) + @param _pAsciiPatternToReplace2 + the ASCII string (2) which is to search in the string. Must not be <NULL/>. + @param _rStringToSubstitute2 + the String which should substitute the ASCII pattern (2) + @param _pAsciiPatternToReplace3 + the ASCII string (3) which is to search in the string. Must not be <NULL/>. + @param _rStringToSubstitute3 + the String which should substitute the ASCII pattern (3) + + @return + the string from the resource file, with applied string substitution + */ + OUString + getResourceStringWithSubstitution( + TranslateId pResId, + const char* _pAsciiPatternToReplace1, + const OUString& _rStringToSubstitute1, + const char* _pAsciiPatternToReplace2, + const OUString& _rStringToSubstitute2, + const char* _pAsciiPatternToReplace3, + const OUString& _rStringToSubstitute3 + ) const; + + /** loads a string from the shared resource file, and replaces a given ASCII pattern with a given string + + @param pResId + the resource ID of the string to load + @param _aStringToSubstitutes + A list of substitutions. + + @return + the string from the resource file, with applied string substitution + */ + OUString getResourceStringWithSubstitution( TranslateId pResId, + const std::vector< std::pair<const char* , OUString > >& _rStringToSubstitutes) const; + }; + + +} // namespace connectivity + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/writer/WCatalog.hxx b/connectivity/source/inc/writer/WCatalog.hxx new file mode 100644 index 0000000000..be61dbabd1 --- /dev/null +++ b/connectivity/source/inc/writer/WCatalog.hxx @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FCatalog.hxx> + +namespace connectivity::writer +{ +class OWriterConnection; +class OWriterCatalog : public file::OFileCatalog +{ +public: + void refreshTables() override; + + OWriterCatalog(OWriterConnection* pConnection); +}; + +} // namespace connectivity::writer + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/writer/WConnection.hxx b/connectivity/source/inc/writer/WConnection.hxx new file mode 100644 index 0000000000..5ae8b2818e --- /dev/null +++ b/connectivity/source/inc/writer/WConnection.hxx @@ -0,0 +1,154 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <memory> +#include <file/FConnection.hxx> +#include <com/sun/star/frame/XDesktop2.hpp> +#include <com/sun/star/frame/XTerminateListener.hpp> +#include <rtl/ref.hxx> +#include <unotools/closeveto.hxx> + +namespace com::sun::star::text +{ +class XTextDocument; +} +namespace utl +{ +class CloseVeto; +} + +namespace connectivity::writer +{ +class ODriver; +class OWriterConnection : public file::OConnection +{ + // the text document: + css::uno::Reference<css::text::XTextDocument> m_xDoc; + OUString m_sPassword; + OUString m_aFileName; + oslInterlockedCount m_nDocCount = 0; + + class CloseVetoButTerminateListener + : public cppu::WeakComponentImplHelper<css::frame::XTerminateListener> + { + private: + /// close listener that vetoes so nobody else disposes m_xDoc + std::unique_ptr<utl::CloseVeto> m_pCloseListener; + /// but also listen to XDesktop and if app is terminating anyway, dispose m_xDoc while + /// its still possible to do so properly + css::uno::Reference<css::frame::XDesktop2> m_xDesktop; + osl::Mutex m_aMutex; + + public: + CloseVetoButTerminateListener() + : cppu::WeakComponentImplHelper<css::frame::XTerminateListener>(m_aMutex) + { + } + + void start(const css::uno::Reference<css::uno::XInterface>& rCloseable, + const css::uno::Reference<css::frame::XDesktop2>& rDesktop) + { + m_xDesktop = rDesktop; + m_xDesktop->addTerminateListener(this); + m_pCloseListener = std::make_unique<utl::CloseVeto>(rCloseable, true); + } + + void stop() + { + m_pCloseListener.reset(); + if (!m_xDesktop.is()) + return; + m_xDesktop->removeTerminateListener(this); + m_xDesktop.clear(); + } + + // XTerminateListener + void SAL_CALL queryTermination(const css::lang::EventObject& /*rEvent*/) override {} + + void SAL_CALL notifyTermination(const css::lang::EventObject& /*rEvent*/) override + { + stop(); + } + + void SAL_CALL disposing() override + { + stop(); + cppu::WeakComponentImplHelperBase::disposing(); + } + + void SAL_CALL disposing(const css::lang::EventObject& rEvent) override + { + const bool bShutDown = (rEvent.Source == m_xDesktop); + if (bShutDown) + stop(); + } + }; + + rtl::Reference<CloseVetoButTerminateListener> m_xCloseVetoButTerminateListener; + +public: + OWriterConnection(ODriver* _pDriver); + ~OWriterConnection() override; + + void construct(const OUString& rURL, + const css::uno::Sequence<css::beans::PropertyValue>& rInfo) override; + + // XServiceInfo + DECLARE_SERVICE_INFO(); + + // OComponentHelper + void SAL_CALL disposing() override; + + // XConnection + css::uno::Reference<css::sdbc::XDatabaseMetaData> SAL_CALL getMetaData() override; + css::uno::Reference<css::sdbcx::XTablesSupplier> createCatalog() override; + css::uno::Reference<css::sdbc::XStatement> SAL_CALL createStatement() override; + css::uno::Reference<css::sdbc::XPreparedStatement> + SAL_CALL prepareStatement(const OUString& sql) override; + css::uno::Reference<css::sdbc::XPreparedStatement> + SAL_CALL prepareCall(const OUString& sql) override; + + // no interface methods + css::uno::Reference<css::text::XTextDocument> const& acquireDoc(); + void releaseDoc(); + + class ODocHolder + { + OWriterConnection* m_pConnection; + css::uno::Reference<css::text::XTextDocument> m_xDoc; + + public: + ODocHolder(OWriterConnection* _pConnection) + : m_pConnection(_pConnection) + { + m_xDoc = m_pConnection->acquireDoc(); + } + ~ODocHolder() + { + m_xDoc.clear(); + m_pConnection->releaseDoc(); + } + const css::uno::Reference<css::text::XTextDocument>& getDoc() const { return m_xDoc; } + }; +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/writer/WDatabaseMetaData.hxx b/connectivity/source/inc/writer/WDatabaseMetaData.hxx new file mode 100644 index 0000000000..b464be11c4 --- /dev/null +++ b/connectivity/source/inc/writer/WDatabaseMetaData.hxx @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <component/CDatabaseMetaData.hxx> + +namespace connectivity::writer +{ +class OWriterDatabaseMetaData : public component::OComponentDatabaseMetaData +{ + OUString SAL_CALL getURL() override; + css::uno::Reference<css::sdbc::XResultSet> + SAL_CALL getTables(const css::uno::Any& catalog, const OUString& schemaPattern, + const OUString& tableNamePattern, + const css::uno::Sequence<OUString>& types) override; + +protected: + ~OWriterDatabaseMetaData() override; + +public: + OWriterDatabaseMetaData(file::OConnection* pConnection); +}; + +} // namespace connectivity::writer + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/writer/WDriver.hxx b/connectivity/source/inc/writer/WDriver.hxx new file mode 100644 index 0000000000..b43168eac9 --- /dev/null +++ b/connectivity/source/inc/writer/WDriver.hxx @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FDriver.hxx> + +namespace com::sun::star::lang +{ +class XMultiServiceFactory; +} + +namespace connectivity::writer +{ +class ODriver : public file::OFileDriver +{ +public: + ODriver(const css::uno::Reference<css::uno::XComponentContext>& _rxContext) + : file::OFileDriver(_rxContext) + { + } + + /// @throws css::uno::RuntimeException + OUString SAL_CALL getImplementationName() override; + + // XDriver + css::uno::Reference<css::sdbc::XConnection> + SAL_CALL connect(const OUString& url, + const css::uno::Sequence<css::beans::PropertyValue>& info) override; + sal_Bool SAL_CALL acceptsURL(const OUString& url) override; + css::uno::Sequence<css::sdbc::DriverPropertyInfo> SAL_CALL getPropertyInfo( + const OUString& url, const css::uno::Sequence<css::beans::PropertyValue>& info) override; +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/writer/WTable.hxx b/connectivity/source/inc/writer/WTable.hxx new file mode 100644 index 0000000000..46ee5412e0 --- /dev/null +++ b/connectivity/source/inc/writer/WTable.hxx @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <component/CTable.hxx> + +namespace com::sun::star::text +{ +class XTextTable; +} +namespace com::sun::star::util +{ +class XNumberFormats; +} + +namespace connectivity::writer +{ +using OWriterTable_BASE = component::OComponentTable; +class OWriterConnection; + +class OWriterTable : public OWriterTable_BASE +{ +private: + css::uno::Reference<css::text::XTextTable> m_xTable; + OWriterConnection* m_pWriterConnection; + sal_Int32 m_nStartCol = 0; + sal_Int32 m_nDataCols = 0; + bool m_bHasHeaders = false; + + void fillColumns(); + +public: + OWriterTable(sdbcx::OCollection* _pTables, OWriterConnection* _pConnection, + const OUString& Name, const OUString& Type); + + bool fetchRow(OValueRefRow& _rRow, const OSQLColumns& _rCols, bool bRetrieveData) override; + + void SAL_CALL disposing() override; + + void construct() override; +}; + +} // namespace connectivity::writer + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/writer/WTables.hxx b/connectivity/source/inc/writer/WTables.hxx new file mode 100644 index 0000000000..df39cc1c22 --- /dev/null +++ b/connectivity/source/inc/writer/WTables.hxx @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <file/FTables.hxx> + +namespace connectivity::writer +{ +using OWriterTables_BASE = file::OTables; + +class OWriterTables : public OWriterTables_BASE +{ +protected: + sdbcx::ObjectType createObject(const OUString& rName) override; + +public: + OWriterTables(const css::uno::Reference<css::sdbc::XDatabaseMetaData>& _rMetaData, + ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, + const ::std::vector<OUString>& _rVector) + : OWriterTables_BASE(_rMetaData, _rParent, _rMutex, _rVector) + { + } +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |