Skip to content

Commit

Permalink
Update hook function and add schedule
Browse files Browse the repository at this point in the history
Signed-off-by: Chenxiao Wang <[email protected]>
  • Loading branch information
Chenxiao Wang committed Dec 20, 2024
1 parent f525d88 commit 12af309
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
46 changes: 25 additions & 21 deletions contrib/babelfishpg_tsql/src/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -5881,33 +5881,37 @@ is_bbf_db_ddladmin_operation(Oid namespaceId)
static const char *
remove_db_name_in_schema(const char *object_name)
{
const char *cur_db_name;
char *cur_db_name;
char **splited_object_name;
char *schema_name = NULL;
char *mutable_name;
size_t db_name_len;
size_t prefix_len;
size_t schema_name_len;
size_t db_name_len;
size_t prefix_len;
size_t schema_name_len;

mutable_name = strdup(object_name);
mutable_name = pstrdup(object_name);
splited_object_name = split_object_name(mutable_name);
for (int i = 0; i < 4; i++)
{
if (strcmp(splited_object_name[i], "")) {
schema_name = splited_object_name[i];
break;
}
}

cur_db_name = get_cur_db_name();
db_name_len = strlen(cur_db_name);
schema_name_len = schema_name ? strlen(schema_name) : 0;
prefix_len = db_name_len + 1;

if (schema_name != NULL && schema_name_len > db_name_len && strncmp(schema_name, cur_db_name, db_name_len) == 0 && schema_name[db_name_len] == '_') {
object_name += prefix_len;
}
// If there are more than two parts, then it’s a cross-db object name (db.schema.object) so we don’t need to deal with it
if (strlen(splited_object_name[1]) == 0)
{
schema_name = strlen(splited_object_name[2]) == 0 ? splited_object_name[3] : splited_object_name[2];
cur_db_name = get_cur_db_name();
db_name_len = strlen(cur_db_name);
schema_name_len = strlen(schema_name);
prefix_len = db_name_len + 1;

if (schema_name != NULL && schema_name_len > db_name_len && strncmp(schema_name, cur_db_name, db_name_len) == 0 && schema_name[db_name_len] == '_') {
// Return the part after the prefix
object_name += prefix_len;
}
pfree(cur_db_name);
}

free(mutable_name);
pfree(mutable_name);
for (int k = 0; k < 4; k++)
pfree(splited_object_name[k]);
pfree(splited_object_name);

return object_name;
}
1 change: 1 addition & 0 deletions test/JDBC/upgrade/latest/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,4 @@ cast_nvarchar_test
smalldatetime_date_cmp
datareader_datawriter
db_owner
BABEL-2961

0 comments on commit 12af309

Please sign in to comment.