diff options
Diffstat (limited to 'connectivity/source/inc/file')
19 files changed, 2789 insertions, 0 deletions
diff --git a/connectivity/source/inc/file/FCatalog.hxx b/connectivity/source/inc/file/FCatalog.hxx new file mode 100644 index 000000000..2bcf82df2 --- /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 000000000..f5fce16b6 --- /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 000000000..e6412992a --- /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 000000000..5c766c31d --- /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 000000000..e8eb12d0c --- /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 000000000..9d289d618 --- /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(const css::uno::Reference< css::uno::XComponentContext >& _rxContext); + + // 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 000000000..765f2cde8 --- /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 000000000..f83d74a6d --- /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 000000000..62a52fe2b --- /dev/null +++ b/connectivity/source/inc/file/FResultSet.hxx @@ -0,0 +1,305 @@ +/* -*- 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, + css::lang::XUnoTunnel> 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; + // css::lang::XUnoTunnel + virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; + static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId(); + //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 000000000..65fc0bb3c --- /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(const ::rtl::Reference<connectivity::OSQLColumns>& _rxColumns,const 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 000000000..57ce0a2fc --- /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 000000000..b3d72294f --- /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 000000000..4f925f799 --- /dev/null +++ b/connectivity/source/inc/file/FTable.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 <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(); } + // css::lang::XUnoTunnel + virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; + static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId(); + + + 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 000000000..9d14c3627 --- /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 000000000..f913529d2 --- /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 000000000..c78461743 --- /dev/null +++ b/connectivity/source/inc/file/fcode.hxx @@ -0,0 +1,330 @@ +/* -*- 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> + +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(const ORowSetValue& _rVar, sal_Int32 eDbType) + : OOperand(eDbType) + , m_aValue(_rVar) + {} + + 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 000000000..ebdb0679e --- /dev/null +++ b/connectivity/source/inc/file/fcomp.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 <file/fcode.hxx> + +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(const ::rtl::Reference<OPredicateCompiler>& rComp) : m_rCompiler(rComp){} + 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 000000000..e32f5f17c --- /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 000000000..7c6becc37 --- /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: */ |