2016-05-21 16:09:03 +08:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Nut project.
|
|
|
|
|
** https://github.com/HamedMasafi/Nut
|
|
|
|
|
**
|
|
|
|
|
** Nut is free software: you can redistribute it and/or modify
|
|
|
|
|
** it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
** (at your option) any later version.
|
|
|
|
|
**
|
|
|
|
|
** Nut is distributed in the hope that it will be useful,
|
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
** GNU Lesser General Public License for more details.
|
|
|
|
|
**
|
|
|
|
|
** You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2016-05-12 14:08:58 +08:00
|
|
|
#include "sqlitegenerator.h"
|
2017-10-07 18:26:05 +08:00
|
|
|
#include "../table.h"
|
|
|
|
|
#include "../tablemodel.h"
|
2016-05-12 14:08:58 +08:00
|
|
|
|
2017-02-01 18:01:21 +08:00
|
|
|
NUT_BEGIN_NAMESPACE
|
|
|
|
|
|
2016-05-24 14:47:37 +08:00
|
|
|
SqliteGenerator::SqliteGenerator(Database *parent) : SqlGeneratorBase(parent)
|
2016-05-12 14:08:58 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-21 16:09:03 +08:00
|
|
|
QString SqliteGenerator::fieldType(FieldModel *field)
|
2016-05-12 14:08:58 +08:00
|
|
|
{
|
|
|
|
|
QString ret = field->name + " ";
|
|
|
|
|
QString dbType;
|
|
|
|
|
|
2019-01-21 00:29:54 +08:00
|
|
|
switch (static_cast<QMetaType::Type>(field->type)) {
|
|
|
|
|
case QMetaType::Bool: return "BOOLEAN";
|
|
|
|
|
case QMetaType::QByteArray: return "BLOB";
|
|
|
|
|
case QMetaType::QDate: return "DATE";
|
|
|
|
|
case QMetaType::QDateTime: return "DATETIME";
|
|
|
|
|
case QMetaType::QTime: return "TIME";
|
|
|
|
|
case QMetaType::Double: return "DOUBLE";
|
|
|
|
|
case QMetaType::Float: return "FLOAT";
|
|
|
|
|
|
|
|
|
|
case QMetaType::SChar:
|
|
|
|
|
case QMetaType::Char: return "TINYINT";
|
|
|
|
|
case QMetaType::UChar: return "TINYINT UNSIGNED";
|
|
|
|
|
case QMetaType::Short: return "SMALLINT";
|
|
|
|
|
case QMetaType::UShort: return "SMALLINT UNSIGNED";
|
|
|
|
|
case QMetaType::Int: return "INT";
|
|
|
|
|
case QMetaType::UInt: return "INT UNSIGNED";
|
|
|
|
|
case QMetaType::Long: return "MEDIUMINT";
|
|
|
|
|
case QMetaType::ULong: return "MEDIUMINT UNSIGNED";
|
|
|
|
|
case QMetaType::LongLong: return "BIGINT";
|
|
|
|
|
case QMetaType::ULongLong: return "BIGINT UNSIGNED";
|
|
|
|
|
|
|
|
|
|
case QMetaType::QUuid: return "text";
|
|
|
|
|
|
2018-01-11 00:18:49 +08:00
|
|
|
// if (field->isAutoIncrement)
|
|
|
|
|
// dbType.append(" PRIMARY KEY AUTOINCREMENT");
|
2019-01-21 00:29:54 +08:00
|
|
|
case QMetaType::QString:
|
2016-05-12 14:08:58 +08:00
|
|
|
if(field->length)
|
2019-01-21 00:29:54 +08:00
|
|
|
return QString("VARCHAR(%1)").arg(field->length);
|
2016-05-12 14:08:58 +08:00
|
|
|
else
|
2019-01-21 00:29:54 +08:00
|
|
|
return "TEXT";
|
2016-05-12 14:08:58 +08:00
|
|
|
default:
|
2019-01-21 00:29:54 +08:00
|
|
|
qDebug() << "The type (" << field->type << ") does not supported";
|
|
|
|
|
return QString();
|
2016-05-12 14:08:58 +08:00
|
|
|
}
|
|
|
|
|
}
|
2017-02-01 18:01:21 +08:00
|
|
|
|
2018-02-21 23:41:45 +08:00
|
|
|
void SqliteGenerator::appendSkipTake(QString &sql, int skip, int take)
|
|
|
|
|
{
|
|
|
|
|
if (take != -1 && skip != -1)
|
|
|
|
|
sql.append(QString(" LIMIT %1 OFFSET %2")
|
|
|
|
|
.arg(take)
|
|
|
|
|
.arg(skip));
|
|
|
|
|
}
|
2018-01-12 00:14:29 +08:00
|
|
|
|
2017-02-01 18:01:21 +08:00
|
|
|
NUT_END_NAMESPACE
|