File: MySQLdb-1.html

package info (click to toggle)
python-mysqldb 0.9.1-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 364 kB
  • ctags: 712
  • sloc: ansic: 1,428; python: 1,098; makefile: 59; sh: 28
file content (147 lines) | stat: -rw-r--r-- 6,667 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
 <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
 <TITLE>MySQLdb: a Python interface for MySQL: Introduction </TITLE>
 <LINK HREF="MySQLdb-2.html" REL=next>

 <LINK HREF="MySQLdb.html#toc1" REL=contents>
</HEAD>
<BODY>
<A HREF="MySQLdb-2.html">Next</A>
Previous
<A HREF="MySQLdb.html#toc1">Contents</A>
<HR>
<H2><A NAME="s1">1. Introduction </A></H2>

<P>This module should be 
<A HREF="#MySQLmodule">mostly compatible</A> with an older interface written by Joe Skinner and
others. However, the older version is a) not thread-friendly (database
operations could cause all other threads to block), b) written for
MySQL 3.21 (does not compile against newer versions without patches),
c) apparently not actively maintained. MySQLdb is a completely new
module, distributed free of charge under the GNU Public License.
<P>
<P>
<H2><A NAME="ss1.1">1.1 Platforms</A>
</H2>

<P>
<H3>Linux/UNIX</H3>

<P>This module is developed on RedHat Linux (currently 7.1) for Intel. It
should build without much trouble on most platforms by using the
<CODE>setup.py</CODE> script.  Supposedly it builds on MacOS X.  Be aware that
you need the Distutils package which comes with Python 2.0. If you
don't have it (i.e. you have Python 1.5.2), you can find it over at
<A HREF="http://www.python.org/">www.python.org</A>.
<P>
<H3>Windows (3.11, 95, 98, NT, 2000, CE, BSOD, XYZ, etc.)</H3>

<P>Windows is <EM>not</EM> a supported platform.  However, the <CODE>setup.py</CODE>
script reportedly gets the job done.  There is probably a link on the
web page for getting a precompiled Windows installer from someone or
other.  Be aware that this is a user-contributed package; the author
cannot help you with compiling and running under Windows.
<H2><A NAME="ss1.2">1.2 Python</A>
</H2>

<P>MySQLdb requires Python 1.5.2 or newer. Earlier versions will not
work, because support for C <CODE>long long</CODE> is required by MySQL.  If
you have an earlier version of Python, upgrade to 1.5.2 or beyond.
Current development is done with Python 2.1, but Python 1.5.2 will be
supported for the forseeable future.
<P>
<H2><A NAME="ss1.3">1.3 MySQL</A>
</H2>

<P>
<H3>MySQL-3.22</H3>

<P>Only versions 3.22.32 and up are guaranteed to work. Some older
versions may work; if you have an older version you should seriously
consider upgrading to get the bug fixes and particularly the security
updates.
<P>MySQL-3.22 seems to have a problem trying to insert <CODE>TIME</CODE> values
with fractional seconds. Values like 12:56:13.00 are returned as
344:13:00, apparently interpreting the original input as 12 days, 56
hours, 13 minutes, 0 seconds. (12 days and 56 hours is 344 hours.) To
avoid this problem, use the <CODE>DateTimeDelta</CODE> type.
<P>
<H3>MySQL-3.23</H3>

<P>MySQL-3.23 is now stable (3.23.37 as of this writing). MySQLdb
supports transactions if the <EM>server</EM> supports them. Even then,
this does not guarantee that transactions will work. For that, you
must use a transaction-safe table (TST). Current TSTs are BDB and
InnoDB. GEMINI tables are slated for MySQL-4.0.  Note that MySQL
generally operates in <CODE>AUTOCOMMIT</CODE> mode by default, and MySQLdb
assumes that <CODE>AUTOCOMMIT</CODE> is on by default. To change this, use the
<CODE>SET AUTOCOMMIT=0</CODE> SQL statement.
<P>
<H2><A NAME="ss1.4">1.4 DateTime </A>
</H2>

