fix uuid as primary key on sqlite [skip ci]
This commit is contained in:
parent
5e5471fdeb
commit
d3b4698b3e
|
|
@ -209,6 +209,11 @@ inline Row<T> create() {
|
||||||
return QSharedPointer<T>(new T);
|
return QSharedPointer<T>(new T);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline Row<T> create(QObject *parent) {
|
||||||
|
return QSharedPointer<T>(new T(parent));
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using RowList = QList<T*>;
|
using RowList = QList<T*>;
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ QString SqliteGenerator::fieldDeclare(FieldModel *field)
|
||||||
if (type.isEmpty())
|
if (type.isEmpty())
|
||||||
return type;
|
return type;
|
||||||
|
|
||||||
if (field->isPrimaryKey) {
|
if (isNumeric(field->type) && field->isPrimaryKey) {
|
||||||
type = "INTEGER PRIMARY KEY";
|
type = "INTEGER PRIMARY KEY";
|
||||||
if (field->isAutoIncrement)
|
if (field->isAutoIncrement)
|
||||||
type.append(" AUTOINCREMENT");
|
type.append(" AUTOINCREMENT");
|
||||||
|
|
|
||||||
|
|
@ -135,10 +135,10 @@ QVariant SqlModel::headerData(int section, Qt::Orientation orientation, int role
|
||||||
return QAbstractItemModel::headerData(section, orientation, role);
|
return QAbstractItemModel::headerData(section, orientation, role);
|
||||||
}
|
}
|
||||||
|
|
||||||
Table *SqlModel::at(const int &i) const
|
Row<Table> SqlModel::at(const int &i) const
|
||||||
{
|
{
|
||||||
Q_D(const SqlModel);
|
Q_D(const SqlModel);
|
||||||
return d->rows.at(i).data();
|
return d->rows.at(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
SqlModelPrivate::SqlModelPrivate(SqlModel *parent) : q_ptr(parent)
|
SqlModelPrivate::SqlModelPrivate(SqlModel *parent) : q_ptr(parent)
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ public:
|
||||||
void append(Row<Table> table);
|
void append(Row<Table> table);
|
||||||
// void append(Table *table);
|
// void append(Table *table);
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||||
Table *at(const int &i) const;
|
Row<Nut::Table> at(const int &i) const;
|
||||||
|
|
||||||
void setRenderer(const std::function<QVariant (int, QVariant)> &renderer);
|
void setRenderer(const std::function<QVariant (int, QVariant)> &renderer);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,10 @@ template<class T>
|
||||||
class NUT_EXPORT TableSet : public TableSetBase
|
class NUT_EXPORT TableSet : public TableSetBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
typedef T value_type;
|
||||||
|
typedef T *pointer;
|
||||||
|
typedef T &reference;
|
||||||
|
|
||||||
explicit TableSet(Database *parent);
|
explicit TableSet(Database *parent);
|
||||||
explicit TableSet(Table *parent);
|
explicit TableSet(Table *parent);
|
||||||
|
|
||||||
|
|
@ -53,8 +57,6 @@ public:
|
||||||
void remove(T *t);
|
void remove(T *t);
|
||||||
void remove(QList<T *> t);
|
void remove(QList<T *> t);
|
||||||
|
|
||||||
inline T *type() const {}
|
|
||||||
|
|
||||||
int length() const;
|
int length() const;
|
||||||
T *at(int i) const;
|
T *at(int i) const;
|
||||||
const T &operator[](int i) const;
|
const T &operator[](int i) const;
|
||||||
|
|
@ -112,6 +114,8 @@ Q_OUTOFLINE_TEMPLATE const T &TableSet<T>::operator[](int i) const
|
||||||
template<class T>
|
template<class T>
|
||||||
Q_OUTOFLINE_TEMPLATE void TableSet<T>::append(Row<T> t)
|
Q_OUTOFLINE_TEMPLATE void TableSet<T>::append(Row<T> t)
|
||||||
{
|
{
|
||||||
|
data.detach();
|
||||||
|
data->childs.append(t);
|
||||||
data->tables.insert(t.data());
|
data->tables.insert(t.data());
|
||||||
data->childRows.append(t.data());
|
data->childRows.append(t.data());
|
||||||
|
|
||||||
|
|
@ -133,6 +137,8 @@ Q_OUTOFLINE_TEMPLATE void TableSet<T>::append(RowList<T> t)
|
||||||
template<class T>
|
template<class T>
|
||||||
Q_OUTOFLINE_TEMPLATE void TableSet<T>::remove(T *t)
|
Q_OUTOFLINE_TEMPLATE void TableSet<T>::remove(T *t)
|
||||||
{
|
{
|
||||||
|
data.detach();
|
||||||
|
data->childs.removeOne(t);
|
||||||
data->tables.remove(t);
|
data->tables.remove(t);
|
||||||
t->setStatus(Table::Deleted);
|
t->setStatus(Table::Deleted);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ int TableSetBase::save(Database *db, bool cleanUp)
|
||||||
if (data->table)
|
if (data->table)
|
||||||
masterModel = db->model().tableByClassName(data->table->metaObject()->className());
|
masterModel = db->model().tableByClassName(data->table->metaObject()->className());
|
||||||
|
|
||||||
foreach (Row<Table> t, data->childRows) {
|
foreach (Table *t, data->childRows) {
|
||||||
if(data->table)
|
if(data->table)
|
||||||
t->setParentTable(data->table,
|
t->setParentTable(data->table,
|
||||||
masterModel,
|
masterModel,
|
||||||
|
|
@ -82,18 +82,22 @@ void TableSetBase::clearChilds()
|
||||||
data->childRows.clear();
|
data->childRows.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableSetBase::add(Row<Table> t)
|
void TableSetBase::add(Table *t)
|
||||||
{
|
{
|
||||||
if(!data->tables.contains(t.data())){
|
if(!data->tables.contains(t)){
|
||||||
data->tables.insert(t.data());
|
data.detach();
|
||||||
|
data->tables.insert(t);
|
||||||
data->childRows.append(t);
|
data->childRows.append(t);
|
||||||
|
// data->childs.append(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableSetBase::remove(Row<Table> t)
|
void TableSetBase::remove(Table *t)
|
||||||
{
|
{
|
||||||
data->tables.remove(t.data());
|
data.detach();
|
||||||
|
data->tables.remove(t);
|
||||||
data->childRows.removeOne(t);
|
data->childRows.removeOne(t);
|
||||||
|
// data->childs.removeOne(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TableSetBase::childClassName() const
|
QString TableSetBase::childClassName() const
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,8 @@ protected:
|
||||||
QExplicitlySharedDataPointer<TableSetBaseData> data;
|
QExplicitlySharedDataPointer<TableSetBaseData> data;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void add(Row<Table> t);
|
void add(Table* t);
|
||||||
void remove(Row<Table> t);
|
void remove(Table *t);
|
||||||
|
|
||||||
friend class Table;
|
friend class Table;
|
||||||
friend class QueryBase;
|
friend class QueryBase;
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,8 @@ public:
|
||||||
|
|
||||||
QSet<Table*> tables;
|
QSet<Table*> tables;
|
||||||
QList<Table*> childRows;
|
QList<Table*> childRows;
|
||||||
|
RowList<Table> childs;
|
||||||
|
|
||||||
Database *database;
|
Database *database;
|
||||||
Table *table;
|
Table *table;
|
||||||
QString childClassName;
|
QString childClassName;
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,6 @@ void UuidTest::save()
|
||||||
int n = db.saveChanges();
|
int n = db.saveChanges();
|
||||||
TOC();
|
TOC();
|
||||||
|
|
||||||
TOC();
|
|
||||||
QTEST_ASSERT(n == 1);
|
QTEST_ASSERT(n == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue