0
Undo
Votes
I have a MySQL database table named \'events\' with a number of columns. Two of them are:
\'ReportType\', which is of type char(30)
\'ReportTime\', which is of type datetime
I want to retrieve and display all records for which the ReportTime is within the last four hours. (Note that this is not the date/time at which the row was written into the database.)
If I sign into phpMyAdmin and enter the following SQL query manually:
SELECT ReportTime, ReportType from `events` WHERE ReportTime >= CURRENT_TIMESTAMP - INTERVAL 4 HOUR
The query returns all matching rows just fine. But if I use the same query (copy/pasted so I am sure it is identical) within Art Data:
{artsqltable query=\"SELECT ReportTime, ReportType from `events` WHERE ReportTime >= CURRENT_TIMESTAMP - INTERVAL 4 HOUR\" connectionString=\"mysql,localhost,database,username,password\" headerNames=\"Report Time,Report Type\" headers=\"ReportTime,ReportType\"} {/artsqltable}
The result is:
Error executing query SELECT ReportTime, ReportType from `events` WHERE ReportTime >=CURRENT_TIMESTAMP - INTERVAL 4 HOUR: 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 \'=CURRENT_TIMESTAMP - INTERVAL 4 HOUR\' at line 1
But I believe the syntax is correct, since as I mentioned above, I copy/pasted and verified the query in the phpMyAdmin interface.
If I remove the WHERE clause:
{artsqltable query=\"SELECT ReportTime, ReportType from `events`\" connectionString=\"mysql,localhost,database,username,password\" headerNames=\"Report Time,Report Type\" headers=\"ReportTime,ReportType\"} {/artsqltable}
Then the Art Data control correctly displays all the rows in the table (although far more rows than I need for this purpose).
Is there anything you can suggest to cause this WHERE clause to work correctly?
UPDATE: This is probably no surprise, but may nonetheless be instructive. If I change the WHERE clause to:
{artsqltable query=\"SELECT ReportTime, ReportType from `events` WHERE ReportType = \'Packet data\'\" connectionString=\"mysql,localhost,database,username,password\" headerNames=\"Report Time,Report Type\" headers=\"ReportTime,ReportType\"} {/artsqltable}
then the query successfully pulls only those rows. So the problem seems to relate to the date/time comparison specifically.
\'ReportType\', which is of type char(30)
\'ReportTime\', which is of type datetime
I want to retrieve and display all records for which the ReportTime is within the last four hours. (Note that this is not the date/time at which the row was written into the database.)
If I sign into phpMyAdmin and enter the following SQL query manually:
SELECT ReportTime, ReportType from `events` WHERE ReportTime >= CURRENT_TIMESTAMP - INTERVAL 4 HOUR
The query returns all matching rows just fine. But if I use the same query (copy/pasted so I am sure it is identical) within Art Data:
{artsqltable query=\"SELECT ReportTime, ReportType from `events` WHERE ReportTime >= CURRENT_TIMESTAMP - INTERVAL 4 HOUR\" connectionString=\"mysql,localhost,database,username,password\" headerNames=\"Report Time,Report Type\" headers=\"ReportTime,ReportType\"} {/artsqltable}
The result is:
Error executing query SELECT ReportTime, ReportType from `events` WHERE ReportTime >=CURRENT_TIMESTAMP - INTERVAL 4 HOUR: 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 \'=CURRENT_TIMESTAMP - INTERVAL 4 HOUR\' at line 1
But I believe the syntax is correct, since as I mentioned above, I copy/pasted and verified the query in the phpMyAdmin interface.
If I remove the WHERE clause:
{artsqltable query=\"SELECT ReportTime, ReportType from `events`\" connectionString=\"mysql,localhost,database,username,password\" headerNames=\"Report Time,Report Type\" headers=\"ReportTime,ReportType\"} {/artsqltable}
Then the Art Data control correctly displays all the rows in the table (although far more rows than I need for this purpose).
Is there anything you can suggest to cause this WHERE clause to work correctly?
UPDATE: This is probably no surprise, but may nonetheless be instructive. If I change the WHERE clause to:
{artsqltable query=\"SELECT ReportTime, ReportType from `events` WHERE ReportType = \'Packet data\'\" connectionString=\"mysql,localhost,database,username,password\" headerNames=\"Report Time,Report Type\" headers=\"ReportTime,ReportType\"} {/artsqltable}
then the query successfully pulls only those rows. So the problem seems to relate to the date/time comparison specifically.