00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef __SIMPLEDB_COLUMN_H_
00028 #define __SIMPLEDB_COLUMN_H_ 1
00029
00030 #include <sql.h>
00031 #include <sqlext.h>
00032 #include <iostream>
00033 #include <string>
00034 #include "Exception.h"
00035
00036 namespace SimpleDB {
00037
00041 class Column {
00042
00043 public:
00044
00049 class UnboundException : public Exception {
00050 public:
00051
00054 UnboundException() : Exception("Column is not bound.") {};
00055 };
00056
00057
00062 virtual bool isNull();
00063
00072 virtual void bind(SQLHSTMT statementHandle, int columnNumber) = 0;
00073
00081 virtual std::ostream& oStream(std::ostream& oStream) = 0;
00082
00086 virtual ~Column() {};
00087
00090 Column();
00091
00092
00097 void value();
00098
00099 protected:
00100
00103 SQLINTEGER lengthOrIndex;
00104
00107 bool bound;
00108
00112 std::string name;
00113 };
00114
00117 class StringColumn : public Column {
00118
00119 public:
00120
00126 StringColumn(const int bufferSize);
00127
00130 ~StringColumn();
00131
00132 std::ostream& oStream(std::ostream& oStream);
00133
00134 void bind(SQLHSTMT statementHandle, int columnNumber);
00135
00140 std::string value();
00141
00142 private:
00143 long bufferSize;
00144 char * buffer;
00145 };
00146
00149 class LongColumn : public Column {
00150
00151 public:
00152 std::ostream& oStream(std::ostream& oStream);
00153
00154 void bind(SQLHSTMT statementHandle, int columnNumber);
00155
00160 long value() {Column::value(); if(isNull()) return 0; else return colValue;};
00161
00162 private:
00165 long colValue;
00166
00167 };
00168
00171 class BoolColumn : public Column {
00172
00173 public:
00174 std::ostream& oStream(std::ostream& oStream);
00175
00176 void bind(SQLHSTMT statementHandle, int columnNumber);
00177
00182 bool value() ;
00183
00184 private:
00187 unsigned char colValue;
00188
00189 };
00190
00191 }
00192
00193 inline
00194 std::ostream& operator<<(std::ostream& strm, SimpleDB::Column& col) {
00195 return col.oStream(strm);
00196 }
00197
00198 #endif