[Libreoffice-commits] core.git: 2 commits - connectivity/source dbaccess/source

Tamas Bunth (via logerrit) logerrit at kemper.freedesktop.org
Sat Aug 31 15:50:33 UTC 2019


 connectivity/source/drivers/mysqlc/mysqlc_databasemetadata.cxx |   16 ++++++++--
 dbaccess/source/ui/misc/WCopyTable.cxx                         |   12 +++++++
 2 files changed, 25 insertions(+), 3 deletions(-)

New commits:
commit c635364120ab8b6cea1e78ebeda4fb028df7678a
Author:     Tamas Bunth <tamas.bunth at collabora.co.uk>
AuthorDate: Fri Aug 30 14:01:19 2019 +0200
Commit:     Tamás Bunth <btomi96 at gmail.com>
CommitDate: Sat Aug 31 17:50:02 2019 +0200

    Query MySQL schema name when pasting table
    
    In case of a MySQL direct connection the current schema in use cannot be
    queried with the getUserName() method of the DatabaseMetadata interface,
    because the user name and the schema name can (and usually do) differ.
    
    Instead, we can always query for the current schema with the DATABASE()
    SQL function.
    
    Change-Id: Ibb026519e1a63e29c5a7c9b04ab64901faec0f85
    Reviewed-on: https://gerrit.libreoffice.org/78297
    Tested-by: Jenkins
    Reviewed-by: Tamás Bunth <btomi96 at gmail.com>

diff --git a/dbaccess/source/ui/misc/WCopyTable.cxx b/dbaccess/source/ui/misc/WCopyTable.cxx
index fc1b2ac38d82..46f563d62959 100644
--- a/dbaccess/source/ui/misc/WCopyTable.cxx
+++ b/dbaccess/source/ui/misc/WCopyTable.cxx
@@ -35,6 +35,7 @@
 #include <com/sun/star/sdbc/ColumnValue.hpp>
 #include <com/sun/star/sdbc/DataType.hpp>
 #include <com/sun/star/sdbc/XResultSet.hpp>
+#include <com/sun/star/sdbc/XStatement.hpp>
 #include <com/sun/star/sdbc/XRow.hpp>
 #include <com/sun/star/sdbcx/KeyType.hpp>
 #include <com/sun/star/sdbcx/XAppend.hpp>
@@ -1205,7 +1206,18 @@ Reference< XPropertySet > OCopyTableWizard::createTable()
 
         if ( sSchema.isEmpty() && xMetaData->supportsSchemasInTableDefinitions() )
         {
+            // query of current schema is quite inconsistent. In case of some
+            // DBMS's each user has their own schema.
             sSchema = xMetaData->getUserName();
+            // In case of mysql it is not that simple
+            if(xMetaData->getDatabaseProductName() == "MySQL")
+            {
+                Reference< XStatement > xSelect = m_xDestConnection->createStatement();
+                Reference< XResultSet > xRs = xSelect->executeQuery("select database()");
+                xRs->next(); // first and only result
+                Reference< XRow > xRow( xRs, UNO_QUERY_THROW );
+                sSchema = xRow->getString(1);
+            }
         }
 
         xTable->setPropertyValue(PROPERTY_CATALOGNAME,makeAny(sCatalog));
commit f5c09ac04860f779532fe83f8ebce237d46eb1f5
Author:     Tamas Bunth <tamas.bunth at collabora.co.uk>
AuthorDate: Fri Aug 30 13:59:35 2019 +0200
Commit:     Tamás Bunth <btomi96 at gmail.com>
CommitDate: Sat Aug 31 17:49:51 2019 +0200

    mysqlc: Implement DatabaseMetadata::getUserName
    
    Change-Id: Id3518a049a55d64e7272d265f22e930881a70161
    Reviewed-on: https://gerrit.libreoffice.org/78296
    Tested-by: Jenkins
    Reviewed-by: Tamás Bunth <btomi96 at gmail.com>

diff --git a/connectivity/source/drivers/mysqlc/mysqlc_databasemetadata.cxx b/connectivity/source/drivers/mysqlc/mysqlc_databasemetadata.cxx
index bca56e119626..a57f10720104 100644
--- a/connectivity/source/drivers/mysqlc/mysqlc_databasemetadata.cxx
+++ b/connectivity/source/drivers/mysqlc/mysqlc_databasemetadata.cxx
@@ -361,9 +361,19 @@ OUString SAL_CALL ODatabaseMetaData::getURL()
 
 OUString SAL_CALL ODatabaseMetaData::getUserName()
 {
-    // TODO execute "SELECT USER()"
-    SAL_WARN("connectivity.mysqlc", "method not implemented");
-    return OUString();
+    Reference<XStatement> statement = m_rConnection.createStatement();
+    Reference<XResultSet> rs = statement->executeQuery("select user()");
+    Reference<XRow> xRow(rs, UNO_QUERY_THROW);
+    rs->next(); // the first and only result
+    // e.g. root at localhost
+    OUString userWithConnection = xRow->getString(1);
+    sal_Int32 nIndexOfAt = userWithConnection.indexOf("@");
+    if (nIndexOfAt > 0)
+    {
+        OUString user = userWithConnection.copy(0, nIndexOfAt);
+        return user;
+    }
+    return userWithConnection;
 }
 
 OUString SAL_CALL ODatabaseMetaData::getDriverName() { return "MySQL Connector/OO.org"; }


More information about the Libreoffice-commits mailing list