Skip to content

Commit 4418f9e

Browse files
author
anju15bharti
committed
fix failures
1 parent a698d70 commit 4418f9e

137 files changed

Lines changed: 29798 additions & 587 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,8 +1250,14 @@ PrepareRowDescription(TupleDesc typeinfo, PlannedStmt *plannedstmt, List *target
12501250
* Use tle->resname if available and longer than attname,
12511251
* since attname is limited to NAMEDATALEN-1 (63 chars).
12521252
*/
1253-
if (tle->resname && strlen(tle->resname) > strlen(NameStr(att->attname)))
1253+
if (tle->resname && strlen(tle->resname) > strlen(NameStr(att->attname))
1254+
&& pg_verifymbstr(tle->resname, strlen(tle->resname), true))
12541255
appendStringInfoString(&col->colName, tle->resname);
1256+
else if (tle->resname && strlen(tle->resname) > strlen(NameStr(att->attname)))
1257+
{
1258+
elog(WARNING, "invalid UTF8 in tle->resname for column %d, falling back to attname", attno + 1);
1259+
appendStringInfoString(&col->colName, NameStr(att->attname));
1260+
}
12551261
else
12561262
{
12571263
appendStringInfoString(&col->colName, NameStr(att->attname));

contrib/babelfishpg_tsql/sql/babelfishpg_tsql.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3299,7 +3299,7 @@ BEGIN
32993299
DECLARE @physical_schema_name sys.nvarchar(776) = '';
33003300
SELECT @physical_schema_name = nspname FROM sys.babelfish_namespace_ext WHERE dbid = sys.db_id() AND orig_name = @schemaname;
33013301
SELECT @curr_relname = relname FROM pg_catalog.pg_trigger tr LEFT JOIN pg_catalog.pg_class c ON tr.tgrelid = c.oid LEFT JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
3302-
WHERE tr.tgname = @subname AND n.nspname = @physical_schema_name;
3302+
WHERE tr.tgname = sys.babelfish_truncate_identifier(pg_catalog.lower(@subname)) AND n.nspname = @physical_schema_name;
33033303
END
33043304
END
33053305
ELSE

contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--6.1.0--6.2.0.sql

Lines changed: 2001 additions & 23 deletions
Large diffs are not rendered by default.

contrib/babelfishpg_tsql/src/catalog.c

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -446,19 +446,10 @@ bbf_rewrite_truncated_identifiers(const char *msg)
446446
const char *found;
447447
const char *search_msg = result ? result : msg;
448448

449+
/* Replace all occurrences of this key in the message */
449450
found = strstr(search_msg, key);
450-
if (found)
451+
while (found)
451452
{
452-
/*
453-
* Only replace if the match is a complete identifier — i.e. the
454-
* character immediately after the match is not an identifier char.
455-
* This prevents partial replacement inside compound names like
456-
* construct_unique_index_name results.
457-
*/
458-
char after = found[key_len];
459-
if (after != '\0' && (isalnum((unsigned char) after) || after == '_'))
460-
continue;
461-
462453
{
463454
int prefix_len = found - search_msg;
464455
int orig_len = strlen(entry->original_name);
@@ -468,7 +459,9 @@ bbf_rewrite_truncated_identifiers(const char *msg)
468459
memcpy(newmsg, search_msg, prefix_len);
469460
memcpy(newmsg + prefix_len, entry->original_name, orig_len);
470461
memcpy(newmsg + prefix_len + orig_len, found + key_len, suffix_len + 1);
462+
search_msg = newmsg;
471463
result = newmsg;
464+
found = strstr(search_msg + prefix_len + orig_len, key);
472465
}
473466
}
474467
}
@@ -3160,9 +3153,9 @@ get_name_db_owner(HeapTuple tuple, TupleDesc dsc)
31603153
char *name_str = text_to_cstring(name);
31613154
char *name_db_owner = palloc0(MAX_BBF_NAMEDATALEND);
31623155

3163-
truncate_identifier(name_str, strlen(name_str), false);
3156+
truncate_tsql_identifier(name_str);
31643157
snprintf(name_db_owner, MAX_BBF_NAMEDATALEND, "%s_db_owner", name_str);
3165-
truncate_identifier(name_db_owner, strlen(name_db_owner), false);
3158+
truncate_tsql_identifier(name_db_owner);
31663159
return CStringGetDatum(name_db_owner);
31673160
}
31683161

@@ -3174,9 +3167,9 @@ get_name_dbo(HeapTuple tuple, TupleDesc dsc)
31743167
char *name_str = text_to_cstring(name);
31753168
char *name_dbo = palloc0(MAX_BBF_NAMEDATALEND);
31763169

3177-
truncate_identifier(name_str, strlen(name_str), false);
3170+
truncate_tsql_identifier(name_str);
31783171
snprintf(name_dbo, MAX_BBF_NAMEDATALEND, "%s_dbo", name_str);
3179-
truncate_identifier(name_dbo, strlen(name_dbo), false);
3172+
truncate_tsql_identifier(name_dbo);
31803173
return CStringGetDatum(name_dbo);
31813174
}
31823175

@@ -3188,9 +3181,9 @@ get_name_guest(HeapTuple tuple, TupleDesc dsc)
31883181
char *name_str = text_to_cstring(name);
31893182
char *name_dbo = palloc0(MAX_BBF_NAMEDATALEND);
31903183

3191-
truncate_identifier(name_str, strlen(name_str), false);
3184+
truncate_tsql_identifier(name_str);
31923185
snprintf(name_dbo, MAX_BBF_NAMEDATALEND, "%s_guest", name_str);
3193-
truncate_identifier(name_dbo, strlen(name_dbo), false);
3186+
truncate_tsql_identifier(name_dbo);
31943187
return CStringGetDatum(name_dbo);
31953188
}
31963189

@@ -5444,7 +5437,9 @@ update_sysdatabases_db_name(const char *old_db_name, const char *new_db_name)
54445437

54455438
/* Set up the new database. */
54465439
values[Anum_sysdatabases_name - 1] = CStringGetTextDatum(new_db_name);
5447-
replaces[Anum_sysdatabases_name - 1] = true;
5440+
replaces[Anum_sysdatabases_name - 1] = true;
5441+
values[Anum_sysdatabases_orig_name - 1] = CStringGetTextDatum(new_db_name);
5442+
replaces[Anum_sysdatabases_orig_name - 1] = true;
54485443

54495444
tuple = heap_modify_tuple(db_found,
54505445
sysdatabases_rel_descr,

contrib/babelfishpg_tsql/src/hooks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ pltsql_bbfCustomProcessUtility(ParseState *pstate, PlannedStmt *pstmt, const cha
851851
}
852852
case T_AlterTableStmt:
853853
{
854-
if (sql_dialect != SQL_DIALECT_TSQL && !IsBinaryUpgrade)
854+
if (sql_dialect != SQL_DIALECT_TSQL && !IsBinaryUpgrade && !babelfish_dump_restore)
855855
{
856856
AlterTableStmt *atstmt = (AlterTableStmt *) parsetree;
857857
ListCell *lcmd;

contrib/babelfishpg_tsql/src/multidb.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,10 +1269,9 @@ get_physical_schema_name_by_mode(char *db_name, const char *schema_name, Migrati
12691269
/* Cache for error messages - with and without db prefix */
12701270
{
12711271
const char *orig = bbf_lookup_ident_name(name);
1272-
const char *val = orig ? orig : name;
1273-
/* Cache with full physical name */
1272+
const char *val = orig ? orig : schema_name;
12741273
bbf_cache_ident_name(result, val);
1275-
/* Cache without db prefix (what PG shows in errors) */
1274+
/* Also cache without db prefix for PG errors that strip it */
12761275
{
12771276
int db_len = strlen(db_name);
12781277
if (strncmp(result, db_name, db_len) == 0 && result[db_len] == '_')
@@ -1356,11 +1355,6 @@ get_physical_user_name(char *db_name, char *user_name, bool suppress_db_error, b
13561355
const char *orig = bbf_lookup_ident_name(new_user_name);
13571356
const char *val = orig ? orig : user_name;
13581357
bbf_cache_ident_name(result, val);
1359-
{
1360-
int db_len = strlen(db_name);
1361-
if (strncmp(result, db_name, db_len) == 0 && result[db_len] == '_')
1362-
bbf_cache_ident_name(result + db_len + 1, val);
1363-
}
13641358
}
13651359

13661360
/*

contrib/babelfishpg_tsql/src/pl_handler.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8726,13 +8726,34 @@ void pltsql_bbfSelectIntoUtility(ParseState *pstate, PlannedStmt *pstmt, const c
87268726
*/
87278727
Query *query = castNode(Query, ((CreateTableAsStmt *)parsetree)->query);
87288728
ListCell *tlc;
8729+
List *saved_resnames = NIL;
8730+
8731+
/* Save original resnames and truncate for table creation */
87298732
foreach(tlc, query->targetList)
87308733
{
87318734
TargetEntry *tle = (TargetEntry *) lfirst(tlc);
8735+
saved_resnames = lappend(saved_resnames, tle->resname);
87328736
if (tle->resname && strlen(tle->resname) >= NAMEDATALEN)
87338737
tle->resname = downcase_truncate_identifier(tle->resname, strlen(tle->resname), false);
87348738
}
8735-
*address = ExecCreateTableAs(pstate, (CreateTableAsStmt *)parsetree, params, queryEnv, qc);
8739+
8740+
PG_TRY();
8741+
{
8742+
*address = ExecCreateTableAs(pstate, (CreateTableAsStmt *)parsetree, params, queryEnv, qc);
8743+
}
8744+
PG_CATCH();
8745+
{
8746+
/* Restore original resnames on failure */
8747+
ListCell *slc = list_head(saved_resnames);
8748+
foreach(tlc, query->targetList)
8749+
{
8750+
TargetEntry *tle = (TargetEntry *) lfirst(tlc);
8751+
tle->resname = (char *) lfirst(slc);
8752+
slc = lnext(saved_resnames, slc);
8753+
}
8754+
PG_RE_THROW();
8755+
}
8756+
PG_END_TRY();
87368757
}
87378758
else
87388759
{

contrib/babelfishpg_tsql/src/procedures.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4108,6 +4108,7 @@ gen_sp_rename_subcmds(const char *objname, const char *newname, const char *sche
41084108
else if ((objtype == OBJECT_TRIGGER))
41094109
{
41104110
ObjectWithArgs *objwargs;
4111+
orig_proc_funcname = pstrdup(newname);
41114112
renamestmt->renameType = objtype;
41124113
renamestmt->relation->schemaname = pstrdup(str_tolower(schemaname, strlen(schemaname), DEFAULT_COLLATION_OID));
41134114
renamestmt->relation->relname = downcase_truncate_identifier(curr_relname, strlen(curr_relname), false);

test/JDBC/expected/BABEL-4231-vu-verify.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ SELECT pg_catalog.pg_get_viewdef(oid, true) FROM pg_class WHERE relname = 'view_
1212
GO
1313
~~START~~
1414
text
15-
SELECT 1 AS "abnkxalnclksncfjnajcb jdsb;fcbo3230b498a93d3d3c201b75df000f7422";
15+
SELECT 1 AS "AbnkxalnclKSNcfjNAJCb jdsb;FCBo3230b498a93d3d3c201b75df000f7422";
1616
~~END~~
1717

1818

@@ -21,7 +21,7 @@ SELECT pg_catalog.pg_get_viewdef(oid, true) FROM pg_class WHERE relname = 'view_
2121
GO
2222
~~START~~
2323
text
24-
SELECT 1 AS "abnkxalnclksncfjnajcb jdsb;fcbo98276e81604b6c8f5b25ae3f87180e62";
24+
SELECT 1 AS "AbnkxalnclKSNcfjNAJCb jdsb;FCBo98276e81604b6c8f5b25ae3f87180e62";
2525
~~END~~
2626

2727

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
-- tsql
2+
USE master
3+
GO
4+
DROP TABLE guest.BABEL5119_t4
5+
GO
6+
DROP TABLE guest.BABEL5119_t5
7+
GO
8+
DROP TABLE guest.BABEL5119_t6
9+
GO
10+
DROP VIEW guest.BABEL5119_v4
11+
GO
12+
DROP VIEW guest.BABEL5119_v5
13+
GO
14+
DROP VIEW guest.BABEL5119_v6
15+
GO
16+
DROP PROCEDURE guest.BABEL5119_p4
17+
GO
18+
DROP PROCEDURE guest.BABEL5119_p5
19+
GO
20+
DROP PROCEDURE guest.BABEL5119_p6
21+
GO
22+
DROP LOGIN login_babel5119_1
23+
GO
24+
DROP DATABASE BABEL5119_db
25+
GO
26+
DROP LOGIN login_babel5119_2
27+
GO
28+
DROP USER user_babel5119_1
29+
go

0 commit comments

Comments
 (0)