Need Help Optomizing Code

Rene Pijlman reply.in.the.newsgroup at my.address.is.invalid
Mon Jan 5 02:14:35 CET 2004


Andrew:
>and was wondering if anyone out there could help me optomize this code.
[...]
>        self.db = MySQLdb.connect("localhost", "", "", "guestbook")
>        self.c = self.db.cursor()
>        self.c.execute("DELETE FROM guests WHERE id LIMIT 1;")
                                            ^^^^^^^^^^^^^^^^
                                           What does that mean?

>        self.results = self.c.fetchall()

In general, it's unwise to reconnect to a database server for every single
data manipulation. Keep the connection open, and perhaps even the cursor.
But I'm not sure if and how this works precisely with MySQL, I prefer
PostgreSQL myself.

Also, you seem to be forgetting the commit and disconnect.

-- 
René Pijlman



More information about the Python-list mailing list