[PD] accessing mysql database

Frank Barknecht fbar at footils.org
Thu Apr 12 18:34:42 CEST 2007


Hallo,
Luigi Rensinghoff hat gesagt: // Luigi Rensinghoff wrote:

> Yes i can acces the database from python, entering some lines of python:
> 
> db = MySQLdb.connect("localhost", "root", "gigiroot", "sfx_database")
> sql = """SELECT * FROM soundfile where description like '%birds%"""
> cursor.execute(sql)
> data = cursor.fetchall()
> print data.
> 
> but from PD it does not work

Could you elaborate "does not work" a bit? Some debugging info or so?

Attached is a very stripped down example how to access a db from
pyext. I use sqlite as a db-backend in the code, the file is hardcoded
to "/tmp/pypd.db". Change as wanted.

You probably want to initialize the db with commands like this:

BEGIN TRANSACTION;
create table soundfile (description text);
INSERT INTO soundfile VALUES('abc');
INSERT INTO soundfile VALUES('mybirds');
INSERT INTO soundfile VALUES('songbirds');
INSERT INTO soundfile VALUES('birdsong');
COMMIT;

Beware: the code isn't very effective. For example normally you should
not slurp in the whole result set in one go etc.

Ciao
-- 
 Frank Barknecht                 _ ______footils.org_ __goto10.org__
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sql.pd
Type: application/puredata
Size: 199 bytes
Desc: not available
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20070412/1a3a3a47/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sql.py
Type: text/x-python
Size: 689 bytes
Desc: not available
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20070412/1a3a3a47/attachment.py>


More information about the Pd-list mailing list