-
Notifications
You must be signed in to change notification settings - Fork 512
Open
Description
HI,
I created a temp table on mssql and want to execute insert on this table,
// Step 1: Create a temporary table based on the database type
if (m_dbType == DBType::MSSQL) {
// SQL Server: Create a local temporary table
*m_sqlSession << "CREATE TABLE #TempOids (oid uniqueidentifier PRIMARY KEY)";
}
else if (m_dbType == DBType::ORACLE) {
// Oracle: Create a global temporary table (if not already created)
// Note: This table should be created once during schema setup, not in every call
// For testing, we'll drop and recreate it, but in production, this should be pre-created
try {
*m_sqlSession << "DROP TABLE TempOids CASCADE CONSTRAINTS";
}
catch (const soci::soci_error& e) {
// Ignore if table doesn't exist
}
*m_sqlSession << "CREATE GLOBAL TEMPORARY TABLE TempOids (oid VARCHAR2(50) PRIMARY KEY) ON COMMIT DELETE ROWS";
}
// Step 2: Batch insert oids into the temporary table
std::string insertQuery;
if (m_dbType == DBType::MSSQL) {
insertQuery = "INSERT INTO #TempOids (oid) VALUES (:oid)";
}
else { // Oracle
insertQuery = "INSERT INTO TempOids (oid) VALUES (:oid)";
}
soci::statement insertStmt = (m_sqlSession->prepare << insertQuery, soci::use(oids));
insertStmt.execute(true);
While insertStmt.execute(true) throws exception,
Any guide is greatly appreciated.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels