Eneboo - Documentación para desarrolladores
src/sqlite/sqlitedataset.h
Ir a la documentación de este archivo.
00001 /**********************************************************************
00002  * Copyright (c) 2004, Leo Seib, Hannover
00003  *
00004  * Project:SQLiteDataset C++ Dynamic Library
00005  * Module: SQLiteDataset class header file
00006  * Author: Leo Seib      E-Mail: leoseib@web.de
00007  * Begin: 5/04/2002
00008  *
00009  * Permission is hereby granted, free of charge, to any person obtaining a copy
00010  * of this software and associated documentation files (the "Software"), to deal
00011  * in the Software without restriction, including without limitation the rights
00012  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013  * copies of the Software, and to permit persons to whom the Software is
00014  * furnished to do so, subject to the following conditions:
00015  *
00016  * The above copyright notice and this permission notice shall be included in
00017  * all copies or substantial portions of the Software.
00018  *
00019  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00022  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025  * THE SOFTWARE.
00026  *
00027  **********************************************************************/
00028 
00029 #ifndef _SQLITEDATASET_H
00030 #define _SQLITEDATASET_H
00031 
00032 #include <stdio.h>
00033 #include <dataset.h>
00034 #include <sqlite.h>
00035 
00036 namespace dbiplus {
00037 /***************** Class SqliteDatabase definition ******************
00038 
00039        class 'SqliteDatabase' connects with Sqlite-server
00040 
00041 ******************************************************************/
00042 
00043 class FL_EXPORT SqliteDatabase: public Database {
00044 protected:
00045 /* connect descriptor */
00046   sqlite *conn;
00047   bool _in_transaction;
00048   int last_err;
00049 
00050 public:
00051 /* default constructor */
00052   SqliteDatabase();
00053 /* destructor */
00054   ~SqliteDatabase();
00055 
00056   Dataset *CreateDataset() const; 
00057 
00058 /* func. returns connection handle with SQLite-server */
00059   sqlite *getHandle() {  return conn; }
00060 /* func. returns current status about SQLite-server connection */
00061   virtual int status();
00062   virtual int setErr(int err_code,const char * qry);
00063 /* func. returns error message if error occurs */
00064   virtual const char *getErrorMsg();
00065   
00066 /* func. connects to database-server */
00067   virtual int connect();
00068 /* func. disconnects from database-server */
00069   virtual void disconnect();
00070 /* func. creates new database */
00071   virtual int create();
00072 /* func. deletes database */
00073   virtual int drop();
00074 
00075   virtual long nextid(const char* seq_name);
00076 
00077 /* virtual methods for transaction */
00078 
00079   virtual void start_transaction();
00080   virtual void commit_transaction();
00081   virtual void rollback_transaction();
00082 
00083   bool in_transaction() {return _in_transaction;};      
00084 
00085 };
00086 
00087 
00088 
00089 /***************** Class SqliteDataset definition *******************
00090 
00091        class 'SqliteDataset' does a query to SQLite-server
00092 
00093 ******************************************************************/
00094 
00095 class FL_EXPORT SqliteDataset : public Dataset {
00096 protected:
00097 /* query results*/
00098   result_set result;
00099   result_set exec_res;
00100   bool autorefresh;
00101   char* errmsg;
00102   
00103   sqlite* handle();
00104 
00105 /* Makes direct queries to database */
00106   virtual void make_query(StringList &_sql);
00107 /* Makes direct inserts into database */
00108   virtual void make_insert();
00109 /* Edit SQL */
00110   virtual void make_edit();
00111 /* Delete SQL */
00112   virtual void make_deletion();
00113 
00114   //static int sqlite_callback(void* res_ptr,int ncol, char** reslt, char** cols);
00115 
00116 /* This function works only with MySQL database
00117   Filling the fields information from select statement */
00118   virtual void fill_fields();
00119 /* Changing field values during dataset navigation */
00120 
00121 public:
00122 /* constructor */
00123   SqliteDataset();
00124   SqliteDataset(SqliteDatabase *newDb);
00125 
00126 /* destructor */
00127   ~SqliteDataset();
00128 
00129 /* set autorefresh boolean value (if true - refresh the data after edit() 
00130 or insert() operations default = false) */
00131   void set_autorefresh(bool val);
00132 
00133 /* opens a query  & then sets a query results */
00134   virtual void open();
00135   virtual void open(const string &sql);
00136 /* func. executes a query without results to return */
00137   virtual int  exec ();
00138   virtual int  exec (const string &sql);
00139   virtual const void* getExecRes();
00140 /* as open, but with our query exept Sql */
00141   virtual bool query(const char *query);
00142   virtual bool query(const string &query);
00143 /* func. closes a query */
00144   virtual void close(void);
00145 /* Cancel changes, made in insert or edit states of dataset */
00146   virtual void cancel();
00147 /* sequence numbers */
00148   virtual long nextid(const char *seq_name);
00149 /* sequence numbers */
00150   virtual int num_rows();
00151 
00152   virtual bool bof();
00153   virtual bool eof();
00154   virtual void first();
00155   virtual void last();
00156   virtual void prev();
00157   virtual void next();
00158 /* Go to record No (starting with 0) */
00159   virtual bool seek(int pos=0);
00160 
00161 
00162 };
00163 } //namespace
00164 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'