Isis 3 Programmer Reference
SqlRecord.cpp
Go to the documentation of this file.
1 
22 #include <cctype>
23 #include <string>
24 #include <vector>
25 #include <iostream>
26 
27 #include "IString.h"
28 #include "SqlRecord.h"
29 #include "SqlQuery.h"
30 
31 #include <QSqlField>
32 #include <QVariant>
33 
34 using namespace std;
35 
36 namespace Isis {
37 
43  SqlRecord::SqlRecord() : QSqlRecord() { }
44 
55  SqlRecord::SqlRecord(const SqlQuery &query) : QSqlRecord(query.record()) { }
56 
67  bool SqlRecord::hasField(const QString &name) const {
68  return (contains(name));
69  }
70 
81  QString SqlRecord::getFieldName(int index) const {
82  return (fieldName(index));
83  }
84 
94  int SqlRecord::getFieldIndex(const QString &name) const {
95  return(indexOf(name));
96  }
97 
118  QString SqlRecord::getType(const QString &name) const {
119  QVariant ftype(field(name).type());
120  return (QtTypeField(ftype.typeName()));
121  }
122 
143  QString SqlRecord::getType(int index) const {
144  QVariant ftype(field(index).type());
145  return (QtTypeField(ftype.typeName()));
146  }
147 
155  bool SqlRecord::isNull(const QString &name) const {
156  return (field(name).isNull());
157  }
158 
169  QString SqlRecord::getValue(int index) const {
170  return (QString(field(index).value().toString()));
171  }
172 
183  QString SqlRecord::getValue(const QString &name) const {
184  return (QString(field(name).value().toString()));
185  }
186 
200  QString SqlRecord::QtTypeField(const char *ctype) const {
201  QString retType("");
202  if(ctype == 0) {
203  return (retType);
204  }
205  else {
206  retType = QString((tolower(ctype[0]) == 'q') ? &ctype[1] : ctype).toLower();
207  }
208  return(retType);
209  }
210 
211 }
QString getType(int index) const
Returns the type of a field/column at the specified index.
Definition: SqlRecord.cpp:143
bool isNull(const QString &name) const
Determines if the value of the field/column is NULL.
Definition: SqlRecord.cpp:155
Namespace for the standard library.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
bool hasField(const QString &name) const
Indicates the existance/non-existance of a field in the row.
Definition: SqlRecord.cpp:67
QString getFieldName(int index) const
Returns the name of a field/column at a particular index.
Definition: SqlRecord.cpp:81
SqlRecord()
Default Constructor.
Definition: SqlRecord.cpp:43
Construct and execute a query on a database and manage result.
Definition: SqlQuery.h:152
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
QString QtTypeField(const char *ctype) const
Returns a generic field type given a Qt QVariant type.
Definition: SqlRecord.cpp:200
QString getValue(int index) const
Returns the value of the field/column at specified index.
Definition: SqlRecord.cpp:169
int getFieldIndex(const QString &name) const
Return the index of a named field/column This method will determine the index of the named field afte...
Definition: SqlRecord.cpp:94