#include "command.h" #include "error.h" #include "param.h" #include ODBC::Command::Command(const Connection & c, const std::string & s) : sql(s), connection(c) { RETCODE rc = SQLAllocHandle(SQL_HANDLE_STMT, c.conn, &hStmt); if (rc != SQL_SUCCESS) { throw Error(rc, SQL_HANDLE_STMT, hStmt, "Allocate statement handle"); } rc = SQLPrepare(hStmt, (SQLCHAR*)sql.c_str(), sql.length()); if (rc != SQL_SUCCESS) { SQLFreeHandle(SQL_HANDLE_STMT, hStmt); throw Error(rc, SQL_HANDLE_STMT, hStmt, "Prepare statement"); } SQLSMALLINT pcount; rc = SQLNumParams(hStmt, &pcount); if (rc != SQL_SUCCESS) { SQLFreeHandle(SQL_HANDLE_STMT, hStmt); throw Error(rc, SQL_HANDLE_STMT, hStmt, "Parameter count"); } params.resize(pcount); } ODBC::Command::~Command() { for (Params::iterator i = params.begin(); i != params.end(); i++) { if (*i) { delete *i; } } }