dbaccess/source/ui/misc/WCopyTable.cxx |   12 ++++++++++++
 1 file changed, 12 insertions(+)

New commits:
commit 0eb27ca7e8e2e07a478b7eb1a7ecc08aa6d472af
Author:     Tamas Bunth <[email protected]>
AuthorDate: Fri Aug 30 14:01:19 2019 +0200
Commit:     Xisco Faulí <[email protected]>
CommitDate: Mon Sep 2 17:24:55 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 <[email protected]>
    (cherry picked from commit c635364120ab8b6cea1e78ebeda4fb028df7678a)
    Reviewed-on: https://gerrit.libreoffice.org/78387
    Reviewed-by: Xisco Faulí <[email protected]>

diff --git a/dbaccess/source/ui/misc/WCopyTable.cxx 
b/dbaccess/source/ui/misc/WCopyTable.cxx
index ca8dac4694f4..14608b3c5d71 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>
@@ -1204,7 +1205,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));
_______________________________________________
Libreoffice-commits mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to