[DB-SIG] Beginner's last words

Ignacio Guerrero ig_laselva@hotmail.com
Thu, 21 Mar 2002 19:14:35 -0300

Andy: (I really don't know if I should address to you as Andy or Mr Dustman 
but, as everyone in this mail list addresses everyone else by their first 

I've been looking, in many different ways, for a solution to my problem. I 
believe I may not been enterelly clear, so I'll try to put it in a different 

I downloaded two versions of the same module:

- MySQL-python-0.9.1.tar.gz: This one, I've been told, is NOT the one I need 
but, has its own HTML documentation.

- MySQL-python-0.9.1.win32-py2.2.exe: This is the one I installed on my 
computer. It's ment to work on "case-insensitive brain-dead operating 
systems" which I agree. It has no HTML documentation so I looked for the 
comments in the module. The module is called CompatMysqldb.py and this are 
its comments:

Original author: James Henstridge <james@daa.com.au>
Adapted by: Andy Dustman <andy@dustman.net>

This is the original Mysqldb.py module which came with MySQLmodule-1.4,
only it has been adapted to use _mysql instead MySQL. It is intended
for backwards compatibility purposes only. But as a bonus, transactions
will work if your database server and table types support them. It is
called CompatMysqldb instead of Mysqldb so as not to interfere with an
existing Mysqldb, or MySQLdb on case-insensitive brain-dead operating

Under no circumstances should you bug James Henstridge about this!!!


This is a class that implements an interface to mySQL databases, conforming
to the API published by the Python db-sig at

It is really just a wrapper for an older python interface to mySQL databases
called mySQL, which I modified to facilitate use of a cursor.  That module 
Joseph Skinner's port of the mSQL module by David Gibson, which was a 
version of Anthony Baxter's msql module.

As an example, to add some extra (unprivelledged) users to your database 
and delete them again:

>>>import Mysqldb
>>>conn = Mysqldb.mysqldb('mysql@localhost root rootpasswd')
>>>curs = conn.cursor()
>>>curs.execute("insert into user (host, user) values ('%s', '%s')",
... [('localhost', 'linus'), ('somewhere.com.au', 'james')])
>>>curs.execute("select * from user")
-- record listing --
>>>curs.execute("delete from user where host = 'somewhere.com.au' or user = 

The argument to mysqldb.mysqldb is of the form 'db@host user pass',
'db@host user', 'db@host', 'db', 'db user pass' or 'db user'.

As always, the source is a good manual :-)

James Henstridge <james@daa.com.au>
This may look cristal clear to everyone else but me. You see, the example 

>>>import Mysqldb

But not just the example. The lines that follow the example go like this:

import _mysql
MySQL = _mysql
from string import upper, split, join

error = 'mysqldb.error'

from MySQLdb.constants import FIELD_TYPE
_type_conv = { FIELD_TYPE.TINY: int,
               FIELD_TYPE.SHORT: int,
               FIELD_TYPE.LONG: long,
               FIELD_TYPE.FLOAT: float,
               FIELD_TYPE.DOUBLE: float,
               FIELD_TYPE.LONGLONG: long,
               FIELD_TYPE.INT24: int,
               FIELD_TYPE.YEAR: int }

Furthermore, I reciebed answers to my previous question by Andy Todd and 
Paul Turcotte. They give me, as I requested, some examples:

Paul Turcotte said:

>   1. Import MySQLdb.   2. Create a Connection object.   3. Create a Cursor 
>object.   4. Execute your query on the Cursor object.   5. If your query 
>returns rows, you can use the Cursor object to fetch them.   6. Rinse, 
>lather, repeat.
>import MySQLdb db = 
>MySQLdb.connect(db='mydb',user='myuser',passwd='mypasswd') c = db.cursor() 
>c.execute(myquery) results = c.fetchall()
>Suerte, PT

and Andy Todd said:

>And don't forget that 'myquery' in the above example must contain a valid 
>SQL statement.
>e.g, with a vanilla MySQL installation on Windows;
>>>import MySQLdb db = MySQLDb.connect(db='mysql') c = db.cursor() myquery = 
>>>"SELECT * FROM user" c.execute(myquery) 5L results = c.fetchall() results
>(('localhost', 'root', '', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', ...
>And it is always good practice to close a cursor when you are done with it;
>Regards, Andy

Finally, this is the log file of the module installation:

*** Installation started 2002/03/18 17:19 ***
020 Reg DB Key: 
040 Reg DB Value: 
[Software\Microsoft\Windows\CurrentVersion\Uninstall]DisplayName=Python 2.2 
040 Reg DB Value: 
-u "D:\PROGRA~1\PYTHON22\MySQL-python-wininst.log"
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\CompatMysqldb.py
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\_mysql_exceptions.py
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\_mysql.pyd
100 Made Dir: D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\__init__.py
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\converters.py
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\connections.py
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\cursors.py
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\sets.py
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\times.py
100 Made Dir: D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\constants
200 File Copy: 
200 File Copy: 
200 File Copy: 
200 File Copy: 
200 File Copy: 
200 File Copy: 
200 File Copy: 
200 File Copy: 
200 File Copy: 
200 File Copy: 
200 File Copy: 
200 File Copy: 
200 File Copy: 
200 File Copy: 
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\times.pyc
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\sets.pyc
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\cursors.pyc
200 File Copy: 
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\converters.pyc
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\__init__.pyc
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\_mysql_exceptions.pyc
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\CompatMysqldb.pyc
200 File Copy: 
200 File Copy: 
200 File Copy: 
200 File Copy: 
200 File Copy: 
200 File Copy: 
200 File Copy: 
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\times.pyo
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\sets.pyo
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\cursors.pyo
200 File Copy: 
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\converters.pyo
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\__init__.pyo
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\_mysql_exceptions.pyo
200 File Copy: D:\PROGRA~1\PYTHON22\Lib\site-packages\CompatMysqldb.pyo
*** Installation finished 2002/03/18 17:19 ***

I hope you see my problem, there is not such a module called Mysqldb.py nor 
MySQLdb.py so:

- Should I use this CompatMysqldb.py module instead of the Mysqldb.py that 
I've been told to use? or...
- Should I Rename this CompatMysqldb.py module to Mysqldb.py? or...
- Is it posible that the main module is missing?

I'm really starting to feel very stupid, which I believe I'm not, and I 
don't feel confortable by wasting your time. I tryed to analize the code but 
I got seasick. I looked for the proper documentation but everything I 
founded seems NOT to applie to the module I have.

So, what is the name of the module I should import to my script? I guess 
it's not Mysqldb.py because such module didn't come whitin the package.

Thank you for your time and patience.

Ignacio Guerrero

Descargue GRATUITAMENTE MSN Explorer en http://explorer.yupimsn.com/intl.asp