Logo
~Sockets~
~Examples~
~Contact~


Query.h

Go to the documentation of this file.
00001 // Query.h
00002 /*
00003 Copyright (C) 2001-2005  Anders Hedstrom
00004 
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 */
00019 
00020 #ifndef _QUERY_H
00021 #define _QUERY_H
00022 
00023 
00024 #define DQ_XML_ENDTAG 1
00025 #define DQ_XML_CDATASTRINGS 2
00026 #define DQ_XML_TYPEINFO 4
00027 #define DQ_XML_APPEND 8
00028 #define DQ_XML_BEGIN 16
00029 #define DQ_XML_END 32
00030 
00031 class Database;
00032 class Session;
00033 
00034 
00035 typedef struct tmpstrstruct 
00036 {
00037   struct tmpstrstruct   *next;
00038   char                  *buffer;
00039   short                 temporary;
00040 } TMPSTR;
00041 
00042 class Query
00043 {
00044 public:
00045                         Query();
00046                         Query(Database *dbin);
00047                         Query(Database *dbin,const char *sql);
00048   virtual               ~Query();
00049 
00050   short                 execute(const char *sql);    // query, no result
00051   short                 execute(const std::string &);
00052 
00053 // methods using db specific api calls
00054 
00055   bool                  get_result(const char *sql,char **attrs = NULL);  // query, result
00056   bool                  get_result(const std::string &);
00057   void                  free_result();
00058   bool                  fetch_row();
00059   long                  insert_id();
00060   long                  num_rows();
00061 
00062 // data retreival methods
00063 
00064   char *                get_string(const char *sql);
00065   double                get_num(const char *sql);
00066   long                  get_count(const char *sql);
00067 
00068   char *                get_string(const std::string &);
00069   double                get_num(const std::string &);
00070   long                  get_count(const std::string &);
00071 
00072   char *                getstr(int x);
00073   double                getnum(int x);
00074   long                  getval(int x);
00075 
00076   char *                getstr();
00077   double                getnum();
00078   long                  getval();
00079 
00080   void                  debug(short val);
00081   void                  syslog(short val);
00082 
00083 //SQLITE_FIELD *  STDCALL mysql_fetch_field(SQLITE_RES *result);
00084 
00085 //  SQLITE_FIELD *         fetch_field();
00086   char *                fetch_fieldname();
00087 
00088 // this breaks sql2class 02-04-30
00089 //  void                  safestr(char *s);
00090 //  void                  unsafestr(char *s);
00091 
00092   bool                  GotMore();
00093 
00094   char *                allocsafestr(const char *s);
00095   void                  safestr(const char *src,char *dest);
00096   char *                gettmpstr(int);
00097   void                  safestr(std::string &);
00098 
00099   std::string           XMLSafe(const std::string &);
00100   void                  ReturnRowAsXML(std::string &,const std::string & = "",long = DQ_XML_ENDTAG) {}
00101 
00102   int                   num_cols() { return m_ncolumns; }
00103   bool                  getcol(std::string &colname,std::string &coltype,int &width,int &dec,int &nullable);
00104   bool                  getcol(int x,std::string &colname,std::string &coltype,int &width,int &dec,int &nullable);
00105 
00106 private:
00107   void                  unsafestr(char *s);
00108   //
00109   Database *db;
00110   Session *odb;
00111 //  SQLITE_RES             *res;
00112 //  SQLITE_ROW             row;
00113   char **               res;
00114   char *                row[256];
00115 //  int                   row; // 1 .. m_ncolumns
00116   TMPSTR                *m_tmpstrbase;
00117   short                 rowcount;
00118   short                 _debug;
00119   short                 _syslog;
00120   int                   m_fetchrows;
00121   int                   m_results; // number of rows returned from query
00122   int                   m_ncolumns; // number of columns in result
00123 };
00124 
00125 
00126 
00127 #endif // _QUERY_H
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4