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__
sql.pd
Description: application/puredata
import pyext, sqlite
class pysql(pyext._class):
_inlets = 1
_outlets = 1
def __init__(self):
self.db = sqlite.connect("/tmp/pypd.db")
self.cursor = self.db.cursor()
def select_1(self, pattern):
""" select * from soundfile where description like "pattern" """
# build sql with inlet-pattern:
sql = """ SELECT * FROM soundfile where description like '%s' """ % pattern
# execute query:
self.cursor.execute(sql)
# slurp everything:
data = self.cursor.fetchall()
# print each row:
for result in data:
self._outlet(1, result)
_______________________________________________ [EMAIL PROTECTED] mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
