Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Query.h

Go to the documentation of this file.
00001 // /******************************************************************************\
00002 // *
00003 // * File:          Query.h
00004 // * Creation date: May 17, 2001 14:24
00005 // * Author:        ClassBuilder
00006 // *                XXXX
00007 // * Purpose:       Declaration of class 'DOQuery'
00008 // *
00009 // * Modifications: @INSERT_MODIFICATIONS(* )
00010 // * May 18, 2001 10:12 WERS
00011 // *     Updated interface of method 'ConstructorInclude'
00012 // *     Updated interface of method 'FindQueryField'
00013 // *     Updated interface of method 'DOQuery'
00014 // *     Updated relation 'Connection(DOConnection) <>-->> Query(DOQuery)'
00015 // *     Updated relation 'Query(DOQuery) <>-->> QueryField(DOQueryField)'
00016 // *     Updated member 'm_row'
00017 // *     Updated member 'm_query'
00018 // *     Updated member 'm_pRes'
00019 // * May 17, 2001 19:39 WERS
00020 // *     Updated member 'm_query'
00021 // * May 17, 2001 15:15 WERS
00022 // *     Added method 'GetRow'
00023 // *     Added method 'Seek'
00024 // *     Added method 'Fetch'
00025 // *     Added member 'm_row'
00026 // * May 17, 2001 15:00 WERS
00027 // *     Added method 'GetNumRows'
00028 // * May 17, 2001 14:55 WERS
00029 // *     Added method 'FindQueryField'
00030 // *     Added method 'FindQueryField'
00031 // * May 17, 2001 14:41 WERS
00032 // *     Added method 'GetNumFields'
00033 // *     Added relation 'Query(DOQuery) <>-->> QueryField(DOQueryField)'
00034 // *     Updated interface of method 'ConstructorInclude'
00035 // *     Updated interface of method 'Query'
00036 // * May 17, 2001 14:24 WERS
00037 // *     Added method 'DOQuery'
00038 // * May 17, 2001 14:24 WERS
00039 // *     Added method 'DestructorInclude'
00040 // *     Added method 'ConstructorInclude'
00041 // *     Added method 'Query'
00042 // *     Added method '~DOQuery'
00043 // *     Added relation 'Connection(DOConnection) <>-->> Query(DOQuery)'
00044 // *     Added member 'm_query'
00045 // *     Added member 'm_pRes'
00046 // *
00047 // *
00048 // \******************************************************************************/
00049 #ifndef _QUERY_H
00050 #define _QUERY_H
00051 
00052 //@START_USER1
00057 /* --------------------------------------------------------------
00058 Copyright (C) 2001 LifeLine Networks BV <soap2corba@lifeline.nl>
00059 
00060 This program is free software; you can redistribute it and/or
00061 modify it under the terms of the GNU General Public License
00062 as published by the Free Software Foundation; either
00063 version 2 of the License, or (at your option) any later
00064 version.
00065 
00066 This program is distributed in the hope that it will be useful,
00067 but WITHOUT ANY WARRANTY; without even the implied warranty of
00068 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00069 GNU General Public License for more details.
00070 
00071 You should have received a copy of the GNU General Public License
00072 along with this program; if not, write to the Free Software
00073 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00074 -------------------------------------------------------------- */
00075 //@END_USER1
00076 
00077 
00081 class DOQuery
00082 {
00083     // RELATION_MULTI_OWNED_ACTIVE(DOQuery, Query, DOQueryField, QueryField)
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     // RELATION_MULTI_OWNED_PASSIVE(DOConnection, Connection, DOQuery, Query)
00180     
00181 public:
00182     DOConnection * _refConnection;
00183     DOQuery * _prevConnection;
00184     DOQuery * _nextConnection;
00185 
00186 public:
00187     DOConnection* GetConnection() const { return _refConnection; };
00188 
00189 //@START_USER2
00190 //@END_USER2
00191 
00192 // Members
00193 private:
00194     MYSQL_RES* m_pRes;
00195     MYSQL_ROW m_row;
00196 
00197 protected:
00198     CString m_query;
00199 
00200 public:
00201 
00202 // Methods
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 {//@CODE_241
00234     if (m_pRes) {
00235         return mysql_num_fields (m_pRes);
00236     }
00237     return 0;
00238     
00239 }//@CODE_241
00240 
00241 
00242 
00246 inline unsigned int DOQuery::GetNumRows()
00247 {//@CODE_250
00248     if (m_pRes) {
00249         return (unsigned int) mysql_num_rows (m_pRes);
00250     }
00251     return 0;
00252     
00253 }//@CODE_250
00254 
00255 
00256 
00260 inline void DOQuery::Seek(unsigned int rownum)
00261 {//@CODE_251
00262     if (m_pRes) {
00263         mysql_data_seek (m_pRes, rownum);
00264         Fetch ();
00265     }
00266 }//@CODE_251
00267 
00268 
00269 
00273 inline MYSQL_ROW DOQuery::GetRow()
00274 {//@CODE_257
00275     return m_row;
00276 }//@CODE_257
00277 
00278 
00279 
00280 //@START_USER3
00281 //@END_USER3
00282 
00283 #endif
00284 #endif
00285 

This documentation is part of the "SOAP to CORBA bridge" project
Copyright © 2000 by Lifeline Networks bv.
All rights are reserved.