On Friday, July 30, 2010 2:40 PM, Igor Tandetnik wrote:

> chris23879 <chris23879-qglwrmlu8clzjhtm8ag...@public.gmane.org> wrote:
>> I'm tring to create a paging function in sqlite. Is it possible to 
>> declare
>> and use a variable in sqlite.
>
> No. But since SQLite is embedded in your application, you can use 
> variables
> in your host programming language.

chris23879,

The suggestion by Igor is probably the best way if you can.  In terms of 
sheer performance and even simplicity, I would say almost certainly.

But sometime back in January I seem to remember someone posted a patch for a 
sort-of procedural language addon for sqlite (it didn't do stored procedures 
in the traditional sense per se, but otherwise it had some very nice 
features!).  I honestly can't remember too much right now except that I 
downloaded it for curiosities sake, and it is certainly not supported by the 
sqlite developers and I don't know its status now that 3.7.0 has come out 
but if you're interested I can have a scan through my email logs and see 
what I can find.

>From your email, it looks like you want a auto-counting row: using the 
procedural language patch you'd then do an sql query something like:

execute using ( num := 0 ) begin
  for cols[] in (select * from data) begin
    set num := num+1;
    select cols[*], num;
  end;
end;

I've just checked this, and it seems to work ok.  It looks a right pig on 
paper, but it produces quite compact and relatively speedy vdbe code (which 
is the important thing).

Anyway, if you wait long enough, I guess sqlite will one day support this 
type of thing as standard.  They've done foreign keys and wal recently - I 
expect they're already looking to the next big feature to add!!!

Rgds, Andy

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

Reply via email to