Edgewall Software

Changes between Version 13 and Version 14 of TracDev/DatabaseApi


Ignore:
Timestamp:
Sep 15, 2010, 7:47:11 PM (14 years ago)
Author:
Christian Boos
Comment:

start to talk about the db_query

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/DatabaseApi

    v13 v14  
    5353See more details in the [../ApiChanges/0.12#with_transaction] paragraph.
    5454
     55The use of `env.get_db_cnx()` is still possible, but deprecated.
     56An alternative `env.get_read_db()` method can be used to get a "read" only access to the database (for performing `SELECT` queries).
     57
    5558=== Trac 0.13 API
    5659
     
    7073
    7174It does essentially the same thing as the 0.12 version above in a terser way.
     75
     76The use of `env.get_db_cnx()` is now strongly discouraged.
     77
     78For performing read-only accesses, a second context manager is provided:
     79
     80{{{
     81#!python
     82from trac.env import Environment
     83def myFunc():
     84    env = Environment('/path/to/projenv')
     85    with env.db_query as db:
     86        cursor = db.cursor()
     87        # Execute some SQL "SELECT" statements
     88
     89    return
     90}}}
     91
     92This one enforces the notion of read-access, because the `db` connection bound to the context doesn't support the `commit()` or `rollback()` methods. As there's not `commit()` upon exit, one could question the usefulness of this construct. The main interest is in better locality of the  connection: in order to improve concurrency and (... finish later)
     93
    7294
    7395=== Configuration