polish alpha [skip ci]
This commit is contained in:
parent
370d5234e0
commit
d2822e3ef3
|
|
@ -23,7 +23,7 @@ void Nut::BulkInserter::setFields(const Nut::PhraseList &ph)
|
||||||
void Nut::BulkInserter::insert(std::initializer_list<QVariant> vars)
|
void Nut::BulkInserter::insert(std::initializer_list<QVariant> vars)
|
||||||
{
|
{
|
||||||
if (vars.size() != _fieldCount) {
|
if (vars.size() != _fieldCount) {
|
||||||
qInfo("Number of rows mstake");
|
qInfo("Number of rows mistake");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,9 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
|
|
||||||
#define __CHANGE_LOG_TABLE_NAME "__change_logs"
|
#ifndef __CHANGE_LOG_TABLE_NAME
|
||||||
|
# define __CHANGE_LOG_TABLE_NAME "__change_logs"
|
||||||
|
#endif
|
||||||
|
|
||||||
NUT_BEGIN_NAMESPACE
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
|
@ -196,6 +198,7 @@ bool DatabasePrivate::getCurrectScheema()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QMap<QString, QString> tables;
|
||||||
tables.clear();
|
tables.clear();
|
||||||
|
|
||||||
// TODO: change logs must not be in model
|
// TODO: change logs must not be in model
|
||||||
|
|
@ -240,21 +243,6 @@ bool DatabasePrivate::getCurrectScheema()
|
||||||
if (!ok)
|
if (!ok)
|
||||||
qFatal("NUT_DB_VERSION macro accept version in format 'x'");
|
qFatal("NUT_DB_VERSION macro accept version in format 'x'");
|
||||||
currentModel.setVersion(version);
|
currentModel.setVersion(version);
|
||||||
|
|
||||||
/* TODO: remove
|
|
||||||
QStringList version
|
|
||||||
= QString(ci.value()).replace("\"", "").split('.');
|
|
||||||
bool ok = false;
|
|
||||||
if (version.length() == 1) {
|
|
||||||
currentModel.setVersion(version.at(0).toInt(&ok));
|
|
||||||
} else if (version.length() == 2) {
|
|
||||||
currentModel.setVersionMajor(version.at(0).toInt(&ok));
|
|
||||||
currentModel.setVersionMinor(version.at(1).toInt(&ok));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ok)
|
|
||||||
qFatal("NUT_DB_VERSION macro accept version in format 'x' or "
|
|
||||||
"'x[.y]' only, and x,y must be integer values\n");*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -288,22 +276,6 @@ bool DatabasePrivate::getCurrectScheema()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//bool DatabasePrivate::checkClassInfo(const QMetaClassInfo &classInfo, QString &type, QString &name, QString &value)
|
|
||||||
//{
|
|
||||||
// if (!QString(classInfo.name()).startsWith(__nut_NAME_PERFIX)) {
|
|
||||||
// return false;
|
|
||||||
// } else {
|
|
||||||
// QStringList parts = QString(classInfo.value()).split("\n");
|
|
||||||
// if (parts.count() != 3)
|
|
||||||
// return false;
|
|
||||||
|
|
||||||
// type = parts[0];
|
|
||||||
// name = parts[1];
|
|
||||||
// value = parts[2];
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
DatabaseModel DatabasePrivate::getLastScheema()
|
DatabaseModel DatabasePrivate::getLastScheema()
|
||||||
{
|
{
|
||||||
ChangeLogTable *u = changeLogs->query()
|
ChangeLogTable *u = changeLogs->query()
|
||||||
|
|
@ -386,6 +358,7 @@ void DatabasePrivate::createChangeLogs()
|
||||||
Database::Database(QObject *parent)
|
Database::Database(QObject *parent)
|
||||||
: QObject(parent), d_ptr(new DatabasePrivate(this))
|
: QObject(parent), d_ptr(new DatabasePrivate(this))
|
||||||
{
|
{
|
||||||
|
// _d = new QSharedDataPointer<DatabasePrivate>(new DatabasePrivate(this));
|
||||||
DatabasePrivate::lastId++;
|
DatabasePrivate::lastId++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -393,6 +366,7 @@ Database::Database(const Database &other)
|
||||||
: QObject(other.parent()), d_ptr(new DatabasePrivate(this))
|
: QObject(other.parent()), d_ptr(new DatabasePrivate(this))
|
||||||
{
|
{
|
||||||
DatabasePrivate::lastId++;
|
DatabasePrivate::lastId++;
|
||||||
|
// _d = other._d;
|
||||||
|
|
||||||
setDriver(other.driver());
|
setDriver(other.driver());
|
||||||
setHostName(other.hostName());
|
setHostName(other.hostName());
|
||||||
|
|
@ -592,7 +566,6 @@ bool Database::open(bool updateDatabase)
|
||||||
if (!d->sqlGenertor) {
|
if (!d->sqlGenertor) {
|
||||||
qFatal("Sql generator for driver %s not found",
|
qFatal("Sql generator for driver %s not found",
|
||||||
driver().toLatin1().constData());
|
driver().toLatin1().constData());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return d->open(updateDatabase);
|
return d->open(updateDatabase);
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
#include <QtCore/qglobal.h>
|
#include <QtCore/qglobal.h>
|
||||||
#include <QtCore/QList>
|
#include <QtCore/QList>
|
||||||
#include <QtSql/QSqlDatabase>
|
#include <QtSql/QSqlDatabase>
|
||||||
|
#include <QSharedDataPointer>
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "tableset.h"
|
#include "tableset.h"
|
||||||
|
|
@ -39,6 +40,7 @@ class NUT_EXPORT Database : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
// QSharedDataPointer<DatabasePrivate> *_d;
|
||||||
DatabasePrivate *d_ptr;
|
DatabasePrivate *d_ptr;
|
||||||
Q_DECLARE_PRIVATE(Database)
|
Q_DECLARE_PRIVATE(Database)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,12 @@
|
||||||
#include "databasemodel.h"
|
#include "databasemodel.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QSharedData>
|
||||||
|
|
||||||
NUT_BEGIN_NAMESPACE
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
class ChangeLogTable;
|
class ChangeLogTable;
|
||||||
class DatabasePrivate
|
class DatabasePrivate //: public QSharedData
|
||||||
{
|
{
|
||||||
Database *q_ptr;
|
Database *q_ptr;
|
||||||
Q_DECLARE_PUBLIC(Database)
|
Q_DECLARE_PUBLIC(Database)
|
||||||
|
|
@ -45,8 +46,6 @@ public:
|
||||||
DatabaseModel getLastScheema();
|
DatabaseModel getLastScheema();
|
||||||
bool getCurrectScheema();
|
bool getCurrectScheema();
|
||||||
|
|
||||||
// bool checkClassInfo(const QMetaClassInfo &classInfo,
|
|
||||||
// QString &type, QString &name, QString &value);
|
|
||||||
QSqlDatabase db;
|
QSqlDatabase db;
|
||||||
|
|
||||||
QString hostName;
|
QString hostName;
|
||||||
|
|
@ -62,8 +61,6 @@ public:
|
||||||
|
|
||||||
TableSet<ChangeLogTable> *changeLogs;
|
TableSet<ChangeLogTable> *changeLogs;
|
||||||
|
|
||||||
QT_DEPRECATED
|
|
||||||
QMap<QString, QString> tables;
|
|
||||||
static QMap<QString, DatabaseModel> allTableMaps;
|
static QMap<QString, DatabaseModel> allTableMaps;
|
||||||
static qulonglong lastId;
|
static qulonglong lastId;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -163,13 +163,15 @@ QString SqlServerGenerator::diff(FieldModel *oldField, FieldModel *newField)
|
||||||
|
|
||||||
QString SqlServerGenerator::escapeValue(const QVariant &v) const
|
QString SqlServerGenerator::escapeValue(const QVariant &v) const
|
||||||
{
|
{
|
||||||
if (v.type() == QMetaType::QString || v.type() == QMetaType::QChar)
|
auto mid = static_cast<QMetaType::Type>(v.userType());
|
||||||
|
|
||||||
|
if (mid == QMetaType::QString || mid == QMetaType::QChar)
|
||||||
return "N'" + v.toString() + "'";
|
return "N'" + v.toString() + "'";
|
||||||
else if (v.type() == QMetaType::QPoint) {
|
else if (mid == QMetaType::QPoint) {
|
||||||
QPoint pt = v.toPoint();
|
QPoint pt = v.toPoint();
|
||||||
return QString("geography::POINT(%1, %2, 4326)").arg(pt.x()).arg(
|
return QString("geography::POINT(%1, %2, 4326)").arg(pt.x()).arg(
|
||||||
pt.y());
|
pt.y());
|
||||||
} else if (v.type() == QMetaType::QPointF) {
|
} else if (mid == QMetaType::QPointF) {
|
||||||
QPointF pt = v.toPointF();
|
QPointF pt = v.toPointF();
|
||||||
return QString("geography::POINT(%1, %2, 4326)").arg(pt.x()).arg(
|
return QString("geography::POINT(%1, %2, 4326)").arg(pt.x()).arg(
|
||||||
pt.y());
|
pt.y());
|
||||||
|
|
|
||||||
12
src/query.h
12
src/query.h
|
|
@ -29,7 +29,9 @@
|
||||||
#include <QtSql/QSqlResult>
|
#include <QtSql/QSqlResult>
|
||||||
#include <QtSql/QSqlError>
|
#include <QtSql/QSqlError>
|
||||||
#include <QtSql/QSqlQueryModel>
|
#include <QtSql/QSqlQueryModel>
|
||||||
|
#include <QSqlQuery>
|
||||||
|
|
||||||
|
#include "table.h"
|
||||||
#include "query_p.h"
|
#include "query_p.h"
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
#include "databasemodel.h"
|
#include "databasemodel.h"
|
||||||
|
|
@ -97,11 +99,11 @@ public:
|
||||||
QString sqlCommand() const;
|
QString sqlCommand() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
//template <typename T>
|
||||||
inline Query<T> *createQuery(TableSet<T> *tableSet)
|
//inline Query<T> *createQuery(TableSet<T> *tableSet)
|
||||||
{
|
//{
|
||||||
return tableSet->query();
|
// return tableSet->query();
|
||||||
}
|
//}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
Q_OUTOFLINE_TEMPLATE Query<T>::Query(Database *database, TableSetBase *tableSet,
|
Q_OUTOFLINE_TEMPLATE Query<T>::Query(Database *database, TableSetBase *tableSet,
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,8 @@
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
#include "tablesetbase_p.h"
|
#include "tablesetbase_p.h"
|
||||||
#include "databasemodel.h"
|
#include "databasemodel.h"
|
||||||
|
#include "tablemodel.h"
|
||||||
|
#include "table.h"
|
||||||
#include "sqlmodel_p.h"
|
#include "sqlmodel_p.h"
|
||||||
#include "sqlmodel.h"
|
#include "sqlmodel.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,14 @@
|
||||||
|
|
||||||
#include <QMetaMethod>
|
#include <QMetaMethod>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
#include <QSqlQuery>
|
||||||
|
|
||||||
#include "table.h"
|
#include "table.h"
|
||||||
#include "table_p.h"
|
#include "table_p.h"
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
#include "databasemodel.h"
|
#include "databasemodel.h"
|
||||||
#include "generators/sqlgeneratorbase_p.h"
|
#include "generators/sqlgeneratorbase_p.h"
|
||||||
|
#include "tablesetbase_p.h"
|
||||||
|
|
||||||
NUT_BEGIN_NAMESPACE
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
|
@ -42,11 +45,7 @@ NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
Table::Table(QObject *parent) : QObject(parent),
|
Table::Table(QObject *parent) : QObject(parent),
|
||||||
d_ptr(new TablePrivate(this))
|
d_ptr(new TablePrivate(this))
|
||||||
{
|
{ }
|
||||||
Q_D(Table);
|
|
||||||
d->status = NewCreated;
|
|
||||||
// d->model = TableModel::findByClassName(metaObject()->className());
|
|
||||||
}
|
|
||||||
|
|
||||||
Table::~Table()
|
Table::~Table()
|
||||||
{
|
{
|
||||||
|
|
@ -62,26 +61,26 @@ void Table::add(TableSetBase *t)
|
||||||
d->childTableSets.insert(t);
|
d->childTableSets.insert(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Table::primaryKey() const
|
//QString Table::primaryKey() const
|
||||||
{
|
//{
|
||||||
Q_D(const Table);
|
// Q_D(const Table);
|
||||||
return d->model->primaryKey();
|
// return d->model->primaryKey();
|
||||||
}
|
//}
|
||||||
|
|
||||||
bool Table::isPrimaryKeyAutoIncrement() const
|
//bool Table::isPrimaryKeyAutoIncrement() const
|
||||||
{
|
//{
|
||||||
Q_D(const Table);
|
// Q_D(const Table);
|
||||||
FieldModel *pk = d->model->field(d->model->primaryKey());
|
// FieldModel *pk = d->model->field(d->model->primaryKey());
|
||||||
if (!pk)
|
// if (!pk)
|
||||||
return false;
|
// return false;
|
||||||
return pk->isAutoIncrement;
|
// return pk->isAutoIncrement;
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
QVariant Table::primaryValue() const
|
//QVariant Table::primaryValue() const
|
||||||
{
|
//{
|
||||||
return property(primaryKey().toLatin1().data());
|
// return property(primaryKey().toLatin1().data());
|
||||||
}
|
//}
|
||||||
|
|
||||||
void Table::propertyChanged(const QString &propName)
|
void Table::propertyChanged(const QString &propName)
|
||||||
{
|
{
|
||||||
|
|
@ -104,6 +103,12 @@ void Table::propertyChanged(const QString &propName)
|
||||||
d->status = Added;
|
d->status = Added;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Table::setModel(TableModel *model)
|
||||||
|
{
|
||||||
|
Q_D(Table);
|
||||||
|
d->model = model;
|
||||||
|
}
|
||||||
|
|
||||||
void Table::clear()
|
void Table::clear()
|
||||||
{
|
{
|
||||||
Q_D(Table);
|
Q_D(Table);
|
||||||
|
|
@ -116,21 +121,21 @@ QSet<QString> Table::changedProperties() const
|
||||||
return d->changedProperties;
|
return d->changedProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Table::setParentTable(Table *master)
|
bool Table::setParentTable(Table *master, TableModel *masterModel, TableModel *model)
|
||||||
{
|
{
|
||||||
Q_D(Table);
|
Q_D(Table);
|
||||||
|
|
||||||
QString masterClassName = master->metaObject()->className();
|
QString masterClassName = master->metaObject()->className();
|
||||||
d->refreshModel();
|
d->refreshModel();
|
||||||
|
|
||||||
if (!d->model)
|
// if (!d->model)
|
||||||
d->model = TableModel::findByClassName(metaObject()->className());
|
// d->model = TableModel::findByClassName(metaObject()->className());
|
||||||
|
|
||||||
foreach (RelationModel *r, d->model->foregionKeys())
|
foreach (RelationModel *r, model->foregionKeys())
|
||||||
if(r->masterClassName == masterClassName)
|
if(r->masterClassName == masterClassName)
|
||||||
{
|
{
|
||||||
setProperty(QString(r->localColumn).toLatin1().data(),
|
setProperty(QString(r->localColumn).toLatin1().data(),
|
||||||
master->primaryValue());
|
master->property(masterModel->primaryKey().toUtf8().data()));
|
||||||
d->changedProperties.insert(r->localColumn);
|
d->changedProperties.insert(r->localColumn);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -202,8 +207,8 @@ TablePrivate::TablePrivate(Table *parent) : q_ptr(parent),
|
||||||
void TablePrivate::refreshModel()
|
void TablePrivate::refreshModel()
|
||||||
{
|
{
|
||||||
Q_Q(Table);
|
Q_Q(Table);
|
||||||
if (!model)
|
// if (!model)
|
||||||
model = TableModel::findByClassName(q->metaObject()->className());
|
// model = TableModel::findByClassName(q->metaObject()->className());
|
||||||
}
|
}
|
||||||
|
|
||||||
NUT_END_NAMESPACE
|
NUT_END_NAMESPACE
|
||||||
|
|
|
||||||
17
src/table.h
17
src/table.h
|
|
@ -55,14 +55,14 @@ public:
|
||||||
|
|
||||||
int save(Database *db);
|
int save(Database *db);
|
||||||
|
|
||||||
Q_DECL_DEPRECATED
|
// Q_DECL_DEPRECATED
|
||||||
QString primaryKey() const;
|
// QString primaryKey() const;
|
||||||
|
|
||||||
Q_DECL_DEPRECATED
|
// Q_DECL_DEPRECATED
|
||||||
bool isPrimaryKeyAutoIncrement() const;
|
// bool isPrimaryKeyAutoIncrement() const;
|
||||||
|
|
||||||
Q_DECL_DEPRECATED
|
// Q_DECL_DEPRECATED
|
||||||
QVariant primaryValue() const;
|
// QVariant primaryValue() const;
|
||||||
|
|
||||||
Status status() const;
|
Status status() const;
|
||||||
void setStatus(const Status &status);
|
void setStatus(const Status &status);
|
||||||
|
|
@ -74,7 +74,7 @@ public:
|
||||||
|
|
||||||
QSet<QString> changedProperties() const;
|
QSet<QString> changedProperties() const;
|
||||||
|
|
||||||
bool setParentTable(Table *master);
|
bool setParentTable(Table *master, TableModel *masterModel, TableModel *model);
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
@ -83,6 +83,7 @@ protected:
|
||||||
void propertyChanged(const QString &propName);
|
void propertyChanged(const QString &propName);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void setModel(TableModel *model);
|
||||||
// TableModel *myModel;
|
// TableModel *myModel;
|
||||||
// Status _status;
|
// Status _status;
|
||||||
// QSet<QString> _changedProperties;
|
// QSet<QString> _changedProperties;
|
||||||
|
|
@ -96,6 +97,8 @@ private:
|
||||||
template<class T>
|
template<class T>
|
||||||
friend class Query;
|
friend class Query;
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
friend class TableSet;
|
||||||
friend class TableSetBase;
|
friend class TableSetBase;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,38 +101,6 @@ QStringList TableModel::fieldsNames() const
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSet<TableModel *> TableModel::allModels()
|
|
||||||
{
|
|
||||||
return _allModels;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This is not used anywhere
|
|
||||||
*/
|
|
||||||
TableModel *TableModel::findByTypeId(int typeId)
|
|
||||||
{
|
|
||||||
foreach (TableModel *model, _allModels)
|
|
||||||
if(model->typeId() == typeId)
|
|
||||||
return model;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief TableModel::findByClassName
|
|
||||||
* Find a table model by class name
|
|
||||||
* @param className
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
TableModel *TableModel::findByClassName(const QString &className)
|
|
||||||
{
|
|
||||||
foreach (TableModel *model, _allModels){
|
|
||||||
if(model->className() == className)
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TableModel::operator ==(const TableModel &t) const{
|
bool TableModel::operator ==(const TableModel &t) const{
|
||||||
if(_name != t.name())
|
if(_name != t.name())
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -157,23 +125,6 @@ bool TableModel::operator !=(const TableModel &t) const
|
||||||
return !(*this == t);
|
return !(*this == t);
|
||||||
}
|
}
|
||||||
|
|
||||||
//bool TableModel::checkClassInfo(const QMetaClassInfo &classInfo,
|
|
||||||
// QString &type, QString &name, QString &value)
|
|
||||||
//{
|
|
||||||
// if (!QString(classInfo.name()).startsWith(__nut_NAME_PERFIX)) {
|
|
||||||
// return false;
|
|
||||||
// } else {
|
|
||||||
// QStringList parts = QString(classInfo.value()).split("\n");
|
|
||||||
// if (parts.count() != 3)
|
|
||||||
// return false;
|
|
||||||
|
|
||||||
// type = parts[0];
|
|
||||||
// name = parts[1];
|
|
||||||
// value = parts[2];
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
TableModel::TableModel(int typeId, const QString &tableName)
|
TableModel::TableModel(int typeId, const QString &tableName)
|
||||||
{
|
{
|
||||||
//TODO: check that
|
//TODO: check that
|
||||||
|
|
@ -271,9 +222,6 @@ TableModel::TableModel(int typeId, const QString &tableName)
|
||||||
f->isAutoIncrement = true;
|
f->isAutoIncrement = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!findByTypeId(typeId) && !tableName.isNull())
|
|
||||||
_allModels.insert(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -87,8 +87,10 @@ struct RelationModel{
|
||||||
|
|
||||||
QJsonObject toJson() const;
|
QJsonObject toJson() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool operator ==(const RelationModel &l, const RelationModel &r);
|
bool operator ==(const RelationModel &l, const RelationModel &r);
|
||||||
bool operator !=(const RelationModel &l, const RelationModel &r);
|
bool operator !=(const RelationModel &l, const RelationModel &r);
|
||||||
|
|
||||||
class NUT_EXPORT TableModel
|
class NUT_EXPORT TableModel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -98,10 +100,6 @@ public:
|
||||||
|
|
||||||
QJsonObject toJson() const;
|
QJsonObject toJson() const;
|
||||||
|
|
||||||
// static TableScheema *registerTable(int typeId, QString tableName);
|
|
||||||
// static void createForegionKeys();
|
|
||||||
// static TableModel* model(QString className);
|
|
||||||
|
|
||||||
FieldModel *field(int n) const;
|
FieldModel *field(int n) const;
|
||||||
FieldModel *field(const QString &name) const;
|
FieldModel *field(const QString &name) const;
|
||||||
RelationModel *foregionKey(const QString &otherTable) const;
|
RelationModel *foregionKey(const QString &otherTable) const;
|
||||||
|
|
@ -124,16 +122,6 @@ public:
|
||||||
QList<RelationModel *> foregionKeys() const;
|
QList<RelationModel *> foregionKeys() const;
|
||||||
QStringList fieldsNames() const;
|
QStringList fieldsNames() const;
|
||||||
|
|
||||||
Q_DECL_DEPRECATED
|
|
||||||
static QSet<TableModel *> allModels();
|
|
||||||
|
|
||||||
Q_DECL_DEPRECATED
|
|
||||||
static TableModel *findByTypeId(int typeId);
|
|
||||||
// static TableModel *findByName(QString name);
|
|
||||||
|
|
||||||
Q_DECL_DEPRECATED
|
|
||||||
static TableModel *findByClassName(const QString &className);
|
|
||||||
|
|
||||||
bool operator ==(const TableModel &t) const;
|
bool operator ==(const TableModel &t) const;
|
||||||
bool operator !=(const TableModel &t) const;
|
bool operator !=(const TableModel &t) const;
|
||||||
|
|
||||||
|
|
@ -143,9 +131,9 @@ private:
|
||||||
int _typeId;
|
int _typeId;
|
||||||
QList<FieldModel*> _fields;
|
QList<FieldModel*> _fields;
|
||||||
QList<RelationModel*> _foreignKeys;
|
QList<RelationModel*> _foreignKeys;
|
||||||
|
|
||||||
|
Q_DECL_DEPRECATED
|
||||||
static QSet<TableModel*>_allModels;
|
static QSet<TableModel*>_allModels;
|
||||||
// bool checkClassInfo(const QMetaClassInfo &classInfo,
|
|
||||||
// QString &type, QString &name, QString &value);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
NUT_END_NAMESPACE
|
NUT_END_NAMESPACE
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@
|
||||||
#include "tablesetbase_p.h"
|
#include "tablesetbase_p.h"
|
||||||
#include "table.h"
|
#include "table.h"
|
||||||
#include "bulkinserter.h"
|
#include "bulkinserter.h"
|
||||||
|
//#include "database.h"
|
||||||
|
#include "databasemodel.h"
|
||||||
|
|
||||||
NUT_BEGIN_NAMESPACE
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
|
@ -37,6 +39,7 @@ template<class T>
|
||||||
class Query;
|
class Query;
|
||||||
|
|
||||||
class BulkInserter;
|
class BulkInserter;
|
||||||
|
class Database;
|
||||||
template<class T>
|
template<class T>
|
||||||
class NUT_EXPORT TableSet : public TableSetBase
|
class NUT_EXPORT TableSet : public TableSetBase
|
||||||
{
|
{
|
||||||
|
|
@ -96,21 +99,24 @@ Q_OUTOFLINE_TEMPLATE int TableSet<T>::length() const
|
||||||
template<class T>
|
template<class T>
|
||||||
Q_OUTOFLINE_TEMPLATE T *TableSet<T >::at(int i) const
|
Q_OUTOFLINE_TEMPLATE T *TableSet<T >::at(int i) const
|
||||||
{
|
{
|
||||||
return reinterpret_cast<T*>(_tablesList.at(i));
|
return reinterpret_cast<T*>(_childRows.at(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Q_OUTOFLINE_TEMPLATE const T &TableSet<T>::operator[](int i) const
|
Q_OUTOFLINE_TEMPLATE const T &TableSet<T>::operator[](int i) const
|
||||||
{
|
{
|
||||||
return _tablesList[i];
|
return _childRows[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Q_OUTOFLINE_TEMPLATE void TableSet<T>::append(T *t)
|
Q_OUTOFLINE_TEMPLATE void TableSet<T>::append(T *t)
|
||||||
{
|
{
|
||||||
_tables.insert(t);
|
_tables.insert(t);
|
||||||
_tablesList.append(t);
|
_childRows.append(t);
|
||||||
// rows.append(t);
|
|
||||||
|
// if (_database)
|
||||||
|
// t->setModel(_database->model().tableByClassName(t->metaObject()->className()));
|
||||||
|
|
||||||
t->setParentTableSet(this);
|
t->setParentTableSet(this);
|
||||||
if(t->status() != Table::FeatchedFromDB)
|
if(t->status() != Table::FeatchedFromDB)
|
||||||
t->setStatus(Table::Added);
|
t->setStatus(Table::Added);
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,13 @@
|
||||||
NUT_BEGIN_NAMESPACE
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
TableSetBase::TableSetBase(Database *parent) : QObject(parent),
|
TableSetBase::TableSetBase(Database *parent) : QObject(parent),
|
||||||
_database(parent), _table(nullptr), _tableName(QString())
|
_database(parent), _table(nullptr)//, _tableName(QString())
|
||||||
{
|
{
|
||||||
parent->add(this);
|
parent->add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
TableSetBase::TableSetBase(Table *parent) : QObject(parent),
|
TableSetBase::TableSetBase(Table *parent) : QObject(parent),
|
||||||
_database(nullptr), _table(parent), _tableName(QString())
|
_database(nullptr), _table(parent)//, _tableName(QString())
|
||||||
{
|
{
|
||||||
parent->add(this);
|
parent->add(this);
|
||||||
}
|
}
|
||||||
|
|
@ -46,9 +46,14 @@ TableSetBase::~TableSetBase()
|
||||||
int TableSetBase::save(Database *db, bool cleanUp)
|
int TableSetBase::save(Database *db, bool cleanUp)
|
||||||
{
|
{
|
||||||
int rowsAffected = 0;
|
int rowsAffected = 0;
|
||||||
foreach (Table *t, _tablesList) {
|
TableModel *masterModel = nullptr;
|
||||||
|
if (_table)
|
||||||
|
masterModel = db->model().tableByClassName(_table->metaObject()->className());
|
||||||
|
|
||||||
|
foreach (Table *t, _childRows) {
|
||||||
if(_table)
|
if(_table)
|
||||||
t->setParentTable(_table);
|
t->setParentTable(_table, masterModel,
|
||||||
|
db->model().tableByClassName(t->metaObject()->className()));
|
||||||
|
|
||||||
if(t->status() == Table::Added
|
if(t->status() == Table::Added
|
||||||
|| t->status() == Table::Modified
|
|| t->status() == Table::Modified
|
||||||
|
|
@ -61,30 +66,30 @@ int TableSetBase::save(Database *db, bool cleanUp)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cleanUp)
|
if (cleanUp)
|
||||||
_tablesList.clear();
|
_childRows.clear();
|
||||||
|
|
||||||
return rowsAffected;
|
return rowsAffected;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableSetBase::clearChilds()
|
void TableSetBase::clearChilds()
|
||||||
{
|
{
|
||||||
foreach (Table *t, _tablesList)
|
foreach (Table *t, _childRows)
|
||||||
t->deleteLater();
|
t->deleteLater();
|
||||||
_tablesList.clear();
|
_childRows.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableSetBase::add(Table *t)
|
void TableSetBase::add(Table *t)
|
||||||
{
|
{
|
||||||
if(!_tables.contains(t)){
|
if(!_tables.contains(t)){
|
||||||
_tables.insert(t);
|
_tables.insert(t);
|
||||||
_tablesList.append(t);
|
_childRows.append(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableSetBase::remove(Table *t)
|
void TableSetBase::remove(Table *t)
|
||||||
{
|
{
|
||||||
_tables.remove(t);
|
_tables.remove(t);
|
||||||
_tablesList.removeOne(t);
|
_childRows.removeOne(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TableSetBase::childClassName() const
|
QString TableSetBase::childClassName() const
|
||||||
|
|
|
||||||
|
|
@ -48,10 +48,10 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QSet<Table*> _tables;
|
QSet<Table*> _tables;
|
||||||
QList<Table*> _tablesList;
|
QList<Table*> _childRows;
|
||||||
Database *_database;
|
Database *_database;
|
||||||
Table *_table;
|
Table *_table;
|
||||||
QString _tableName;
|
// QString _tableName;
|
||||||
QString _childClassName;
|
QString _childClassName;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@
|
||||||
#include <qsystemdetection.h>
|
#include <qsystemdetection.h>
|
||||||
|
|
||||||
#define REGISTER(x) qDebug() << (#x) << "type id:" << qMetaTypeId<x*>()
|
#define REGISTER(x) qDebug() << (#x) << "type id:" << qMetaTypeId<x*>()
|
||||||
#define PRINT(x) qDebug() << (#x "=") << (x);
|
#define PRINT(x)
|
||||||
|
//qDebug() << (#x "=") << (x);
|
||||||
#define TIC() QElapsedTimer timer; timer.start()
|
#define TIC() QElapsedTimer timer; timer.start()
|
||||||
#define TOC() qDebug() << QString("Elapsed time: %1ms for %2") \
|
#define TOC() qDebug() << QString("Elapsed time: %1ms for %2") \
|
||||||
.arg(timer.elapsed() / 1000.) \
|
.arg(timer.elapsed() / 1000.) \
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,6 @@ win32 {
|
||||||
LIBDIR = $$absolute_path($$OUT_PWD/../../src)
|
LIBDIR = $$absolute_path($$OUT_PWD/../../src)
|
||||||
}
|
}
|
||||||
|
|
||||||
#LIBS += -L$$LIBDIR -lnut
|
LIBS += -L$$LIBDIR -lnut
|
||||||
INCLUDEPATH += $$PWD/../../src $$PWD/../common
|
INCLUDEPATH += $$PWD/../../src $$PWD/../common
|
||||||
include(../../src/src.pri)
|
#include(../../src/src.pri)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue