summaryrefslogtreecommitdiff
path: root/connectivity
diff options
context:
space:
mode:
authorAndrzej J.R. Hunt <andrzej@ahunt.org>2013-09-06 11:47:49 +0100
committerAndrzej J.R. Hunt <andrzej@ahunt.org>2013-09-06 13:46:49 +0100
commit2e31c305a374f14d927ea700657a85aa705f21d9 (patch)
treec78da5c4f2534afdca2e46d4b0f5b04215420425 /connectivity
parent4ef1215d6a380b05bb8bb8d6fca869ac7eca05ff (diff)
Actually rebuild indexes in rebuildIndexes. (firebird-sdbc)
Change-Id: I76ac3b261bce830879f17e82ddd22a9f4d957f11
Diffstat (limited to 'connectivity')
-rw-r--r--connectivity/source/drivers/firebird/Connection.cxx35
1 files changed, 28 insertions, 7 deletions
diff --git a/connectivity/source/drivers/firebird/Connection.cxx b/connectivity/source/drivers/firebird/Connection.cxx
index 5cca8113ada6..cb935c96f3e2 100644
--- a/connectivity/source/drivers/firebird/Connection.cxx
+++ b/connectivity/source/drivers/firebird/Connection.cxx
@@ -792,12 +792,13 @@ uno::Reference< XTablesSupplier > OConnection::createCatalog()
void OConnection::rebuildIndexes() throw(SQLException)
{
-
SAL_INFO("connectivity.firebird", "rebuildIndexes()");
MutexGuard aGuard(m_aMutex);
// We only need to do this for character based columns on user-created tables.
+ // Ideally we'd use a FOR SELECT ... INTO .... DO ..., but that seems to
+ // only be possible using PSQL, i.e. using a stored procedure.
OUString sSql(
// multiple columns possible per index, only select once
"SELECT DISTINCT indices.RDB$INDEX_NAME "
@@ -816,15 +817,35 @@ void OConnection::rebuildIndexes() throw(SQLException)
"AND (indices.RDB$INDEX_INACTIVE IS NULL OR indices.RDB$INDEX_INACTIVE = 0) "
);
+ uno::Reference< XStatement > xCharIndicesStatement = createStatement();
+ uno::Reference< XResultSet > xCharIndices =
+ xCharIndicesStatement->executeQuery(sSql);
+ uno::Reference< XRow > xRow(xCharIndices, UNO_QUERY_THROW);
+
+ uno::Reference< XStatement > xAlterIndexStatement = createStatement();
- uno::Reference< XStatement > xStatement = createStatement();
- uno::Reference< XResultSet > xCharIndices = xStatement->executeQuery(sSql);
- uno::Reference< XRow > xRow( xCharIndices, UNO_QUERY_THROW );
+ // ALTER is a DDL statement, hence using Statement will cause a commit
+ // after every alter -- in this case this is inappropriate (xCharIndicesStatement
+ // and its ResultSet become invalidated) hence we use the native api.
while (xCharIndices->next())
{
+ OUString sIndexName(xRow->getString(1));
+ SAL_INFO("connectivity.firebird", "rebuilding index " + sIndexName);
+ OString sAlterIndex = "ALTER INDEX "
+ + OUStringToOString(sIndexName, RTL_TEXTENCODING_UTF8)
+ + " ACTIVE";
+
+ ISC_STATUS_ARRAY aStatusVector;
+ ISC_STATUS aErr = 0;
+
+ aErr = isc_dsql_execute_immediate(aStatusVector,
+ &getDBHandle(),
+ &getTransaction(),
+ 0, // Length: 0 for null terminated
+ sAlterIndex.getStr(),
+ FIREBIRD_SQL_DIALECT,
+ NULL);
}
-
- Reference< XCloseable> xClose(xCharIndices,UNO_QUERY);
- xClose->close();
+ commit();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */