On Wed, Sep 1, 2010 at 6:11 PM, Paweł Salawa <[email protected]> wrote:
> Hi,
>
> It's pretty hard to make a SELECT from same table, but using two different
> aliases for the table and at the same time also getting column names in
> results - using Tcl bindings.
>
> The SQL query would be:
>
> select a1.txt, a2.txt
> from a a1
> join a a2
> using (ref)
> where a1.lang = 'french'
> and
> a2.lang = 'english';
>
> We can either use:
> db eval $query arr {
> parray arr
> }
>
> But then we would have arr(*) = a.txt a.txt
> but only one entry: arr(a.txt) = something
> which can fail (see thread on forum I mentioned below).
>
The column names on queries that do not have AS clauses on the columns are
undefined and are subject to change. To get specific column names, use AS:
select a1.txt AS a1, a2.txt AS a2 ....
Then your arr() will contain entries a(*), a(a1), and a(a2).
>
> Other way is to use:
> set results [db eval $query]
> foreach cellValue $results {
> puts $cellValue
> }
>
> But then we lose informations about column names in results.
>
> The problem was discussed here (escpecially first and last post in the
> thread): http://forum.sqlitestudio.one.pl/viewtopic.php?f=4&t=3596
>
> One of possible solutions would be to add some prefix or suffix to array
> indexes.
>
> Other one would be to provide column names in results of [db eval $query],
> using for example flag, like: [db eval $query -withColumnNames] or
> something
> like that. The results would be: [list $columnList $tableDataList]
>
> I hope I explained it clearly enough. In case of any questions don't
> hesistate
> to ask.
>
> Regards,
> --
> Paweł Salawa
> [email protected]
> _______________________________________________
> sqlite-users mailing list
> [email protected]
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
--
D. Richard Hipp
[email protected]
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users