Python论坛  - 讨论区

标题:[python-chinese] [翻译] PEP249 - Python Database API Specification v2.0 (未完成)

2006年12月31日 星期日 14:13

swordsp sparas2006在gmail.com
星期日 十二月 31 14:13:22 HKT 2006

(这封邮件等了两天也能没被approve...只好把附件压缩成zip重发一遍-_-b)

最近半年给忙坏了,几乎都没时间看邮件列表,之前的啄木鸟条目质量提升计划也搁浅了...
年底终于又有了点空闲,总算又可以干点自己的事情了。

这几天试着翻译了一下这篇PEP249,算是python数据库接口方面的权威文档。
说来这还是之前编辑PyDatabase条目时给自己定的计划,也算是COTW的副产品吧。

目前的成果见附件,中英对照的版本,完成了最主要的几个章节(关于标准API的部分),本着早发布勤发布的原则,先拿出来让大家瞅瞅。
顺便申请swordsp的啄木鸟编辑权限,以后就直接更新在wiki上了。

之前并没有什么翻译的经验,译文中有好些吃不太准或者对原文理解不透的地方,先一并记在下面。
因为是比较正式权威的文档,所以希望能尽量少出些错,还请大家帮忙审查一下:

===

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.

这份文档中定义的API鼓励实现相似的访问数据库的Python模块。我们希望这种一致性使得模块更易理解,代码更易于在不同数据库之间移植,最终使得Python语言得以更广泛的连接各种数据库。

(开头第一段就觉得怎么也翻不通顺,改了好几遍还是不太满意)

Access to the database is made available through connection objects. The
module must provide the following constructor for these:
对数据库的访问通过connection对象进行。模块必须提供以下的构造器:

(我把本文中的constructor一律译为构造器,不知道有没有更合适的词)

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.

"共享"在以上语境中意味着两个线程可以共用同一资源而不需要用互斥信号量来实现外部的锁机制。注意,你无法用互斥量来保证外部资源的线程安全:因为这些资源可能依赖于你无法控制的全局变量或者其它外部资源。

(后一句好像和前文有些衔接不上?"你"是指类库的作者还是使用者?)

Exception raised for errors that are related to the database's operation and
not necessarily under the control of the programmer...
无法由程序员完全控制的数据库操作错误所抛出的异常...

(necessarily的含义吃不太准,字面上似乎是"不必",但"无法"明显通顺一些)

Note: The values of these exceptions are not defined. They should give the
user a fairly good idea of what went wrong, though.
注意:这些异常的值并未定义,但它们应当尽量让用户对哪里出了错心中有数。

("心中有数"总感觉离原文远了点...但也想不出合适的词了)

Close the connection now (rather than whenever __del__ is called).
立即关闭连接(而非等待__del__方法被调用)。

(吃不太准原文的"rather than"到底怎么个语气)

pending transaction
未决的事务

(有没有更好的惯用译法?)

Note that if the database supports an auto-commit feature, this must be
initially off.
注意,如果数据库支持auto-commit功能,必须在初始化时将其关闭。

(initially off的意思拿不太准,是指类库作者应该让auto-commit默认关闭?初始化是指初始化连接对象时?)

The type_code can be interpreted by comparing it to the Type Objects
specified in the section below.
type_code元素可以被解释为与下文中指定的Type对象的比较结果。

(这句译文完全是逐字堆砌出来的...)

Call a stored database procedure with the given name. The sequence of
parameters must contain one entry for each argument that the procedure
expects. The result of the
call is returned as modified copy of the input sequence. Input parameters
are left untouched, output and input/output parameters replaced with
possibly new values.
调用指定名字的数据库存储过程。参数序列必须为存储过程所期望的每一个参数包含一个入口。调用结果作为输入序列的一个修改过的拷贝返回。输入参数仍然保持不变,输出和"输入/输出"参数可能被替换成新的值。


(我没有在python中使用过存储过程,这一段不是特别理解。是不是说函数本身没有返回值,但传入的sequence可能在执行完后已经被修改了?)

This is most effective for algorithms where the same operation is used, but
different parameters are bound to it (many times).
对于使用不同参数(多次)调用同一操作的算法,这是非常有效的。

It is legal for a parameter to not match the predefined information; the
implementation should compensate, possibly with a loss of efficiency.
实际的参数与预先指定的信息不一致是合法的,实现应当予以兼容(可能会以损失效率的方式)。

...execute it against all parameter sequences or mappings found in the
sequence seq_of_parameters.
然后使用seq_of_parameters序列中的所有参数序列(或者映射)将其执行

(这几段都翻得很难受...不知道有没有更通顺准确的译文)

