init for ci test
This commit is contained in:
parent
d906bd81fd
commit
d3f43ca15e
|
|
@ -0,0 +1 @@
|
|||
QT -= gui
|
||||
|
|
@ -264,9 +264,20 @@ bool DatabasePrivate::getCurrectScheema()
|
|||
}
|
||||
}
|
||||
|
||||
foreach (TableModel *table, currentModel)
|
||||
foreach (TableModel *table, currentModel) {
|
||||
foreach (FieldModel *f, table->fields()) {
|
||||
if (f->isPrimaryKey && ! sqlGenertor->supportPrimaryKey(f->type))
|
||||
qFatal("The field of type %s does not support as primary key",
|
||||
qPrintable(f->typeName));
|
||||
|
||||
if (f->isAutoIncrement && ! sqlGenertor->supportAutoIncrement(f->type))
|
||||
qFatal("The field of type %s does not support as auto increment",
|
||||
qPrintable(f->typeName));
|
||||
}
|
||||
|
||||
foreach (RelationModel *fk, table->foregionKeys())
|
||||
fk->masterTable = currentModel.tableByClassName(fk->masterClassName);
|
||||
}
|
||||
|
||||
allTableMaps.insert(q->metaObject()->className(), currentModel);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -181,6 +181,7 @@ public: \
|
|||
return m_##n; \
|
||||
}
|
||||
|
||||
#define NUT_FIELD(name) NUT_INFO(__nut_FIELD, name, 0)
|
||||
#define NUT_PRIMARY_KEY(x) NUT_INFO(__nut_PRIMARY_KEY, x, 0)
|
||||
#define NUT_AUTO_INCREMENT(x) NUT_INFO(__nut_AUTO_INCREMENT, x, 0)
|
||||
#define NUT_PRIMARY_AUTO_INCREMENT(x) NUT_INFO(__nut_PRIMARY_KEY_AI, x, 0)
|
||||
|
|
|
|||
|
|
@ -52,6 +52,21 @@ NUT_BEGIN_NAMESPACE
|
|||
* INNER JOIN dbo.GiftCards ON dbo.GiftTypes.GiftTypeID = dbo.GiftCards.GiftTypeID
|
||||
* INNER JOIN dbo.Entities ON dbo.GiftCards.GiftCardID = dbo.Entities.GiftCardID
|
||||
*/
|
||||
bool SqlGeneratorBase::isNumeric(const QMetaType::Type &type)
|
||||
{
|
||||
return type == QMetaType::SChar
|
||||
|| type == QMetaType::Char
|
||||
|| type == QMetaType::UChar
|
||||
|| type == QMetaType::Short
|
||||
|| type == QMetaType::UShort
|
||||
|| type == QMetaType::Int
|
||||
|| type == QMetaType::UInt
|
||||
|| type == QMetaType::Long
|
||||
|| type == QMetaType::ULong
|
||||
|| type == QMetaType::LongLong
|
||||
|| type == QMetaType::ULongLong;
|
||||
}
|
||||
|
||||
SqlGeneratorBase::SqlGeneratorBase(Database *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@ class SqlGeneratorBase : public QObject
|
|||
protected:
|
||||
SqlSerializer *_serializer;
|
||||
|
||||
bool isNumeric(const QMetaType::Type &type);
|
||||
|
||||
public:
|
||||
//TODO: remove this enum
|
||||
enum CommandType{
|
||||
|
|
@ -74,12 +76,14 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
//fields
|
||||
virtual QString fieldType(FieldModel *field) = 0;
|
||||
virtual QString fieldDeclare(FieldModel *field);
|
||||
|
||||
virtual QString masterDatabaseName(QString databaseName);
|
||||
|
||||
virtual QString createTable(TableModel *table);
|
||||
|
||||
virtual QString fieldType(FieldModel *field) = 0;
|
||||
virtual QString fieldDeclare(FieldModel *field);
|
||||
virtual QString relationDeclare(const RelationModel *relation);
|
||||
|
||||
virtual QStringList diff(const DatabaseModel &lastModel, const DatabaseModel &newModel);
|
||||
|
|
|
|||
|
|
@ -31,12 +31,6 @@ SqliteGenerator::SqliteGenerator(Database *parent) : SqlGeneratorBase(parent)
|
|||
|
||||
QString SqliteGenerator::fieldType(FieldModel *field)
|
||||
{
|
||||
if (field->isPrimaryKey) {
|
||||
QString primaryKeyPerfix = " PRIMARY KEY";
|
||||
if (field->isAutoIncrement)
|
||||
primaryKeyPerfix += " AUTOINCREMENT";
|
||||
return "INTEGER" + primaryKeyPerfix;
|
||||
}
|
||||
switch (field->type) {
|
||||
case QMetaType::Bool: return "BOOLEAN";
|
||||
case QMetaType::QBitArray:
|
||||
|
|
@ -78,7 +72,7 @@ QString SqliteGenerator::fieldType(FieldModel *field)
|
|||
case QMetaType::QPolygonF:
|
||||
case QMetaType::QStringList:
|
||||
case QMetaType::QColor:
|
||||
case QMetaType::QUuid: return "text";
|
||||
case QMetaType::QUuid: return "TEXT";
|
||||
|
||||
// if (field->isAutoIncrement)
|
||||
// dbType.append(" PRIMARY KEY AUTOINCREMENT");
|
||||
|
|
@ -95,6 +89,29 @@ QString SqliteGenerator::fieldType(FieldModel *field)
|
|||
}
|
||||
}
|
||||
|
||||
QString SqliteGenerator::fieldDeclare(FieldModel *field)
|
||||
{
|
||||
QString type = fieldType(field);
|
||||
if (type.isEmpty())
|
||||
return type;
|
||||
|
||||
if (field->isPrimaryKey) {
|
||||
type.append(" PRIMARY KEY");
|
||||
if (field->isAutoIncrement)
|
||||
type = "INTEGER PRIMARY KEY AUTOINCREMENT";
|
||||
}
|
||||
|
||||
if (field->notNull)
|
||||
type.append(" NOT NULL");
|
||||
|
||||
return field->name + " " + type;
|
||||
}
|
||||
|
||||
bool SqliteGenerator::supportAutoIncrement(const QMetaType::Type &type)
|
||||
{
|
||||
return isNumeric(type);
|
||||
}
|
||||
|
||||
|
||||
QStringList SqliteGenerator::diff(TableModel *oldTable, TableModel *newTable)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -32,11 +32,14 @@ public:
|
|||
explicit SqliteGenerator(Database *parent = nullptr);
|
||||
|
||||
QString fieldType(FieldModel *field) override;
|
||||
QString fieldDeclare(FieldModel *field) override;
|
||||
bool supportAutoIncrement(const QMetaType::Type &type) override;
|
||||
|
||||
void appendSkipTake(QString &sql, int skip, int take) override;
|
||||
|
||||
QString primaryKeyConstraint(const TableModel *table) const override;
|
||||
QStringList diff(TableModel *oldTable, TableModel *newTable) override;
|
||||
|
||||
};
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -72,3 +72,4 @@ SOURCES += \
|
|||
$$PWD/phrases/datephrase.cpp
|
||||
|
||||
include($$PWD/../3rdparty/serializer/src/src.pri)
|
||||
include($$PWD/../ci-test-init.pri)
|
||||
|
|
|
|||
|
|
@ -23,3 +23,5 @@ HEADERS += \
|
|||
../common/weblogdatabase.h \
|
||||
../common/score.h \
|
||||
tst_basic.h
|
||||
|
||||
include($$PWD/../../ci-test-init.pri)
|
||||
|
|
|
|||
|
|
@ -24,3 +24,4 @@ HEADERS += \
|
|||
../common/weblogdatabase.h \
|
||||
../common/score.h
|
||||
|
||||
include($$PWD/../ci-test-init.pri)
|
||||
|
|
|
|||
|
|
@ -16,3 +16,5 @@ HEADERS += \
|
|||
db.h \
|
||||
sampletable.h \
|
||||
tst_datatypes.h
|
||||
|
||||
include($$PWD/../ci-test-init.pri)
|
||||
|
|
|
|||
|
|
@ -12,3 +12,5 @@ SOURCES += \
|
|||
|
||||
HEADERS += \
|
||||
tst_generators.h
|
||||
|
||||
include($$PWD/../ci-test-init.pri)
|
||||
|
|
|
|||
|
|
@ -12,3 +12,5 @@ SOURCES += \
|
|||
|
||||
HEADERS += \
|
||||
tst_phrases.h
|
||||
|
||||
include($$PWD/../ci-test-init.pri)
|
||||
|
|
|
|||
|
|
@ -16,3 +16,5 @@ HEADERS += \
|
|||
testdatabase.h \
|
||||
test.h \
|
||||
tst_uuid.h
|
||||
|
||||
include($$PWD/../ci-test-init.pri)
|
||||
|
|
|
|||
|
|
@ -22,3 +22,5 @@ HEADERS += \
|
|||
table2.h \
|
||||
db3.h \
|
||||
table3.h
|
||||
|
||||
include($$PWD/../ci-test-init.pri)
|
||||
|
|
|
|||
Loading…
Reference in New Issue