1 /**********************************************************************
2 * Copyright (c) 2004, Leo Seib, Hannover
4 * Project:SQLiteDataset C++ Dynamic Library
5 * Module: SQLiteDataset class header file
6 * Author: Leo Seib E-Mail: leoseib@web.de
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 **********************************************************************/
29 #ifndef _SQLITEDATASET_H
30 #define _SQLITEDATASET_H
37 /***************** Class SqliteDatabase definition ******************
39 class 'SqliteDatabase' connects with Sqlite-server
41 ******************************************************************/
42 class SqliteDatabase: public Database {
44 /* connect descriptor */
50 /* default constructor */
55 Dataset *CreateDataset() const;
57 /* func. returns connection handle with SQLite-server */
58 sqlite3 *getHandle() { return conn; }
59 /* func. returns current status about SQLite-server connection */
61 virtual int setErr(int err_code,const char * qry);
62 /* func. returns error message if error occurs */
63 virtual const char *getErrorMsg();
65 /* func. connects to database-server */
66 virtual int connect(bool create);
67 /* func. disconnects from database-server */
68 virtual void disconnect();
69 /* func. creates new database */
71 /* func. deletes database */
73 /* check if database exists (ie has tables/views defined) */
74 virtual bool exists();
76 virtual long nextid(const char* seq_name);
78 /* virtual methods for transaction */
80 virtual void start_transaction();
81 virtual void commit_transaction();
82 virtual void rollback_transaction();
84 /* virtual methods for formatting */
85 virtual std::string vprepare(const char *format, va_list args);
87 bool in_transaction() {return _in_transaction;};
93 /***************** Class SqliteDataset definition *******************
95 class 'SqliteDataset' does a query to SQLite-server
97 ******************************************************************/
99 class SqliteDataset : public Dataset {
109 /* Makes direct queries to database */
110 virtual void make_query(StringList &_sql);
111 /* Makes direct inserts into database */
112 virtual void make_insert();
114 virtual void make_edit();
116 virtual void make_deletion();
118 //static int sqlite_callback(void* res_ptr,int ncol, char** reslt, char** cols);
120 /* This function works only with MySQL database
121 Filling the fields information from select statement */
122 virtual void fill_fields();
123 /* Changing field values during dataset navigation */
124 virtual void free_row(); // free the memory allocated for the current row
129 SqliteDataset(SqliteDatabase *newDb);
134 /* set autorefresh boolean value (if true - refresh the data after edit()
135 or insert() operations default = false) */
136 void set_autorefresh(bool val);
138 /* opens a query & then sets a query results */
140 virtual void open(const std::string &sql);
141 /* func. executes a query without results to return */
143 virtual int exec (const std::string &sql);
144 virtual const void* getExecRes();
145 /* as open, but with our query exept Sql */
146 virtual bool query(const char *query);
147 virtual bool query(const std::string &query);
148 /* func. closes a query */
149 virtual void close(void);
150 /* Cancel changes, made in insert or edit states of dataset */
151 virtual void cancel();
152 /* last inserted id */
153 virtual int64_t lastinsertid();
154 /* sequence numbers */
155 virtual long nextid(const char *seq_name);
156 /* sequence numbers */
157 virtual int num_rows();
158 /* interupt any pending database operation */
159 virtual void interrupt();
163 virtual void first();
167 /* Go to record No (starting with 0) */
168 virtual bool seek(int pos=0);