-
Book Overview & Buying
-
Table Of Contents
MySQL for Python
By :
As you might expect, affecting the creation and deletion of databases and tables in Python is very similar to MySQL when using MySQL for Python. There are some differences as we shall see in this section.
For the following examples, we will work with the following code being assumed:
import MySQLdb
mydb = MySQLdb.connect('localhost', 'skipper', 'secret', 'csv')
cur = mydb.cursor()Where Cursor.execute() shows the number of affected rows in previous commands, whether INSERT or SELECT, it always returns a 0 value for the CREATE command of a database:
>>> cur.execute("""CREATE DATABASE foo""") 0L
Consequently, passing the output of the method to a variable will result in that variable equating to 0:
>>> res = cur.execute("CREATE DATABASE foo") >>> print res 0
The only time that this does not occur is if an error is thrown (that is, if you do not include the conditional IF NOT EXISTS).
This is helpful...
Change the font size
Change margin width
Change background colour