working for now && compiler in success form
This commit is contained in:
parent
7871092a81
commit
8af5f06727
30
src/query.h
30
src/query.h
|
|
@ -259,6 +259,10 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
|
||||||
int n = -1;
|
int n = -1;
|
||||||
|
|
||||||
while (p) {
|
while (p) {
|
||||||
|
// Q_ASSERT(p != lastP);
|
||||||
|
// if (p == lastP)
|
||||||
|
// qFatal("NULL Loop detected");
|
||||||
|
|
||||||
++n;
|
++n;
|
||||||
n = n % levels.count();
|
n = n % levels.count();
|
||||||
if (checked[n])
|
if (checked[n])
|
||||||
|
|
@ -268,14 +272,14 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
|
||||||
// check if key value is changed
|
// check if key value is changed
|
||||||
if (data.lastKeyValue == q.value(data.keyFiledname)) {
|
if (data.lastKeyValue == q.value(data.keyFiledname)) {
|
||||||
--p;
|
--p;
|
||||||
qDebug() << "key os not changed for" << data.keyFiledname;
|
// qDebug() << "key os not changed for" << data.keyFiledname;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if master if current table has processed
|
// check if master if current table has processed
|
||||||
foreach (int m, data.masters)
|
foreach (int m, data.masters)
|
||||||
if (!checked[m]) {
|
if (!checked[m]) {
|
||||||
qDebug() << "row is checked";
|
// qDebug() << "row is checked";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -285,13 +289,13 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
|
||||||
|
|
||||||
//create table row
|
//create table row
|
||||||
Table *table;
|
Table *table;
|
||||||
Row<T> tablePointer;
|
Row<Table> shp;
|
||||||
if (data.table->className() == d->className) {
|
if (data.table->className() == d->className) {
|
||||||
table = new T();
|
table = new T();
|
||||||
#ifdef NUT_SHARED_POINTER
|
#ifdef NUT_SHARED_POINTER
|
||||||
tablePointer = QSharedPointer<T>(qobject_cast<T*>(table));
|
shp = QSharedPointer<Table>(table);
|
||||||
returnList.append(tablePointer);
|
returnList.append(shp.objectCast<T>());
|
||||||
d->tableSet->add(tablePointer);
|
d->tableSet->add(shp);
|
||||||
#else
|
#else
|
||||||
returnList.append(dynamic_cast<T*>(table));
|
returnList.append(dynamic_cast<T*>(table));
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -303,9 +307,13 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
|
||||||
if (!table)
|
if (!table)
|
||||||
qFatal("Could not create instance of %s",
|
qFatal("Could not create instance of %s",
|
||||||
qPrintable(data.table->name()));
|
qPrintable(data.table->name()));
|
||||||
|
shp = QSharedPointer<Table>(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connect(table, &QObject::destroyed, [](QObject *){
|
||||||
|
qDebug() << "Destroyed";
|
||||||
|
});
|
||||||
|
|
||||||
QList<FieldModel*> childFields = data.table->fields();
|
QList<FieldModel*> childFields = data.table->fields();
|
||||||
foreach (FieldModel *field, childFields)
|
foreach (FieldModel *field, childFields)
|
||||||
table->setProperty(field->name.toLatin1().data(),
|
table->setProperty(field->name.toLatin1().data(),
|
||||||
|
|
@ -321,6 +329,9 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
|
||||||
bool ok = table->metaObject()->invokeMethod(table,
|
bool ok = table->metaObject()->invokeMethod(table,
|
||||||
mName.toLocal8Bit().data(),
|
mName.toLocal8Bit().data(),
|
||||||
QGenericArgument(type.toLatin1().data(), levels[master].lastRow));
|
QGenericArgument(type.toLatin1().data(), levels[master].lastRow));
|
||||||
|
// bool ok = table->setProperty(data.masterFields[i].toLocal8Bit().data(),
|
||||||
|
// QVariant::fromValue(shp.data()));
|
||||||
|
|
||||||
#else
|
#else
|
||||||
bool ok = table->setProperty(data.masterFields[i].toLocal8Bit().data(),
|
bool ok = table->setProperty(data.masterFields[i].toLocal8Bit().data(),
|
||||||
QVariant::fromValue(levels[master].lastRow));
|
QVariant::fromValue(levels[master].lastRow));
|
||||||
|
|
@ -334,7 +345,9 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
|
||||||
data.table->className());
|
data.table->className());
|
||||||
table->setParentTableSet(tableset);
|
table->setParentTableSet(tableset);
|
||||||
#ifdef NUT_SHARED_POINTER
|
#ifdef NUT_SHARED_POINTER
|
||||||
tableset->add(qSharedPointerCast<Table>(tablePointer));
|
tableset->add(shp);
|
||||||
|
#else
|
||||||
|
tableset->add(table);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -352,6 +365,7 @@ Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
|
||||||
deleteLater();
|
deleteLater();
|
||||||
#endif
|
#endif
|
||||||
return returnList;
|
return returnList;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,8 @@ public:
|
||||||
void remove(RowList<T> t);
|
void remove(RowList<T> t);
|
||||||
|
|
||||||
int length() const;
|
int length() const;
|
||||||
T *at(int i) const;
|
Row<T> at(int i) const;
|
||||||
const T &operator[](int i) const;
|
const Row<T> operator[](int i) const;
|
||||||
|
|
||||||
Query<T> *query(bool autoDelete = true);
|
Query<T> *query(bool autoDelete = true);
|
||||||
BulkInserter *bulkInserter();
|
BulkInserter *bulkInserter();
|
||||||
|
|
@ -95,20 +95,27 @@ Q_OUTOFLINE_TEMPLATE BulkInserter *TableSet<T>::bulkInserter()
|
||||||
template<class T>
|
template<class T>
|
||||||
Q_OUTOFLINE_TEMPLATE int TableSet<T>::length() const
|
Q_OUTOFLINE_TEMPLATE int TableSet<T>::length() const
|
||||||
{
|
{
|
||||||
return data->tables.count();
|
return data->childs.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Q_OUTOFLINE_TEMPLATE T *TableSet<T >::at(int i) const
|
Q_OUTOFLINE_TEMPLATE Row<T> TableSet<T >::at(int i) const
|
||||||
{
|
{
|
||||||
//TODO: check
|
#ifdef NUT_SHARED_POINTER
|
||||||
return reinterpret_cast<T*>(data->childRows.at(i));
|
return data->childs.at(i).objectCast<T>();
|
||||||
|
#else
|
||||||
|
return reinterpret_cast<T*>(data->childs.at(i));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Q_OUTOFLINE_TEMPLATE const T &TableSet<T>::operator[](int i) const
|
Q_OUTOFLINE_TEMPLATE const Row<T> TableSet<T>::operator[](int i) const
|
||||||
{
|
{
|
||||||
return data->childRows[i];
|
#ifdef NUT_SHARED_POINTER
|
||||||
|
return data->childs.at(i).objectCast<T>();
|
||||||
|
#else
|
||||||
|
return reinterpret_cast<T*>(data->childs.at(i));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|
@ -116,8 +123,8 @@ Q_OUTOFLINE_TEMPLATE void TableSet<T>::append(Row<T> t)
|
||||||
{
|
{
|
||||||
data.detach();
|
data.detach();
|
||||||
data->childs.append(t);
|
data->childs.append(t);
|
||||||
data->tables.insert(t.data());
|
// data->tables.insert(t.data());
|
||||||
data->childRows.append(t.data());
|
// data->childRows.append(t.data());
|
||||||
|
|
||||||
// if (_database)
|
// if (_database)
|
||||||
// t->setModel(_database->model().tableByClassName(t->metaObject()->className()));
|
// t->setModel(_database->model().tableByClassName(t->metaObject()->className()));
|
||||||
|
|
@ -138,8 +145,8 @@ template<class T>
|
||||||
Q_OUTOFLINE_TEMPLATE void TableSet<T>::remove(Row<T> t)
|
Q_OUTOFLINE_TEMPLATE void TableSet<T>::remove(Row<T> t)
|
||||||
{
|
{
|
||||||
data.detach();
|
data.detach();
|
||||||
data->childs.removeOne(t.data());
|
// data->childs.removeOne(t.data());
|
||||||
data->tables.remove(t.data());
|
// data->tables.remove(t.data());
|
||||||
data->childs.removeOne(t);
|
data->childs.removeOne(t);
|
||||||
t->setStatus(Table::Deleted);
|
t->setStatus(Table::Deleted);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,8 @@ TableSetBase::TableSetBase(Table *parent) : QObject(parent),
|
||||||
|
|
||||||
TableSetBase::~TableSetBase()
|
TableSetBase::~TableSetBase()
|
||||||
{
|
{
|
||||||
foreach (Table *t, data->tables)
|
// foreach (Table *t, data->tables)
|
||||||
t->setParentTableSet(nullptr);
|
// t->setParentTableSet(nullptr);
|
||||||
|
|
||||||
foreach (Row<Table> t, data->childs)
|
foreach (Row<Table> t, data->childs)
|
||||||
if (t)
|
if (t)
|
||||||
|
|
@ -75,7 +75,7 @@ int TableSetBase::save(Database *db, bool cleanUp)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cleanUp)
|
if (cleanUp)
|
||||||
data->childRows.clear();
|
data->childs.clear();
|
||||||
|
|
||||||
return rowsAffected;
|
return rowsAffected;
|
||||||
}
|
}
|
||||||
|
|
@ -83,10 +83,10 @@ int TableSetBase::save(Database *db, bool cleanUp)
|
||||||
void TableSetBase::clearChilds()
|
void TableSetBase::clearChilds()
|
||||||
{
|
{
|
||||||
#ifndef NUT_SHARED_POINTER
|
#ifndef NUT_SHARED_POINTER
|
||||||
foreach (Table *t, data->childRows)
|
foreach (Table *t, data->childs)
|
||||||
t->deleteLater();
|
t->deleteLater();
|
||||||
#endif
|
#endif
|
||||||
data->childRows.clear();
|
data->childs.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
//void TableSetBase::add(Table *t)
|
//void TableSetBase::add(Table *t)
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,8 @@ public:
|
||||||
database(nullptr), table(parent)
|
database(nullptr), table(parent)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
QSet<Table*> tables;
|
// QSet<Table*> tables;
|
||||||
QList<Table*> childRows;
|
// QList<Table*> childRows;
|
||||||
RowList<Table> childs;
|
RowList<Table> childs;
|
||||||
|
|
||||||
Database *database;
|
Database *database;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#define CONSTS_H
|
#define CONSTS_H
|
||||||
|
|
||||||
#include <qsystemdetection.h>
|
#include <qsystemdetection.h>
|
||||||
|
#include <qcompilerdetection.h>
|
||||||
|
|
||||||
#define REGISTER(x) qDebug() << (#x) << "type id:" << qMetaTypeId<x*>()
|
#define REGISTER(x) qDebug() << (#x) << "type id:" << qMetaTypeId<x*>()
|
||||||
#define PRINT(x)
|
#define PRINT(x)
|
||||||
|
|
@ -27,6 +28,20 @@
|
||||||
# define OS "Unknown"
|
# define OS "Unknown"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef Q_CC_GNU
|
||||||
|
# ifdef Q_CC_MINGW
|
||||||
|
# define CC "MinGW"
|
||||||
|
# else
|
||||||
|
# define CC "GNU"
|
||||||
|
# endif
|
||||||
|
#elif defined (Q_CC_MSVC)
|
||||||
|
# define CC "msvc"
|
||||||
|
#elif defined (Q_CC_CLANG)
|
||||||
|
# define CC "clang"
|
||||||
|
#else
|
||||||
|
# define CC "Unknown"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define PRINT_FORM(db) \
|
#define PRINT_FORM(db) \
|
||||||
qDebug() << "\n\n****************************" \
|
qDebug() << "\n\n****************************" \
|
||||||
<< "\nAll tests passed," \
|
<< "\nAll tests passed," \
|
||||||
|
|
@ -34,6 +49,7 @@
|
||||||
<< "hamed.masafi@gmail.com" \
|
<< "hamed.masafi@gmail.com" \
|
||||||
<< "\n\tDriver:" << db.driver() \
|
<< "\n\tDriver:" << db.driver() \
|
||||||
<< "\n\tOS: " OS " (version: ________)" \
|
<< "\n\tOS: " OS " (version: ________)" \
|
||||||
|
<< "\n\tCompiler: " CC " (version: ________)" \
|
||||||
<< "\n\tQt version: " QT_VERSION_STR \
|
<< "\n\tQt version: " QT_VERSION_STR \
|
||||||
<< "\n\tTest:" << metaObject()->className() \
|
<< "\n\tTest:" << metaObject()->className() \
|
||||||
<< "\n****************************\n";
|
<< "\n****************************\n";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue