WIP: SQL for creating table and related objects
This commit is contained in:
parent
57217974f4
commit
498233d58c
15 changed files with 221 additions and 121 deletions
|
|
@ -261,7 +261,7 @@ QString dollarQuoteString(const QString &value)
|
|||
// return ns->quotedObjectName() % "." % cls.quotedObjectName();
|
||||
//}
|
||||
|
||||
QString genAlterTable(const PgDatabaseCatalog &catalog, const PgClass &cls)
|
||||
QString genAlterTable(const PgDatabaseCatalog &, const PgClass &cls)
|
||||
{
|
||||
return "ALTER TABLE " % cls.fullyQualifiedQuotedObjectName(); // genFQTableName(catalog, cls);
|
||||
}
|
||||
|
|
@ -269,7 +269,7 @@ QString genAlterTable(const PgDatabaseCatalog &catalog, const PgClass &cls)
|
|||
QString getDropConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstraint &constraint)
|
||||
{
|
||||
const PgClass *cls = catalog.classes()->getByKey(constraint.relid);
|
||||
return genAlterTable(catalog, *cls) % " DROP CONSTRAINT " % quoteIdent(constraint.name) % ";";
|
||||
return genAlterTable(catalog, *cls) % " DROP CONSTRAINT " % quoteIdent(constraint.objectName()) % ";";
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -368,7 +368,7 @@ QString getForeignKeyConstraintReferencesShort(const PgDatabaseCatalog &catalog,
|
|||
QString getPrimaryKeyConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstraint &constraint)
|
||||
{
|
||||
QString ddl = " PRIMARY KEY ("
|
||||
% getColumnNameList(catalog, constraint.relid, constraint.key) % ");";
|
||||
% getColumnNameList(catalog, constraint.relid, constraint.key) % ")";
|
||||
|
||||
return ddl;
|
||||
}
|
||||
|
|
@ -376,18 +376,22 @@ QString getPrimaryKeyConstraintDefinition(const PgDatabaseCatalog &catalog, cons
|
|||
QString getUniqueConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstraint &constraint)
|
||||
{
|
||||
QString ddl = " UNIQUE ("
|
||||
% getColumnNameList(catalog, constraint.relid, constraint.key) % ");";
|
||||
% getColumnNameList(catalog, constraint.relid, constraint.key) % ")";
|
||||
|
||||
return ddl;
|
||||
}
|
||||
|
||||
QString getConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstraint &constraint)
|
||||
QString getAlterTableConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstraint &constraint)
|
||||
{
|
||||
const PgClass *cls = catalog.classes()->getByKey(constraint.relid);
|
||||
// return genAlterTable(catalog, cls) % " ADD CONSTRAINT "
|
||||
// % quoteIdent(constraint.name) % " " % constraint.definition % ";";
|
||||
QString result = genAlterTable(catalog, *cls) % "\n ADD CONSTRAINT "
|
||||
% quoteIdent(constraint.name);
|
||||
QString result = genAlterTable(catalog, *cls) % "\n ADD ";
|
||||
result += getConstraintDefinition(catalog, constraint) % ";";
|
||||
return result;
|
||||
}
|
||||
|
||||
QString getConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstraint &constraint)
|
||||
{
|
||||
QString result = "CONSTRAINT " % quoteIdent(constraint.objectName());
|
||||
switch (constraint.type) {
|
||||
case ConstraintType::ForeignKey:
|
||||
result += getForeignKeyConstraintDefinition(catalog, constraint);
|
||||
|
|
@ -406,66 +410,4 @@ QString getConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstr
|
|||
return result;
|
||||
}
|
||||
|
||||
QString getIndexDefinition(const PgDatabaseCatalog &, const PgIndex &index)
|
||||
{
|
||||
// const PgClass *table_class = catalog.classes()->getByKey(index.relid);
|
||||
// const PgClass *index_class = catalog.classes()->getByKey(index.indexrelid);
|
||||
|
||||
|
||||
return index.definition + ";";
|
||||
|
||||
// QString result;
|
||||
// result = "CREATE ";
|
||||
// if (index.isunique)
|
||||
// result += "UNIQUE ";
|
||||
// result += "INDEX "
|
||||
//// % quoteIdent(getIndexDisplayString(catalog, index.indexrelid))
|
||||
// % quoteIdent(index_class.name)
|
||||
// % "\n ON " % genFQTableName(catalog, table_class);
|
||||
//// % "\n USING " % index_class.am lookup in pg_am table
|
||||
// return result;
|
||||
|
||||
#if 0
|
||||
+ wxT("\n USING ") + GetIndexType()
|
||||
+ wxT("\n (");
|
||||
if (GetProcName().IsNull())
|
||||
str += GetQuotedColumns();
|
||||
else
|
||||
{
|
||||
str += GetQuotedSchemaPrefix(GetProcNamespace()) + qtIdent(GetProcName()) + wxT("(") + GetQuotedColumns() + wxT(")");
|
||||
if (!this->GetOperatorClasses().IsNull())
|
||||
str += wxT(" ") + GetOperatorClasses();
|
||||
}
|
||||
|
||||
str += wxT(")");
|
||||
|
||||
if (GetConnection()->BackendMinimumVersion(8, 2) && GetFillFactor().Length() > 0)
|
||||
str += wxT("\n WITH (FILLFACTOR=") + GetFillFactor() + wxT(")");
|
||||
|
||||
if (GetConnection()->BackendMinimumVersion(8, 0) && tablespace != GetDatabase()->GetDefaultTablespace())
|
||||
str += wxT("\nTABLESPACE ") + qtIdent(tablespace);
|
||||
|
||||
AppendIfFilled(str, wxT("\n WHERE "), GetConstraint());
|
||||
|
||||
str += wxT(";\n");
|
||||
|
||||
if (GetConnection()->BackendMinimumVersion(7, 5))
|
||||
if (GetIsClustered())
|
||||
str += wxT("ALTER TABLE ") + GetQuotedSchemaPrefix(GetIdxSchema()) + qtIdent(GetIdxTable())
|
||||
+ wxT(" CLUSTER ON ") + qtIdent(GetName())
|
||||
+ wxT(";\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
QString getDropIndexDefinition(const PgDatabaseCatalog &catalog, const PgIndex &index)
|
||||
{
|
||||
// const PgClass *table_class = catalog.classes()->getByKey(index.relid);
|
||||
// const PgClass *index_class = catalog.classes()->getByKey(index.indexrelid);
|
||||
|
||||
QString result;
|
||||
result = "DROP INDEX "
|
||||
% index.fullyQualifiedQuotedObjectName() // quoteIdent(getIndexDisplayString(catalog, index.indexrelid))
|
||||
% ";";
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue