fix(sqlite): validate ssh backup and query errors

This commit is contained in:
skyler authored and GitHub committed 2026-08-30 13:30:00 +08:00
1 parent e6f8b2187a
commit 9190554e50
58 files changed
+2815 -149

No files matched your search

@@ -55,7 +55,7 @@ import { doltSystemTablesVisible, isDoltDriverProfile, setDoltSystemTablesVisibl
import { DamengJvmSystemPropertyError, damengJvmSystemPropertiesText, parseDamengJvmSystemProperties } from "@/lib/database/damengJvmOptions";
import { copyToClipboard } from "@/lib/common/clipboard";
import { configuredDatabaseProductName, connectionConfigFingerprint, databaseInfoCopyText, databaseInfoRows, normalizeDatabaseConnectionInfo, type DatabaseInfoField } from "@/lib/connection/connectionDatabaseInfo";
import { agentDriverInstallKey, appendAgentDriverUpdateHint, hasAgentDriverUpdate, showAgentDriverInstallHint, type AgentDriverInstallState, type DriverStoreFocus } from "@/lib/connection/agentDriverInstallHint";
import { agentDriverInstallKey, appendAgentDriverUpdateHint, connectionUsesSsh, hasAgentDriverUpdate, showAgentDriverInstallHint, type AgentDriverInstallState, type DriverStoreFocus } from "@/lib/connection/agentDriverInstallHint";
import { prestoSqlBuiltinDriverPaths } from "@/lib/database/prestoSqlBuiltinDriver";
import { JDBCX_DEFAULT_URL, JDBCX_DRIVER_PROFILE, JDBCX_JDBC_DRIVER_CLASS, ensureJdbcxRuntimeDrivers, isJdbcxRuntimeBundle, isJdbcxRuntimePath, jdbcxHighPrivilegeExtensionsEnabled, setJdbcxHighPrivilegeExtensionsEnabled } from "@/lib/database/jdbcxBuiltinDriver";
import { SQLITE_DATABASE_FILE_EXTENSIONS } from "@/lib/database/databaseFileDetection";
@@ -1726,7 +1726,7 @@ function errorMessage(error: unknown): string {
function connectionErrorWithDriverUpdateHint(config: ConnectionConfig, message: string): string {
message = appendConnectionErrorHints(config, message, t);
if (!hasAgentDriverUpdate(config.db_type, agentDrivers.value, config.driver_profile)) return message;
if (!hasAgentDriverUpdate(config.db_type, agentDrivers.value, config.driver_profile, { ssh: connectionUsesSsh(config) })) return message;
return appendAgentDriverUpdateHint(message, t("connection.agentDriverUpdateConnectionHint"));
}
@@ -1838,11 +1838,11 @@ async function ensureRequiredAgentDriverInstalled(config: ConnectionConfig): Pro
await installSqlServerLegacyCompatibilityComponentIfNeeded();
}
const driverKey = agentDriverInstallKey(config.db_type, config.driver_profile);
const driverKey = agentDriverInstallKey(config.db_type, config.driver_profile, { ssh: connectionUsesSsh(config) });
if (!driverKey) return;
let drivers = agentDrivers.value.length ? agentDrivers.value : await refreshLocalAgentDrivers();
if (!showAgentDriverInstallHint(config.db_type, drivers, config.driver_profile)) return;
if (!showAgentDriverInstallHint(config.db_type, drivers, config.driver_profile, { ssh: connectionUsesSsh(config) })) return;
if (installedAgentDriver(drivers, driverKey)?.installed === true) return;
drivers = await refreshLocalAgentDrivers();
@@ -2659,7 +2659,11 @@ const selectedSshLayer = computed(() => (selectedTransportLayer.value?.type ===
const selectedProxyLayer = computed(() => (selectedTransportLayer.value?.type === "proxy" ? selectedTransportLayer.value : null));
const selectedHttpTunnelLayer = computed(() => (selectedTransportLayer.value?.type === "http_tunnel" ? selectedTransportLayer.value : null));
const tunnelProfiles = computed(() => tunnelProfileStore.profiles);
const tunnelProfiles = computed(() => {
const profiles = tunnelProfileStore.profiles;
if (!sqliteSshOnlyTransport.value) return profiles;
return profiles.filter((profile) => profile.type === "ssh");
});
const selectedLayerProfileId = computed(() => selectedTransportLayer.value?.profile_id || "");
const selectedLayerProfile = computed(() => tunnelProfileStore.profileById(selectedLayerProfileId.value));
@@ -3102,10 +3106,63 @@ const zookeeperAuthScheme = computed<ZooKeeperAuthScheme>({
resetTestState();
},
});
const canUseTransportLayers = computed(() => form.value.db_type !== "sqlite" && form.value.db_type !== "access" && !isCloudflareD1Connection(form.value) && !isH2FileMode.value && !(form.value.db_type === "oracle" && form.value.oracle_connection_type === "tns"));
const shouldShowAgentDriverInstallHint = computed(() => showAgentDriverInstallHint(form.value.db_type, agentDrivers.value, form.value.driver_profile));
const canUseTransportLayers = computed(() => {
if (form.value.db_type === "access" || isCloudflareD1Connection(form.value) || isH2FileMode.value || (form.value.db_type === "oracle" && form.value.oracle_connection_type === "tns")) {
return false;
}
if (form.value.db_type === "sqlite") {
return isDesktop;
}
return true;
});
const sqliteSshOnlyTransport = computed(() => form.value.db_type === "sqlite");
const sqliteUsesSsh = computed(() => form.value.db_type === "sqlite" && connectionUsesSsh(form.value));
const sqliteWorkerPlacement = computed({
get: () => getUrlParam(form.value.url_params, "dbx_sqlite_worker") || "session",
set: (value: string) => {
const next = value === "session" ? "" : value;
form.value.url_params = setUrlParam(form.value.url_params, "dbx_sqlite_worker", next);
if (value !== "preplaced" && !getUrlParam(form.value.url_params, "dbx_sqlite_worker_path")) {
return;
}
if (value === "session") {
form.value.url_params = setUrlParam(form.value.url_params, "dbx_sqlite_worker_path", "");
}
},
});
const sqliteWorkerPath = computed({
get: () => getUrlParam(form.value.url_params, "dbx_sqlite_worker_path"),
set: (value: string) => {
form.value.url_params = setUrlParam(form.value.url_params, "dbx_sqlite_worker_path", value);
},
});
const sqliteWorkerPlacementOptions = [
{
value: "session",
labelKey: "connection.sqliteWorkerPlacementSession",
hintKey: "connection.sqliteWorkerPlacementSessionHint",
recommended: true,
},
{
value: "persist",
labelKey: "connection.sqliteWorkerPlacementPersist",
hintKey: "connection.sqliteWorkerPlacementPersistHint",
recommended: false,
},
{
value: "preplaced",
labelKey: "connection.sqliteWorkerPlacementPreplaced",
hintKey: "connection.sqliteWorkerPlacementPreplacedHint",
recommended: false,
},
] as const;
const shouldShowSqliteSshWorkerInstallHint = computed(() => form.value.db_type === "sqlite" && sqliteUsesSsh.value && showAgentDriverInstallHint("sqlite", agentDrivers.value, form.value.driver_profile, { ssh: true }));
const shouldShowAgentDriverInstallHint = computed(() => {
if (form.value.db_type === "sqlite" && sqliteUsesSsh.value) return false;
return showAgentDriverInstallHint(form.value.db_type, agentDrivers.value, form.value.driver_profile, { ssh: sqliteUsesSsh.value });
});
const agentDriverFocus = computed<DriverStoreFocus>(() => ({ target: "driver", driver: agentDriverInstallKey(form.value.db_type, form.value.driver_profile, { ssh: sqliteUsesSsh.value }) }));
const h2DriverMissing = computed(() => form.value.db_type === "h2" && isH2FileMode.value && agentDrivers.value.find((d) => d.db_type === "h2")?.installed !== true);
const agentDriverFocus = computed<DriverStoreFocus>(() => ({ target: "driver", driver: agentDriverInstallKey(form.value.db_type, form.value.driver_profile) }));
const canChooseVisibleNacosNamespaces = computed(() => form.value.db_type === "nacos");
const isNacosV3AdminPlane = computed(() => nacosImplementation.value === "nacos" && nacosVersionMode.value === "v3" && nacosApiPlane.value === "admin");
const isNacosV3ConsolePlane = computed(() => nacosImplementation.value === "nacos" && nacosVersionMode.value === "v3" && nacosApiPlane.value === "console");
@@ -5056,6 +5113,15 @@ watch(canUseTransportLayers, (value) => {
}
});
watch(sqliteSshOnlyTransport, (sshOnly) => {
if (!sshOnly) return;
const layers = form.value.transport_layers || [];
const next = layers.filter((layer) => layer.type === "ssh");
if (next.length === layers.length) return;
form.value.transport_layers = next;
selectedTransportLayerId.value = next[0]?.id || null;
});
watch(supportsTlsToggle, (value) => {
if (!value && configTab.value === "tls") {
configTab.value = "connection";
@@ -5077,6 +5143,7 @@ function addSshTunnel() {
}
function addProxyTunnel() {
if (sqliteSshOnlyTransport.value) return;
const next: TransportLayerConfig = { type: "proxy", ...defaultProxyTunnel() };
next.name = `Proxy ${transportLayers.value.length + 1}`;
form.value.transport_layers = [...transportLayers.value, next];
@@ -5085,6 +5152,7 @@ function addProxyTunnel() {
}
function addHttpTunnel() {
if (sqliteSshOnlyTransport.value) return;
const next: TransportLayerConfig = { type: "http_tunnel", ...defaultHttpTunnel() };
next.name = t("connection.httpTunnelDefaultName", { index: 1 });
form.value.transport_layers = [next, ...transportLayers.value];
@@ -5093,6 +5161,7 @@ function addHttpTunnel() {
}
function duplicateTransportLayer(layer: TransportLayerConfig) {
if (sqliteSshOnlyTransport.value && layer.type !== "ssh") return;
const next = normalizeTransportLayer({ ...layer, id: uuid(), name: layer.name ? `${layer.name} copy` : "" });
form.value.transport_layers = [...transportLayers.value, next];
selectedTransportLayerId.value = next.id;
@@ -5132,6 +5201,7 @@ function dropTransportLayer(targetId: string) {
function changeSelectedTransportLayerType(type: "ssh" | "proxy" | "http_tunnel") {
const selected = selectedTransportLayer.value;
if (!selected || selected.type === type) return;
if (sqliteSshOnlyTransport.value && type !== "ssh") return;
const replacement: TransportLayerConfig =
type === "proxy" ? { type: "proxy", ...defaultProxyTunnel(), id: selected.id, name: selected.name } : type === "http_tunnel" ? { type: "http_tunnel", ...defaultHttpTunnel(), id: selected.id, name: selected.name } : { type: "ssh", ...defaultSshTunnel(), id: selected.id, name: selected.name };
form.value.transport_layers = transportLayers.value.map((layer) => (layer.id === selected.id ? replacement : layer));
@@ -5154,6 +5224,9 @@ function updateSelectedSshAuthMethod(value: unknown) {
function validateTransportLayers(config: LegacyConnectionConfig) {
const layers = config.transport_layers || [];
if (config.db_type === "sqlite" && layers.some((layer) => layer.enabled !== false && layer.type !== "ssh")) {
throw new Error(t("connection.sqliteTransportSshOnly"));
}
layers.forEach((layer, index) => {
if (layer.enabled === false) return;
// Profile-referencing layers are stubs: the shared profile supplies the
@@ -6119,10 +6192,10 @@ function openExternalUrl(url: string) {
<Label :class="connectionLabelClass">{{ t("connection.filePath") }}</Label>
<div class="col-span-3 space-y-1">
<div class="flex items-center gap-1">
<Input v-model="form.host" class="flex-1" :placeholder="filePathPlaceholder" />
<Input v-model="form.host" class="flex-1" :placeholder="sqliteUsesSsh ? t('connection.sqliteRemotePathPlaceholder') : filePathPlaceholder" />
<Tooltip v-if="isDesktop">
<TooltipTrigger as-child>
<Button variant="outline" size="icon" class="h-9 w-9 shrink-0" @click="browseDbFilePath">
<Button variant="outline" size="icon" class="h-9 w-9 shrink-0" :disabled="sqliteUsesSsh" @click="browseDbFilePath">
<FolderOpen class="h-4 w-4" />
</Button>
</TooltipTrigger>
@@ -6138,23 +6211,54 @@ function openExternalUrl(url: string) {
</Tooltip>
<Tooltip v-if="isDesktop && form.db_type === 'sqlite'">
<TooltipTrigger as-child>
<Button variant="outline" size="icon" class="h-9 w-9 shrink-0" @click="createSqliteFilePath">
<Button variant="outline" size="icon" class="h-9 w-9 shrink-0" :disabled="sqliteUsesSsh" @click="createSqliteFilePath">
<FilePlus2 class="h-4 w-4" />
</Button>
</TooltipTrigger>
<TooltipContent>{{ t("connection.createSqliteFile") }}</TooltipContent>
</Tooltip>
</div>
<p v-if="supportsMemoryDatabasePath" class="text-xs text-muted-foreground">
<p v-if="sqliteUsesSsh" class="text-xs text-muted-foreground">
{{ t("connection.sqliteRemotePathHint") }}
</p>
<p v-else-if="supportsMemoryDatabasePath" class="text-xs text-muted-foreground">
{{ t("connection.memoryDatabasePathHint") }}
</p>
</div>
</div>
<div v-if="form.db_type === 'sqlite'" class="grid grid-cols-4 items-center gap-4">
<div v-if="form.db_type === 'sqlite' && sqliteUsesSsh" class="grid grid-cols-4 items-start gap-4">
<Label :class="connectionLabelTopClass">{{ t("connection.sqliteWorkerPlacement") }}</Label>
<div class="col-span-3 space-y-2">
<div class="flex min-h-9 flex-wrap items-center gap-x-5 gap-y-2">
<Tooltip v-for="option in sqliteWorkerPlacementOptions" :key="option.value" :delay-duration="0">
<TooltipTrigger as-child>
<label class="flex cursor-pointer items-center gap-1.5 text-sm">
<input type="radio" name="sqlite-worker-placement" class="h-3.5 w-3.5 accent-primary" :value="option.value" v-model="sqliteWorkerPlacement" />
<span>{{ t(option.labelKey) }}</span>
<Badge v-if="option.recommended" class="h-4 rounded-full px-1.5 text-[10px] leading-none">{{ t("connection.sqliteWorkerPlacementDefault") }}</Badge>
</label>
</TooltipTrigger>
<TooltipContent side="bottom" class="max-w-[18rem] flex-col items-start gap-1 py-2 text-left">
<div class="flex items-center gap-1.5 font-medium">
<span>{{ t(option.labelKey) }}</span>
<Badge v-if="option.recommended" class="h-4 rounded-full px-1.5 text-[10px] leading-none">{{ t("connection.sqliteWorkerPlacementDefault") }}</Badge>
</div>
<p class="text-[11px] leading-relaxed text-background/80">{{ t(option.hintKey) }}</p>
</TooltipContent>
</Tooltip>
</div>
<Input v-if="sqliteWorkerPlacement !== 'session'" v-model="sqliteWorkerPath" :placeholder="sqliteWorkerPlacement === 'persist' ? t('connection.sqliteWorkerPersistPathPlaceholder') : t('connection.sqliteWorkerPreplacedPathPlaceholder')" />
<p v-if="shouldShowSqliteSshWorkerInstallHint" class="text-xs text-muted-foreground">
{{ t("connection.driverInstallHintPrefix") }}<a class="underline cursor-pointer text-primary hover:text-primary/80" @click="emit('openDriverStore', agentDriverFocus)">{{ t("toolbar.driverManager") }}</a
>{{ t("connection.driverInstallHintSuffix") }}
</p>
</div>
</div>
<div v-if="form.db_type === 'sqlite' && !sqliteUsesSsh" class="grid grid-cols-4 items-center gap-4">
<Label :class="connectionLabelClass">{{ t("connection.sqliteCipherKey") }}</Label>
<PasswordInput v-model="form.password" class="col-span-3" :placeholder="t('connection.sqliteCipherKeyPlaceholder')" />
</div>
<div v-if="form.db_type === 'sqlite'" class="grid grid-cols-4 items-start gap-4">
<div v-if="form.db_type === 'sqlite' && !sqliteUsesSsh" class="grid grid-cols-4 items-start gap-4">
<Label :class="connectionLabelTopClass">{{ t("connection.sqliteExtensions") }}</Label>
<div class="col-span-3 space-y-1">
<div class="flex items-start gap-1">
@@ -8419,11 +8523,11 @@ function openExternalUrl(url: string) {
<Plus class="mr-1.5 h-3.5 w-3.5" />
{{ t("connection.sshHopAdd") }}
</Button>
<Button type="button" variant="outline" size="sm" @click="addProxyTunnel">
<Button v-if="!sqliteSshOnlyTransport" type="button" variant="outline" size="sm" @click="addProxyTunnel">
<Plus class="mr-1.5 h-3.5 w-3.5" />
{{ t("connection.proxy") }}
</Button>
<Button type="button" variant="outline" size="sm" @click="addHttpTunnel">
<Button v-if="!sqliteSshOnlyTransport" type="button" variant="outline" size="sm" @click="addHttpTunnel">
<Plus class="mr-1.5 h-3.5 w-3.5" />
{{ t("connection.httpTunnelAdd") }}
</Button>
@@ -8472,7 +8576,7 @@ function openExternalUrl(url: string) {
<span v-else class="text-red-500">{{ t("connection.tunnelProfileMissing") }}</span>
</div>
</div>
<div v-if="!selectedLayerProfileId" class="grid grid-cols-4 items-center gap-4">
<div v-if="!selectedLayerProfileId && !sqliteSshOnlyTransport" class="grid grid-cols-4 items-center gap-4">
<Label :class="connectionLabelSmallClass">Type</Label>
<Select :model-value="selectedTransportLayer.type" @update:model-value="(value: any) => changeSelectedTransportLayerType(value)">
<SelectTrigger class="col-span-3 h-9">