The method should try to fetch as many rows as indicated by the size
parameter. If this is not possible due to the specified number of rows not
being available, fewer rows may be returned.
此方法应当(从结果集中)获取size参数指定数量的若干行。如果无法获得足够数量,应返回尽可能多的行。

(怎么翻都觉得绕口...尽管已经有些意译了)

It defaults to 1 meaning to fetch a single row at a time.
默认值为1,表示每次只获取一行。

(是指arraysize属性的默认值应该是1,还是说"如果"是1则如何如何?)

Implementations must observe this value with respect to the fetchmany()
method, but are free to interact with the database a single row at a time.
fetchmany()方法的实现必须遵循这个值,但与数据库的实际交互可以逐行进行。

(还是说arraysize属性,后半句总觉得翻不到位)

.setoutputsize(size[,column])
Set a column buffer size for fetches of large columns (e.g. LONGs, BLOBs,
etc.). The column is specified as an index into the result sequence. Not
specifying the column will set the default size for all large columns in the
cursor.
设定列缓冲区大小,用于对大体积的列(例如,LONGs,BLOBs等等)
的获取。column参数指定了结果序列中的一个索引序号。如果不指定column参数,则对于游标中所有大体积的列,(缓冲区)都将被设置 成默认的大小。

(这个概念不太理解,凭感觉翻的,哪位能详细解说一下这个buffer是怎么工作的?)

A Cursor Object's description attribute returns information about each of
the result columns of a query. The type_code must compare equal to one of
Type Objects defined below. Type Objects may be equal to more than one type
code ( e.g. DATETIME could be equal to the type codes for date, time and
timestamp columns; see the
Implementation Hints below for details).
Cursor对象的description属性返回一个查询操作的结果中每一列的信息。其类型代码(type_code值)必须等价于(compare
equal to)以下定义的某一Type对象。同一Type对象可以等价于多种类型代码(例如,DATETIME可以等价于date,time或者
timestamp列的类型代码;详细说明参见下文中"Implementation Hints"一节)。

("等价于"感觉还不太到位,有更好的翻法吗?)

===
这些只是最没把握的地方,相信文中还有更多的错误...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20061231/b08b26c6/attachment-0001.htm 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PEP249_cn.zip
Type: application/zip
Size: 18945 bytes
Desc: not available
Url : http://python.cn/pipermail/python-chinese/attachments/20061231/b08b26c6/attachment-0001.zip 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年12月31日 星期日 15:16

yi huang yi.codeplayer在gmail.com
星期日 十二月 31 15:16:03 HKT 2006

