From 2a1fa15d8baa4eda37e17b2e9362f8bde17a939d Mon Sep 17 00:00:00 2001 From: randomdan Date: Sat, 8 Jul 2006 16:32:05 +0000 Subject: libcodbcpp initial release --- libodbcpp/command.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 libodbcpp/command.cpp (limited to 'libodbcpp/command.cpp') diff --git a/libodbcpp/command.cpp b/libodbcpp/command.cpp new file mode 100644 index 0000000..6c8bf3c --- /dev/null +++ b/libodbcpp/command.cpp @@ -0,0 +1,35 @@ +#include "command.h" +#include "error.h" +#include "param.h" +#include + +ODBC::Command::Command(const Connection& c, String s) : + sql(s) +{ + 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, sql, sql.size()); + 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; + } + } +} + -- cgit v1.2.3