| 75 | |
| 76 | The use of `env.get_db_cnx()` is now strongly discouraged. |
| 77 | |
| 78 | For performing read-only accesses, a second context manager is provided: |
| 79 | |
| 80 | {{{ |
| 81 | #!python |
| 82 | from trac.env import Environment |
| 83 | def 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 | |
| 92 | This 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 | |