On 10/8/08, Tim Streater <[EMAIL PROTECTED]> wrote:
> At 14:56 -0400 08/10/08, Igor Tandetnik wrote:
>  >Shaun R. <[EMAIL PROTECTED]> wrote:
>  >>  Anybody help me out here, trying to grab column info based on the
>  >>  columns name.  Examples i keep seeing people seam to use the colunm
>  >>  number but cant you access these values by the name?
>  >
>  >Not in general. Consider:
>  >
>  >select 1, 2, 3*5;
>  >
>  >What do you think the column names are here?
>  >
>  >However, see sqlite3_column_name[16], sqlite3_column_origin_name[16].
>  >With these, you can enumerate all the columns, get the name of each,
>  >figure out whether it's the one you want and thus obtain its number.
>
>
> In PHP I'm doing something like this:
>
>  $dbh    = new PDO ("sqlite:mydb");
>  $resorg = $dbh->query ("select * from my_table where absid='$PTR_org'");
>  $orgs   = $resorg->fetch (PDO::FETCH_ASSOC);
>  $organisation = $orgs["name"];
>  $address = $orgs["address"];
>
>  I never use the column number.

That is a facility provided by your specific driver. Perl's DBD (and
so, I am assuming, most other mature drivers) allow the same facility.
Nevertheless, Igor's point is worth underscoring... the column name is
a moving concept. If you use the AS keyword, then the column name is
what you alias it to. See

Last login: Wed Oct  8 09:54:19 on console
[02:30 PM] ~$sqlite3
SQLite version 3.5.9
Enter ".help" for instructions
sqlite> .m col
sqlite> .h on
sqlite> SELECT 1 AS foo, 2 AS elephant, 3 * 4 AS stars, 12;
foo         elephant    stars       12
----------  ----------  ----------  ----------
1           2           12          12
sqlite>




-- 
Puneet Kishor http://punkish.eidesis.org/
Nelson Institute for Environmental Studies http://www.nelson.wisc.edu/
Open Source Geospatial Foundation (OSGeo) http://www.osgeo.org/
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to