LibreOffice Module connectivity (master) 1
mysqlc_connection.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#pragma once
21
22#include <memory>
24#include "mysqlc_types.hxx"
25
26#include <com/sun/star/beans/PropertyValue.hpp>
27#include <com/sun/star/lang/XServiceInfo.hpp>
28#include <com/sun/star/lang/XUnoTunnel.hpp>
29#include <com/sun/star/sdbc/ColumnValue.hpp>
30#include <com/sun/star/sdbc/SQLWarning.hpp>
31#include <com/sun/star/sdbc/XConnection.hpp>
32#include <com/sun/star/sdbc/XWarningsSupplier.hpp>
33#include <com/sun/star/util/XStringSubstitution.hpp>
34
35#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
36
39#include <rtl/ref.hxx>
40
41#include <mysql.h>
42
43#include <map>
44
45namespace sql
46{
47class SQLException;
48}
49
50namespace connectivity
51{
52class OMetaConnection;
53class ODatabaseMetaData;
54
55namespace mysqlc
56{
57typedef ::cppu::WeakComponentImplHelper<css::sdbc::XConnection, css::sdbc::XWarningsSupplier,
58 css::lang::XUnoTunnel, css::lang::XServiceInfo>
60
62{
63 rtl_TextEncoding encoding;
64 OUString connectionURL;
67 : encoding(RTL_TEXTENCODING_DONTKNOW)
68 , readOnly(false)
69 {
70 }
71};
72
73class MysqlCDriver;
74
76
77typedef std::vector<css::uno::WeakReferenceHelper> OWeakRefArray;
78
79class OConnection final : public cppu::BaseMutex, public OConnection_BASE
80{
81private:
82 MYSQL m_mysql;
84 css::uno::Reference<css::container::XNameAccess> m_typeMap;
85 css::uno::Reference<css::util::XStringSubstitution> m_xParameterSubstitution;
86
87 // Data attributes
88
89 css::uno::WeakReference<css::sdbcx::XTablesSupplier> m_xCatalog;
90 css::uno::WeakReference<css::sdbc::XDatabaseMetaData> m_xMetaData;
91
92 OWeakRefArray m_aStatements; // vector containing a list
93 // of all the Statement objects
94 // for this Connection
95
96 rtl::Reference<MysqlCDriver> m_xDriver; // Pointer to the owning driver object
97public:
98 MYSQL* getMysqlConnection() { return &m_mysql; }
99
102 sal_Int32 getMysqlVersion();
103
105 void construct(const OUString& url, const css::uno::Sequence<css::beans::PropertyValue>& info);
106
107 OConnection(MysqlCDriver& _rDriver);
108 virtual ~OConnection() override;
109
110 rtl_TextEncoding getConnectionEncoding() const { return m_settings.encoding; }
111
116 css::uno::Reference<css::sdbcx::XTablesSupplier> createCatalog();
117
118 // OComponentHelper
119 virtual void SAL_CALL disposing() override;
120
121 // XServiceInfo
122 virtual OUString SAL_CALL getImplementationName() override;
123
124 virtual sal_Bool SAL_CALL supportsService(OUString const& ServiceName) override;
125
126 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
127
128 // XUnoTunnel
129 virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence<sal_Int8>& rId) override;
130 static const css::uno::Sequence<sal_Int8>& getUnoTunnelId();
131
132 // XConnection
133 css::uno::Reference<css::sdbc::XStatement> SAL_CALL createStatement() override;
134
135 css::uno::Reference<css::sdbc::XPreparedStatement>
136 SAL_CALL prepareStatement(const OUString& sql) override;
137
138 css::uno::Reference<css::sdbc::XPreparedStatement>
139 SAL_CALL prepareCall(const OUString& sql) override;
140
141 OUString SAL_CALL nativeSQL(const OUString& sql) override;
142
143 void SAL_CALL setAutoCommit(sal_Bool autoCommit) override;
144
145 sal_Bool SAL_CALL getAutoCommit() override;
146
147 void SAL_CALL commit() override;
148
149 void SAL_CALL rollback() override;
150
151 sal_Bool SAL_CALL isClosed() override;
152
153 css::uno::Reference<css::sdbc::XDatabaseMetaData> SAL_CALL getMetaData() override;
154
155 void SAL_CALL setReadOnly(sal_Bool readOnly) override;
156
157 sal_Bool SAL_CALL isReadOnly() override;
158
159 void SAL_CALL setCatalog(const OUString& catalog) override;
160
161 OUString SAL_CALL getCatalog() override;
162
163 void SAL_CALL setTransactionIsolation(sal_Int32 level) override;
164
165 sal_Int32 SAL_CALL getTransactionIsolation() override;
166
167 css::uno::Reference<css::container::XNameAccess> SAL_CALL getTypeMap() override;
168
169 void SAL_CALL
170 setTypeMap(const css::uno::Reference<css::container::XNameAccess>& typeMap) override;
171 // XCloseable
172 void SAL_CALL close() override;
173 // XWarningsSupplier
174 css::uno::Any SAL_CALL getWarnings() override;
175 void SAL_CALL clearWarnings() override;
176
177 // TODO: Not used
178 //sal_Int32 sdbcColumnType(OUString typeName);
180 OUString transFormPreparedStatement(const OUString& _sSQL);
181
182 const MysqlCDriver& getDriver() const { return *m_xDriver; }
183
184}; /* OConnection */
185// TODO: Not used.
186//inline OUString getPattern(OUString p) { return (p.getLength()) ? p : ASC2OU("%"); }
187} /* mysqlc */
188} /* connectivity */
189
190/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const ConnectionSettings & getConnectionSettings() const
sal_Int32 SAL_CALL getTransactionIsolation() override
void SAL_CALL setCatalog(const OUString &catalog) override
void SAL_CALL setAutoCommit(sal_Bool autoCommit) override
void SAL_CALL setTransactionIsolation(sal_Int32 level) override
virtual void SAL_CALL disposing() override
css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData() override
css::uno::Reference< css::sdbcx::XTablesSupplier > createCatalog()
Create and/or connect to the sdbcx Catalog.
void SAL_CALL setTypeMap(const css::uno::Reference< css::container::XNameAccess > &typeMap) override
OUString SAL_CALL nativeSQL(const OUString &sql) override
sal_Bool SAL_CALL isClosed() override
css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall(const OUString &sql) override
OConnection(MysqlCDriver &_rDriver)
rtl_TextEncoding getConnectionEncoding() const
void construct(const OUString &url, const css::uno::Sequence< css::beans::PropertyValue > &info)
css::uno::Reference< css::container::XNameAccess > m_typeMap
OUString transFormPreparedStatement(const OUString &_sSQL)
void SAL_CALL clearWarnings() override
css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement(const OUString &sql) override
sal_Bool SAL_CALL getAutoCommit() override
const MysqlCDriver & getDriver() const
void SAL_CALL setReadOnly(sal_Bool readOnly) override
rtl::Reference< MysqlCDriver > m_xDriver
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &rId) override
css::uno::WeakReference< css::sdbcx::XTablesSupplier > m_xCatalog
css::uno::Reference< css::container::XNameAccess > SAL_CALL getTypeMap() override
sal_Bool SAL_CALL isReadOnly() override
virtual OUString SAL_CALL getImplementationName() override
css::uno::Reference< css::util::XStringSubstitution > m_xParameterSubstitution
css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement() override
OUString SAL_CALL getCatalog() override
css::uno::Any SAL_CALL getWarnings() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::uno::WeakReference< css::sdbc::XDatabaseMetaData > m_xMetaData
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
virtual sal_Bool SAL_CALL supportsService(OUString const &ServiceName) override
std::vector< css::uno::WeakReferenceHelper > OWeakRefArray
OMetaConnection_BASE OConnection_BASE
::cppu::WeakComponentImplHelper< css::sdbc::XConnection, css::sdbc::XWarningsSupplier, css::lang::XUnoTunnel, css::lang::XServiceInfo > OMetaConnection_BASE
unsigned char sal_Bool