removed abstractquery
This commit is contained in:
parent
457d9a5d77
commit
22195353c1
|
|
@ -1,43 +0,0 @@
|
||||||
/**************************************************************************
|
|
||||||
**
|
|
||||||
** 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 <http://www.gnu.org/licenses/>.
|
|
||||||
**
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
#include "abstractquery.h"
|
|
||||||
#include "abstractquery_p.h"
|
|
||||||
|
|
||||||
NUT_BEGIN_NAMESPACE
|
|
||||||
|
|
||||||
AbstractQuery::AbstractQuery(QObject *parent) : QObject(parent)
|
|
||||||
, d_ptr(new AbstractQueryPrivate(this))
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Nut::AbstractQueryPrivate::AbstractQueryPrivate(Nut::AbstractQuery *parent) :
|
|
||||||
q_ptr(parent), skip(0), take(0)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Nut::AbstractQueryPrivate::~AbstractQueryPrivate()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
NUT_END_NAMESPACE
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
/**************************************************************************
|
|
||||||
**
|
|
||||||
** 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 <http://www.gnu.org/licenses/>.
|
|
||||||
**
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
#ifndef NUT_ABSTRACTQUERY_H
|
|
||||||
#define NUT_ABSTRACTQUERY_H
|
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
|
||||||
#include <QtCore/qglobal.h>
|
|
||||||
#include <QtCore/QExplicitlySharedDataPointer>
|
|
||||||
|
|
||||||
#include "defines.h"
|
|
||||||
#include "abstractquery_p.h"
|
|
||||||
|
|
||||||
NUT_BEGIN_NAMESPACE
|
|
||||||
|
|
||||||
class AbstractQueryPrivate;
|
|
||||||
class NUT_EXPORT AbstractQuery : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
protected:
|
|
||||||
AbstractQueryPrivate *d_ptr;
|
|
||||||
Q_DECLARE_PRIVATE(AbstractQuery)
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit AbstractQuery(QObject *parent = nullptr);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
// void addTableToSet(TableSetBase *set, Table *table);
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
};
|
|
||||||
|
|
||||||
NUT_END_NAMESPACE
|
|
||||||
|
|
||||||
#endif // NUT_ABSTRACTQUERY_H
|
|
||||||
|
|
@ -1,71 +0,0 @@
|
||||||
/**************************************************************************
|
|
||||||
**
|
|
||||||
** 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 <http://www.gnu.org/licenses/>.
|
|
||||||
**
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
#ifndef NUT_QUERY_P_H
|
|
||||||
#define NUT_QUERY_P_H
|
|
||||||
|
|
||||||
//
|
|
||||||
// W A R N I N G
|
|
||||||
// -------------
|
|
||||||
//
|
|
||||||
// This file is not part of the Qt API. It exists for the convenience
|
|
||||||
// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
|
|
||||||
// file may change from version to version without notice, or even be removed.
|
|
||||||
//
|
|
||||||
// We mean it.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "phrase.h"
|
|
||||||
|
|
||||||
#include <QtCore/QList>
|
|
||||||
#include <QtCore/QString>
|
|
||||||
#include <QtCore/QSharedData>
|
|
||||||
|
|
||||||
NUT_BEGIN_NAMESPACE
|
|
||||||
|
|
||||||
class Database;
|
|
||||||
class AbstractTableSet;
|
|
||||||
class AbstractQuery;
|
|
||||||
struct RelationModel;
|
|
||||||
class NUT_EXPORT AbstractQueryPrivate {
|
|
||||||
AbstractQuery *q_ptr;
|
|
||||||
Q_DECLARE_PUBLIC(AbstractQuery)
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit AbstractQueryPrivate(AbstractQuery *parent);
|
|
||||||
~AbstractQueryPrivate();
|
|
||||||
|
|
||||||
QString sql;
|
|
||||||
QString className;
|
|
||||||
QString tableName;
|
|
||||||
QString select;
|
|
||||||
Database *database;
|
|
||||||
AbstractTableSet *tableSet;
|
|
||||||
QStringList joins;
|
|
||||||
QList<RelationModel*> relations;
|
|
||||||
int skip;
|
|
||||||
int take;
|
|
||||||
PhraseList orderPhrase, fieldPhrase;
|
|
||||||
ConditionalPhrase wherePhrase;
|
|
||||||
};
|
|
||||||
|
|
||||||
NUT_END_NAMESPACE
|
|
||||||
|
|
||||||
#endif // NUT_QUERY_P_H
|
|
||||||
|
|
@ -47,9 +47,7 @@ HEADERS += \
|
||||||
$$PWD/phrases/phrasedatalist.h \
|
$$PWD/phrases/phrasedatalist.h \
|
||||||
$$PWD/phrases/phraselist.h \
|
$$PWD/phrases/phraselist.h \
|
||||||
$$PWD/phrases/datephrase.h \
|
$$PWD/phrases/datephrase.h \
|
||||||
$$PWD/table_p.h \
|
$$PWD/table_p.h
|
||||||
$$PWD/abstractquery.h \
|
|
||||||
$$PWD/abstractquery_p.h
|
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/generators/abstractsqlgenerator.cpp \
|
$$PWD/generators/abstractsqlgenerator.cpp \
|
||||||
|
|
@ -78,8 +76,7 @@ SOURCES += \
|
||||||
$$PWD/phrases/phrasedata.cpp \
|
$$PWD/phrases/phrasedata.cpp \
|
||||||
$$PWD/phrases/phrasedatalist.cpp \
|
$$PWD/phrases/phrasedatalist.cpp \
|
||||||
$$PWD/phrases/phraselist.cpp \
|
$$PWD/phrases/phraselist.cpp \
|
||||||
$$PWD/phrases/datephrase.cpp \
|
$$PWD/phrases/datephrase.cpp
|
||||||
$$PWD/abstractquery.cpp
|
|
||||||
|
|
||||||
load(qt_module)
|
load(qt_module)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,6 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <QtNut/table.h>
|
#include <QtNut/table.h>
|
||||||
#include <QtNut/abstractquery.h>
|
|
||||||
|
|
||||||
#include <QtNut/database.h>
|
#include <QtNut/database.h>
|
||||||
#include <QtNut/databasemodel.h>
|
#include <QtNut/databasemodel.h>
|
||||||
#include <QtNut/abstracttableset.h>
|
#include <QtNut/abstracttableset.h>
|
||||||
|
|
@ -79,16 +77,19 @@ struct NUT_EXPORT QueryData {
|
||||||
r->wherePhrase = wherePhrase;
|
r->wherePhrase = wherePhrase;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QueryData() = default;
|
||||||
|
QueryData(Database *db) : database(db)
|
||||||
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class Query : public AbstractQuery
|
class Query
|
||||||
{
|
{
|
||||||
QueryData *d;
|
QueryData *d;
|
||||||
bool m_autoDelete;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Query(Database *database, AbstractTableSet *tableSet, bool autoDelete);
|
explicit Query(Database *database, AbstractTableSet *tableSet);
|
||||||
Query (const Query<T> &other);
|
Query (const Query<T> &other);
|
||||||
Query (Query<T> &&other);
|
Query (Query<T> &&other);
|
||||||
|
|
||||||
|
|
@ -168,8 +169,6 @@ Q_OUTOFLINE_TEMPLATE QList<O> Query<T>::select(const std::function<O (const QSql
|
||||||
ret.append(obj);
|
ret.append(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_autoDelete)
|
|
||||||
deleteLater();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -180,9 +179,8 @@ Q_OUTOFLINE_TEMPLATE QList<O> Query<T>::select(const std::function<O (const QSql
|
||||||
//}
|
//}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
Q_OUTOFLINE_TEMPLATE Query<T>::Query(Database *database, AbstractTableSet *tableSet,
|
Q_OUTOFLINE_TEMPLATE Query<T>::Query(Database *database, AbstractTableSet *tableSet)
|
||||||
bool autoDelete)
|
: d(new QueryData(database))
|
||||||
: AbstractQuery(database), d(new QueryData), m_autoDelete(autoDelete)
|
|
||||||
{
|
{
|
||||||
//Q_D(AbstractQuery);
|
//Q_D(AbstractQuery);
|
||||||
|
|
||||||
|
|
@ -196,12 +194,12 @@ Q_OUTOFLINE_TEMPLATE Query<T>::Query(Database *database, AbstractTableSet *table
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Q_OUTOFLINE_TEMPLATE Query<T>::Query(const Query<T> &other) : AbstractQuery() {
|
Q_OUTOFLINE_TEMPLATE Query<T>::Query(const Query<T> &other) {
|
||||||
d = other.d->clone();
|
d = other.d->clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Q_OUTOFLINE_TEMPLATE Query<T>::Query(Query<T> &&other) : AbstractQuery() {
|
Q_OUTOFLINE_TEMPLATE Query<T>::Query(Query<T> &&other) {
|
||||||
d = std::move(other.d);
|
d = std::move(other.d);
|
||||||
other.d = nullptr;
|
other.d = nullptr;
|
||||||
}
|
}
|
||||||
|
|
@ -393,10 +391,6 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
|
||||||
} //while
|
} //while
|
||||||
} // while
|
} // while
|
||||||
|
|
||||||
#ifndef NUT_SHARED_POINTER
|
|
||||||
if (m_autoDelete)
|
|
||||||
deleteLater();
|
|
||||||
#endif
|
|
||||||
return returnList;
|
return returnList;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -423,8 +417,6 @@ Q_OUTOFLINE_TEMPLATE QList<F> Query<T>::select(const FieldPhrase<F> f)
|
||||||
ret.append(v.value<F>());
|
ret.append(v.value<F>());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_autoDelete)
|
|
||||||
deleteLater();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -644,8 +636,6 @@ Q_OUTOFLINE_TEMPLATE int Query<T>::update(const AssignmentPhraseList &ph)
|
||||||
|
|
||||||
QSqlQuery q = d->database->exec(d->sql);
|
QSqlQuery q = d->database->exec(d->sql);
|
||||||
|
|
||||||
if (m_autoDelete)
|
|
||||||
deleteLater();
|
|
||||||
return q.numRowsAffected();
|
return q.numRowsAffected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -658,8 +648,6 @@ Q_OUTOFLINE_TEMPLATE int Query<T>::remove()
|
||||||
d->tableName, d->wherePhrase);
|
d->tableName, d->wherePhrase);
|
||||||
QSqlQuery q = d->database->exec(d->sql);
|
QSqlQuery q = d->database->exec(d->sql);
|
||||||
|
|
||||||
if (m_autoDelete)
|
|
||||||
deleteLater();
|
|
||||||
return q.numRowsAffected();
|
return q.numRowsAffected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ public:
|
||||||
Row<T> at(int i) const;
|
Row<T> at(int i) const;
|
||||||
Row<T> operator[](int i) const;
|
Row<T> operator[](int i) const;
|
||||||
|
|
||||||
Query<T> query(bool autoDelete = true);
|
Query<T> query();
|
||||||
BulkInserter *bulkInserter();
|
BulkInserter *bulkInserter();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -80,9 +80,9 @@ Q_OUTOFLINE_TEMPLATE TableSet<T>::TableSet(Table *parent) : AbstractTableSet(par
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Q_OUTOFLINE_TEMPLATE Query<T> TableSet<T>::query(bool autoDelete)
|
Q_OUTOFLINE_TEMPLATE Query<T> TableSet<T>::query()
|
||||||
{
|
{
|
||||||
return Query<T>(data->database, this, autoDelete);
|
return Query<T>(data->database, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue