SQL Syntax Error?

Expected behavior

Access the datas in my database

Actual behavior

When i try to access one of my table, i got a server error

This happen with only ONE of my table, the other is fully working without any problem.

Any idea on how i can resolve this?

Failure Logs

SequelizeDatabaseError: 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 '*) AS count FROM db_mcs AS dbMcs’ at line 1
at Query.formatError (C:\laragon\www\VHC\node_modules\sequelize\lib\dialects\mysql\query.js:243:16)
at Query.handler [as onResult] (C:\laragon\www\VHC\node_modules\sequelize\lib\dialects\mysql\query.js:50:23)
at Query.execute (C:\laragon\www\VHC\node_modules\mysql2\lib\commands\command.js:30:14)
at Connection.handlePacket (C:\laragon\www\VHC\node_modules\mysql2\lib\connection.js:408:32)
at PacketParser.onPacket (C:\laragon\www\VHC\node_modules\mysql2\lib\connection.js:70:12)
at PacketParser.executeStart (C:\laragon\www\VHC\node_modules\mysql2\lib\packet_parser.js:75:16)
at Socket. (C:\laragon\www\VHC\node_modules\mysql2\lib\connection.js:77:25)
at Socket.emit (events.js:315:20)
at addChunk (_stream_readable.js:295:12)
at readableAddChunk (_stream_readable.js:271:9)
at Socket.Readable.push (_stream_readable.js:212:10)
at TCP.onStreamRead (internal/stream_base_commons.js:186:23)

Context

Please provide any relevant information about your setup.

  • Package Version: Lastest
  • Express Version: Lastest
  • Sequelize Version: Lastest
  • Database Dialect: MySQL
  • Database Version: Lastest
  • Project Name: VHC

Hi @j.cange, welcome to the Forest Admin community :evergreen_tree:

I guess the name of the table that does not display properly is db_mcs.
Could you share the DDL of the table to let us investigate with a similar table?

Do you have the full SQL query that fails in your server logs?

Thanks for your help.

Hi @arnaud,

I don’t have the full SQL query since it’s not one i created… The only informations i have is this :

'*) AS count FROM db_mcs AS dbMcs

For the DDL : Sorry but i don’t understand what is it… (I’m still learning about database management)

About the full SQL query, you can add the NODE_ENV=development environment variable in your .env file, it should activate the SQL queries logs once your server restarted.

About the DDL, it is basically the set of SQL instructions that builds you table structure (name, columns, types, indexes,…). If you don’t know how to find that, a screenshot of the table definition could also help.

Is that what you need? :confused:

I’ve added the NODE_ENV variable to my .env i get the same message with extra informations :

[forest] ­ƒî│­ƒî│­ƒî│ Unexpected 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 ') AS count FROM db_mcs AS dbMcs’ at line 1
SequelizeDatabaseError: 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 '
) AS count FROM db_mcs AS dbMcs’ at line 1
at Query.formatError (C:\laragon\www\VHC\node_modules\sequelize\lib\dialects\mysql\query.js:243:16)
at Query.handler [as onResult] (C:\laragon\www\VHC\node_modules\sequelize\lib\dialects\mysql\query.js:50:23)
at Query.execute (C:\laragon\www\VHC\node_modules\mysql2\lib\commands\command.js:30:14)
at Connection.handlePacket (C:\laragon\www\VHC\node_modules\mysql2\lib\connection.js:408:32)
at PacketParser.onPacket (C:\laragon\www\VHC\node_modules\mysql2\lib\connection.js:70:12)
at PacketParser.executeStart (C:\laragon\www\VHC\node_modules\mysql2\lib\packet_parser.js:75:16)
at Socket. (C:\laragon\www\VHC\node_modules\mysql2\lib\connection.js:77:25)
at Socket.emit (events.js:315:20)
at addChunk (_stream_readable.js:295:12)
at readableAddChunk (_stream_readable.js:271:9)
at Socket.Readable.push (_stream_readable.js:212:10)
at TCP.onStreamRead (internal/stream_base_commons.js:186:23)
From previous event:
at Query.run (C:\laragon\www\VHC\node_modules\sequelize\lib\dialects\mysql\query.js:39:12)
at C:\laragon\www\VHC\node_modules\sequelize\lib\sequelize.js:641:29
From previous event:
at C:\laragon\www\VHC\node_modules\sequelize\lib\sequelize.js:641:12
From previous event:
at C:\laragon\www\VHC\node_modules\sequelize\lib\sequelize.js:637:10
at C:\laragon\www\VHC\node_modules\retry-as-promised\index.js:70:21
at new Promise ()
at retryAsPromised (C:\laragon\www\VHC\node_modules\retry-as-promised\index.js:60:10)
at C:\laragon\www\VHC\node_modules\sequelize\lib\sequelize.js:627:30
From previous event:
at Sequelize.query (C:\laragon\www\VHC\node_modules\sequelize\lib\sequelize.js:576:23)
at QueryInterface.rawSelect (C:\laragon\www\VHC\node_modules\sequelize\lib\query-interface.js:1160:27)
at Function.aggregate (C:\laragon\www\VHC\node_modules\sequelize\lib\model.js:1990:32)
at C:\laragon\www\VHC\node_modules\sequelize\lib\model.js:2042:19
at processImmediate (internal/timers.js:456:21)
From previous event:
at Function.count (C:\laragon\www\VHC\node_modules\sequelize\lib\model.js:2026:8)
at C:\laragon\www\VHC\node_modules\forest-express-sequelize\dist\services\resources-getter.js:357:30

