Xcellent improvement; that's (my code) what happens when you're too busy
fixing the problem to learn the tool ;)

 

From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Arnett
Sent: Wednesday, April 13, 2011 4:44 PM
To: [email protected]
Subject: Re: Best Practice for Raw SQL

 

 

On Wed, Apr 13, 2011 at 1:38 PM, Sells, Fred
<[email protected]> wrote:

In my case I had to read some legacy data from a different schema on the
same MySQL server and it was easy (but perhaps not elegant) to just
establish a separate connection using MySQLdb module.

 

You shouldn't have to do that.  Use this:

 

from django.db import connection, transaction

cursor = connection.cursor()

 

Then you can do anything you would with a MySQLdb cursor, e.g.:

 

cursor.execute("UPDATE foo SET bar = 3")

 

After any operation that changes data, apparently you should also call
this:

 

transaction.commit_unless_managed()

 

I'm doing a lot of that right now to vastly speed up a huge data import.

 

Nick

-- 
You received this message because you are subscribed to the Google
Groups "Django users" 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/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" 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/django-users?hl=en.

Reply via email to