Hi,
I am looking for prepared statement support in KDB. My coding environment is pure C. So something like “select timeofday from table where acl = ? and user = ?” and then bind the 2 params to diff values - 132, “jck”.
I see the ::k function and the fact that it has variable argument support but there’s nothing in the documentation which supports or denies this use case.
M
I’ve made some assumptions about acl being ints, and user being symbols.
K result=k(handle,“{[x;y]select timeofday from table where acl=x and user=y}”,ki(132),ks(“jck”),(K)0);
sorry, you probably also want to adjust your select to use cascading constraints -
K result=k(handle,“{[x;y]select timeofday from table where acl=x,user=y}”,ki(132),ks(“jck”),(K)0);
Hi, I suppose there is no performance difference of doing this, compare with I construct the many difference Q queries with difference parameter? Or It will run faster if I pass a lot difference parameters with same query with this approach?
correct, there’s no performance difference.
Much thanks, btw, How can this approach be done at other language, say R?
An example to highlight the general mechanism - in kdb+ itself you would do
q)h:hopen :host:port q)result:h({[x;y]select timeofday from table where acl=x,user=y}";132i,
jck);
i.e. you send a list to be evaluated. .z.pg by default is “value”. So the processing at the remote kdb+ side is simply
value ({[x;y]select timeofday from table where acl=x,user=y}";132i,`jck)
To do this from other languages, you would build that list and send it to the remote as a sync message.
The interface from R however
http://code.kx.com/wsvn/code/cookbook_code/r/c/qserver.c
is currently limited to a single argument char vector.