Could you share your .env file values (hidding your DATABASE_URL, FOREST_ENV_SECRET, FOREST_AUTH_SECRET that are sensitive values)?

APPLICATION_PORT=3310
CORS_ORIGINS=
DATABASE_SSL=false
NODE_ENV=development

With this .env configuration, on top of this log:

[forest] ­ƒî│­ƒî│­ƒî│ Unexpected 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 ' *) AS `count` FROM `db_mcs` AS `dbMcs` ’ at line 1*

you should have the full SQL query that fails.
That is really strange that you can’t see it in your server console.

Okay i’ve found the query sorry i didn’t correctly open my eyes…

Executing (default): SELECT count(dbMcs.*) AS count FROM db_mcs AS dbMcs;

Thanks!

Can you run this SQL query directly in your database and try to find what’s wrong with it?
I guess:
SELECT count(*) AS count FROM db_mcs;
should works right?

Another question I have in mind about case sensitivity:
on what machine OS (linux, mac, windows) is running your database?

Our server is under Linux (Debian 9)

For the query here’s the result (sorry our phpmyadmin is in french)

Thank you, and what about SELECT count(dbMcs.*) AS count FROM db_mcs AS dbMcs; query?

It return me an error :

#1064 - Syntax error near ‘*) AS count FROM db_mcs AS dbMcs LIMIT 0, 25’ on line 1

Hi @j.cange,

I just pulled a docker database using mariadb and generated a lumber project, and I’m sadly not able to reproduce your issue.

This is weird to me though, since running SELECT COUNT(*) FROM foo; works fine on mariadb, but SELECT COUNT(foo.*) FROM foo; does not.

Also, I would suggest to try specifying the sequelize dialect to mariadb inside the models/index.js of your project, just in case this would help (But since I’m not able to reproduce, I cannot check if it would help or not). You can see the syntax here

Let me know if that helps

Hi !

So i’ve followed your link and i managed to specify the dialect. Now the log return the same error as previously but with a little more info :

sql: SELECT count(dbMcs.*) AS count FROM db_mcs AS dbMcs; - parameters:[ ]

The “Parameters:[ ]” is new …

Something strange is that, i have another table in this database and i can access it without any problem :

Executing (default): SELECT count(employees.ID) AS count FROM employees AS employees;
GET /forest/employees/count?fields%5Bemployees%5D=accessLevel%2Cemail%2Cid%2Cpass&searchExtended=0&timezone=Europe%2FBrussels 304 - - 16.592 ms

If the dialect does not fix your issue, I think you should remove it.

Since I cannot reproduce your issue, could you answer a few question related to your DBMS :

Could you tell me which version of mariadb you are using ?
Is there any specific configuration related to that particular table ?
Are you using a all-in-one software (Like MAMP/LAMP/WAMP) to host your database (From the stack trace it looks like it, but I just want to be sure) ?

Well it looks like i figured out what the problem was…

Basically i used an old CSV to populate my table. In this CSV there was no ID as primary key. So i added an ID and everything work now !

Pretty dumb problem…

Thanks for your time and very sorry for the incovenience due to my stupidity :frowning:

1 Like