Does QueryToClass() support JOIN?


Recommended Posts

This works OK:

private string SQLQuery = "SELECT Data_Manager.Time_Stamp, Inverter.RemoteReady FROM Data_Manager JOIN Inverter ON Inverter.Time_Stamp LIMIT 1000"   
private FieldHandle = DB.Query(MySQLHandle, SQLQuery)
? DB.Field(FieldHandle, 1)

But I get an error "O1004 Unable to run query" for this:

private string SQLQuery = "SELECT Data_Manager.Time_Stamp, Inverter.RemoteReady FROM Data_Manager JOIN Inverter ON Inverter.Time_Stamp LIMIT 1000"
private RO = DB.QueryToClass(MySQLHandle, SQLQuery) 
? RO.FieldNames

 

Link to comment
Share on other sites

That error comes from the database itself.  First you should try typing in the query directly into your database tool outside DAQFactory.  That will often give you a more detailed error message.  If it is successful, then the issue has to do with how DAQFactory does QueryToClass().  This function is designed for high efficiency acquisition of data from the database.  As such, it first queries for the number of records so it can preallocate the required memory.  It does this by replacing everything in the select with count(*), so:

select field1, field2 from myTable

would be replaced with

select count(*) from myTable

This works fine in most cases, but some more advanced queries, possibly like yours, it does not work with.  In these cases you are forced to use the older and slower db.Query() function and read records one at a time.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.