<P>If you have the 
<A HREF="http://www.lemburg.com/files/python/mxDateTime.html">mx.DateTime</A> package installed (recommended), MySQLdb will use
it for date-related objects. Otherwise, these will be returned to
Python as strings. You can also modify the type conversion
dictionary to return these as other object classes, if you prefer.
<P>
<H2><A NAME="MySQLmodule"></A> <A NAME="ss1.5">1.5 MySQLmodule</A>
</H2>

<P>MySQLmodule, the older MySQL interface by Joe Skinner and others, is
also a split C/Python interface. <CODE>MySQL</CODE>, the C portion, has an
interface similar to perl's DBI internally. In addition, there is
Python portion, <CODE>Mysqldb</CODE>, which provides a DB API v1.0 interface,
written by James Henstridge.  MySQLdb-0.2.2 and up include
<CODE>CompatMysqldb</CODE>, which is an adaptation of <CODE>Mysqldb</CODE> to
<CODE>_mysql</CODE>. It should be considered experimental.
<P>In contrast, MySQLdb's C portion, <CODE>
<A HREF="MySQLdb-2.html#_mysql">_mysql</A>
</CODE>, is
designed to mimic the MySQL C API in an object-oriented way; you
should not expect to move from <CODE>MySQL</CODE> to <CODE>_mysql</CODE> without a
fair amount of work. <CODE>
<A HREF="MySQLdb-3.html#MySQLdb">MySQLdb</A>
</CODE> provides a DB API
v2.0 interface, which has some changes from the v1.0 interface. Things
to watch out for in particular:
<P>
<CENTER><TABLE BORDER><TR><TD>
<BR>
Operation </TD><TD> Mysqldb </TD><TD> MySQLdb</TD></TR><TR><TD>
 Connecting </TD><TD> <CODE>db = Mysqldb.Mysqldb("db@host user pass")</CODE></TD><TD> <CODE>db = MySQLdb.connect(db='db', host='host', user='user', passwd='pass')</CODE></TD></TR><TR><TD>
 Implicit cursor </TD><TD> <CODE>db.execute(SQL)</CODE> </TD><TD>implicit cursors dropped from DB API v2.0; always use <CODE>c = db.cursor()</CODE></TD></TR><TR><TD>
 Fetch row as dictionary </TD><TD> <CODE>c.fetchDict()</CODE>,keys are "<EM>table.column</EM>" </TD><TD>not standard; alternate cursor class <CODE>DictCursor</CODE>provides a dictionary interface,keys are "<EM>column</EM>" or "<EM>table.column</EM>" if there are two columnswith the same name; use SQL <CODE>AS</CODE> to rename fields.</TD></TR><TR><TD>
 Transactions </TD><TD> <CODE>db.commit()</CODE> and <CODE>db.rollback()</CODE>both exist and silently do nothing 
<A HREF="MySQLdb-3.html#rollback">(danger!)</A></TD><TD> <CODE>db.commit()</CODE> and <CODE>db.rollback()</CODE> work if the MySQLserver can perform transactions; otherwise <CODE>db.rollback()</CODE>always fails
<CAPTION>Mysqldb to MySQLdb changes</CAPTION>

</TD></TR></TABLE></CENTER>
<P>
<H2><A NAME="ss1.6">1.6 Zope and ZMySQLDA</A>
</H2>

<P>I wrote a 
<A HREF="http://dustman.net/andy/python/ZMySQLDA">ZMySQLDA</A> for use with MySQLdb. It's adapted from ZOracleDA
from Digital Creations, makers of Zope.
<P>
<H2><A NAME="ss1.7">1.7 Documentation</A>
</H2>

<P>The web page documentation may be slightly ahead of the latest
release and may reflect features of the next release.  
<H2><A NAME="ss1.8">1.8 FAQs</A>
</H2>

<P>A FAQ is available at 
<A HREF="http://dustman.net/andy/python/MySQLdb/faq/MySQLdb-FAQ.html">http://dustman.net/andy/python/MySQLdb/faq/MySQLdb-FAQ.html</A>.
<P>
<HR>
<A HREF="MySQLdb-2.html">Next</A>
Previous
<A HREF="MySQLdb.html#toc1">Contents</A>
</BODY>
</HTML>