Page 1 of 1

Error in SQL Syntax - MySQL Event issue

Posted: Fri Feb 01, 2019 10:20 pm
by mpriest
I am using this query in the MySQL services tab from a Meteobridge Pro:

INSERT INTO 'wassenaarstrand' ('ID', 'DateTime', 'TempOutCur', 'WindSpeedCur', 'WindDirCur', 'WindGust10', 'WindDirAvg10') VALUES (NULL, '[YYYY]-[MM]-[DD] [hh]:[mm]:[ss]', '[th0temp-act]', '[wind0wind-act=kn]', '[wind0dir-act]', '[wind0wind-max10=kn]', '[wind0dir-avg10]')

The response is an error in SQL syntax.

Could you help me please with spotting the error ?

Re: Error in SQL Syntax - MySQL Event issue

Posted: Sat Feb 02, 2019 5:49 am
by Ag2000CO
I see several problems.
1. The table name in the INSERT query should not be quoted. INSERT INTO wassenaarstrand ...

2. If you are not sure of the column order in the table include the column names in a comma separated list in the order you will provide the VALUES without quotes.
INSERT INTO wassenaarstrand (ID, DateTime, TempOutCur, WindSpeedCur, WindDirCur, WindGust10, WindDirAvg10) VALUES ...

3. If you know the column order in the table wassenaarstrand then you do not need to include the column names, BUT you must present the VALUES in the same order as the table columns were defined. NOTE the values are quoted (except the defined value NULL).
INSERT INTO wassenaarstrand VALUES (NULL, '[YYYY]-[MM]-[DD] [hh]:[mm]:[ss]', '[th0temp-act]', '[wind0wind-act=kn]', '[wind0dir-act]', '[wind0wind-max10=kn]', '[wind0dir-avg10]')

Of course MB when processing the request will replace the values within square brackets [] with the appropriate values before submitting the MySQL query.

A. I assumed that the first table column, ID, was defined as "AUTO_INCREMENT" Otherwise the VALUES (NULL... would also be an error in an INSERT query.