mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-28 16:09:17 +00:00
fix(sqlserver): support TLS fallback, TOP syntax, and schema browsing
This commit is contained in:
+5
-1
@@ -319,7 +319,7 @@ function quoteIdent(tab: ActiveTab, name: string): string {
|
||||
function qualifiedTableName(tab: NonNullable<typeof activeTab.value>): string {
|
||||
const config = connectionStore.getConfig(tab.connectionId);
|
||||
if (!tab.tableMeta) return "";
|
||||
if ((config?.db_type === "postgres" || config?.db_type === "oracle") && tab.tableMeta.schema) {
|
||||
if ((config?.db_type === "postgres" || config?.db_type === "oracle" || config?.db_type === "sqlserver") && tab.tableMeta.schema) {
|
||||
return `${quoteIdent(tab, tab.tableMeta.schema)}.${quoteIdent(tab, tab.tableMeta.tableName)}`;
|
||||
}
|
||||
return quoteIdent(tab, tab.tableMeta.tableName);
|
||||
@@ -345,6 +345,10 @@ function buildTableSql(
|
||||
return `SELECT * FROM ${qualifiedTableName(tab)}${order}${offset} FETCH FIRST ${limit} ROWS ONLY`;
|
||||
}
|
||||
|
||||
if (config?.db_type === "sqlserver") {
|
||||
return `SELECT TOP ${limit} * FROM ${qualifiedTableName(tab)}${order}`;
|
||||
}
|
||||
|
||||
const offset = options.offset ? ` OFFSET ${options.offset}` : "";
|
||||
return `SELECT * FROM ${qualifiedTableName(tab)}${order} LIMIT ${limit}${offset};`;
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ async function toggle() {
|
||||
queryStore.updateSql(tab, node.label);
|
||||
} else if (node.type === "database" && node.connectionId && node.database) {
|
||||
const config = connectionStore.getConfig(node.connectionId);
|
||||
if (config?.db_type === "postgres") {
|
||||
if (config?.db_type === "postgres" || config?.db_type === "sqlserver") {
|
||||
await connectionStore.loadSchemas(node.connectionId, node.database);
|
||||
} else {
|
||||
await connectionStore.loadTables(node.connectionId, node.database);
|
||||
@@ -144,7 +144,7 @@ async function openData() {
|
||||
if (!(node.type === "table" || node.type === "view") || !node.connectionId || !node.database) return;
|
||||
await connectionStore.ensureConnected(node.connectionId);
|
||||
const config = connectionStore.getConfig(node.connectionId);
|
||||
const qualifiedName = (config?.db_type === "postgres" || config?.db_type === "oracle") && node.schema
|
||||
const qualifiedName = (config?.db_type === "postgres" || config?.db_type === "oracle" || config?.db_type === "sqlserver") && node.schema
|
||||
? `${quoteIdent(node.schema)}.${quoteIdent(node.label)}`
|
||||
: quoteIdent(node.label);
|
||||
const tabId = queryStore.createTab(node.connectionId, node.database, node.label, "data");
|
||||
@@ -153,9 +153,14 @@ async function openData() {
|
||||
const columns = await api.getColumns(node.connectionId, node.database, querySchema, node.label);
|
||||
const pks = columns.filter((c) => c.is_primary_key).map((c) => c.name);
|
||||
const order = pks.length ? ` ORDER BY ${pks.map((pk) => `${quoteIdent(pk)} ASC`).join(", ")}` : "";
|
||||
const sql = config?.db_type === "oracle"
|
||||
? `SELECT * FROM ${qualifiedName}${order} FETCH FIRST 100 ROWS ONLY`
|
||||
: `SELECT * FROM ${qualifiedName}${order} LIMIT 100;`;
|
||||
let sql: string;
|
||||
if (config?.db_type === "oracle") {
|
||||
sql = `SELECT * FROM ${qualifiedName}${order} FETCH FIRST 100 ROWS ONLY`;
|
||||
} else if (config?.db_type === "sqlserver") {
|
||||
sql = `SELECT TOP 100 * FROM ${qualifiedName}${order}`;
|
||||
} else {
|
||||
sql = `SELECT * FROM ${qualifiedName}${order} LIMIT 100;`;
|
||||
}
|
||||
queryStore.updateSql(tabId, sql);
|
||||
queryStore.setTableMeta(tabId, {
|
||||
schema: node.schema,
|
||||
|
||||
Reference in New Issue
Block a user