[Libreoffice-commits] core.git: connectivity/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Fri Aug 31 13:32:55 UTC 2018
connectivity/source/drivers/mysqlc/mysqlc_databasemetadata.cxx | 64 +++++++++-
1 file changed, 58 insertions(+), 6 deletions(-)
New commits:
commit d2a1ca79e50f191e20688345c4d78e82477342be
Author: Tamas Bunth <tamas.bunth at collabora.co.uk>
AuthorDate: Fri Aug 31 10:10:50 2018 +0200
Commit: Tamás Bunth <btomi96 at gmail.com>
CommitDate: Fri Aug 31 15:32:29 2018 +0200
mysqlc: implement getImpotedKeys
Change-Id: Ic819389000b5b31de69bece6b280cf89f93db948
Reviewed-on: https://gerrit.libreoffice.org/59851
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 4319405ad9eb..e4d70bed516a 100644
--- a/connectivity/source/drivers/mysqlc/mysqlc_databasemetadata.cxx
+++ b/connectivity/source/drivers/mysqlc/mysqlc_databasemetadata.cxx
@@ -895,16 +895,68 @@ Reference<XResultSet> SAL_CALL ODatabaseMetaData::getExportedKeys(const Any& /*c
}
Reference<XResultSet> SAL_CALL ODatabaseMetaData::getImportedKeys(const Any& /*catalog*/,
- const rtl::OUString& /*schema*/,
- const rtl::OUString& /*table*/)
+ const rtl::OUString& schema,
+ const rtl::OUString& table)
{
Reference<XResultSet> xResultSet(getOwnConnection().getDriver().getFactory()->createInstance(
"org.openoffice.comp.helper.DatabaseMetaDataResultSet"),
UNO_QUERY);
- std::vector<std::vector<Any>> rRows;
- // TODO implement
- SAL_WARN("connectivity.mysqlc", "method not implemented");
- lcl_setRows_throw(xResultSet, 9, rRows);
+
+ rtl::OUString query(
+ "SELECT refi.CONSTRAINT_CATALOG, k.COLUMN_NAME, "
+ " refi.UNIQUE_CONSTRAINT_CATALOG, "
+ " refi.UNIQUE_CONSTRAINT_SCHEMA, refi.REFERENCED_TABLE_NAME, k.REFERENCED_COLUMN_NAME, "
+ " refi.UPDATE_RULE, refi.DELETE_RULE, refi.CONSTRAINT_NAME "
+ " FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS as refi"
+ " INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE as k ON k.CONSTRAINT_NAME = "
+ "refi.CONSTRAINT_NAME "
+ " and k.TABLE_NAME = refi.TABLE_NAME "
+ " WHERE refi.CONSTRAINT_SCHEMA LIKE "
+ "'?' AND refi.TABLE_NAME='?'"); // TODO
+ query = query.replaceFirst("?", schema);
+ query = query.replaceFirst("?", table);
+
+ std::vector<std::vector<Any>> aRows;
+ Reference<XStatement> statement = m_rConnection.createStatement();
+ Reference<XResultSet> rs = statement->executeQuery(query.getStr());
+ Reference<XRow> xRow(rs, UNO_QUERY_THROW);
+
+ while (rs->next())
+ {
+ std::vector<Any> aRow{ Any() }; // 0. element is unused
+
+ // primary key catalog
+ aRow.push_back(makeAny(xRow->getString(1)));
+ // primary key schema
+ aRow.push_back(makeAny(schema));
+ // primary key table
+ aRow.push_back(makeAny(table));
+ // primary column name
+ aRow.push_back(makeAny(xRow->getString(2)));
+
+ // fk table catalog
+ aRow.push_back(makeAny(xRow->getString(3)));
+ // fk schema
+ aRow.push_back(makeAny(xRow->getString(4)));
+ // fk table
+ aRow.push_back(makeAny(xRow->getString(5)));
+ // fk column name
+ aRow.push_back(makeAny(xRow->getString(6)));
+ // KEY_SEQ
+ aRow.push_back(makeAny(sal_Int32{ 0 })); // TODO
+ // update rule
+ aRow.push_back(makeAny(xRow->getShort(7)));
+ // delete rule
+ aRow.push_back(makeAny(xRow->getShort(8)));
+ // foreign key name
+ aRow.push_back(makeAny(xRow->getShort(9)));
+ // primary key name
+ aRow.push_back(makeAny(OUString{})); // TODO
+ // deferrability
+ aRow.push_back(makeAny(Deferrability::NONE));
+ aRows.push_back(aRow);
+ }
+ lcl_setRows_throw(xResultSet, 1, aRows);
return xResultSet;
}
More information about the Libreoffice-commits
mailing list