summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamas Bunth <tamas.bunth@collabora.co.uk>2019-08-30 14:01:19 +0200
committerTamás Bunth <btomi96@gmail.com>2019-08-31 17:50:02 +0200
commitc635364120ab8b6cea1e78ebeda4fb028df7678a (patch)
treeac28c46b8ada44f8b7eb6f0e190c54bb3b03b56b
parentf5c09ac04860f779532fe83f8ebce237d46eb1f5 (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>
-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 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));