summaryrefslogtreecommitdiff
path: root/libodbcpp/command.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libodbcpp/command.cpp')
-rw-r--r--libodbcpp/command.cpp35
1 files changed, 35 insertions, 0 deletions
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 <sqlext.h>
+
+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;
+ }
+ }
+}
+