Reorganize files in pglablib

The enitities and containers of the catalog now go into catalog subfolder
Models go into model
This commit is contained in:
eelke 2018-12-16 10:17:59 +01:00
parent 56cbeea183
commit f0c1035378
121 changed files with 226 additions and 183 deletions

View file

@ -0,0 +1,56 @@
#include "PgAttribute.h"
#include "QStringBuilder"
#include "SqlFormattingUtils.h"
#include "PgClass.h"
#include "PgDatabaseCatalog.h"
#include "PgTypeContainer.h"
#include "PgCollation.h"
#include "PgCollationContainer.h"
QString PgAttribute::columnDefinition(const PgDatabaseCatalog &cat) const
{
// create: column_name data_type [ COLLATE collation ] [ column_constraint [ ... ]
// alter: column_name data_type [ COLLATE collation ] [ column_constraint [ ... ]
// constraints NULL/NOT NULL, DEFAULT, GENERATED other constraints will be ignored here a
auto&& type = cat.types()->getByKey(typid);
QString sql = quoteIdent(name) % " " % type->objectName();
if (collation != InvalidOid) {
auto&& col = cat.collations()->getByKey(collation);
QString oname = col->objectName();
if (oname != "default")
sql += " COLLATE " % quoteIdent(oname);
}
if (notnull)
sql += " NOT NULL";
if (hasdef)
sql += " DEFAULT " % defaultValue;
if (identity != ' ') {
sql += " GENERATED ";
if (identity == 'a') sql += "ALWAYS";
else if (identity == 'd') sql += "BY DEFAULT";
sql += " AS IDENTITY";
}
// TODO sequence options might be missing
return sql;
}
QString PgAttribute::alterTableAddColumn(const PgDatabaseCatalog &cat, const PgClass &table) const
{
QString sql = "ALTER TABLE " % table.fullyQualifiedQuotedObjectName()
% " ADD COLUMN " % columnDefinition(cat) % ";";
return sql;
}
QString PgAttribute::alterTableDropColumn(const PgDatabaseCatalog &cat, const PgClass &table) const
{
QString sql = "ALTER TABLE " % table.fullyQualifiedQuotedObjectName()
% " DROP COLUMN " % quoteIdent(name) % ";";
return sql;
}