Isis 3 Programmer Reference
SqlRecord.cpp
1 
7 /* SPDX-License-Identifier: CC0-1.0 */
8 
9 #include <cctype>
10 #include <string>
11 #include <vector>
12 #include <iostream>
13 
14 #include "IString.h"
15 #include "SqlRecord.h"
16 #include "SqlQuery.h"
17 
18 #include <QSqlField>
19 #include <QVariant>
20 
21 using namespace std;
22 
23 namespace Isis {
24 
30  SqlRecord::SqlRecord() : QSqlRecord() { }
31 
42  SqlRecord::SqlRecord(const SqlQuery &query) : QSqlRecord(query.record()) { }
43 
54  bool SqlRecord::hasField(const QString &name) const {
55  return (contains(name));
56  }
57 
68  QString SqlRecord::getFieldName(int index) const {
69  return (fieldName(index));
70  }
71 
81  int SqlRecord::getFieldIndex(const QString &name) const {
82  return(indexOf(name));
83  }
84 
105  QString SqlRecord::getType(const QString &name) const {
106  QVariant ftype(field(name).type());
107  return (QtTypeField(ftype.typeName()));
108  }
109 
130  QString SqlRecord::getType(int index) const {
131  QVariant ftype(field(index).type());
132  return (QtTypeField(ftype.typeName()));
133  }
134 
142  bool SqlRecord::isNull(const QString &name) const {
143  return (field(name).isNull());
144  }
145 
156  QString SqlRecord::getValue(int index) const {
157  return (QString(field(index).value().toString()));
158  }
159 
170  QString SqlRecord::getValue(const QString &name) const {
171  return (QString(field(name).value().toString()));
172  }
173 
187  QString SqlRecord::QtTypeField(const char *ctype) const {
188  QString retType("");
189  if(ctype == 0) {
190  return (retType);
191  }
192  else {
193  retType = QString((tolower(ctype[0]) == 'q') ? &ctype[1] : ctype).toLower();
194  }
195  return(retType);
196  }
197 
198 }
Isis::SqlRecord::SqlRecord
SqlRecord()
Default Constructor.
Definition: SqlRecord.cpp:30
Isis::SqlRecord::hasField
bool hasField(const QString &name) const
Indicates the existance/non-existance of a field in the row.
Definition: SqlRecord.cpp:54
Isis::SqlRecord::QtTypeField
QString QtTypeField(const char *ctype) const
Returns a generic field type given a Qt QVariant type.
Definition: SqlRecord.cpp:187
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
Isis::SqlRecord::getType
QString getType(int index) const
Returns the type of a field/column at the specified index.
Definition: SqlRecord.cpp:130
Isis::SqlRecord::getFieldIndex
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:81
Isis::SqlRecord::getValue
QString getValue(int index) const
Returns the value of the field/column at specified index.
Definition: SqlRecord.cpp:156
Isis::SqlRecord::isNull
bool isNull(const QString &name) const
Determines if the value of the field/column is NULL.
Definition: SqlRecord.cpp:142
std
Namespace for the standard library.
QSqlRecord
Isis::SqlRecord::getFieldName
QString getFieldName(int index) const
Returns the name of a field/column at a particular index.
Definition: SqlRecord.cpp:68
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