calzoneman / sync

Node.JS Server and JavaScript/HTML Client for synchronizing online media
Other
1.46k stars 235 forks source link

SQL Error on Channel Creation #822

Closed DryWood closed 4 years ago

DryWood commented 5 years ago

Hello,

I have deployed Cytube to a Ubuntu Server 19.04 VM. Using a separate VM (192.x.x.12) that hosts my mysql server 8.0.16. Connection from Cytube VM to SQL VM works as intended for most operations.

All initial tables are generated upon launch and

User generation works as intended.

Server Problem

Description of the Problem

When I try to create a Channel I receive this error : chrome_Fb1mhAJq4E

Console Error : chrome_krrJWFkYPC [ERROR] database: Legacy DB query failed. Query: INSERT INTO 'channel_ranks' VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE rank=?, Substitutions: ["UserName",5,"ChannelName",5], Error: Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'rank=5' at line 1.

In the MySQL Server, the channel_ranks table contains no info : RDCMan_hAYbcpPcHk

On page refresh, you can see that it does create the channel (test2) : chrome_h8PoNJ8AkD

The channel is also created in the Channel Table in MySQL. : RDCMan_M4MOn29IyV

But once you enter the channel. as the creator, my user does not have Channel Admin authority : chrome_yFvoIoCP9y

System Information

RDCMan_Hr0eK2Y7uc RDCMan_iAGfBddYvG RDCMan_qgCTu8pSme

calzoneman commented 5 years ago

I actually see the problem here: the ON DUPLICATE KEY references a column called rank, but rank is a reserved word in MySQL 8 (specifically, the name of a window function).

Changing this line to explicitly quote the column name in backticks should fix it: https://github.com/calzoneman/sync/blob/08f9feef7479c09e932377b57409ce2e5ce76fe2/src/database/channels.js#L381