diff options
Diffstat (limited to 'connectivity/source/drivers/postgresql')
65 files changed, 601 insertions, 702 deletions
diff --git a/connectivity/source/drivers/postgresql/pq_array.cxx b/connectivity/source/drivers/postgresql/pq_array.cxx index 5ae646f230e3..841ed70c6cb2 100644 --- a/connectivity/source/drivers/postgresql/pq_array.cxx +++ b/connectivity/source/drivers/postgresql/pq_array.cxx @@ -100,7 +100,7 @@ css::uno::Reference< css::sdbc::XResultSet > Array::getResultSetAtIndex( } return new SequenceResultSet( - m_xMutex, m_owner, getStatics().resultSetArrayColumnNames, ret, m_tc ); + m_xMutex, m_owner, std::vector(getStatics().resultSetArrayColumnNames), std::move(ret), m_tc ); } diff --git a/connectivity/source/drivers/postgresql/pq_array.hxx b/connectivity/source/drivers/postgresql/pq_array.hxx index c0ed6aa97efd..589fe063d234 100644 --- a/connectivity/source/drivers/postgresql/pq_array.hxx +++ b/connectivity/source/drivers/postgresql/pq_array.hxx @@ -34,12 +34,12 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_ARRAY_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_ARRAY_HXX +#pragma once #include <cppuhelper/implbase.hxx> #include <com/sun/star/sdbc/XArray.hpp> #include "pq_connection.hxx" +#include <utility> #include <vector> namespace pq_sdbc_driver @@ -54,14 +54,14 @@ class Array : public cppu::WeakImplHelper< css::sdbc::XArray > public: Array( - const rtl::Reference< comphelper::RefCountedMutex > & mutex, - const std::vector< css::uno::Any > & data, - const css::uno::Reference< css::uno::XInterface > & owner, - const css::uno::Reference< css::script::XTypeConverter > &tc) : - m_data( data ), - m_owner( owner ), - m_tc( tc ), - m_xMutex( mutex ) + rtl::Reference< comphelper::RefCountedMutex > mutex, + std::vector< css::uno::Any > && data, + css::uno::Reference< css::uno::XInterface > owner, + css::uno::Reference< css::script::XTypeConverter > tc) : + m_data( std::move(data) ), + m_owner(std::move( owner )), + m_tc(std::move( tc )), + m_xMutex(std::move( mutex )) {} public: // XArray @@ -95,6 +95,4 @@ private: }; -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_baseresultset.hxx b/connectivity/source/drivers/postgresql/pq_baseresultset.hxx index 8b062ddf9ac0..90e6609a0860 100644 --- a/connectivity/source/drivers/postgresql/pq_baseresultset.hxx +++ b/connectivity/source/drivers/postgresql/pq_baseresultset.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_BASERESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_BASERESULTSET_HXX +#pragma once #include <cppuhelper/propshlp.hxx> #include <cppuhelper/component.hxx> @@ -104,8 +103,8 @@ protected: virtual ~BaseResultSet() override; public: // XInterface - virtual void SAL_CALL acquire() throw() override { BaseResultSet_BASE::acquire(); } - virtual void SAL_CALL release() throw() override { BaseResultSet_BASE::release(); } + virtual void SAL_CALL acquire() noexcept override { BaseResultSet_BASE::acquire(); } + virtual void SAL_CALL release() noexcept override { BaseResultSet_BASE::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -200,6 +199,5 @@ public: // OComponentHelper }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_connection.cxx b/connectivity/source/drivers/postgresql/pq_connection.cxx index 2bc1e4a42af8..091479f87f95 100644 --- a/connectivity/source/drivers/postgresql/pq_connection.cxx +++ b/connectivity/source/drivers/postgresql/pq_connection.cxx @@ -34,6 +34,7 @@ * ************************************************************************/ +#include <utility> #include <vector> #include <string.h> @@ -48,6 +49,7 @@ #include "pq_xviews.hxx" #include "pq_xusers.hxx" +#include <rtl/ref.hxx> #include <rtl/uuid.h> #include <sal/log.hxx> @@ -95,8 +97,8 @@ class ClosableReference : public cppu::WeakImplHelper< css::uno::XReference > rtl::Reference<Connection> m_conn; ::rtl::ByteSequence m_id; public: - ClosableReference( const ::rtl::ByteSequence & id , Connection *that ) - : m_conn( that ), m_id( id ) + ClosableReference( ::rtl::ByteSequence id , Connection *that ) + : m_conn( that ), m_id(std::move( id )) { } @@ -114,9 +116,9 @@ public: Connection::Connection( const rtl::Reference< comphelper::RefCountedMutex > &refMutex, - const css::uno::Reference< css::uno::XComponentContext > & ctx ) + css::uno::Reference< css::uno::XComponentContext > ctx ) : ConnectionBase( refMutex->GetMutex() ), - m_ctx( ctx ) , + m_ctx(std::move( ctx )) , m_xMutex( refMutex ) { } @@ -186,13 +188,12 @@ Reference< XStatement > Connection::createStatement() MutexGuard guard( m_xMutex->GetMutex() ); checkClosed(); - Statement *stmt = new Statement( m_xMutex, this , &m_settings ); - Reference< XStatement > ret( stmt ); + rtl::Reference<Statement> stmt = new Statement( m_xMutex, this , &m_settings ); ::rtl::ByteSequence id( 16 ); rtl_createUuid( reinterpret_cast<sal_uInt8*>(id.getArray()), nullptr, false ); m_myStatements[ id ] = Reference< XCloseable > ( stmt ); stmt->queryAdapter()->addReference( new ClosableReference( id, this ) ); - return ret; + return stmt; } Reference< XPreparedStatement > Connection::prepareStatement( const OUString& sql ) @@ -201,14 +202,14 @@ Reference< XPreparedStatement > Connection::prepareStatement( const OUString& sq checkClosed(); OString byteSql = OUStringToOString( sql, ConnectionSettings::encoding ); - PreparedStatement *stmt = new PreparedStatement( m_xMutex, this, &m_settings, byteSql ); - Reference< XPreparedStatement > ret = stmt; + rtl::Reference<PreparedStatement> stmt + = new PreparedStatement( m_xMutex, this, &m_settings, byteSql ); ::rtl::ByteSequence id( 16 ); rtl_createUuid( reinterpret_cast<sal_uInt8*>(id.getArray()), nullptr, false ); m_myStatements[ id ] = Reference< XCloseable > ( stmt ); stmt->queryAdapter()->addReference( new ClosableReference( id, this ) ); - return ret; + return stmt; } Reference< XPreparedStatement > Connection::prepareCall( const OUString& ) @@ -330,7 +331,15 @@ class cstr_vector std::vector<char*> values; std::vector<bool> acquired; public: - cstr_vector () : values(), acquired() { values.reserve(8); acquired.reserve(8); } +#if defined __GNUC__ && !defined __clang__ && __GNUC__ == 14 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" +#pragma GCC diagnostic ignored "-Wstringop-overflow" +#endif + cstr_vector () { values.reserve(8); acquired.reserve(8); } +#if defined __GNUC__ && !defined __clang__ && __GNUC__ == 14 +#pragma GCC diagnostic pop +#endif ~cstr_vector () { OSL_ENSURE(values.size() == acquired.size(), "pq_connection: cstr_vector values and acquired size mismatch"); diff --git a/connectivity/source/drivers/postgresql/pq_connection.hxx b/connectivity/source/drivers/postgresql/pq_connection.hxx index f8d19c406b18..2bba070a7273 100644 --- a/connectivity/source/drivers/postgresql/pq_connection.hxx +++ b/connectivity/source/drivers/postgresql/pq_connection.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_CONNECTION_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_CONNECTION_HXX +#pragma once #include <config_lgpl.h> #include <com/sun/star/uno/XComponentContext.hpp> @@ -61,19 +60,18 @@ #include <libpq-fe.h> #include <unordered_map> +#include "pq_xtables.hxx" +#include "pq_xviews.hxx" + namespace pq_sdbc_driver { struct ConnectionSettings; -class Tables; -class Views; struct ConnectionSettings { ConnectionSettings() : pConnection(nullptr), maxNameLen(0), - maxIndexKeys(0), - pTablesImpl(nullptr), - pViewsImpl(nullptr) + maxIndexKeys(0) {} static const rtl_TextEncoding encoding = RTL_TEXTENCODING_UTF8; PGconn *pConnection; @@ -83,8 +81,8 @@ struct ConnectionSettings css::uno::Reference< css::container::XNameAccess > tables; css::uno::Reference< css::container::XNameAccess > users; css::uno::Reference< css::container::XNameAccess > views; - Tables *pTablesImpl; // needed to implement renaming of tables / views - Views *pViewsImpl; // needed to implement renaming of tables / views + rtl::Reference<Tables> pTablesImpl; // needed to implement renaming of tables / views + rtl::Reference<Views> pViewsImpl; // needed to implement renaming of tables / views OUString user; OUString catalog; }; @@ -136,7 +134,7 @@ private: public: Connection( const rtl::Reference< comphelper::RefCountedMutex > &refMutex, - const css::uno::Reference< css::uno::XComponentContext > & ctx ); + css::uno::Reference< css::uno::XComponentContext > ctx ); virtual ~Connection( ) override; @@ -192,6 +190,5 @@ public: // helper function }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_databasemetadata.cxx b/connectivity/source/drivers/postgresql/pq_databasemetadata.cxx index 07e0e85815c1..1fbcb1aa69f5 100644 --- a/connectivity/source/drivers/postgresql/pq_databasemetadata.cxx +++ b/connectivity/source/drivers/postgresql/pq_databasemetadata.cxx @@ -74,6 +74,7 @@ #include "pq_statics.hxx" #include "pq_tools.hxx" +#include <o3tl/string_view.hxx> #include <rtl/ustrbuf.hxx> #include <sal/macros.h> #include <com/sun/star/sdbc/TransactionIsolation.hpp> @@ -83,6 +84,7 @@ #include <com/sun/star/sdbc/IndexType.hpp> #include <com/sun/star/sdbc/ColumnValue.hpp> #include <com/sun/star/sdbc/ColumnSearch.hpp> +#include <utility> using ::osl::MutexGuard; @@ -113,12 +115,12 @@ namespace pq_sdbc_driver #define DEFERRABILITY_NONE 7 DatabaseMetaData::DatabaseMetaData( - const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, - const css::uno::Reference< css::sdbc::XConnection > & origin, + ::rtl::Reference< comphelper::RefCountedMutex > refMutex, + css::uno::Reference< css::sdbc::XConnection > origin, ConnectionSettings *pSettings ) - : m_xMutex( refMutex ), + : m_xMutex(std::move( refMutex )), m_pSettings( pSettings ), - m_origin( origin ), + m_origin(std::move( origin )), m_getIntSetting_stmt ( m_origin->prepareStatement("SELECT setting FROM pg_catalog.pg_settings WHERE name=?") ) { init_getReferences_stmt(); @@ -209,10 +211,10 @@ sal_Int32 DatabaseMetaData::getDriverMinorVersion( ) sal_Bool DatabaseMetaData::usesLocalFiles( ) { // LEM TODO: - // http://wiki.openoffice.org/wiki/Documentation/DevGuide/Database/XDatabaseMetaData_Interface + // https://wiki.documentfoundation.org/Documentation/DevGuide/Database_Access#XDatabaseMetaData_Interface // says "Returns true when the catalog name of the // database should not appear in the DatasourceBrowser - // of OpenOffice.org API, otherwise false is returned." + // of LibreOffice API, otherwise false is returned." // So, hmmm, think about it. return false; } @@ -309,8 +311,8 @@ OUString DatabaseMetaData::getSQLKeywords( ) } OUString DatabaseMetaData::getNumericFunctions( ) { - // See http://www.postgresql.org/docs/9.1/static/functions-math.html - // LEM TODO: Err... http://wiki.openoffice.org/wiki/Documentation/DevGuide/Database/Support_Scalar_Functions + // See https://www.postgresql.org/docs/9.1/static/functions-math.html + // LEM TODO: Err... https://wiki.documentfoundation.org/Documentation/DevGuide/Database_Access#Support_Scalar_Functions // says this should be "Open Group CLI" names, not PostgreSQL names. // Currently this is just a list of supported functions in PostgreSQL, with PostgreSQL names. // And it is my job to map from Open Group CLI names/syntax to PostgreSQL names/syntax. Where? By parsing the SQL??? @@ -1178,46 +1180,46 @@ css::uno::Reference< XResultSet > DatabaseMetaData::getTables( closeable->close(); return new SequenceResultSet( - m_xMutex, *this, statics.tablesRowNames, vec, m_pSettings->tc ); + m_xMutex, *this, std::vector(statics.tablesRowNames), std::move(vec), m_pSettings->tc ); } namespace { // sort no schema first, then "public", then normal schemas, then internal schemas - int compare_schema(const OUString &nsA, const OUString &nsB) + int compare_schema(std::u16string_view nsA, std::u16string_view nsB) { - if (nsA.isEmpty()) + if (nsA.empty()) { - return nsB.isEmpty() ? 0 : -1; + return nsB.empty() ? 0 : -1; } - else if (nsB.isEmpty()) + else if (nsB.empty()) { - assert(!nsA.isEmpty()); + assert(!nsA.empty()); return 1; } - else if(nsA == "public") + else if(nsA == u"public") { - return (nsB == "public") ? 0 : -1; + return (nsB == u"public") ? 0 : -1; } - else if(nsB == "public") + else if(nsB == u"public") { - assert(nsA != "public"); + assert(nsA != u"public"); return 1; } - else if(nsA.startsWith("pg_")) + else if(o3tl::starts_with(nsA, u"pg_")) { - if(nsB.startsWith("pg_")) - return nsA.compareTo(nsB); + if(o3tl::starts_with(nsB, u"pg_")) + return nsA.compare(nsB); else return 1; } - else if(nsB.startsWith("pg_")) + else if(o3tl::starts_with(nsB, u"pg_")) { return -1; } else { - return nsA.compareTo(nsB); + return nsA.compare(nsB); } } @@ -1229,7 +1231,7 @@ namespace OUString valueB; a[0] >>= valueA; b[0] >>= valueB; - return compare_schema(valueA, valueB); + return compare_schema(valueA, valueB) < 0; } }; } @@ -1251,9 +1253,7 @@ css::uno::Reference< XResultSet > DatabaseMetaData::getSchemas( ) std::vector< std::vector<Any> > vec; while( rs->next() ) { - std::vector<Any> row(1); - row[0] <<= xRow->getString(1); - vec.push_back( row ); + vec.push_back( { Any(xRow->getString(1)) } ); } // sort public first, sort internal schemas last, sort rest in alphabetic order @@ -1263,7 +1263,7 @@ css::uno::Reference< XResultSet > DatabaseMetaData::getSchemas( ) if( closeable.is() ) closeable->close(); return new SequenceResultSet( - m_xMutex, *this, getStatics().schemaNames, vec, m_pSettings->tc ); + m_xMutex, *this, std::vector(getStatics().schemaNames), std::move(vec), m_pSettings->tc ); } css::uno::Reference< XResultSet > DatabaseMetaData::getCatalogs( ) @@ -1280,7 +1280,7 @@ css::uno::Reference< XResultSet > DatabaseMetaData::getTableTypes( ) // LEM TODO: this can be made dynamic, see JDBC driver MutexGuard guard( m_xMutex->GetMutex() ); return new SequenceResultSet( - m_xMutex, *this, getStatics().tableTypeNames, getStatics().tableTypeData, + m_xMutex, *this, std::vector(getStatics().tableTypeNames), std::vector(getStatics().tableTypeData), m_pSettings->tc ); } @@ -1365,9 +1365,9 @@ namespace { { DatabaseTypeDescription() {} - DatabaseTypeDescription( const OUString &name, const OUString & type ) : - typeName( name ), - typeType( type ) + DatabaseTypeDescription( OUString name, OUString type ) : + typeName(std::move( name )), + typeType(std::move( type )) {} DatabaseTypeDescription( const DatabaseTypeDescription &source ) : typeName( source.typeName ), @@ -1406,8 +1406,7 @@ static void columnMetaData2DatabaseTypeDescription( oidMap[row->getInt(12)] = DatabaseTypeDescription(); if( domains ) queryBuf.append( " OR " ); - queryBuf.append( "oid = " ); - queryBuf.append( row->getInt(12 ) ); + queryBuf.append( "oid = " + OUString::number( row->getInt(12 ) ) ); domains ++; } } @@ -1600,7 +1599,7 @@ css::uno::Reference< XResultSet > DatabaseMetaData::getColumns( closeable->close(); return new SequenceResultSet( - m_xMutex, *this, statics.columnRowNames, vec, m_pSettings->tc ); + m_xMutex, *this, std::vector(statics.columnRowNames), std::move(vec), m_pSettings->tc ); } css::uno::Reference< XResultSet > DatabaseMetaData::getColumnPrivileges( @@ -1783,7 +1782,7 @@ css::uno::Reference< XResultSet > DatabaseMetaData::getPrimaryKeys( elements ++; } return new SequenceResultSet( - m_xMutex, *this, getStatics().primaryKeyNames, ret, m_pSettings->tc ); + m_xMutex, *this, std::vector(getStatics().primaryKeyNames), std::move(ret), m_pSettings->tc ); } // Copied / adapted / simplified from JDBC driver @@ -2087,45 +2086,45 @@ namespace OUString nameB; a[0 /*TYPE_NAME*/] >>= nameA; b[0 /*TYPE_NAME*/] >>= nameB; - OUString nsA, tnA, nsB, tnB; + std::u16string_view nsA, tnA, nsB, tnB; // parse typename into schema and typename sal_Int32 nIndex=0; - nsA = nameA.getToken(0, '.', nIndex); + nsA = o3tl::getToken(nameA, 0, '.', nIndex); if (nIndex<0) { tnA = nsA; - nsA.clear(); + nsA = std::u16string_view(); } else { - tnA = nameA.getToken(0, '.', nIndex); + tnA = o3tl::getToken(nameA, 0, '.', nIndex); assert(nIndex < 0); } nIndex=0; - nsB = nameB.getToken(0, '.', nIndex); + nsB = o3tl::getToken(nameB, 0, '.', nIndex); if (nIndex<0) { tnB = nsB; - nsB.clear(); + nsB = std::u16string_view(); } else { - tnB = nameB.getToken(0, '.', nIndex); + tnB = o3tl::getToken(nameB, 0, '.', nIndex); assert(nIndex < 0); } const int ns_comp = compare_schema(nsA, nsB); if(ns_comp == 0) { - if(nsA.isEmpty()) + if(nsA.empty()) { - assert(nsB.isEmpty()); + assert(nsB.empty()); // within each type category, sort privileged choice first - if( tnA == "int4" || tnA == "varchar" || tnA == "char" || tnA == "text") + if( tnA == u"int4" || tnA == u"varchar" || tnA == u"char" || tnA == u"text") return true; - if( tnB == "int4" || tnB == "varchar" || tnB == "char" || tnB == "text") + if( tnB == u"int4" || tnB == u"varchar" || tnB == u"char" || tnB == u"text") return false; } return nameA.compareTo( nameB ) < 0; @@ -2299,8 +2298,8 @@ css::uno::Reference< XResultSet > DatabaseMetaData::getTypeInfo( ) return new SequenceResultSet( m_xMutex, *this, - getStatics().typeinfoColumnNames, - vec, + std::vector(getStatics().typeinfoColumnNames), + std::move(vec), m_pSettings->tc, &( getStatics().typeInfoMetaData )); } @@ -2424,8 +2423,8 @@ css::uno::Reference< XResultSet > DatabaseMetaData::getIndexInfo( } } return new SequenceResultSet( - m_xMutex, *this, getStatics().indexinfoColumnNames, - vec, + m_xMutex, *this, std::vector(getStatics().indexinfoColumnNames), + std::move(vec), m_pSettings->tc ); } diff --git a/connectivity/source/drivers/postgresql/pq_databasemetadata.hxx b/connectivity/source/drivers/postgresql/pq_databasemetadata.hxx index c016886f2643..4e8b717a96b2 100644 --- a/connectivity/source/drivers/postgresql/pq_databasemetadata.hxx +++ b/connectivity/source/drivers/postgresql/pq_databasemetadata.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_DATABASEMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_DATABASEMETADATA_HXX +#pragma once #include "pq_connection.hxx" #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> @@ -75,8 +74,8 @@ class DatabaseMetaData : public: DatabaseMetaData( - const ::rtl::Reference< comphelper::RefCountedMutex > & reMutex, - const css::uno::Reference< css::sdbc::XConnection > & origin, + ::rtl::Reference< comphelper::RefCountedMutex > reMutex, + css::uno::Reference< css::sdbc::XConnection > origin, ConnectionSettings *pSettings ); @@ -235,6 +234,4 @@ public: } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_driver.cxx b/connectivity/source/drivers/postgresql/pq_driver.cxx index 87eb5682a2b2..8e07123a2b0f 100644 --- a/connectivity/source/drivers/postgresql/pq_driver.cxx +++ b/connectivity/source/drivers/postgresql/pq_driver.cxx @@ -40,12 +40,6 @@ #include "pq_driver.hxx" -using osl::MutexGuard; - -using com::sun::star::lang::XSingleComponentFactory; -using com::sun::star::lang::XServiceInfo; -using com::sun::star::lang::XComponent; - using com::sun::star::uno::Sequence; using com::sun::star::uno::Reference; using com::sun::star::uno::XInterface; @@ -70,9 +64,7 @@ Reference< XConnection > Driver::connect( if( ! acceptsURL( url ) ) // XDriver spec tells me to do so ... return Reference< XConnection > (); - Sequence< Any > seq ( 2 ); - seq[0] <<= url; - seq[1] <<= info; + Sequence< Any > seq{ Any(url), Any(info) }; return Reference< XConnection> ( m_smgr->createInstanceWithArgumentsAndContext( "org.openoffice.comp.connectivity.pq.Connection.noext", @@ -143,7 +135,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* connectivity_pq_sdbc_driver_get_implementation( css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&) { - return cppu::acquire(static_cast<cppu::OWeakObject*>(new pq_sdbc_driver::Driver(context))); + return cppu::acquire(new pq_sdbc_driver::Driver(context)); } diff --git a/connectivity/source/drivers/postgresql/pq_driver.hxx b/connectivity/source/drivers/postgresql/pq_driver.hxx index 3b61a7bcf269..31d407f36965 100644 --- a/connectivity/source/drivers/postgresql/pq_driver.hxx +++ b/connectivity/source/drivers/postgresql/pq_driver.hxx @@ -34,12 +34,11 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_DRIVER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_DRIVER_HXX +#pragma once -#include <osl/mutex.hxx> #include <sal/macros.h> #include <cppuhelper/compbase.hxx> +#include <cppuhelper/basemutex.hxx> #include <com/sun/star/lang/XServiceInfo.hpp> @@ -55,7 +54,6 @@ namespace pq_sdbc_driver SAL_STRINGIFY(PQ_SDBC_MINOR) "." \ SAL_STRINGIFY(PQ_SDBC_MICRO) -struct MutexHolder { osl::Mutex m_mutex; }; // use this to switch off sdbc support ! // typedef cppu::WeakComponentImplHelper< // css::sdbc::XDriver, @@ -65,14 +63,14 @@ typedef cppu::WeakComponentImplHelper< css::sdbc::XDriver, css::lang::XServiceInfo, css::sdbcx::XDataDefinitionSupplier > DriverBase ; -class Driver : public MutexHolder, public DriverBase +class Driver : public cppu::BaseMutex, public DriverBase { css::uno::Reference< css::uno::XComponentContext > m_ctx; css::uno::Reference< css::lang::XMultiComponentFactory > m_smgr; public: explicit Driver ( const css::uno::Reference < css::uno::XComponentContext > & ctx ) - : DriverBase( m_mutex ), + : DriverBase( m_aMutex ), m_ctx( ctx ), m_smgr( ctx->getServiceManager() ) {} @@ -115,6 +113,4 @@ public: } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_fakedupdateableresultset.cxx b/connectivity/source/drivers/postgresql/pq_fakedupdateableresultset.cxx index a75897ccb211..216a25220355 100644 --- a/connectivity/source/drivers/postgresql/pq_fakedupdateableresultset.cxx +++ b/connectivity/source/drivers/postgresql/pq_fakedupdateableresultset.cxx @@ -38,6 +38,7 @@ #include <com/sun/star/sdbc/SQLException.hpp> #include <cppuhelper/typeprovider.hxx> #include <cppuhelper/queryinterface.hxx> +#include <utility> using com::sun::star::uno::Sequence; @@ -58,9 +59,9 @@ FakedUpdateableResultSet::FakedUpdateableResultSet( PGresult *result, const OUString &schema, const OUString &table, - const OUString &aReason ) + OUString aReason ) : ResultSet( mutex, owner, pSettings, result, schema, table ), - m_aReason( aReason ) + m_aReason(std::move( aReason )) {} diff --git a/connectivity/source/drivers/postgresql/pq_fakedupdateableresultset.hxx b/connectivity/source/drivers/postgresql/pq_fakedupdateableresultset.hxx index 65113344cdec..44e7dc9bcf13 100644 --- a/connectivity/source/drivers/postgresql/pq_fakedupdateableresultset.hxx +++ b/connectivity/source/drivers/postgresql/pq_fakedupdateableresultset.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_FAKEDUPDATEABLERESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_FAKEDUPDATEABLERESULTSET_HXX +#pragma once #include <com/sun/star/sdbc/XResultSetUpdate.hpp> #include <com/sun/star/sdbc/XRowUpdate.hpp> @@ -62,11 +61,11 @@ public: PGresult *result, const OUString &schema, const OUString &table, - const OUString &aReason ); + OUString aReason ); public: // XInterface - virtual void SAL_CALL acquire() throw() override { ResultSet::acquire(); } - virtual void SAL_CALL release() throw() override { ResultSet::release(); } + virtual void SAL_CALL acquire() noexcept override { ResultSet::acquire(); } + virtual void SAL_CALL release() noexcept override { ResultSet::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -103,6 +102,5 @@ public: // XRowUpdate }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx b/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx index 344c27175850..e616e9b22966 100644 --- a/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx +++ b/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx @@ -40,7 +40,7 @@ #include "pq_statics.hxx" #include "pq_statement.hxx" -#include <o3tl/deleter.hxx> +#include <o3tl/safeint.hxx> #include <rtl/strbuf.hxx> #include <rtl/ustrbuf.hxx> @@ -57,6 +57,7 @@ #include <string_view> #include <connectivity/dbconversion.hxx> +#include <utility> using osl::MutexGuard; @@ -149,12 +150,12 @@ PreparedStatement::PreparedStatement( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const Reference< XConnection > & conn, struct ConnectionSettings *pSettings, - const OString & stmt ) + OString stmt ) : PreparedStatement_BASE(refMutex->GetMutex()) , OPropertySetHelper(PreparedStatement_BASE::rBHelper) , m_connection(conn) , m_pSettings(pSettings) - , m_stmt(stmt) + , m_stmt(std::move(stmt)) , m_xMutex(refMutex) , m_multipleResultAvailable(false) , m_multipleResultUpdateCount(0) @@ -198,7 +199,7 @@ PreparedStatement::~PreparedStatement() void PreparedStatement::checkColumnIndex( sal_Int32 parameterIndex ) { - if( parameterIndex < 1 || parameterIndex > static_cast<sal_Int32>(m_vars.size()) ) + if( parameterIndex < 1 || o3tl::make_unsigned(parameterIndex) > m_vars.size() ) { throw SQLException( "pq_preparedstatement: parameter index out of range (expected 1 to " @@ -262,10 +263,9 @@ void PreparedStatement::close( ) void PreparedStatement::raiseSQLException( const char * errorMsg ) { OUStringBuffer buf(128); - buf.append( "pq_driver: "); - buf.append( - OUString( errorMsg, strlen(errorMsg) , ConnectionSettings::encoding ) ); - buf.append( " (caused by statement '" ); + buf.append( "pq_driver: " + + OUString( errorMsg, strlen(errorMsg) , ConnectionSettings::encoding ) + + " (caused by statement '" ); buf.appendAscii( m_executedStatement.getStr() ); buf.append( "')" ); OUString error = buf.makeStringAndClear(); @@ -390,7 +390,7 @@ void PreparedStatement::setNull( sal_Int32 parameterIndex, sal_Int32 ) MutexGuard guard( m_xMutex->GetMutex() ); checkClosed(); checkColumnIndex( parameterIndex ); - m_vars[parameterIndex-1] = OString( "NULL" ); + m_vars[parameterIndex-1] = "NULL"_ostr; } void PreparedStatement::setObjectNull( @@ -399,7 +399,7 @@ void PreparedStatement::setObjectNull( MutexGuard guard( m_xMutex->GetMutex() ); checkClosed(); checkColumnIndex( parameterIndex ); - m_vars[parameterIndex-1] = OString( "NULL" ); + m_vars[parameterIndex-1] = "NULL"_ostr; } @@ -409,9 +409,9 @@ void PreparedStatement::setBoolean( sal_Int32 parameterIndex, sal_Bool x ) checkClosed(); checkColumnIndex( parameterIndex ); if( x ) - m_vars[parameterIndex-1] = OString( "'t'" ); + m_vars[parameterIndex-1] = "'t'"_ostr; else - m_vars[parameterIndex-1] = OString( "'f'" ); + m_vars[parameterIndex-1] = "'f'"_ostr; } void PreparedStatement::setByte( sal_Int32 parameterIndex, sal_Int8 x ) diff --git a/connectivity/source/drivers/postgresql/pq_preparedstatement.hxx b/connectivity/source/drivers/postgresql/pq_preparedstatement.hxx index eb0794f9efe0..ed81420cec7d 100644 --- a/connectivity/source/drivers/postgresql/pq_preparedstatement.hxx +++ b/connectivity/source/drivers/postgresql/pq_preparedstatement.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_PREPAREDSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_PREPAREDSTATEMENT_HXX +#pragma once #include <vector> #include <libpq-fe.h> @@ -99,12 +98,12 @@ public: PreparedStatement( const rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection> & con, struct ConnectionSettings *pSettings, - const OString &stmt ); + OString stmt ); virtual ~PreparedStatement() override; public: // XInterface - virtual void SAL_CALL acquire() throw() override { PreparedStatement_BASE::acquire(); } - virtual void SAL_CALL release() throw() override { PreparedStatement_BASE::release(); } + virtual void SAL_CALL acquire() noexcept override { PreparedStatement_BASE::acquire(); } + virtual void SAL_CALL release() noexcept override { PreparedStatement_BASE::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; public: // XCloseable @@ -218,6 +217,5 @@ private: }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_resultset.cxx b/connectivity/source/drivers/postgresql/pq_resultset.cxx index 556bae92d5be..0058041c87b5 100644 --- a/connectivity/source/drivers/postgresql/pq_resultset.cxx +++ b/connectivity/source/drivers/postgresql/pq_resultset.cxx @@ -44,6 +44,7 @@ #include <com/sun/star/sdbc/ResultSetType.hpp> #include <com/sun/star/sdbc/DataType.hpp> #include <com/sun/star/sdbc/SQLException.hpp> +#include <utility> using osl::MutexGuard; @@ -79,14 +80,14 @@ ResultSet::ResultSet( const ::rtl::Reference< comphelper::RefCountedMutex > & re const Reference< XInterface > & owner, ConnectionSettings **ppSettings, PGresult * result, - const OUString &schema, - const OUString &table) + OUString schema, + OUString table) : BaseResultSet( refMutex, owner, PQntuples( result ), PQnfields( result ),(*ppSettings)->tc ), m_result( result ), - m_schema( schema ), - m_table( table ), + m_schema(std::move( schema )), + m_table(std::move( table )), m_ppSettings( ppSettings ) { // LEM TODO: shouldn't these things be inherited from the statement or something like that? diff --git a/connectivity/source/drivers/postgresql/pq_resultset.hxx b/connectivity/source/drivers/postgresql/pq_resultset.hxx index 4b2bb6f41fb9..cf2888bf5b93 100644 --- a/connectivity/source/drivers/postgresql/pq_resultset.hxx +++ b/connectivity/source/drivers/postgresql/pq_resultset.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_RESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_RESULTSET_HXX +#pragma once #include <cppuhelper/propshlp.hxx> #include <cppuhelper/component.hxx> @@ -73,8 +72,8 @@ public: const css::uno::Reference< css::uno::XInterface > &owner, ConnectionSettings **pSettings, PGresult *result, - const OUString &schema, - const OUString &table ); + OUString schema, + OUString table ); virtual ~ResultSet() override; public: // XCloseable @@ -91,6 +90,5 @@ public: }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_resultsetmetadata.cxx b/connectivity/source/drivers/postgresql/pq_resultsetmetadata.cxx index fbe10f82dacb..26b11de27985 100644 --- a/connectivity/source/drivers/postgresql/pq_resultsetmetadata.cxx +++ b/connectivity/source/drivers/postgresql/pq_resultsetmetadata.cxx @@ -46,6 +46,7 @@ #include <com/sun/star/sdbc/DataType.hpp> #include <com/sun/star/sdbc/SQLException.hpp> #include <com/sun/star/sdbc/XRow.hpp> +#include <utility> #include <string.h> @@ -113,18 +114,18 @@ static void extractPrecisionAndScale( sal_Int32 atttypmod, sal_Int32 *precision, } ResultSetMetaData::ResultSetMetaData( - const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, - const css::uno::Reference< css::sdbc::XResultSet > & origin, + ::rtl::Reference< comphelper::RefCountedMutex > refMutex, + css::uno::Reference< css::sdbc::XResultSet > origin, ResultSet * pResultSet, ConnectionSettings **ppSettings, PGresult const *pResult, - const OUString &schemaName, - const OUString &tableName ) : - m_xMutex( refMutex ), + OUString schemaName, + OUString tableName ) : + m_xMutex(std::move( refMutex )), m_ppSettings( ppSettings ), - m_origin( origin ), - m_tableName( tableName ), - m_schemaName( schemaName ), + m_origin(std::move( origin )), + m_tableName(std::move( tableName )), + m_schemaName(std::move( schemaName )), m_colDesc( PQnfields( pResult ) ), m_pResultSet( pResultSet ), m_checkedForTable( false ), @@ -166,8 +167,7 @@ void ResultSetMetaData::checkForTypes() if( i > 0 ) buf.append( " OR " ); int oid = m_colDesc[i].typeOid; - buf.append( "oid=" ); - buf.append( static_cast<sal_Int32>(oid) ); + buf.append( "oid=" + OUString::number(static_cast<sal_Int32>(oid)) ); } Reference< XResultSet > rs = stmt->executeQuery( buf.makeStringAndClear() ); Reference< XRow > xRow( rs, UNO_QUERY ); diff --git a/connectivity/source/drivers/postgresql/pq_resultsetmetadata.hxx b/connectivity/source/drivers/postgresql/pq_resultsetmetadata.hxx index 2c1b5e5e5965..71c98190ba2b 100644 --- a/connectivity/source/drivers/postgresql/pq_resultsetmetadata.hxx +++ b/connectivity/source/drivers/postgresql/pq_resultsetmetadata.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_RESULTSETMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_RESULTSETMETADATA_HXX +#pragma once #include <vector> #include "pq_connection.hxx" @@ -90,13 +89,13 @@ class ResultSetMetaData : public: ResultSetMetaData( - const ::rtl::Reference< comphelper::RefCountedMutex > & reMutex, - const css::uno::Reference< css::sdbc::XResultSet > & origin, + ::rtl::Reference< comphelper::RefCountedMutex > reMutex, + css::uno::Reference< css::sdbc::XResultSet > origin, ResultSet *pResultSet, ConnectionSettings **pSettings, PGresult const *pResult, - const OUString &schemaName, - const OUString &tableName ); + OUString schemaName, + OUString tableName ); public: // Methods @@ -125,6 +124,4 @@ public: } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_sequenceresultset.cxx b/connectivity/source/drivers/postgresql/pq_sequenceresultset.cxx index 02030729ad73..defb99906048 100644 --- a/connectivity/source/drivers/postgresql/pq_sequenceresultset.cxx +++ b/connectivity/source/drivers/postgresql/pq_sequenceresultset.cxx @@ -65,17 +65,17 @@ Any SequenceResultSet::getValue( sal_Int32 columnIndex ) SequenceResultSet::SequenceResultSet( const ::rtl::Reference< comphelper::RefCountedMutex > & mutex, const css::uno::Reference< css::uno::XInterface > &owner, - const std::vector< OUString > &colNames, - const std::vector< std::vector< Any > > &data, + std::vector< OUString >&& colNames, + std::vector< std::vector< Any > >&& data, const Reference< css::script::XTypeConverter > & tc, const ColumnMetaDataVector *pVec) : BaseResultSet( mutex, owner, data.size(), colNames.size(), tc ), - m_data(data ), - m_columnNames( colNames ) + m_data(std::move(data) ), + m_columnNames( std::move(colNames) ) { if( pVec ) { - m_meta = new SequenceResultSetMetaData( *pVec, m_columnNames.size() ); + m_meta = new SequenceResultSetMetaData( std::vector(*pVec), m_columnNames.size() ); } } diff --git a/connectivity/source/drivers/postgresql/pq_sequenceresultset.hxx b/connectivity/source/drivers/postgresql/pq_sequenceresultset.hxx index 3b97e24a3001..64ac212b6b76 100644 --- a/connectivity/source/drivers/postgresql/pq_sequenceresultset.hxx +++ b/connectivity/source/drivers/postgresql/pq_sequenceresultset.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_SEQUENCERESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_SEQUENCERESULTSET_HXX +#pragma once #include <cppuhelper/propshlp.hxx> #include <cppuhelper/component.hxx> @@ -72,8 +71,8 @@ public: SequenceResultSet( const ::rtl::Reference< comphelper::RefCountedMutex > & mutex, const css::uno::Reference< css::uno::XInterface > &owner, - const std::vector< OUString > &colNames, - const std::vector< std::vector< css::uno::Any > > &data, + std::vector< OUString >&& colNames, + std::vector< std::vector< css::uno::Any > >&& data, const css::uno::Reference< css::script::XTypeConverter > &tc, const ColumnMetaDataVector *pVec = nullptr); virtual ~SequenceResultSet() override; @@ -89,6 +88,5 @@ public: // XColumnLocate }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_sequenceresultsetmetadata.cxx b/connectivity/source/drivers/postgresql/pq_sequenceresultsetmetadata.cxx index d45ffc0a614a..568e6bb9f49d 100644 --- a/connectivity/source/drivers/postgresql/pq_sequenceresultsetmetadata.cxx +++ b/connectivity/source/drivers/postgresql/pq_sequenceresultsetmetadata.cxx @@ -46,9 +46,9 @@ namespace pq_sdbc_driver { SequenceResultSetMetaData::SequenceResultSetMetaData( - const ColumnMetaDataVector &metaDataVector, + ColumnMetaDataVector&& metaDataVector, int colCount ) : - m_columnData( metaDataVector ), + m_columnData( std::move(metaDataVector) ), m_colCount( colCount ) { } diff --git a/connectivity/source/drivers/postgresql/pq_sequenceresultsetmetadata.hxx b/connectivity/source/drivers/postgresql/pq_sequenceresultsetmetadata.hxx index 2bba06aa7d2f..3cd32ff66d7a 100644 --- a/connectivity/source/drivers/postgresql/pq_sequenceresultsetmetadata.hxx +++ b/connectivity/source/drivers/postgresql/pq_sequenceresultsetmetadata.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_SEQUENCERESULTSETMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_SEQUENCERESULTSETMETADATA_HXX +#pragma once #include <cppuhelper/implbase.hxx> #include <com/sun/star/sdbc/XResultSetMetaData.hpp> @@ -57,7 +56,7 @@ namespace pq_sdbc_driver public: SequenceResultSetMetaData( - const ColumnMetaDataVector &vec, + ColumnMetaDataVector&& vec, int colCount ); public: @@ -87,6 +86,4 @@ namespace pq_sdbc_driver } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_SEQUENCERESULTSETMETADATA_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_statement.cxx b/connectivity/source/drivers/postgresql/pq_statement.cxx index 946d25b0c91e..648faa69811b 100644 --- a/connectivity/source/drivers/postgresql/pq_statement.cxx +++ b/connectivity/source/drivers/postgresql/pq_statement.cxx @@ -44,7 +44,6 @@ #include <osl/time.h> #include <rtl/ustrbuf.hxx> -#include <rtl/strbuf.hxx> #include <comphelper/sequence.hxx> @@ -60,6 +59,7 @@ #include <com/sun/star/container/XIndexAccess.hpp> #include <com/sun/star/container/XEnumerationAccess.hpp> +#include <cstddef> #include <string.h> #include <string_view> @@ -253,10 +253,10 @@ static void raiseSQLException( buf.append( "]" ); } buf.append( - OUString( errorMsg, strlen(errorMsg) , ConnectionSettings::encoding ) ); - buf.append( " (caused by statement '" ); - buf.append( OStringToOUString( sql, ConnectionSettings::encoding ) ); - buf.append( "')" ); + OUString( errorMsg, strlen(errorMsg) , ConnectionSettings::encoding ) + + " (caused by statement '" + + OStringToOUString( sql, ConnectionSettings::encoding ) + + "')" ); OUString error = buf.makeStringAndClear(); SAL_WARN("connectivity.postgresql", error); throw SQLException( error, owner, OUString(), 1, Any() ); @@ -430,8 +430,8 @@ bool executePostgresCommand( const OString & cmd, struct CommandData *data ) &table); // check, whether the columns are in the result set (required !) - int i; - for( i = 0 ; i < static_cast<int>(sourceTableKeys.size()) ; i ++ ) + std::size_t i; + for( i = 0 ; i < sourceTableKeys.size() ; i ++ ) { if( -1 == PQfnumber( result, @@ -442,12 +442,12 @@ bool executePostgresCommand( const OString & cmd, struct CommandData *data ) } } - if( !sourceTableKeys.empty() && i == static_cast<int>(sourceTableKeys.size()) ) + if( !sourceTableKeys.empty() && i == sourceTableKeys.size() ) { *(data->pLastResultset) = UpdateableResultSet::createFromPGResultSet( data->refMutex, data->owner, data->ppSettings, result, - schema, table,sourceTableKeys ); + schema, table, std::move(sourceTableKeys) ); } else if( ! table.getLength() ) { @@ -456,15 +456,12 @@ bool executePostgresCommand( const OString & cmd, struct CommandData *data ) } else if( !sourceTableKeys.empty() ) { - OStringBuffer buf( 128 ); - buf.append( "can't support updateable resultset for table " ); - buf.append( OUStringToOString( schema, ConnectionSettings::encoding ) ); - buf.append( "." ); - buf.append( OUStringToOString( table, ConnectionSettings::encoding ) ); - buf.append( ", because resultset does not contain a part of the primary key ( column " ); - buf.append( OUStringToOString( sourceTableKeys[i], ConnectionSettings::encoding ) ); - buf.append( " is missing )" ); - aReason = buf.makeStringAndClear(); + aReason = "can't support updateable resultset for table " + + OUStringToOString( schema, ConnectionSettings::encoding ) + "." + + OUStringToOString( table, ConnectionSettings::encoding ) + + ", because resultset does not contain a part of the primary key ( column " + + OUStringToOString( sourceTableKeys[i], ConnectionSettings::encoding ) + + " is missing )"; } else { @@ -559,7 +556,7 @@ static void getAutoValues( const Reference< XConnection > & connection, const OUString &schemaName, const OUString & tableName, - ConnectionSettings *pConnectionSettings ) + const ConnectionSettings *pConnectionSettings ) { OUString strDefaultValue = getColExprForDefaultSettingVal(pConnectionSettings); Reference< XPreparedStatement > stmt = connection->prepareStatement( @@ -593,7 +590,7 @@ Reference< XResultSet > getGeneratedValuesFromLastInsert( ConnectionSettings *pConnectionSettings, const Reference< XConnection > &connection, sal_Int32 nLastOid, - const OUString & lastTableInserted, + std::u16string_view lastTableInserted, const OString & lastQuery ) { Reference< XResultSet > ret; @@ -602,7 +599,7 @@ Reference< XResultSet > getGeneratedValuesFromLastInsert( splitConcatenatedIdentifier( lastTableInserted, &schemaName, &tableName ); - if( nLastOid && lastTableInserted.getLength() ) + if( nLastOid && lastTableInserted.size() ) { OUStringBuffer buf( 128 ); buf.append( "SELECT * FROM " ); @@ -610,11 +607,10 @@ Reference< XResultSet > getGeneratedValuesFromLastInsert( bufferQuoteQualifiedIdentifier(buf, schemaName, tableName, pConnectionSettings ); else bufferQuoteIdentifier( buf, lastTableInserted, pConnectionSettings ); - buf.append( " WHERE oid = " ); - buf.append( nLastOid ); + buf.append( " WHERE oid = " + OUString::number(nLastOid) ); query = buf.makeStringAndClear(); } - else if ( lastTableInserted.getLength() && lastQuery.getLength() ) + else if ( lastTableInserted.size() && lastQuery.getLength() ) { // extract nameValue Pairs String2StringMap namedValues; @@ -703,8 +699,7 @@ Reference< XResultSet > getGeneratedValuesFromLastInsert( if( bAdditionalCondition ) buf.append( " AND " ); bufferQuoteIdentifier( buf, columnNameUnicode, pConnectionSettings ); - buf.append( " = " ); - buf.append( value ); + buf.append( " = " + value ); bAdditionalCondition = true; } query = buf.makeStringAndClear(); diff --git a/connectivity/source/drivers/postgresql/pq_statement.hxx b/connectivity/source/drivers/postgresql/pq_statement.hxx index 6f9fb3bb1ecc..816d2a55afaa 100644 --- a/connectivity/source/drivers/postgresql/pq_statement.hxx +++ b/connectivity/source/drivers/postgresql/pq_statement.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_STATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_STATEMENT_HXX +#pragma once #include <sal/config.h> @@ -101,8 +100,8 @@ public: virtual ~Statement() override; public: // XInterface - virtual void SAL_CALL acquire() throw() override { Statement_BASE::acquire(); } - virtual void SAL_CALL release() throw() override { Statement_BASE::release(); } + virtual void SAL_CALL acquire() noexcept override { Statement_BASE::acquire(); } + virtual void SAL_CALL release() noexcept override { Statement_BASE::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; public: // XCloseable @@ -190,11 +189,10 @@ css::uno::Reference< css::sdbc::XResultSet > getGeneratedValuesFromLastInsert( ConnectionSettings *pConnectionSettings, const css::uno::Reference< css::sdbc::XConnection > &connection, sal_Int32 nLastOid, - const OUString & lastTableInserted, + std::u16string_view lastTableInserted, const OString & lastQuery ); } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_statics.cxx b/connectivity/source/drivers/postgresql/pq_statics.cxx index a68242e2c55d..f69556202240 100644 --- a/connectivity/source/drivers/postgresql/pq_statics.cxx +++ b/connectivity/source/drivers/postgresql/pq_statics.cxx @@ -35,9 +35,9 @@ ************************************************************************/ #include "pq_statics.hxx" -#include "pq_updateableresultset.hxx" #include <com/sun/star/sdbc/DataType.hpp> #include <com/sun/star/beans/PropertyAttribute.hpp> +#include <utility> using com::sun::star::uno::Sequence; using com::sun::star::uno::Any; @@ -69,8 +69,8 @@ struct BaseTypeDef { const char * typeName; sal_Int32 value; }; struct PropertyDef { - PropertyDef( const OUString &str, const Type &t ) - : name( str ) , type( t ) {} + PropertyDef( OUString str, const Type &t ) + : name(std::move( str )) , type( t ) {} OUString name; css::uno::Type type; }; @@ -89,9 +89,10 @@ static cppu::IPropertyArrayHelper * createPropertyArrayHelper( PropertyDef const *props, int count , sal_Int16 attr ) { Sequence< Property > seq( count ); + auto seqRange = asNonConstRange(seq); for( int i = 0 ; i < count ; i ++ ) { - seq[i] = Property( props[i].name, i, props[i].type, attr ); + seqRange[i] = Property( props[i].name, i, props[i].type, attr ); } return new cppu::OPropertyArrayHelper( seq, true ); } @@ -100,9 +101,10 @@ static cppu::IPropertyArrayHelper * createPropertyArrayHelper( PropertyDefEx const *props, int count ) { Sequence< Property > seq( count ); + auto seqRange = asNonConstRange(seq); for( int i = 0 ; i < count ; i ++ ) { - seq[i] = Property( props[i].name, i, props[i].type, props[i].attribute ); + seqRange[i] = Property( props[i].name, i, props[i].type, props[i].attribute ); } return new cppu::OPropertyArrayHelper( seq, true ); } @@ -184,8 +186,7 @@ Statics & getStatics() // Table props set ImplementationStatics &ist = statics.refl.table; ist.implName = "org.openoffice.comp.pq.sdbcx.Table"; - ist.serviceNames = Sequence< OUString > ( 1 ); - ist.serviceNames[0] = "com.sun.star.sdbcx.Table"; + ist.serviceNames = { "com.sun.star.sdbcx.Table" }; PropertyDef tableDef[] = { PropertyDef( statics.CATALOG_NAME , tString ), @@ -196,13 +197,11 @@ Statics & getStatics() PropertyDef( statics.TYPE , tString ) }; ist.pProps = createPropertyArrayHelper( - tableDef, SAL_N_ELEMENTS(tableDef), READONLY ); + tableDef, std::size(tableDef), READONLY ); statics.refl.tableDescriptor.implName = "org.openoffice.comp.pq.sdbcx.TableDescriptor"; - statics.refl.tableDescriptor.serviceNames = Sequence< OUString > (1); - statics.refl.tableDescriptor.serviceNames[0] = - "com.sun.star.sdbcx.TableDescriptor"; + statics.refl.tableDescriptor.serviceNames = { "com.sun.star.sdbcx.TableDescriptor" }; PropertyDef tableDescDef[] = { PropertyDef( statics.CATALOG_NAME , tString ), @@ -212,12 +211,11 @@ Statics & getStatics() PropertyDef( statics.SCHEMA_NAME , tString ) }; statics.refl.tableDescriptor.pProps = createPropertyArrayHelper( - tableDescDef, SAL_N_ELEMENTS(tableDescDef), 0 ); + tableDescDef, std::size(tableDescDef), 0 ); // Column props set statics.refl.column.implName = "org.openoffice.comp.pq.sdbcx.Column"; - statics.refl.column.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.column.serviceNames[0] = "com.sun.star.sdbcx.Column"; + statics.refl.column.serviceNames = { "com.sun.star.sdbcx.Column" }; PropertyDefEx columnDef[] = { PropertyDefEx( statics.CATALOG_NAME , tString, READONLY ), @@ -235,13 +233,11 @@ Statics & getStatics() PropertyDefEx( statics.TYPE_NAME , tString ,READONLY) }; statics.refl.column.pProps = createPropertyArrayHelper( - columnDef, SAL_N_ELEMENTS(columnDef) ); + columnDef, std::size(columnDef) ); statics.refl.columnDescriptor.implName = "org.openoffice.comp.pq.sdbcx.ColumnDescriptor"; - statics.refl.columnDescriptor.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.columnDescriptor.serviceNames[0] = - "com.sun.star.sdbcx.ColumnDescriptor"; + statics.refl.columnDescriptor.serviceNames = { "com.sun.star.sdbcx.ColumnDescriptor" }; PropertyDef columnDescDef[] = { PropertyDef( statics.CATALOG_NAME , tString ), @@ -260,12 +256,11 @@ Statics & getStatics() }; statics.refl.columnDescriptor.pProps = createPropertyArrayHelper( - columnDescDef, SAL_N_ELEMENTS(columnDescDef), 0 ); + columnDescDef, std::size(columnDescDef), 0 ); // Key properties statics.refl.key.implName = "org.openoffice.comp.pq.sdbcx.Key"; - statics.refl.key.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.key.serviceNames[0] = "com.sun.star.sdbcx.Key"; + statics.refl.key.serviceNames = { "com.sun.star.sdbcx.Key" }; PropertyDef keyDef[] = { PropertyDef( statics.DELETE_RULE, tInt ), @@ -277,15 +272,13 @@ Statics & getStatics() PropertyDef( statics.UPDATE_RULE, tInt ) }; statics.refl.key.pProps = createPropertyArrayHelper( - keyDef, SAL_N_ELEMENTS(keyDef), READONLY ); + keyDef, std::size(keyDef), READONLY ); // Key properties statics.refl.keyDescriptor.implName = "org.openoffice.comp.pq.sdbcx.KeyDescriptor"; - statics.refl.keyDescriptor.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.keyDescriptor.serviceNames[0] = - "com.sun.star.sdbcx.KeyDescriptor"; + statics.refl.keyDescriptor.serviceNames = { "com.sun.star.sdbcx.KeyDescriptor" }; PropertyDef keyDescDef[] = { PropertyDef( statics.DELETE_RULE, tInt ), @@ -295,13 +288,12 @@ Statics & getStatics() PropertyDef( statics.UPDATE_RULE, tInt ) }; statics.refl.keyDescriptor.pProps = createPropertyArrayHelper( - keyDescDef, SAL_N_ELEMENTS(keyDescDef), 0 ); + keyDescDef, std::size(keyDescDef), 0 ); // KeyColumn props set statics.refl.keycolumn.implName = "org.openoffice.comp.pq.sdbcx.KeyColumn"; - statics.refl.keycolumn.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.keycolumn.serviceNames[0] = "com.sun.star.sdbcx.KeyColumn"; + statics.refl.keycolumn.serviceNames = { "com.sun.star.sdbcx.KeyColumn" }; PropertyDef keycolumnDef[] = { PropertyDef( statics.CATALOG_NAME , tString ), @@ -319,26 +311,24 @@ Statics & getStatics() PropertyDef( statics.TYPE_NAME , tString ) }; statics.refl.keycolumn.pProps = createPropertyArrayHelper( - keycolumnDef, SAL_N_ELEMENTS(keycolumnDef), READONLY ); + keycolumnDef, std::size(keycolumnDef), READONLY ); // KeyColumn props set statics.refl.keycolumnDescriptor.implName = "org.openoffice.comp.pq.sdbcx.KeyColumnDescriptor"; - statics.refl.keycolumnDescriptor.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.keycolumnDescriptor.serviceNames[0] = - "com.sun.star.sdbcx.KeyColumnDescriptor"; + statics.refl.keycolumnDescriptor.serviceNames = + { "com.sun.star.sdbcx.KeyColumnDescriptor" }; PropertyDef keycolumnDescDef[] = { PropertyDef( statics.NAME , tString ), PropertyDef( statics.RELATED_COLUMN, tString ) }; statics.refl.keycolumnDescriptor.pProps = createPropertyArrayHelper( - keycolumnDescDef, SAL_N_ELEMENTS(keycolumnDescDef), 0 ); + keycolumnDescDef, std::size(keycolumnDescDef), 0 ); // view props set statics.refl.view.implName = "org.openoffice.comp.pq.sdbcx.View"; - statics.refl.view.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.view.serviceNames[0] = "com.sun.star.sdbcx.View"; + statics.refl.view.serviceNames = { "com.sun.star.sdbcx.View" }; PropertyDef viewDef[] = { PropertyDef( statics.CATALOG_NAME , tString ), @@ -348,43 +338,38 @@ Statics & getStatics() PropertyDef( statics.SCHEMA_NAME , tString ) }; statics.refl.view.pProps = createPropertyArrayHelper( - viewDef, SAL_N_ELEMENTS(viewDef), READONLY ); + viewDef, std::size(viewDef), READONLY ); // view props set statics.refl.viewDescriptor.implName = "org.openoffice.comp.pq.sdbcx.ViewDescriptor"; - statics.refl.viewDescriptor.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.viewDescriptor.serviceNames[0] = "com.sun.star.sdbcx.ViewDescriptor"; + statics.refl.viewDescriptor.serviceNames = { "com.sun.star.sdbcx.ViewDescriptor" }; statics.refl.viewDescriptor.pProps = createPropertyArrayHelper( - viewDef, SAL_N_ELEMENTS(viewDef), 0 ); // reuse view, as it is identical + viewDef, std::size(viewDef), 0 ); // reuse view, as it is identical // user props set statics.refl.user.implName = "org.openoffice.comp.pq.sdbcx.User"; - statics.refl.user.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.user.serviceNames[0] = "com.sun.star.sdbcx.User"; + statics.refl.user.serviceNames = { "com.sun.star.sdbcx.User" }; PropertyDef userDefRO[] = { PropertyDef( statics.NAME , tString ) }; statics.refl.user.pProps = createPropertyArrayHelper( - userDefRO, SAL_N_ELEMENTS(userDefRO), READONLY ); + userDefRO, std::size(userDefRO), READONLY ); // user props set statics.refl.userDescriptor.implName = "org.openoffice.comp.pq.sdbcx.UserDescriptor"; - statics.refl.userDescriptor.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.userDescriptor.serviceNames[0] = - "com.sun.star.sdbcx.UserDescriptor"; + statics.refl.userDescriptor.serviceNames = { "com.sun.star.sdbcx.UserDescriptor" }; PropertyDef userDefWR[] = { PropertyDef( statics.NAME , tString ), PropertyDef( statics.PASSWORD , tString ) }; statics.refl.userDescriptor.pProps = createPropertyArrayHelper( - userDefWR, SAL_N_ELEMENTS(userDefWR), 0 ); + userDefWR, std::size(userDefWR), 0 ); // index props set statics.refl.index.implName = "org.openoffice.comp.pq.sdbcx.Index"; - statics.refl.index.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.index.serviceNames[0] = "com.sun.star.sdbcx.Index"; + statics.refl.index.serviceNames = { "com.sun.star.sdbcx.Index" }; PropertyDef indexDef[] = { PropertyDef( statics.CATALOG , tString ), @@ -395,21 +380,18 @@ Statics & getStatics() PropertyDef( statics.PRIVATE_COLUMN_INDEXES, tStringSequence ) }; statics.refl.index.pProps = createPropertyArrayHelper( - indexDef, SAL_N_ELEMENTS(indexDef), READONLY ); + indexDef, std::size(indexDef), READONLY ); // index props set statics.refl.indexDescriptor.implName = "org.openoffice.comp.pq.sdbcx.IndexDescriptor"; - statics.refl.indexDescriptor.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.indexDescriptor.serviceNames[0] = - "com.sun.star.sdbcx.IndexDescriptor"; + statics.refl.indexDescriptor.serviceNames = { "com.sun.star.sdbcx.IndexDescriptor" }; statics.refl.indexDescriptor.pProps = createPropertyArrayHelper( - indexDef, SAL_N_ELEMENTS(indexDef), 0 ); + indexDef, std::size(indexDef), 0 ); // indexColumn props set statics.refl.indexColumn.implName = "org.openoffice.comp.pq.sdbcx.IndexColumn"; - statics.refl.indexColumn.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.indexColumn.serviceNames[0] = "com.sun.star.sdbcx.IndexColumn"; + statics.refl.indexColumn.serviceNames = { "com.sun.star.sdbcx.IndexColumn" }; PropertyDef indexColumnDef[] = { PropertyDef( statics.CATALOG_NAME , tString ), @@ -427,47 +409,20 @@ Statics & getStatics() PropertyDef( statics.TYPE_NAME , tString ) }; statics.refl.indexColumn.pProps = createPropertyArrayHelper( - indexColumnDef, SAL_N_ELEMENTS(indexColumnDef), READONLY ); + indexColumnDef, std::size(indexColumnDef), READONLY ); // indexColumn props set statics.refl.indexColumnDescriptor.implName = "org.openoffice.comp.pq.sdbcx.IndexColumnDescriptor"; - statics.refl.indexColumnDescriptor.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.indexColumnDescriptor.serviceNames[0] = - "com.sun.star.sdbcx.IndexColumnDescriptor"; + statics.refl.indexColumnDescriptor.serviceNames = + { "com.sun.star.sdbcx.IndexColumnDescriptor" }; PropertyDef indexColumnDescDef[] = { PropertyDef( statics.IS_ASCENDING, tBool ), PropertyDef( statics.NAME , tString ) }; statics.refl.indexColumnDescriptor.pProps = createPropertyArrayHelper( - indexColumnDescDef, SAL_N_ELEMENTS(indexColumnDescDef), 0 ); - - // resultset - statics.refl.resultSet.implName = "org.openoffice.comp.pq.ResultSet"; - statics.refl.resultSet.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.resultSet.serviceNames[0] = "com.sun.star.sdbc.ResultSet"; - statics.refl.resultSet.types = UpdateableResultSet::getStaticTypes( false /* updateable */ ); - PropertyDef resultSet[] = - { - PropertyDef( statics.CURSOR_NAME , tString ), - PropertyDef( statics.ESCAPE_PROCESSING , tBool ), - PropertyDef( statics.FETCH_DIRECTION , tInt ), - PropertyDef( statics.FETCH_SIZE , tInt ), - PropertyDef( statics.IS_BOOKMARKABLE , tBool ), - PropertyDef( statics.RESULT_SET_CONCURRENCY , tInt ), - PropertyDef( statics.RESULT_SET_TYPE , tInt ) - }; - statics.refl.resultSet.pProps = createPropertyArrayHelper( - resultSet, SAL_N_ELEMENTS(resultSet), 0 ); - - // updateableResultset - statics.refl.updateableResultSet.implName = "org.openoffice.comp.pq.UpdateableResultSet"; - statics.refl.updateableResultSet.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.updateableResultSet.serviceNames[0] = "com.sun.star.sdbc.ResultSet"; - statics.refl.updateableResultSet.types = UpdateableResultSet::getStaticTypes( true /* updateable */ ); - statics.refl.updateableResultSet.pProps = createPropertyArrayHelper( - resultSet, SAL_N_ELEMENTS(resultSet), 0 ); + indexColumnDescDef, std::size(indexColumnDescDef), 0 ); // databasemetadata statics.tablesRowNames = std::vector< OUString > ( 5 ); diff --git a/connectivity/source/drivers/postgresql/pq_statics.hxx b/connectivity/source/drivers/postgresql/pq_statics.hxx index 017f49b5a655..4e745e4086ee 100644 --- a/connectivity/source/drivers/postgresql/pq_statics.hxx +++ b/connectivity/source/drivers/postgresql/pq_statics.hxx @@ -34,10 +34,10 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_STATICS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_STATICS_HXX +#pragma once #include <unordered_map> +#include <utility> #include <vector> #include <com/sun/star/uno/Any.hxx> @@ -51,20 +51,20 @@ namespace pq_sdbc_driver struct ColumnMetaData { ColumnMetaData( - const OUString &_columnName, - const OUString &_tableName, - const OUString &_schemaTableName, - const OUString &_typeName, + OUString _columnName, + OUString _tableName, + OUString _schemaTableName, + OUString _typeName, sal_Int32 _type, sal_Int32 _precision, sal_Int32 _scale, bool _isCurrency, bool _isNullable, bool _isAutoIncrement ) : - columnName( _columnName ), - tableName( _tableName ), - schemaTableName( _schemaTableName ), - typeName( _typeName ), + columnName(std::move( _columnName )), + tableName(std::move( _tableName )), + schemaTableName(std::move( _schemaTableName )), + typeName(std::move( _typeName )), type( _type ), precision( _precision ), scale( _scale ), @@ -123,9 +123,6 @@ struct ReflectionImplementations struct ImplementationStatics indexDescriptor; struct ImplementationStatics indexColumn; struct ImplementationStatics indexColumnDescriptor; - - struct ImplementationStatics updateableResultSet; - struct ImplementationStatics resultSet; }; const sal_Int32 TABLE_INDEX_CATALOG = 0; @@ -239,6 +236,5 @@ private: Statics & getStatics(); } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_tools.cxx b/connectivity/source/drivers/postgresql/pq_tools.cxx index 1bb089a5407a..fb42f864f97e 100644 --- a/connectivity/source/drivers/postgresql/pq_tools.cxx +++ b/connectivity/source/drivers/postgresql/pq_tools.cxx @@ -37,6 +37,7 @@ #include <sal/config.h> #include <o3tl/any.hxx> +#include <o3tl/string_view.hxx> #include <rtl/strbuf.hxx> #include <rtl/ustrbuf.hxx> #include <sal/log.hxx> @@ -79,7 +80,6 @@ using com::sun::star::uno::Reference; using com::sun::star::uno::Sequence; using com::sun::star::uno::XInterface; using com::sun::star::uno::Any; -using com::sun::star::uno::makeAny; using com::sun::star::container::XEnumeration; using com::sun::star::container::XEnumerationAccess; @@ -125,7 +125,7 @@ void bufferEscapeConstant( OUStringBuffer & buf, std::u16string_view value, Conn strbuf.setLength( len ); // Previously here RTL_TEXTENCODING_ASCII_US; as we set the PostgreSQL client_encoding to UTF8, // we get UTF8 here, too. I'm not sure why it worked well before... - buf.append( OStringToOUString( strbuf.makeStringAndClear(), RTL_TEXTENCODING_UTF8 ) ); + buf.append( OStringToOUString( strbuf, RTL_TEXTENCODING_UTF8 ) ); } static void ibufferQuoteConstant( OUStringBuffer & buf, std::u16string_view value, ConnectionSettings *settings ) @@ -315,30 +315,30 @@ bool isWhitespace( sal_Unicode c ) return ' ' == c || 9 == c || 10 == c || 13 == c; } -OUString extractTableFromInsert( const OUString & sql ) +OUString extractTableFromInsert( std::u16string_view sql ) { OUString ret; - int i = 0; - while (i < sql.getLength() && isWhitespace(sql[i])) { i++; } + size_t i = 0; + while (i < sql.size() && isWhitespace(sql[i])) { i++; } - if( sql.matchIgnoreAsciiCase("insert", i) ) + if( o3tl::matchIgnoreAsciiCase(sql, u"insert", i) ) { i += 6; - while (i < sql.getLength() && isWhitespace(sql[i])) { i++; } - if( sql.matchIgnoreAsciiCase("into", i) ) + while (i < sql.size() && isWhitespace(sql[i])) { i++; } + if( o3tl::matchIgnoreAsciiCase(sql, u"into", i) ) { i +=4; - while (i < sql.getLength() && isWhitespace(sql[i])) { i++; } + while (i < sql.size() && isWhitespace(sql[i])) { i++; } int start = i; bool quote = (sql[i] == '"'); - for( i++ ; i < sql.getLength() ; i ++ ) + for( i++ ; i < sql.size() ; i ++ ) { if( quote && sql[i] == '"' ) { - while (i < sql.getLength() && isWhitespace(sql[i])) { i++; } + while (i < sql.size() && isWhitespace(sql[i])) { i++; } if( '.' == sql[i] ) { - while (i < sql.getLength() && isWhitespace(sql[i])) { i++; } + while (i < sql.size() && isWhitespace(sql[i])) { i++; } if( '"' == sql[i] ) { // the second part of the table name does not use quotes @@ -361,7 +361,7 @@ OUString extractTableFromInsert( const OUString & sql ) } } } - ret = sql.copy(start, i - start ).trim(); + ret = o3tl::trim(sql.substr(start, i - start )); // printf( "pq_statement: parsed table name %s from insert\n" , // OUStringToOString( ret, RTL_TEXTENCODING_ASCII_US).getStr() ); } @@ -416,7 +416,7 @@ void splitSQL( const OString & sql, std::vector< OString > &vec ) { if( '"' == c ) { - vec.push_back( OString( &sql.getStr()[start], i-start+1 ) ); + vec.emplace_back( &sql.getStr()[start], i-start+1 ); start = i + 1; doubleQuote = false; } @@ -431,7 +431,7 @@ void splitSQL( const OString & sql, std::vector< OString > &vec ) } else if( '\'' == c ) { - vec.push_back( OString( &sql.getStr()[start], i - start +1 ) ); + vec.emplace_back( &sql.getStr()[start], i - start +1 ); start = i + 1; // leave single quotes ! singleQuote = false; } @@ -440,20 +440,20 @@ void splitSQL( const OString & sql, std::vector< OString > &vec ) { if( '"' == c ) { - vec.push_back( OString( &sql.getStr()[start], i - start ) ); + vec.emplace_back( &sql.getStr()[start], i - start ); doubleQuote = true; start = i; } else if( '\'' == c ) { - vec.push_back( OString( &sql.getStr()[start], i - start ) ); + vec.emplace_back( &sql.getStr()[start], i - start ); singleQuote = true; start = i; } } } if( start < i ) - vec.push_back( OString( &sql.getStr()[start] , i - start ) ); + vec.emplace_back( &sql.getStr()[start] , i - start ); // for( i = 0 ; i < vec.size() ; i ++ ) // printf( "%s!" , vec[i].getStr() ); @@ -476,7 +476,7 @@ void tokenizeSQL( const OString & sql, std::vector< OString > &vec ) { if( '"' == c ) { - vec.push_back( OString( &sql.getStr()[start], i-start ) ); + vec.emplace_back( &sql.getStr()[start], i-start ); start = i + 1; doubleQuote = false; } @@ -485,7 +485,7 @@ void tokenizeSQL( const OString & sql, std::vector< OString > &vec ) { if( '\'' == c ) { - vec.push_back( OString( &sql.getStr()[start], i - start +1 ) ); + vec.emplace_back( &sql.getStr()[start], i - start +1 ); start = i + 1; // leave single quotes ! singleQuote = false; } @@ -508,15 +508,15 @@ void tokenizeSQL( const OString & sql, std::vector< OString > &vec ) start ++; // skip additional whitespace else { - vec.push_back( OString( &sql.getStr()[start], i - start ) ); + vec.emplace_back( &sql.getStr()[start], i - start ); start = i +1; } } else if( ',' == c || isOperator( c ) || '(' == c || ')' == c ) { if( i - start ) - vec.push_back( OString( &sql.getStr()[start], i - start ) ); - vec.push_back( OString( &sql.getStr()[i], 1 ) ); + vec.emplace_back( &sql.getStr()[start], i - start ); + vec.emplace_back( &sql.getStr()[i], 1 ); start = i + 1; } else if( '.' == c ) @@ -529,15 +529,15 @@ void tokenizeSQL( const OString & sql, std::vector< OString > &vec ) else { if( i - start ) - vec.push_back( OString( &sql.getStr()[start], i - start ) ); - vec.push_back( OString( "." ) ); + vec.emplace_back( &sql.getStr()[start], i - start ); + vec.emplace_back( "." ); start = i + 1; } } } } if( start < i ) - vec.push_back( OString( &sql.getStr()[start] , i - start ) ); + vec.emplace_back( &sql.getStr()[start] , i - start ); // for( i = 0 ; i < vec.size() ; i ++ ) // printf( "%s!" , vec[i].getStr() ); @@ -596,12 +596,12 @@ OUString array2String( const css::uno::Sequence< Any > &seq ) } -std::vector< Any > parseArray( const OUString & str ) +std::vector< Any > parseArray( std::u16string_view str ) { - int len = str.getLength(); + size_t len = str.size(); bool doubleQuote = false; int brackets = 0; - int i = 0; + size_t i = 0; OUStringBuffer current; std::vector<Any> elements; @@ -644,7 +644,7 @@ std::vector< Any > parseArray( const OUString & str ) if( brackets == 0 ) { if( !current.isEmpty() || doubleQuotedValue ) - elements.push_back( makeAny( current.makeStringAndClear() ) ); + elements.emplace_back( current.makeStringAndClear() ); } else { @@ -673,7 +673,7 @@ std::vector< Any > parseArray( const OUString & str ) else if( ',' == c && brackets == 1) { doubleQuotedValue = false; - elements.push_back( makeAny( current.makeStringAndClear() ) ); + elements.emplace_back( current.makeStringAndClear() ); } else if( isWhitespace( c ) ) { @@ -840,17 +840,17 @@ OUString getColExprForDefaultSettingVal(ConnectionSettings const *settings) OUString("pg_get_expr(pg_attrdef.adbin, pg_attrdef.adrelid, true)"); } -css::uno::Sequence< sal_Int32 > string2intarray( const OUString & str ) +css::uno::Sequence< sal_Int32 > string2intarray( std::u16string_view str ) { css::uno::Sequence< sal_Int32 > ret; - const sal_Int32 strlen = str.getLength(); - if( str.getLength() > 1 ) + const sal_Int32 strlen = str.size(); + if( strlen > 1 ) { sal_Int32 start = 0; sal_uInt32 c; for (;;) { - c = str.iterateCodePoints(&start); + c = o3tl::iterateCodePoints(str, &start); if (!iswspace(c)) break; if ( start == strlen) @@ -860,7 +860,7 @@ css::uno::Sequence< sal_Int32 > string2intarray( const OUString & str ) return ret; for (;;) { - c = str.iterateCodePoints(&start); + c = o3tl::iterateCodePoints(str, &start); if ( !iswspace(c) ) break; if ( start == strlen) @@ -879,7 +879,7 @@ css::uno::Sequence< sal_Int32 > string2intarray( const OUString & str ) break; if ( start == strlen) return ret; - c=str.iterateCodePoints(&start); + c = o3tl::iterateCodePoints(str, &start); } while ( c ); do { @@ -888,20 +888,20 @@ css::uno::Sequence< sal_Int32 > string2intarray( const OUString & str ) if ( start == strlen) return ret; digits.append(OUString(&c, 1)); - c = str.iterateCodePoints(&start); + c = o3tl::iterateCodePoints(str, &start); } while ( c ); - vec.push_back( digits.makeStringAndClear().toInt32() ); + vec.push_back( o3tl::toInt32(digits) ); do { if(!iswspace(c)) break; if ( start == strlen) return ret; - c = str.iterateCodePoints(&start); + c = o3tl::iterateCodePoints(str, &start); } while ( c ); if ( c == L'}' ) break; - if ( str.iterateCodePoints(&start) != L',' ) + if ( o3tl::iterateCodePoints(str, &start) != L',' ) return ret; if ( start == strlen) return ret; @@ -918,11 +918,12 @@ Sequence< OUString > convertMappedIntArray2StringArray( const Int2StringMap &map, const Sequence< sal_Int32 > &intArray ) { Sequence< OUString > ret( intArray.getLength() ); + auto retRange = asNonConstRange(ret); for( int i = 0; i < intArray.getLength() ; i ++ ) { Int2StringMap::const_iterator ii = map.find( intArray[i] ); if( ii != map.end() ) - ret[i] = ii->second; + retRange[i] = ii->second; } return ret; } @@ -942,19 +943,17 @@ OUString sqltype2string( const Reference< XPropertySet > & desc ) case css::sdbc::DataType::VARCHAR: case css::sdbc::DataType::CHAR: { - typeName.append( "(" ); - typeName.append( precision ); - typeName.append( ")" ); + typeName.append( "(" + OUString::number(precision) + ")" ); break; } case css::sdbc::DataType::DECIMAL: case css::sdbc::DataType::NUMERIC: { - typeName.append( "(" ); - typeName.append( precision ); - typeName.append( "," ); - typeName.append( extractIntProperty( desc, getStatics().SCALE ) ); - typeName.append( ")" ); + typeName.append( "(" + + OUString::number(precision) + + "," + + OUString::number(extractIntProperty( desc, getStatics().SCALE )) + + ")" ); break; } default: diff --git a/connectivity/source/drivers/postgresql/pq_tools.hxx b/connectivity/source/drivers/postgresql/pq_tools.hxx index 6d11e9b40425..c5f9174111ca 100644 --- a/connectivity/source/drivers/postgresql/pq_tools.hxx +++ b/connectivity/source/drivers/postgresql/pq_tools.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_TOOLS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_TOOLS_HXX +#pragma once #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/sdbc/XParameters.hpp> @@ -107,7 +106,7 @@ bool extractBoolProperty( void disposeNoThrow( const css::uno::Reference< css::uno::XInterface > & r ); void disposeObject( const css::uno::Reference< css::uno::XInterface > & r ); -OUString extractTableFromInsert( const OUString & sql ); +OUString extractTableFromInsert( std::u16string_view sql ); OString extractSingleTableFromSelect( const std::vector< OString > &vec ); OUString getColExprForDefaultSettingVal(ConnectionSettings const *settings); @@ -116,7 +115,7 @@ void tokenizeSQL( const OString & sql, std::vector< OString > &vec ); void splitSQL( const OString & sql, std::vector< OString > &vec ); std::vector< sal_Int32 > parseIntArray( const OUString & str ); /// @throws css::sdbc::SQLException -std::vector< css::uno::Any > parseArray( const OUString & str ); +std::vector< css::uno::Any > parseArray( std::u16string_view str ); OUString array2String( const css::uno::Sequence< css::uno::Any > &seq ); @@ -132,7 +131,7 @@ void fillAttnum2attnameMap( const OUString &schema, const OUString &table ); -css::uno::Sequence< sal_Int32 > string2intarray( const OUString & str ); +css::uno::Sequence< sal_Int32 > string2intarray( std::u16string_view str ); css::uno::Sequence< OUString > convertMappedIntArray2StringArray( const Int2StringMap &map, const css::uno::Sequence< sal_Int32> &source ); @@ -174,6 +173,4 @@ public: } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_updateableresultset.cxx b/connectivity/source/drivers/postgresql/pq_updateableresultset.cxx index d8780e76c563..49eb65cd9fbf 100644 --- a/connectivity/source/drivers/postgresql/pq_updateableresultset.cxx +++ b/connectivity/source/drivers/postgresql/pq_updateableresultset.cxx @@ -35,6 +35,7 @@ ************************************************************************/ #include <sal/log.hxx> +#include <rtl/ref.hxx> #include <rtl/ustrbuf.hxx> #include <cppuhelper/queryinterface.hxx> @@ -88,7 +89,7 @@ css::uno::Reference< css::sdbc::XCloseable > UpdateableResultSet::createFromPGRe PGresult *result, const OUString &schema, const OUString &table, - const std::vector< OUString > &primaryKey ) + std::vector< OUString > && primaryKey ) { sal_Int32 columnCount = PQnfields( result ); sal_Int32 rowCount = PQntuples( result ); @@ -118,16 +119,14 @@ css::uno::Reference< css::sdbc::XCloseable > UpdateableResultSet::createFromPGRe data[row] = aRow; } - UpdateableResultSet *pRS = new UpdateableResultSet( - mutex, owner, columnNames, data, ppSettings, schema, table, primaryKey ); - - Reference <XCloseable > ret = pRS; // give it a refcount + rtl::Reference<UpdateableResultSet> pRS = new UpdateableResultSet( + mutex, owner, std::move(columnNames), std::move(data), ppSettings, schema, table, std::move(primaryKey) ); pRS->m_meta = new ResultSetMetaData( mutex, pRS,nullptr, ppSettings, result, schema, table ); PQclear( result ); // we don't need it anymore - return ret; + return pRS; } css::uno::Any UpdateableResultSet::queryInterface( @@ -297,8 +296,8 @@ void UpdateableResultSet::updateRow( ) buf.append( ", " ); columns ++; - buf.append( m_columnNames[i] ); - buf.append( " = " ); + buf.append( m_columnNames[i] + + " = " ); bufferQuoteAnyConstant( buf, m_updateableField[i].value, *m_ppSettings ); // OUString val; // m_updateableField[i].value >>= val; @@ -343,8 +342,8 @@ void UpdateableResultSet::deleteRow( ) OUStringBuffer buf( 128 ); buf.append( "DELETE FROM " ); bufferQuoteQualifiedIdentifier( buf, m_schema, m_table, *m_ppSettings ); - buf.append( " " ); - buf.append( buildWhereClause() ); + buf.append( " " + + buildWhereClause() ); stmt->executeUpdate( buf.makeStringAndClear() ); diff --git a/connectivity/source/drivers/postgresql/pq_updateableresultset.hxx b/connectivity/source/drivers/postgresql/pq_updateableresultset.hxx index feb3f53225d5..52cb513a5856 100644 --- a/connectivity/source/drivers/postgresql/pq_updateableresultset.hxx +++ b/connectivity/source/drivers/postgresql/pq_updateableresultset.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_UPDATEABLERESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_UPDATEABLERESULTSET_HXX +#pragma once #include "pq_sequenceresultset.hxx" #include "pq_resultsetmetadata.hxx" @@ -45,6 +44,7 @@ #include <com/sun/star/sdbc/ResultSetType.hpp> #include <com/sun/star/sdbc/XResultSetUpdate.hpp> #include <com/sun/star/sdbc/XRowUpdate.hpp> +#include <utility> namespace pq_sdbc_driver { @@ -76,17 +76,17 @@ private: UpdateableResultSet( const ::rtl::Reference< comphelper::RefCountedMutex > & mutex, const css::uno::Reference< css::uno::XInterface > &owner, - const std::vector< OUString > &colNames, - const std::vector< std::vector< css::uno::Any > > &data, + std::vector< OUString >&& colNames, + std::vector< std::vector< css::uno::Any > >&& data, ConnectionSettings **ppSettings, - const OUString &schema, - const OUString &table, - const std::vector< OUString > &primaryKey) - : SequenceResultSet( mutex, owner, colNames, data, (*ppSettings)->tc ), + OUString schema, + OUString table, + std::vector< OUString >&& primaryKey) + : SequenceResultSet( mutex, owner, std::move(colNames), std::move(data), (*ppSettings)->tc ), m_ppSettings( ppSettings ), - m_schema( schema ), - m_table( table ), - m_primaryKey( primaryKey ), + m_schema(std::move( schema )), + m_table(std::move( table )), + m_primaryKey( std::move(primaryKey) ), m_insertRow( false ) { // LEM TODO: this duplicates code in pq_resultset.cxx, except for different value @@ -119,11 +119,11 @@ public: PGresult *result, const OUString &schema, const OUString &table, - const std::vector< OUString > &primaryKey ); + std::vector< OUString > && primaryKey ); public: // XInterface - virtual void SAL_CALL acquire() throw() override { SequenceResultSet::acquire(); } - virtual void SAL_CALL release() throw() override { SequenceResultSet::release(); } + virtual void SAL_CALL acquire() noexcept override { SequenceResultSet::acquire(); } + virtual void SAL_CALL release() noexcept override { SequenceResultSet::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -167,6 +167,4 @@ public: } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_UPDATEABLERESULTSET_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xbase.cxx b/connectivity/source/drivers/postgresql/pq_xbase.cxx index 1fec4130a9db..001046aa52fa 100644 --- a/connectivity/source/drivers/postgresql/pq_xbase.cxx +++ b/connectivity/source/drivers/postgresql/pq_xbase.cxx @@ -36,7 +36,9 @@ #include <cppuhelper/supportsservice.hxx> #include <comphelper/sequence.hxx> +#include <utility> +#include "pq_statics.hxx" #include "pq_tools.hxx" #include "pq_xbase.hxx" @@ -55,18 +57,18 @@ namespace pq_sdbc_driver { ReflectionBase::ReflectionBase( - const OUString &implName, + OUString implName, const css::uno::Sequence< OUString > &supportedServices, const ::rtl::Reference< comphelper::RefCountedMutex >& refMutex, - const css::uno::Reference< css::sdbc::XConnection > &conn, + css::uno::Reference< css::sdbc::XConnection > conn, ConnectionSettings *pSettings, cppu::IPropertyArrayHelper & props /* must survive this object !*/ ) : ReflectionBase_BASE( refMutex->GetMutex() ), OPropertySetHelper( ReflectionBase_BASE::rBHelper ), - m_implName( implName ), + m_implName(std::move( implName )), m_supportedServices( supportedServices ), m_xMutex( refMutex ), - m_conn( conn ), + m_conn(std::move( conn )), m_pSettings( pSettings ), m_propsDesc( props ), m_values( props.getProperties().getLength() ) diff --git a/connectivity/source/drivers/postgresql/pq_xbase.hxx b/connectivity/source/drivers/postgresql/pq_xbase.hxx index 6e7ac8413f47..e4ca16fd5e6a 100644 --- a/connectivity/source/drivers/postgresql/pq_xbase.hxx +++ b/connectivity/source/drivers/postgresql/pq_xbase.hxx @@ -34,10 +34,8 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XBASE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XBASE_HXX +#pragma once #include <cppuhelper/propshlp.hxx> -#include <cppuhelper/component.hxx> #include <cppuhelper/compbase.hxx> #include <com/sun/star/lang/XServiceInfo.hpp> @@ -67,10 +65,10 @@ protected: std::vector< css::uno::Any > m_values; public: ReflectionBase( - const OUString &implName, + OUString implName, const css::uno::Sequence< OUString > &supportedServices, const ::rtl::Reference< comphelper::RefCountedMutex >& refMutex, - const css::uno::Reference< css::sdbc::XConnection > &conn, + css::uno::Reference< css::sdbc::XConnection > conn, ConnectionSettings *pSettings, cppu::IPropertyArrayHelper & props /* must survive this object !*/ ); @@ -82,8 +80,8 @@ public: // for initialization purposes only, not exported via an interface ! const OUString & name, const css::uno::Any & value ); public: //XInterface - virtual void SAL_CALL acquire() throw() override { ReflectionBase_BASE::acquire(); } - virtual void SAL_CALL release() throw() override { ReflectionBase_BASE::release(); } + virtual void SAL_CALL acquire() noexcept override { ReflectionBase_BASE::acquire(); } + virtual void SAL_CALL release() noexcept override { ReflectionBase_BASE::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -129,6 +127,5 @@ public: // XNamed }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xcolumn.cxx b/connectivity/source/drivers/postgresql/pq_xcolumn.cxx index c6d98b0fcb85..b19d95c3c994 100644 --- a/connectivity/source/drivers/postgresql/pq_xcolumn.cxx +++ b/connectivity/source/drivers/postgresql/pq_xcolumn.cxx @@ -34,6 +34,11 @@ * ************************************************************************/ +#include <sal/config.h> + +#include <rtl/ref.hxx> + +#include "pq_statics.hxx" #include "pq_xcolumn.hxx" using com::sun::star::uno::Reference; @@ -56,7 +61,7 @@ Column::Column( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex Reference< XPropertySet > Column::createDataDescriptor( ) { - ColumnDescriptor * pColumn = new ColumnDescriptor( + rtl::Reference<ColumnDescriptor> pColumn = new ColumnDescriptor( m_xMutex, m_conn, m_pSettings ); pColumn->copyValuesFrom( this ); return Reference< XPropertySet > ( pColumn ); @@ -77,7 +82,7 @@ ColumnDescriptor::ColumnDescriptor( Reference< XPropertySet > ColumnDescriptor::createDataDescriptor( ) { - ColumnDescriptor * pColumn = new ColumnDescriptor( + rtl::Reference<ColumnDescriptor> pColumn = new ColumnDescriptor( m_xMutex, m_conn, m_pSettings ); pColumn->copyValuesFrom( this ); diff --git a/connectivity/source/drivers/postgresql/pq_xcolumn.hxx b/connectivity/source/drivers/postgresql/pq_xcolumn.hxx index ea4e099fcd2b..794b5851d3c7 100644 --- a/connectivity/source/drivers/postgresql/pq_xcolumn.hxx +++ b/connectivity/source/drivers/postgresql/pq_xcolumn.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XCOLUMN_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XCOLUMN_HXX +#pragma once #include <cppuhelper/component.hxx> #include <cppuhelper/propshlp.hxx> @@ -80,6 +79,4 @@ public: // XDataDescriptorFactory } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xcolumns.cxx b/connectivity/source/drivers/postgresql/pq_xcolumns.cxx index ed3af3579d2a..2902879c49b0 100644 --- a/connectivity/source/drivers/postgresql/pq_xcolumns.cxx +++ b/connectivity/source/drivers/postgresql/pq_xcolumns.cxx @@ -34,6 +34,13 @@ * ************************************************************************/ +#include <sal/config.h> + +#include <string_view> + +#include <o3tl/safeint.hxx> +#include <o3tl/string_view.hxx> +#include <rtl/ref.hxx> #include <rtl/ustrbuf.hxx> #include <sal/log.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> @@ -43,6 +50,7 @@ #include <com/sun/star/sdbc/ColumnValue.hpp> #include <cppuhelper/exc_hlp.hxx> +#include <utility> #include "pq_xcolumns.hxx" #include "pq_xcolumn.hxx" @@ -55,7 +63,6 @@ using osl::MutexGuard; using com::sun::star::beans::XPropertySet; using com::sun::star::uno::Any; -using com::sun::star::uno::makeAny; using com::sun::star::uno::UNO_QUERY; using com::sun::star::uno::Reference; using com::sun::star::uno::RuntimeException; @@ -69,9 +76,9 @@ using com::sun::star::sdbc::SQLException; namespace pq_sdbc_driver { -static Any isCurrency( const OUString & typeName ) +static Any isCurrency( std::u16string_view typeName ) { - return Any( typeName.equalsIgnoreAsciiCase("money") ); + return Any( o3tl::equalsIgnoreAsciiCase(typeName, u"money") ); } // static sal_Bool isAutoIncrement8( const OUString & typeName ) @@ -80,9 +87,9 @@ static Any isCurrency( const OUString & typeName ) // typeName.equalsIgnoreAsciiCase("bigserial"); // } -static Any isAutoIncrement( const OUString & defaultValue ) +static Any isAutoIncrement( std::u16string_view defaultValue ) { - bool ret = defaultValue.startsWith( "nextval(" ); + bool ret = o3tl::starts_with( defaultValue, u"nextval(" ); // printf( "%s %d\n", // OUStringToOString(defaultValue, RTL_TEXTENCODING_ASCII_US).getStr(), // ret ); @@ -103,11 +110,11 @@ Columns::Columns( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName) + OUString schemaName, + OUString tableName) : Container( refMutex, origin, pSettings, "COLUMN" ), - m_schemaName( schemaName ), - m_tableName( tableName ) + m_schemaName(std::move( schemaName )), + m_tableName(std::move( tableName )) {} Columns::~Columns() @@ -179,25 +186,25 @@ OUString columnMetaData2SDBCX( OUString typeName = xRow->getString( TYPE_NAME ); pBase->setPropertyValue_NoBroadcast_public( - st.NAME, makeAny( name ) ); + st.NAME, Any( name ) ); pBase->setPropertyValue_NoBroadcast_public( - st.TYPE, makeAny( xRow->getInt( DATA_TYPE ) ) ); + st.TYPE, Any( xRow->getInt( DATA_TYPE ) ) ); pBase->setPropertyValue_NoBroadcast_public( - st.TYPE_NAME, makeAny( typeName ) ); + st.TYPE_NAME, Any( typeName ) ); pBase->setPropertyValue_NoBroadcast_public( - st.PRECISION, makeAny( xRow->getInt( COLUMN_SIZE ) ) ); + st.PRECISION, Any( xRow->getInt( COLUMN_SIZE ) ) ); pBase->setPropertyValue_NoBroadcast_public( - st.SCALE, makeAny( xRow->getInt( DECIMAL_DIGITS ) ) ); + st.SCALE, Any( xRow->getInt( DECIMAL_DIGITS ) ) ); pBase->setPropertyValue_NoBroadcast_public( - st.IS_NULLABLE, makeAny( xRow->getInt( IS_NULLABLE ) ) ); + st.IS_NULLABLE, Any( xRow->getInt( IS_NULLABLE ) ) ); pBase->setPropertyValue_NoBroadcast_public( - st.DEFAULT_VALUE, makeAny( xRow->getString( DEFAULT_VALUE ) ) ); + st.DEFAULT_VALUE, Any( xRow->getString( DEFAULT_VALUE ) ) ); // pBase->setPropertyValue_NoBroadcast_public( // st.DESCRIPTION, makeAny( xRow->getString( DESCRIPTION ) ) ); @@ -207,7 +214,7 @@ OUString columnMetaData2SDBCX( // st.HELP_TEXT, makeAny( xRow->getString( DESCRIPTION ) ) ); // else // for key columns, etc. ... pBase->setPropertyValue_NoBroadcast_public( - st.DESCRIPTION, makeAny( xRow->getString( DESCRIPTION ) ) ); + st.DESCRIPTION, Any( xRow->getString( DESCRIPTION ) ) ); // maybe a better criterion than the type name can be found in future @@ -294,11 +301,11 @@ void Columns::refresh() int columnIndex = 0; while( rs->next() ) { - Column * pColumn = + rtl::Reference<Column> pColumn = new Column( m_xMutex, m_origin, m_pSettings ); Reference< css::beans::XPropertySet > prop = pColumn; - OUString name = columnMetaData2SDBCX( pColumn, xRow ); + OUString name = columnMetaData2SDBCX( pColumn.get(), xRow ); // pColumn->addPropertyChangeListener( // st.HELP_TEXT, // new CommentChanger( @@ -310,7 +317,7 @@ void Columns::refresh() // name ) ); { - m_values.push_back( makeAny( prop ) ); + m_values.emplace_back(prop); map[ name ] = columnIndex; ++columnIndex; } @@ -399,11 +406,10 @@ void alterColumnByDescriptor( bufferQuoteQualifiedIdentifier( buf, schemaName, tableName, settings ); buf.append( "ALTER COLUMN" ); bufferQuoteIdentifier( buf, futureColumnName, settings ); - buf.append( "SET DEFAULT " ); // LEM TODO: check out // default value is not quoted, caller needs to quote himself (otherwise // how to pass e.g. nextval('something' ) ???? - buf.append( futureDefaultValue ); + buf.append( "SET DEFAULT " + futureDefaultValue ); // bufferQuoteConstant( buf, defaultValue, encoding ); transaction.executeUpdate( buf.makeStringAndClear() ); } @@ -455,7 +461,7 @@ void Columns::appendByDescriptor( osl::MutexGuard guard( m_xMutex->GetMutex() ); Statics & st = getStatics(); Reference< XPropertySet > past = createDataDescriptor(); - past->setPropertyValue( st.IS_NULLABLE, makeAny( css::sdbc::ColumnValue::NULLABLE ) ); + past->setPropertyValue( st.IS_NULLABLE, Any( css::sdbc::ColumnValue::NULLABLE ) ); alterColumnByDescriptor( m_schemaName, m_tableName, m_pSettings, m_origin->createStatement() , past, future ); @@ -487,7 +493,7 @@ void Columns::appendByDescriptor( void Columns::dropByIndex( sal_Int32 index ) { osl::MutexGuard guard( m_xMutex->GetMutex() ); - if( index < 0 || index >= static_cast<sal_Int32>(m_values.size()) ) + if( index < 0 || o3tl::make_unsigned(index) >= m_values.size() ) { throw css::lang::IndexOutOfBoundsException( "COLUMNS: Index out of range (allowed 0 to " @@ -526,14 +532,13 @@ Reference< css::container::XNameAccess > Columns::create( ConnectionSettings *pSettings, const OUString &schemaName, const OUString &tableName, - Columns **ppColumns) + rtl::Reference<Columns> *ppColumns) { *ppColumns = new Columns( refMutex, origin, pSettings, schemaName, tableName ); - Reference< css::container::XNameAccess > ret = *ppColumns; (*ppColumns)->refresh(); - return ret; + return *ppColumns; } diff --git a/connectivity/source/drivers/postgresql/pq_xcolumns.hxx b/connectivity/source/drivers/postgresql/pq_xcolumns.hxx index 78bb9770ebdf..8ff8fcfbd95c 100644 --- a/connectivity/source/drivers/postgresql/pq_xcolumns.hxx +++ b/connectivity/source/drivers/postgresql/pq_xcolumns.hxx @@ -34,13 +34,14 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XCOLUMNS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XCOLUMNS_HXX +#pragma once #include <sal/config.h> #include <string_view> +#include <rtl/ref.hxx> + #include "pq_xcontainer.hxx" #include "pq_xbase.hxx" @@ -72,15 +73,15 @@ public: // instances Columns 'exception safe' ConnectionSettings *pSettings, const OUString &schemaName, const OUString &tableName, - Columns **pColumns); + rtl::Reference<Columns> *pColumns); private: Columns( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName); + OUString schemaName, + OUString tableName); virtual ~Columns() override; @@ -117,6 +118,5 @@ public: // XDataDescriptorFactory }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xcontainer.cxx b/connectivity/source/drivers/postgresql/pq_xcontainer.cxx index 06323615f4b7..131148c3e192 100644 --- a/connectivity/source/drivers/postgresql/pq_xcontainer.cxx +++ b/connectivity/source/drivers/postgresql/pq_xcontainer.cxx @@ -36,7 +36,10 @@ #include <com/sun/star/container/ElementExistException.hpp> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> +#include <comphelper/diagnose_ex.hxx> #include <cppuhelper/implbase.hxx> +#include <o3tl/safeint.hxx> +#include <utility> #include "pq_xcontainer.hxx" #include "pq_statics.hxx" @@ -47,7 +50,6 @@ using osl::MutexGuard; using com::sun::star::beans::XPropertySet; using com::sun::star::uno::Any; -using com::sun::star::uno::makeAny; using com::sun::star::uno::Type; using com::sun::star::uno::XInterface; using com::sun::star::uno::Reference; @@ -76,7 +78,7 @@ public: const OUString & name, const Any & newElement, const OUString & oldElement ) : - m_event( source, makeAny( name ), newElement, makeAny(oldElement) ) + m_event( source, Any( name ), newElement, Any(oldElement) ) {} virtual void fire( XEventListener * listener ) const override @@ -97,7 +99,7 @@ public: const Reference< XInterface > & source, const OUString & name, const Any & newElement ) : - m_event( source, makeAny( name ), newElement, Any() ) + m_event( source, Any( name ), newElement, Any() ) {} virtual void fire( XEventListener * listener ) const override @@ -118,7 +120,7 @@ public: RemovedBroadcaster( const Reference< XInterface > & source, const OUString & name) : - m_event( source, makeAny( name ), Any(), Any() ) + m_event( source, Any( name ), Any(), Any() ) {} virtual void fire( XEventListener * listener ) const override @@ -136,14 +138,14 @@ public: Container::Container( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, - const css::uno::Reference< css::sdbc::XConnection > & origin, + css::uno::Reference< css::sdbc::XConnection > origin, ConnectionSettings *pSettings, - const OUString &type) + OUString type) : ContainerBase( refMutex->GetMutex() ), m_xMutex( refMutex ), m_pSettings( pSettings ), - m_origin( origin ), - m_type( type ) + m_origin(std::move( origin )), + m_type(std::move( type )) { } @@ -156,17 +158,18 @@ Any Container::getByName( const OUString& aName ) "Element " + aName + " unknown in " + m_type + "-Container", *this ); } - OSL_ASSERT( ii->second >= 0 && ii->second < static_cast<int>(m_values.size()) ); + OSL_ASSERT( ii->second >= 0 && o3tl::make_unsigned(ii->second) < m_values.size() ); return m_values[ ii->second ]; } Sequence< OUString > Container::getElementNames( ) { Sequence< OUString > ret( m_values.size() ); + auto retRange = asNonConstRange(ret); for( const auto& [rName, rIndex] : m_name2index ) { // give element names in index order ! - ret[rIndex] = rName; + retRange[rIndex] = rName; } return ret; } @@ -188,7 +191,7 @@ sal_Bool Container::hasElements( ) Any Container::getByIndex( sal_Int32 Index ) { - if( Index < 0 || Index >= static_cast<sal_Int32>(m_values.size()) ) + if( Index < 0 || o3tl::make_unsigned(Index) >= m_values.size() ) { throw IndexOutOfBoundsException( "Index " + OUString::number( Index ) @@ -211,8 +214,8 @@ class ContainerEnumeration : public ::cppu::WeakImplHelper< XEnumeration > std::vector< css::uno::Any > m_vec; sal_Int32 m_index; public: - explicit ContainerEnumeration( const std::vector< css::uno::Any > &vec ) - : m_vec( vec ), + explicit ContainerEnumeration( std::vector< css::uno::Any >&& vec ) + : m_vec( std::move(vec) ), m_index( -1 ) {} @@ -243,7 +246,7 @@ css::uno::Any ContainerEnumeration::nextElement() Reference< XEnumeration > Container::createEnumeration( ) { - return new ContainerEnumeration( m_values ); + return new ContainerEnumeration( std::vector(m_values) ); } void Container::addRefreshListener( @@ -298,7 +301,7 @@ void Container::dropByName( const OUString& elementName ) void Container::dropByIndex( sal_Int32 index ) { osl::MutexGuard guard( m_xMutex->GetMutex() ); - if( index < 0 || index >=static_cast<sal_Int32>(m_values.size()) ) + if( index < 0 || o3tl::make_unsigned(index) >=m_values.size() ) { throw css::lang::IndexOutOfBoundsException( "Index out of range (allowed 0 to " @@ -349,10 +352,10 @@ void Container::append( } int index = m_values.size(); - m_values.push_back( makeAny( descriptor ) ); + m_values.emplace_back(descriptor); m_name2index[name] = index; - fire( InsertedBroadcaster( *this, name, makeAny( descriptor ) ) ); + fire( InsertedBroadcaster( *this, name, Any( descriptor ) ) ); } void Container::appendByDescriptor( @@ -390,13 +393,13 @@ void Container::fire( const EventBroadcastHelper &helper ) } catch ( css::uno::RuntimeException & ) { - OSL_ENSURE( false, "exception caught" ); + TOOLS_WARN_EXCEPTION( "connectivity.postgresql", "exception caught" ); // loose coupling, a runtime exception shall not break anything // TODO: log away as warning ! } catch( css::uno::Exception & ) { - OSL_ENSURE( false, "exception from listener flying through" ); + TOOLS_WARN_EXCEPTION( "connectivity.postgresql", "exception from listener flying through" ); throw; } } diff --git a/connectivity/source/drivers/postgresql/pq_xcontainer.hxx b/connectivity/source/drivers/postgresql/pq_xcontainer.hxx index f53b0303ae1b..4b6c190b0a59 100644 --- a/connectivity/source/drivers/postgresql/pq_xcontainer.hxx +++ b/connectivity/source/drivers/postgresql/pq_xcontainer.hxx @@ -34,29 +34,30 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XCONTAINER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XCONTAINER_HXX +#pragma once #include <com/sun/star/container/XNameAccess.hpp> #include <com/sun/star/container/XIndexAccess.hpp> #include <com/sun/star/container/XEnumerationAccess.hpp> #include <com/sun/star/container/XContainer.hpp> +#include <com/sun/star/sdbc/XConnection.hpp> #include <com/sun/star/sdbcx/XAppend.hpp> #include <com/sun/star/sdbcx/XDrop.hpp> #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp> #include <com/sun/star/util/XRefreshable.hpp> +#include <comphelper/refcountedmutex.hxx> #include <cppuhelper/compbase.hxx> +#include <rtl/ref.hxx> #include <unordered_map> -#include "pq_connection.hxx" -#include "pq_statics.hxx" - namespace pq_sdbc_driver { +struct ConnectionSettings; + class EventBroadcastHelper { public: @@ -116,9 +117,9 @@ protected: public: Container( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, - const css::uno::Reference< css::sdbc::XConnection > & origin, + css::uno::Reference< css::sdbc::XConnection > origin, ConnectionSettings *pSettings, - const OUString & type // for exception messages + OUString type // for exception messages ); public: // XIndexAccess @@ -183,6 +184,5 @@ protected: }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xindex.cxx b/connectivity/source/drivers/postgresql/pq_xindex.cxx index c340484a17df..4753b5fd4e3c 100644 --- a/connectivity/source/drivers/postgresql/pq_xindex.cxx +++ b/connectivity/source/drivers/postgresql/pq_xindex.cxx @@ -36,6 +36,8 @@ #include <cppuhelper/typeprovider.hxx> #include <cppuhelper/queryinterface.hxx> +#include <rtl/ref.hxx> +#include <utility> #include "pq_xindex.hxx" #include "pq_xindexcolumns.hxx" @@ -57,8 +59,8 @@ namespace pq_sdbc_driver Index::Index( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const Reference< css::sdbc::XConnection > & connection, ConnectionSettings *pSettings, - const OUString & schemaName, - const OUString & tableName ) + OUString schemaName, + OUString tableName ) : ReflectionBase( getStatics().refl.index.implName, getStatics().refl.index.serviceNames, @@ -66,13 +68,13 @@ Index::Index( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, connection, pSettings, * getStatics().refl.index.pProps ), - m_schemaName( schemaName ), - m_tableName( tableName ) + m_schemaName(std::move( schemaName )), + m_tableName(std::move( tableName )) {} Reference< XPropertySet > Index::createDataDescriptor( ) { - IndexDescriptor * pIndex = new IndexDescriptor( + rtl::Reference<IndexDescriptor> pIndex = new IndexDescriptor( m_xMutex, m_conn, m_pSettings ); pIndex->copyValuesFrom( this ); @@ -133,7 +135,7 @@ IndexDescriptor::IndexDescriptor( Reference< XPropertySet > IndexDescriptor::createDataDescriptor( ) { - IndexDescriptor * pIndex = new IndexDescriptor( + rtl::Reference<IndexDescriptor> pIndex = new IndexDescriptor( m_xMutex, m_conn, m_pSettings ); pIndex->copyValuesFrom( this ); return Reference< XPropertySet > ( pIndex ); diff --git a/connectivity/source/drivers/postgresql/pq_xindex.hxx b/connectivity/source/drivers/postgresql/pq_xindex.hxx index 26e5613630a2..8ccf45660467 100644 --- a/connectivity/source/drivers/postgresql/pq_xindex.hxx +++ b/connectivity/source/drivers/postgresql/pq_xindex.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XINDEX_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XINDEX_HXX +#pragma once #include <cppuhelper/component.hxx> #include <cppuhelper/propshlp.hxx> @@ -62,12 +61,12 @@ public: Index( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & connection, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName); + OUString schemaName, + OUString tableName); public: // XInterface - virtual void SAL_CALL acquire() throw() override { ReflectionBase::acquire(); } - virtual void SAL_CALL release() throw() override { ReflectionBase::release(); } + virtual void SAL_CALL acquire() noexcept override { ReflectionBase::acquire(); } + virtual void SAL_CALL release() noexcept override { ReflectionBase::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -98,8 +97,8 @@ public: ConnectionSettings *pSettings); public: // XInterface - virtual void SAL_CALL acquire() throw() override { ReflectionBase::acquire(); } - virtual void SAL_CALL release() throw() override { ReflectionBase::release(); } + virtual void SAL_CALL acquire() noexcept override { ReflectionBase::acquire(); } + virtual void SAL_CALL release() noexcept override { ReflectionBase::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -121,6 +120,4 @@ public: // XDataDescriptorFactory } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xindexcolumn.cxx b/connectivity/source/drivers/postgresql/pq_xindexcolumn.cxx index 58b36234b1fb..fe72059bc15a 100644 --- a/connectivity/source/drivers/postgresql/pq_xindexcolumn.cxx +++ b/connectivity/source/drivers/postgresql/pq_xindexcolumn.cxx @@ -34,6 +34,11 @@ * ************************************************************************/ +#include <sal/config.h> + +#include <rtl/ref.hxx> + +#include "pq_statics.hxx" #include "pq_xindexcolumn.hxx" using com::sun::star::uno::Reference; @@ -56,7 +61,7 @@ IndexColumn::IndexColumn( const ::rtl::Reference< comphelper::RefCountedMutex > Reference< XPropertySet > IndexColumn::createDataDescriptor( ) { - IndexColumnDescriptor * pIndexColumn = new IndexColumnDescriptor( + rtl::Reference<IndexColumnDescriptor> pIndexColumn = new IndexColumnDescriptor( m_xMutex, m_conn, m_pSettings ); pIndexColumn->copyValuesFrom( this ); @@ -79,7 +84,7 @@ IndexColumnDescriptor::IndexColumnDescriptor( Reference< XPropertySet > IndexColumnDescriptor::createDataDescriptor( ) { - IndexColumnDescriptor * pIndexColumn = new IndexColumnDescriptor( + rtl::Reference<IndexColumnDescriptor> pIndexColumn = new IndexColumnDescriptor( m_xMutex, m_conn, m_pSettings ); pIndexColumn->copyValuesFrom( this ); diff --git a/connectivity/source/drivers/postgresql/pq_xindexcolumn.hxx b/connectivity/source/drivers/postgresql/pq_xindexcolumn.hxx index 5e7ae8d4fa65..7872985ec801 100644 --- a/connectivity/source/drivers/postgresql/pq_xindexcolumn.hxx +++ b/connectivity/source/drivers/postgresql/pq_xindexcolumn.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XINDEXCOLUMN_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XINDEXCOLUMN_HXX +#pragma once #include <cppuhelper/component.hxx> #include <cppuhelper/propshlp.hxx> @@ -81,6 +80,4 @@ public: // XDataDescriptorFactory } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xindexcolumns.cxx b/connectivity/source/drivers/postgresql/pq_xindexcolumns.cxx index a16d22d0cf2f..2bca00e13b77 100644 --- a/connectivity/source/drivers/postgresql/pq_xindexcolumns.cxx +++ b/connectivity/source/drivers/postgresql/pq_xindexcolumns.cxx @@ -37,12 +37,14 @@ #include <sal/log.hxx> #include <string_view> +#include <utility> #include <vector> #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/sdbc/SQLException.hpp> #include <com/sun/star/sdbc/XRow.hpp> #include <cppuhelper/exc_hlp.hxx> +#include <rtl/ref.hxx> #include "pq_xcolumns.hxx" #include "pq_xindexcolumns.hxx" @@ -55,7 +57,6 @@ using osl::MutexGuard; using com::sun::star::beans::XPropertySet; using com::sun::star::uno::Any; -using com::sun::star::uno::makeAny; using com::sun::star::uno::UNO_QUERY; using com::sun::star::uno::Reference; using com::sun::star::uno::Sequence; @@ -72,14 +73,14 @@ IndexColumns::IndexColumns( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName, - const OUString &indexName, + OUString schemaName, + OUString tableName, + OUString indexName, const css::uno::Sequence< OUString > &columns ) : Container( refMutex, origin, pSettings, "INDEX_COLUMN" ), - m_schemaName( schemaName ), - m_tableName( tableName ), - m_indexName( indexName ), + m_schemaName(std::move( schemaName )), + m_tableName(std::move( tableName )), + m_indexName(std::move( indexName )), m_columns( columns ) {} @@ -124,13 +125,13 @@ void IndexColumns::refresh() if( index >= m_columns.getLength() ) continue; - IndexColumn * pIndexColumn = + rtl::Reference<IndexColumn> pIndexColumn = new IndexColumn( m_xMutex, m_origin, m_pSettings ); Reference< css::beans::XPropertySet > prop = pIndexColumn; - columnMetaData2SDBCX( pIndexColumn, xRow ); + columnMetaData2SDBCX( pIndexColumn.get(), xRow ); pIndexColumn->setPropertyValue_NoBroadcast_public( - st.IS_ASCENDING , makeAny( false ) ); + st.IS_ASCENDING , Any( false ) ); m_values[ index ] <<= prop; m_name2index[ columnName ] = index; @@ -234,12 +235,11 @@ Reference< css::container::XNameAccess > IndexColumns::create( const OUString &indexName, const Sequence< OUString > &columns ) { - IndexColumns *pIndexColumns = new IndexColumns( + rtl::Reference<IndexColumns> pIndexColumns = new IndexColumns( refMutex, origin, pSettings, schemaName, tableName, indexName, columns ); - Reference< css::container::XNameAccess > ret = pIndexColumns; pIndexColumns->refresh(); - return ret; + return pIndexColumns; } diff --git a/connectivity/source/drivers/postgresql/pq_xindexcolumns.hxx b/connectivity/source/drivers/postgresql/pq_xindexcolumns.hxx index 353b75ddbf63..a838d5d66908 100644 --- a/connectivity/source/drivers/postgresql/pq_xindexcolumns.hxx +++ b/connectivity/source/drivers/postgresql/pq_xindexcolumns.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XINDEXCOLUMNS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XINDEXCOLUMNS_HXX +#pragma once #include "pq_xcontainer.hxx" @@ -64,9 +63,9 @@ private: const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName, - const OUString &indexName, + OUString schemaName, + OUString tableName, + OUString indexName, const css::uno::Sequence< OUString > &columns ); virtual ~IndexColumns() override; @@ -107,6 +106,5 @@ public: // XDataDescriptorFactory }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xindexes.cxx b/connectivity/source/drivers/postgresql/pq_xindexes.cxx index 2f6df914f0a2..bff96216c568 100644 --- a/connectivity/source/drivers/postgresql/pq_xindexes.cxx +++ b/connectivity/source/drivers/postgresql/pq_xindexes.cxx @@ -35,6 +35,7 @@ ************************************************************************/ #include <sal/log.hxx> +#include <rtl/ref.hxx> #include <rtl/ustrbuf.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> @@ -42,6 +43,8 @@ #include <com/sun/star/sdbc/XRow.hpp> #include <com/sun/star/sdbc/XParameters.hpp> #include <cppuhelper/exc_hlp.hxx> +#include <o3tl/safeint.hxx> +#include <utility> #include "pq_xindexes.hxx" #include "pq_xindex.hxx" @@ -54,7 +57,6 @@ using osl::MutexGuard; using com::sun::star::beans::XPropertySet; using com::sun::star::uno::Any; -using com::sun::star::uno::makeAny; using com::sun::star::uno::UNO_QUERY; using com::sun::star::uno::Reference; using com::sun::star::uno::Sequence; @@ -77,11 +79,11 @@ Indexes::Indexes( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName) + OUString schemaName, + OUString tableName) : Container( refMutex, origin, pSettings, getStatics().KEY ), - m_schemaName( schemaName ), - m_tableName( tableName ) + m_schemaName(std::move( schemaName )), + m_tableName(std::move( tableName )) { } @@ -133,7 +135,7 @@ void Indexes::refresh() static const sal_Int32 C_IS_PRIMARY = 6; static const sal_Int32 C_COLUMNS = 7; OUString currentIndexName = row->getString( C_INDEXNAME ); - Index *pIndex = + rtl::Reference<Index> pIndex = new Index( m_xMutex, m_origin, m_pSettings, m_schemaName, m_tableName ); @@ -148,20 +150,21 @@ void Indexes::refresh() pIndex->setPropertyValue_NoBroadcast_public( st.IS_CLUSTERED, Any( isClusterd ) ); pIndex->setPropertyValue_NoBroadcast_public( - st.NAME, makeAny( currentIndexName ) ); + st.NAME, Any( currentIndexName ) ); std::vector< sal_Int32 > seq = parseIntArray( row->getString( C_COLUMNS ) ); Sequence< OUString > columnNames(seq.size()); + auto columnNamesRange = asNonConstRange(columnNames); for( size_t columns = 0 ; columns < seq.size() ; columns ++ ) { - columnNames[columns] = column2NameMap[ seq[columns] ]; + columnNamesRange[columns] = column2NameMap[ seq[columns] ]; } pIndex->setPropertyValue_NoBroadcast_public( - st.PRIVATE_COLUMN_INDEXES, makeAny( columnNames )); + st.PRIVATE_COLUMN_INDEXES, Any( columnNames )); { - m_values.push_back( makeAny( prop ) ); + m_values.emplace_back(prop); map[ currentIndexName ] = index; ++index; } @@ -233,7 +236,7 @@ void Indexes::dropByIndex( sal_Int32 index ) osl::MutexGuard guard( m_xMutex->GetMutex() ); - if( index < 0 || index >= static_cast<sal_Int32>(m_values.size()) ) + if( index < 0 || o3tl::make_unsigned(index) >= m_values.size() ) { throw css::lang::IndexOutOfBoundsException( "Indexes: Index out of range (allowed 0 to " @@ -268,10 +271,10 @@ Reference< css::container::XNameAccess > Indexes::create( const OUString & schemaName, const OUString & tableName) { - Indexes *pIndexes = new Indexes( refMutex, origin, pSettings, schemaName, tableName ); - Reference< css::container::XNameAccess > ret = pIndexes; + rtl::Reference<Indexes> pIndexes + = new Indexes( refMutex, origin, pSettings, schemaName, tableName ); pIndexes->refresh(); - return ret; + return pIndexes; } diff --git a/connectivity/source/drivers/postgresql/pq_xindexes.hxx b/connectivity/source/drivers/postgresql/pq_xindexes.hxx index 7991058f5799..536d17b96198 100644 --- a/connectivity/source/drivers/postgresql/pq_xindexes.hxx +++ b/connectivity/source/drivers/postgresql/pq_xindexes.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XINDEXES_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XINDEXES_HXX +#pragma once #include "pq_xcontainer.hxx" @@ -59,8 +58,8 @@ private: const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName); + OUString schemaName, + OUString tableName); virtual ~Indexes() override; @@ -99,6 +98,5 @@ public: // XDataDescriptorFactory }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xkey.cxx b/connectivity/source/drivers/postgresql/pq_xkey.cxx index ed0b2669e894..81d1f7a86eb6 100644 --- a/connectivity/source/drivers/postgresql/pq_xkey.cxx +++ b/connectivity/source/drivers/postgresql/pq_xkey.cxx @@ -36,6 +36,8 @@ #include <cppuhelper/typeprovider.hxx> #include <cppuhelper/queryinterface.hxx> +#include <rtl/ref.hxx> +#include <utility> #include "pq_xkey.hxx" #include "pq_xkeycolumns.hxx" @@ -56,8 +58,8 @@ namespace pq_sdbc_driver Key::Key( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const Reference< css::sdbc::XConnection > & connection, ConnectionSettings *pSettings, - const OUString & schemaName, - const OUString & tableName ) + OUString schemaName, + OUString tableName ) : ReflectionBase( getStatics().refl.key.implName, getStatics().refl.key.serviceNames, @@ -65,13 +67,13 @@ Key::Key( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, connection, pSettings, * getStatics().refl.key.pProps ), - m_schemaName( schemaName ), - m_tableName( tableName ) + m_schemaName(std::move( schemaName )), + m_tableName(std::move( tableName )) {} Reference< XPropertySet > Key::createDataDescriptor( ) { - KeyDescriptor * pKeyDescriptor = new KeyDescriptor( + rtl::Reference<KeyDescriptor> pKeyDescriptor = new KeyDescriptor( m_xMutex, m_conn, m_pSettings ); pKeyDescriptor->copyValuesFrom( this ); @@ -134,7 +136,7 @@ KeyDescriptor::KeyDescriptor( const ::rtl::Reference< comphelper::RefCountedMute Reference< XPropertySet > KeyDescriptor::createDataDescriptor( ) { - KeyDescriptor * pKeyDescriptor = new KeyDescriptor( + rtl::Reference<KeyDescriptor> pKeyDescriptor = new KeyDescriptor( m_xMutex, m_conn, m_pSettings ); pKeyDescriptor->copyValuesFrom( this ); diff --git a/connectivity/source/drivers/postgresql/pq_xkey.hxx b/connectivity/source/drivers/postgresql/pq_xkey.hxx index 3174d189206b..68f05fd27d4e 100644 --- a/connectivity/source/drivers/postgresql/pq_xkey.hxx +++ b/connectivity/source/drivers/postgresql/pq_xkey.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XKEY_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XKEY_HXX +#pragma once #include <cppuhelper/component.hxx> #include <cppuhelper/propshlp.hxx> @@ -62,12 +61,12 @@ public: Key( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & connection, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName); + OUString schemaName, + OUString tableName); public: // XInterface - virtual void SAL_CALL acquire() throw() override { ReflectionBase::acquire(); } - virtual void SAL_CALL release() throw() override { ReflectionBase::release(); } + virtual void SAL_CALL acquire() noexcept override { ReflectionBase::acquire(); } + virtual void SAL_CALL release() noexcept override { ReflectionBase::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -96,8 +95,8 @@ public: ConnectionSettings *pSettings ); public: // XInterface - virtual void SAL_CALL acquire() throw() override { ReflectionBase::acquire(); } - virtual void SAL_CALL release() throw() override { ReflectionBase::release(); } + virtual void SAL_CALL acquire() noexcept override { ReflectionBase::acquire(); } + virtual void SAL_CALL release() noexcept override { ReflectionBase::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -117,6 +116,4 @@ public: // XDataDescriptorFactory } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xkeycolumn.cxx b/connectivity/source/drivers/postgresql/pq_xkeycolumn.cxx index 9eea45204f3d..30eef179716c 100644 --- a/connectivity/source/drivers/postgresql/pq_xkeycolumn.cxx +++ b/connectivity/source/drivers/postgresql/pq_xkeycolumn.cxx @@ -34,6 +34,11 @@ * ************************************************************************/ +#include <sal/config.h> + +#include <rtl/ref.hxx> + +#include "pq_statics.hxx" #include "pq_xkeycolumn.hxx" using com::sun::star::uno::Reference; @@ -56,7 +61,7 @@ KeyColumn::KeyColumn( const ::rtl::Reference< comphelper::RefCountedMutex > & re Reference< XPropertySet > KeyColumn::createDataDescriptor( ) { - KeyColumnDescriptor * pKeyColumn = new KeyColumnDescriptor( + rtl::Reference<KeyColumnDescriptor> pKeyColumn = new KeyColumnDescriptor( m_xMutex, m_conn, m_pSettings ); pKeyColumn->copyValuesFrom( this ); @@ -78,7 +83,7 @@ KeyColumnDescriptor::KeyColumnDescriptor( Reference< XPropertySet > KeyColumnDescriptor::createDataDescriptor( ) { - KeyColumnDescriptor * pKeyColumn = new KeyColumnDescriptor( + rtl::Reference<KeyColumnDescriptor> pKeyColumn = new KeyColumnDescriptor( m_xMutex, m_conn, m_pSettings ); pKeyColumn->copyValuesFrom( this ); diff --git a/connectivity/source/drivers/postgresql/pq_xkeycolumn.hxx b/connectivity/source/drivers/postgresql/pq_xkeycolumn.hxx index 14baf7f66cf2..7d49d5d26570 100644 --- a/connectivity/source/drivers/postgresql/pq_xkeycolumn.hxx +++ b/connectivity/source/drivers/postgresql/pq_xkeycolumn.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XKEYCOLUMN_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XKEYCOLUMN_HXX +#pragma once #include <cppuhelper/component.hxx> #include <cppuhelper/propshlp.hxx> @@ -80,6 +79,4 @@ public: // XDataDescriptorFactory } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xkeycolumns.cxx b/connectivity/source/drivers/postgresql/pq_xkeycolumns.cxx index 890b57fa7420..89f63ceb5a65 100644 --- a/connectivity/source/drivers/postgresql/pq_xkeycolumns.cxx +++ b/connectivity/source/drivers/postgresql/pq_xkeycolumns.cxx @@ -39,6 +39,8 @@ #include <com/sun/star/sdbc/SQLException.hpp> #include <com/sun/star/sdbc/XRow.hpp> #include <cppuhelper/exc_hlp.hxx> +#include <rtl/ref.hxx> +#include <utility> #include "pq_xcolumns.hxx" #include "pq_xkeycolumns.hxx" @@ -51,7 +53,6 @@ using osl::MutexGuard; using com::sun::star::beans::XPropertySet; using com::sun::star::uno::Any; -using com::sun::star::uno::makeAny; using com::sun::star::uno::UNO_QUERY; using com::sun::star::uno::Reference; using com::sun::star::uno::Sequence; @@ -68,13 +69,13 @@ KeyColumns::KeyColumns( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName, + OUString schemaName, + OUString tableName, const Sequence< OUString > &columnNames, const Sequence< OUString > &foreignColumnNames ) : Container( refMutex, origin, pSettings, "KEY_COLUMN" ), - m_schemaName( schemaName ), - m_tableName( tableName ), + m_schemaName(std::move( schemaName )), + m_tableName(std::move( tableName )), m_columnNames( columnNames ), m_foreignColumnNames( foreignColumnNames ) {} @@ -117,19 +118,19 @@ void KeyColumns::refresh() if( m_columnNames.getLength() == keyindex ) continue; - KeyColumn * pKeyColumn = + rtl::Reference<KeyColumn> pKeyColumn = new KeyColumn( m_xMutex, m_origin, m_pSettings ); Reference< css::beans::XPropertySet > prop = pKeyColumn; - OUString name = columnMetaData2SDBCX( pKeyColumn, xRow ); + OUString name = columnMetaData2SDBCX( pKeyColumn.get(), xRow ); if( keyindex < m_foreignColumnNames.getLength() ) { pKeyColumn->setPropertyValue_NoBroadcast_public( - st.RELATED_COLUMN, makeAny( m_foreignColumnNames[keyindex]) ); + st.RELATED_COLUMN, Any( m_foreignColumnNames[keyindex]) ); } { - m_values.push_back( makeAny( prop ) ); + m_values.emplace_back(prop); map[ name ] = columnIndex; ++columnIndex; } @@ -214,12 +215,11 @@ Reference< css::container::XNameAccess > KeyColumns::create( const Sequence< OUString > &columnNames , const Sequence< OUString > &foreignColumnNames ) { - KeyColumns *pKeyColumns = new KeyColumns( + rtl::Reference<KeyColumns> pKeyColumns = new KeyColumns( refMutex, origin, pSettings, schemaName, tableName, columnNames, foreignColumnNames ); - Reference< css::container::XNameAccess > ret = pKeyColumns; pKeyColumns->refresh(); - return ret; + return pKeyColumns; } diff --git a/connectivity/source/drivers/postgresql/pq_xkeycolumns.hxx b/connectivity/source/drivers/postgresql/pq_xkeycolumns.hxx index 0ada98aa4052..60bbd0c0de36 100644 --- a/connectivity/source/drivers/postgresql/pq_xkeycolumns.hxx +++ b/connectivity/source/drivers/postgresql/pq_xkeycolumns.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XKEYCOLUMNS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XKEYCOLUMNS_HXX +#pragma once #include "pq_xcontainer.hxx" @@ -64,8 +63,8 @@ private: const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName, + OUString schemaName, + OUString tableName, const css::uno::Sequence< OUString > &keyColumns, const css::uno::Sequence< OUString > &foreignColumnNames); @@ -98,6 +97,5 @@ public: // XDataDescriptorFactory virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL createDataDescriptor( ) override; }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xkeys.cxx b/connectivity/source/drivers/postgresql/pq_xkeys.cxx index 969ce4dd398c..0758be630e04 100644 --- a/connectivity/source/drivers/postgresql/pq_xkeys.cxx +++ b/connectivity/source/drivers/postgresql/pq_xkeys.cxx @@ -39,6 +39,7 @@ #include <string_view> #include <sal/log.hxx> +#include <rtl/ref.hxx> #include <rtl/ustrbuf.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> @@ -48,6 +49,8 @@ #include <com/sun/star/sdbc/KeyRule.hpp> #include <com/sun/star/sdbcx/KeyType.hpp> #include <cppuhelper/exc_hlp.hxx> +#include <o3tl/safeint.hxx> +#include <utility> #include "pq_xkeys.hxx" #include "pq_xkey.hxx" @@ -59,7 +62,7 @@ using osl::MutexGuard; using css::beans::XPropertySet; -using com::sun::star::uno::makeAny; +using com::sun::star::uno::Any; using com::sun::star::uno::UNO_QUERY; using com::sun::star::uno::Reference; @@ -77,11 +80,11 @@ Keys::Keys( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName) + OUString schemaName, + OUString tableName) : Container( refMutex, origin, pSettings, getStatics().KEY ), - m_schemaName( schemaName ), - m_tableName( tableName ) + m_schemaName(std::move( schemaName )), + m_tableName(std::move( tableName )) {} Keys::~Keys() @@ -150,37 +153,36 @@ void Keys::refresh() int keyIndex = 0; while( rs->next() ) { - Key * pKey = + rtl::Reference<Key> pKey = new Key( m_xMutex, m_origin, m_pSettings , m_schemaName, m_tableName ); Reference< css::beans::XPropertySet > prop = pKey; pKey->setPropertyValue_NoBroadcast_public( - st.NAME, makeAny( xRow->getString( 1 ) ) ); + st.NAME, Any( xRow->getString( 1 ) ) ); sal_Int32 keyType = string2keytype( xRow->getString(2) ); - pKey->setPropertyValue_NoBroadcast_public( st.TYPE, makeAny( keyType ) ); + pKey->setPropertyValue_NoBroadcast_public( st.TYPE, Any( keyType ) ); pKey->setPropertyValue_NoBroadcast_public( - st.UPDATE_RULE, makeAny( string2keyrule( xRow->getString(3) ) ) ); + st.UPDATE_RULE, Any( string2keyrule( xRow->getString(3) ) ) ); pKey->setPropertyValue_NoBroadcast_public( - st.DELETE_RULE, makeAny( string2keyrule( xRow->getString(4) ) ) ); + st.DELETE_RULE, Any( string2keyrule( xRow->getString(4) ) ) ); pKey->setPropertyValue_NoBroadcast_public( st.PRIVATE_COLUMNS, - makeAny( + Any( convertMappedIntArray2StringArray( mainMap, string2intarray( xRow->getString( 7 ) ) ) ) ); if( css::sdbcx::KeyType::FOREIGN == keyType ) { - OUStringBuffer buf( 128 ); - buf.append( xRow->getString( 6 ) ).append( "." ).append( xRow->getString( 5 ) ); + OUString buf = xRow->getString( 6 ) + "." + xRow->getString( 5 ); pKey->setPropertyValue_NoBroadcast_public( - st.REFERENCED_TABLE, makeAny( buf.makeStringAndClear() ) ); + st.REFERENCED_TABLE, Any( buf ) ); Int2StringMap foreignMap; fillAttnum2attnameMap( foreignMap, m_origin, xRow->getString(6), xRow->getString(5)); pKey->setPropertyValue_NoBroadcast_public( st.PRIVATE_FOREIGN_COLUMNS, - makeAny( + Any( convertMappedIntArray2StringArray( foreignMap, string2intarray( xRow->getString(8) ) ) ) ); @@ -189,7 +191,7 @@ void Keys::refresh() { map[ xRow->getString( 1 ) ] = keyIndex; - m_values.push_back( makeAny( prop ) ); + m_values.push_back( Any( prop ) ); ++keyIndex; } } @@ -226,7 +228,7 @@ void Keys::appendByDescriptor( void Keys::dropByIndex( sal_Int32 index ) { osl::MutexGuard guard( m_xMutex->GetMutex() ); - if( index < 0 || index >= static_cast<sal_Int32>(m_values.size()) ) + if( index < 0 || o3tl::make_unsigned(index) >= m_values.size() ) { throw css::lang::IndexOutOfBoundsException( "TABLES: Index out of range (allowed 0 to " + OUString::number(m_values.size() -1) @@ -262,11 +264,10 @@ Reference< css::container::XIndexAccess > Keys::create( const OUString & schemaName, const OUString & tableName) { - Keys *pKeys = new Keys( refMutex, origin, pSettings, schemaName, tableName ); - Reference< css::container::XIndexAccess > ret = pKeys; + rtl::Reference<Keys> pKeys = new Keys( refMutex, origin, pSettings, schemaName, tableName ); pKeys->refresh(); - return ret; + return pKeys; } KeyDescriptors::KeyDescriptors( diff --git a/connectivity/source/drivers/postgresql/pq_xkeys.hxx b/connectivity/source/drivers/postgresql/pq_xkeys.hxx index aedd46b578da..ef6376d4d780 100644 --- a/connectivity/source/drivers/postgresql/pq_xkeys.hxx +++ b/connectivity/source/drivers/postgresql/pq_xkeys.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XKEYS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XKEYS_HXX +#pragma once #include "pq_xcontainer.hxx" @@ -59,8 +58,8 @@ private: const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName); + OUString schemaName, + OUString tableName); virtual ~Keys() override; @@ -98,6 +97,5 @@ public: // XDataDescriptorFactory }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xtable.cxx b/connectivity/source/drivers/postgresql/pq_xtable.cxx index 82b66a316a3f..de8196f9fecd 100644 --- a/connectivity/source/drivers/postgresql/pq_xtable.cxx +++ b/connectivity/source/drivers/postgresql/pq_xtable.cxx @@ -34,6 +34,7 @@ * ************************************************************************/ +#include <rtl/ref.hxx> #include <rtl/ustrbuf.hxx> #include <cppuhelper/typeprovider.hxx> @@ -59,7 +60,6 @@ using com::sun::star::uno::Reference; using com::sun::star::uno::UNO_QUERY; using com::sun::star::uno::Sequence; using com::sun::star::uno::Any; -using com::sun::star::uno::makeAny; using com::sun::star::uno::Type; using com::sun::star::beans::XPropertySet; @@ -78,13 +78,12 @@ Table::Table( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, refMutex, connection, pSettings, - * getStatics().refl.table.pProps ), - m_pColumns( nullptr ) + * getStatics().refl.table.pProps ) {} Reference< XPropertySet > Table::createDataDescriptor( ) { - TableDescriptor * pTable = new TableDescriptor( + rtl::Reference<TableDescriptor> pTable = new TableDescriptor( m_xMutex, m_conn, m_pSettings ); pTable->copyValuesFrom( this ); @@ -168,7 +167,7 @@ void Table::rename( const OUString& newName ) if( Xrename.is() ) { Xrename->rename( newName ); - setPropertyValue_NoBroadcast_public( st.SCHEMA_NAME, makeAny(newSchemaName) ); + setPropertyValue_NoBroadcast_public( st.SCHEMA_NAME, Any(newSchemaName) ); } } else @@ -185,14 +184,13 @@ void Table::rename( const OUString& newName ) bufferQuoteIdentifier( buf, newSchemaName, m_pSettings ); Reference< XStatement > statement = m_conn->createStatement(); statement->executeUpdate( buf.makeStringAndClear() ); - setPropertyValue_NoBroadcast_public( st.SCHEMA_NAME, makeAny(newSchemaName) ); + setPropertyValue_NoBroadcast_public( st.SCHEMA_NAME, Any(newSchemaName) ); disposeNoThrow( statement ); schema = newSchemaName; } catch( css::sdbc::SQLException &e ) { - OUString buf( e.Message + "(NOTE: Only postgresql server >= V8.1 support changing a table's schema)" ); - e.Message = buf; + e.Message += "(NOTE: Only postgresql server >= V8.1 support changing a table's schema)"; throw; } @@ -209,7 +207,7 @@ void Table::rename( const OUString& newName ) disposeNoThrow( statement ); } } - setPropertyValue_NoBroadcast_public( st.NAME, makeAny(newTableName) ); + setPropertyValue_NoBroadcast_public( st.NAME, Any(newTableName) ); // inform the container of the name change ! if( m_pSettings->tables.is() ) { @@ -381,7 +379,7 @@ Any TableDescriptor::queryInterface( const Type & reqType ) Reference< XPropertySet > TableDescriptor::createDataDescriptor( ) { - TableDescriptor * pTable = new TableDescriptor( + rtl::Reference<TableDescriptor> pTable = new TableDescriptor( m_xMutex, m_conn, m_pSettings ); // TODO: deep copies diff --git a/connectivity/source/drivers/postgresql/pq_xtable.hxx b/connectivity/source/drivers/postgresql/pq_xtable.hxx index 69e9d6435c8a..7c8ca73f566b 100644 --- a/connectivity/source/drivers/postgresql/pq_xtable.hxx +++ b/connectivity/source/drivers/postgresql/pq_xtable.hxx @@ -34,22 +34,16 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XTABLE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XTABLE_HXX +#pragma once -#include <cppuhelper/component.hxx> -#include <cppuhelper/propshlp.hxx> - -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp> #include <com/sun/star/sdbcx/XColumnsSupplier.hpp> #include <com/sun/star/sdbcx/XIndexesSupplier.hpp> #include <com/sun/star/sdbcx/XKeysSupplier.hpp> #include <com/sun/star/sdbcx/XRename.hpp> #include <com/sun/star/sdbcx/XAlterTable.hpp> -#include <com/sun/star/container/XNamed.hpp> #include "pq_xbase.hxx" +#include "pq_xcolumns.hxx" namespace pq_sdbc_driver { @@ -66,7 +60,7 @@ class Table : public ReflectionBase, css::uno::Reference< css::container::XNameAccess > m_columns; css::uno::Reference< css::container::XIndexAccess > m_keys; css::uno::Reference< css::container::XNameAccess > m_indexes; - Columns *m_pColumns; + rtl::Reference<Columns> m_pColumns; public: Table( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, @@ -74,8 +68,8 @@ public: ConnectionSettings *pSettings); // XInterface - virtual void SAL_CALL acquire() throw() override { ReflectionBase::acquire(); } - virtual void SAL_CALL release() throw() override { ReflectionBase::release(); } + virtual void SAL_CALL acquire() noexcept override { ReflectionBase::acquire(); } + virtual void SAL_CALL release() noexcept override { ReflectionBase::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -134,8 +128,8 @@ public: ConnectionSettings *pSettings); public: // XInterface - virtual void SAL_CALL acquire() throw() override { ReflectionBase::acquire(); } - virtual void SAL_CALL release() throw() override { ReflectionBase::release(); } + virtual void SAL_CALL acquire() noexcept override { ReflectionBase::acquire(); } + virtual void SAL_CALL release() noexcept override { ReflectionBase::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -164,6 +158,4 @@ public: // XDataDescriptorFactory } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xtables.cxx b/connectivity/source/drivers/postgresql/pq_xtables.cxx index 83758208b203..423ec81f2166 100644 --- a/connectivity/source/drivers/postgresql/pq_xtables.cxx +++ b/connectivity/source/drivers/postgresql/pq_xtables.cxx @@ -34,6 +34,7 @@ * ************************************************************************/ +#include <rtl/ref.hxx> #include <rtl/ustrbuf.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> @@ -42,6 +43,7 @@ #include <com/sun/star/sdbcx/Privilege.hpp> #include <com/sun/star/sdbc/DataType.hpp> #include <cppuhelper/exc_hlp.hxx> +#include <o3tl/safeint.hxx> #include "pq_xtables.hxx" #include "pq_xviews.hxx" @@ -54,7 +56,6 @@ using osl::MutexGuard; using com::sun::star::beans::XPropertySet; using com::sun::star::uno::Any; -using com::sun::star::uno::makeAny; using com::sun::star::uno::UNO_QUERY; using com::sun::star::uno::Reference; using com::sun::star::uno::Sequence; @@ -103,23 +104,23 @@ void Tables::refresh() { // if creating all these tables turns out to have too bad performance, we might // instead offer a factory interface - Table * pTable = + rtl::Reference<Table> pTable = new Table( m_xMutex, m_origin, m_pSettings ); Reference< css::beans::XPropertySet > prop = pTable; OUString name = xRow->getString( TABLE_INDEX_NAME+1); OUString schema = xRow->getString( TABLE_INDEX_SCHEMA+1); pTable->setPropertyValue_NoBroadcast_public( - st.CATALOG_NAME , makeAny(xRow->getString( TABLE_INDEX_CATALOG+1) ) ); - pTable->setPropertyValue_NoBroadcast_public( st.NAME , makeAny( name ) ); - pTable->setPropertyValue_NoBroadcast_public( st.SCHEMA_NAME , makeAny( schema )); + st.CATALOG_NAME , Any(xRow->getString( TABLE_INDEX_CATALOG+1) ) ); + pTable->setPropertyValue_NoBroadcast_public( st.NAME , Any( name ) ); + pTable->setPropertyValue_NoBroadcast_public( st.SCHEMA_NAME , Any( schema )); pTable->setPropertyValue_NoBroadcast_public( - st.TYPE , makeAny( xRow->getString( TABLE_INDEX_TYPE+1) ) ); + st.TYPE , Any( xRow->getString( TABLE_INDEX_TYPE+1) ) ); pTable->setPropertyValue_NoBroadcast_public( - st.DESCRIPTION , makeAny( xRow->getString( TABLE_INDEX_REMARKS+1) ) ); + st.DESCRIPTION , Any( xRow->getString( TABLE_INDEX_REMARKS+1) ) ); pTable->setPropertyValue_NoBroadcast_public( st.PRIVILEGES , - makeAny( sal_Int32( css::sdbcx::Privilege::SELECT | + Any( sal_Int32( css::sdbcx::Privilege::SELECT | css::sdbcx::Privilege::INSERT | css::sdbcx::Privilege::UPDATE | css::sdbcx::Privilege::DELETE | @@ -130,7 +131,7 @@ void Tables::refresh() css::sdbcx::Privilege::DROP ) ) ); { - m_values.push_back( makeAny( prop ) ); + m_values.push_back( Any( prop ) ); map[ schema + "." + name ] = tableIndex; ++tableIndex; } @@ -310,7 +311,7 @@ void Tables::appendByDescriptor( void Tables::dropByIndex( sal_Int32 index ) { osl::MutexGuard guard( m_xMutex->GetMutex() ); - if( index < 0 || index >= static_cast<sal_Int32>(m_values.size()) ) + if( index < 0 || o3tl::make_unsigned(index) >= m_values.size() ) { throw css::lang::IndexOutOfBoundsException( "TABLES: Index out of range (allowed 0 to " + OUString::number(m_values.size() -1) @@ -355,13 +356,12 @@ Reference< css::container::XNameAccess > Tables::create( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - Tables **ppTables) + rtl::Reference<Tables> *ppTables) { *ppTables = new Tables( refMutex, origin, pSettings ); - Reference< css::container::XNameAccess > ret = *ppTables; (*ppTables)->refresh(); - return ret; + return *ppTables; } }; diff --git a/connectivity/source/drivers/postgresql/pq_xtables.hxx b/connectivity/source/drivers/postgresql/pq_xtables.hxx index 33eab3a5b8c4..9222db82c77f 100644 --- a/connectivity/source/drivers/postgresql/pq_xtables.hxx +++ b/connectivity/source/drivers/postgresql/pq_xtables.hxx @@ -34,14 +34,19 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XTABLES_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XTABLES_HXX +#pragma once + +#include <sal/config.h> + +#include <rtl/ref.hxx> #include "pq_xcontainer.hxx" namespace pq_sdbc_driver { +struct ConnectionSettings; + class Tables : public Container { @@ -50,7 +55,7 @@ public: // instances Tables 'exception safe' const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - Tables ** ppTables); + rtl::Reference<Tables> * ppTables); protected: Tables( @@ -82,6 +87,5 @@ protected: }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xuser.cxx b/connectivity/source/drivers/postgresql/pq_xuser.cxx index bc06c541064e..4d0a01f6366f 100644 --- a/connectivity/source/drivers/postgresql/pq_xuser.cxx +++ b/connectivity/source/drivers/postgresql/pq_xuser.cxx @@ -35,6 +35,7 @@ ************************************************************************/ #include <sal/log.hxx> +#include <rtl/ref.hxx> #include <rtl/ustrbuf.hxx> #include <cppuhelper/typeprovider.hxx> @@ -73,7 +74,7 @@ User::User( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, Reference< XPropertySet > User::createDataDescriptor( ) { - UserDescriptor * pUser = new UserDescriptor( m_xMutex, m_conn, m_pSettings ); + rtl::Reference<UserDescriptor> pUser = new UserDescriptor( m_xMutex, m_conn, m_pSettings ); pUser->copyValuesFrom( this ); return Reference< XPropertySet > ( pUser ); @@ -159,7 +160,7 @@ UserDescriptor::UserDescriptor( Reference< XPropertySet > UserDescriptor::createDataDescriptor( ) { - UserDescriptor * pUser = new UserDescriptor( m_xMutex, m_conn, m_pSettings ); + rtl::Reference<UserDescriptor> pUser = new UserDescriptor( m_xMutex, m_conn, m_pSettings ); pUser->copyValuesFrom( this ); return Reference< XPropertySet > ( pUser ); diff --git a/connectivity/source/drivers/postgresql/pq_xuser.hxx b/connectivity/source/drivers/postgresql/pq_xuser.hxx index 950cd998b0d5..702787a67496 100644 --- a/connectivity/source/drivers/postgresql/pq_xuser.hxx +++ b/connectivity/source/drivers/postgresql/pq_xuser.hxx @@ -34,14 +34,8 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XUSER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XUSER_HXX +#pragma once -#include <cppuhelper/component.hxx> -#include <cppuhelper/propshlp.hxx> - -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp> #include <com/sun/star/sdbcx/XUser.hpp> #include "pq_xbase.hxx" @@ -59,8 +53,8 @@ public: ConnectionSettings *pSettings); // XInterface - virtual void SAL_CALL acquire() throw() override { ReflectionBase::acquire(); } - virtual void SAL_CALL release() throw() override { ReflectionBase::release(); } + virtual void SAL_CALL acquire() noexcept override { ReflectionBase::acquire(); } + virtual void SAL_CALL release() noexcept override { ReflectionBase::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -96,6 +90,4 @@ public: // XDataDescriptorFactory } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xusers.cxx b/connectivity/source/drivers/postgresql/pq_xusers.cxx index a6fe3489fa7f..08cdf2d1c135 100644 --- a/connectivity/source/drivers/postgresql/pq_xusers.cxx +++ b/connectivity/source/drivers/postgresql/pq_xusers.cxx @@ -34,12 +34,14 @@ * ************************************************************************/ +#include <rtl/ref.hxx> #include <rtl/ustrbuf.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/sdbc/SQLException.hpp> #include <com/sun/star/sdbc/XRow.hpp> #include <cppuhelper/exc_hlp.hxx> +#include <o3tl/safeint.hxx> #include "pq_xusers.hxx" #include "pq_xuser.hxx" @@ -50,7 +52,7 @@ using osl::MutexGuard; using com::sun::star::beans::XPropertySet; -using com::sun::star::uno::makeAny; +using com::sun::star::uno::Any; using com::sun::star::uno::UNO_QUERY; using com::sun::star::uno::Reference; @@ -91,16 +93,16 @@ void Users::refresh() sal_Int32 tableIndex = 0; while( rs->next() ) { - User * pUser = + rtl::Reference<User> pUser = new User( m_xMutex, m_origin, m_pSettings ); Reference< css::beans::XPropertySet > prop = pUser; OUString name = xRow->getString( 1); pUser->setPropertyValue_NoBroadcast_public( - st.NAME , makeAny(xRow->getString( TABLE_INDEX_CATALOG+1) ) ); + st.NAME , Any(xRow->getString( TABLE_INDEX_CATALOG+1) ) ); { - m_values.push_back( makeAny( prop ) ); + m_values.push_back( Any( prop ) ); map[ name ] = tableIndex; ++tableIndex; } @@ -150,7 +152,7 @@ void Users::dropByIndex( sal_Int32 index ) { osl::MutexGuard guard( m_xMutex->GetMutex() ); - if( index < 0 || index >= static_cast<sal_Int32>(m_values.size()) ) + if( index < 0 || o3tl::make_unsigned(index) >= m_values.size() ) { throw css::lang::IndexOutOfBoundsException( "USERS: Index out of range (allowed 0 to " @@ -185,11 +187,10 @@ Reference< css::container::XNameAccess > Users::create( const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings ) { - Users *pUsers = new Users( refMutex, origin, pSettings ); - Reference< css::container::XNameAccess > ret = pUsers; + rtl::Reference<Users> pUsers = new Users( refMutex, origin, pSettings ); pUsers->refresh(); - return ret; + return pUsers; } void Users::disposing() diff --git a/connectivity/source/drivers/postgresql/pq_xusers.hxx b/connectivity/source/drivers/postgresql/pq_xusers.hxx index 359b97dd11cf..f95ec174915f 100644 --- a/connectivity/source/drivers/postgresql/pq_xusers.hxx +++ b/connectivity/source/drivers/postgresql/pq_xusers.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XUSERS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XUSERS_HXX +#pragma once #include "pq_xcontainer.hxx" @@ -79,6 +78,5 @@ private: }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xview.cxx b/connectivity/source/drivers/postgresql/pq_xview.cxx index 1b00b9b5d326..c2e936e9a314 100644 --- a/connectivity/source/drivers/postgresql/pq_xview.cxx +++ b/connectivity/source/drivers/postgresql/pq_xview.cxx @@ -34,6 +34,7 @@ * ************************************************************************/ +#include <rtl/ref.hxx> #include <rtl/ustrbuf.hxx> #include <cppuhelper/typeprovider.hxx> @@ -51,7 +52,6 @@ using osl::MutexGuard; using com::sun::star::uno::Reference; using com::sun::star::uno::Sequence; using com::sun::star::uno::Any; -using com::sun::star::uno::makeAny; using com::sun::star::uno::Type; using com::sun::star::beans::XPropertySet; @@ -76,7 +76,7 @@ View::View( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, Reference< XPropertySet > View::createDataDescriptor( ) { - ViewDescriptor * pView = new ViewDescriptor( + rtl::Reference<ViewDescriptor> pView = new ViewDescriptor( m_xMutex, m_conn, m_pSettings ); pView->copyValuesFrom( this ); @@ -120,14 +120,13 @@ void View::rename( const OUString& newName ) bufferQuoteIdentifier( buf, newSchemaName, m_pSettings ); Reference< XStatement > statement = m_conn->createStatement(); statement->executeUpdate( buf.makeStringAndClear() ); - setPropertyValue_NoBroadcast_public( st.SCHEMA_NAME, makeAny(newSchemaName) ); + setPropertyValue_NoBroadcast_public( st.SCHEMA_NAME, Any(newSchemaName) ); disposeNoThrow( statement ); schema = newSchemaName; } catch( css::sdbc::SQLException &e ) { - OUString buf( e.Message + "(NOTE: Only postgresql server >= V8.1 support changing a table's schema)" ); - e.Message = buf; + e.Message += "(NOTE: Only postgresql server >= V8.1 support changing a table's schema)"; throw; } @@ -141,7 +140,7 @@ void View::rename( const OUString& newName ) bufferQuoteIdentifier( buf, newTableName, m_pSettings ); Reference< XStatement > statement = m_conn->createStatement(); statement->executeUpdate( buf.makeStringAndClear() ); - setPropertyValue_NoBroadcast_public( st.NAME, makeAny(newTableName) ); + setPropertyValue_NoBroadcast_public( st.NAME, Any(newTableName) ); } // inform the container of the name change ! @@ -205,7 +204,7 @@ ViewDescriptor::ViewDescriptor( Reference< XPropertySet > ViewDescriptor::createDataDescriptor( ) { - ViewDescriptor * pView = new ViewDescriptor( + rtl::Reference<ViewDescriptor> pView = new ViewDescriptor( m_xMutex, m_conn, m_pSettings ); pView->copyValuesFrom( this ); diff --git a/connectivity/source/drivers/postgresql/pq_xview.hxx b/connectivity/source/drivers/postgresql/pq_xview.hxx index d5c86981f6f4..f68b5535a8d7 100644 --- a/connectivity/source/drivers/postgresql/pq_xview.hxx +++ b/connectivity/source/drivers/postgresql/pq_xview.hxx @@ -34,16 +34,9 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XVIEW_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XVIEW_HXX +#pragma once -#include <cppuhelper/component.hxx> -#include <cppuhelper/propshlp.hxx> - -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp> #include <com/sun/star/sdbcx/XRename.hpp> -#include <com/sun/star/container/XNamed.hpp> #include "pq_xbase.hxx" @@ -58,8 +51,8 @@ public: ConnectionSettings *pSettings); // XInterface - virtual void SAL_CALL acquire() throw() override { ReflectionBase::acquire(); } - virtual void SAL_CALL release() throw() override { ReflectionBase::release(); } + virtual void SAL_CALL acquire() noexcept override { ReflectionBase::acquire(); } + virtual void SAL_CALL release() noexcept override { ReflectionBase::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -96,6 +89,4 @@ public: } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xviews.cxx b/connectivity/source/drivers/postgresql/pq_xviews.cxx index ac684a16c124..1f5b6c4fa52c 100644 --- a/connectivity/source/drivers/postgresql/pq_xviews.cxx +++ b/connectivity/source/drivers/postgresql/pq_xviews.cxx @@ -34,12 +34,14 @@ * ************************************************************************/ +#include <rtl/ref.hxx> #include <rtl/ustrbuf.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/sdbc/SQLException.hpp> #include <com/sun/star/sdbc/XRow.hpp> #include <cppuhelper/exc_hlp.hxx> +#include <o3tl/safeint.hxx> #include "pq_xviews.hxx" #include "pq_xview.hxx" @@ -51,7 +53,7 @@ using osl::MutexGuard; using com::sun::star::beans::XPropertySet; -using com::sun::star::uno::makeAny; +using com::sun::star::uno::Any; using com::sun::star::uno::UNO_QUERY; using com::sun::star::uno::Reference; @@ -106,15 +108,15 @@ void Views::refresh() table = xRow->getString( 2 ); command = xRow->getString( 3 ); - View *pView = new View (m_xMutex, m_origin, m_pSettings ); + rtl::Reference<View> pView = new View (m_xMutex, m_origin, m_pSettings ); Reference< css::beans::XPropertySet > prop = pView; - pView->setPropertyValue_NoBroadcast_public(st.NAME , makeAny(table) ); - pView->setPropertyValue_NoBroadcast_public(st.SCHEMA_NAME, makeAny(schema) ); - pView->setPropertyValue_NoBroadcast_public(st.COMMAND, makeAny(command) ); + pView->setPropertyValue_NoBroadcast_public(st.NAME , Any(table) ); + pView->setPropertyValue_NoBroadcast_public(st.SCHEMA_NAME, Any(schema) ); + pView->setPropertyValue_NoBroadcast_public(st.COMMAND, Any(command) ); { - m_values.push_back( makeAny( prop ) ); + m_values.push_back( Any( prop ) ); map[ schema + "." + table ] = viewIndex; ++viewIndex; } @@ -148,7 +150,7 @@ void Views::appendByDescriptor( buf.append( "CREATE VIEW "); bufferQuoteQualifiedIdentifier( buf, schema, name, m_pSettings ); - buf.append(" AS " ).append( command ); + buf.append(" AS " + command ); stmt->executeUpdate( buf.makeStringAndClear() ); @@ -174,7 +176,7 @@ void Views::dropByName( const OUString& elementName ) void Views::dropByIndex( sal_Int32 index ) { osl::MutexGuard guard( m_xMutex->GetMutex() ); - if( index < 0 || index >= static_cast<sal_Int32>(m_values.size()) ) + if( index < 0 || o3tl::make_unsigned(index) >= m_values.size() ) { throw css::lang::IndexOutOfBoundsException( "VIEWS: Index out of range (allowed 0 to " + OUString::number(m_values.size() -1) @@ -204,13 +206,12 @@ Reference< css::container::XNameAccess > Views::create( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - Views **ppViews) + rtl::Reference<Views> *ppViews) { *ppViews = new Views( refMutex, origin, pSettings ); - Reference< css::container::XNameAccess > ret = *ppViews; (*ppViews)->refresh(); - return ret; + return *ppViews; } }; diff --git a/connectivity/source/drivers/postgresql/pq_xviews.hxx b/connectivity/source/drivers/postgresql/pq_xviews.hxx index 5ce5b879bd0e..04137b6868a1 100644 --- a/connectivity/source/drivers/postgresql/pq_xviews.hxx +++ b/connectivity/source/drivers/postgresql/pq_xviews.hxx @@ -34,14 +34,19 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XVIEWS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XVIEWS_HXX +#pragma once + +#include <sal/config.h> + +#include <rtl/ref.hxx> #include "pq_xcontainer.hxx" namespace pq_sdbc_driver { +struct ConnectionSettings; + class Views : public Container { @@ -50,7 +55,7 @@ public: // instances Views 'exception safe' const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - Views **ppViews ); + rtl::Reference<Views> *ppViews ); protected: Views( @@ -79,6 +84,5 @@ protected: }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |