fix(oracle): preserve hash characters in SQL identifiers
This commit is contained in:
2 files changed
+20
-1
No files matched your search
@@ -470,6 +470,22 @@ describe("splitSqlStatementRanges", () => {
|
||||
expect(rangeSqlTexts(splitSqlStatementRanges(sql))).toEqual(["SELECT 1", "SELECT 2"]);
|
||||
});
|
||||
|
||||
it("preserves hash characters in Oracle identifiers", () => {
|
||||
const sql = "select a.FILE_ID,a.BLOCK_ID,a.BLOCKS,b.NAME from dba_extents a,v$datafile b where a.FILE_ID=b.FILE#";
|
||||
expect(rangeSqlTexts(splitSqlStatementRanges(sql, "oracle"))).toEqual([sql]);
|
||||
});
|
||||
|
||||
it("preserves hash characters in Oracle-family identifiers", () => {
|
||||
const sql = "select 1 from dba_extents where FILE_ID = b.FILE#";
|
||||
expect(rangeSqlTexts(splitSqlStatementRanges(sql, "dameng"))).toEqual([sql]);
|
||||
expect(rangeSqlTexts(splitSqlStatementRanges(sql, "oceanbase-oracle"))).toEqual([sql]);
|
||||
});
|
||||
|
||||
it("keeps hash line comments scoped to MySQL", () => {
|
||||
const sql = "SELECT 1 # comment;\n;\nSELECT 2";
|
||||
expect(rangeSqlTexts(splitSqlStatementRanges(sql, "mysql"))).toEqual(["SELECT 1", "SELECT 2"]);
|
||||
});
|
||||
|
||||
it("keeps SQL Server temporary table names instead of treating them as hash comments", () => {
|
||||
const sql = "DROP TABLE IF EXISTS #Temp;\nSELECT * FROM ##GlobalTemp;";
|
||||
expect(rangeSqlTexts(splitSqlStatementRanges(sql, "sqlserver"))).toEqual(["DROP TABLE IF EXISTS #Temp", "SELECT * FROM ##GlobalTemp"]);
|
||||
|
||||
@@ -1409,7 +1409,10 @@ function startsLineComment(sql: string, pos: number, databaseType?: DatabaseType
|
||||
}
|
||||
|
||||
function startsHashLineComment(sql: string, pos: number, databaseType?: DatabaseType, parameterOptions?: SqlParameterOptions): boolean {
|
||||
if (databaseType === "sqlserver" || sql[pos] !== "#") return false;
|
||||
// `#` is a MySQL-family line-comment marker. Oracle-family engines also allow
|
||||
// it in unquoted identifiers (for example `V$DATAFILE.FILE#`), so treating it
|
||||
// as a comment there truncates otherwise valid statements.
|
||||
if ((databaseType !== undefined && ORACLE_LIKE_PL_SQL_DATABASES.has(databaseType)) || databaseType === "sqlserver" || sql[pos] !== "#") return false;
|
||||
return readSqlBracedParameterAt(sql, pos, parameterOptions)?.syntax !== "mybatis";
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user