Edgewall Software

Changes between Version 37 and Version 38 of TracDev/DatabaseApi


Ignore:
Timestamp:
Mar 7, 2023, 8:42:51 AM (14 months ago)
Author:
figaro
Comment:

Cosmetic changes

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/DatabaseApi

    v37 v38  
    33= Trac SQL Database API
    44
    5 Trac uses a very thin layer on top of the standard [http://www.python.org/peps/pep-0249.html Python Database API 2.0] for interfacing with supported relational database systems such as [http://sqlite.org/ SQLite], [http://www.postgresql.org/ PostgreSQL] or the MySqlDb systems.
     5Trac uses a thin layer on top of the standard [http://www.python.org/peps/pep-0249.html Python Database API 2.0] to interface with supported relational database systems such as [http://sqlite.org/ SQLite], [http://www.postgresql.org/ PostgreSQL] and MySqlDb systems.
    66
    77You can find the specifics of the database API in the [source:/trunk/trac/db/ trac.db] package. This package provides:
     
    1616=== API before Trac 0.12
    1717
    18 //This is how things used to be for Trac 0.5 - 0.11, and is still supported until [milestone:1.1.2]. Its use is discouraged for new code.//
     18//This is the style for Trac 0.5 - 0.11 and supported until [milestone:1.1.2]. Its use is discouraged for new code.//
    1919
    2020Code accessing the database in Trac go through this layer simply by using the {{{Environment}}} method {{{get_db_cnx()}}} 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:
     
    3636=== Trac 0.12 API
    3737
    38 //The 0.12 style can still be used in 1.0, but for new code we encourage you to focus on Trac version 1.0 and adopt the even simpler 1.0 style. See next sections for details. The 0.12 style was removed in [milestone:1.3.1].//
     38//This is the style for Trac 0.12 and deprecated in [milestone:1.3.1]. Its use is discouraged for new code.//
    3939
    4040As support for Python 2.3 has been dropped, we could make use of decorators to get rid of some of the boilerplate code:
     
    6060==== Nested Transactions
    6161
    62 With the API described above (since ''0.12'') it is possible to have nested transactions. A nested transaction is best explained by an example:
     62With the API described above (since ''0.12'') it is possible to have nested transactions, as in the following example:
    6363
    6464{{{#!python
     
    9393
    9494[=#Trac0.13API]
    95 //This style is supported for Trac version 1.0 and later.
    96 Starting with [milestone:1.3.1], this is actually the only way, as the deprecated APIs were removed.//
    97 
    98 As we dropped support for Python 2.4, we could simplify the code a bit more by using the `with` keyword and context managers:
     95//This style is supported for Trac version 1.0 and later. Starting with [milestone:1.3.1], this is actually the only way, as the deprecated APIs were removed.//
     96
     97As we dropped support for Python 2.4, we simplified the code by using the `with` keyword and context managers:
    9998
    10099{{{#!python
     
    202201}}}
    203202
    204 Note that dict comprehensions are only available in Python 2.7
    205 and Trac < 1.3.1 supports Python 2.6.
     203Note that dict comprehensions are only available in Python 2.7 and Trac < 1.3.1 supports Python 2.6.
    206204
    207205These short forms also present an additional safety measure as they're only allowing a "SELECT" query to be executed by a read-only connection. Indeed, the same short forms are possible on both `env.db_transaction` and `env.db_query`.