Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(sql-editor): 🔥 use the last element of singleSQLResultList for compatibility (#4889)

Liu Ji8b0a8dfef3b0
diff --git a/frontend/src/store/modules/sql.ts b/frontend/src/store/modules/sql.ts
index a56ff60251..5bf3ebf635 100644
--- a/frontend/src/store/modules/sql.ts
+++ b/frontend/src/store/modules/sql.ts
@@ -9,14 +9,49 @@ import {
ResourceObject,
SQLResultSet,
Advice,
+ SingleSQLResult,
+ Attributes,
} from "@/types";
import { useDatabaseStore } from "./database";
import { useInstanceStore } from "./instance";
+import { last } from "lodash-es";
+
+export function convertSingleSQLResult(
+ attributes: Attributes
+): SingleSQLResult {
+ try {
+ return {
+ data: JSON.parse((attributes.data as string) || "null"),
+ error: attributes.error as string,
+ };
+ } catch {
+ return {
+ data: null as any,
+ error: attributes.error as string,
+ };
+ }
+}
export function convert(resultSet: ResourceObject): SQLResultSet {
+ const resultList: SingleSQLResult[] = [];
+ const singleSQLResultAttributesList = resultSet.attributes
+ .singleSQLResultList as Attributes[];
+ if (Array.isArray(singleSQLResultAttributesList)) {
+ singleSQLResultAttributesList.forEach((attributes) => {
+ resultList.push(convertSingleSQLResult(attributes));
+ });
+ }
+
+ // Our UI doesn't support multiple results by now.
+ // So we use the last result as the final result.
+ const lastResult = last(resultList) ?? {
+ data: null as any,
+ error: "",
+ };
+
return {
- data: JSON.parse((resultSet.attributes.data as string) || "null"),
- error: resultSet.attributes.error as string,
+ ...lastResult,
+ error: lastResult?.error || (resultSet.attributes.error as string) || "",
adviceList: resultSet.attributes.adviceList as Advice[],
};
}
diff --git a/frontend/src/types/sql.ts b/frontend/src/types/sql.ts
index 1e2f1f0519..97078e830e 100644
--- a/frontend/src/types/sql.ts
+++ b/frontend/src/types/sql.ts
@@ -1,5 +1,6 @@
-import { EngineType } from ".";
+import { EngineType } from "./instance";
import { InstanceId } from "./id";
+import { Advice } from "./sqlAdvice";
export type ConnectionInfo = {
engine: EngineType;
@@ -28,3 +29,17 @@ export type QueryInfo = {
statement: string;
limit?: number;
};
+
+// TODO(Jim): not used yet
+export type SingleSQLResult = {
+ // [columnNames: string[], types: string[], data: any[][], sensitive?: boolean[]]
+ data: [string[], string[], any[][], boolean[]];
+ error: string;
+};
+
+export type SQLResultSet = {
+ error: string;
+ // resultList: SingleSQLResult[];
+ data: SingleSQLResult["data"];
+ adviceList: Advice[];
+};
diff --git a/frontend/src/types/sqlAdvice.ts b/frontend/src/types/sqlAdvice.ts
index 6045817bce..97ab38288c 100644
--- a/frontend/src/types/sqlAdvice.ts
+++ b/frontend/src/types/sqlAdvice.ts
@@ -11,10 +11,3 @@ export type Advice = {
content: string;
line: number;
};
-
-export type SQLResultSet = {
- // [columnNames: string[], types: string[], data: any[][], sensitive?: boolean[]]
- data: [string[], string[], any[][], boolean[]];
- error: string;
- adviceList: Advice[];
-};
diff --git a/frontend/src/types/tab.ts b/frontend/src/types/tab.ts
index 7aa9e7cca5..172915aa80 100644
--- a/frontend/src/types/tab.ts
+++ b/frontend/src/types/tab.ts
@@ -1,4 +1,10 @@
-import { Advice, DatabaseId, InstanceId, SheetId } from "../types";
+import {
+ Advice,
+ DatabaseId,
+ InstanceId,
+ SheetId,
+ SingleSQLResult,
+} from "../types";
export type ExecuteConfig = {
databaseType: string;
@@ -33,8 +39,7 @@ export interface TabInfo {
option?: Partial<ExecuteOption>;
};
isExecutingSQL: boolean;
- // [columnNames: string[], types: string[], data: any[][]]
- queryResult?: [string[], string[], any[][]];
+ queryResult?: SingleSQLResult["data"];
sheetId?: SheetId;
adviceList?: Advice[];
}
diff --git a/frontend/src/views/sql-editor/EditorCommon/TableView.vue b/frontend/src/views/sql-editor/EditorCommon/TableView.vue
index e782855c1d..bfc33bfb1f 100644
--- a/frontend/src/views/sql-editor/EditorCommon/TableView.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/TableView.vue
@@ -113,13 +113,13 @@ import {
getPaginationRowModel,
useVueTable,
} from "@tanstack/vue-table";
-import { SQLResultSet } from "@/types";
+import { SingleSQLResult } from "@/types";
interface State {
search: string;
}
-type QueryResult = SQLResultSet["data"];
+type QueryResult = SingleSQLResult["data"];
const props = defineProps({
queryResult: {