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: 2005-08-12 / grymse@alhem.net
00008  **/
00009 
00010 /*
00011 Copyright (C) 2001-2006  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_SQLITE
00037 #define _QUERY_H_SQLITE
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 SQLITEW_NAMESPACE
00050 namespace SQLITEW_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);
00075 
00077         sqlite3_stmt *get_result(const std::string& sql);
00080         void free_result();
00083         bool fetch_row();
00085         sqlite_int64 insert_id();
00087         long num_rows();
00089         int num_cols();
00091         std::string GetError();
00093         int GetErrno();
00094 
00096         bool is_null(int x);
00097 
00099         const char *get_string(const std::string& sql);
00101         long get_count(const std::string& sql);
00103         double get_num(const std::string& sql);
00104 
00106         const char *getstr(const std::string& x);
00108         const char *getstr(int x);
00110         const char *getstr();
00111 
00113         long getval(const std::string& x);
00115         long getval(int x);
00117         long getval();
00118 
00120         unsigned long getuval(const std::string& x);
00122         unsigned long getuval(int x);
00124         unsigned long getuval();
00125 
00127         int64_t getbigint(const std::string& x);
00129         int64_t getbigint(int x);
00131         int64_t getbigint();
00132 
00134         uint64_t getubigint(const std::string& x);
00136         uint64_t getubigint(int x);
00138         uint64_t getubigint();
00139 
00141         double getnum(const std::string& x);
00143         double getnum(int x);
00145         double getnum();
00146 
00147 private:
00149         Query(const Query& q) : m_db(q.GetDatabase()) {}
00151         Query& operator=(const Query& ) { return *this; }
00153         void ViewRes();
00155         void error(const std::string& );
00156         Database& m_db; 
00157         Database::OPENDB *odb; 
00158         sqlite3_stmt *res; 
00159         bool row; 
00160         short rowcount; 
00161         std::string m_tmpstr; 
00162         std::string m_last_query; 
00163         int cache_rc; 
00164         bool cache_rc_valid; 
00165         int m_row_count; 
00166         //
00167         std::map<std::string,int> m_nmap; 
00168         int m_num_cols; 
00169 };
00170 
00171 
00172 #ifdef SQLITEW_NAMESPACE
00173 } // namespace SQLITEW_NAMESPACE {
00174 #endif
00175 
00176 #endif // _QUERY_H
Page, code, and content Copyright (C) 2006 by Anders Hedström