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
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #ifndef _QUERY_H
00050 #define _QUERY_H
00051
00052
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00081 class DOQuery
00082 {
00083
00084 public:
00085 DOQueryField * _firstQueryField;
00086 DOQueryField * _lastQueryField;
00087 int _countQueryField;
00088
00089 protected:
00090 void AddQueryFieldFirst(DOQueryField* item);
00091 void AddQueryFieldLast(DOQueryField* item);
00092 void AddQueryFieldAfter(DOQueryField* item, DOQueryField* pos);
00093 void AddQueryFieldBefore(DOQueryField* item, DOQueryField* pos);
00094 void RemoveQueryField(DOQueryField* item);
00095 void ReplaceQueryField(DOQueryField* item, DOQueryField* newItem);
00096
00097 public:
00098 void DeleteAllQueryField();
00099 DOQueryField* GetFirstQueryField() const;
00100 DOQueryField* GetLastQueryField() const;
00101 DOQueryField* GetNextQueryField(DOQueryField* pos) const;
00102 DOQueryField* GetPrevQueryField(DOQueryField* pos) const;
00103 int GetQueryFieldCount() const;
00104 void MoveQueryFieldFirst(DOQueryField* item);
00105 void MoveQueryFieldLast(DOQueryField* item);
00106 void MoveQueryFieldAfter(DOQueryField* item, DOQueryField* pos);
00107 void MoveQueryFieldBefore(DOQueryField* item, DOQueryField* pos);
00108 void SortQueryField(int (*comp)(DOQueryField*, DOQueryField*));
00109
00110 class QueryFieldIterator
00111 {
00112 private:
00113 DOQueryField* _refQueryField;
00114 DOQueryField* _prevQueryField;
00115 DOQueryField* _nextQueryField;
00116 const DOQuery* _iterQuery;
00117
00118 QueryFieldIterator* _prev;
00119 QueryFieldIterator* _next;
00120
00121 int (DOQueryField::*_method)() const;
00122
00123 static QueryFieldIterator* _first;
00124 static QueryFieldIterator* _last;
00125
00126 public:
00127 QueryFieldIterator(const DOQuery* iterQuery,
00128 int (DOQueryField::*method)() const = 0,
00129 DOQueryField* refQueryField = 0);
00130 QueryFieldIterator(const DOQuery& iterQuery,
00131 int (DOQueryField::*method)() const = 0,
00132 DOQueryField* refQueryField = 0);
00133 QueryFieldIterator(const QueryFieldIterator& iterator,
00134 int (DOQueryField::*method)() const = 0);
00135 ~QueryFieldIterator();
00136
00137 QueryFieldIterator& operator= (const QueryFieldIterator& iterator)
00138 {
00139 _iterQuery = iterator._iterQuery;
00140 _refQueryField = iterator._refQueryField;
00141 _prevQueryField = iterator._prevQueryField;
00142 _nextQueryField = iterator._nextQueryField;
00143 _method = iterator._method;
00144 return *this;
00145 }
00146 DOQueryField* operator++ ()
00147 {
00148 _nextQueryField = _iterQuery->GetNextQueryField(_nextQueryField);
00149 if (_method != 0)
00150 {
00151 while (_nextQueryField && !(_nextQueryField->*_method)())
00152 _nextQueryField = _iterQuery->GetNextQueryField(_nextQueryField);
00153 }
00154 _refQueryField = _prevQueryField = _nextQueryField;
00155 return _refQueryField;
00156 }
00157 DOQueryField* operator-- ()
00158 {
00159 _prevQueryField = _iterQuery->GetPrevQueryField(_prevQueryField);
00160 if (_method != 0)
00161 {
00162 while (_prevQueryField && !(_prevQueryField->*_method)())
00163 _prevQueryField = _iterQuery->GetPrevQueryField(_prevQueryField);
00164 }
00165 _refQueryField = _nextQueryField = _prevQueryField;
00166 return _refQueryField;
00167 }
00168 operator DOQueryField*() { return _refQueryField; }
00169 DOQueryField* operator-> () { return _refQueryField; }
00170 DOQueryField* Get() { return _refQueryField; }
00171 void Reset() { _refQueryField = _prevQueryField = _nextQueryField = (DOQueryField*)0; }
00172
00173 int IsLast() { return (_iterQuery->GetLastQueryField() == _refQueryField); }
00174 int IsFirst() { return (_iterQuery->GetFirstQueryField() == _refQueryField); }
00175
00176 static void Check(DOQueryField* itemQueryField);
00177 static void Check(DOQueryField* itemQueryField, DOQueryField* newItemQueryField);
00178 };
00179
00180
00181 public:
00182 DOConnection * _refConnection;
00183 DOQuery * _prevConnection;
00184 DOQuery * _nextConnection;
00185
00186 public:
00187 DOConnection* GetConnection() const { return _refConnection; };
00188
00189
00190
00191
00192
00193 private:
00194 MYSQL_RES* m_pRes;
00195 MYSQL_ROW m_row;
00196
00197 protected:
00198 CString m_query;
00199
00200 public:
00201
00202
00203 private:
00204 void ConstructorInclude(DOConnection* pConnection);
00205 void DestructorInclude();
00206
00207 protected:
00208
00209 public:
00210 DOQuery(DOConnection* pConnection);
00211 virtual ~DOQuery();
00212 bool Fetch();
00213 DOQueryField* FindQueryField(unsigned int number);
00214 DOQueryField* FindQueryField(const char* fldName);
00215 unsigned int GetNumFields();
00216 unsigned int GetNumRows();
00217 bool Query(const char* pszSQL);
00218 void Seek(unsigned int rownum);
00219 MYSQL_ROW GetRow();
00220 };
00221
00222 #endif
00223
00224
00225 #ifdef CB_INLINES
00226 #ifndef _QUERY_H_INLINES
00227 #define _QUERY_H_INLINES
00228
00232 inline unsigned int DOQuery::GetNumFields()
00233 {
00234 if (m_pRes) {
00235 return mysql_num_fields (m_pRes);
00236 }
00237 return 0;
00238
00239 }
00240
00241
00242
00246 inline unsigned int DOQuery::GetNumRows()
00247 {
00248 if (m_pRes) {
00249 return (unsigned int) mysql_num_rows (m_pRes);
00250 }
00251 return 0;
00252
00253 }
00254
00255
00256
00260 inline void DOQuery::Seek(unsigned int rownum)
00261 {
00262 if (m_pRes) {
00263 mysql_data_seek (m_pRes, rownum);
00264 Fetch ();
00265 }
00266 }
00267
00268
00269
00273 inline MYSQL_ROW DOQuery::GetRow()
00274 {
00275 return m_row;
00276 }
00277
00278
00279
00280
00281
00282
00283 #endif
00284 #endif
00285