From: Gerhard <ger...@gm...> - 2002-03-10 02:51:13
|
Le 09/03/02 à 12:31, Ellen Spertus écrivit: > I'm having trouble decoding a resultSet from a query: > >>> from pyPgSQL.libpq import * libpq is the low-level API. If you don't have a good reason to use it, don't :) Much better is to use the DB-API interface in pyPgSQL.PgSQL. Then, you can also stay fairly portable across databases. > [snip] Using the DB-API interface, your code would look like: from pyPgSQL import PgSQL # Connect to the default database with database=user=$USER db = PgSQL.connect() # using no default values: # PgSQL.connect(host=..., database=..., user=..., password=...) # Create a cursor object (that is implicitely wrapped in a transaction) cursor = db.cursor() # Execute the query cursor.execute("select count(*) from test") # Fetch one row (here, the only one) from the resultset, # and select the first column from that row numrows = cursor.fetchone()[0] > [...] Also, can anyone point me to any documentation for pypgsql? I > haven't been able to find it. AFAIK the only documentation there is is in the README, the docstrings, and the examples in the examples directory. But as pyPgSQL "only" is an implementation of the Python DB-API 2.0 for PostgreSQL, so you can use the documentation available for the DB-API, for example: - the specification itself: http://www.python.org/topics/database/DatabaseAPI-2.0.html - an article by Andrew Kuchling: http://www.amk.ca/python/writing/DB-API.html All documentation you can find for other DB-API modules like MySQLdb also mostly applies to pyPgSQL.PgSQL. You only have to import a different module and the way the connect method works differs :) Gerhard -- mail: gerhard <at> bigfoot <dot> de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) |