-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 04/14/2011 07:39 AM, Johannes Radinger wrote:
>> c.execute('SELECT * FROM table ORDER BY X')
> 
> Thank you very much, I just found that out myself :)

Incidentally the code above is somewhat brittle.  If the database schema
changed at some point in the future it would start giving back the wrong
column.  You should explicitly mention which columns you want and the order
you want them back in:

  SELECT rowid,x,y FROM table ORDER by x

If for example you deleted the dist column or added another one the above
code will keep working.  And you'd get an error if you renamed the y column
rather than getting whatever happened to be in that position in the schema.

I go a step further and let Python provide it into the right variables too:

  for rowid,x,y in c.execute("select rowid,x,y from table order by x"):
      print x

Roger
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk2n1K0ACgkQmOOfHg372QTIMgCePD7xIiGetklpHw84n+9IjxQj
bXsAoKg3OwpJLtcSpMB5lrjpMIC9tssH
=ST8F
-----END PGP SIGNATURE-----
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to