Revision 3b5d8beb
Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt
src/schema.cpp | ||
---|---|---|
Schema::~Schema() {
|
||
}
|
||
|
||
QString Schema::primaryKey(int length) const {
|
||
return this->buildColumnSchema(TYPE_PK, this->lengthToString(length));
|
||
}
|
||
|
||
QString Schema::bigPrimaryKey(int length) const {
|
||
return this->buildColumnSchema(TYPE_BIGPK, this->lengthToString(length));
|
||
}
|
||
|
||
QString Schema::string(int length, bool notNull, QString defaultValue,
|
||
bool unique, QString checkConstraint) const {
|
||
return this->buildColumnSchema(TYPE_STRING, this->lengthToString(length),
|
||
notNull, defaultValue, unique, checkConstraint);
|
||
}
|
||
|
||
QString Schema::text(bool notNull, QString defaultValue, bool unique,
|
||
QString checkConstraint) const {
|
||
return this->buildColumnSchema(TYPE_TEXT, "", notNull, defaultValue, unique,
|
||
checkConstraint);
|
||
}
|
||
|
||
QString Schema::smallInteger(int length, bool notNull, QString defaultValue,
|
||
bool unique, QString checkConstraint) const {
|
||
return this->buildColumnSchema(TYPE_SMALLINT, this->lengthToString(length),
|
||
notNull, defaultValue, unique, checkConstraint);
|
||
}
|
||
|
||
QString Schema::integer(int length, bool notNull, QString defaultValue,
|
||
bool unique, QString checkConstraint) const {
|
||
return this->buildColumnSchema(TYPE_INTEGER, this->lengthToString(length),
|
||
notNull, defaultValue, unique, checkConstraint);
|
||
}
|
||
|
||
QString Schema::bigInteger(int length, bool notNull, QString defaultValue,
|
||
bool unique, QString checkConstraint) const {
|
||
return this->buildColumnSchema(TYPE_BIGINT, this->lengthToString(length),
|
||
notNull, defaultValue, unique, checkConstraint);
|
||
}
|
||
|
||
QString Schema::floatColumn(int precision, bool notNull, QString defaultValue,
|
||
bool unique, QString checkConstraint) const {
|
||
return this->buildColumnSchema(TYPE_FLOAT, this->lengthToString(precision),
|
||
notNull, defaultValue, unique, checkConstraint);
|
||
}
|
||
|
||
QString Schema::doubleColumn(int precision, bool notNull, QString defaultValue,
|
||
bool unique, QString checkConstraint) const {
|
||
return this->buildColumnSchema(TYPE_DOUBLE, this->lengthToString(precision),
|
||
notNull, defaultValue, unique, checkConstraint);
|
||
}
|
||
|
||
QString Schema::decimal(int precision, int scale, bool notNull,
|
||
QString defaultValue, bool unique, QString checkConstraint) const {
|
||
|
||
return this->buildColumnSchema(TYPE_DECIMAL,
|
||
this->combineScaleAndPrecision(precision, scale), notNull, defaultValue,
|
||
unique, checkConstraint);
|
||
}
|
||
|
||
QString Schema::dateTime(int precision, bool notNull, QString defaultValue,
|
||
bool unique, QString checkConstraint) const {
|
||
return this->buildColumnSchema(TYPE_DATETIME, this->lengthToString(precision),
|
||
notNull, defaultValue, unique, checkConstraint);
|
||
}
|
||
|
||
QString Schema::timestamp(int precision, bool notNull, QString defaultValue,
|
||
bool unique, QString checkConstraint) const {
|
||
return this->buildColumnSchema(TYPE_TIMESTAMP, this->lengthToString(precision),
|
||
notNull, defaultValue, unique, checkConstraint);
|
||
}
|
||
|
||
QString Schema::time(int precision, bool notNull, QString defaultValue,
|
||
bool unique, QString checkConstraint) const {
|
||
return this->buildColumnSchema(TYPE_TIME, this->lengthToString(precision),
|
||
notNull, defaultValue, unique, checkConstraint);
|
||
}
|
||
|
||
QString Schema::binary(int length, bool notNull, bool unique,
|
||
QString checkConstraint) const {
|
||
return this->buildColumnSchema(TYPE_BINARY, this->lengthToString(length),
|
||
notNull, "", unique, checkConstraint);
|
||
}
|
||
|
||
QString Schema::boolean(QString defaultValue, bool notNull) const {
|
||
return this->buildColumnSchema(TYPE_DOUBLE, "", notNull, defaultValue);
|
||
}
|
||
|
||
QString Schema::money(int precision, int scale, bool notNull,
|
||
QString defaultValue, bool unique, QString checkConstraint) const {
|
||
return this->buildColumnSchema(TYPE_MONEY,
|
||
this->combineScaleAndPrecision(precision, scale),
|
||
notNull, defaultValue, unique, checkConstraint);
|
||
}
|
||
|
||
void Schema::initAbstractDatabaseTypes() {
|
||
this->abstractTypeMap->insert("bool", TYPE_SMALLINT);
|
||
this->abstractTypeMap->insert("short", TYPE_SMALLINT);
|
||
... | ... | |
}
|
||
|
||
QString Schema::buildDefaultString(QString def) const {
|
||
|
||
if (def.isEmpty()) {
|
||
return "";
|
||
}
|
||
QString defaultValue = " DEFAULT ";
|
||
bool ok;
|
||
def.toInt(&ok);
|
||
if (ok) {
|
||
return (defaultValue + def);
|
||
}
|
||
if (def == "true" || def == "false") {
|
||
return (defaultValue + def.toUpper());
|
||
}
|
||
QString copy = def.replace(",", ".");
|
||
copy.toDouble(&ok);
|
||
if (ok) {
|
||
return (defaultValue + copy);
|
||
}
|
||
return ("\'" + defaultValue + def + "\'");
|
||
}
|
||
|
||
QString Schema::buildCheckString(QString check) const {
|
||
return check.isEmpty() ? "" : (" CHECK (" + check + ")");
|
||
}
|
||
|
||
QString Schema::lengthToString(int length) const {
|
||
return length != 0 ? QString::number(length) : "";
|
||
}
|
||
|
||
QString Schema::combineScaleAndPrecision(int precision, int scale) const {
|
||
QString length = "";
|
||
if (precision != 0) {
|
||
length += QString::number(precision);
|
||
}
|
||
if (scale != 0) {
|
||
if (precision != 0) {
|
||
length += ", ";
|
||
}
|
||
length += QString::number(scale);
|
||
}
|
||
return length;
|
||
}
|
||
|
||
|
||
QHash<QString, QSharedPointer<TableSchema> > Schema::getTables() const {
|
||
return this->tables;
|
src/schema.h | ||
---|---|---|
const QString TYPE_BOOLEAN = "boolean";
|
||
const QString TYPE_MONEY = "money";
|
||
|
||
// QString primaryKey(int length = 0) const;
|
||
// QString bigPrimaryKey(int length = 0) const;
|
||
// QString string(int length = 0, bool notNull = false,
|
||
// QString defaultValue = "", bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
// QString text(bool notNull = false, QString defaultValue = "",
|
||
// bool unique = false, QString checkConstraint = "") const;
|
||
// QString smallInteger(int length = 0, bool notNull = false,
|
||
// QString defaultValue = "", bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
// QString integer(int length = 0, bool notNull = false,
|
||
// QString defaultValue = "", bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
// QString bigInteger(int length = 0, bool notNull = false,
|
||
// QString defaultValue = "", bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
// QString floatColumn(int precision = 0, bool notNull = false,
|
||
// QString defaultValue = "", bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
// QString doubleColumn(int precision = 0, bool notNull = false,
|
||
// QString defaultValue = "", bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
// QString decimal(int precision = 0, int scale = 0, bool notNull = false,
|
||
// QString defaultValue = "", bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
// QString dateTime(int precision = 0, bool notNull = false,
|
||
// QString defaultValue = "", bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
// QString timestamp(int precision = 0, bool notNull = false,
|
||
// QString defaultValue = "", bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
// QString time(int precision = 0, bool notNull = false,
|
||
// QString defaultValue = "", bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
// QString date( bool notNull = false, QString defaultValue = "") const;
|
||
// QString binary(int length = 0, bool notNull = false, bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
// QString boolean(bool defaultValue = 0) const;
|
||
// QString money(int precision = 0, int scale = 0, bool notNull = false,
|
||
// QString defaultValue = "", bool unique = false,
|
||
// QString checkConstraint = "") const;
|
||
QString primaryKey(int length = 0) const;
|
||
QString bigPrimaryKey(int length = 0) const;
|
||
QString string(int length = 0, bool notNull = false,
|
||
QString defaultValue = "", bool unique = false,
|
||
QString checkConstraint = "") const;
|
||
QString text(bool notNull = false, QString defaultValue = "",
|
||
bool unique = false, QString checkConstraint = "") const;
|
||
QString smallInteger(int length = 0, bool notNull = false,
|
||
QString defaultValue = "", bool unique = false,
|
||
QString checkConstraint = "") const;
|
||
QString integer(int length = 0, bool notNull = false,
|
||
QString defaultValue = "", bool unique = false,
|
||
QString checkConstraint = "") const;
|
||
QString bigInteger(int length = 0, bool notNull = false,
|
||
QString defaultValue = "", bool unique = false,
|
||
QString checkConstraint = "") const;
|
||
QString floatColumn(int precision = 0, bool notNull = false,
|
||
QString defaultValue = "", bool unique = false,
|
||
QString checkConstraint = "") const;
|
||
QString doubleColumn(int precision = 0, bool notNull = false,
|
||
QString defaultValue = "", bool unique = false,
|
||
QString checkConstraint = "") const;
|
||
QString decimal(int precision = 0, int scale = 0, bool notNull = false,
|
||
QString defaultValue = "", bool unique = false,
|
||
QString checkConstraint = "") const;
|
||
QString dateTime(int precision = 0, bool notNull = false,
|
||
QString defaultValue = "", bool unique = false,
|
||
QString checkConstraint = "") const;
|
||
QString timestamp(int precision = 0, bool notNull = false,
|
||
QString defaultValue = "", bool unique = false,
|
||
QString checkConstraint = "") const;
|
||
QString time(int precision = 0, bool notNull = false,
|
||
QString defaultValue = "", bool unique = false,
|
||
QString checkConstraint = "") const;
|
||
QString date( bool notNull = false, QString defaultValue = "") const;
|
||
QString binary(int length = 0, bool notNull = false, bool unique = false,
|
||
QString checkConstraint = "") const;
|
||
QString boolean(QString defaultValue = "", bool notNull = false) const;
|
||
QString money(int precision = 0, int scale = 0, bool notNull = false,
|
||
QString defaultValue = "", bool unique = false,
|
||
QString checkConstraint = "") const;
|
||
|
||
|
||
|
||
... | ... | |
void setAbstractTypeMap(const QSharedPointer<QHash<QString, QString> > &value);
|
||
|
||
protected:
|
||
virtual QString buildColumnSchema(QString type, QString length, bool notNull = false, QString defaultValue = "",
|
||
bool unique = false, QString checkConstraint = "") const;
|
||
virtual QString buildColumnSchema(QString type, QString length,
|
||
bool notNull = false, QString defaultValue = "",
|
||
bool unique = false, QString checkConstraint = "") const;
|
||
virtual QString buildLengthString(QString length) const;
|
||
virtual QString buildNotNullString(bool notNull) const;
|
||
virtual QString buildUniqueString(bool unique) const;
|
||
virtual QString buildDefaultString(QString def) const;
|
||
virtual QString buildCheckString(QString check) const;
|
||
|
||
virtual QString lengthToString(int length) const;
|
||
virtual QString combineScaleAndPrecision(int precision, int scale) const;
|
||
|
||
|
||
virtual QStringList findTableNames(QString schema = "") = 0;
|
Auch abrufbar als: Unified diff
building column schema