58#include <com/sun/star/beans/PropertyValue.hpp>
59#include <com/sun/star/script/Converter.hpp>
60#include <com/sun/star/sdbc/SQLException.hpp>
64using com::sun::star::container::XNameAccess;
66using com::sun::star::lang::XComponent;
67using com::sun::star::lang::IllegalArgumentException;
69using com::sun::star::script::Converter;
70using com::sun::star::script::XTypeConverter;
72using com::sun::star::uno::RuntimeException;
75using com::sun::star::uno::XInterface;
76using com::sun::star::uno::UNO_QUERY;
77using com::sun::star::uno::UNO_QUERY_THROW;
78using com::sun::star::uno::XComponentContext;
79using com::sun::star::uno::Any;
81using com::sun::star::beans::PropertyValue;
83using com::sun::star::sdbc::XCloseable;
84using com::sun::star::sdbc::SQLException;
85using com::sun::star::sdbc::XPreparedStatement;
86using com::sun::star::sdbc::XStatement;
87using com::sun::star::sdbc::XDatabaseMetaData;
95class ClosableReference :
public cppu::WeakImplHelper< css::uno::XReference >
100 ClosableReference( ::rtl::ByteSequence
id , Connection *that )
105 virtual void SAL_CALL
dispose()
override
119 css::uno::Reference< css::uno::XComponentContext > ctx )
137 std::vector< css::uno::Reference< css::sdbc::XCloseable > > vectorCloseable;
138 std::vector< css::uno::Reference< css::lang::XComponent > > vectorDispose;
140 MutexGuard guard(
m_xMutex->GetMutex() );
144 SAL_INFO(
"connectivity.postgresql",
"closing connection");
160 vectorCloseable.push_back( r );
165 for (
auto const& elem : vectorCloseable)
169 for (
auto const& elem : vectorDispose)
180 MutexGuard guard(
m_xMutex->GetMutex() );
188 MutexGuard guard(
m_xMutex->GetMutex() );
192 ::rtl::ByteSequence id( 16 );
193 rtl_createUuid(
reinterpret_cast<sal_uInt8*
>(
id.getArray()),
nullptr,
false );
195 stmt->queryAdapter()->addReference(
new ClosableReference(
id,
this ) );
201 MutexGuard guard(
m_xMutex->GetMutex() );
208 ::rtl::ByteSequence id( 16 );
209 rtl_createUuid(
reinterpret_cast<sal_uInt8*
>(
id.getArray()),
nullptr,
false );
211 stmt->queryAdapter()->addReference(
new ClosableReference(
id,
this ) );
218 "pq_driver: Callable statements not supported",
256 MutexGuard guard(
m_xMutex->GetMutex() );
282 MutexGuard guard(
m_xMutex->GetMutex() );
285 throw SQLException(
"pq_connection: connection is closed", *
this,
286 OUString(), 1,
Any() );
307 MutexGuard guard(
m_xMutex->GetMutex() );
315 MutexGuard guard(
m_xMutex->GetMutex() );
337 OSL_ENSURE(
values.size() ==
acquired.size(),
"pq_connection: cstr_vector values and acquired size mismatch");
338 std::vector<bool>::const_iterator pa =
acquired.begin();
339 for(
const auto& v :
values )
346 void push_back(
const char* s, __sal_NoAcquire)
348 values.push_back(
const_cast<char*
>(s));
351 void push_back(
char* s)
359 char const** c_array()
const {
return const_cast <const char**
>(
values.data()); }
366 rtl_TextEncoding enc,
367 cstr_vector &keywords,
375 static const char* keyword_list[] = {
385 for( PropertyValue
const & prop :
args )
388 for(
const char* j : keyword_list)
390 if( prop.Name.equalsIgnoreAsciiCaseAscii( j ))
392 keywords.push_back( j, SAL_NO_ACQUIRE );
408 SAL_WARN(
"connectivity.postgresql",
"sdbc-postgresql: unknown argument '" << prop.Name <<
"' having value: " << prop.Value );
422 "pq_driver: Couldn't instantiate converter service" );
426 throw IllegalArgumentException(
427 "pq_driver: expected 2 arguments, got " + OUString::number(
aArguments.getLength( ) ),
433 throw IllegalArgumentException(
434 "pq_driver: expected string as first argument, got "
442 int nColon = url.indexOf(
':' );
445 nColon = url.indexOf(
':' , 1+ nColon );
452 cstr_vector keywords;
455 if ( o.getLength() > 0 )
458 const std::unique_ptr<PQconninfoOption, deleter_from_fn<PQconninfoFree>>
459 oOpts(PQconninfoParse(o.getStr(), &
err));
460 if (oOpts ==
nullptr)
462 OUString errorMessage;
469 errorMessage =
"#no error message#";
473 "Error in database URL '" + url +
"':\n" + errorMessage,
474 *
this,
"HY092", 5,
Any() );
477 for ( PQconninfoOption * opt = oOpts.get(); opt->keyword !=
nullptr; ++opt)
479 if ( opt->val !=
nullptr )
481 keywords.push_back(strdup(opt->keyword));
482 values.push_back(strdup(opt->val));
487 keywords.push_back(
nullptr, SAL_NO_ACQUIRE);
488 values.push_back(
nullptr, SAL_NO_ACQUIRE);
497 OUString errorMessage( error, strlen( error) , RTL_TEXTENCODING_ASCII_US );
501 "Couldn't establish database connection to '" + url +
"'\n"
503 *
this, errorMessage, CONNECTION_BAD,
Any() );
512 SAL_INFO(
"connectivity.postgresql",
"connection to '" << url <<
"' successfully opened");
523 throw SQLException(
"pq_connection: Connection already closed",
524 *
this, OUString(), 1,
Any() );
529 SAL_INFO(
"connectivity.postgresql",
"Connection::getTables() got called");
530 MutexGuard guard(
m_xMutex->GetMutex() );
541 SAL_INFO(
"connectivity.postgresql",
"Connection::getViews() got called");
542 MutexGuard guard(
m_xMutex->GetMutex() );
554 SAL_INFO(
"connectivity.postgresql",
"Connection::getUsers() got called");
556 MutexGuard guard(
m_xMutex->GetMutex() );
564extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
566 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any>
const&)
virtual ~Connection() override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
css::uno::Reference< css::sdbc::XDatabaseMetaData > m_meta
virtual sal_Int32 SAL_CALL getTransactionIsolation() override
virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement(const OUString &sql) override
virtual void SAL_CALL setReadOnly(sal_Bool readOnly) override
virtual sal_Bool SAL_CALL isClosed() override
virtual void SAL_CALL setTransactionIsolation(sal_Int32 level) override
virtual void SAL_CALL rollback() override
virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall(const OUString &sql) override
virtual void SAL_CALL commit() override
virtual void SAL_CALL close() override
css::uno::Reference< css::uno::XComponentContext > m_ctx
virtual sal_Bool SAL_CALL getAutoCommit() override
virtual css::uno::Any SAL_CALL getWarnings() override
virtual void SAL_CALL setAutoCommit(sal_Bool autoCommit) override
ConnectionSettings m_settings
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getViews() override
::rtl::Reference< comphelper::RefCountedMutex > m_xMutex
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTables() override
virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData() override
virtual void SAL_CALL setCatalog(const OUString &catalog) override
virtual OUString SAL_CALL getCatalog() override
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTypeMap() override
virtual void SAL_CALL setTypeMap(const css::uno::Reference< css::container::XNameAccess > &typeMap) override
virtual sal_Bool SAL_CALL isReadOnly() override
WeakHashMap m_myStatements
virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement() override
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getUsers() override
Connection(const rtl::Reference< comphelper::RefCountedMutex > &refMutex, css::uno::Reference< css::uno::XComponentContext > ctx)
virtual void SAL_CALL disposing() override
virtual void SAL_CALL clearWarnings() override
css::uno::Reference< css::container::XNameAccess > m_typeMap
void removeFromWeakMap(const ::rtl::ByteSequence &seq)
virtual OUString SAL_CALL nativeSQL(const OUString &sql) override
static css::uno::Reference< css::container::XNameAccess > create(const ::rtl::Reference< comphelper::RefCountedMutex > &refMutex, const css::uno::Reference< css::sdbc::XConnection > &origin, ConnectionSettings *pSettings, rtl::Reference< Tables > *ppTables)
static css::uno::Reference< css::container::XNameAccess > create(const ::rtl::Reference< comphelper::RefCountedMutex > &refMutex, const css::uno::Reference< css::sdbc::XConnection > &origin, ConnectionSettings *pSettings)
static css::uno::Reference< css::container::XNameAccess > create(const ::rtl::Reference< comphelper::RefCountedMutex > &refMutex, const css::uno::Reference< css::sdbc::XConnection > &origin, ConnectionSettings *pSettings, rtl::Reference< Views > *ppViews)
Sequence< PropertyValue > aArguments
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
rtl::OUString getTypeName(rtl::OUString const &rEnvDcp)
static void properties2arrays(const Sequence< PropertyValue > &args, const Reference< XTypeConverter > &tc, rtl_TextEncoding enc, cstr_vector &keywords, cstr_vector &values)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
cppu::WeakComponentImplHelper< css::sdbc::XConnection, css::sdbc::XWarningsSupplier, css::lang::XInitialization, css::sdbcx::XTablesSupplier, css::sdbcx::XViewsSupplier, css::sdbcx::XUsersSupplier > ConnectionBase
std::vector< bool > acquired
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * connectivity_postgresql_Connection_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
rtl::Reference< Connection > m_conn
std::vector< char * > values
css::uno::Reference< css::script::XTypeConverter > tc
rtl::Reference< Views > pViewsImpl
css::uno::Reference< css::container::XNameAccess > views
css::uno::Reference< css::container::XNameAccess > users
css::uno::Reference< css::container::XNameAccess > tables
static const rtl_TextEncoding encoding
rtl::Reference< Tables > pTablesImpl