Hello.

I need to create a sensor retrieving data from a MySQL database, but the table name is dynmaic. So i have to use a Prepared Statement to produce the query string first As in:

SET @c = '131';
SET @tb = CONCAT('hist_',YEAR(CURDATE()), LPAD(MONTH(CURDATE()),2,0));
SET @s = CONCAT('select truncate(sum(stime)/60,0) as min from ', @tb, ' where c_id=',@c,' and `time` > CURDATE()'); 
PREPARE stmt1 FROM @s; 
EXECUTE stmt1; 
DEALLOCATE PREPARE stmt1;

But I only get "Fatal Error encountered during command execution". I tried thru the gui from SQL_V2.exe, same result.

Can someone point me to the right direction i should take to make this work? Thank you very much.


Article Comments

Dear edm09

While this could be a valid SQL statement, the code injection protection we use via Dotnet catches the EXECUTE command and prevents the execution. I am sorry, there is no way around this.


May, 2016 - Permalink

Thanks.

I'll try to wrap it on a procedure and just call the proc, this should work right?


May, 2016 - Permalink

Dear edm09

That should work.


May, 2016 - Permalink