Re: [sqlite] how to get result of eval as list of lists?

2005-01-23 Thread Stefan Finzel
Kurt Welgehausen wrote:
proc lpartition {recsize data} {
 set ret {}
 set datalen [llength $data]
 for {set i 0; set j [expr {$recsize-1}]} \
 {$i < $datalen} {incr i $recsize; incr j $recsize} {
   lappend ret [lrange $data $i $j]
 }
 set ret}
So is there another way to determine the number of columns/or results of 
a query to calculate recsize?
A query can be quite complicate like combined SELECTs or something like 
{SELECT*,rowid from...}

db eval {SELECT*,rowid from t1} data {set columns $data(*); lappend 
records }]
set recsize [llength ${columns}]
set recordslist [lpartition ${recsize} ${records}]

This still requires the eval script and has the drawback duplicating the 
used memory.

There seems to be only two simple and fast solutions for me.
- First one is creating another db subcommand (e.g.: db evallist ...}
- Second one would be easier (but slower?) creating another element (a 
pedant to data(*)) holding exactly one row of the result array

 data(*)= a b rowid
 data(a)= 3
 data(b)= howdy!
 data(rowid)= 3
 data(typeof:a) = text
 data(typeof:b) = text
 data(typeof:rowid) = INTEGER
proposed:
 data(_)  = {3 howdy! 3}
TIA
Stefan


Re: [sqlite] how to get result of eval as list of lists?

2005-01-23 Thread Kurt Welgehausen
> Is there a fast way to get ... list of lists ... ?

proc lpartition {recsize data} {
  set ret {}
  set datalen [llength $data]
  for {set i 0; set j [expr {$recsize-1}]} \
  {$i < $datalen} {incr i $recsize; incr j $recsize} {
lappend ret [lrange $data $i $j]
  }
  set ret
}

or for a fixed record size:

proc lpartition3 data { 
  set ret {}
  foreach {col1 col2 col3} $data {  
lappend ret [list $col1 $col2 $col3]
  } 
  set ret   
}

The second version should be somewhat faster, but of course,
it's not very flexible.

Regards