On Sat, 8 Sep 2012, Dirk Stöcker wrote:

Could someone please cleanup http://trac.edgewall.org/wiki/TracDev/DatabaseApi

Actually I don't know what is right and what not. It seems I understand the with form, but do I need a db.commit() at the end or does the with do this automatically?

Beside this that page states the now deprecated @with... form as state of the art.

Reading the page again and again I actually see you tried to tell old and new forms. Better would be to state newest recommended form first. Then after that describe how it was before and also how old forms can be converted into new forms.

Actually as it is a wiki I could do some changes myself, but I don't dare to touch that as there is too much stuff I don't really understand. I wanted to change the code I maintained already for 0.12, but as I did not understand the descriptions, I didn't do. As you now plan to drop old syntax I must do, so please make the description what to do understandabble also for someone who does not want to understand the whole database concept, but only wants to use a database for read and write access to store/load data.

After trying to understand that code a bit more - Is following correct:

Old code:
- db = self.env.get_db_cnx()
- cursor = db.cursor()
- cursor.execute("DELETE FROM spamfilter_bayes")
- db.commit()

New code:
+ env.db_transaction("DELETE FROM spamfilter_bayes")

or:
+ with env.db_transaction as db:
+   db("DELETE FROM spamfilter_bayes")
+   db.commit()

or:
+ with env.db_transaction as db:
+   cursor = db.cursor()
+   cursor.execute("DELETE FROM spamfilter_bayes")
+   db.commit()

Do all these the same and first is preferred?

Ciao
--
http://www.dstoecker.eu/ (PGP key available)

--
You received this message because you are subscribed to the Google Groups "Trac 
Development" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/trac-dev?hl=en.

Reply via email to