Commit 80418f08 authored by Michael Davis's avatar Michael Davis
Browse files

[catalogue] Adds create temporary table code for all DB types

parent 1cf202ae
......@@ -60,13 +60,12 @@ MysqlCatalogue::~MysqlCatalogue() {
// createAndPopulateTempTableFxid
//------------------------------------------------------------------------------
std::string MysqlCatalogue::createAndPopulateTempTableFxid(rdbms::Conn &conn, const TapeFileSearchCriteria &tapeFileSearchCriteria) const {
const std::string tempTableName = "ORA$PTT_DISK_FXIDS";
const std::string tempTableName = "TEMP_DISK_FXIDS";
try {
if(tapeFileSearchCriteria.diskFileIds) {
// ON COMMIT PRESERVE DEFINITION preserves the table until the end of the session
std::string sql = "CREATE PRIVATE TEMPORARY TABLE " + tempTableName +
"(DISK_FILE_ID VARCHAR2(100)) ON COMMIT PRESERVE DEFINITION";
std::string sql = "CREATE TEMPORARY TABLE " + tempTableName +
"(DISK_FILE_ID VARCHAR(100))";
conn.executeNonQuery(sql);
sql = "INSERT INTO " + tempTableName + " VALUES(:DISK_FILE_ID)";
......
......@@ -159,9 +159,9 @@ std::string OracleCatalogue::createAndPopulateTempTableFxid(rdbms::Conn &conn, c
try {
if(tapeFileSearchCriteria.diskFileIds) {
// ON COMMIT PRESERVE DEFINITION preserves the table until the end of the session
conn.setAutocommitMode(rdbms::AutocommitMode::AUTOCOMMIT_OFF);
std::string sql = "CREATE PRIVATE TEMPORARY TABLE " + tempTableName +
"(DISK_FILE_ID VARCHAR2(100)) ON COMMIT PRESERVE DEFINITION";
"(DISK_FILE_ID VARCHAR2(100))";
conn.executeNonQuery(sql);
sql = "INSERT INTO " + tempTableName + " VALUES(:DISK_FILE_ID)";
......
......@@ -153,13 +153,12 @@ PostgresCatalogue::~PostgresCatalogue() {
// createAndPopulateTempTableFxid
//------------------------------------------------------------------------------
std::string PostgresCatalogue::createAndPopulateTempTableFxid(rdbms::Conn &conn, const TapeFileSearchCriteria &tapeFileSearchCriteria) const {
const std::string tempTableName = "ORA$PTT_DISK_FXIDS";
const std::string tempTableName = "TEMP_DISK_FXIDS";
try {
if(tapeFileSearchCriteria.diskFileIds) {
// ON COMMIT PRESERVE DEFINITION preserves the table until the end of the session
std::string sql = "CREATE PRIVATE TEMPORARY TABLE " + tempTableName +
"(DISK_FILE_ID VARCHAR2(100)) ON COMMIT PRESERVE DEFINITION";
std::string sql = "CREATE TEMPORARY TABLE " + tempTableName +
"(DISK_FILE_ID VARCHAR(100)) ON COMMIT DROP";
conn.executeNonQuery(sql);
sql = "INSERT INTO " + tempTableName + " VALUES(:DISK_FILE_ID)";
......
......@@ -184,11 +184,6 @@ RdbmsCatalogueGetArchiveFilesItor::RdbmsCatalogueGetArchiveFilesItor(
lc.log(log::INFO, "RdbmsCatalogueGetArchiveFilesItor - immediately after m_stmt.executeQuery()");
}
// Clean up temporary table
if(searchCriteria.diskFileIds) {
m_conn.executeNonQuery("DROP TABLE " + tempDiskFxidsTableName);
}
m_rsetIsEmpty = !m_rset.next();
if(m_rsetIsEmpty) releaseDbResources();
} catch(exception::UserError &) {
......
......@@ -199,25 +199,30 @@ void SqliteCatalogue::DO_NOT_USE_deleteArchiveFile_DO_NOT_USE(const std::string
std::string SqliteCatalogue::createAndPopulateTempTableFxid(rdbms::Conn &conn, const TapeFileSearchCriteria &tapeFileSearchCriteria) const {
const std::string tempTableName = "TEMP.DISK_FXIDS";
try {
if(tapeFileSearchCriteria.diskFileIds) {
// ON COMMIT PRESERVE DEFINITION preserves the table until the end of the session
if(tapeFileSearchCriteria.diskFileIds) {
try {
std::string sql = "CREATE TEMPORARY TABLE " + tempTableName + "(DISK_FILE_ID TEXT)";
conn.executeNonQuery(sql);
try {
conn.executeNonQuery(sql);
} catch(exception::Exception &ex) {
// SQLite does not drop temporary tables automatically; trying to create another temporary table
// in the same unit test will fail. If this happens, truncate the table and carry on.
sql = "DELETE FROM " + tempTableName;
conn.executeNonQuery(sql);
}
sql = "INSERT INTO " + tempTableName + " VALUES(:DISK_FILE_ID)";
auto stmt = conn.createStmt(sql);
for(auto &diskFileId : tapeFileSearchCriteria.diskFileIds.value()) {
stmt.bindString(":DISK_FILE_ID", diskFileId);
stmt.executeNonQuery();
}
} catch(exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
return tempTableName;
} catch(exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
return tempTableName;
}
//------------------------------------------------------------------------------
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment