From 2e31c305a374f14d927ea700657a85aa705f21d9 Mon Sep 17 00:00:00 2001 From: "Andrzej J.R. Hunt" Date: Fri, 6 Sep 2013 11:47:49 +0100 Subject: Actually rebuild indexes in rebuildIndexes. (firebird-sdbc) Change-Id: I76ac3b261bce830879f17e82ddd22a9f4d957f11 --- .../source/drivers/firebird/Connection.cxx | 35 +++++++++++++++++----- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'connectivity') 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: */ -- cgit