Isis 3 Programmer Reference
SqlQuery.h
Go to the documentation of this file.
1 #ifndef SqlQuery_h
2 #define SqlQuery_h
3 
26 #include <string>
27 #include <vector>
28 #include <iostream>
29 #include "IException.h"
30 #include "Database.h"
31 #include <QSqlQuery>
32 #include <QSqlError>
33 
34 namespace Isis {
35 
36  class SqlRecord;
37 
152  class SqlQuery : public QSqlQuery {
153  public:
154  SqlQuery();
155  SqlQuery(Database &db);
156  SqlQuery(const std::string &query,
158  SqlQuery(const SqlQuery &other);
159  virtual ~SqlQuery() { }
160 
167  bool isThrowing() const {
168  return (_throwIfFailed);
169  }
170 
175  _throwIfFailed = true;
176  }
181  _throwIfFailed = false;
182  }
183 
184  bool exec(const std::string &query);
185  bool exec() {
186  return(QSqlQuery::exec());
187  }
188  std::string getQuery() const;
189 
190  int nFields() const;
191  std::string fieldName(int index) const;
192  int fieldIndex(const std::string &name) const;
193  std::vector<std::string> fieldNameList() const;
194  std::vector<std::string> fieldTypeList() const;
195 
196  int nRows() const;
197  SqlRecord getRecord() const;
198 
199  private:
201 
202  void tossQueryError(const std::string &message, const char *f, int l) const;
203  };
204 }
205 #endif
std::vector< std::string > fieldTypeList() const
Returns the types of each field/column in a resutling query.
Definition: SqlQuery.cpp:228
SqlQuery()
Default constructor.
Definition: SqlQuery.cpp:43
std::vector< std::string > fieldNameList() const
Returns the names of all fields in the resulting query.
Definition: SqlQuery.cpp:211
Connect to database immediately.
Definition: Database.h:88
SqlRecord getRecord() const
Returns a SqlRecord for the current query row.
Definition: SqlQuery.cpp:267
bool isThrowing() const
Report error status when executing queries.
Definition: SqlQuery.h:167
int fieldIndex(const std::string &name) const
Returns index of column for given name.
Definition: SqlQuery.cpp:194
void tossQueryError(const std::string &message, const char *f, int l) const
Issues an IException from various sources of error states in this class.
Definition: SqlQuery.cpp:291
void setThrowOnFailure()
Sets throwing of exceptions on errors to true.
Definition: SqlQuery.h:174
Construct and execute a query on a database and manage result.
Definition: SqlQuery.h:152
bool _throwIfFailed
User can select action on query results.
Definition: SqlQuery.h:200
Isis database class providing generalized access to a variety of databases.
Definition: Database.h:84
std::string getQuery() const
Returns the executed query string.
Definition: SqlQuery.cpp:146
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
int nFields() const
Returns the number of fields (columns) from query.
Definition: SqlQuery.cpp:163
void setNoThrowOnFailure()
Turns throwing of iExceptions off on errors.
Definition: SqlQuery.h:180
std::string fieldName(int index) const
Returns the column name of the resulting query at the given index.
Definition: SqlQuery.cpp:179
int nRows() const
Returns the count of rows resulting from the query.
Definition: SqlQuery.cpp:250