Using dynamics query by using columnnames from variable

Posted by Wim on 21-Aug-2015 07:11

The variable is containing the column name as a relation between 2 objects, i.e. R23145 or R_vehicle_vehicletyre.

Here is a piece of code i try to use, but an error occurs:

var v_tussenresultaat = '{!orderlinem_searchresult#value}';
var v_temp = v_tussenresultaat.split(",");

rbv_api.println(v_temp.length);

for (i=0; i<v_temp.length; i++)
{
var v_zoekelement = v_tempIdea;
var v_length = v_zoekelement.indexOf(".");
var v_relatie = v_zoekelement.substring(0,v_length);
var v_tijdelijk = 'iets';
var v_id = v_zoekelement.substring(v_length + 1);
rbv_api.println(v_relatie);
rbv_api.println(v_id);
var v_arr = [];
v_arr = rbv_api.selectQuery2("SELECT name FROM discount WHERE v_relatie = ?", 0, 1000, v_id, v_relatie);
rbv_api.printArr(v_arr);

}

All Replies

Posted by Karthikeyan Bhaskaran on 21-Aug-2015 07:19

Hello Wim, what error do you see? Can you post a screenshot?

Posted by Wim on 21-Aug-2015 07:38

This is the errromessage in debug mode:

Error  Error in SQL Query

SELECT name FROM discount WHERE v_relatie = ?

RB_1997: Error preparing statement for query

SELECT A.OBJ_NAME FROM RB_OBJ_DATA A WHERE A.OBJ_DEF_ID=296012 AND (v_relatie = ?)

[DataDirect][OpenEdge JDBC Driver][OpenEdge] Column "V_RELATIE" cannot be found or is not specified for query. (13865) (line #26) in formula:

var rbv_api = new Packages.com.rb.core.services.api.ServerSideAPI(000000, 24476);

var v_tussenresultaat = '30.00000000,R_discount_tyresize.74018';

var v_temp = v_tussenresultaat.split(",");

rbv_api.println(v_temp.length);

for (i=0; i<v_temp.length; i++)

 {    

   var v_zoekelement =...

Posted by srikanth kasavajhula on 26-Aug-2015 09:13

In the above select query you have wriiten v_relatie  inside doublequotes which makes it a string .

In order to access the column name concactenate the value of the variable v_relatie

Ex: query="select .... where" + v_realtie +"=?"..;

rbv_api.selectQuery2(query,rowFrom, maxRows, arg1, arg2…))

This thread is closed