lua-users home
lua-l archive

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


On Sun, Mar 13, 2011 at 22:04, Henderson, Michael D
<michael.d.henderson@lmco.com> wrote:
> I’m trying to dynamically bind parameters based on a table being passed to
> my C function.
>
> The Lua side looks like
>
> query = “select * from foo where key = :key and foo between :lbound and
> :ubound”
> parms = { key = ‘JAN03’, lbound = 0, ubound = 30}
>
> exec(query, parms);
>
> And the library function looks something like
>
> // C library
> nParms = lua_istable(L,2) ? lua_objlen(L,2) : 0;
>
> for (idx = 1; idx <= nParms; ++idx) {
>   int type = // how do I get the type of the parameter?
>
>   switch (type) {
>   case LUA_TNUMBER:
>      bindNumber(nameOfParameter, valueOfParameter);
>        // how do I get the name of the parameter?
>        // how do I get the value of the parameter?
>
> I’ve been going through the PIL and looking at the source of luasql and
> luasqlite, but I don’t see anything like what I’m trying to. I’d appreciate
> being pointed in the right direction.
>
> Thanks,
> Mike
>

For type, look up lua_type, although lua_isnumber and friends are
usually what you want.
Also since your 'params' table has no integer keys, lua_objlen() will
return zero. You want lua_next() to iterate named keys.

-- 
Sent from my toaster.