crud icon indicating copy to clipboard operation
crud copied to clipboard

WHERE clause doesnt work for mariadb

Open Duckybee opened this issue 3 years ago • 1 comments

Hello, So i are facing an issue today with nestjs/crud version after May 7 for our MariaDB. The query being generated after May 7 has this format:

SELECT .... 

FROM `watchlist` `WatchSubcription` 

WHERE ("WatchSubcription"."subscriberEmail" = '[email protected]') 

The query we had before is:

SELECT .... 

FROM `watchlist` `WatchSubcription` 
WHERE `WatchSubcription`.`subscriberEmail` = '[email protected]'

We are running MaridDB version 10.3

I believe this is the changes that introduce that issue https://github.com/nestjsx/crud/commit/4a85b242221efa2e4f55afe876fb51aa76e4e346

protected getFieldWithAlias(field: string, sort: boolean = false) {
    /* istanbul ignore next */
    const i = this.dbName === 'mysql' ? '`' : '"';

In file: packages/crud-typeorm/src/typeorm-crud.service.ts

Duckybee avatar Apr 14 '21 06:04 Duckybee

Hello, I found the same issue, but requests showing this error

ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '."preferido" = true)

I ran the sql in my database manager and got the same, but when changing the sql to `preferido`=true the request finish as expected.

The problen got fixed in the same line you are pointing

const i = this.dbName === 'mysql' ? '`' : '"';

But got fixed if set like this

const i = ['mysql','mariadb'].includes(this.dbName) ? '`' : '"';

sgClaudia98 avatar Dec 28 '21 01:12 sgClaudia98