lua-users home
lua-l archive

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


I’m writing a SQL interface for Oracle and have a question on representing the result sets.
 
My approach is to create tables that look like this:
 
        resultMeta = {
                columnA = {pos = 1, type = varchar2, length = 11, precision = nil},
                columnB = {pos = 2, type = number  , length = 5, precision =   2},
                columnC = {pos = 3, type = varchar2, length = 40, precision = nil},
                columnD = {pos = 4, type = date    , length = nil, precision = nil},
        }
 
        resultSet[1] = {[[e]], 0, nil, [[2010/12/25 00:00:00 UTC]]}
 
        result = { meta = resultMeta, set = resultSet, rowCount = #set }
 
That makes it tough for the developers to use the data. They have to use
 
        row = result.set[rowNumber]
        val = row[result.meta[columnB].pos]
 
I’d like something friendlier like
        result[rowNumber][columnB]
 
I can’t figure out how write that in lua. I made the result set look like
 
        resultSet[1] = {
                columnA = [[e]],
                columnB = 0,
                columnC = nil,
                columnD = [[2010/12/25 00:00:00 UTC]]
        }
 
I’m stumped with the [x][y] reference. Is this harder than it seems because I’m not thinking this through using a Lua idiom?
 
 
I know that it’s too early to concentrate on optimizing, but I am concerned that looking up via a string key will be slower than via a numeric key. Since this will be operating in a loop over large data sets (daily runs with a set of a million rows), little improvements may help.