summaryrefslogtreecommitdiff
path: root/dbaccess
diff options
context:
space:
mode:
authorTamas Bunth <tamas.bunth@collabora.co.uk>2019-08-30 14:01:19 +0200
committerXisco Faulí <xiscofauli@libreoffice.org>2019-09-02 17:24:55 +0200
commit0eb27ca7e8e2e07a478b7eb1a7ecc08aa6d472af (patch)
treed49e5f936b8d2ef1baaed61ee75627613b84d12d /dbaccess
parent3ae4ce3919a4e61afa94c7eb02c03c05cb1cc3f5 (diff)
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@gmail.com> (cherry picked from commit c635364120ab8b6cea1e78ebeda4fb028df7678a) Reviewed-on: https://gerrit.libreoffice.org/78387 Reviewed-by: Xisco Faulí <xiscofauli@libreoffice.org>
Diffstat (limited to 'dbaccess')
-rw-r--r--dbaccess/source/ui/misc/WCopyTable.cxx12
1 files changed, 12 insertions, 0 deletions
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));