Isis Developer Reference
SqlQuery.h
Go to the documentation of this file.
1 #ifndef SqlQuery_h
2 #define SqlQuery_h
3 
10 /* SPDX-License-Identifier: CC0-1.0 */
11 
12 #include <string>
13 #include <vector>
14 #include <iostream>
15 #include "IException.h"
16 #include "Database.h"
17 #include <QSqlQuery>
18 #include <QSqlError>
19 
20 namespace Isis {
21 
22  class SqlRecord;
23 
138  class SqlQuery : public QSqlQuery {
139  public:
140  SqlQuery();
141  SqlQuery(Database &db);
142  SqlQuery(const std::string &query,
144  SqlQuery(const SqlQuery &other);
145  virtual ~SqlQuery() { }
146 
153  bool isThrowing() const {
154  return (_throwIfFailed);
155  }
156 
161  _throwIfFailed = true;
162  }
167  _throwIfFailed = false;
168  }
169 
170  bool exec(const std::string &query);
171  bool exec() {
172  return(QSqlQuery::exec());
173  }
174  std::string getQuery() const;
175 
176  int nFields() const;
177  std::string fieldName(int index) const;
178  int fieldIndex(const std::string &name) const;
179  std::vector<std::string> fieldNameList() const;
180  std::vector<std::string> fieldTypeList() const;
181 
182  int nRows() const;
183  SqlRecord getRecord() const;
184 
185  private:
186  bool _throwIfFailed;
187 
188  void tossQueryError(const std::string &message, const char *f, int l) const;
189  };
190 }
191 #endif
Isis::SqlQuery::setNoThrowOnFailure
void setNoThrowOnFailure()
Turns throwing of iExceptions off on errors.
Definition: SqlQuery.h:166
Isis::SqlQuery::exec
bool exec()
Definition: SqlQuery.h:171
Isis::SqlQuery::fieldName
std::string fieldName(int index) const
Returns the column name of the resulting query at the given index.
Definition: SqlQuery.cpp:166
Isis::IString::ToStd
static std::string ToStd(const QString &str)
Converts a Qt string into a std::string.
Definition: IString.cpp:1333
Isis::Database::Connect
@ Connect
Connect to database immediately.
Definition: Database.h:74
Database.h
Isis::SqlQuery::fieldIndex
int fieldIndex(const std::string &name) const
Returns index of column for given name.
Definition: SqlQuery.cpp:181
IString.h
Isis::SqlQuery::fieldNameList
std::vector< std::string > fieldNameList() const
Returns the names of all fields in the resulting query.
Definition: SqlQuery.cpp:198
Isis::SqlRecord::getType
QString getType(int index) const
Returns the type of a field/column at the specified index.
Definition: SqlRecord.cpp:130
Isis::SqlQuery::fieldTypeList
std::vector< std::string > fieldTypeList() const
Returns the types of each field/column in a resutling query.
Definition: SqlQuery.cpp:215
_FILEINFO_
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:24
Isis::SqlQuery::getQuery
std::string getQuery() const
Returns the executed query string.
Definition: SqlQuery.cpp:133
Isis::SqlQuery::setThrowOnFailure
void setThrowOnFailure()
Sets throwing of exceptions on errors to true.
Definition: SqlQuery.h:160
SqlRecord.h
Isis::SqlQuery::nFields
int nFields() const
Returns the number of fields (columns) from query.
Definition: SqlQuery.cpp:150
Isis::IException
Isis exception class.
Definition: IException.h:91
IException.h
std
Namespace for the standard library.
Isis::Database
Isis database class providing generalized access to a variety of databases.
Definition: Database.h:70
QSqlQuery
QSqlRecord
DbProfile.h
Isis::SqlQuery::~SqlQuery
virtual ~SqlQuery()
Definition: SqlQuery.h:145
Isis::SqlQuery::getRecord
SqlRecord getRecord() const
Returns a SqlRecord for the current query row.
Definition: SqlQuery.cpp:254
Isis::SqlQuery::nRows
int nRows() const
Returns the count of rows resulting from the query.
Definition: SqlQuery.cpp:237
Isis::SqlQuery::SqlQuery
SqlQuery()
Default constructor.
Definition: SqlQuery.cpp:30
SqlQuery.h
Isis::SqlQuery
Construct and execute a query on a database and manage result.
Definition: SqlQuery.h:138
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::IString::ToQt
QString ToQt() const
Retuns the object string as a QString.
Definition: IString.cpp:869
Isis::IException::User
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition: IException.h:126
Isis::SqlQuery::isThrowing
bool isThrowing() const
Report error status when executing queries.
Definition: SqlQuery.h:153
Isis::SqlRecord
Provide simplified access to resulting SQL query row.
Definition: SqlRecord.h:48