Edgewall Software

Changes between Version 26 and Version 27 of TracDev/DatabaseApi


Ignore:
Timestamp:
Sep 8, 2012, 1:22:47 PM (12 years ago)
Author:
Christian Boos
Comment:

clarify which API goes with which versions

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/DatabaseApi

    v26 v27  
    1111
    1212== Accessing the Database ==
     13
     14The DB API has evolved quite a lot in the recent versions of Trac, and the usage is substantially different whether you're working with Trac 0.11, 0.12 or 1.0 and up.
     15
     16
    1317=== API before Trac 0.12
     18
     19//This is how things used to be for Trac 0.5 - 0.11, and is still supported in Trac 0.12, but in new code this style should be definitely **not** used, as it introduces all the problems that the new styles are solving (see next sections for details). //
    1420
    1521Code 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. 
     
    3238=== Trac 0.12 API
    3339
     40// The 0.12 style can still be used in 1.0, but for new code we encourage you to focus on the Trac version 1.0 and to adopt the even simpler 1.0 style (see next section). //
     41
    3442As we dropped support for Python 2.3, we could make use of decorators to get rid of some of the boilerplate code.
    3543
     
    4654}}}
    4755
    48 This is slightly simpler and more robust than the previous API, as not only the `commit()` is performed in any successful case (i.e. the `Execute some SQL statements` code can `return` at any
     56This is slightly simpler and **more robust** than the previous API, as not only the `commit()` is performed in any successful case (i.e. the `Execute some SQL statements` code can `return` at any
    4957place), but a `rollback` will be performed should an exception be triggered in that block.
    5058
     
    8795''Note:'' Uncommited changes of a transaction are only visible to nested transactions in the same thread. Different threads use different database connections and therefore different transactions.
    8896
    89 === Trac 0.13dev and 1.0 API #Trac0.13API
     97=== Trac 1.0 API #Trac0.13API
     98
     99// This style is supported for version 1.0.x, 1.1.x and will be supported beyond as well. //
    90100
    91101As we dropped support for Python 2.4, we could simplify the code a bit more by using the `with` keyword and context managers: