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 #ifndef _SIMPLEDB_COLUMN_H_
00027 #define _SIMPLEDB_COLUMN_H_
00028
00029 #include "macros.h"
00030 #include <memory>
00031 #include <iostream>
00032 #include <string>
00033 #include <vector>
00034 #include <stdint.h>
00035 #include "Exception.h"
00036
00037 namespace SimpleDB {
00038
00039 class Database;
00040 struct QueryPimplData;
00041
00045 class Column {
00046
00049 struct PimplData;
00050
00054 friend class Query;
00055
00056 public:
00057
00062 class UnboundException : public Exception {
00063 public:
00064
00067 UnboundException() : Exception("Column is not bound.") {};
00068 };
00069
00070
00075 virtual bool isNull() const;
00076
00084 virtual std::ostream& oStream(std::ostream& oStream) = 0;
00085
00089 virtual ~Column();
00090
00093 Column();
00094
00099 void value() const;
00100
00101 protected:
00102
00106 PimplData& getPimplData();
00107
00116 virtual void doBind(QueryPimplData& queryPimplData, int columnNumber) = 0;
00117
00118 private:
00121 std::auto_ptr<PimplData> pimplData;
00122 };
00123
00126 class StringColumn : public Column {
00127
00128 public:
00129
00135 StringColumn(const int bufferSize);
00136
00139 ~StringColumn();
00140
00141 std::ostream& oStream(std::ostream& oStream);
00142
00147 std::string value() const;
00148
00149 protected:
00150
00153 virtual void doBind(QueryPimplData& queryPimplData, int columnNumber);
00154
00155 private:
00156 std::vector<char> buffer;
00157 };
00158
00161 class BigintColumn : public Column {
00162
00163 public:
00164 std::ostream& oStream(std::ostream& oStream);
00165
00169 int64_t value() const;
00170 protected:
00171
00172 virtual void doBind(QueryPimplData& queryPimplData, int columnNumber);
00173
00174 private:
00175
00178 int64_t colValue;
00179 };
00180
00183 class IntColumn : public Column {
00184
00185 public:
00186
00189 IntColumn();
00190
00191 std::ostream& oStream(std::ostream& oStream);
00192
00196 int32_t value() const;
00197 protected:
00198
00199 virtual void doBind(QueryPimplData& queryPimplData, int columnNumber);
00200
00201 private:
00202
00205 int32_t colValue;
00206 };
00207
00211 class LongColumn : public Column {
00212
00213 public:
00214 std::ostream& oStream(std::ostream& oStream);
00215
00220 long value() const;
00221 protected:
00222
00223 virtual void doBind(QueryPimplData& queryPimplData, int columnNumber);
00224
00225 private:
00228 long colValue;
00229
00230 };
00231
00234 class DoubleColumn : public Column {
00235
00236 public:
00237 std::ostream& oStream(std::ostream& oStream);
00238
00242 double value() const;
00243 protected:
00244
00245 virtual void doBind(QueryPimplData& queryPimplData, int columnNumber);
00246
00247 private:
00248
00251 double colValue;
00252 };
00253
00256 class BoolColumn : public Column {
00257
00258 public:
00259 std::ostream& oStream(std::ostream& oStream);
00260
00265 bool value() const;
00266
00267 protected:
00268
00269 void doBind(QueryPimplData& queryPimplData,
00270 int columnNumber);
00271
00272 private:
00273
00276 unsigned char colValue;
00277
00278 };
00279
00280 }
00281
00282 inline
00283 std::ostream& operator<<(std::ostream& strm, SimpleDB::Column& col) {
00284 return col.oStream(strm);
00285 }
00286
00287 #endif