Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

sql.h

00001 /***************************************************************************
00002  *   Copyright (C) 2006 by Graeme Foster                                   *
00003  *   email    foster.graeme@gmail.com                                      *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #ifndef __SQL
00021 #define __SQL
00022 
00023 #include <stdexcept>
00024 
00025 #include <QtSql>
00026 
00039 class sql
00040 {
00041         public:  // static properties
00042                 static QString * DefaultConnectionName; 
00043         private: // Singleton Instance
00044                 static sql * _instance;        
00045         private: // properties
00046                 QString      lastDBConnName;   
00047                 QSqlQuery  * result;           
00048                 QList<QSqlQuery *> queryList;  
00049                 QSqlQuery  * activeQuery;      
00050                 QList<QSqlQuery *> cursorList; 
00051         public:  // static methods
00052                 static sql * Instance();       
00053         public:  // methods
00055                 inline void setCursor() {cursorList.push_back(result);}
00057                 inline void restoreCursor() {result = cursorList.takeLast();}
00067                 void initConn(const QString & uName
00068                                                  ,const QString & dbName = "guest"
00069                                                  ,const QString & password =""
00070                                                  ,const QString & connName = "guestConn"
00071                                                  ,const QString & host="localhost"
00072                                                  ,const QString & connType= "QPSQL"
00073                                                  );
00082                 int prepare(const QString & functionName
00083                            ,int paramCnt
00084                            ,const QString & connName="");
00085                 
00087                 int prepare(const QString & command
00088                            ,const QString & connName="");
00095                 void bind(int posn
00096                          ,QVariant value
00097                          ,int qID=-1);
00103                 bool query(int qID=-1);
00105                 bool first();
00107                 bool next ();
00109                 bool last ();
00113                 QVariant get(int index);
00117                 QVariant getFirst(int index);
00121                 QVariant getNext(int index);
00122                 
00124                 void dump();
00125         private: // methods
00127                 sql ();
00129                 sql (sql & clone);
00130         public:  // methods to be moved to a specialist class
00131                 QString * useModuleConn() {return &lastDBConnName;}
00132 };
00133 
00142 class sqlE
00143 {
00144         public:
00146                 sqlE(const QSqlDatabase & dbConn
00147                          ,const QString & type = "Database Error");
00149                 QString getErrorType() {return ErrorType;}
00151                 QString getErrorMessage() {return ErrorMessage;}
00152         private:
00153                 QString ErrorType;    
00154                 QString ErrorMessage; 
00155 };
00156 
00157 #endif

Generated on Thu Apr 6 16:27:17 2006 for time-table by  doxygen 1.4.4