summaryrefslogtreecommitdiff
path: root/libodbcpp/param.h
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2010-09-16 00:01:56 +0000
committerrandomdan <randomdan@localhost>2010-09-16 00:01:56 +0000
commit7297648c278903589beebf6fbc7511e5c1ff421d (patch)
treea2686c7d458aad2c32bcb1ae61cb4e04702fd9d4 /libodbcpp/param.h
parentRemove duplication in ODBC::Connection constructors (diff)
downloadlibdbpp-odbc-7297648c278903589beebf6fbc7511e5c1ff421d.tar.bz2
libdbpp-odbc-7297648c278903589beebf6fbc7511e5c1ff421d.tar.xz
libdbpp-odbc-7297648c278903589beebf6fbc7511e5c1ff421d.zip
Rewrite the whole of parameter and column binding almost from scratch
No more template rubbish, no more messy partial specialisation Add copyless rebind of column to parameter Changes in project2 to suit
Diffstat (limited to 'libodbcpp/param.h')
-rw-r--r--libodbcpp/param.h96
1 files changed, 84 insertions, 12 deletions
diff --git a/libodbcpp/param.h b/libodbcpp/param.h
index f0d70ab..f845a49 100644
--- a/libodbcpp/param.h
+++ b/libodbcpp/param.h
@@ -2,25 +2,97 @@
#define ODBC_PARAM_H
#include <malloc.h>
+#include <sqlext.h>
+#include <glibmm/ustring.h>
#include "bind.h"
namespace ODBC {
- template <class> class _Param;
- class Param : public BindBase {
+ class Command;
+ class Param : public virtual Bind {
public:
Param();
- virtual ~Param();
- bool bound; // Has SqlBind... been called?
- void bind(SQLHANDLE, SQLUINTEGER, SQLSMALLINT, SQLSMALLINT, SQLINTEGER,
- SQLINTEGER, const void*, size_t);
- template <class t>
- static ODBC::_Param<t>*
- makeParam(ODBC::Param*& p);
+ Param(Command *, unsigned int idx);
+ virtual ~Param() = 0;
+ void bind() const;
+
+ virtual SQLSMALLINT stype() const = 0; // The SQL type ID
+ virtual SQLINTEGER dp() const = 0; // The decimal place count
+ virtual const void * dataAddress() const = 0; // The address of the data
+
+ protected:
+ friend class Column;
+ mutable Command * paramCmd;
+ mutable unsigned int paramIdx;
+ mutable bool paramBound; // Has SqlBind(...) been called since last change of address?
+ SQLLEN dataLength;
+ };
+
+ class SignedIntegerParam : public Param {
+ public:
+ SignedIntegerParam() : Param() { }
+ SignedIntegerParam(Command * c, unsigned int i) : Param(c, i) { bindLen = size(); }
+ virtual SQLSMALLINT ctype() const { return SQL_C_LONG; }
+ virtual SQLSMALLINT stype() const { return SQL_C_LONG; }
+ virtual SQLINTEGER size() const { return sizeof(SQLINTEGER); }
+ virtual SQLINTEGER dp() const { return 0; }
+ virtual const void * dataAddress() const { return &data; }
+ void operator=(const SQLINTEGER & d) { data = d; }
+ protected:
+ SQLINTEGER data;
+ };
+ class UnsignedIntegerParam : public Param {
+ public:
+ UnsignedIntegerParam() : Param() { }
+ UnsignedIntegerParam(Command * c, unsigned int i) : Param(c, i) { bindLen = size(); }
+ virtual SQLSMALLINT ctype() const { return SQL_C_ULONG; }
+ virtual SQLSMALLINT stype() const { return SQL_C_ULONG; }
+ virtual SQLINTEGER size() const { return sizeof(SQLUINTEGER); }
+ virtual SQLINTEGER dp() const { return 0; }
+ virtual const void * dataAddress() const { return &data; }
+ void operator=(const SQLUINTEGER & d) { data = d; }
+ protected:
+ SQLUINTEGER data;
+ };
+ class FloatingPointParam : public Param {
+ public:
+ FloatingPointParam() : Param() { }
+ FloatingPointParam(Command * c, unsigned int i) : Param(c, i) { bindLen = size(); }
+ virtual SQLSMALLINT ctype() const { return SQL_C_DOUBLE; }
+ virtual SQLSMALLINT stype() const { return SQL_C_DOUBLE; }
+ virtual SQLINTEGER size() const { return sizeof(SQLDOUBLE); }
+ virtual SQLINTEGER dp() const { return 10; }
+ virtual const void * dataAddress() const { return &data; }
+ void operator=(const SQLDOUBLE & d) { data = d; }
+ protected:
+ SQLDOUBLE data;
+ };
+ class GlibUstringParam : public Param {
+ public:
+ GlibUstringParam() : Param() { }
+ GlibUstringParam(Command * c, unsigned int i) : Param(c, i) { bindLen = size(); }
+ virtual SQLSMALLINT ctype() const { return SQL_C_CHAR; }
+ virtual SQLSMALLINT stype() const { return SQL_CHAR; }
+ virtual SQLINTEGER size() const { return data.bytes(); }
+ virtual SQLINTEGER dp() const { return 0; }
+ virtual const void * dataAddress() const { return data.data(); }
+ void operator=(const Glib::ustring & d);
+ protected:
+ Glib::ustring data;
};
- template <class t>
- class _Param : public Bind<t>, public Param {
+ class TimeStampParam : public Param {
public:
- ~_Param() {}
+ TimeStampParam() : Param() { }
+ TimeStampParam(Command * c, unsigned int i) : Param(c, i) { bindLen = size(); }
+ virtual SQLSMALLINT ctype() const { return SQL_C_TYPE_TIMESTAMP; }
+ virtual SQLSMALLINT stype() const { return SQL_TYPE_TIMESTAMP; }
+ virtual SQLINTEGER size() const { return sizeof(SQL_TIMESTAMP_STRUCT); }
+ virtual SQLINTEGER dp() const { return 0; }
+ virtual const void * dataAddress() const { return &data; }
+ void operator=(const time_t & d);
+ void operator=(const struct tm * d) { data << *d; }
+ void operator=(const SQL_TIMESTAMP_STRUCT & d) { data = d; }
+ protected:
+ SQL_TIMESTAMP_STRUCT data;
};
}