refactor table sql generation
This commit is contained in:
parent
3158a4364b
commit
14b5293dea
2 changed files with 40 additions and 24 deletions
|
|
@ -127,7 +127,8 @@ QString PgClass::createTableSql() const
|
||||||
{
|
{
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
else sql += ",\n ";
|
else
|
||||||
|
sql += ",\n ";
|
||||||
if (!col.islocal) sql += "-- ";
|
if (!col.islocal) sql += "-- ";
|
||||||
sql += col.columnDefinition(catalog());
|
sql += col.columnDefinition(catalog());
|
||||||
}
|
}
|
||||||
|
|
@ -143,37 +144,49 @@ QString PgClass::createTableSql() const
|
||||||
sql += "\n ";
|
sql += "\n ";
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
else sql += ",\n ";
|
else
|
||||||
|
sql += ",\n ";
|
||||||
sql += getConstraintDefinition(catalog(), constraint, " ");
|
sql += getConstraintDefinition(catalog(), constraint, " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
sql += "\n)";
|
sql += "\n)"
|
||||||
{
|
% generateInheritsSql()
|
||||||
// [ INHERITS ( parent_table [, ... ] ) ]
|
// [ PARTITION BY { RANGE | LIST } ( { column_name | ( expression ) } [ COLLATE collation ] [ opclass ] [, ... ] ) ]
|
||||||
auto parents = catalog().inherits()->getParentsOf(oid());
|
// [ WITH ( storage_parameter [= value] [, ... ] ) | WITH OIDS | WITHOUT OIDS ]
|
||||||
if (!parents.empty())
|
// [ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
|
||||||
|
% generateTablespaceSql()
|
||||||
|
% ";\n";
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString PgClass::generateInheritsSql() const
|
||||||
|
{
|
||||||
|
QString sql;
|
||||||
|
// [ INHERITS ( parent_table [, ... ] ) ]
|
||||||
|
auto parents = catalog().inherits()->getParentsOf(oid());
|
||||||
|
if (!parents.empty())
|
||||||
|
{
|
||||||
|
sql += "\nINHERITS (";
|
||||||
|
bool first = true;
|
||||||
|
for (auto parent_oid : parents)
|
||||||
{
|
{
|
||||||
sql += "\nINHERITS (";
|
if (first) first = false;
|
||||||
bool first = true;
|
else sql += ", ";
|
||||||
for (auto parent_oid : parents)
|
sql += catalog().classes()->getByKey(parent_oid)->fullyQualifiedQuotedObjectName();
|
||||||
{
|
}
|
||||||
if (first) first = false;
|
sql += ")";
|
||||||
else sql += ", ";
|
}
|
||||||
sql += catalog().classes()->getByKey(parent_oid)->fullyQualifiedQuotedObjectName();
|
return sql;
|
||||||
}
|
}
|
||||||
sql += ")";
|
|
||||||
}
|
QString PgClass::generateTablespaceSql() const
|
||||||
}
|
{
|
||||||
// [ PARTITION BY { RANGE | LIST } ( { column_name | ( expression ) } [ COLLATE collation ] [ opclass ] [, ... ] ) ]
|
|
||||||
// [ WITH ( storage_parameter [= value] [, ... ] ) | WITH OIDS | WITHOUT OIDS ]
|
|
||||||
// [ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
|
|
||||||
if (tablespace != 0)
|
if (tablespace != 0)
|
||||||
{
|
{
|
||||||
auto ns = getTablespaceDisplayString(catalog(), tablespace);
|
auto ns = getTablespaceDisplayString(catalog(), tablespace);
|
||||||
sql += "\n TABLESPACE " % quoteIdent(ns);
|
return "\n TABLESPACE " % quoteIdent(ns);
|
||||||
}
|
}
|
||||||
sql += ";\n";
|
return {};
|
||||||
return sql;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PgClass::createViewSql() const
|
QString PgClass::createViewSql() const
|
||||||
|
|
@ -192,3 +205,4 @@ QString PgClass::createViewSql() const
|
||||||
return sql;
|
return sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,8 @@ private:
|
||||||
mutable QString createSqlCache;
|
mutable QString createSqlCache;
|
||||||
|
|
||||||
QString createTableSql() const;
|
QString createTableSql() const;
|
||||||
|
QString generateInheritsSql() const;
|
||||||
|
QString generateTablespaceSql() const;
|
||||||
QString createViewSql() const;
|
QString createViewSql() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue