Forums  +  C++ and Sockets  +  C++ and SQL: MySQL, sqlite, ODBC  +  Miscellaneous Projects
Logo
~Database~
~ C++ ~
~Contact~

Query.h

Go to the documentation of this file.
00001 #ifdef _WIN32
00002 #pragma warning(disable:4786)
00003 #endif
00004 /*
00005  **     Query.h
00006  **
00007  **     Published / author: 2001-02-15 / grymse@alhem.net
00008  **/
00009 
00010 /*
00011 Copyright (C) 2001  Anders Hedstrom
00012 
00013 This program is made available under the terms of the GNU GPL.
00014 
00015 If you would like to use this program in a closed-source application,
00016 a separate license agreement is available. For information about 
00017 the closed-source license agreement for this program, please
00018 visit http://www.alhem.net/sqlwrapped/license.html and/or
00019 email license@alhem.net.
00020 
00021 This program is free software; you can redistribute it and/or
00022 modify it under the terms of the GNU General Public License
00023 as published by the Free Software Foundation; either version 2
00024 of the License, or (at your option) any later version.
00025 
00026 This program is distributed in the hope that it will be useful,
00027 but WITHOUT ANY WARRANTY; without even the implied warranty of
00028 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00029 GNU General Public License for more details.
00030 
00031 You should have received a copy of the GNU General Public License
00032 along with this program; if not, write to the Free Software
00033 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00034 */
00035 
00036 #ifndef _QUERY_H
00037 #define _QUERY_H
00038 
00039 #include <string>
00040 #include <map>
00041 #ifdef WIN32
00042 typedef unsigned __int64 uint64_t;
00043 typedef __int64 int64_t;
00044 #else
00045 #include <stdint.h>
00046 #endif
00047 
00048 
00049 #ifdef MYSQLW_NAMESPACE
00050 namespace MYSQLW_NAMESPACE {
00051 #endif
00052 
00053 
00055 class Query 
00056 {
00057 public:
00059         Query(Database& dbin);
00062         Query(Database& dbin,const std::string& sql);
00063         ~Query();
00064 
00066         bool Connected();
00068         Database& GetDatabase() const;
00070         const std::string& GetLastQuery();
00071 
00074         bool execute(const std::string& sql);
00076         MYSQL_RES *get_result(const std::string& sql);
00077 
00079         void free_result();
00082         MYSQL_ROW fetch_row();
00084         my_ulonglong insert_id();
00086         long num_rows();
00088         int num_cols();
00090         std::string GetError();
00092         int GetErrno();
00093 
00095         bool is_null(const std::string& x);
00096         bool is_null(int x);
00097         bool is_null();
00098 
00100         const char *get_string(const std::string& sql);
00102         long get_count(const std::string& sql);
00104         double get_num(const std::string& sql);
00105 
00106         const char *getstr(const std::string& x);
00107         const char *getstr(int x);
00108         const char *getstr();
00109         long getval(const std::string& x);
00110         long getval(int x);
00111         long getval();
00112         unsigned long getuval(const std::string& x);
00113         unsigned long getuval(int x);
00114         unsigned long getuval();
00115         int64_t getbigint(const std::string& x);
00116         int64_t getbigint(int x);
00117         int64_t getbigint();
00118         uint64_t getubigint(const std::string& x);
00119         uint64_t getubigint(int x);
00120         uint64_t getubigint();
00121         double getnum(const std::string& x);
00122         double getnum(int x);
00123         double getnum();
00124 
00125         std::string safestr(const std::string& x);
00126 
00127 protected:
00128         Query(Database *dbin);
00129         Query(Database *dbin,const std::string& sql);
00130 private:
00131         Query(const Query& q) : m_db(q.GetDatabase()) {}
00132         Query& operator=(const Query& ) { return *this; }
00133         void error(const std::string& );
00134         Database& m_db;
00135         Database::OPENDB *odb;
00136         MYSQL_RES *res;
00137         MYSQL_ROW row;
00138         short rowcount;
00139         std::string m_tmpstr;
00140         std::string m_last_query;
00141         std::map<std::string,int> m_nmap;
00142         int m_num_cols;
00143 };
00144 
00145 
00146 #ifdef MYSQLW_NAMESPACE
00147 } // namespace MYSQLW_NAMESPACE {
00148 #endif
00149 
00150 #endif // _QUERY_H
Page, code, and content Copyright (C) 2006 by Anders Hedström