On 6 Jan 2011, at 08:39, Andy Gibbs 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.

DECLARE is an extension which only works within stored procedures written in 
certain vendors' procedural SQL extensions. Since SQLite does not have any 
stored procedure facility (no CALL, no EXECUTE) the OP will need to redesign 
his/her application on a larger scale than the original question presumes; 
given that, why not remove the requirement for DECLARE at the same time? It 
will probably disappear naturally as the stored procedure logic is removed.

If it is still required something like the API you suggested is about as good 
as you can get. You need a variable hashtable per connection. I would dispense 
with del_var and instead register commit and rollback hooks to clear out 
declared variables when the transaction which declared them ends; this is both 
more like the behaviour of DECLARE and is more defensive in that it will leave 
things tidy without requiring programmers to explicitly free their variables. 
Make sure that you define the behaviour of get_var when a variable of that name 
has not been set: I suggest that raising an error is the most useful thing you 
can do in this situation.

Phil
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to