23#include <com/sun/star/sdbc/SQLException.hpp>
30#include <com/sun/star/beans/NamedValue.hpp>
41using ::osl::MutexGuard;
45void lcl_executeUpdate(MYSQL* pMySql,
const OString&
sql)
47 mysql_real_query(pMySql,
sql.getStr(),
sql.getLength());
56 , m_xMetaData(nullptr)
57 , m_xDriver(&_rDriver)
73 mysql_library_init(0,
nullptr,
nullptr);
76 OString charset_name{
"utf8mb4" };
77 mysql_options(&
m_mysql, MYSQL_SET_CHARSET_NAME, charset_name.getStr());
81 OUString aHostName(
"localhost");
82 sal_Int32 nPort = 3306;
90 if (url.startsWith(
"sdbc:mysqlc:"))
100 token = url.getToken(0,
'/', nIndex);
101 if (!token.isEmpty())
103 sal_Int32 nIndex1 = 0;
104 OUString hostandport = token.getToken(0,
':', nIndex1);
105 if (!hostandport.isEmpty())
107 aHostName = hostandport;
108 hostandport = token.getToken(0,
':', nIndex1);
109 if (!hostandport.isEmpty() && nIndex1)
111 nPort = hostandport.toInt32();
113 token = url.getToken(0,
'/', nIndex);
114 if (!token.isEmpty() && nIndex)
122 const PropertyValue* pIter = info.getConstArray();
123 const PropertyValue* pEnd = pIter + info.getLength();
124 OUString aUser, aPass, sUnixSocket, sNamedPipe;
125 bool unixSocketPassed =
false;
126 bool namedPipePassed =
false;
129 for (; pIter != pEnd; ++pIter)
131 if (pIter->Name ==
"user")
133 OSL_VERIFY(pIter->Value >>= aUser);
135 else if (pIter->Name ==
"password")
137 OSL_VERIFY(pIter->Value >>= aPass);
139 else if (pIter->Name ==
"LocalSocket")
141 OSL_VERIFY(pIter->Value >>= sUnixSocket);
142 unixSocketPassed = !sUnixSocket.isEmpty();
144 else if (pIter->Name ==
"NamedPipe")
146 OSL_VERIFY(pIter->Value >>= sNamedPipe);
147 namedPipePassed = !sNamedPipe.isEmpty();
149 else if (pIter->Name ==
"PublicConnectionURL")
153 else if (pIter->Name ==
"NewURL")
166 mysql_protocol_type protocol = MYSQL_PROTOCOL_TCP;
167 if (unixSocketPassed)
170 protocol = MYSQL_PROTOCOL_SOCKET;
172 else if (namedPipePassed)
175 protocol = MYSQL_PROTOCOL_PIPE;
178 mysql_options(&
m_mysql, MYSQL_OPT_PROTOCOL, &protocol);
181 if (!mysql_real_connect(&
m_mysql, host_str.getStr(), user_str.getStr(), pass_str.getStr(),
182 schema_str.getStr(), nPort, socket_str.getStr(),
183 CLIENT_MULTI_STATEMENTS))
191 throw SQLException(
"MariaDB LibreOffice Connector requires MySQL Server 4.1 or above",
192 *
this, OUString(), 0,
Any());
196 OString{
"SET session sql_mode='ANSI_QUOTES,NO_AUTO_VALUE_ON_ZERO'" });
197 lcl_executeUpdate(&
m_mysql, OString{
"SET NAMES utf8mb4" });
202 return "com.sun.star.sdbc.drivers.mysqlc.OConnection";
207 return {
"com.sun.star.sdbc.Connection" };
222 Reference<XStatement> xReturn =
new OStatement(
this);
232 const OString sSqlStatement
235 MYSQL_STMT* pStmt = mysql_stmt_init(&
m_mysql);
236 mysql_stmt_prepare(pStmt, sSqlStatement.getStr(), sSqlStatement.getLength());
238 unsigned int nErrorNum = mysql_errno(&
m_mysql);
241 mysql_sqlstate(&
m_mysql), nErrorNum, *
this,
255 return Reference<XPreparedStatement>();
269 if (!mysql_autocommit(&
m_mysql, autoCommit))
314 return OConnection_BASE::rBHelper.bDisposed;
322 Reference<XDatabaseMetaData> xMetaData =
m_xMetaData;
436 Reference<XComponent> xComp(statement.get(), UNO_QUERY);
454 unsigned long version = mysql_get_server_version(&
m_mysql);
455 return static_cast<sal_Int32
>(version);
460 OUString sSqlStatement = _sSQL;
465 Reference<XConnection> xCon =
this;
466 Sequence<Any> aArgs{
Any(NamedValue(
"ActiveConnection",
Any(xCon))) };
469 m_xDriver->getFactory()->createInstanceWithArguments(
470 "org.openoffice.comp.helper.ParameterSubstitution", aArgs),
487 return sSqlStatement;
509 Reference<XTablesSupplier> xCatalog =
m_xCatalog;
const css::uno::Sequence< sal_Int8 > & getSeq() const
virtual void SAL_CALL disposing() override
static rtl_TextEncoding getDefaultEncoding()
sal_Int32 SAL_CALL getTransactionIsolation() override
OWeakRefArray m_aStatements
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 rollback() override
void SAL_CALL setTypeMap(const css::uno::Reference< css::container::XNameAccess > &typeMap) override
OUString SAL_CALL nativeSQL(const OUString &sql) override
void SAL_CALL close() override
sal_Bool SAL_CALL isClosed() override
css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall(const OUString &sql) override
rtl_TextEncoding getConnectionEncoding() const
virtual ~OConnection() override
ConnectionSettings m_settings
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
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
sal_Int32 getMysqlVersion()
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
void SAL_CALL commit() override
virtual sal_Bool SAL_CALL supportsService(OUString const &ServiceName) override
mutable::osl::Mutex m_aMutex
sal_Int64 getSomethingImpl(const css::uno::Sequence< sal_Int8 > &rId, T *pThis, FallbackToGetSomethingOf< Base >={})
void checkDisposed(bool _bThrow)
::cppu::WeakComponentImplHelper< css::sdbc::XConnection, css::sdbc::XWarningsSupplier, css::lang::XUnoTunnel, css::lang::XServiceInfo > OMetaConnection_BASE
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
void throwSQLExceptionWithMsg(const char *msg, const char *SQLSTATE, unsigned int errorNum, const css::uno::Reference< css::uno::XInterface > &_context, const rtl_TextEncoding encoding)
void throwFeatureNotImplementedException(const char *_pAsciiFeatureName, const css::uno::Reference< XInterface > &_rxContext)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
rtl_TextEncoding encoding