How to get max id of ticket list in a trac environment?

526 Views Asked by At

I'm developing a small utility script for trac which needs to know which is the max ticket id present in each environment.

At this time (with trac 0.11) I'm getting this extracting directly from the trac database with sqlite api, but since we have several environments with different database systems, the intended small utility script is getting bigger doing stupid things.

Is there anything in the trac.* namespace which allows me to find the max ticket id present in an open Environment?

Something which gives me an array with all the tickets or a generator to iterate over all of them will solve my problem.

I can't use the query package because it's an automated/commandline script.

2

There are 2 best solutions below

2
On BEST ANSWER

Why do you need to write custom code for the DB connection? There are Trac objects for getting a database connection that abstracts from the actual DB backend.

See the Trac Database API. For 0.11, you should use Environment.get_db_cnx(), get a Cursor object with the .cursor() method and run your query.

1
On

One of possible ways would be querying Trac via XmlRpcPlugin whith ticket query looking like

"order=id&desc&max=1"

Evidently it is db-agnostic, however not an option if you can't/don't want install additional plugins in your Trac environment.