Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | Related Pages | Examples

Column.h

00001 /* -*- c++ -*-
00002  * __BEGIN_COPYRIGHT
00003  * SimpleDB API
00004  * 
00005  * Copyright (C) 2005 Eminence Technology Pty Ltd
00006  * 
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  * 
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  * 
00017  * You can view the GNU Lesser General Public Licence at
00018  * http://www.gnu.org/licenses/lgpl.html or you can write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  * 
00021  * Eminence Technology Pty Ltd can be contacted by writing to
00022  * Eminence Technology, PO Box 118, Moorooka QLD 4105, Australia.
00023  * Alternatively, you may email opensource [at] eminence [dot] com [dot] au
00024  * __END_COPYRIGHT
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" // for Database::Exception
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

Copyright (C) 2005 Eminence Technology Pty Ltd.
Documentation pages generated by doxygen.

SourceForge.net Logo