Re: [PD] accessing mysql database

2007-04-12 Thread Frank Barknecht
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


Re: [PD] accessing mysql database

2007-04-08 Thread David Powers
Hi Luigi,

Just to be clear: Can you connect to the database with just Python? If
not, I will try to help later today. This gives me a good excuse to
try such a thing, I've been doing PHP+MySQL typical web programming
lately, but Python is (in my opinion) a far nicer language than PHP
and I've wanted to try this.

~David

On 4/8/07, Luigi Rensinghoff [EMAIL PROTECTED] wrote:
 Hi List,

 i successfully installed py/pyext on an intel macbook, and got
 pyhton, mysql and mysqldb running.

 The patch by georg holzmann i was trying to use is attached.

 Since i have no clue about python and sql and all of that i need some
 help to get started.

 i managed to create a database with mysql, its called sfx_database




 but when i try to connect via the patch i get the error:


 PD mysql: could not log into MySQL server


 in python i imported MySQldb, i think that is necessary and i
 executed dir(MySQLdb), but i am not sure if it is really loaded.

 Who could help me debug/troubleshoot that ??






 ___
 PD-list@iem.at mailing list
 UNSUBSCRIBE and account-management - 
 http://lists.puredata.info/listinfo/pd-list




___
PD-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] accessing mysql database

2007-04-08 Thread Luigi Rensinghoff
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




Am 08.04.2007 um 16:17 schrieb David Powers:

 Hi Luigi,

 Just to be clear: Can you connect to the database with just Python? If
 not, I will try to help later today. This gives me a good excuse to
 try such a thing, I've been doing PHP+MySQL typical web programming
 lately, but Python is (in my opinion) a far nicer language than PHP
 and I've wanted to try this.

 ~David

 On 4/8/07, Luigi Rensinghoff [EMAIL PROTECTED] wrote:
 Hi List,

 i successfully installed py/pyext on an intel macbook, and got
 pyhton, mysql and mysqldb running.

 The patch by georg holzmann i was trying to use is attached.

 Since i have no clue about python and sql and all of that i need some
 help to get started.

 i managed to create a database with mysql, its called sfx_database




 but when i try to connect via the patch i get the error:


 PD mysql: could not log into MySQL server


 in python i imported MySQldb, i think that is necessary and i
 executed dir(MySQLdb), but i am not sure if it is really loaded.

 Who could help me debug/troubleshoot that ??






 ___
 PD-list@iem.at mailing list
 UNSUBSCRIBE and account-management - http://lists.puredata.info/ 
 listinfo/pd-list




 ___
 PD-list@iem.at mailing list
 UNSUBSCRIBE and account-management - http://lists.puredata.info/ 
 listinfo/pd-list



___
PD-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] accessing mysql database

2007-04-08 Thread David Powers
Ahhh I guess I can't be of any help then, I haven't used Python inside
PD too much ... But I'd love to hear the outcome of this.

~David

On 4/8/07, Luigi Rensinghoff [EMAIL PROTECTED] 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




 Am 08.04.2007 um 16:17 schrieb David Powers:

  Hi Luigi,
 
  Just to be clear: Can you connect to the database with just Python? If
  not, I will try to help later today. This gives me a good excuse to
  try such a thing, I've been doing PHP+MySQL typical web programming
  lately, but Python is (in my opinion) a far nicer language than PHP
  and I've wanted to try this.
 
  ~David
 
  On 4/8/07, Luigi Rensinghoff [EMAIL PROTECTED] wrote:
  Hi List,
 
  i successfully installed py/pyext on an intel macbook, and got
  pyhton, mysql and mysqldb running.
 
  The patch by georg holzmann i was trying to use is attached.
 
  Since i have no clue about python and sql and all of that i need some
  help to get started.
 
  i managed to create a database with mysql, its called sfx_database
 
 
 
 
  but when i try to connect via the patch i get the error:
 
 
  PD mysql: could not log into MySQL server
 
 
  in python i imported MySQldb, i think that is necessary and i
  executed dir(MySQLdb), but i am not sure if it is really loaded.
 
  Who could help me debug/troubleshoot that ??
 
 
 
 
 
 
  ___
  PD-list@iem.at mailing list
  UNSUBSCRIBE and account-management - http://lists.puredata.info/
  listinfo/pd-list
 
 
 
 
  ___
  PD-list@iem.at mailing list
  UNSUBSCRIBE and account-management - http://lists.puredata.info/
  listinfo/pd-list
 



___
PD-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] accessing mysql database

2007-04-08 Thread Thomas Grill
Hi Luigi,

 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

How does it not work?
You should in any case use the detached mode (send [detach 1(  ) to  
py/pyext to run in the background, otherwise the pd kernel will be  
disturbed during the SQL query.

greetings,
Thomas


--
Thomas Grill
http://g.org



___
PD-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list