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
21using namespace std;
22
23namespace Isis {
24
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}
Construct and execute a query on a database and manage result.
Definition SqlQuery.h:138
SqlRecord()
Default Constructor.
Definition SqlRecord.cpp:30
bool isNull(const QString &name) const
Determines if the value of the field/column is NULL.
bool hasField(const QString &name) const
Indicates the existance/non-existance of a field in the row.
Definition SqlRecord.cpp:54
QString getType(int index) const
Returns the type of a field/column at the specified index.
QString getFieldName(int index) const
Returns the name of a field/column at a particular index.
Definition SqlRecord.cpp:68
QString getValue(int index) const
Returns the value of the field/column at specified index.
QString QtTypeField(const char *ctype) const
Returns a generic field type given a Qt QVariant type.
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
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211
Namespace for the standard library.