1 parent
f3d2b6cb01
commit
355f34f3c7
3 files changed
+30
-3
No files matched your search
@@ -531,6 +531,15 @@ END pkg_utils_without_replace;`;
|
|||||||
expect(rangeSqlTexts(splitSqlStatementRanges(`${packageSpecWithoutReplace}\nSELECT 1;`, "xugu"))).toEqual([packageSpecWithoutReplace, "SELECT 1"]);
|
expect(rangeSqlTexts(splitSqlStatementRanges(`${packageSpecWithoutReplace}\nSELECT 1;`, "xugu"))).toEqual([packageSpecWithoutReplace, "SELECT 1"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("splits a declaration-only Oracle package body before following DML", () => {
|
||||||
|
const packageBody = `CREATE OR REPLACE PACKAGE BODY packageName IS
|
||||||
|
null;
|
||||||
|
END packageName;`;
|
||||||
|
|
||||||
|
expect(rangeSqlTexts(splitSqlStatementRanges(`${packageBody}\nSELECT * FROM goods;`, "oracle"))).toEqual([packageBody, "SELECT * FROM goods"]);
|
||||||
|
expect(rangeSqlTexts(splitSqlStatementRanges(`${packageBody}\n/\nSELECT * FROM goods;`, "oracle"))).toEqual([packageBody, "SELECT * FROM goods"]);
|
||||||
|
});
|
||||||
|
|
||||||
it("splits plain CREATE TYPE AS OBJECT on semicolon without waiting for END", () => {
|
it("splits plain CREATE TYPE AS OBJECT on semicolon without waiting for END", () => {
|
||||||
const sql = "CREATE OR REPLACE TYPE address_t AS OBJECT (id INT);\nSELECT 1;";
|
const sql = "CREATE OR REPLACE TYPE address_t AS OBJECT (id INT);\nSELECT 1;";
|
||||||
expect(rangeSqlTexts(splitSqlStatementRanges(sql, "xugu"))).toEqual(["CREATE OR REPLACE TYPE address_t AS OBJECT (id INT)", "SELECT 1"]);
|
expect(rangeSqlTexts(splitSqlStatementRanges(sql, "xugu"))).toEqual(["CREATE OR REPLACE TYPE address_t AS OBJECT (id INT)", "SELECT 1"]);
|
||||||
|
|||||||
@@ -1782,7 +1782,7 @@ function oraclePlSqlBlockEnd(sql: string): number | null {
|
|||||||
for (let index = 0; index < tokens.length; index += 1) {
|
for (let index = 0; index < tokens.length; index += 1) {
|
||||||
const token = tokens[index];
|
const token = tokens[index];
|
||||||
if (token.kind === "semicolon") {
|
if (token.kind === "semicolon") {
|
||||||
const complete = objectKind === "spec" ? stack.length === 0 : sawBegin && stack.length === 0;
|
const complete = objectKind !== null ? stack.length === 0 : sawBegin && stack.length === 0;
|
||||||
if (complete) return token.to;
|
if (complete) return token.to;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2288,8 +2288,10 @@ impl OraclePlSqlBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
match object_kind {
|
match object_kind {
|
||||||
// Specs complete on outer END [name]; without requiring BEGIN.
|
// Package/type objects complete on their outer END [name]; a package
|
||||||
Some(OraclePlSqlCreateObjectKind::Spec) => complete,
|
// body may omit an initialization BEGIN when it has no executable
|
||||||
|
// initialization section.
|
||||||
|
Some(OraclePlSqlCreateObjectKind::Body | OraclePlSqlCreateObjectKind::Spec) => complete,
|
||||||
_ => saw_begin && complete,
|
_ => saw_begin && complete,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3927,6 +3929,22 @@ SELECT 1;";
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn oracle_like_split_declaration_only_package_body_before_following_dml() {
|
||||||
|
let package_body = "CREATE OR REPLACE PACKAGE BODY packageName IS\nnull;\nEND packageName;";
|
||||||
|
assert_eq!(
|
||||||
|
split_sql_statements_for_database(&format!("{package_body}\nSELECT * FROM goods;"), DatabaseType::Oracle),
|
||||||
|
vec![package_body, "SELECT * FROM goods"]
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
split_sql_statements_for_database(
|
||||||
|
&format!("{package_body}\n/\nSELECT * FROM goods;"),
|
||||||
|
DatabaseType::Oracle
|
||||||
|
),
|
||||||
|
vec![package_body, "SELECT * FROM goods"]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn xugu_split_keeps_create_type_body_together() {
|
fn xugu_split_keeps_create_type_body_together() {
|
||||||
let sql = "\
|
let sql = "\
|
||||||
|
|||||||
Reference in new issue
Block a user