SQLHDBC handle;
};
- struct ODBCStatement {
- ODBCStatement(SQLHSTMT statement) : handle(statement) {}
- ~ODBCStatement() {SQLFreeHandle(SQL_HANDLE_STMT,handle);}
- operator SQLHSTMT() {return handle;}
- SQLHSTMT handle;
- };
-
class ODBCStorageService : public StorageService
{
public:
shutdown_wait->signal();
cleanup_thread->join(NULL);
delete shutdown_wait;
- SQLFreeHandle(SQL_HANDLE_ENV, m_henv);
+ if (m_henv != SQL_NULL_HANDLE)
+ SQLFreeHandle(SQL_HANDLE_ENV, m_henv);
}
bool ODBCStorageService::log_error(SQLHANDLE handle, SQLSMALLINT htype, const char* checkfor)
pair<int,int> ODBCStorageService::getVersion(SQLHDBC conn)
{
// Grab the version number from the database.
- ODBCStatement stmt(getHSTMT(conn));
+ SQLHSTMT stmt = getHSTMT(conn);
SQLRETURN sr=SQLExecDirect(stmt, (SQLCHAR*)"SELECT major,minor FROM version", SQL_NTS);
if (!SQL_SUCCEEDED(sr)) {
// Get statement handle.
ODBCConn conn(getHDBC());
- ODBCStatement stmt(getHSTMT(conn));
+ SQLHSTMT stmt = getHSTMT(conn);
// Prepare and exectute insert statement.
//char *scontext = makeSafeSQL(context);
log_error(stmt, SQL_HANDLE_STMT);
throw IOException("ODBC StorageService failed to insert record.");
}
- m_log.debug("SQLPrepare() succeded. SQL: %s", q.c_str());
+ m_log.debug("SQLPrepare succeded. SQL: %s", q.c_str());
SQLINTEGER b_ind = SQL_NTS;
- sr = SQLBindParam(stmt, 1, SQL_C_CHAR, SQL_VARCHAR, 0, 0, const_cast<char*>(context), &b_ind);
+ sr = SQLBindParam(stmt, 1, SQL_C_CHAR, SQL_VARCHAR, 255, 0, const_cast<char*>(context), &b_ind);
if (!SQL_SUCCEEDED(sr)) {
m_log.error("SQLBindParam failed (context = %s)", context);
log_error(stmt, SQL_HANDLE_STMT);
}
m_log.debug("SQLBindParam succeded (context = %s)", context);
- sr = SQLBindParam(stmt, 2, SQL_C_CHAR, SQL_VARCHAR, 0, 0, const_cast<char*>(key), &b_ind);
+ sr = SQLBindParam(stmt, 2, SQL_C_CHAR, SQL_VARCHAR, 255, 0, const_cast<char*>(key), &b_ind);
if (!SQL_SUCCEEDED(sr)) {
m_log.error("SQLBindParam failed (key = %s)", key);
log_error(stmt, SQL_HANDLE_STMT);
}
m_log.debug("SQLBindParam succeded (key = %s)", key);
- sr = SQLBindParam(stmt, 3, SQL_C_CHAR, (strcmp(table, TEXT_TABLE)==0 ? SQL_LONGVARCHAR : SQL_VARCHAR), 0, 0, const_cast<char*>(value), &b_ind);
+ if (strcmp(table, TEXT_TABLE)==0)
+ sr = SQLBindParam(stmt, 3, SQL_C_CHAR, SQL_LONGVARCHAR, strlen(value), 0, const_cast<char*>(value), &b_ind);
+ else
+ sr = SQLBindParam(stmt, 3, SQL_C_CHAR, SQL_VARCHAR, 255, 0, const_cast<char*>(value), &b_ind);
if (!SQL_SUCCEEDED(sr)) {
m_log.error("SQLBindParam failed (value = %s)", value);
log_error(stmt, SQL_HANDLE_STMT);
return false; // supposedly integrity violation?
throw IOException("ODBC StorageService failed to insert record.");
}
+
+ m_log.debug("SQLExecute of insert succeeded");
return true;
}
// Get statement handle.
ODBCConn conn(getHDBC());
- ODBCStatement stmt(getHSTMT(conn));
+ SQLHSTMT stmt = getHSTMT(conn);
// Prepare and exectute select statement.
char timebuf[32];
// Get statement handle.
ODBCConn conn(getHDBC());
- ODBCStatement stmt(getHSTMT(conn));
+ SQLHSTMT stmt = getHSTMT(conn);
// First, fetch the current version for later, which also ensures the record still exists.
char timebuf[32];
return -1;
}
+ SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+ stmt = getHSTMT(conn);
+
// Prepare and exectute update statement.
q = string("UPDATE ") + table + " SET ";
log_error(stmt, SQL_HANDLE_STMT);
throw IOException("ODBC StorageService failed to update record.");
}
- m_log.debug("SQLPrepare() succeded. SQL: %s", q.c_str());
+ m_log.debug("SQLPrepare succeded. SQL: %s", q.c_str());
SQLINTEGER b_ind = SQL_NTS;
if (value) {
- sr = SQLBindParam(stmt, 1, SQL_C_CHAR, (strcmp(table, TEXT_TABLE)==0 ? SQL_LONGVARCHAR : SQL_VARCHAR), 0, 0, const_cast<char*>(value), &b_ind);
+ if (strcmp(table, TEXT_TABLE)==0)
+ sr = SQLBindParam(stmt, 1, SQL_C_CHAR, SQL_LONGVARCHAR, strlen(value), 0, const_cast<char*>(value), &b_ind);
+ else
+ sr = SQLBindParam(stmt, 1, SQL_C_CHAR, SQL_VARCHAR, 255, 0, const_cast<char*>(value), &b_ind);
if (!SQL_SUCCEEDED(sr)) {
m_log.error("SQLBindParam failed (context = %s)", context);
log_error(stmt, SQL_HANDLE_STMT);
throw IOException("ODBC StorageService failed to update record.");
}
+ m_log.debug("SQLExecute of update succeeded");
return ver + 1;
}
// Get statement handle.
ODBCConn conn(getHDBC());
- ODBCStatement stmt(getHSTMT(conn));
+ SQLHSTMT stmt = getHSTMT(conn);
// Prepare and execute delete statement.
char *scontext = makeSafeSQL(context);
// Get statement handle.
ODBCConn conn(getHDBC());
- ODBCStatement stmt(getHSTMT(conn));
+ SQLHSTMT stmt = getHSTMT(conn);
char timebuf[32];
timestampFromTime(expiration, timebuf);
// Get statement handle.
ODBCConn conn(getHDBC());
- ODBCStatement stmt(getHSTMT(conn));
+ SQLHSTMT stmt = getHSTMT(conn);
// Prepare and execute delete statement.
char nowbuf[32];
// Get statement handle.
ODBCConn conn(getHDBC());
- ODBCStatement stmt(getHSTMT(conn));
+ SQLHSTMT stmt = getHSTMT(conn);
// Prepare and execute delete statement.
char *scontext = makeSafeSQL(context);