Hallo,
Frank Barknecht hat gesagt: // Frank Barknecht wrote:

> pdlua is easier to build than pyext so you may try Claude's pdlua with
> luasql: http://www.keplerproject.org/luasql/

So, I hacked together a quick example with not much error checking.
Tested on Debian with the package: liblua5.1-sql-sqlite2

(Claude, feel free to include it in pdlua with whatever license.)

Ciao
-- 
 Frank Barknecht                                     _ ______footils.org__

Attachment: lsql-help.pd
Description: application/puredata

-- SQL example for pdlua
-- Written by Frank Barknecht in 2007, use however you like.

-- load driver
require "luasql.sqlite"

local M = pd.Class:new():register("lsql")

function M:initialize(name)
    -- create environment object
    self.env = assert (luasql.sqlite())
    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


_______________________________________________
PD-dev mailing list
PD-dev@iem.at
http://lists.puredata.info/listinfo/pd-dev

Reply via email to