Python Database Objects (PDO) 1.2.0 Released
jfranz at neurokode.com
Mon Nov 17 11:20:29 CET 2003
I'll reply to this, if that's ok. Keep in mind I can't sleep, so
typos may abound.
I guess what PDO comes down to is (an attempt at) ease-of-learning
and ease-of-use without sacrificing power. PDO is built on the
DBAPI, but just provides a (hopefully) higher-level interface.
Having said that, lets dive into the differences between a DBAPI
cursor and a PDO Resultset.
A Resultset is actually very different from a cursor - The first and
most blatant difference being that with a Resultset, you get column
access by name.
With a DBAPI cursor, you create the cursor first, then perform an
execute on the cursor, then do a fetchXXX (depending upon
if you want one row at a time or many, or all). The data returned
is separate from the cursor, and is a sequence of sequences.
If you do a fetchmany or fetchall, iteration over the results is
Also, data about the result columns is stored separately
from the columns themselves, in a .description field of the cursor.
PDO Resultset objects are created with the same statement
in which you perform your query, no manual cursor creation required
PDO Resultsets also allow for easy transversal of the results, in a
forwards or backwards or random manner, via the .move(x), .next(),
.prev(), .moveto(n) and other methods. Each method will return 0 if
the destination is out-of-bounds.
Data about the columns is accessed as if it were intrinsic to the
columns - thus Resultset columns in PDO are objects with member
Here's a quick example of a simple query and loop-over results, first
via DBAPI, then via PDO.
mycon = MySQLdb(user='test', passwd='foobar', db='sample')
mycursor = mycon.cursor()
mycursor.execute("SELECT * FROM Customers")
results = mycursor.fetchall()
for row in range(0, len(results)):
print "Name: " + row
print "Address: " + row
print "Size of 'Name' column in the db: " +
mycon = pdo.connect("module=MySQLdb;user=test;passwd=foobar;db=sample")
results = mycon.open("SELECT * FROM Customers")
print "Name: " + results['Name'].value
print "Address: " + results['Address'].value
print "Size of 'Name' column in the db: " + str(results['Name'].length)
NeuroKode Labs, LLC
----- Original Message -----
From: "Rene Pijlman" <reply.in.the.newsgroup at my.address.is.invalid>
To: <python-list at python.org>
Sent: Monday, November 17, 2003 2:27 AM
Subject: Re: Python Database Objects (PDO) 1.2.0 Released
> Bryan J Gudorf:
> >PDO, an open source python module for interfacing with RDBMS (SQL
> >databases), has now reached 1.2.0!
> I just browsed the documentation, but I don't quite understand what
> advantages PDO offers over using DBAPI directly. A resultset object looks
> very similar to a cursor.
> What are the advantages IYO?
> René Pijlman
More information about the Python-list