xc
Query.h
1 #ifdef _WIN32
2 #pragma warning(disable:4786)
3 #endif
4 /*
5  ** Query.h
6  **
7  ** Published / author: 2005-08-12 / grymse@alhem.net
8  **/
9 
10 //Modificada LCPT.
11 
12 /*
13 Copyright (C) 2001-2006 Anders Hedstrom
14 
15 This program is free software; you can redistribute it and/or
16 modify it under the terms of the GNU General Public License
17 as published by the Free Software Foundation; either version 2
18 of the License, or (at your option) any later version.
19 
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24 
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 */
29 
30 #ifndef _QUERY_H_SQLITE
31 #define _QUERY_H_SQLITE
32 
33 #include <string>
34 #include <map>
35 #ifdef WIN32
36 typedef unsigned __int64 uint64_t;
37 typedef __int64 int64_t;
38 #else
39 #include <stdint.h>
40 #endif
41 
42 
43 #ifdef SQLITEW_NAMESPACE
44 namespace SQLITEW_NAMESPACE {
45 #endif
46 
47 
49 class Query
50  {
51  private:
53  Query(const Query& q) : m_db(q.GetDatabase()), res(NULL) {}
55  Query& operator=(const Query& ) { return *this; }
57  void ViewRes();
59  void error(const std::string& );
60  Database& m_db;
61  Database::OPENDB *odb;
62  sqlite3_stmt *res;
63  bool row;
64  short rowcount;
65  std::string m_tmpstr;
66  std::string m_last_query;
67  int cache_rc;
68  bool cache_rc_valid;
69  int m_row_count;
70  //
71  std::map<std::string,int> m_nmap;
72  public:
74  Query(Database& dbin);
77  Query(Database& dbin,const std::string& sql);
78  ~Query(void);
79 
81  bool Connected();
83  Database& GetDatabase() const;
85  const std::string& GetLastQuery(void) const;
86 
89  bool execute(const std::string& sql);
90  bool insert_blob1(const std::string &sql,const void *blobData,const size_t &numBytes);
92  sqlite3_stmt *get_result(const std::string& sql);
95  void free_result();
98  bool fetch_row(void);
100  sqlite_int64 insert_id();
101 
102  long num_rows(void) const;
103  size_t num_columns(void) const;
104  std::string field_names(void) const;
105  inline int field_index(const std::string &str)
106  { return (m_nmap[str] - 1); }
107 
109  std::string getError(void) const;
111  int GetErrno();
112 
114  const char *get_string(const std::string& sql);
116  long get_count(const std::string& sql);
118  double get_num(const std::string& sql);
119 
121  bool is_null(int x);
122 
123 
125  const void *getblob(const std::string& x);
127  const void *getblob(int x);
129  const void *getblob();
130 
132  const char *getstr(const std::string& x);
134  const char *getstr(int x);
136  const char *getstr();
137 
139  long getval(const std::string& x);
141  long getval(int x);
143  long getval();
144 
146  unsigned long getuval(const std::string& x);
148  unsigned long getuval(int x);
150  unsigned long getuval();
151 
153  int64_t getbigint(const std::string& x);
155  int64_t getbigint(int x);
157  int64_t getbigint();
158 
160  uint64_t getubigint(const std::string& x);
162  uint64_t getubigint(int x);
164  uint64_t getubigint();
165 
167  double getnum(const std::string& x);
169  double getnum(int x);
171  double getnum();
172  };
173 
174 
175 #ifdef SQLITEW_NAMESPACE
176 } // namespace SQLITEW_NAMESPACE {
177 #endif
178 
179 #endif // _QUERY_H
Definition: Database.h:53
Connection pool struct.
Definition: Database.h:85
Database & GetDatabase() const
Return reference to database object.
Definition: Query.cpp:79
SQL Statement execute / result.
Definition: Query.h:49