fix(sqlserver): clarify GO batch semantics
This commit is contained in:
1 parent
14ce7a229e
commit
8311a88b07
3 files changed
+54
-2
No files matched your search
@@ -21,6 +21,7 @@ import { useSettingsStore, type StructureEditorDensity } from "@/stores/settings
|
||||
import { useTheme } from "@/composables/useTheme";
|
||||
import { useToast } from "@/composables/useToast";
|
||||
import { type SqlHighlighter, createShikiSqlHighlighter } from "@/lib/sql/sqlHighlighter";
|
||||
import { joinSqlStatementsForScript } from "@/lib/sql/sqlBatchScript";
|
||||
import { copyToClipboard } from "@/lib/common/clipboard";
|
||||
import { formatSqlForDisplay, sqlFormatDialectForDbType } from "@/lib/sql/sqlFormatter";
|
||||
import { queryTimeoutSecsForConnection } from "@/lib/sql/queryTimeout";
|
||||
@@ -99,10 +100,10 @@ onMounted(async () => {
|
||||
|
||||
const highlightedSql = computed(() => {
|
||||
if (!pendingStatements.value.length) return "";
|
||||
const sql = pendingStatements.value.join("\n");
|
||||
const sql = previewSqlText.value;
|
||||
return sqlHighlighter.value?.(sql) ?? sql;
|
||||
});
|
||||
const previewSqlText = computed(() => pendingStatements.value.join("\n"));
|
||||
const previewSqlText = computed(() => joinSqlStatementsForScript(pendingStatements.value, databaseType.value));
|
||||
|
||||
const props = defineProps<{
|
||||
connectionId: string;
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import type { DatabaseType } from "@/types/database";
|
||||
|
||||
/**
|
||||
* Joins generated DDL statements into a script for display/copy. SQL Server statements
|
||||
* are separated with GO so tools that execute the copied script (SSMS, sqlcmd, DBX's
|
||||
* GO-aware runner) treat each statement as an independent batch. GO only defines batch
|
||||
* boundaries; whether execution continues after an error depends on the client policy.
|
||||
*/
|
||||
export function joinSqlStatementsForScript(statements: readonly string[], databaseType?: DatabaseType): string {
|
||||
if (databaseType !== "sqlserver") return statements.join("\n");
|
||||
return statements.map((statement) => statement.trimEnd()).join("\nGO\n");
|
||||
}
|
||||
Reference in new issue
Block a user