On 12/31/06, swordsp <sparas2006 at gmail.com> wrote:
>
> (这封邮件等了两天也能没被approve...只好把附件压缩成zip重发一遍-_-b)
>
> 最近半年给忙坏了,几乎都没时间看邮件列表,之前的啄木鸟条目质量提升计划也搁浅了...
> 年底终于又有了点空闲,总算又可以干点自己的事情了。
>
> 这几天试着翻译了一下这篇PEP249,算是python数据库接口方面的权威文档。
> 说来这还是之前编辑PyDatabase条目时给自己定的计划,也算是COTW的副产品吧。
>
> 目前的成果见附件,中英对照的版本,完成了最主要的几个章节(关于标准API的部分),本着早发布勤发布的原则,先拿出来让大家瞅瞅。
> 顺便申请swordsp的啄木鸟编辑权限,以后就直接更新在wiki上了。
>
> 之前并没有什么翻译的经验,译文中有好些吃不太准或者对原文理解不透的地方,先一并记在下面。
> 因为是比较正式权威的文档,所以希望能尽量少出些错,还请大家帮忙审查一下:
>
> ===
>
> 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.
>
>
> 这份文档中定义的API鼓励实现相似的访问数据库的Python模块。我们希望这种一致性使得模块更易理解,代码更易于在不同数据库之间移植,最终使得Python语言得以更广泛的连接各种数据库。
>
> (开头第一段就觉得怎么也翻不通顺,改了好几遍还是不太满意)
>
> Access to the database is made available through connection objects. The
> module must provide the following constructor for these:
> 对数据库的访问通过connection对象进行。模块必须提供以下的构造器:
>
> (我把本文中的constructor一律译为构造器,不知道有没有更合适的词)
>
> 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.
>
>
> "共享"在以上语境中意味着两个线程可以共用同一资源而不需要用互斥信号量来实现外部的锁机制。注意,你无法用互斥量来保证外部资源的线程安全:因为这些资源可能依赖于你无法控制的全局变量或者其它外部资源。
>
> (后一句好像和前文有些衔接不上?"你"是指类库的作者还是使用者?)
>
> Exception raised for errors that are related to the database's operation
> and not necessarily under the control of the programmer...
> 无法由程序员完全控制的数据库操作错误所抛出的异常...
>
> (necessarily的含义吃不太准,字面上似乎是"不必",但"无法"明显通顺一些)
>
> Note: The values of these exceptions are not defined. They should give the
> user a fairly good idea of what went wrong, though.
> 注意:这些异常的值并未定义,但它们应当尽量让用户对哪里出了错心中有数。
>
> ("心中有数"总感觉离原文远了点...但也想不出合适的词了)
>
> Close the connection now (rather than whenever __del__ is called).
> 立即关闭连接(而非等待__del__方法被调用)。
>
> (吃不太准原文的"rather than"到底怎么个语气)
>
> pending transaction
> 未决的事务
>
> (有没有更好的惯用译法?)
>
> Note that if the database supports an auto-commit feature, this must be
> initially off.
> 注意,如果数据库支持auto-commit功能,必须在初始化时将其关闭。
>
> (initially off的意思拿不太准,是指类库作者应该让auto-commit默认关闭?初始化是指初始化连接对象时?)
>
> The type_code can be interpreted by comparing it to the Type Objects
> specified in the section below.
> type_code元素可以被解释为与下文中指定的Type对象的比较结果。
>
> (这句译文完全是逐字堆砌出来的...)
>
> Call a stored database procedure with the given name. The sequence of
> parameters must contain one entry for each argument that the procedure
> expects. The result of the
> call is returned as modified copy of the input sequence. Input parameters
> are left untouched, output and input/output parameters replaced with
> possibly new values.
> 调用指定名字的数据库存储过程。参数序列必须为存储过程所期望的每一个参数包含一个入口。调用结果作为输入序列的一个修改过的拷贝返回。输入参数仍然保持不变,输出和"输入/输出"参数可能被替换成新的值。
>
>
> (我没有在python中使用过存储过程,这一段不是特别理解。是不是说函数本身没有返回值,但传入的sequence可能在执行完后已经被修改了?)
>
> This is most effective for algorithms where the same operation is used,
> but different parameters are bound to it (many times).
> 对于使用不同参数(多次)调用同一操作的算法,这是非常有效的。
>
> It is legal for a parameter to not match the predefined information; the
> implementation should compensate, possibly with a loss of efficiency.
> 实际的参数与预先指定的信息不一致是合法的,实现应当予以兼容(可能会以损失效率的方式)。
>
> ...execute it against all parameter sequences or mappings found in the
> sequence seq_of_parameters.
> 然后使用seq_of_parameters序列中的所有参数序列(或者映射)将其执行
>
> (这几段都翻得很难受...不知道有没有更通顺准确的译文)
>
> The method should try to fetch as many rows as indicated by the size
> parameter. If this is not possible due to the specified number of rows not
> being available, fewer rows may be returned.
> 此方法应当(从结果集中)获取size参数指定数量的若干行。如果无法获得足够数量,应返回尽可能多的行。
>
> (怎么翻都觉得绕口...尽管已经有些意译了)
>
> It defaults to 1 meaning to fetch a single row at a time.
> 默认值为1,表示每次只获取一行。
>
> (是指arraysize属性的默认值应该是1,还是说"如果"是1则如何如何?)
>
> Implementations must observe this value with respect to the fetchmany()
> method, but are free to interact with the database a single row at a time.
> fetchmany()方法的实现必须遵循这个值,但与数据库的实际交互可以逐行进行。
>
> (还是说arraysize属性,后半句总觉得翻不到位)
>
> .setoutputsize(size[,column])
> Set a column buffer size for fetches of large columns (e.g. LONGs, BLOBs,
> etc.). The column is specified as an index into the result sequence. Not
> specifying the column will set the default size for all large columns in the
> cursor.
> 设定列缓冲区大小,用于对大体积的列(例如,LONGs,BLOBs等等)
> 的获取。column参数指定了结果序列中的一个索引序号。如果不指定column参数,则对于游标中所有大体积的列,(缓冲区)都将被设置 成默认的大小。
>
> (这个概念不太理解,凭感觉翻的,哪位能详细解说一下这个buffer是怎么工作的?)
>
> A Cursor Object's description attribute returns information about each of
> the result columns of a query. The type_code must compare equal to one of
> Type Objects defined below. Type Objects may be equal to more than one type
> code ( e.g. DATETIME could be equal to the type codes for date, time and
> timestamp columns; see the
> Implementation Hints below for details).
> Cursor对象的description属性返回一个查询操作的结果中每一列的信息。其类型代码(type_code值)必须等价于(compare
> equal to)以下定义的某一Type对象。同一Type对象可以等价于多种类型代码(例如,DATETIME可以等价于date,time或者
> timestamp列的类型代码;详细说明参见下文中"Implementation Hints"一节)。
>
> ("等价于"感觉还不太到位,有更好的翻法吗?)
>
> ===
> 这些只是最没把握的地方,相信文中还有更多的错误...
>
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese


