Skip to content

Commit

Permalink
Run astyle
Browse files Browse the repository at this point in the history
  • Loading branch information
Euler Taveira committed Jul 1, 2018
1 parent 98b31f7 commit ce7ee4d
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 63 deletions.
3 changes: 2 additions & 1 deletion src/function.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ getFunctions(PGconn *c, int *n)

logNoise("function: server version: %d", PQserverVersion(c));

if (PQserverVersion(c) >= 90600) /* parallel is new in 9.6 ('u'nsafe is the default) */
/* parallel is new in 9.6 ('u'nsafe is the default) */
if (PQserverVersion(c) >= 90600)
{
res = PQexec(c,
"SELECT p.oid, nspname, proname, proretset, prosrc, pg_get_function_arguments(p.oid) as funcargs, pg_get_function_identity_arguments(p.oid) as funciargs, pg_get_function_result(p.oid) as funcresult, proiswindow, provolatile, proisstrict, prosecdef, proleakproof, array_to_string(proconfig, ',') AS proconfig, proparallel, procost, prorows, (SELECT lanname FROM pg_language WHERE oid = prolang) AS lanname, obj_description(p.oid, 'pg_proc') AS description, pg_get_userbyid(proowner) AS proowner, proacl FROM pg_proc p INNER JOIN pg_namespace n ON (n.oid = p.pronamespace) WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema' AND NOT EXISTS(SELECT 1 FROM pg_depend d WHERE p.oid = d.objid AND d.deptype = 'e') ORDER BY nspname, proname, pg_get_function_identity_arguments(p.oid)");
Expand Down
118 changes: 63 additions & 55 deletions src/quarrel.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,35 +207,62 @@ help(void)
printf(" --ignore-version ignore version check\n");
printf(" -s, --summary print a summary of changes\n");
printf(" -t, --single-transaction execute as a single transaction\n");
printf(" --temp-directory=DIR use as temporary file area (default: \"%s\")\n", (opts.general.tmpdir) ? opts.general.tmpdir : "");
printf(" --temp-directory=DIR use as temporary file area (default: \"%s\")\n",
(opts.general.tmpdir) ? opts.general.tmpdir : "");
printf(" -v, --verbose verbose mode\n");
printf("\nObject options:\n");
printf(" --aggregate=BOOL aggregate (default: %s)\n", (opts.general.aggregate) ? "true" : "false");
printf(" --cast=BOOL cast (default: %s)\n", (opts.general.cast) ? "true" : "false");
printf(" --collation=BOOL collation (default: %s)\n", (opts.general.collation) ? "true" : "false");
printf(" --comment=BOOL comment (default: %s)\n", (opts.general.comment) ? "true" : "false");
printf(" --conversion=BOOL conversion (default: %s)\n", (opts.general.conversion) ? "true" : "false");
printf(" --domain=BOOL domain (default: %s)\n", (opts.general.domain) ? "true" : "false");
printf(" --event-trigger=BOOL event trigger (default: %s)\n", (opts.general.eventtrigger) ? "true" : "false");
printf(" --extension=BOOL extension (default: %s)\n", (opts.general.extension) ? "true" : "false");
printf(" --fdw=BOOL foreign data wrapper (default: %s)\n", (opts.general.fdw) ? "true" : "false");
printf(" --function=BOOL function (default: %s)\n", (opts.general.function) ? "true" : "false");
printf(" --index=BOOL index (default: %s)\n", (opts.general.index) ? "true" : "false");
printf(" --language=BOOL language (default: %s)\n", (opts.general.language) ? "true" : "false");
printf(" --materialized-view=BOOL materialized view (default: %s)\n", (opts.general.matview) ? "true" : "false");
printf(" --operator=BOOL operator (default: %s)\n", (opts.general.operator) ? "true" : "false");
printf(" --owner=BOOL owner (default: %s)\n", (opts.general.owner) ? "true" : "false");
printf(" --privileges=BOOL privileges (default: %s)\n", (opts.general.privileges) ? "true" : "false");
printf(" --rule=BOOL rule (default: %s)\n", (opts.general.rule) ? "true" : "false");
printf(" --schema=BOOL schema (default: %s)\n", (opts.general.schema) ? "true" : "false");
printf(" --security-labels=BOOL security labels (default: %s)\n", (opts.general.securitylabels) ? "true" : "false");
printf(" --sequence=BOOL sequence (default: %s)\n", (opts.general.sequence) ? "true" : "false");
printf(" --statistics=BOOL statistics (default: %s)\n", (opts.general.statistics) ? "true" : "false");
printf(" --table=BOOL table (default: %s)\n", (opts.general.table) ? "true" : "false");
printf(" --text-search=BOOL text search (default: %s)\n", (opts.general.textsearch) ? "true" : "false");
printf(" --trigger=BOOL trigger (default: %s)\n", (opts.general.trigger) ? "true" : "false");
printf(" --type=BOOL type (default: %s)\n", (opts.general.type) ? "true" : "false");
printf(" --view=BOOL view (default: %s)\n", (opts.general.view) ? "true" : "false");
printf(" --aggregate=BOOL aggregate (default: %s)\n",
(opts.general.aggregate) ? "true" : "false");
printf(" --cast=BOOL cast (default: %s)\n",
(opts.general.cast) ? "true" : "false");
printf(" --collation=BOOL collation (default: %s)\n",
(opts.general.collation) ? "true" : "false");
printf(" --comment=BOOL comment (default: %s)\n",
(opts.general.comment) ? "true" : "false");
printf(" --conversion=BOOL conversion (default: %s)\n",
(opts.general.conversion) ? "true" : "false");
printf(" --domain=BOOL domain (default: %s)\n",
(opts.general.domain) ? "true" : "false");
printf(" --event-trigger=BOOL event trigger (default: %s)\n",
(opts.general.eventtrigger) ? "true" : "false");
printf(" --extension=BOOL extension (default: %s)\n",
(opts.general.extension) ? "true" : "false");
printf(" --fdw=BOOL foreign data wrapper (default: %s)\n",
(opts.general.fdw) ? "true" : "false");
printf(" --function=BOOL function (default: %s)\n",
(opts.general.function) ? "true" : "false");
printf(" --index=BOOL index (default: %s)\n",
(opts.general.index) ? "true" : "false");
printf(" --language=BOOL language (default: %s)\n",
(opts.general.language) ? "true" : "false");
printf(" --materialized-view=BOOL materialized view (default: %s)\n",
(opts.general.matview) ? "true" : "false");
printf(" --operator=BOOL operator (default: %s)\n",
(opts.general.operator) ? "true" : "false");
printf(" --owner=BOOL owner (default: %s)\n",
(opts.general.owner) ? "true" : "false");
printf(" --privileges=BOOL privileges (default: %s)\n",
(opts.general.privileges) ? "true" : "false");
printf(" --rule=BOOL rule (default: %s)\n",
(opts.general.rule) ? "true" : "false");
printf(" --schema=BOOL schema (default: %s)\n",
(opts.general.schema) ? "true" : "false");
printf(" --security-labels=BOOL security labels (default: %s)\n",
(opts.general.securitylabels) ? "true" : "false");
printf(" --sequence=BOOL sequence (default: %s)\n",
(opts.general.sequence) ? "true" : "false");
printf(" --statistics=BOOL statistics (default: %s)\n",
(opts.general.statistics) ? "true" : "false");
printf(" --table=BOOL table (default: %s)\n",
(opts.general.table) ? "true" : "false");
printf(" --text-search=BOOL text search (default: %s)\n",
(opts.general.textsearch) ? "true" : "false");
printf(" --trigger=BOOL trigger (default: %s)\n",
(opts.general.trigger) ? "true" : "false");
printf(" --type=BOOL type (default: %s)\n",
(opts.general.type) ? "true" : "false");
printf(" --view=BOOL view (default: %s)\n",
(opts.general.view) ? "true" : "false");
printf("\nSource options:\n");
printf(" --source-dbname=DBNAME database name\n");
printf(" --source-host=HOSTNAME server host or socket directory\n");
Expand Down Expand Up @@ -392,12 +419,14 @@ loadConfig(const char *cf, QuarrelOptions *options)
"general", "privileges"));

if (mini_file_get_value(config, "general", "ignore-version") != NULL)
options->general.ignoreversion = parseBoolean("ignore-version", mini_file_get_value(config,
"general", "ignore-version"));
options->general.ignoreversion = parseBoolean("ignore-version",
mini_file_get_value(config,
"general", "ignore-version"));

if (mini_file_get_value(config, "general", "single-transaction") != NULL)
options->general.singletxn = parseBoolean("single-transaction", mini_file_get_value(config,
"general", "single-transaction"));
options->general.singletxn = parseBoolean("single-transaction",
mini_file_get_value(config,
"general", "single-transaction"));

/*
* select objects that will be compared
Expand Down Expand Up @@ -501,9 +530,7 @@ loadConfig(const char *cf, QuarrelOptions *options)
/* source options */
tmp = mini_file_get_value(config, "source", "host");
if (tmp != NULL)
{
options->source.host = strdup(tmp);
}
else
{
tmp = mini_file_get_value(config, "to", "host");
Expand All @@ -513,9 +540,7 @@ loadConfig(const char *cf, QuarrelOptions *options)

tmp = mini_file_get_value(config, "source", "port");
if (tmp != NULL)
{
options->source.port = strdup(tmp);
}
else
{
tmp = mini_file_get_value(config, "to", "port");
Expand All @@ -525,9 +550,7 @@ loadConfig(const char *cf, QuarrelOptions *options)

tmp = mini_file_get_value(config, "source", "user");
if (tmp != NULL)
{
options->source.username = strdup(tmp);
}
else
{
tmp = mini_file_get_value(config, "to", "user");
Expand All @@ -537,9 +560,7 @@ loadConfig(const char *cf, QuarrelOptions *options)

tmp = mini_file_get_value(config, "source", "password");
if (tmp != NULL)
{
options->source.password = strdup(tmp);
}
else
{
tmp = mini_file_get_value(config, "to", "password");
Expand All @@ -549,9 +570,7 @@ loadConfig(const char *cf, QuarrelOptions *options)

tmp = mini_file_get_value(config, "source", "dbname");
if (tmp != NULL)
{
options->source.dbname = strdup(tmp);
}
else
{
tmp = mini_file_get_value(config, "to", "dbname");
Expand All @@ -563,9 +582,7 @@ loadConfig(const char *cf, QuarrelOptions *options)
/* target options */
tmp = mini_file_get_value(config, "target", "host");
if (tmp != NULL)
{
options->target.host = strdup(tmp);
}
else
{
tmp = mini_file_get_value(config, "from", "host");
Expand All @@ -575,9 +592,7 @@ loadConfig(const char *cf, QuarrelOptions *options)

tmp = mini_file_get_value(config, "target", "port");
if (tmp != NULL)
{
options->target.port = strdup(tmp);
}
else
{
tmp = mini_file_get_value(config, "from", "port");
Expand All @@ -587,9 +602,7 @@ loadConfig(const char *cf, QuarrelOptions *options)

tmp = mini_file_get_value(config, "target", "user");
if (tmp != NULL)
{
options->target.username = strdup(tmp);
}
else
{
tmp = mini_file_get_value(config, "from", "user");
Expand All @@ -599,9 +612,7 @@ loadConfig(const char *cf, QuarrelOptions *options)

tmp = mini_file_get_value(config, "target", "password");
if (tmp != NULL)
{
options->target.password = strdup(tmp);
}
else
{
tmp = mini_file_get_value(config, "from", "password");
Expand All @@ -611,9 +622,7 @@ loadConfig(const char *cf, QuarrelOptions *options)

tmp = mini_file_get_value(config, "target", "dbname");
if (tmp != NULL)
{
options->target.dbname = strdup(tmp);
}
else
{
tmp = mini_file_get_value(config, "from", "dbname");
Expand Down Expand Up @@ -4179,8 +4188,9 @@ int main(int argc, char *argv[])
* old pgquarrel version or a to-be-released postgres version. If you know
* what you are doing, use --ignore-version option.
*/
if (!options.ignoreversion && ((compareMajorVersion(pgversion1, PG_VERSION_NUM) > 0) ||
(compareMajorVersion(pgversion2, PG_VERSION_NUM) > 0)))
if (!options.ignoreversion &&
((compareMajorVersion(pgversion1, PG_VERSION_NUM) > 0) ||
(compareMajorVersion(pgversion2, PG_VERSION_NUM) > 0)))
{
logError("cannot connect to server whose version (%s) is greater than postgres version (%s) used to compile pgquarrel",
(pgversion1 > pgversion2) ? PQparameterStatus(conn1,
Expand Down Expand Up @@ -4210,9 +4220,7 @@ int main(int argc, char *argv[])
}
}
else
{
fout = stdout;
}

/* temporary files are used to put commands in the right dependency order */
snprintf(prepath, PGQMAXPATH, "%s/quarrel.%d.pre", options.tmpdir, getpid());
Expand Down
21 changes: 14 additions & 7 deletions src/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,17 @@ getTables(PGconn *c, int *n)

t[i].partitioned = (PQgetvalue(res, i, PQfnumber(res, "relkind"))[0] == 'p');
if (t[i].partitioned)
t[i].partitionkey = strdup(PQgetvalue(res, i, PQfnumber(res, "partitionkeydef")));
t[i].partitionkey = strdup(PQgetvalue(res, i, PQfnumber(res,
"partitionkeydef")));
else
t[i].partitionkey = NULL;

t[i].partition = (PQgetvalue(res, i, PQfnumber(res, "relispartition"))[0] == 't');
t[i].partition = (PQgetvalue(res, i, PQfnumber(res,
"relispartition"))[0] == 't');
if (t[i].partition)
{
t[i].partitionbound = strdup(PQgetvalue(res, i, PQfnumber(res, "partitionbound")));
t[i].partitionbound = strdup(PQgetvalue(res, i, PQfnumber(res,
"partitionbound")));
getParentTables(c, &t[i]);
}
else
Expand Down Expand Up @@ -1719,7 +1722,8 @@ dumpAttachPartition(FILE *output, PQLTable *a)
char *parentname = formatObjectIdentifier(a->parent[0].objectname);

fprintf(output, "\n\n");
fprintf(output, "ALTER TABLE %s.%s ATTACH PARTITION %s.%s %s;", parentschema, parentname, schema, tabname, a->partitionbound);
fprintf(output, "ALTER TABLE %s.%s ATTACH PARTITION %s.%s %s;", parentschema,
parentname, schema, tabname, a->partitionbound);

free(schema);
free(tabname);
Expand All @@ -1736,7 +1740,8 @@ dumpDetachPartition(FILE *output, PQLTable *a)
char *parentname = formatObjectIdentifier(a->parent[0].objectname);

fprintf(output, "\n\n");
fprintf(output, "ALTER TABLE %s.%s DETACH PARTITION %s.%s;", parentschema, parentname, schema, tabname);
fprintf(output, "ALTER TABLE %s.%s DETACH PARTITION %s.%s;", parentschema,
parentname, schema, tabname);

free(schema);
free(tabname);
Expand Down Expand Up @@ -1889,9 +1894,11 @@ dumpAlterTable(FILE *output, PQLTable *a, PQLTable *b)

/* partitioned table cannot be converted to regular table and vice-versa */
if (a->partitioned && !b->partitioned)
logWarning("regular table %s.%s cannot be converted to partitioned table", schema2, tabname2);
logWarning("regular table %s.%s cannot be converted to partitioned table",
schema2, tabname2);
else if (!a->partitioned && b->partitioned)
logWarning("partitioned table %s.%s cannot be converted to regular table", schema2, tabname2);
logWarning("partitioned table %s.%s cannot be converted to regular table",
schema2, tabname2);

/* partition */
if (!a->partition && b->partition)
Expand Down

0 comments on commit ce7ee4d

Please sign in to comment.