lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Florian:
I am getting this error after I added, this is pointing to dfunction db.escape, I added function below, also I kept modifed code, appreciated fro any help
db.lua:38  attempt to call method 'escape' (a nil value)



--************* Requires *************

require "luasql.sqlite3"

--************* Initial Code *************

--package db
db = {}

--create environment object
local _DB_env = luasql.sqlite3()
local _DB_con = nil

--************* Functions *************

--Connect to the given DB.
function db.connect (dbname)
        _DB_con = _DB_env:connect(dbname)
end

--escape to the given DB.
function db.escape (str)
        return _DB_con:escape(str)
end


                if (v ~= "_ROWID_") then
                        insertPart = insertPart .. "\'" .. db.escape(v) .. "\', "
                        -- if post contained field already
                        if notFullKey and util.tableKeyExists(tableInput, v) then
                                valuesPart = valuesPart .. "\'" .. _DB_con:escape(tableInput[v]) .. "\', "
                        elseif util.tableKeyExists(tableInput, tablename .. "." .. db.escape(v)) then
                                valuesPart = valuesPart .. "\'" .. tableInput[tablename .. "." .. db.escape(v)] .. "\', "
                        -- else if default exists, use it
                        elseif defaults[tablename .. "." .. db.escape(v)] then
                                valuesPart = valuesPart .. "\'" .. defaults[tablename .. "." .. db.escape(v)] .. "\', "
                        -- else use empty string
                        else
                                valuesPart = valuesPart .. "NULL, "
                        end
                end









On Wed, Feb 3, 2010 at 12:35 PM, Florian Weimer <fw@deneb.enyo.de> wrote:
* Vasanta:

> Thanks a lot, appreciated, let me add this, also let me delete "|", it
> should look like "conn:escape(v)," instead "v" right?.

Yes, or db.escape(v), once you've added that function.