00001
00002 #if !defined(__INC_GQL_OBJECT_H)
00003 #define __INC_GQL_OBJECT_H
00004
00005 #include <string>
00006
00007 #include <gql++/exception.h>
00008
00009 namespace GQL
00010 {
00011
00012 class SQLType
00013 {
00014 public:
00015 enum TypeCode
00016 {
00017 VOID,
00018 BOOLEAN,
00019 DATE,
00020 DECIMAL,
00021 FLOAT,
00022 SMALLINT,
00023 INTEGER,
00024 INTERVAL,
00025 NUMERIC,
00026 TIME,
00027 TIME_WITH_TZ,
00028 TIMESTAMP_WITH_TZ,
00029 CHARACTER,
00030 CHARACTER_VARYING,
00031 BLOB,
00032
00033 MAX_TYPE
00034 };
00035
00036 SQLType();
00037 SQLType(TypeCode type, ...);
00038
00039 TypeCode typecode() const { return(type_); }
00040 int length() const { return(length_); }
00041 int decimals() const { return(decimals_); }
00042 private:
00043 TypeCode type_;
00044 int length_;
00045 int decimals_;
00046 };
00047
00048 class Blob
00049 {
00050 public:
00051 virtual ~Blob();
00052
00053 typedef enum
00054 {
00055 in = 0x01,
00056 out = 0x02
00057 } openmode;
00058 typedef enum { beg, cur, end } seek_dir;
00059
00060 virtual void open(openmode om = in) = 0;
00061 virtual bool is_open() = 0;
00062 virtual void close() = 0;
00063
00064 virtual int write(const void *data, int len) = 0;
00065 virtual int read(void *data, int len) = 0;
00066 virtual int seek(int offset, seek_dir whence) = 0;
00067 virtual int tell() const = 0;
00068 protected:
00069 Blob() { }
00070 };
00071
00072 class SQLObject
00073 {
00074 public:
00075 SQLObject() {
00076 is_null_ = true;
00077 type_ = VOID;
00078 }
00079 virtual ~SQLObject() { }
00080
00081 void set_null() { is_null_ = true; }
00082 bool is_null() const { return(is_null_); }
00083
00084 virtual string output() const;
00085 virtual bool input(const string& s);
00086
00087 virtual string to_string() const;
00088 virtual long to_int() const;
00089 virtual double to_real() const;
00090 virtual bool to_boolean() const;
00091 virtual Blob *to_blob() const;
00092
00093 virtual bool from_string(const string& s);
00094 virtual bool from_int(long l);
00095 virtual bool from_real(double d);
00096 virtual bool from_boolean(bool b);
00097 virtual bool from_type(const SQLType& type);
00099 virtual bool from_blob(const Blob *blob = 0);
00100 protected:
00101 void set_null(bool null) { is_null_ = null; }
00102 private:
00103 bool is_null_;
00104
00105 enum { VOID, STRING, INT, FLOAT, TYPE, BLOB } type_;
00106 string value_;
00107 };
00108
00109 }
00110
00111
00112 #endif