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