[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [Aki] c1d1cdc: Needed to export Query class Added some DEBUG info
From: Keith Rusler <xzekecomax () gmail ! com>
Date: 2011-01-10 13:06:24
Message-ID: 20110110130624.7FEF8A6090 () git ! kde ! org
[Download RAW message or body]
commit c1d1cdce3e2aed9148b942f85a288b5b8d72cddb
branch master
Author: Keith Rusler <xzekecomax@gmail.com>
Date: Mon Jan 10 07:04:07 2011 -0600
Needed to export Query class
Added some DEBUG info for right now.
Added code to get the results from the query.
diff --git a/libaki/sql/query.hpp b/libaki/sql/query.hpp
index 986347e..6fb8a52 100644
--- a/libaki/sql/query.hpp
+++ b/libaki/sql/query.hpp
@@ -21,18 +21,21 @@
#ifndef AKI_SQL_QUERY_HPP
#define AKI_SQL_QUERY_HPP
+#include "aki.hpp"
+#include "debughelper.hpp"
#include "sql/database.hpp"
#include <QtCore/QMetaClassInfo>
#include <QtCore/QObject>
#include <QtCore/QSharedPointer>
#include <QtSql/QSqlQuery>
+#include <QtSql/QSqlRecord>
namespace Aki
{
namespace Sql
{
template<typename T>
-class Query
+class LIBAKI_EXPORT Query
{
public:
Query();
@@ -160,17 +163,29 @@ Query<T>::orderBy(const QString& field)
template<typename T> QList<QSharedPointer<T> >
Query<T>::result()
{
+ DEBUG_FUNC_NAME;
QList<QSharedPointer<T> > results;
+ DEBUG_TEXT2("Preparing Sql Statement:\n%1", _sql);
_query.prepare(_sql);
QMapIterator<QString, QVariant> i(_placeHolders);
while (i.hasNext()) {
i.next();
+ DEBUG_TEXT2("Binding: %1", i.key());
_query.bindValue(i.key(), i.value());
}
if (_query.exec()) {
-
+ if (_query.next()) {
+ T* res = qobject_cast<T*>(_object.newInstance());
+ for (int i = 0, c = _object.classInfoCount(); i < c; ++i) {
+ const QMetaClassInfo classInfo = _object.classInfo(i);
+ const int indexRecord = _query.record().indexOf(classInfo.name());
+ res->setProperty(classInfo.name(), _query.value(indexRecord));
+ }
+
+ results.append(QSharedPointer<T>(res));
+ }
}
return results;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic