Skip to content

Commit

Permalink
[CBRD-24849] Synonyms related to classes are also extracted when unlo…
Browse files Browse the repository at this point in the history
…addb is performed using -i and --input-class-only. (#4574)

http://jira.cubrid.org/browse/CBRD-24849

When unloaddb was performed using -i and --input-class-only, synonym data related to class was extract
  • Loading branch information
airnet73 authored Aug 9, 2023
1 parent cad9ca3 commit dda2520
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions src/executables/unload_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ static int emit_foreign_key (print_output & output_ctx, DB_OBJLIST * classes);
static int create_filename (const char *output_dirname, const char *output_prefix, const char *suffix,
char *output_filename_p, const size_t filename_size);
static int export_server (print_output & output_ctx);
static void str_tolower (char *str);
/*
* CLASS DEPENDENCY ORDERING
*
Expand Down Expand Up @@ -834,7 +835,7 @@ export_serial (print_output & output_ctx)
* output_ctx(in/out): output context
*/
static int
export_synonym (print_output & output_ctx)
export_synonym (extract_context & ctxt, print_output & output_ctx)
{
DB_QUERY_RESULT *query_result;
DB_QUERY_ERROR query_error;
Expand All @@ -850,6 +851,9 @@ export_synonym (print_output & output_ctx)
int i = 0;
int save = 0;
int error = NO_ERROR;
DB_OBJLIST *cl = NULL;
const char *name = NULL;
char temp_schema[DB_MAX_CLASS_LENGTH] = { '\0' };

// *INDENT-OFF*
const char *query = "SELECT [name], "
Expand Down Expand Up @@ -955,6 +959,28 @@ export_synonym (print_output & output_ctx)
continue;
}

if (required_class_only == true)
{
int same_schema = 0;
for (cl = ctxt.classes; cl != NULL; cl = cl->next)
{
name = db_get_class_name (cl->op);

str_tolower ((char *) target_owner_name);
snprintf (temp_schema, DB_MAX_CLASS_LENGTH, "%s%s%s", (target_owner_name), ".", target_name);

if (strcmp (temp_schema, name) == 0)
{
same_schema++;
}
}

if (same_schema == 0)
{
continue;
}
}

if (is_public == 1)
{
output_ctx ("CREATE PUBLIC");
Expand Down Expand Up @@ -1081,7 +1107,7 @@ extract_classes (extract_context & ctxt, print_output & schema_output_ctx)
* Since a synonym is like an alias, it can be created even if the target does not exist.
* So, unload the synonym before class/vclass.
*/
if (required_class_only == false && export_synonym (schema_output_ctx) < 0)
if (export_synonym (ctxt, schema_output_ctx) < 0)
{
fprintf (stderr, "%s", db_error_string (3));
if (db_error_code () == ER_SYNONYM_INVALID_VALUE)
Expand Down Expand Up @@ -3939,3 +3965,18 @@ create_filename (const char *output_dirname, const char *output_prefix, const ch

return 0;
}

static void
str_tolower (char *str)
{
char *p;

if (str == NULL)
return;

for (p = str; *p; p++)
{
if (*p >= 'A' && *p <= 'Z')
*p = *p - 'A' + 'a';
}
}

0 comments on commit dda2520

Please sign in to comment.