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();
64 /* sets a new host name */
65 virtual void setHostName(const char *newHost);
66 /* sets a database name */
67 virtual void setDatabase(const char *newDb);
69 /* func. connects to database-server */
71 virtual int connect(bool create);
72 /* func. disconnects from database-server */
73 virtual void disconnect();
74 /* func. creates new database */
76 /* func. deletes database */
78 /* check if database exists (ie has tables/views defined) */
79 virtual bool exists();
81 /* \brief copy database */
82 virtual int copy(const char *backup_name);
84 /* \brief drop all extra analytics from database */
85 virtual int drop_analytics(void);
87 virtual long nextid(const char* seq_name);
89 /* virtual methods for transaction */
91 virtual void start_transaction();
92 virtual void commit_transaction();
93 virtual void rollback_transaction();
95 /* virtual methods for formatting */
96 virtual std::string vprepare(const char *format, va_list args);
98 bool in_transaction() {return _in_transaction;};
104 /***************** Class SqliteDataset definition *******************
106 class 'SqliteDataset' does a query to SQLite-server
108 ******************************************************************/
110 class SqliteDataset : public Dataset {
114 /* Makes direct queries to database */
115 virtual void make_query(StringList &_sql);
116 /* Makes direct inserts into database */
117 virtual void make_insert();
119 virtual void make_edit();
121 virtual void make_deletion();
123 //static int sqlite_callback(void* res_ptr,int ncol, char** reslt, char** cols);
125 /* This function works only with MySQL database
126 Filling the fields information from select statement */
127 virtual void fill_fields();
128 /* Changing field values during dataset navigation */
129 virtual void free_row(); // free the memory allocated for the current row
134 SqliteDataset(SqliteDatabase *newDb);
139 /* set autorefresh boolean value (if true - refresh the data after edit()
140 or insert() operations default = false) */
141 void set_autorefresh(bool val);
143 /* opens a query & then sets a query results */
145 virtual void open(const std::string &sql);
146 /* func. executes a query without results to return */
148 virtual int exec (const std::string &sql);
149 virtual const void* getExecRes();
150 /* as open, but with our query exept Sql */
151 virtual bool query(const char *query);
152 virtual bool query(const std::string &query);
153 /* func. closes a query */
154 virtual void close(void);
155 /* Cancel changes, made in insert or edit states of dataset */
156 virtual void cancel();
157 /* last inserted id */
158 virtual int64_t lastinsertid();
159 /* sequence numbers */
160 virtual long nextid(const char *seq_name);
161 /* sequence numbers */
162 virtual int num_rows();
163 /* interupt any pending database operation */
164 virtual void interrupt();
168 virtual void first();
172 /* Go to record No (starting with 0) */
173 virtual bool seek(int pos=0);
175 virtual bool dropIndex(const char *table, const char *index);