Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

DS.h

Go to the documentation of this file.
00001 /*********************************************************************** 00002 00003 ColorBox2: DS.h 00004 (c) 2004 by Martin Decky 00005 00006 Distributed under the terms of Lesser General Public Licence, see 00007 COPYING. 00008 00009 0.4 10th September 2004 initial 00010 00011 ***********************************************************************/ 00012 00013 00014 #ifndef __CB2__DS_H__ 00015 #define __CB2__DS_H__ 00016 00017 00018 #include <cb2/utils.h> 00019 #include <mysql.h> 00020 00021 00022 #define CB2_MYSQL(cond, error, warning) \ 00023 if (!(cond)) \ 00024 throw ExceptionMySQL(ExceptionMySQL::error, warning ": " #cond " in " __FILE__, __LINE__); 00025 00026 00027 namespace CB2 { 00028 00029 00030 typedef MapList Row; 00031 typedef List< Row > Query; 00041 class Domain : public Class { 00042 public: 00043 00047 typedef enum { 00048 str_row_eq, 00049 str_row_neq 00050 } constrain_str_value; 00051 00055 typedef enum { 00056 int_row_eq, 00057 int_row_neq, 00058 int_row_gt, 00059 int_row_lt, 00060 int_row_ge, 00061 int_row_le 00062 } constrain_int_value; 00063 00064 Domain(); 00065 Domain(const Domain & prev); 00066 Domain(const constrain_str_value con, const String & key, const String & value); 00067 Domain(const constrain_int_value con, const String & key, const int value); 00068 ~Domain(); 00070 const Domain & operator&&(const Domain & right); 00071 const Domain & operator||(const Domain & right); 00072 const Domain & operator!(); 00077 typedef enum { 00078 str_value, 00079 int_value 00080 } constrain_type; 00081 00085 typedef struct { 00086 constrain_str_value con; 00087 String key; 00088 String value; 00089 } constrain_str_value_atom; 00090 00094 typedef struct { 00095 constrain_int_value con; 00096 String key; 00097 int value; 00098 } constrain_int_value_atom; 00099 00103 typedef struct { 00104 constrain_type type; 00105 constrain_str_value_atom str_value; 00106 constrain_int_value_atom int_value; 00107 } constrain_atom; 00108 00109 typedef List< constrain_atom> constrain_literal; 00110 typedef List< constrain_literal> constrain_cnf; 00112 constrain_cnf constrains; 00113 }; 00114 00115 00122 class DataSource : public Class { 00123 public: 00124 DataSource(); 00125 virtual ~DataSource() = 0; 00127 virtual Query Select(const String & table, const Domain & domain, const Query::size_type limit, const Query::size_type displacement) = 0; 00128 }; 00129 00130 00137 class ExceptionMySQL : public Exception { 00138 public: 00139 00140 typedef enum { 00141 unknown_error, 00142 internal_error, 00143 connection_error, 00144 query_error 00145 } error_type; 00147 ExceptionMySQL(); 00148 ExceptionMySQL(const error_type error, const String what); 00149 ExceptionMySQL(const error_type error, const String what, const int line); 00151 error_type GetError() const; 00153 private: 00154 00155 error_type err; 00156 }; 00157 00158 00165 class DSMySQL : public DataSource { 00166 public: 00167 DSMySQL(const String & host, const String & user, const String & passwd, const String & db, const unsigned int port = 0, const String & socket = ""); 00168 virtual ~DSMySQL(); 00170 Query Select(const String & table, const Domain & domain, const Query::size_type limit = 0, const Query::size_type displacement = 0); 00172 private: 00173 00174 MYSQL * handle; 00176 }; 00177 00178 00185 class DSFlatFile : public DataSource { 00186 public: 00187 DSFlatFile(const String & filename); 00188 virtual ~DSFlatFile(); 00189 00190 Query Select(const String & table, const Domain & domain, const Query::size_type limit = 0, const Query::size_type displacement = 0); 00191 }; 00192 00193 00200 class DSCSVFile : public DataSource { 00201 public: 00202 DSCSVFile(const String & filename); 00203 virtual ~DSCSVFile(); 00204 00205 Query Select(const String & table, const Domain & domain, const Query::size_type limit = 0, const Query::size_type displacement = 0); 00206 }; 00207 00208 00215 class DSXMLFile : public DataSource { 00216 public: 00217 DSXMLFile(const String & filename); 00218 virtual ~DSXMLFile(); 00219 00220 Query Select(const String & table, const Domain & domain, const Query::size_type limit = 0, const Query::size_type displacement = 0); 00221 }; 00222 00223 } 00224 00225 00226 #endif

Generated on Thu Sep 16 23:26:49 2004 for ColorBox2 by doxygen 1.3.7