From 9ea6199ebacf9268d6f5cde895919141e4247af0 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 29 Apr 2022 16:22:11 +0100 Subject: [PATCH 1/7] Fixing issue #5594 - allowing use of double underscores in table names for SQL. --- packages/server/src/integrations/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/server/src/integrations/utils.ts b/packages/server/src/integrations/utils.ts index 326b213bc7..16cc6d387e 100644 --- a/packages/server/src/integrations/utils.ts +++ b/packages/server/src/integrations/utils.ts @@ -85,9 +85,9 @@ export function breakExternalTableId(tableId: string | undefined) { return {} } const parts = tableId.split(DOUBLE_SEPARATOR) - let tableName = parts.pop() + let datasourceId = parts.shift() // if they need joined - let datasourceId = parts.join(DOUBLE_SEPARATOR) + let tableName = parts.join(DOUBLE_SEPARATOR) return { datasourceId, tableName } } From 6b4377c93271025df71533173fa23827f9fd9f0e Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 29 Apr 2022 16:47:43 +0100 Subject: [PATCH 2/7] Fix for #5612 - stop some formats of string being in-correctly parsed as dates by MySQL - disable type coercion for data source plus mysql tables (knex converts). --- packages/server/src/integrations/mysql.ts | 27 ++++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/server/src/integrations/mysql.ts b/packages/server/src/integrations/mysql.ts index 065a1b2333..c2ef44c1bd 100644 --- a/packages/server/src/integrations/mysql.ts +++ b/packages/server/src/integrations/mysql.ts @@ -101,7 +101,7 @@ module MySQLModule { } // if not a number, see if it is a date - important to do in this order as any // integer will be considered a valid date - else if (dayjs(binding).isValid()) { + else if (/^\d/.test(binding) && dayjs(binding).isValid()) { bindings[i] = dayjs(binding).toDate() } } @@ -151,20 +151,24 @@ module MySQLModule { async internalQuery( query: SqlQuery, - connect: boolean = true + opts: { connect?: boolean; disableCoercion?: boolean } = { + connect: true, + disableCoercion: false, + } ): Promise { try { - if (connect) { + if (opts?.connect) { await this.connect() } + const baseBindings = query.bindings || [] + const bindings = opts?.disableCoercion + ? baseBindings + : bindingTypeCoerce(baseBindings) // Node MySQL is callback based, so we must wrap our call in a promise - const response = await this.client.query( - query.sql, - bindingTypeCoerce(query.bindings || []) - ) + const response = await this.client.query(query.sql, bindings) return response[0] } finally { - if (connect) { + if (opts?.connect) { await this.disconnect() } } @@ -179,7 +183,7 @@ module MySQLModule { // get the tables first const tablesResp = await this.internalQuery( { sql: "SHOW TABLES;" }, - false + { connect: false } ) const tableNames = tablesResp.map( (obj: any) => @@ -191,7 +195,7 @@ module MySQLModule { const schema: TableSchema = {} const descResp = await this.internalQuery( { sql: `DESCRIBE \`${tableName}\`;` }, - false + { connect: false } ) for (let column of descResp) { const columnName = column.Field @@ -254,7 +258,8 @@ module MySQLModule { async query(json: QueryJson) { await this.connect() try { - const queryFn = (query: any) => this.internalQuery(query, false) + const queryFn = (query: any) => + this.internalQuery(query, { connect: false, disableCoercion: true }) return await this.queryWithReturning(json, queryFn) } finally { await this.disconnect() From d090f2a8aa8efc8907f4ff5524def55c9251277b Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 3 May 2022 14:11:06 +0100 Subject: [PATCH 3/7] Fix for #5553 - when importing for SQL databases attempt to manage date and time only column times, handle these when displaying in tables and when filtering. --- .../bbui/src/Table/DateTimeRenderer.svelte | 13 +++++++++---- .../backend/DataTable/RowFieldControl.svelte | 9 +++++++-- .../FilterEditor/FilterDrawer.svelte | 11 ++++++++++- .../app/dynamic-filter/FilterModal.svelte | 11 ++++++++++- .../src/integrations/microsoftSqlServer.ts | 4 +--- packages/server/src/integrations/mysql.ts | 3 ++- packages/server/src/integrations/oracle.ts | 6 +++--- packages/server/src/integrations/postgres.ts | 3 +-- packages/server/src/integrations/utils.ts | 17 ++++++++++++++--- packages/server/yarn.lock | 18 +++++++++--------- packages/worker/yarn.lock | 18 +++++++++--------- 11 files changed, 75 insertions(+), 38 deletions(-) diff --git a/packages/bbui/src/Table/DateTimeRenderer.svelte b/packages/bbui/src/Table/DateTimeRenderer.svelte index 5d856968e7..f4b0821069 100644 --- a/packages/bbui/src/Table/DateTimeRenderer.svelte +++ b/packages/bbui/src/Table/DateTimeRenderer.svelte @@ -2,17 +2,22 @@ import dayjs from "dayjs" export let value + export let schema // adding the 0- will turn a string like 00:00:00 into a valid ISO // date, but will make actual ISO dates invalid $: time = new Date(`0-${value}`) - $: isTime = !isNaN(time) + $: isTimeOnly = !isNaN(time) || schema?.timeOnly + $: isDateOnly = schema?.dateOnly + $: format = isTimeOnly + ? "HH:mm:ss" + : isDateOnly + ? "MMMM D YYYY" + : "MMMM D YYYY, HH:mm"
- {dayjs(isTime ? time : value).format( - isTime ? "HH:mm:ss" : "MMMM D YYYY, HH:mm" - )} + {dayjs(isTimeOnly ? time : value).format(format)}