mySQLdb

Piet pit.grinja at gmx.de
Fri Aug 27 18:28:53 CEST 2004


Hi Johan,
I am afraid that there is no simple answer to your (very broad)
question. However, that doesn´t mean that the idea behind getting data
from python into a MySql database is inherently difficult. It is just
not a single step.
As Sibylle pointed out, subclassing MySQLdb is not possible. From what
I have understood so far, this module is more or less an interface
that you can use to type SQL commands. That is, IMHO this module is of
very limited use when you are not familiar with the mysql syntax. The
second thing that you have to know (which is a prerequisite for
profiting from the SQL statements) that you are familiar in general
with the idea of relational databases.
When these conditions are fulfilled, everything is quite ease. Lets us
assume that you have a table named "persons" with the columns
"firstname" and "lastname" and a dictionary "people" with the content
{"Johan":"Potums";"Pit":"Grinja"} and you want to get that data in the
database, then you would make a connection to the database and create
a cursor as  follows:
server = MySQLdb.connect()
cursor = server.cursor
for name in {"Johan":"Potums";"Pit":"Grinja"}.keys():
  cursor.execute("INSERT into persons (name,vorname) "+ name + ","
+people[name])
or something like that.
Depending on where you start, it can take some time to get used to
these concepts, but believe me, it is worth it!
Best wishes

Peter



More information about the Python-list mailing list