Changeset 129 for trunk/src/sql_Query.h
- Timestamp:
- 11/18/09 04:40:30 (3 years ago)
- Files:
-
- 1 modified
-
trunk/src/sql_Query.h (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sql_Query.h
r127 r129 5 5 ** Query.h 6 6 ** 7 ** Published / author: 200 5-08-12/ grymse@alhem.net7 ** Published / author: 2001-02-15 / grymse@alhem.net 8 8 **/ 9 9 10 10 /* 11 Copyright (C) 2001 -2006Anders Hedstrom11 Copyright (C) 2001 Anders Hedstrom 12 12 13 13 This program is made available under the terms of the GNU GPL. … … 34 34 */ 35 35 36 #ifndef _QUERY_H _SQLITE37 #define _QUERY_H _SQLITE36 #ifndef _QUERY_H 37 #define _QUERY_H 38 38 39 39 #include <string> … … 47 47 48 48 49 #ifdef SQLITEW_NAMESPACE50 namespace SQLITEW_NAMESPACE {49 #ifdef MYSQLW_NAMESPACE 50 namespace MYSQLW_NAMESPACE { 51 51 #endif 52 52 53 53 54 /** SQL Statement execute / result . */54 /** SQL Statement execute / result set helper class. */ 55 55 class Query 56 56 { … … 59 59 Query(Database& dbin); 60 60 /** Constructor accepting reference to database object 61 and query stringto execute. */61 and query to execute. */ 62 62 Query(Database& dbin,const std::string& sql); 63 63 ~Query(); 64 64 65 /** Check if database object is connectable. */65 /** Check to see if database object is connectable. */ 66 66 bool Connected(); 67 67 /** Return reference to database object. */ 68 68 Database& GetDatabase() const; 69 /** Return string containinglast query executed. */69 /** Return string of last query executed. */ 70 70 const std::string& GetLastQuery(); 71 71 72 72 /** execute() returns true if query is successful, 73 does not store result .*/73 does not store result */ 74 74 bool execute(const std::string& sql); 75 /** execute query and store result. */ 76 MYSQL_RES *get_result(const std::string& sql); 75 77 76 /** Execute query and store result. */ 77 sqlite3_stmt *get_result(const std::string& sql); 78 /** Free stored result, must be called after get_result() before calling 79 execute()/get_result() again. */ 78 /** free stored result, must be called after get_result() */ 80 79 void free_result(); 81 80 /** Fetch next result row. 82 81 \return false if there was no row to fetch (end of rows) */ 83 boolfetch_row();82 MYSQL_ROW fetch_row(); 84 83 /** Get id of last insert. */ 85 sqlite_int64insert_id();86 /** Returns 0 if there are no rows to fetch. */84 my_ulonglong insert_id(); 85 /** Returns number of rows returned by last select call. */ 87 86 long num_rows(); 88 87 /** Number of columns in current result. */ … … 94 93 95 94 /** Check if column x in current row is null. */ 95 bool is_null(const std::string& x); 96 96 bool is_null(int x); 97 bool is_null(); 97 98 98 99 /** Execute query and return first result as a string. */ … … 103 104 double get_num(const std::string& sql); 104 105 105 /** Return column named x as a string value. */106 106 const char *getstr(const std::string& x); 107 /** Return column x as a string value. */108 107 const char *getstr(int x); 109 /** Return next column as a string value - see rowcount. */110 108 const char *getstr(); 111 112 /** Return column named x as a long integer. */113 109 long getval(const std::string& x); 114 /** Return column x as a long integer. */115 110 long getval(int x); 116 /** Return next column as a long integer - see rowcount. */117 111 long getval(); 118 119 /** Return column named x as an unsigned long integer. */120 112 unsigned long getuval(const std::string& x); 121 /** Return column x as an unsigned long integer. */122 113 unsigned long getuval(int x); 123 /** Return next column as an unsigned long integer. */124 114 unsigned long getuval(); 125 126 /** Return column named x as a 64-bit integer value. */127 115 int64_t getbigint(const std::string& x); 128 /** Return column x as a 64-bit integer value. */129 116 int64_t getbigint(int x); 130 /** Return next column as a 64-bit integer value. */131 117 int64_t getbigint(); 132 133 /** Return column named x as an unsigned 64-bit integer value. */134 118 uint64_t getubigint(const std::string& x); 135 /** Return column x as an unsigned 64-bit integer value. */136 119 uint64_t getubigint(int x); 137 /** Return next column as an unsigned 64-bit integer value. */138 120 uint64_t getubigint(); 139 140 /** Return column named x as a double. */141 121 double getnum(const std::string& x); 142 /** Return column x as a double. */143 122 double getnum(int x); 144 /** Return next column as a double. */145 123 double getnum(); 146 124 125 std::string safestr(const std::string& x); 126 char *strip(char* Oldstr); 127 128 protected: 129 Query(Database *dbin); 130 Query(Database *dbin,const std::string& sql); 147 131 private: 148 /** Hide the copy constructor. */149 132 Query(const Query& q) : m_db(q.GetDatabase()) {} 150 /** Hide the assignment operator. */151 133 Query& operator=(const Query& ) { return *this; } 152 /** Print current result to stdout. */153 void ViewRes();154 /** Print error to debug class. */155 134 void error(const std::string& ); 156 Database& m_db; ///< Reference to database object 157 Database::OPENDB *odb; ///< Connection pool handle 158 sqlite3_stmt *res; ///< Stored result 159 bool row; ///< true if fetch_row succeeded 160 short rowcount; ///< Current column pointer in result 161 std::string m_tmpstr; ///< Used to store result in get_string() call 162 std::string m_last_query; ///< Last query executed 163 int cache_rc; ///< Cached result after call to get_result() 164 bool cache_rc_valid; ///< Indicates cache_rc is valid 165 int m_row_count; ///< 0 if get_result() returned no rows 166 // 167 std::map<std::string,int> m_nmap; ///< map translating column names to index 168 int m_num_cols; ///< number of columns in result 135 Database& m_db; 136 Database::OPENDB *odb; 137 MYSQL_RES *res; 138 MYSQL_ROW row; 139 short rowcount; 140 std::string m_tmpstr; 141 std::string m_last_query; 142 std::map<std::string,int> m_nmap; 143 int m_num_cols; 169 144 }; 170 145 171 146 172 #ifdef SQLITEW_NAMESPACE173 } // namespace SQLITEW_NAMESPACE {147 #ifdef MYSQLW_NAMESPACE 148 } // namespace MYSQLW_NAMESPACE { 174 149 #endif 175 150
Enthral BBS Software for *nix/bsd/osx