summaryrefslogtreecommitdiff
path: root/connectivity/source/drivers/mysqlc/mysqlc_connection.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'connectivity/source/drivers/mysqlc/mysqlc_connection.cxx')
-rw-r--r--connectivity/source/drivers/mysqlc/mysqlc_connection.cxx66
1 files changed, 49 insertions, 17 deletions
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_connection.cxx b/connectivity/source/drivers/mysqlc/mysqlc_connection.cxx
index 600e131b89b1..269113383d8d 100644
--- a/connectivity/source/drivers/mysqlc/mysqlc_connection.cxx
+++ b/connectivity/source/drivers/mysqlc/mysqlc_connection.cxx
@@ -17,8 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include "mysqlc_catalog.hxx"
#include "mysqlc_connection.hxx"
#include "mysqlc_databasemetadata.hxx"
+#include <com/sun/star/sdbc/SQLException.hpp>
#include "mysqlc_driver.hxx"
#include "mysqlc_statement.hxx"
@@ -27,20 +29,17 @@
#include <com/sun/star/beans/NamedValue.hpp>
-#include <osl/diagnose.h>
-#include <cppuhelper/supportsservice.hxx>
+#include <comphelper/servicehelper.hxx>
using namespace connectivity::mysqlc;
using namespace com::sun::star::uno;
using namespace com::sun::star::container;
-using namespace com::sun::star::lang;
using namespace com::sun::star::beans;
using namespace com::sun::star::sdbc;
+using namespace com::sun::star::sdbcx;
using ::osl::MutexGuard;
-#define MYSQLC_URI_PREFIX "sdbc:mysqlc:"
-
namespace
{
void lcl_executeUpdate(MYSQL* pMySql, const OString& sql)
@@ -53,6 +52,7 @@ void lcl_executeUpdate(MYSQL* pMySql, const OString& sql)
OConnection::OConnection(MysqlCDriver& _rDriver)
: OMetaConnection_BASE(m_aMutex)
, m_mysql()
+ , m_xCatalog(nullptr)
, m_xMetaData(nullptr)
, m_xDriver(&_rDriver)
{
@@ -73,10 +73,7 @@ void OConnection::construct(const OUString& url, const Sequence<PropertyValue>&
mysql_library_init(0, nullptr, nullptr);
mysql_init(&m_mysql);
- // use TCP as connection
- mysql_protocol_type protocol = MYSQL_PROTOCOL_TCP;
- mysql_options(&m_mysql, MYSQL_OPT_PROTOCOL, &protocol);
- OString charset_name{ "utf8mb4" };
+ OString charset_name{ "utf8mb4"_ostr };
mysql_options(&m_mysql, MYSQL_SET_CHARSET_NAME, charset_name.getStr());
sal_Int32 nIndex;
@@ -90,7 +87,7 @@ void OConnection::construct(const OUString& url, const Sequence<PropertyValue>&
// parse url. Url has the following format:
// external server: sdbc:mysqlc:[hostname]:[port]/[dbname]
- if (url.startsWith(MYSQLC_URI_PREFIX))
+ if (url.startsWith("sdbc:mysqlc:"))
{
nIndex = 12;
}
@@ -164,15 +161,22 @@ void OConnection::construct(const OUString& url, const Sequence<PropertyValue>&
OString pass_str = OUStringToOString(aPass, m_settings.encoding);
OString schema_str = OUStringToOString(aDbName, m_settings.encoding);
OString socket_str;
+
+ // use TCP as connection by default
+ mysql_protocol_type protocol = MYSQL_PROTOCOL_TCP;
if (unixSocketPassed)
{
socket_str = OUStringToOString(sUnixSocket, m_settings.encoding);
+ protocol = MYSQL_PROTOCOL_SOCKET;
}
else if (namedPipePassed)
{
socket_str = OUStringToOString(sNamedPipe, m_settings.encoding);
+ protocol = MYSQL_PROTOCOL_PIPE;
}
+ mysql_options(&m_mysql, MYSQL_OPT_PROTOCOL, &protocol);
+
// flags can also be passed as last parameter
if (!mysql_real_connect(&m_mysql, host_str.getStr(), user_str.getStr(), pass_str.getStr(),
schema_str.getStr(), nPort, socket_str.getStr(),
@@ -188,9 +192,8 @@ void OConnection::construct(const OUString& url, const Sequence<PropertyValue>&
*this, OUString(), 0, Any());
}
- lcl_executeUpdate(&m_mysql,
- OString{ "SET session sql_mode='ANSI_QUOTES,NO_AUTO_VALUE_ON_ZERO'" });
- lcl_executeUpdate(&m_mysql, OString{ "SET NAMES utf8mb4" });
+ lcl_executeUpdate(&m_mysql, "SET session sql_mode='ANSI_QUOTES,NO_AUTO_VALUE_ON_ZERO'"_ostr);
+ lcl_executeUpdate(&m_mysql, "SET NAMES utf8mb4"_ostr);
}
OUString OConnection::getImplementationName()
@@ -253,8 +256,6 @@ Reference<XPreparedStatement> SAL_CALL OConnection::prepareCall(const OUString&
OUString SAL_CALL OConnection::nativeSQL(const OUString& /*_sSql*/)
{
- MutexGuard aGuard(m_aMutex);
-
// const OUString sSqlStatement = transFormPreparedStatement( _sSql );
// TODO
return OUString();
@@ -460,9 +461,8 @@ OUString OConnection::transFormPreparedStatement(const OUString& _sSQL)
{
try
{
- Sequence<Any> aArgs(1);
Reference<XConnection> xCon = this;
- aArgs[0] <<= NamedValue("ActiveConnection", makeAny(xCon));
+ Sequence<Any> aArgs{ Any(NamedValue("ActiveConnection", Any(xCon))) };
m_xParameterSubstitution.set(
m_xDriver->getFactory()->createInstanceWithArguments(
@@ -486,4 +486,36 @@ OUString OConnection::transFormPreparedStatement(const OUString& _sSQL)
return sSqlStatement;
}
+//----- XUnoTunnel ----------------------------------------------------------
+// virtual
+sal_Int64 SAL_CALL OConnection::getSomething(const css::uno::Sequence<sal_Int8>& rId)
+{
+ return comphelper::getSomethingImpl(rId, this);
+}
+
+// static
+const Sequence<sal_Int8>& OConnection::getUnoTunnelId()
+{
+ static const comphelper::UnoIdInit implId;
+ return implId.getSeq();
+}
+
+Reference<XTablesSupplier> OConnection::createCatalog()
+{
+ MutexGuard aGuard(m_aMutex);
+
+ // m_xCatalog is a weak reference. Reuse it if it still exists.
+ Reference<XTablesSupplier> xCatalog = m_xCatalog;
+ if (xCatalog.is())
+ {
+ return xCatalog;
+ }
+ else
+ {
+ xCatalog = new Catalog(this);
+ m_xCatalog = xCatalog;
+ return m_xCatalog;
+ }
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */