PEP: 249
Title: Python Database API Specification v2.0
Version: $Revision: 1555 $
Author: db-sig@python.org (Python Database SIG)
Editor: mal@lemburg.com (Marc-Andre Lemburg)
Status: Final
Type: Informational
Replaces: 248
Release-Date: 07 Apr 1999
Introduction
This API has been defined to encourage similarity between the
Python modules that are used to access databases. By doing this,
we hope to achieve a consistency leading to more easily understood
modules, code that is generally more portable across databases,
and a broader reach of database connectivity from Python.
The interface specification consists of several sections:
* Module Interface
* Connection Objects
* Cursor Objects
* DBI Helper Objects
* Type Objects and Constructors
* Implementation Hints
* Major Changes from 1.0 to 2.0
Comments and questions about this specification may be directed
to the SIG for Database Interfacing with Python
(db-sig@python.org).
For more information on database interfacing with Python and
available packages see the Database Topic
Guide at http://www.python.org/topics/database/.
This document describes the Python Database API Specification 2.0
and a set of common optional extensions. The previous version 1.0
version is still available as reference, in PEP 248. Package
writers are encouraged to use this version of the specification as
basis for new interfaces.
Module Interface
Access to the database is made available through connection
objects. The module must provide the following constructor for
these:
connect(parameters...)
Constructor for creating a connection to the database.
Returns a Connection Object. It takes a number of
parameters which are database dependent. [1]
These module globals must be defined:
apilevel
String constant stating the supported DB API level.
Currently only the strings '1.0' and '2.0' are allowed.
If not given, a DB-API 1.0 level interface should be
assumed.
threadsafety
Integer constant stating the level of thread safety the
interface supports. Possible values are:
0 Threads may not share the module.
1 Threads may share the module, but not connections.
2 Threads may share the module and connections.
3 Threads may share the module, connections and
cursors.
Sharing in the above context means that two threads may
use a resource without wrapping it using a mutex semaphore
to implement resource locking. Note that you cannot always
make external resources thread safe by managing access
using a mutex: the resource may rely on global variables
or other external sources that are beyond your control.
paramstyle
String constant stating the type of parameter marker
formatting expected by the interface. Possible values are
[2]:
'qmark' Question mark style,
e.g. '...WHERE name=?'
'numeric' Numeric, positional style,
e.g. '...WHERE name=:1'
'named' Named style,
e.g. '...WHERE name=:name'
'format' ANSI C printf format codes,
e.g. '...WHERE name=%s'
'pyformat' Python extended format codes,
e.g. '...WHERE name=%(name)s'
The module should make all error information available through
these exceptions or subclasses thereof:
Warning
Exception raised for important warnings like data
truncations while inserting, etc. It must be a subclass of
the Python StandardError (defined in the module
exceptions).
Error
Exception that is the base class of all other error
exceptions. You can use this to catch all errors with one
single 'except' statement. Warnings are not considered
errors and thus should not use this class as base. It must
be a subclass of the Python StandardError (defined in the
module exceptions).
InterfaceError
Exception raised for errors that are related to the
database interface rather than the database itself. It
must be a subclass of Error.
DatabaseError
Exception raised for errors that are related to the
database. It must be a subclass of Error.
DataError
Exception raised for errors that are due to problems with
the processed data like division by zero, numeric value
out of range, etc. It must be a subclass of DatabaseError.
OperationalError
Exception raised for errors that are related to the
database's operation and not necessarily under the control
of the programmer, e.g. an unexpected disconnect occurs,
the data source name is not found, a transaction could not
be processed, a memory allocation error occurred during
processing, etc. It must be a subclass of DatabaseError.
IntegrityError
Exception raised when the relational integrity of the
database is affected, e.g. a foreign key check fails. It
must be a subclass of DatabaseError.
InternalError
Exception raised when the database encounters an internal
error, e.g. the cursor is not valid anymore, the
transaction is out of sync, etc. It must be a subclass of
DatabaseError.
ProgrammingError
Exception raised for programming errors, e.g. table not
found or already exists, syntax error in the SQL
statement, wrong number of parameters specified, etc. It
must be a subclass of DatabaseError.
NotSupportedError
Exception raised in case a method or database API was used
which is not supported by the database, e.g. requesting a
.rollback() on a connection that does not support
transaction or has transactions turned off. It must be a
subclass of DatabaseError.
This is the exception inheritance layout:
StandardError
|__Warning
|__Error
|__InterfaceError
|__DatabaseError
|__DataError
|__OperationalError
|__IntegrityError
|__InternalError
|__ProgrammingError
|__NotSupportedError
Note: The values of these exceptions are not defined. They should
give the user a fairly good idea of what went wrong, though.
Connection Objects
Connection Objects should respond to the following methods:
.close()
Close the connection now (rather than whenever __del__ is
called). The connection will be unusable from this point
forward; an Error (or subclass) exception will be raised
if any operation is attempted with the connection. The
same applies to all cursor objects trying to use the
connection. Note that closing a connection without
committing the changes first will cause an implicit
rollback to be performed.
.commit()
Commit any pending transaction to the database. Note that
if the database supports an auto-commit feature, this must
be initially off. An interface method may be provided to
turn it back on.
Database modules that do not suppor
没有合适的资源?快使用搜索试试~ 我知道了~
python psycopg2-binary==2.9.9
需积分: 0 0 下载量 95 浏览量
2024-05-08
18:07:28
上传
评论
收藏 376KB GZ 举报
温馨提示
odoo包
资源推荐
资源详情
资源评论
收起资源包目录
python psycopg2-binary==2.9.9 (179个子文件)
AUTHORS 475B
cursor_type.c 59KB
pqpath.c 52KB
connection_type.c 42KB
connection_int.c 40KB
psycopgmodule.c 31KB
xid_type.c 19KB
conninfo_type.c 17KB
typecast.c 17KB
adapter_datetime.c 13KB
typecast_datetime.c 13KB
lobject_type.c 12KB
column_type.c 12KB
replication_cursor_type.c 12KB
lobject_int.c 12KB
utils.c 12KB
error_type.c 11KB
bytes_format.c 11KB
adapter_list.c 9KB
notify_type.c 9KB
typecast_array.c 9KB
typecast_binary.c 8KB
adapter_qstring.c 8KB
microprotocols.c 8KB
adapter_binary.c 7KB
diagnostics_type.c 7KB
replication_connection_type.c 6KB
adapter_pdecimal.c 6KB
green.c 6KB
adapter_pfloat.c 6KB
adapter_pint.c 6KB
replication_message_type.c 5KB
adapter_asis.c 5KB
adapter_pboolean.c 5KB
microprotocols_proto.c 5KB
cursor_int.c 5KB
typecast_builtins.c 5KB
typecast_basic.c 4KB
win32_support.c 3KB
libpq_support.c 3KB
solaris_support.c 2KB
aix_support.c 2KB
setup.cfg 166B
psycopg.css 2KB
sqlstate_errors.h 11KB
connection.h 9KB
config.h 6KB
cursor.h 5KB
adapter_datetime.h 4KB
lobject.h 4KB
pqpath.h 3KB
python.h 3KB
typecast.h 3KB
psycopg.h 3KB
green.h 3KB
replication_cursor.h 2KB
utils.h 2KB
microprotocols.h 2KB
libpq_support.h 2KB
win32_support.h 2KB
xid.h 2KB
replication_connection.h 2KB
replication_message.h 2KB
solaris_support.h 2KB
aix_support.h 2KB
error.h 2KB
column.h 2KB
typecast_binary.h 1KB
pgtypes.h 1KB
adapter_qstring.h 1KB
adapter_pdecimal.h 1KB
adapter_pboolean.h 1KB
adapter_pfloat.h 1KB
adapter_pint.h 1KB
adapter_asis.h 1KB
adapter_binary.h 1KB
diagnostics.h 1KB
microprotocols_proto.h 1KB
adapter_list.h 1KB
conninfo.h 1KB
notify.h 1KB
MANIFEST.in 398B
INSTALL 155B
COPYING.LESSER 7KB
LICENSE 2KB
Makefile 3KB
Makefile 2KB
Makefile 1KB
_psycopg.vc9.amd64.manifest 644B
_psycopg.vc9.x86.manifest 642B
NEWS 55KB
PKG-INFO 4KB
PKG-INFO 4KB
test_connection.py 68KB
test_types_extras.py 59KB
extras.py 43KB
dbapi20.py 31KB
test_cursor.py 26KB
test_extras_dictcursor.py 24KB
test_dates.py 23KB
共 179 条
- 1
- 2
资源评论
odoo实施
- 粉丝: 2422
- 资源: 48
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功