Hi Andy, The idea sounds good but the problem i am getting "SQL error: no such function". Need I have to write a custom function set_var or it is already part of sqlite3. I tried in sqlite3 version 3.6.22.
Thanks Venkateswaran On Thu, Jan 6, 2011 at 2:09 PM, Andy Gibbs <andyg1...@hotmail.co.uk> wrote: > On Thursday, January 06, 2011 9:09 AM, stunner Easwar wrote: > > > I need to use local variables similar to sql syntax using DECLARE. My > > project involves lot of places where I need to select values from > > different > > tables and insert it into one table. In most of the cases creation of > view > > is also not feasible. Any alternative for DECLARE. > > As far as I am aware, there is no direct solution for what you want. If > you > are willing to code some custom functions (see > http://www.sqlite.org/c3ref/create_function.html), then you could create a > workaround for yourself. > > I would suggest something along the lines of: > > set_var(var_name, value) -- create or set existing variable > get_var(var_name) -- get value from variable > del_var(var_name) -- clear out variable > > in this case "set_var" could add the variable to a global or > connection-specific hash-table, and "del_var" can be used to remove it when > you're done (and to free memory). > > Its use is still a little clunky, but it might be the best you can get. > Some examples of its use: > > SELECT set_var('var1', 15); -- set var1 to 15 > SELECT set_var('var2', a) FROM tab WHERE rowid=1; -- set var2 to value > from > table > SELECT a, b, c FROM tab WHERE a = get_var('var2'); -- select from table > using variable > SELECT del_var('var2'); -- delete variable > > Of course, there are still things that need to be worked out in the > implementation (e.g. what do you want to happen if you do something like > "SELECT set_var('var', a) FROM tab" and it returns more than one row?), but > this might get you started. > > The alternative to all this, is just to embed sqlite into an > application/script that stores the variables for you. > > Andy > > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users