[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 
name...)

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 
way:

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
systems.

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
http://www.python.org/sigs/db-sig/DatabaseAPI.html

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 
was
Joseph Skinner's port of the mSQL module by David Gibson, which was a 
modified
version of Anthony Baxter's msql module.

As an example, to add some extra (unprivelledged) users to your database 
system,
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')])
2
>>>curs.execute("select * from user")
>>>curs.fetchall()
-- record listing --
>>>curs.execute("delete from user where host = 'somewhere.com.au' or user = 
>>>'linus'")
2
>>>curs.close()
>>>conn.close()

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 
states:

>>>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.
>
>Example:
>
>import MySQLdb db = 
>MySQLdb.connect(db='mydb',user='myuser',passwd='mypasswd') c = db.cursor() 
>c.execute(myquery) results = c.fetchall()
>
></snip>
>
>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;
>
>>>c.close()
>
>Regards, Andy

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

*** Installation started 2002/03/18 17:19 ***
Source: D:\MIS DOCUMENTOS\MYSQL-PYTHON-0.9.1.WIN32-PY2.2.EXE
020 Reg DB Key: 
[Software\Microsoft\Windows\CurrentVersion\Uninstall]MySQL-python-py2.2
040 Reg DB Value: 
[Software\Microsoft\Windows\CurrentVersion\Uninstall]DisplayName=Python 2.2 
MySQL-python-0.9.1
040 Reg DB Value: 
[Software\Microsoft\Windows\CurrentVersion\Uninstall]UninstallString="D:\PROGRA~1\PYTHON22\RemoveMySQL-python.exe" 
-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: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\constants\__init__.py
200 File Copy: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\constants\CR.py
200 File Copy: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\constants\FIELD_TYPE.py
200 File Copy: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\constants\ER.py
200 File Copy: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\constants\FLAG.py
200 File Copy: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\constants\REFRESH.py
200 File Copy: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\constants\CLIENT.py
200 File Copy: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\constants\CLIENT.pyc
200 File Copy: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\constants\REFRESH.pyc
200 File Copy: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\constants\FLAG.pyc
200 File Copy: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\constants\ER.pyc
200 File Copy: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\constants\FIELD_TYPE.pyc
200 File Copy: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\constants\CR.pyc
200 File Copy: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\constants\__init__.pyc
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: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\connections.pyc
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: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\constants\CLIENT.pyo
200 File Copy: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\constants\REFRESH.pyo
200 File Copy: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\constants\FLAG.pyo
200 File Copy: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\constants\ER.pyo
200 File Copy: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\constants\FIELD_TYPE.pyo
200 File Copy: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\constants\CR.pyo
200 File Copy: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\constants\__init__.pyo
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: 
D:\PROGRA~1\PYTHON22\Lib\site-packages\MySQLdb\connections.pyo
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.
Sincerelly,

Ignacio Guerrero

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