summaryrefslogtreecommitdiff
path: root/libodbcpp/command.cpp
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2006-07-08 16:32:05 +0000
committerrandomdan <randomdan@localhost>2006-07-08 16:32:05 +0000
commit2a1fa15d8baa4eda37e17b2e9362f8bde17a939d (patch)
tree09386e52320b7c52a521ab56fc7553896e639dcd /libodbcpp/command.cpp
downloadlibdbpp-odbc-2a1fa15d8baa4eda37e17b2e9362f8bde17a939d.tar.bz2
libdbpp-odbc-2a1fa15d8baa4eda37e17b2e9362f8bde17a939d.tar.xz
libdbpp-odbc-2a1fa15d8baa4eda37e17b2e9362f8bde17a939d.zip
libcodbcpp initial release
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;
+ }
+ }
+}
+