[PD] Pd and SQL

patrice colet via Pd-list pd-list at lists.iem.at
Mon Jun 23 21:05:37 CEST 2014


  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




More information about the Pd-list mailing list