2011-11-17 21:29:14 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2011-08-02 16:10:00 +02:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2011-11-21 11:29:03 +01:00
|
|
|
* Effective License of whole file:
|
2011-08-02 16:10:00 +02:00
|
|
|
*
|
2011-11-21 11:29:03 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2011-08-02 16:10:00 +02:00
|
|
|
*
|
2011-11-21 11:29:03 +01:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2011-08-02 16:10:00 +02:00
|
|
|
*
|
2011-11-21 11:29:03 +01:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2011-08-02 16:10:00 +02:00
|
|
|
*
|
2011-11-21 11:29:03 +01:00
|
|
|
* Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
|
2011-08-02 16:10:00 +02:00
|
|
|
*
|
2011-11-21 11:29:03 +01:00
|
|
|
* The Contents of this file are made available subject to the terms of
|
|
|
|
* the GNU Lesser General Public License Version 2.1
|
2011-08-02 16:10:00 +02:00
|
|
|
*
|
2011-11-21 11:29:03 +01:00
|
|
|
* Copyright: 2000 by Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* Contributor(s): Joerg Budischewski
|
|
|
|
*
|
|
|
|
* All parts contributed on or after August 2011:
|
|
|
|
*
|
2013-04-24 17:14:03 +01:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2011-11-21 11:29:03 +01:00
|
|
|
*
|
2011-08-02 16:10:00 +02:00
|
|
|
************************************************************************/
|
|
|
|
|
2014-04-18 18:41:08 +02:00
|
|
|
#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_CONNECTION_HXX
|
|
|
|
#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_CONNECTION_HXX
|
2013-05-16 21:56:04 +01:00
|
|
|
|
|
|
|
#include <config_lgpl.h>
|
2011-08-02 16:10:00 +02:00
|
|
|
#include <com/sun/star/uno/XComponentContext.hpp>
|
|
|
|
#include <com/sun/star/lang/XInitialization.hpp>
|
|
|
|
#include <com/sun/star/script/XTypeConverter.hpp>
|
|
|
|
#include <com/sun/star/sdbc/XWarningsSupplier.hpp>
|
|
|
|
#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
|
|
|
|
#include <com/sun/star/sdbcx/XUsersSupplier.hpp>
|
|
|
|
#include <com/sun/star/sdbcx/XViewsSupplier.hpp>
|
|
|
|
#include <com/sun/star/sdbc/XConnection.hpp>
|
|
|
|
|
|
|
|
#include <com/sun/star/container/XNameAccess.hpp>
|
|
|
|
|
|
|
|
#include <rtl/ref.hxx>
|
|
|
|
#include <rtl/byteseq.hxx>
|
|
|
|
|
2017-06-19 17:06:34 +02:00
|
|
|
#include <comphelper/refcountedmutex.hxx>
|
2011-08-02 16:10:00 +02:00
|
|
|
|
|
|
|
#include <cppuhelper/weakref.hxx>
|
2015-07-13 11:21:57 +09:00
|
|
|
#include <cppuhelper/compbase.hxx>
|
2016-02-01 11:56:21 +02:00
|
|
|
#include <functional>
|
2011-08-02 16:10:00 +02:00
|
|
|
|
|
|
|
#include <libpq-fe.h>
|
2015-01-04 11:10:45 +00:00
|
|
|
#include <unordered_map>
|
2011-08-02 16:10:00 +02:00
|
|
|
|
|
|
|
namespace pq_sdbc_driver
|
|
|
|
{
|
|
|
|
#ifdef POSTGRE_TRACE
|
|
|
|
#define POSTGRE_TRACE( x ) printf( "%s\n" , x )
|
|
|
|
#else
|
|
|
|
#define POSTGRE_TRACE(x) ((void)0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct ConnectionSettings;
|
|
|
|
|
|
|
|
|
|
|
|
// Logging API
|
2014-02-25 17:59:09 +01:00
|
|
|
|
2016-09-15 11:35:05 +02:00
|
|
|
enum class LogLevel
|
2011-08-02 16:10:00 +02:00
|
|
|
{
|
2016-09-15 11:35:05 +02:00
|
|
|
NONE = 0,
|
|
|
|
Error,
|
|
|
|
Sql,
|
|
|
|
Info,
|
|
|
|
LAST = Info
|
|
|
|
};
|
2017-07-18 13:40:38 +02:00
|
|
|
bool isLog(ConnectionSettings const *settings, LogLevel nLevel);
|
2016-09-15 11:35:05 +02:00
|
|
|
void log(ConnectionSettings *settings, LogLevel nLevel, const OUString &logString);
|
|
|
|
void log(ConnectionSettings *settings, LogLevel nLevel, const char *str);
|
2014-02-25 17:59:09 +01:00
|
|
|
|
2011-08-02 16:10:00 +02:00
|
|
|
|
|
|
|
class Tables;
|
|
|
|
class Views;
|
|
|
|
struct ConnectionSettings
|
|
|
|
{
|
|
|
|
ConnectionSettings() :
|
2015-11-10 10:12:07 +01:00
|
|
|
pConnection(nullptr),
|
2011-08-09 22:33:16 +02:00
|
|
|
maxNameLen(0),
|
|
|
|
maxIndexKeys(0),
|
2015-11-10 10:12:07 +01:00
|
|
|
pTablesImpl(nullptr),
|
|
|
|
pViewsImpl(nullptr),
|
|
|
|
logFile( nullptr ),
|
2016-09-15 11:35:05 +02:00
|
|
|
m_nLogLevel(LogLevel::Info)
|
2011-08-02 16:10:00 +02:00
|
|
|
{}
|
2016-09-15 15:54:19 +02:00
|
|
|
static const rtl_TextEncoding encoding = RTL_TEXTENCODING_UTF8;
|
2011-08-02 16:10:00 +02:00
|
|
|
PGconn *pConnection;
|
2011-08-09 22:33:16 +02:00
|
|
|
sal_Int32 maxNameLen;
|
|
|
|
sal_Int32 maxIndexKeys;
|
2016-05-27 12:31:29 +02:00
|
|
|
css::uno::Reference< css::script::XTypeConverter > tc;
|
|
|
|
css::uno::Reference< css::container::XNameAccess > tables;
|
|
|
|
css::uno::Reference< css::container::XNameAccess > users;
|
|
|
|
css::uno::Reference< css::container::XNameAccess > views;
|
2011-08-02 16:10:00 +02:00
|
|
|
Tables *pTablesImpl; // needed to implement renaming of tables / views
|
|
|
|
Views *pViewsImpl; // needed to implement renaming of tables / views
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString user;
|
|
|
|
OUString catalog;
|
2011-08-02 16:10:00 +02:00
|
|
|
FILE *logFile;
|
2016-09-15 11:35:05 +02:00
|
|
|
LogLevel m_nLogLevel;
|
2011-08-02 16:10:00 +02:00
|
|
|
};
|
|
|
|
|
2014-02-25 17:59:09 +01:00
|
|
|
|
2015-07-13 11:21:57 +09:00
|
|
|
typedef cppu::WeakComponentImplHelper<
|
2016-05-27 12:31:29 +02:00
|
|
|
css::sdbc::XConnection,
|
|
|
|
css::sdbc::XWarningsSupplier,
|
|
|
|
css::lang::XInitialization,
|
|
|
|
css::sdbcx::XTablesSupplier,
|
|
|
|
css::sdbcx::XViewsSupplier,
|
|
|
|
css::sdbcx::XUsersSupplier > ConnectionBase;
|
2011-08-02 16:10:00 +02:00
|
|
|
|
|
|
|
// some types
|
|
|
|
struct HashByteSequence
|
|
|
|
{
|
|
|
|
sal_Int32 operator () ( const ::rtl::ByteSequence & seq ) const
|
|
|
|
{
|
2015-01-17 18:17:00 +01:00
|
|
|
return *reinterpret_cast<sal_Int32 const *>(seq.getConstArray());
|
2011-08-02 16:10:00 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-01-04 11:10:45 +00:00
|
|
|
typedef std::unordered_map<
|
2011-08-02 16:10:00 +02:00
|
|
|
::rtl::ByteSequence,
|
2016-05-27 12:31:29 +02:00
|
|
|
css::uno::WeakReference< css::sdbc::XCloseable >,
|
2016-04-03 17:42:53 +02:00
|
|
|
HashByteSequence > WeakHashMap;
|
2017-02-15 23:55:18 +02:00
|
|
|
typedef std::vector< OString > OStringVector;
|
2011-08-02 16:10:00 +02:00
|
|
|
|
|
|
|
|
2015-01-04 11:10:45 +00:00
|
|
|
typedef std::unordered_map
|
2011-08-02 16:10:00 +02:00
|
|
|
<
|
2015-01-04 14:21:13 +01:00
|
|
|
sal_Int32,
|
2016-03-04 10:04:07 +05:30
|
|
|
OUString
|
2011-08-02 16:10:00 +02:00
|
|
|
> Int2StringMap;
|
|
|
|
|
|
|
|
class Connection : public ConnectionBase
|
|
|
|
{
|
2016-05-27 12:31:29 +02:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > m_ctx;
|
|
|
|
css::uno::Reference< css::container::XNameAccess > m_typeMap;
|
2011-08-02 16:10:00 +02:00
|
|
|
ConnectionSettings m_settings;
|
2017-06-19 17:06:34 +02:00
|
|
|
::rtl::Reference< comphelper::RefCountedMutex > m_xMutex;
|
2016-05-27 12:31:29 +02:00
|
|
|
css::uno::Reference< css::sdbc::XDatabaseMetaData > m_meta;
|
2011-08-02 16:10:00 +02:00
|
|
|
WeakHashMap m_myStatements;
|
|
|
|
|
|
|
|
private:
|
2017-01-19 17:59:45 +01:00
|
|
|
/// @throws css::sdbc::SQLException
|
|
|
|
/// @throws css::uno::RuntimeException
|
2017-01-26 12:28:58 +01:00
|
|
|
void checkClosed();
|
2011-08-02 16:10:00 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
Connection(
|
2017-06-19 17:06:34 +02:00
|
|
|
const rtl::Reference< comphelper::RefCountedMutex > &refMutex,
|
2016-05-27 12:31:29 +02:00
|
|
|
const css::uno::Reference< css::uno::XComponentContext > & ctx );
|
2011-08-02 16:10:00 +02:00
|
|
|
|
2016-09-13 13:09:01 +02:00
|
|
|
virtual ~Connection( ) override;
|
2011-08-02 16:10:00 +02:00
|
|
|
|
|
|
|
public: // XCloseable
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual void SAL_CALL close() override;
|
2011-08-02 16:10:00 +02:00
|
|
|
|
|
|
|
public: // XConnection
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement( ) override ;
|
2016-05-27 12:31:29 +02:00
|
|
|
virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement(
|
2017-01-26 12:28:58 +01:00
|
|
|
const OUString& sql ) override;
|
2016-05-27 12:31:29 +02:00
|
|
|
virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall(
|
2017-01-26 12:28:58 +01:00
|
|
|
const OUString& sql ) override;
|
|
|
|
virtual OUString SAL_CALL nativeSQL( const OUString& sql ) override;
|
|
|
|
virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) override;
|
|
|
|
virtual sal_Bool SAL_CALL getAutoCommit( ) override;
|
|
|
|
virtual void SAL_CALL commit( ) override;
|
|
|
|
virtual void SAL_CALL rollback( ) override;
|
|
|
|
virtual sal_Bool SAL_CALL isClosed( ) override;
|
|
|
|
virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( ) override;
|
|
|
|
virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) override;
|
|
|
|
virtual sal_Bool SAL_CALL isReadOnly( ) override;
|
|
|
|
virtual void SAL_CALL setCatalog( const OUString& catalog ) override;
|
|
|
|
virtual OUString SAL_CALL getCatalog( ) override;
|
|
|
|
virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) override;
|
|
|
|
virtual sal_Int32 SAL_CALL getTransactionIsolation( ) override;
|
|
|
|
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTypeMap( ) override;
|
2011-08-02 16:10:00 +02:00
|
|
|
virtual void SAL_CALL setTypeMap(
|
2017-01-26 12:28:58 +01:00
|
|
|
const css::uno::Reference< css::container::XNameAccess >& typeMap ) override;
|
2011-08-02 16:10:00 +02:00
|
|
|
|
|
|
|
public: // XWarningsSupplier
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual css::uno::Any SAL_CALL getWarnings( ) override;
|
|
|
|
virtual void SAL_CALL clearWarnings( ) override;
|
2011-08-02 16:10:00 +02:00
|
|
|
|
|
|
|
public: // XInitialization
|
|
|
|
virtual void SAL_CALL initialize(
|
2017-01-26 12:28:58 +01:00
|
|
|
const css::uno::Sequence< css::uno::Any >& aArguments ) override;
|
2011-08-02 16:10:00 +02:00
|
|
|
|
|
|
|
public: // XTablesSupplier
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTables( ) override;
|
2011-08-02 16:10:00 +02:00
|
|
|
|
|
|
|
public: // XUsersSupplier
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getUsers( ) override;
|
2011-08-02 16:10:00 +02:00
|
|
|
|
|
|
|
public: // XViewsSupplier
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getViews( ) override;
|
2011-08-02 16:10:00 +02:00
|
|
|
|
|
|
|
public:
|
2015-10-12 16:04:04 +02:00
|
|
|
virtual void SAL_CALL disposing() override;
|
2011-08-02 16:10:00 +02:00
|
|
|
|
|
|
|
public: // helper function
|
|
|
|
void removeFromWeakMap( const ::rtl::ByteSequence & seq );
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
2014-02-18 12:11:15 +00:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|