From 8e6e8da06c4e28e8ceadd0644951fc2f8f33a5f7 Mon Sep 17 00:00:00 2001 From: Daniel Spaude Date: Sun, 23 Oct 2022 21:16:00 +0400 Subject: [PATCH] qrcode column type: fix wrong sql query construction when using formula as value column --- .../sql-data-mapper/lib/sql/BaseModelSqlv2.ts | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts index 30c4d5424a..1acfad08e8 100644 --- a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts +++ b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts @@ -1368,7 +1368,57 @@ class BaseModelSqlv2 { }); console.log('qrCodeColumn', qrCodeColumn); console.log('qrValueColumn', qrValueColumn); - qb.select({ [column.column_name]: qrValueColumn.column_name }); + // qb.select({ [column.column_name]: qrValueColumn.column_name }); + + switch (qrValueColumn.uidt) { + case UITypes.Formula: + { + const formula = + await qrValueColumn.getColOptions(); + if (formula.error) continue; + const selectQb = await formulaQueryBuilderv2( + formula.formula, + null, + this.dbDriver, + this.model + // this.aliasToColumn + ); + // todo: verify syntax of as ? / ?? + // qb.select( + // this.dbDriver.raw(`?? as ??`, [ + // selectQb.builder, + // sanitize(column.title), + // ]) + // ); + // qb.select({ + // [column.column_name]: this.dbDriver.raw(`?? as ??`, [ + // selectQb.builder, + // sanitize(column.title), + // ]), + // }); + + qb.select({ + [column.column_name]: selectQb.builder, + }); + + // const formulOption = await col.getColOptions(); + // const { builder } = await formulaQueryBuilderv2( + // formulOption.formula, + // alias, + // knex, + // model, + // { ...aliasToColumn, [col.id]: null } + // ); + // builder.sql = '(' + builder.sql + ')'; + // aliasToColumn[col.id] = builder; + } + break; + default: { + qb.select({ [column.column_name]: qrValueColumn.column_name }); + break; + } + } + break; } case 'Formula': @@ -1410,6 +1460,7 @@ class BaseModelSqlv2 { break; } } + console.debug('qb.toQuery(): ', qb.toQuery()); qb.select(res); }