Nut/src/generators/sqlitegenerator.cpp

95 lines
2.9 KiB
C++
Raw Normal View History

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;
switch (field->type) {
case QVariant::Bool:
dbType = "int";
break;
case QVariant::ByteArray:
dbType = "blob";
break;
case QVariant::Date:
dbType = "date";
break;
case QVariant::DateTime:
dbType = "datetime";
break;
2016-05-21 16:09:03 +08:00
case QVariant::Time:
dbType = "time";
break;
2016-05-12 14:08:58 +08:00
case QVariant::Double:
dbType = "real";
break;
case QVariant::Int:
2018-01-11 00:18:49 +08:00
dbType = "integer";
// if (field->isAutoIncrement)
// dbType.append(" PRIMARY KEY AUTOINCREMENT");
2016-05-12 14:08:58 +08:00
break;
case QVariant::String:
if(field->length)
dbType = QString("varchar(%1)").arg(field->length);
else
dbType = "text";
break;
default:
dbType = "";
}
2016-05-21 16:09:03 +08:00
return dbType;
2016-05-12 14:08:58 +08:00
}
2017-02-01 18:01:21 +08:00
2018-02-17 23:44:39 +08:00
//QString SqliteGenerator::selectCommand(SqlGeneratorBase::AgregateType t,
// QString agregateArg,
// QString tableName,
// QList<WherePhrase> &wheres,
// QList<WherePhrase> &orders,
// QList<RelationModel*> joins,
// int skip, int take)
//{
// QString command = SqlGeneratorBase::selectCommand(t, agregateArg,
// tableName,
// wheres, orders,
// joins, skip, take);
2018-01-12 00:14:29 +08:00
2018-02-17 23:44:39 +08:00
// if (take != -1 && skip != -1)
// command.append(QString(" LIMIT %1 OFFSET %2")
// .arg(take)
// .arg(skip));
// return command;
//}
2018-01-12 00:14:29 +08:00
2017-02-01 18:01:21 +08:00
NUT_END_NAMESPACE