feat(sqlserver): add sql server 2000 legacy support
This commit is contained in:
20 files changed
+682
-24
No files matched your search
@@ -76,4 +76,35 @@ describe("queryStore query result export", () => {
|
||||
expect(request?.identifierQuote).toBe("[");
|
||||
expect(mocks.connectionIdentifierQuote).toHaveBeenCalledWith("kingbase-1");
|
||||
});
|
||||
|
||||
it("uses the Agent cursor for SQL Server legacy result export", async () => {
|
||||
mocks.getConfig.mockReturnValue({
|
||||
id: "sqlserver-2000",
|
||||
name: "SQL Server 2000",
|
||||
db_type: "sqlserver",
|
||||
driver_profile: "sqlserver-legacy",
|
||||
database: "master",
|
||||
query_timeout_secs: 30,
|
||||
});
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("sqlserver-2000", "master", "Query");
|
||||
const tab = store.tabs.find((item) => item.id === tabId)!;
|
||||
tab.sql = "SELECT * FROM dbo.Users";
|
||||
tab.lastExecutedSql = tab.sql;
|
||||
tab.result = {
|
||||
columns: ["id"],
|
||||
rows: [[1]],
|
||||
affected_rows: 0,
|
||||
execution_time_ms: 1,
|
||||
};
|
||||
|
||||
const request = await store.buildQueryResultExportRequest(tabId, {
|
||||
exportId: "export-legacy",
|
||||
filePath: "users.csv",
|
||||
format: "csv",
|
||||
});
|
||||
|
||||
expect(request?.useAgentCursor).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -4714,7 +4714,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
const targetDatabase = resumedExecutionTarget ? resumedExecutionTarget.database : targetContext?.scope === "connection" ? "" : (contextDatabase ?? executionTarget?.database ?? tab.database);
|
||||
const targetSchema = resumedExecutionTarget ? resumedExecutionTarget.schema : targetContext?.scope === "connection" ? undefined : (databaseTargetContext?.schema ?? executionTarget?.schema ?? tab.schema);
|
||||
const executionDatabase = dataTabExecutionDatabase(conn, targetDatabase, executionCatalog);
|
||||
const useAgentCursor = usesAgentCursorForQuery(conn?.db_type);
|
||||
const useAgentCursor = usesAgentCursorForQuery(conn?.db_type, conn?.driver_profile);
|
||||
const queryTimeoutSecs = queryTimeoutSecsForConnection(conn, settingsStore.editorSettings.globalQueryTimeoutSecs);
|
||||
if (!batchResume) {
|
||||
const statementExecution =
|
||||
@@ -5322,6 +5322,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
const pagination = limitQueryPagination(requestedPagination, queryResultMaxRows);
|
||||
pageLimit = pagination.limit;
|
||||
pageOffset = pagination.offset;
|
||||
useAgentResultSession = conn?.db_type === "sqlserver" && conn?.driver_profile?.trim().toLowerCase() === "sqlserver-legacy";
|
||||
}
|
||||
|
||||
const executionSchema = connectionQueryExecutionSchema(conn, targetDatabase, targetSchema, tab.mode === "data");
|
||||
@@ -6495,6 +6496,8 @@ export const useQueryStore = defineStore("query", () => {
|
||||
let offset = 0;
|
||||
const clientSessionId = tabClientSessionId(tab, "export");
|
||||
const exportExecutionId = uuid();
|
||||
const useAgentCursor = conn?.db_type === "sqlserver" && conn?.driver_profile?.trim().toLowerCase() === "sqlserver-legacy";
|
||||
let sessionId: string | undefined;
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
@@ -6514,23 +6517,43 @@ export const useQueryStore = defineStore("query", () => {
|
||||
limit: pageLimit,
|
||||
offset,
|
||||
});
|
||||
const results = await api.executeMulti(tab.connectionId, executionDatabase, sql, undefined, exportExecutionId, {
|
||||
maxRows: pageLimit,
|
||||
fetchSize: pageLimit,
|
||||
clientSessionId,
|
||||
catalog: tableMeta.catalog,
|
||||
timeoutSecs: queryTimeoutSecs,
|
||||
});
|
||||
const results = await api.executeMulti(
|
||||
tab.connectionId,
|
||||
executionDatabase,
|
||||
sql,
|
||||
undefined,
|
||||
exportExecutionId,
|
||||
useAgentCursor
|
||||
? {
|
||||
maxRows: 2_147_483_647,
|
||||
fetchSize: pageLimit,
|
||||
pageSize: pageLimit,
|
||||
resultSessionId: sessionId,
|
||||
clientSessionId,
|
||||
catalog: tableMeta.catalog,
|
||||
timeoutSecs: queryTimeoutSecs,
|
||||
}
|
||||
: {
|
||||
maxRows: pageLimit,
|
||||
fetchSize: pageLimit,
|
||||
clientSessionId,
|
||||
catalog: tableMeta.catalog,
|
||||
timeoutSecs: queryTimeoutSecs,
|
||||
},
|
||||
);
|
||||
const result = results[0];
|
||||
if (!result) break;
|
||||
if (columns.length === 0) columns = result.columns;
|
||||
rows.push(...result.rows);
|
||||
executionTimeMs += result.execution_time_ms ?? 0;
|
||||
onProgress?.({ rowsExported: rows.length, totalRows });
|
||||
if (result.rows.length < pageLimit) break;
|
||||
sessionId = result.session_id ?? undefined;
|
||||
const shouldFetchNextPage = useAgentCursor ? result.has_more === true : result.rows.length >= pageLimit;
|
||||
if (!shouldFetchNextPage) break;
|
||||
offset += result.rows.length;
|
||||
}
|
||||
} finally {
|
||||
if (sessionId) void api.closeQuerySession(tab.connectionId, executionDatabase, sessionId, clientSessionId, tableMeta.catalog);
|
||||
void closeClientSessionId(tab.connectionId, executionDatabase, clientSessionId, tableMeta.catalog, { tabId: tab.id });
|
||||
}
|
||||
|
||||
@@ -6558,7 +6581,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
// main 引入全局查询超时:queryTimeoutSecsForConnection 现需传入全局默认值;
|
||||
// settingsStore 取 defineStore 顶层声明的实例(本函数无局部覆盖)。
|
||||
const queryTimeoutSecs = queryTimeoutSecsForConnection(conn, settingsStore.editorSettings.globalQueryTimeoutSecs);
|
||||
const useAgentCursor = usesAgentCursorForQuery(conn?.db_type);
|
||||
const useAgentCursor = usesAgentCursorForQuery(conn?.db_type, conn?.driver_profile);
|
||||
const queryBaseSql = queryResultBaseSql(tab);
|
||||
const exportSettings = useSettingsStore().editorSettings;
|
||||
const exportRowLimit = exportSettings.exportRowLimitEnabled ? exportSettings.exportRowLimit : Number.POSITIVE_INFINITY;
|
||||
@@ -6699,7 +6722,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
const effectiveDbType = effectiveDatabaseTypeForConnection(conn);
|
||||
if (!effectiveDbType) return undefined;
|
||||
if (effectiveDbType === "mongodb") return undefined;
|
||||
const useAgentCursor = usesAgentCursorForQuery(conn?.db_type);
|
||||
const useAgentCursor = usesAgentCursorForQuery(conn?.db_type, conn?.driver_profile);
|
||||
const queryBaseSql = queryResultBaseSql(tab);
|
||||
const resultStatementIndex = tab.result.statement_index;
|
||||
const batchSql = tab.resultBaseSql ?? tab.lastExecutedSql ?? tab.sql;
|
||||
@@ -6757,7 +6780,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
sql,
|
||||
queryBaseSql: sql,
|
||||
databaseType: effectiveDbType,
|
||||
useAgentCursor: usesAgentCursorForQuery(conn?.db_type),
|
||||
useAgentCursor: usesAgentCursorForQuery(conn?.db_type, conn?.driver_profile),
|
||||
filePath,
|
||||
format,
|
||||
pageSize: settings.exportBatchSize,
|
||||
|
||||
Reference in new issue
Block a user