summaryrefslogtreecommitdiff
path: root/libodbcpp/param.h
blob: 0009956fdabd5c6242389817fac1c368ae7dc76b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifndef ODBC_PARAM_H
#define ODBC_PARAM_H

#include <malloc.h>
#include <sqlext.h>
#include <glibmm/ustring.h>
#include "bind.h"

namespace ODBC {
	class Command;
	class Param : public virtual Bind {
		public:
			Param();
			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;
	};
	class TimeStampParam : public Param {
		public:
			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;
	};
	class NullParam : public Param {
		public:
			NullParam() : Param() { }
			NullParam(Command * c, unsigned int i) : Param(c, i) { bindLen = SQL_NULL_DATA; }
			virtual SQLSMALLINT ctype() const { return SQL_C_LONG; }
			virtual SQLSMALLINT stype() const { return SQL_C_LONG; }
			virtual SQLINTEGER size() const { return 0; }
			virtual SQLINTEGER dp() const { return 0; }
			virtual const void * dataAddress() const { return NULL; }
	};
}

#endif