- 浏览: 332479 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
ProgrammingPower:
非常感谢您,搞定了,哈哈!
Debian下安装CodeBlocks -
hfa1s2:
是的。谢谢你哈! 我解决了这个问题
python模块之smtplib: 用python发送SSL/TLS安全邮件 -
huangro:
587端口的是很麻烦的,毕竟是需要ssl验证的。
python模块之smtplib: 用python发送SSL/TLS安全邮件 -
hfa1s2:
我想利用内网往公司邮箱里发,但接口是587 的 而且需要 SS ...
python模块之smtplib: 用python发送SSL/TLS安全邮件 -
zyb88325:
你好 我现在用的cakephp2.0,因为服务器不支持rewr ...
CakePHP常用技巧总结
Trac SQL Database API
Trac uses a very thin layer on top of the standard Python Database API 2.0 for interfacing with supported relational database systems such as SQLite or PostgreSQL.
Note that Trac prior to version 0.9 used the PySQLite APIs directly, and has no support for other database systems. This document describes the thin DB API abstraction layer introduced in version 0.9.
You can find the specifics of the database API in the trac.db package. This package provides:
Simple pooling of database connections
Iterable cursors
Selection of DB modules based of connection URIs.
Accessing the Database
Code accessing the database in Trac go through this layer simply by using the Environment method get_db_cnx() in order to get a pooled database connection. A database cursor can be obtained from the pooled database connection, and the code uses the cursor in conjunction with SQL statements to implement the behavior.
Note that you should always make sure that db won't get garbage collected while cursor is still used, as the collection will do a rollback and close the cursors (avoid in particular doing cursor = env.get_db_cnx().cursor(), see r8878).
The get_db_cnx method looks at the value of the database configuration option in trac.ini, which should contain a database connection URI. The default value for this option tells Trac to use an SQLite database inside the environment directory:
The connection URI syntax has been designed to be compatible with that provided by SQLObject (see also the Wiki page on SQLObject connections). The only supported URI schemes at this point are sqlite and postgres.
Pooled Connections
The Environment method get_db_cnx() returns a connection from the pool of connections. This connection needs to be returned, and Trac is written so that the return will happen automatically by the garbage collector if the code is written to follow a simple rule. When the garbage collector determines the pooled database connection is no longer being used, it's del method will return the pooled connection to the pool for reuse. If you have set a lexical variable in the function's body to the pooled connection, this typically occurs when the function is returning. In the example above of myFunc it occurs at the return statement since db is a variable local to myFunc
Rules for DB API Usage
Different DB API modules have different ways to pass parameters to the cursors' execute method, and different ways to access query results. To keep the database API as thin as possible, the Trac team has decided to use a relatively common subset in all database code.
Parameter passing
Always use the "format" parameter style, and always with %s (because that's the only type that pyPgSQL supports). Statement parameters always need to be passed into execute as an actual sequence (list or tuple).
So the following statements are okay:
The following uses are not okay:
At any cost, try avoiding the use of string formatting to get values into the SQL statement. The database automatically escapes values you pass using execute() arguments, the same is not true if you use string formatting, opening your code up to SQL injection attacks.
On the other hand, you must use string formatting to dynamically specify names of tables or columns, i.e. anything that is not a value as such:
Retrieving results
For convenience, cursors returned by the database connection object are iterable after having executed an SQL query. Individual fields in result rows may only be accessed using integer indices:
Accessing fields using the column names is not supported by all database modules, so it should not be used. Automatically unpacking rows into tuples of named variables often provides better readability:
Guidelines for SQL Statements
As you may know, support for SQL varies among different database systems. The requirements of Trac are relatively trivial, so we try to stick to a common subset that is supported by the majority of databases.
TODO: Need content
Trac uses a very thin layer on top of the standard Python Database API 2.0 for interfacing with supported relational database systems such as SQLite or PostgreSQL.
Note that Trac prior to version 0.9 used the PySQLite APIs directly, and has no support for other database systems. This document describes the thin DB API abstraction layer introduced in version 0.9.
You can find the specifics of the database API in the trac.db package. This package provides:
Simple pooling of database connections
Iterable cursors
Selection of DB modules based of connection URIs.
Accessing the Database
Code accessing the database in Trac go through this layer simply by using the Environment method get_db_cnx() in order to get a pooled database connection. A database cursor can be obtained from the pooled database connection, and the code uses the cursor in conjunction with SQL statements to implement the behavior.
from trac.env import Environment def myFunc(): env = Environment('/path/to/projenv') db = env.get_db_cnx() cursor = db.cursor() # Execute some SQL statements db.commit() return
Note that you should always make sure that db won't get garbage collected while cursor is still used, as the collection will do a rollback and close the cursors (avoid in particular doing cursor = env.get_db_cnx().cursor(), see r8878).
The get_db_cnx method looks at the value of the database configuration option in trac.ini, which should contain a database connection URI. The default value for this option tells Trac to use an SQLite database inside the environment directory:
[trac] database = sqlite:db/trac.db
The connection URI syntax has been designed to be compatible with that provided by SQLObject (see also the Wiki page on SQLObject connections). The only supported URI schemes at this point are sqlite and postgres.
Pooled Connections
The Environment method get_db_cnx() returns a connection from the pool of connections. This connection needs to be returned, and Trac is written so that the return will happen automatically by the garbage collector if the code is written to follow a simple rule. When the garbage collector determines the pooled database connection is no longer being used, it's del method will return the pooled connection to the pool for reuse. If you have set a lexical variable in the function's body to the pooled connection, this typically occurs when the function is returning. In the example above of myFunc it occurs at the return statement since db is a variable local to myFunc
Rules for DB API Usage
Different DB API modules have different ways to pass parameters to the cursors' execute method, and different ways to access query results. To keep the database API as thin as possible, the Trac team has decided to use a relatively common subset in all database code.
Parameter passing
Always use the "format" parameter style, and always with %s (because that's the only type that pyPgSQL supports). Statement parameters always need to be passed into execute as an actual sequence (list or tuple).
So the following statements are okay:
cursor.execute("SELECT author,ipnr,comment FROM wiki WHERE name=%s", [thename]) cursor.execute("SELECT id FROM ticket WHERE time>=%s AND time<=%s", (start, stop))
The following uses are not okay:
cursor.execute("SELECT author,ipnr,comment FROM wiki WHERE name=?", thename) cursor.execute("SELECT id FROM ticket WHERE time>=%i AND time<=%i", start, stop)
At any cost, try avoiding the use of string formatting to get values into the SQL statement. The database automatically escapes values you pass using execute() arguments, the same is not true if you use string formatting, opening your code up to SQL injection attacks.
On the other hand, you must use string formatting to dynamically specify names of tables or columns, i.e. anything that is not a value as such:
cursor.execute("SELECT time FROM %s WHERE name=%%s" % table, (thename,))
Retrieving results
For convenience, cursors returned by the database connection object are iterable after having executed an SQL query. Individual fields in result rows may only be accessed using integer indices:
cursor.execute("SELECT author,ipnr,comment FROM wiki WHERE name=%s", (thename,)) for row in cursor: print 'Author: %s (%s)' % (row[0], row[1]) print row[2]
Accessing fields using the column names is not supported by all database modules, so it should not be used. Automatically unpacking rows into tuples of named variables often provides better readability:
cursor.execute("SELECT author,ipnr,comment FROM wiki WHERE name=%s", (thename,)) for author, ipnr, comment in cursor: print 'Author: %s (%s)' % (author, ipnr) print comment
Guidelines for SQL Statements
As you may know, support for SQL varies among different database systems. The requirements of Trac are relatively trivial, so we try to stick to a common subset that is supported by the majority of databases.
TODO: Need content
发表评论
-
Trac Data Models and Schema
2010-09-15 10:56 6336The main models that developers ... -
在Mac OS上运行wxPython
2010-09-14 15:42 3205如果在一个64位的Mac上跑wxPython, 将会出现以下错 ... -
Trac系统相关文档
2010-02-01 12:53 10461. Trac组件架构 http://trac.edgewal ... -
Django上传文件
2009-11-26 18:06 1348之前写了一个上传文件模块,但是当文件很大时就会挂掉,分析了一下 ... -
50个Python重要模块
2009-10-20 09:32 1982原文地址:http://www.cnblogs.com/yd1 ... -
Trac系统的双重认证
2009-10-20 09:27 1136首先,需要导入urllib2及cookielib。 然后,关键 ... -
分享一个图表制作库
2009-06-18 15:15 1308该包名为ChartDirector,可以从其官方主页http: ... -
django newforms的更改
2009-06-16 13:34 1053Django升级之后,有一些应用包的名称也相应发生了变化,比如 ... -
Python版支付宝集成插件源代码
2009-05-08 15:34 4914之前在做一项目的时候需要集成支付宝功能,网站是用python做 ... -
Django多语言问题
2009-05-06 17:22 1904最近多Django比较感兴趣,打算用它来做一个网站,看了官方关 ... -
Installing Satchmo on Webfaction
2009-04-29 15:39 1646link: http://brianmckinney.net/ ... -
Satchmo配置注意事项
2009-04-25 16:10 1019Satchmo在同步数据库之后,在操作后台管理页面过程中,一直 ... -
Yaml与python类型的对照表
2009-04-22 23:03 1690因为常用yaml作为python程序的配置文件,特将其与pyt ... -
satchmo汉化
2009-04-21 15:21 1900转载:http://blog.csdn.net/huliuhe ... -
python模块之smtplib: 用python发送SSL/TLS安全邮件
2008-07-04 19:08 9451原文出自 http://blog.csdn.net/zhaow ... -
python模块之poplib: 用pop3收取邮件
2008-07-04 19:09 2197python的poplib模块是用来 ... -
python模块之email: 电子邮件编码解码 (转)
2008-07-04 19:11 3483用email模块来生成邮件也是很简单的,只是需要一些mime的 ... -
用iconv做通用的语言编码转换(转)
2008-07-04 19:13 1364#include <stdio.h> #in ... -
python模块之email: 电子邮件编码解码(转)
2008-07-04 19:16 3276出处:http://blog.csdn.net/zhaowei ... -
一个不错的web开发组合
2008-07-19 15:26 1148Twisted + Nevow 在python web开发上 ...
相关推荐
标题 "trac api调用测试 c#" 描述的是一个C#项目,该项目涉及使用Trac API进行功能测试。Trac是一个开源的项目管理和问题跟踪系统,它提供了RESTful API接口,允许开发者通过编程方式与Trac系统交互。C#是微软开发的...
Trac 1.0 API是开发插件的基础,提供了丰富的接口和组件,以允许开发者集成新的功能。了解这些API是创建高效且兼容Trac环境的插件的关键。API文档涵盖了各种模块,如附件管理、缓存控制、核心组件、环境模型、内容...
5. **与其他工具的集成**:Trac可以通过插件或API与各种工具集成,如Jenkins(持续集成)、Bugzilla(缺陷跟踪)、Git(版本控制系统)等。 6. **维护和升级**:随着Trac新版本的发布,你可能需要升级Trac环境以...
Trac是一款开源且免费的项目管理工具,它集成了版本控制系统、缺陷跟踪系统以及文档管理系统,主要用于软件开发项目的协作和管理。在这个“trac汉化安装程序”压缩包中,包含的是Trac的中文版安装文档和相关组件,...
### Apache+Trac配置详解 #### 一、概述 Trac是一个开源的增强型缺陷跟踪系统,它结合了易于使用的Web界面(包含wiki语法)、一个简单的缺陷/问题/任务管理系统和一个可方便浏览的文件存储库。Trac的核心功能通过...
Trac是一款开源且免费的项目管理工具,特别适合软件开发团队使用。它集成了版本控制系统(如Git或Subversion),提供了问题跟踪、wiki和时间线等功能,帮助团队高效协作和管理项目。本教程将通过一系列截图,详细...
开源项目管理工具-Trac使用手册 Trac 是一个开源的项目管理软件应用平台,它集成了 Wiki 和问题跟踪管理系统,旨在帮助开发人员更好地写出高质量的软件。Trac 使用 Python 语言开发,需要有 Python 环境的支持,...
《TRAC教程【原创】》是一份非常实用的教材,主要介绍了如何配置和使用TRAC这一开源的项目管理和问题跟踪系统。TRAC是一个基于Python语言的Web应用,它结合了Wiki和问题跟踪功能,旨在帮助软件开发团队更高效地管理...
Trac是一款开源且免费的项目管理工具,专为软件开发团队设计,集成了版本控制系统、问题跟踪系统和项目wiki功能。这款工具旨在提供一个透明的工作环境,帮助团队成员更好地协作,跟踪项目进度,并且便于非技术人员...
Trac是一款开源且免费的软件开发流程管理工具,它结合了问题跟踪系统、项目管理和文档版本控制系统等功能,为软件团队提供了一个集中的、基于Web的协作环境。Trac的出现旨在帮助开发团队更好地追踪和解决项目中的...
《Trac项目管理使用手册》提供了详尽的指导,帮助项目经理有效地利用Trac工具进行项目管理。Trac是一个集成Wiki和问题跟踪管理系统的开源软件,旨在简化软件开发项目的管理,同时尊重并适应现有的开发流程。它由...
Trac-0.12.2及配套是一个包含多个组件的软件包,主要涉及的工具是Trac,以及与其紧密协作的Babel、Bitten、Genshi和Python。这些工具在IT行业中扮演着重要的角色,特别是在软件开发、项目管理和文档生成等方面。 ...
Trac是一个开源的软件项目管理工具,它集成了Wiki和问题跟踪管理系统,旨在帮助软件开发团队更有效地管理和协作。Trac以轻量级的方式构建,旨在不干扰现有的开发流程,而是增强其效率。该工具使用Python语言编写,...
Trac是一款基于Python语言开发的开源项目管理工具,它与SQLite数据库紧密结合,提供了一套集成了版本控制系统(如Subversion)的全方位项目管理解决方案。Trac不仅能够追踪问题报告、任务管理和时间线,还能作为代码...
【Apache+Trac+SVN】是一个常见的项目管理和版本控制系统组合,主要应用于Windows环境。Apache作为Web服务器,Trac是一个带有内置wiki和问题跟踪系统的Web应用程序,而SVN(Subversion)则是版本控制系统,用于追踪...
Trac 是一个开源的项目管理和问题追踪工具,尤其适合软件开发团队用来管理代码库、跟踪缺陷、处理任务和文档管理。本安装手册将指导你从零开始在本地环境中搭建 Trac 系统。 首先,确保你已经具备了必要的前置条件...
标题中的“Trac安装用到的软件”表明我们要讨论的是Trac的安装过程,而Trac是一个开源的项目管理工具,常用于版本控制系统的集成,尤其是与Subversion(SVN)配合使用。在这个场景中,描述虽为空,但从提供的文件名...
- **pysqlite-2.3.3.win32-py2.4.exe**:Python和SQLite的DB-API 2.0数据库接口。尽管存在针对Python 2.5的版本,但考虑到与Trac的兼容性,选择匹配Python 2.4的版本更为合适。 - **sqlite-3_3_11.zip**:SQLite...
Apache 和 Trac 是两个在 IT 领域中广泛应用的开源软件。Apache 是最流行的 Web 服务器,而 Trac 是一个项目管理和问题跟踪系统,它提供了网页界面,用于集成源代码控制、缺陷追踪、文档管理和任务管理。这篇文章将...