diff --git a/src/dbgeography.cpp b/src/dbgeography.cpp
index 3ab1d46..67d28b8 100644
--- a/src/dbgeography.cpp
+++ b/src/dbgeography.cpp
@@ -1,3 +1,23 @@
+/**************************************************************************
+**
+** This file is part of Nut project.
+** https://github.com/HamedMasafi/Nut
+**
+** Nut is free software: you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published by
+** the Free Software Foundation, either version 3 of the License, or
+** (at your option) any later version.
+**
+** Nut is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU Lesser General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public License
+** along with Nut. If not, see .
+**
+**************************************************************************/
+
#include "dbgeography.h"
NUT_BEGIN_NAMESPACE
diff --git a/src/dbgeography.h b/src/dbgeography.h
index 37c48a3..6cc9160 100644
--- a/src/dbgeography.h
+++ b/src/dbgeography.h
@@ -1,3 +1,23 @@
+/**************************************************************************
+**
+** This file is part of Nut project.
+** https://github.com/HamedMasafi/Nut
+**
+** Nut is free software: you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published by
+** the Free Software Foundation, either version 3 of the License, or
+** (at your option) any later version.
+**
+** Nut is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU Lesser General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public License
+** along with Nut. If not, see .
+**
+**************************************************************************/
+
#ifndef DBGEOGRAPHY_H
#define DBGEOGRAPHY_H
diff --git a/src/query.h b/src/query.h
index 38e25a3..cbeb6b9 100644
--- a/src/query.h
+++ b/src/query.h
@@ -51,18 +51,6 @@ public:
~Query();
- T *first();
-
- int count();
-
- QList toList(int count = -1);
-
- template
- QList select(const FieldPhrase f);
- QVariant max(FieldPhrase &f);
- QVariant min(FieldPhrase &f);
- QVariant average(FieldPhrase &f);
-
Query *join(const QString &tableName);
Query *setWhere(WherePhrase where);
@@ -71,12 +59,22 @@ public:
return this;
}
-// Query *setWhere(const QString &where);
Query *orderBy(QString fieldName, QString type);
Query *orderBy(WherePhrase phrase);
+ int count();
+ QVariant max(FieldPhrase &f);
+ QVariant min(FieldPhrase &f);
+ QVariant average(FieldPhrase &f);
+ T *first();
+ QList toList(int count = -1);
+ template
+ QList select(const FieldPhrase f);
+
int update(WherePhrase phrase);
int remove();
+
+ QString sqlCommand() const;
};
template
@@ -93,7 +91,7 @@ Q_OUTOFLINE_TEMPLATE Query::Query(Database *database, TableSetBase *tableSet,
d->database = database;
d->tableSet = tableSet;
d->tableName = //TableModel::findByClassName(T::staticMetaObject.className())->name();
- d->database->model().modelByClass(T::staticMetaObject.className())->name();
+ d->database->model().modelByClass(T::staticMetaObject.className())->name();
}
template
@@ -112,15 +110,16 @@ Q_OUTOFLINE_TEMPLATE QList Query::toList(int count)
d->select = "*";
// QSqlQuery q = d->database->exec(d->database->sqlGenertor()->selectCommand(d->wheres, d->orders, d->tableName, d->joinClassName));
- QString sql = d->database->sqlGenertor()->selectCommand(
- SqlGeneratorBase::SelectAll,
- "",
- d->wheres,
- d->orderPhrases,
- d->tableName,
- d->joinClassName);
+ d->sql = d->database->sqlGenertor()->selectCommand(
+ SqlGeneratorBase::SelectAll,
+ "",
+ d->wheres,
+ d->orderPhrases,
+ d->tableName,
+ d->joinClassName);
- QSqlQuery q = d->database->exec(sql);
+// qDebug() << sql;
+ QSqlQuery q = d->database->exec(d->sql);
// QString pk = TableModel::findByName(d->tableName)->primaryKey();
QString pk = d->database->model().model(d->tableName)->primaryKey();
@@ -202,14 +201,14 @@ Q_OUTOFLINE_TEMPLATE QList Query::select(const FieldPhrase f)
{
Q_D(Query);
QList ret;
- QString sql = d->database->sqlGenertor()->selectCommand(
+ d->sql = d->database->sqlGenertor()->selectCommand(
SqlGeneratorBase::SignleField,
f.data()->text,
d->wheres,
d->orderPhrases,
d->tableName,
d->joinClassName);
- QSqlQuery q = d->database->exec(sql);
+ QSqlQuery q = d->database->exec(d->sql);
while (q.next()) {
QVariant v = q.value(f.data()->text);
@@ -238,7 +237,8 @@ Q_OUTOFLINE_TEMPLATE int Query::count()
Q_D(Query);
d->select = "COUNT(*)";
- QSqlQuery q = d->database->exec(d->database->sqlGenertor()->selectCommand("COUNT(*)", d->wheres, d->orders, d->tableName, d->joinClassName));
+ d->sql = d->database->sqlGenertor()->selectCommand("COUNT(*)", d->wheres, d->orders, d->tableName, d->joinClassName);
+ QSqlQuery q = d->database->exec(d->sql);
if(q.next())
return q.value(0).toInt();
@@ -249,7 +249,8 @@ template
Q_OUTOFLINE_TEMPLATE QVariant Query::max(FieldPhrase &f){
Q_D(Query);
- QSqlQuery q = d->database->exec(d->database->sqlGenertor()->selectCommand("MAX(" + f.data()->text + ")", d->wheres, d->orders, d->tableName, d->joinClassName));
+ d->sql = d->database->sqlGenertor()->selectCommand("MAX(" + f.data()->text + ")", d->wheres, d->orders, d->tableName, d->joinClassName);
+ QSqlQuery q = d->database->exec(d->sql);
if(q.next())
return q.value(0).toInt();
@@ -260,7 +261,8 @@ template
Q_OUTOFLINE_TEMPLATE QVariant Query::min(FieldPhrase &f){
Q_D(Query);
- QSqlQuery q = d->database->exec(d->database->sqlGenertor()->selectCommand("MIN(" + f.data()->text + ")", d->wheres, d->orders, d->tableName, d->joinClassName));
+ d->sql = d->database->sqlGenertor()->selectCommand("MIN(" + f.data()->text + ")", d->wheres, d->orders, d->tableName, d->joinClassName);
+ QSqlQuery q = d->database->exec(d->sql);
if(q.next())
return q.value(0).toInt();
@@ -272,7 +274,8 @@ Q_OUTOFLINE_TEMPLATE QVariant Query::average(FieldPhrase &f)
{
Q_D(Query);
- QSqlQuery q = d->database->exec(d->database->sqlGenertor()->selectCommand("AVG(" + f.data()->text + ")", d->wheres, d->orders, d->tableName, d->joinClassName));
+ d->sql = d->database->sqlGenertor()->selectCommand("AVG(" + f.data()->text + ")", d->wheres, d->orders, d->tableName, d->joinClassName);
+ QSqlQuery q = d->database->exec(d->sql);
if(q.next())
return q.value(0).toInt();
@@ -316,12 +319,12 @@ Q_OUTOFLINE_TEMPLATE int Query::update(WherePhrase phrase)
{
Q_D(Query);
- QString sql = d->database->sqlGenertor()->updateCommand(
+ d->sql = d->database->sqlGenertor()->updateCommand(
phrase,
d->wheres,
d->tableName);
- QSqlQuery q = d->database->exec(sql);
-qDebug()<database->exec(d->sql);
+
if (m_autoDelete)
deleteLater();
return q.numRowsAffected();
@@ -332,13 +335,23 @@ Q_OUTOFLINE_TEMPLATE int Query::remove()
{
Q_D(Query);
- QString sql = d->database->sqlGenertor()->deleteCommand(
+ d->sql = d->database->sqlGenertor()->deleteCommand(
d->wheres,
d->tableName);
- QSqlQuery q = d->database->exec(sql);
+ QSqlQuery q = d->database->exec(d->sql);
+
+ if (m_autoDelete)
+ deleteLater();
return q.numRowsAffected();
}
+template
+Q_OUTOFLINE_TEMPLATE QString Query::sqlCommand() const
+{
+ Q_D(const Query);
+ return d->sql;
+}
+
NUT_END_NAMESPACE
#endif // QUERY_H
diff --git a/src/query_p.h b/src/query_p.h
index a6cddb5..f074592 100644
--- a/src/query_p.h
+++ b/src/query_p.h
@@ -40,6 +40,7 @@ public:
QueryPrivate(QueryBase *parent);
~QueryPrivate();
+ QString sql;
QString tableName;
QString select;
Database *database;
diff --git a/src/querybase_p.h b/src/querybase_p.h
index 762a928..087c714 100644
--- a/src/querybase_p.h
+++ b/src/querybase_p.h
@@ -1,3 +1,23 @@
+/**************************************************************************
+**
+** This file is part of Nut project.
+** https://github.com/HamedMasafi/Nut
+**
+** Nut is free software: you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published by
+** the Free Software Foundation, either version 3 of the License, or
+** (at your option) any later version.
+**
+** Nut is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU Lesser General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public License
+** along with Nut. If not, see .
+**
+**************************************************************************/
+
#ifndef QUERYBASE_H
#define QUERYBASE_H
diff --git a/src/tableset.cpp b/src/tableset.cpp
index b80f27a..3bcce89 100644
--- a/src/tableset.cpp
+++ b/src/tableset.cpp
@@ -1,21 +1,21 @@
-///**************************************************************************
-//**
-//** This file is part of Nut project.
-//** https://github.com/HamedMasafi/Nut
-//**
-//** Nut is free software: you can redistribute it and/or modify
-//** it under the terms of the GNU Lesser General Public License as published by
-//** the Free Software Foundation, either version 3 of the License, or
-//** (at your option) any later version.
-//**
-//** Nut is distributed in the hope that it will be useful,
-//** but WITHOUT ANY WARRANTY; without even the implied warranty of
-//** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-//** GNU Lesser General Public License for more details.
-//**
-//** You should have received a copy of the GNU Lesser General Public License
-//** along with Nut. If not, see .
-//**
-//**************************************************************************/
+/**************************************************************************
+**
+** This file is part of Nut project.
+** https://github.com/HamedMasafi/Nut
+**
+** Nut is free software: you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published by
+** the Free Software Foundation, either version 3 of the License, or
+** (at your option) any later version.
+**
+** Nut is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU Lesser General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public License
+** along with Nut. If not, see .
+**
+**************************************************************************/
#include "tableset.h"
diff --git a/src/wherephrase.h b/src/wherephrase.h
index 19fa9b9..5b9a8fb 100644
--- a/src/wherephrase.h
+++ b/src/wherephrase.h
@@ -392,7 +392,7 @@ public:
}
};
-#define SPECIALIZATION_NUMERIC(type) \
+#define SPECIALIZATION_NUMERIC(type) \
template<> \
class FieldPhrase: public NumericFieldPhrase{ \
public: \
@@ -402,18 +402,25 @@ public:
{ \
return WherePhrase(this, PhraseData::Set, (WherePhrase *)&other); \
} \
- WherePhrase in(QList list) \
+ WherePhrase in(QList list) \
{ \
QVariantList vlist; \
- foreach (type t, list) \
+ foreach (type t, list) \
vlist.append(QVariant::fromValue(t)); \
return WherePhrase(this, PhraseData::In, vlist); \
} \
};
+SPECIALIZATION_NUMERIC(qint8)
SPECIALIZATION_NUMERIC(qint16)
SPECIALIZATION_NUMERIC(qint32)
SPECIALIZATION_NUMERIC(qint64)
+
+SPECIALIZATION_NUMERIC(quint8)
+SPECIALIZATION_NUMERIC(quint16)
+SPECIALIZATION_NUMERIC(quint32)
+SPECIALIZATION_NUMERIC(quint64)
+
SPECIALIZATION_NUMERIC(qreal)