RawSQL Plug.. mixing fieldnames ?

Is there a way to mix rawsql and servoy fieldnames ? I would need this to speed things up within a method…

my code:

plugins.rawSQL.executeSQL(‘my_server’,‘my_table’, "INSERT INTO table_new (field_A,field_B) SELECT field_A,field_B FROM table_old WHERE field_C = forms.mytable.my_variable ");

How can i solve this ?? I would need a variable in the SQL Statement… any idee ? Thanks a lot !

Rainer

rainer / dsp:
I would need a variable in the SQL Statement… any idee ? Thanks a lot !

Your SQL statement is just another string. So you can concatenate any variable in there as well like so:

var sQuery = "SELECT * FROM tableName WHERE fieldName=" + varName;

Hope this helps.

great forum

ROCLASI:

rainer / dsp:
I would need a variable in the SQL Statement… any idee ? Thanks a lot !

Your SQL statement is just another string. So you can concatenate any variable in there as well like so:

var sQuery = "SELECT * FROM tableName WHERE fieldName=" + varName;

Hope this helps.

It is better to use a prepared statement, concatenation will lead to security problems one day or another. Additionally prepared statements are faster, they make your code more readable and automatically map datatypes making eg date related queries much easier.

jaleman:
It is better to use a prepared statement, concatenation will lead to security problems one day or another. Additionally prepared statements are faster, they make your code more readable and automatically map datatypes making eg date related queries much easier.

Very true!
But if you use any version before Servoy 3.5 then you need to use the concatenation method when using the rawSQL plugin because you can’t pass any arguments in those versions.