Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

sqlite.h

Go to the documentation of this file.
00001 
00002 // Name:        wx/dbi/sqlite.h
00003 // Purpose:     
00004 // Author:      Joe Yates
00005 // Created:     2004-11-17
00006 // Copyright:   (c) Joe Yates
00007 // License:     BSD license (see the file 'LICENSE.txt')
00009 
00010 #ifndef __wx_dbi_sqlite_h__
00011 #define __wx_dbi_sqlite_h__
00012 
00013 #ifdef wxDBI_SQLITE
00014 
00015 #include <wx/dbi.h>
00016 // Interface to SQLite
00017 #include <sqlite3.h>
00018 
00019 namespace wx
00020 {
00021 
00022 namespace DBI
00023 {
00024 
00025 // Map unicode names (and non-) onto common names
00026 #if wxUSE_UNICODE
00027   #define SQLite3_open(a, b)              sqlite3_open16(a, b)
00028   #define SQLite3_prepare(a, b, c, d, e)  sqlite3_prepare16(a, b, c, d, e)
00029   #define SQLite3_errmsg(a)               sqlite3_errmsg16(a)
00030   
00031   #define SQLiteString                    void *  
00032   #define wxStringBytes(x)                (2 * x.Length())
00033   #define SQLiteStringTowxString(x)       cnv.cMB2WC((const char *) x)
00034 //  #define wxStringToSQLiteString(x)       cnv.cWC2MB(x.c_str()).data()
00035 #else // wxUSE_UNICODE
00036   #define SQLite3_open(a, b)              sqlite3_open(a, b)
00037   #define SQLite3_prepare(a, b, c, d, e)  sqlite3_prepare(a, b, c, d, e)
00038   #define SQLite3_errmsg(a)               sqlite3_errmsg(a)
00039   
00040 //  #define SQLiteStringTowxString(x)       x
00041   #define wxStringBytes(x)                (x.Length())
00042 #endif // wxUSE_UNICODE
00043 
00044 // Redefine the rest, just to keep the names in line
00045 #define SQLite3_close(a)                  sqlite3_close(a)
00046 #define SQLite3_finalize(a)               sqlite3_finalize(a)
00047 
00048 #define SQLITE_DATABASE_PATHNAME wxT("PathName")
00049 #define SQLITE_CREATEIFMISSING wxT("CreateIfMissing")
00050 
00051 class SQLite : public Database
00052   {
00053   // friends, classes, enums and types
00054   friend class SQLiteStatement;
00055 
00056   // Constructors/destructors
00057   public:
00061     SQLite();
00062 
00067     ~SQLite()
00068       {
00069       Disconnect();
00070       }
00071 
00073   // 'Database' Implementation
00074 
00075   // Operators
00076 
00077   // Methods
00078   public:
00079     // Connection
00080 
00091     virtual void      Connect(const ConnectionInfo& cni);
00092     virtual void      Disconnect();
00093     bool              IsConnected();
00094 
00095     // Transactions
00096     void Begin();
00097     void Rollback();
00098     void Commit();
00099 
00100     // Queries
00101     Statement *       Prepare(wxString const& sQuery);
00102 
00103     // Database info
00104     wxArrayString     GetDatabases();
00105     bool              DatabaseExists(const wxString& sDatabaseName);
00106     wxArrayString     GetTables();
00107     bool              TableExists(const wxString& sTableName);
00108 
00110   // SQLite-specific methods
00111   public:
00112 
00114   // Members
00115   private:
00116     sqlite3 *         plite;
00117     wxString          sDatabasePathName;
00118   };
00119 
00120 class SQLiteStatement : public Statement
00121   {
00122   // friends, classes, enums and types
00123 
00124   public:
00125     SQLiteStatement(Database * pdbOwner, const wxString& sNewQuery);
00126     ~SQLiteStatement();
00127 
00128   public:
00129     bool  DataAvailable();
00130 
00135     void  ExecutePrepared(const ArrayRecord& raParameters = ArrayRecord());
00136 
00141     void  ExecuteTemporary(const ArrayRecord& raParameters = ArrayRecord());
00142     long  GetLastInsertId();
00143 
00144   protected:
00145     int   GetFieldCount();
00146     void  MoveNext();
00147     void  GetFieldValue
00148       (
00149       int             nIndex,
00150       wxVariant&      v
00151       );
00152     wxString GetFieldName
00153       (
00154       int         nIndex
00155       );
00156 
00157   private:
00158     void  Execute(const ArrayRecord& raParameters);
00159 
00160   private:
00161     sqlite3_stmt *  pls;
00162     int             nStepReturn;
00163   };
00164 
00165 } //namespace DBI
00166 
00167 } //namespace wx
00168 
00169 #endif // def wxDBI_SQLITE
00170 
00171 #endif // ndef __wx_dbi_sqlite_h__
00172 

Generated on Wed Jan 25 08:13:09 2006 for Sherpa wxWidgets Classes by doxygen 1.3.6