MySQSLdb: just guessing

Bob Kline bkline at rksystems.com
Wed Apr 25 08:27:11 EDT 2001


On Tue, 24 Apr 2001, Albert Wagner wrote:

> I can find no docs for MySQLdb, so I am just guessing how to get going.  

Really?  What about the docs that come with the distribution?  What
about the online docs?

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

>>> import _mysql
>>> print _mysql.__doc__
_mysql: an adaptation of the MySQL C API (mostly)
 
You probably are better off using MySQLdb instead of using this module
directly.
 
In general, renaming goes from mysql_* to _mysql.*. _mysql.connect()
returns a connection object (MYSQL). Functions which expect MYSQL * as
an argument are now methods of the connection object. A number of things
return result objects (MYSQL_RES). Functions which expect MYSQL_RES * as
an argument are now methods of the result object. The mysql_real_*
functions are the ones used in place of not-real ones. The various
FLAG_*, CLIENT_*, FIELD_TYPE_*, etc. constants are renamed to FLAG.*,
CLIENT.*, FIELD_TYPE.*, etc. Deprecated functions are NOT implemented.
 
type_conv is a dictionary which maps FIELD_TYPE.* to Python functions
which convert a string to some value. This is used by the fetch_row
method. Types not mapped are returned as strings. Numbers are all
converted reasonably, except DECIMAL.
 
result.describe() produces a DB API description of the rows.
 
escape_sequence() accepts a sequence of items and a type conversion
dictionary. Using the type of the item, it gets a converter function
from the dictionary (uses the string type if the item type is not found)
and applies this to the item. the result should be converted to strings
with all the necessary quoting.
 
mysql_escape_string() on them, and returns them as a tuple.
 
result.field_flags() returns the field flags for the result.
 
result.fetch_row([n=0[, how=1]]) fetches up to n rows (default: n=1) as
a tuple of tuples (default: how=0) or dictionaries (how=1). MySQL
returns strings, but fetch_row() does data conversion according to
type_conv.
 
For everything else, check the MySQL docs.
>>> import MySQLdb
>>> print MySQLdb.__doc__
MySQLdb - A DB API v2.0 compatible interface to MySQL.
 
This module is a thin wrapper around _mysql, which mostly implements the
MySQL C API. All symbols from that module are imported.
 
connect() -- connects to server
type_conv -- dictionary mapping SQL types to Python functions, which
             convert a string into an appropriate data type. Reasonable
             defaults are set for most items, and you can add your own.
 
See the API specification and the MySQL documentation for more info
on other items.
 
This module uses the mxDateTime package for handling date/time types.

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

> I need to know the args to connect().  

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

>>> print MySQLdb.connect.__doc__
Connection(host=NULL, user=NULL, passwd=NULL, db=NULL,
                  port=<MYSQL_PORT>, unix_socket=NULL, client_flag=0)
 
    Note: This interface uses keyword arguments exclusively.
 
    host -- string, host to connect to or NULL pointer (localhost)
    user -- string, user to connect as or NULL (your username)
    passwd -- string, password to use or NULL (no password)
    db -- string, database to use or NULL (no DB selected)
    port -- integer, TCP/IP port to connect to or default MySQL port
    unix_socket -- string, location of unix_socket to use or use TCP
    client_flags -- integer, flags to use or 0 (see MySQL docs)
    conv -- dictionary, maps MySQL FIELD_TYPE.* to Python functions
            which convert a string to the appropriate Python type
 
    Returns a Connection object.
 
    Useful attributes and methods:
 
    db -- connection object from _mysql. Good for accessing some of the
        MySQL-specific calls.
    close -- close the connection.
    cursor -- create a cursor (emulated) for executing queries.

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Doesn't look to me as if Dustman was stingy on the documentation.

> Anything at all will be really helpful.  Thanks ahead for any
> advice.

No problem.  Thank Andy for doing such a good job of documenting his
module. :->}

-- 
Bob Kline
mailto:bkline at rksystems.com
http://www.rksystems.com





More information about the Python-list mailing list