automotive-message-broker  0.14.803
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
sqlitequery.h
1 /*
2  * timedate - Displays time and date and daily events
3  * Copyright (c) <2009>, Intel Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU Lesser General Public License,
7  * version 2.1, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  */
19 
20 #ifndef SQLITEQUERY_H
21 #define SQLITEQUERY_H
22 
23 #include "sqlitedatabase.h"
24 #include <map>
25 
26 class sqlite3_stmt;
27 
29 {
30 public:
31  sqlitequery() : result(NULL), row(false), cache_rc(0), cache_rc_valid(false), m_row_count(0), m_db(NULL), m_num_cols(0) {}
32  virtual ~sqlitequery();
33 
34  bool init(sqlitedatabase * dbin);
35  bool init(sqlitedatabase * dbin, const std::string & sql);
36 
37  virtual bool Connected(){return odb ? true : false;}
38  virtual bool execute(const std::string & sql);
39  virtual bool fetchRow();
40  virtual long numRows();
41  virtual void freeResult();
42  virtual void resetStatement();
43  virtual long getCount(const std::string & sql);
44  virtual bool prepareStatement(const std::string & sql);
45  virtual bool getResult(const std::string & sql);
46  virtual bool bind(const std::string bindMatch);
47  virtual bool bind(const int value);
48  virtual bool bind(const double value);
49  virtual int64_t getBigInt(){return getBigInt(rowcount++);}
50  virtual int64_t getBigInt(int x);
51  virtual int GetErrno();
52  virtual std::string GetError();
53  virtual double getNum(){ return getNum(rowcount++); }
54  virtual double getNum(int x);
55  virtual const char * getStr(){return getStr(rowcount++);}
56  virtual const char * getStr(int x);
57  virtual uint64_t getUBigInt(){ return getUBigInt(rowcount++); }
58  virtual uint64_t getUBigInt(int x);
59  virtual unsigned long getUVal(){ return getUVal(rowcount++); }
60  virtual unsigned long getUVal(int x);
61  virtual long getVal(){ return getVal(rowcount++); }
62  virtual long getVal(int x);
63  virtual bool isNull(int x);
64 protected:
65  sqlite3_stmt * result;
66  bool row;
67  int cache_rc;
68  bool cache_rc_valid;
69  int m_row_count;
70 
71  virtual sqlitequery & operator=(const sqlitequery &){return *this;}
72 
73  sqlitedatabase * m_db;
74  std::string m_last_query;
75  short rowcount;
76  std::string m_tmpstr;
77  std::map<std::string, int> m_nmap;
78  int m_num_cols;
79  SqliteDB * odb;
80 
81 private:
82  std::string sql_replace_tokens(std::string sqlstring,std::string &dest);
83 };
84 
85 #endif
86