我来尝试一下

This API has been defined to encourage similarity between the Python modules
that are use
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.

定义这份 API 的目的是要鼓励那些用来访问数据库的 python
模块之间的相似性。通过这样做,我们希望获得一种一致性,并由此产生更易懂的模块,在不同数据库之间更容易移植的代码,和 python
与数据库之间更广阔的联通。
-- 我直译的,感觉不是特别绕口,最后一句不会翻。

Exception raised for errors that are related to the database's operation and
not necessarily
under the control of the programmer...

由于数据库操作错误而产生的异常,不必由程序员来控制 ...

This is most effective for algorithms where the same operation is used, but
different
parameters are bound to it (many times).

这对于需要使用不同参数多次调用同一操作的算法特别有用。

The method should try to fetch as many rows as indicated by the size
parameter. If this is
not possible due to the specified number of rows not being available, fewer
rows may be
returned.

该方法应该尽可能返回参数 size 指定的那么多行。如果没有这么多,少一些也可以。


A Cursor Object's description attribute returns information about each of
> the result columns of a query. The type_code must compare equal to one of
> Type Objects defined below. Type Objects may be equal to more than one type
> code ( e.g. DATETIME could be equal to the type codes for date, time and
> timestamp columns; see the
> Implementation Hints below for details).
> Cursor对象的description属性返回一个查询操作的结果中每一列的信息。其类型代码(type_code值)必须等价于(compare
> equal to)以下定义的某一Type对象。同一Type对象可以等价于多种类型代码(例如,DATETIME可以等价于date,time或者
> timestamp列的类型代码;详细说明参见下文中"Implementation Hints"一节)。
>
> ("等价于"感觉还不太到位,有更好的翻法吗?)
>

compare equal to 就是等于的意思吧。

-- 
http://codeplayer.blogspot.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20061231/0100bc8b/attachment-0001.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年12月31日 星期日 23:52

swordsp sparas2006在gmail.com
星期日 十二月 31 23:52:04 HKT 2006

谢啦~

On 12/31/06, yi huang <yi.codeplayer at gmail.com> wrote:
>
> On 12/31/06, swordsp <sparas2006 at gmail.com > wrote:
>
> 我来尝试一下
>
> This API has been defined to encourage similarity between the Python
> modules that are use
> 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.
>
> 定义这份 API 的目的是要鼓励那些用来访问数据库的 python
> 模块之间的相似性。通过这样做,我们希望获得一种一致性,并由此产生更易懂的模块,在不同数据库之间更容易移植的代码,和 python
> 与数据库之间更广阔的联通。
> -- 我直译的,感觉不是特别绕口,最后一句不会翻。
>
> Exception raised for errors that are related to the database's operation
> and not necessarily
> under the control of the programmer...
>
> 由于数据库操作错误而产生的异常,不必由程序员来控制 ...
>

嗯,后半句理解成对"异常"的修饰就 通顺多了,我总想成对是"错误"的修饰了。


> This is most effective for algorithms where the same operation is used,
> but different
> parameters are bound to it (many times).
>
> 这对于需要使用不同参数多次调用同一操作的算法特别有用。
>
> The method should try to fetch as many rows as indicated by the size
> parameter. If this is
> not possible due to the specified number of rows not being available,
> fewer rows may be
> returned.
>
> 该方法应该尽可能返回参数 size 指定的那么多行。如果没有这么多,少一些也可以。
>

这句的主要问题是,我觉得"as many
as"隐含着"即使剩余的行数量不足,也要返回尽可能多的行(也就是全部返回)"这样一个意思,我想把这层意思直接一点的表示出来。

A Cursor Object's description attribute returns information about each of
> > the result columns of a query. The type_code must compare equal to one of
> > Type Objects defined below. Type Objects may be equal to more than one type
> > code ( e.g. DATETIME could be equal to the type codes for date, time and
> > timestamp columns; see the
> > Implementation Hints below for details).
> > Cursor对象的description属性返回一个查询操作的结果中每一列的信息。其类型代码(type_code值)必须等价于(compare
> > equal to)以下定义的某一Type对象。同一Type对象可以等价于多 种类型代码(例如,DATETIME可以等价于date,time或者
> > timestamp列的类型代码;详细说明参见下文中"Implementation Hints"一节)。
> >
> > ("等价于"感觉还不太到位,有更好的翻法吗?)
> >
>
> compare equal to 就是等于的意思吧。


这里多加了一个"compare",总让我潜意识里有这样一层想法:
在做"compare"操作时("="运算符)表现为相等――但也可能在其它场合表现出差异。
当然很可能只是我单纯的想多了。
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20061231/2332b5c1/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号