Skip to content

Commit 7cdc4d2

Browse files
author
anju15bharti
committed
fix failures
1 parent a698d70 commit 7cdc4d2

134 files changed

Lines changed: 30202 additions & 461 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", i + 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: 424 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/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);
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
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-- tsql
2+
CREATE DATABASE BABEL5119_db
3+
GO
4+
5+
USE BABEL5119_db
6+
GO
7+
CREATE TABLE BABEL5119_t1(a int)
8+
GO
9+
CREATE TABLE BABEL5119_t2(a int)
10+
GO
11+
CREATE TABLE BABEL5119_t3(a int)
12+
GO
13+
CREATE VIEW BABEL5119_v1 AS SELECT 1
14+
GO
15+
CREATE VIEW BABEL5119_v2 AS SELECT 1
16+
GO
17+
CREATE VIEW BABEL5119_v3 AS SELECT 1
18+
GO
19+
CREATE PROCEDURE BABEL5119_p1 AS SELECT 1
20+
GO
21+
CREATE PROCEDURE BABEL5119_p2 AS SELECT 1
22+
GO
23+
CREATE PROCEDURE BABEL5119_p3 AS SELECT 1
24+
GO
25+
-- terminate-tsql-conn

0 commit comments

Comments
 (0)