Re: PyPgSQL help
От | Oliver Fromme |
---|---|
Тема | Re: PyPgSQL help |
Дата | |
Msg-id | 200407260952.i6Q9qNY6030221@lurza.secnetix.de обсуждение исходный текст |
Ответ на | PyPgSQL help (Bob Jarman <rjarman@knology.net>) |
Список | pgsql-novice |
Bob Jarman wrote: > Off-topic re Python. I'm trying to connect to Postgres 7.4.2 using > python. I'm using PyGreSQL: http://www.druid.net/pygresql/ You simply "import pgdb" and get a Python DB-API 2.0- compliant interface. Here's a short excerpt from one of my Python programs (simplified for brevity): import sys import pgdb try: db = pgdb.connect(host = "foo.bar", database = "baz", user = "chuck", password = "xxxxxxxx") except pgdb.Error, detail: print "Cannot open connection to database!" print detail sys.exit (1) try: cursor = db.cursor() except pgdb.Error, detail: print "Cannot acquire cursor for database!" print detail sys.exit (1) try: cursor.execute ("SELECT * FROM moonlight") result = cursor.fetchall() except pgdb.DatabaseError, detail: print "SQL query failed!" print detail sys.exit (1) db.close() The full Python DB-API 2.0 documentation can be found in PEP 249: http://www.python.org/peps/pep-0249.html Best regards Oliver -- Oliver Fromme, secnetix GmbH & Co KG, Oettingenstr. 2, 80538 München Any opinions expressed in this message may be personal to the author and may not necessarily reflect the opinions of secnetix in any way. Python is executable pseudocode. Perl is executable line noise.
В списке pgsql-novice по дате отправления: