Hi
The few times I had to interface Pd with MySQL, I decided to use [shell] and cobbled together some queries sent to mysql command. While I think that is probably not the most elegant approach, I'd like to ask the community how you dealt with Pd and MySQL, or SQL in general, or even Databases in general.
There are certainly many other ways to achieve data retrieval from databases within Pd, I am also thinking of ways that offload the talking to the database to other technologies/languages like PHP, bash, pyhton, etc. Then you have plenty of ways to interface Pd with those. I'm thinking of RESTful (purest_json), web (http* from mrpeach), still bash.
I wonder what people decided to use in the end and what they found to be working well. Any success or failure stories to share?
Roman
Hi,
is it already 7 years ago? Anyway, in 2007 I posted an example using luaSQL and Pdlua that should still work: http://lists.puredata.info/pipermail/pd-dev/2007-11/009964.html
Frank
On Thu, Jun 19, 2014 at 02:32:28PM +0200, Roman Haefeli via Pd-list wrote:
Hi
The few times I had to interface Pd with MySQL, I decided to use [shell] and cobbled together some queries sent to mysql command. While I think that is probably not the most elegant approach, I'd like to ask the community how you dealt with Pd and MySQL, or SQL in general, or even Databases in general.
There are certainly many other ways to achieve data retrieval from databases within Pd, I am also thinking of ways that offload the talking to the database to other technologies/languages like PHP, bash, pyhton, etc. Then you have plenty of ways to interface Pd with those. I'm thinking of RESTful (purest_json), web (http* from mrpeach), still bash.
I wonder what people decided to use in the end and what they found to be working well. Any success or failure stories to share?
Roman
Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
it still works if luasql.sqlite is replaced by luasql.sqlite3 like following lsql.pd_lua code:
:)
-- SQL example for pdlua -- Written by Frank Barknecht in 2007, use however you like.
-- load driver require "luasql.sqlite3"
local M = pd.Class:new():register("lsql")
function M:initialize(name) -- create environment object self.env = assert (luasql.sqlite3()) self.con = nil self.outlets = 2 self.inlets = 1 return true end
function M:in_1_open(atoms) -- connect to data source self.con = assert (self.env:connect(atoms[1])) end
function M:in_1_sql(atoms) if not self.con then self:error("open a database file first") return end local command = table.concat(atoms, " ") -- use : instead of , command = command:gsub(":", ",") local cur = assert (self.con:execute(command)) if type(cur) == "number" then -- report affected rows to second outlet: self:outlet(2, "float", {cur}) else local row = cur:fetch({}) while row do self:outlet(1, "list", row) row = cur:fetch(row) end -- close cursor cur:close() end end
Le 19/06/2014 15:37, Frank Barknecht via Pd-list a écrit :
Hi,
is it already 7 years ago? Anyway, in 2007 I posted an example using luaSQL and Pdlua that should still work: http://lists.puredata.info/pipermail/pd-dev/2007-11/009964.html
Ciao
Hello,
Pdlua is working fine on my system.
I installed : $ sudo apt-get install lua-sql-sqlite3-dev
and used the code below to create a file 'mysql.pd_lua'.
But when i tried to create [mysql] object in Pd, i got in the pd console : maximum object loading depth 1000 reached mysql ... couldn't create
Did I miss something ? ++
Jack
Le 23/06/2014 21:05, patrice colet via Pd-list a écrit :
it still works if luasql.sqlite is replaced by luasql.sqlite3 like following lsql.pd_lua code:
:)
-- SQL example for pdlua -- Written by Frank Barknecht in 2007, use however you like.
-- load driver require "luasql.sqlite3"
local M = pd.Class:new():register("lsql")
function M:initialize(name) -- create environment object self.env = assert (luasql.sqlite3()) self.con = nil self.outlets = 2 self.inlets = 1 return true end
function M:in_1_open(atoms) -- connect to data source self.con = assert (self.env:connect(atoms[1])) end
function M:in_1_sql(atoms) if not self.con then self:error("open a database file first") return end local command = table.concat(atoms, " ") -- use : instead of , command = command:gsub(":", ",") local cur = assert (self.con:execute(command)) if type(cur) == "number" then -- report affected rows to second outlet: self:outlet(2, "float", {cur}) else local row = cur:fetch({}) while row do self:outlet(1, "list", row) row = cur:fetch(row) end -- close cursor cur:close() end end
Le 19/06/2014 15:37, Frank Barknecht via Pd-list a écrit :
Hi,
is it already 7 years ago? Anyway, in 2007 I posted an example using luaSQL and Pdlua that should still work: http://lists.puredata.info/pipermail/pd-dev/2007-11/009964.html
Ciao
Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
On 13/07/14 11:11, Jack via Pd-list wrote:
and used the code below to create a file 'mysql.pd_lua'.
But when i tried to create [mysql] object in Pd, i got in the pd console : maximum object loading depth 1000 reached mysql ... couldn't create
Did I miss something ?
local M = pd.Class:new():register("lsql")
The file should register a class with the same name, otherwise you get a "can't create". The other classes registered should work after that, similar to loading with -lib.
Not sure where the maximum loading depth error happens, but I could reproduce it with an empty nonsense.pd_lua and trying to create [nonsense].
I'm using these versions:
$ pd -version Pd-0.45.5 ("") compiled 18:50:42 Jun 18 2014
lua 0.8 (GPL) 2013 Claude Heiland-Allen, merging pdlua 0.7.1 (GPL) 2011 Martin Peach, based on lua 0.6~svn (GPL) 2008 Claude Heiland-Allen lua: compiled for pd-0.45 on Jun 18 2014 19:11:04
compiled against Debian's lua5.1
(I merged Martin Peach's bugfixes into my gitorious repo, because I had trouble building the version from svn)
I forgot :
Pd 0.45.0test 2 pdlua 0.7.2 (GPL) 2014 Martin Peach, based on lua 0.6~svn (GPL) 2008 Claude Heiland-Allen claudiusmaximus@goto10.org pdlua: compiled for pd-0.43 on Jul 13 2014 11:47:47 Using lua version 5.2 ++
Jack
Le 13/07/2014 12:59, Claude Heiland-Allen via Pd-list a écrit :
On 13/07/14 11:11, Jack via Pd-list wrote:
and used the code below to create a file 'mysql.pd_lua'.
But when i tried to create [mysql] object in Pd, i got in the pd console : maximum object loading depth 1000 reached mysql ... couldn't create
Did I miss something ?
local M = pd.Class:new():register("lsql")
The file should register a class with the same name, otherwise you get a "can't create". The other classes registered should work after that, similar to loading with -lib.
Not sure where the maximum loading depth error happens, but I could reproduce it with an empty nonsense.pd_lua and trying to create [nonsense].
I'm using these versions:
$ pd -version Pd-0.45.5 ("") compiled 18:50:42 Jun 18 2014
lua 0.8 (GPL) 2013 Claude Heiland-Allen, merging pdlua 0.7.1 (GPL) 2011 Martin Peach, based on lua 0.6~svn (GPL) 2008 Claude Heiland-Allen lua: compiled for pd-0.45 on Jun 18 2014 19:11:04
compiled against Debian's lua5.1
(I merged Martin Peach's bugfixes into my gitorious repo, because I had trouble building the version from svn)
Claude
On 2014-07-13 06:59, Claude Heiland-Allen via Pd-list wrote:
$ pd -version Pd-0.45.5 ("") compiled 18:50:42 Jun 18 2014
lua 0.8 (GPL) 2013 Claude Heiland-Allen, merging pdlua 0.7.1 (GPL) 2011 Martin Peach, based on lua 0.6~svn (GPL) 2008 Claude Heiland-Allen lua: compiled for pd-0.45 on Jun 18 2014 19:11:04
compiled against Debian's lua5.1
(I merged Martin Peach's bugfixes into my gitorious repo, because I had trouble building the version from svn)
What kind of trouble did you have?
Martin
On 13/07/14 15:56, Martin Peach wrote:
On 2014-07-13 06:59, Claude Heiland-Allen via Pd-list wrote:
$ pd -version Pd-0.45.5 ("") compiled 18:50:42 Jun 18 2014
lua 0.8 (GPL) 2013 Claude Heiland-Allen, merging pdlua 0.7.1 (GPL) 2011 Martin Peach, based on lua 0.6~svn (GPL) 2008 Claude Heiland-Allen lua: compiled for pd-0.45 on Jun 18 2014 19:11:04
compiled against Debian's lua5.1
(I merged Martin Peach's bugfixes into my gitorious repo, because I had trouble building the version from svn)
What kind of trouble did you have?
There wasn't a build system in the relevant directory. I did this some time ago so it might have changed since...
On 2014-07-13 11:01, Claude Heiland-Allen via Pd-list wrote:
On 13/07/14 15:56, Martin Peach wrote:
On 2014-07-13 06:59, Claude Heiland-Allen via Pd-list wrote:
$ pd -version Pd-0.45.5 ("") compiled 18:50:42 Jun 18 2014
lua 0.8 (GPL) 2013 Claude Heiland-Allen, merging pdlua 0.7.1 (GPL) 2011 Martin Peach, based on lua 0.6~svn (GPL) 2008 Claude Heiland-Allen lua: compiled for pd-0.45 on Jun 18 2014 19:11:04
compiled against Debian's lua5.1
(I merged Martin Peach's bugfixes into my gitorious repo, because I had trouble building the version from svn)
What kind of trouble did you have?
There wasn't a build system in the relevant directory. I did this some time ago so it might have changed since...
I think the way to do it is using the makefile in the externals directory of svn trunk. From /externals do: make loaders-pdlua That should set up the paths properly.
Martin
Claude
On 13/07/14 16:15, Martin Peach wrote:
On 2014-07-13 11:01, Claude Heiland-Allen via Pd-list wrote:
On 13/07/14 15:56, Martin Peach wrote:
On 2014-07-13 06:59, Claude Heiland-Allen via Pd-list wrote:
$ pd -version Pd-0.45.5 ("") compiled 18:50:42 Jun 18 2014
lua 0.8 (GPL) 2013 Claude Heiland-Allen, merging pdlua 0.7.1 (GPL) 2011 Martin Peach, based on lua 0.6~svn (GPL) 2008 Claude Heiland-Allen lua: compiled for pd-0.45 on Jun 18 2014 19:11:04
compiled against Debian's lua5.1
(I merged Martin Peach's bugfixes into my gitorious repo, because I had trouble building the version from svn)
What kind of trouble did you have?
There wasn't a build system in the relevant directory. I did this some time ago so it might have changed since...
I think the way to do it is using the makefile in the externals directory of svn trunk. From /externals do: make loaders-pdlua That should set up the paths properly.
Right. I didn't fancy getting the whole externals tree, just the part I wanted (pdlua) and there wasn't any way to build it "locally".
On 2014-07-13 11:30, Claude Heiland-Allen via Pd-list wrote:
On 13/07/14 16:15, Martin Peach wrote:
On 2014-07-13 11:01, Claude Heiland-Allen via Pd-list wrote:
On 13/07/14 15:56, Martin Peach wrote:
On 2014-07-13 06:59, Claude Heiland-Allen via Pd-list wrote:
$ pd -version Pd-0.45.5 ("") compiled 18:50:42 Jun 18 2014
lua 0.8 (GPL) 2013 Claude Heiland-Allen, merging pdlua 0.7.1 (GPL) 2011 Martin Peach, based on lua 0.6~svn (GPL) 2008 Claude Heiland-Allen lua: compiled for pd-0.45 on Jun 18 2014 19:11:04
compiled against Debian's lua5.1
(I merged Martin Peach's bugfixes into my gitorious repo, because I had trouble building the version from svn)
What kind of trouble did you have?
There wasn't a build system in the relevant directory. I did this some time ago so it might have changed since...
I think the way to do it is using the makefile in the externals directory of svn trunk. From /externals do: make loaders-pdlua That should set up the paths properly.
Right. I didn't fancy getting the whole externals tree, just the part I wanted (pdlua) and there wasn't any way to build it "locally".
You just need the makefile that is in trunk/externals then. (and trunk/externals/loaders/pdlua)
make loaders-pdlua just builds the pdlua stuff.
Martin
Quoting Martin Peach via Pd-list pd-list@lists.iem.at:
On 2014-07-13 11:30, Claude Heiland-Allen via Pd-list wrote:
Right. I didn't fancy getting the whole externals tree, just the part I wanted (pdlua) and there wasn't any way to build it "locally".
You just need the makefile that is in trunk/externals then. (and
trunk/externals/loaders/pdlua)
i just noticed that pdlua has not been packaged for Debian, and i
think this should be changed.
however, not having a self-contained build-system is, hmm, ugly.
given that the template/Makefile has been the "way to go" for some
time now, would you consider adding/switching?
fmgasdr IOhannes
On 2014-07-15 12:31, via Pd-list wrote:
Quoting Martin Peach via Pd-list pd-list@lists.iem.at:
On 2014-07-13 11:30, Claude Heiland-Allen via Pd-list wrote:
Right. I didn't fancy getting the whole externals tree, just the part I wanted (pdlua) and there wasn't any way to build it "locally".
You just need the makefile that is in trunk/externals then. (and trunk/externals/loaders/pdlua)
i just noticed that pdlua has not been packaged for Debian, and i think this should be changed.
however, not having a self-contained build-system is, hmm, ugly.
given that the template/Makefile has been the "way to go" for some time now, would you consider adding/switching?
I thought it _was_ following the template. There is a makefile in pdlua/src. I'm not sure what to add to it to make it self-contained. All the compiler needs to know is the locations of m_pd.h and lua.h, and the linker needs to find the right liblua.
Martin
On 07/16/2014 02:23 PM, Martin Peach via Pd-list wrote:
given that the template/Makefile has been the "way to go" for some time now, would you consider adding/switching?
I thought it _was_ following the template. There is a makefile in pdlua/src. I'm not sure what to add to it to make it self-contained. All the compiler needs to know is the locations of m_pd.h and lua.h, and the linker needs to find the right liblua.
yes indeed. sorry.
my answer was rather generic (me being basically on holiday, without a real computer, and not being able to *easily* check the actual state of affairs) and i assumed that your answer ("You just need the makefile that is in trunk/externals then") explained that you need an ressource outside the pdlua/ folder (that said Makefile).
so the build-system seems to be self-contained, but my build fails because of an unknown CFLAG "-threepic" (for linux). what it this supposed to do and can it be safely removed?
i then managed to build pdlua using:
$ make LUACFLAGS="$(pkg-config --cflags lua5.2 pd)" LIBS="$(pkg-config --libs lua5.2 pd)"
but this somehow feels wrong because it overrides the "-DVERSION=..." of LUACFLAGS. what is the proper way to *only* set the lua-cflags / -libs from the cmdline?
the build correctly loads the hello.pd_lua, but i tested list-pak and it throws me a number of errors:
lua: error in dispatcher: [string "list-pak"]:51: attempt to call field 'getn' (a nil value)
gfmdsr IOhannes
On 07/19/2014 09:17 AM, IOhannes m zmölnig via Pd-list wrote:
i then managed to build pdlua using:
$ make LUACFLAGS="$(pkg-config --cflags lua5.2 pd)" LIBS="$(pkg-config --libs lua5.2 pd)"
but this somehow feels wrong because it overrides the "-DVERSION=..." of LUACFLAGS. what is the proper way to *only* set the lua-cflags / -libs from the cmdline?
the build correctly loads the hello.pd_lua, but i tested list-pak and it throws me a number of errors:
lua: error in dispatcher: [string "list-pak"]:51: attempt to call field 'getn' (a nil value)
after a bit of research this turned out to be a "problem" in lua: the table.getn() function has been deprecated in lua5.1 and removed in lua5.2, hence those lua-externs are no longer working with recent versions of lua.
similariy [lexpr] doesn't work any more since getfenv/setfenv have been removed in lua5.2
these probably should be fixed by some lua savy.
gfmadsr IOhannes
On 2014-07-19 07:34, IOhannes m zmölnig via Pd-list wrote:
On 07/19/2014 09:17 AM, IOhannes m zmölnig via Pd-list wrote:
..
the build correctly loads the hello.pd_lua, but i tested list-pak and it throws me a number of errors:
lua: error in dispatcher: [string "list-pak"]:51: attempt to call field 'getn' (a nil value)
after a bit of research this turned out to be a "problem" in lua: the table.getn() function has been deprecated in lua5.1 and removed in lua5.2, hence those lua-externs are no longer working with recent versions of lua.
Those are now fixed in svn, I used the '#' operator instead of table.getn, it should work as in these cases the tables never have holes in them.
similariy [lexpr] doesn't work any more since getfenv/setfenv have been removed in lua5.2
That is more difficult as a fix for 5.2 will be incompatible with lua5.1. The lua version is available to the script so maybe it could be done with 'if' statements as long as lua doesn't try to evaluate the non-compatible code.
Martin