diff --git a/changes/17946-fleetd-chrome-numbers b/changes/17946-fleetd-chrome-numbers new file mode 100644 index 0000000000..c26bffdd51 --- /dev/null +++ b/changes/17946-fleetd-chrome-numbers @@ -0,0 +1,2 @@ +- Fix a bug where values not derived from "actual" fleetd-chrome tables were not being displayed + correctly (e.g., `SELECT 1` gets its value from the query itself, not a table) diff --git a/ee/fleetd-chrome/src/db.test.ts b/ee/fleetd-chrome/src/db.test.ts index 41493348fb..6bf7526005 100644 --- a/ee/fleetd-chrome/src/db.test.ts +++ b/ee/fleetd-chrome/src/db.test.ts @@ -3,5 +3,5 @@ import VirtualDatabase from "./db"; test("Simple query", async () => { const db = await VirtualDatabase.init(); const res = await db.query("select 1"); - expect(res).toEqual({"data": [{ "1": 1 }], "warnings": null}); + expect(res).toEqual({ data: [{ "1": "1" }], warnings: null }); }); diff --git a/ee/fleetd-chrome/src/db.ts b/ee/fleetd-chrome/src/db.ts index b50f186df9..c309b2cdab 100644 --- a/ee/fleetd-chrome/src/db.ts +++ b/ee/fleetd-chrome/src/db.ts @@ -1,7 +1,6 @@ import SQLiteAsyncESMFactory from "wa-sqlite/dist/wa-sqlite-async.mjs"; import * as SQLite from "wa-sqlite"; -// Alphabetical order import Table from "./tables/Table"; import TableChromeExtensions from "./tables/chrome_extensions"; import TableDiskInfo from "./tables/disk_info"; @@ -34,7 +33,6 @@ export default class VirtualDatabase { this.sqlite3 = sqlite3; this.db = db; - // Alphabetical order VirtualDatabase.register( sqlite3, db, @@ -81,7 +79,23 @@ export default class VirtualDatabase { await this.sqlite3.exec(this.db, sql, (row, columns) => { // map each row to object rows.push( - Object.fromEntries(columns.map((_, i) => [columns[i], row[i]])) + Object.fromEntries( + columns.map((_, i) => { + let [colName, val] = [columns[i], row[i]]; + if (typeof val !== "string") { + if (val.toString) { + val = val.toString(); + } else { + this.warnings.push({ + column: colName, + error_message: `Value is not a string and doesn't have a toString method: ${val}`, + }); + val = null; + } + } + return [colName, val]; + }) + ) ); }); return { data: rows, warnings: this.warnings };