1

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.

theist
  • 3,270
  • 2
  • 22
  • 23

2 Answers2

2

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.

Andrea Spadaccini
  • 12,378
  • 5
  • 40
  • 54
  • Hmmm, Good point. I'll change my code with this. But it isn't solve my problem. I still searching for something who tells me the max ticket ID. Perhaps something what gives me an array with all the tickets will solve my problem. – theist Feb 25 '11 at 05:58
  • @theist I don't know the internals of trac, but can't you just do `SELECT MAX(id) FROM ticket;`? – Andrea Spadaccini Feb 25 '11 at 08:11
1

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.

barti_ddu
  • 10,179
  • 1
  • 45
  • 53
  • I find the XmlRpcPlugin very handy for scripting things like this, especially since there is a lot of XmlRpc sample code out there for a number of languages. If you have the option to install the plugin, I would recommend this method. – bta Feb 24 '11 at 13:54