Python数据库对象(PDO)1.2.0发布 [英] Python Database Objects (PDO) 1.2.0 Released

查看:124
本文介绍了Python数据库对象(PDO)1.2.0发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PDO是一个用于与RDBMS(SQL

数据库)连接的开源python模块,现已达到1.2.0! PDO为python开发人员提供了一个面向对象的API,类似于ADO或JDBC的
。 PDO功能列

按名称访问。这个新版本增加了对cx_Oracle,DB2和

adodbapi模块的支持,允许用户将PDO用于各种数据库

系统。现在支持9种不同的DBAPI模块,允许PDO几乎任何RDBMS都可以使用
。此版本中还添加了其他功能,例如查询

参数,以及通常的

错误修复。


PDO是在BSD风格许可下发布的。


PDO支持以下DBAPI python模块和数据库:

MySQLdb(支持MySQL)

PySQLite(SQLite)

pgdb(PostgreSQL)

kinterbasdb(Firebird,Interbase)

mxODBC(很多)

pyDB2(IBM的DB / 2)

cx_Oracle(Oracle)

adodbapi(仅限Windows - 任何带有OLE DB提供程序或ODBC的RDBMS < br $>
司机)


随着我们在本系列中向前推进,我们将进一步增加

功能

和支持。我们非常感谢社区支持和反馈,以便我们能够尽可能地为PDO提供支持。

Python数据库对象的下载可在SourceForge上获得.Net

或欲了解更多信息,请访问pdo.neurokode.com。


Bryan J Gudorf

~NeuroKode Labs

解决方案

Bryan J Gudorf:

PDO,一个用于与RDBMS连接的开源python模块(SQL
数据库) ,现在已达到1.2.0!




我刚刚浏览了文档,但我不太明白PDO提供的优惠是什么?直接使用DBAPI。结果集对象看起来非常类似于游标。


IYO有哪些优势?


-
$ b $bRenéPijlman


我会回答这个问题,如果没问题的话。请记住,我无法入睡,所以

错别字可能比比皆是。


我想PDO归结为(试图)轻松 - 学习

和易用性而不牺牲力量。 PDO建立在

DBAPI上,但只是提供了一个(希望)更高级别的界面。

话虽如此,让我们深入探讨DBAPI之间的差异
光标和PDO结果集。


结果集实际上与游标非常不同 - 第一个和

最显着的区别在于一个Resultset,你得到列

按名称访问。


使用DBAPI游标,先创建游标,然后执行

执行光标,然后执行fetchXXX(取决于

,如果你想一次一行或多行,或全部)。返回的数据

与光标分开,是一系列序列。

如果你进行fetchmany或fetchall,迭代结果就是

您的责任。

此外,有关结果列的数据将单独存储

来自列本身,位于光标的.description字段中。


PDO结果集对象使用相同的语句创建

,在其中执行查询,无需手动创建游标



PDO结果集还允许通过.move(x),. next(),


向前或向后或随机方式轻松颠换结果。
..prev(),. move(n)和其他方法。如果目的地超出界限,每个方法将返回0

有关列的数据被访问,就好像它是
$ b固有的一样。 $ b列 - 因此PDO中的Resultset列是具有成员

变量的对象。


这是一个简单查询和循环结果的快速示例,首先通过DBAPI获得
,然后通过PDO。


DBAPI:

导入MySQLdb


mycon = MySQLdb(user =''test'',passwd =''foobar'',db =''sample'')

mycursor = mycon.cursor()

mycursor.execute(" SELECT * FROM Customers")

results = mycursor.fetchall()

范围内的行(0,len(结果) ):

print" Name:" +行[1]

print"地址:" + row [3]

print" db中''Name''列的大小:" +

str(mycursor.description [1] [3])


------------

PDO:

导入pdo

mycon = pdo.connect(" module = MySQLdb; user = test; passwd = fooba r; db =样本)

results = mycon.open(" SELECT * FROM Customers")

而results.next():

print" ;姓名: + results [''Name'']。value

print" Address:" + results [''Address'']。value

print" db中''Name''列的大小:" + str(结果[''姓名'']。长度)


------------------------ --------

~Jon Franz

NeuroKode Labs,LLC


-----原帖-----

来自:Rene Pijlman < re ******************** @ my.address.is.invalid>

收件人:< py ***** ****@python.org>

已发送:2003年11月17日星期一2:27

主题:Re:Python数据库对象(PDO)1.2.0发布

Bryan J Gudorf:

PDO,一个用于与RDBMS(SQL
数据库)连接的开源python模块,现在达到了1.2.0!



我刚刚浏览了文档,但我不太明白PDO提供的优势直接使用DBAPI。结果集对象看起来非常类似于光标。

IYO有哪些优势?

-
RenéPijlman



Jon Franz:

结果集实际上与游标非常不同 - 第一个和最明显的区别是使用Resultset,您可以按名称访问列




感谢Jon,澄清了它。


-
$ b $bRenéPijlman


PDO, an open source python module for interfacing with RDBMS (SQL
databases), has now reached 1.2.0! PDO provides an object oriented API,
similar to that of ADO or JDBC, to python developers. PDO features column
access by name. This new release adds support for the cx_Oracle, DB2 and
adodbapi modules, allowing users to use PDO with a variety of database
systems. 9 different DBAPI modules are now supported, allowing for PDO to
be used with almost any RDBMS. Additional features, such as query
parameters, have also been added in this release, as well as the usual
bug-fixes.

PDO is released under a BSD style license.

PDO supports the following DBAPI python modules and databases:
MySQLdb (supports MySQL)
PySQLite (SQLite)
pgdb (PostgreSQL)
kinterbasdb (Firebird, Interbase)
mxODBC (Many)
pyDB2 (IBM''s DB/2)
cx_Oracle (Oracle)
adodbapi (windows only - any RDBMS with an OLE DB provider or ODBC
driver)

As we move forward in this series we will be adding further
functionality
and support. Community support and feedback is appreciated so that we can
make
PDO as useful as possible.
Downloads for Python Database Objects are available on SourceForge.Net
or for more information please visit pdo.neurokode.com.

Bryan J Gudorf
~NeuroKode Labs

解决方案

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


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
your responsibility.
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
beforehand.
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
variables.

Here''s a quick example of a simple query and loop-over results, first
via DBAPI, then via PDO.

DBAPI:
import MySQLdb

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[1]
print "Address: " + row[3]
print "Size of ''Name'' column in the db: " +
str(mycursor.description[1][3])

------------
PDO:
import pdo

mycon = pdo.connect("module=MySQLdb;user=test;passwd=fooba r;db=sample")
results = mycon.open("SELECT * FROM Customers")
while results.next():
print "Name: " + results[''Name''].value
print "Address: " + results[''Address''].value
print "Size of ''Name'' column in the db: " + str(results[''Name''].length)

--------------------------------
~Jon Franz
NeuroKode Labs, LLC

----- Original Message -----
From: "Rene Pijlman" <re********************@my.address.is.invalid>
To: <py*********@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



Jon Franz:

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.



Thanks Jon, that clarifies it.

--
René Pijlman


这篇关于Python数据库对象(PDO)1.2.0发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