Attention!

These forums are not monitored. We provide the discussions forum as a place for users of free extensions to help each other and find answers, not as a place for our staff to deal with urgent support issues. Our staff very rarely responds to forum posts. Occasionally we will respond to forum posts but responses are not guaranteed.

If you have an active subscription for a commercial extension and wish to receive support please login to your Artetics.com account and submit a ticket. The ticketing system is the best way for you to get assistance in a timely manner.

Thank you!

  Monday, 15 July 2013
  2 Replies
  3.7K Visits
0
Votes
Undo
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.