USGS

Isis 3.0 Developer's Reference (API)

Home

SqlQuery.h

Go to the documentation of this file.
00001 #ifndef SqlQuery_h
00002 #define SqlQuery_h
00003 
00026 #include <string>
00027 #include <vector>
00028 #include <iostream>
00029 #include "IException.h"
00030 #include "Database.h"
00031 #include <QSqlQuery>
00032 #include <QSqlError>
00033 
00034 namespace Isis {
00035 
00036   class SqlRecord;
00037 
00152   class SqlQuery : public QSqlQuery {
00153     public:
00154       SqlQuery();
00155       SqlQuery(Database &db);
00156       SqlQuery(const std::string &query,
00157                Database db = Database(Database::Connect));
00158       SqlQuery(const SqlQuery &other);
00159       virtual ~SqlQuery()  { }
00160 
00167       bool isThrowing() const {
00168         return (_throwIfFailed);
00169       }
00170 
00174       void setThrowOnFailure() {
00175         _throwIfFailed = true;
00176       }
00180       void setNoThrowOnFailure() {
00181         _throwIfFailed = false;
00182       }
00183 
00184       bool exec(const std::string &query);
00185       bool exec() {
00186         return(QSqlQuery::exec());
00187       }
00188       std::string getQuery() const;
00189 
00190       int nFields() const;
00191       std::string fieldName(int index) const;
00192       int fieldIndex(const std::string &name) const;
00193       std::vector<std::string> fieldNameList() const;
00194       std::vector<std::string> fieldTypeList() const;
00195 
00196       int nRows() const;
00197       SqlRecord getRecord() const;
00198 
00199     private:
00200       bool _throwIfFailed;        
00201 
00202       void tossQueryError(const std::string &message, const char *f, int l) const;
00203   };
00204 }
00205 #endif