Adds missing types

create_drop_db_gh
gindibay 2023-10-09 15:14:13 +03:00
parent b99674dcf9
commit 7022344870
2 changed files with 31 additions and 17 deletions

View File

@ -35,6 +35,16 @@ handleOption(StringInfo buf, DefElem *option, const struct option_format *opt_fo
bool value = defGetBoolean(option); bool value = defGetBoolean(option);
appendStringInfo(buf, opt_formats[i].format, value ? "true" : "false"); appendStringInfo(buf, opt_formats[i].format, value ? "true" : "false");
} }
else if (strcmp(opt_formats[i].type, "object_id") == 0)
{
Oid value = defGetObjectId(option);
appendStringInfo(buf, opt_formats[i].format, value );
}
else if (strcmp(opt_formats[i].type, "literal_cstr") == 0)
{
char *value = defGetString(option);
appendStringInfo(buf, opt_formats[i].format, quote_literal_cstr(value) );
}
else else
{ {
elog(ERROR, "unrecognized option type: %s", opt_formats[i].type); elog(ERROR, "unrecognized option type: %s", opt_formats[i].type);

View File

@ -30,6 +30,25 @@ static void AppendAlterDatabaseOwnerStmt(StringInfo buf, AlterOwnerStmt *stmt);
static void AppendAlterDatabaseStmt(StringInfo buf, AlterDatabaseStmt *stmt); static void AppendAlterDatabaseStmt(StringInfo buf, AlterDatabaseStmt *stmt);
static void AppendDefElemConnLimit(StringInfo buf, DefElem *def); static void AppendDefElemConnLimit(StringInfo buf, DefElem *def);
const struct option_format create_database_option_formats[] = {
{ "template", " TEMPLATE %s", "string" },
{ "owner", " OWNER %s", "string" },
{ "tablespace", " TABLESPACE %s", "string" },
{ "connection_limit", " CONNECTION LIMIT %d", "integer" },
{ "encoding", " ENCODING %s", "literal_cstr" },
{ "locale", " LOCALE %s", "literal_cstr" },
{ "lc_collate", " LC_COLLATE %s", "literal_cstr" },
{ "lc_ctype", " LC_CTYPE %s", "literal_cstr" },
{ "icu_locale", " ICU_LOCALE %s", "literal_cstr" },
{ "icu_rules", " ICU_RULES %s", "literal_cstr" },
{ "locale_provider", " LOCALE_PROVIDER %s", "literal_cstr" },
{ "is_template", " IS_TEMPLATE %s", "boolean" },
{ "allow_connections", " ALLOW_CONNECTIONS %s", "boolean" },
{ "collation_version", " COLLATION_VERSION %s", "literal_cstr" },
{ "strategy", " STRATEGY %s", "literal_cstr" },
{ "oid", " OID %d", "object_id" },
};
char * char *
DeparseAlterDatabaseOwnerStmt(Node *node) DeparseAlterDatabaseOwnerStmt(Node *node)
{ {
@ -207,22 +226,6 @@ DeparseAlterDatabaseSetStmt(Node *node)
} }
const struct option_format option_formats[] = {
{ "template", " TEMPLATE %s", "string" },
{ "owner", " OWNER %s", "string" },
{ "tablespace", " TABLESPACE %s", "string" },
{ "connection_limit", " CONNECTION LIMIT %d", "integer" },
{ "encoding", " ENCODING %s", "string" },
{ "lc_collate", " LC_COLLATE %s", "string" },
{ "lc_ctype", " LC_CTYPE %s", "string" },
{ "icu_locale", " ICU_LOCALE %s", "string" },
{ "icu_rules", " ICU_RULES %s", "string" },
{ "locale_provider", " LOCALE_PROVIDER %s", "string" },
{ "is_template", " IS_TEMPLATE %s", "boolean" },
{ "allow_connections", " ALLOW_CONNECTIONS %s", "boolean" },
};
static void static void
AppendCreateDatabaseStmt(StringInfo buf, CreatedbStmt *stmt) AppendCreateDatabaseStmt(StringInfo buf, CreatedbStmt *stmt)
{ {
@ -234,7 +237,8 @@ AppendCreateDatabaseStmt(StringInfo buf, CreatedbStmt *stmt)
foreach_ptr(option, stmt->options) foreach_ptr(option, stmt->options)
{ {
handleOption(buf, option, option_formats, lengthof(option_formats)); handleOption(buf, option, create_database_option_formats, lengthof(
create_database_option_formats));
} }
} }