summaryrefslogtreecommitdiff
path: root/libodbcpp/column.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/column.cpp
downloadlibdbpp-odbc-2a1fa15d8baa4eda37e17b2e9362f8bde17a939d.tar.bz2
libdbpp-odbc-2a1fa15d8baa4eda37e17b2e9362f8bde17a939d.tar.xz
libdbpp-odbc-2a1fa15d8baa4eda37e17b2e9362f8bde17a939d.zip
libcodbcpp initial release
Diffstat (limited to 'libodbcpp/column.cpp')
-rw-r--r--libodbcpp/column.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/libodbcpp/column.cpp b/libodbcpp/column.cpp
new file mode 100644
index 0000000..212b792
--- /dev/null
+++ b/libodbcpp/column.cpp
@@ -0,0 +1,54 @@
+#include "column.h"
+#include "error.h"
+#include "timetypepair.h"
+
+ODBC::Column::Column(String n, u_int i) :
+ colNo(i),
+ name(n),
+ fresh(false)
+{
+}
+
+ODBC::Column::~Column()
+{
+}
+
+#define ODBC_DEFAULT_COLUMN_CAST(ctype, rtype) \
+ ODBC::Column::operator rtype() const { \
+ return (dynamic_cast<const _Column<ctype>& >(*this)).value; \
+ }
+
+ODBC_DEFAULT_COLUMN_CAST(SQLINTEGER, unsigned int);
+ODBC_DEFAULT_COLUMN_CAST(SQLINTEGER, unsigned long long);
+ODBC_DEFAULT_COLUMN_CAST(SQLINTEGER, long long);
+ODBC_DEFAULT_COLUMN_CAST(SQLINTEGER, int);
+ODBC_DEFAULT_COLUMN_CAST(SQLDOUBLE, double);
+ODBC_DEFAULT_COLUMN_CAST(SQLDOUBLE, float);
+ODBC_DEFAULT_COLUMN_CAST(SQLCHAR*, const unsigned char * const);
+ODBC_DEFAULT_COLUMN_CAST(SQLCHAR*, String);
+ODBC::Column::operator std::string() const {
+ return (const char*)((dynamic_cast<const _Column<SQLCHAR*>& >(*this)).value);
+}
+ODBC::Column::operator const char * const () const {
+ return (const char*)((dynamic_cast<const _Column<SQLCHAR*>& >(*this)).value);
+}
+ODBC::Column::operator const struct tm & () const {
+ const _Column<TimeTypePair>& c = dynamic_cast<const _Column<TimeTypePair>& >(*this);
+ if (c.fresh) {
+ c.value.sql2c();
+ c.fresh = false;
+ }
+ return c.value.c();
+}
+
+void
+ODBC::Column::bind(SQLHANDLE hStmt, SQLUINTEGER col, SQLSMALLINT ctype, void * buf, size_t size)
+{
+ bindSize = size;
+ RETCODE rc = SQLBindCol(hStmt, col, ctype, buf, bindSize, &bindLen);
+ if (rc != SQL_SUCCESS) {
+ throw Error(rc, SQL_HANDLE_STMT, hStmt, "%s: Bind column %lu", __FUNCTION__, col);
+ }
+}
+
+