From 05992579352fa25b50617593ea041681b49d272c Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 30 Jul 2024 11:26:16 +0100 Subject: [PATCH] Fix time-only columns. --- packages/backend-core/src/sql/sql.ts | 27 ++++++++++++++++--- .../src/api/routes/tests/search.spec.ts | 18 ++++++------- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/packages/backend-core/src/sql/sql.ts b/packages/backend-core/src/sql/sql.ts index 26d6545868..7a76e09d3f 100644 --- a/packages/backend-core/src/sql/sql.ts +++ b/packages/backend-core/src/sql/sql.ts @@ -219,6 +219,23 @@ class InternalBuilder { if (input == undefined) { return null } + + if ( + this.client === SqlClient.ORACLE && + schema.type === FieldType.DATETIME && + schema.timeOnly + ) { + if (input instanceof Date) { + const hours = input.getHours().toString().padStart(2, "0") + const minutes = input.getMinutes().toString().padStart(2, "0") + const seconds = input.getSeconds().toString().padStart(2, "0") + return `${hours}:${minutes}:${seconds}` + } + if (typeof input === "string") { + return new Date(`1970-01-01 ${input}`) + } + } + if (typeof input === "string") { if (isInvalidISODateString(input)) { return null @@ -531,7 +548,7 @@ class InternalBuilder { } else if (this.client === SqlClient.ORACLE) { const identifier = this.convertClobs(key) query = query[fnc]( - `(${identifier} IS NOT NULL AND ${identifier} != ?)`, + `(${identifier} IS NOT NULL AND ${identifier} != ?) OR ${identifier} IS NULL`, [value] ) } else { @@ -605,8 +622,12 @@ class InternalBuilder { const direction = value.direction === SortOrder.ASCENDING ? "asc" : "desc" let nulls - if (this.client === SqlClient.POSTGRES) { - // All other clients already sort this as expected by default, and adding this to the rest of the clients is causing issues + if ( + this.client === SqlClient.POSTGRES || + this.client === SqlClient.ORACLE + ) { + // All other clients already sort this as expected by default, and + // adding this to the rest of the clients is causing issues nulls = value.direction === SortOrder.ASCENDING ? "first" : "last" } diff --git a/packages/server/src/api/routes/tests/search.spec.ts b/packages/server/src/api/routes/tests/search.spec.ts index 110a9ae699..d1fc361993 100644 --- a/packages/server/src/api/routes/tests/search.spec.ts +++ b/packages/server/src/api/routes/tests/search.spec.ts @@ -40,14 +40,14 @@ import { structures } from "@budibase/backend-core/tests" import { DEFAULT_EMPLOYEE_TABLE_SCHEMA } from "../../../db/defaultData/datasource_bb_default" describe.each([ - ["in-memory", undefined], - ["lucene", undefined], - ["sqs", undefined], - [DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)], - [DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)], - [DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)], - [DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)], - // [DatabaseName.ORACLE, getDatasource(DatabaseName.ORACLE)], + // ["in-memory", undefined], + // ["lucene", undefined], + // ["sqs", undefined], + // [DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)], + // [DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)], + // [DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)], + // [DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)], + [DatabaseName.ORACLE, getDatasource(DatabaseName.ORACLE)], ])("search (%s)", (name, dsProvider) => { const isSqs = name === "sqs" const isLucene = name === "lucene" @@ -958,7 +958,7 @@ describe.each([ }).toMatchExactly([{ name: "bar" }, { name: "foo" }]) }) - it("sorts descending", async () => { + it.only("sorts descending", async () => { await expectSearch({ query: {}, sort: "name",