summaryrefslogtreecommitdiffstats
path: root/src/sql/kernel
diff options
context:
space:
mode:
authorThiago A. Correa <thiago.correa@gmail.com>2012-10-03 22:52:59 -0300
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-08 08:55:28 +0200
commit7e6e1412348fb8d8df844d821ee80d6d3de69517 (patch)
tree4c90539cd4de03da3f7fc9283ae1a852bcc2c7c9 /src/sql/kernel
parent179437bdbad3fa2f27ea7fc3a4284a844cb30792 (diff)
QSqlQuery::value string overload
Introduce value overload to take field name as a parameter. This allows for terser application code that avoids explicit calls to QSqlRecord::value(). Change-Id: I02b6712cd5ec41633b902714315b5716c17d1a9b Reviewed-by: Mark Brand <mabrand@mabrand.nl>
Diffstat (limited to 'src/sql/kernel')
-rw-r--r--src/sql/kernel/qsqlquery.cpp18
-rw-r--r--src/sql/kernel/qsqlquery.h1
2 files changed, 19 insertions, 0 deletions
diff --git a/src/sql/kernel/qsqlquery.cpp b/src/sql/kernel/qsqlquery.cpp
index eff211cc37..07b23f7f03 100644
--- a/src/sql/kernel/qsqlquery.cpp
+++ b/src/sql/kernel/qsqlquery.cpp
@@ -406,6 +406,24 @@ QVariant QSqlQuery::value(int index) const
}
/*!
+ \overload
+
+ Returns the value of the field called \a name in the current record.
+ If field \a name does not exist an invalid variant is returned.
+
+ This overload is less efficient than \l{QSqlQuery::}{value()}
+*/
+
+QVariant QSqlQuery::value(const QString& name) const
+{
+ int index = d->sqlResult->record().indexOf(name);
+ if (index > -1)
+ return value(index);
+ qWarning("QSqlQuery::value: unknown field name '%s'", qPrintable(name));
+ return QVariant();
+}
+
+/*!
Returns the current internal position of the query. The first
record is at position zero. If the position is invalid, the
function returns QSql::BeforeFirstRow or
diff --git a/src/sql/kernel/qsqlquery.h b/src/sql/kernel/qsqlquery.h
index 9b4f35c775..9d660e08c1 100644
--- a/src/sql/kernel/qsqlquery.h
+++ b/src/sql/kernel/qsqlquery.h
@@ -86,6 +86,7 @@ public:
void setForwardOnly(bool forward);
bool exec(const QString& query);
QVariant value(int i) const;
+ QVariant value(const QString& name) const;
void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy);
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const;