diff options
author | Pixel <pixel@nobis-crew.org> | 2009-09-30 16:24:06 -0700 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2009-09-30 16:24:06 -0700 |
commit | 15c9b1d365b31e37e2163375c5a643179c46e6ff (patch) | |
tree | 2b3a4d46a325c618cd12d2e55d0fe6faf9a0a3d9 /lib | |
parent | cd5af67c1d0266c38ddce37f72e906726a776b9c (diff) |
Fixing a few bugs, moving Desc from hitten to public, and adding the rawselect methods.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dblib.lua | 93 |
1 files changed, 58 insertions, 35 deletions
diff --git a/lib/dblib.lua b/lib/dblib.lua index 6b4599a..a47b755 100644 --- a/lib/dblib.lua +++ b/lib/dblib.lua @@ -194,11 +194,50 @@ END; return r, alters, keys, extras end, + newtable = function(tablename, tname, db, ddl) + return { + insert = _luadb.insert, + delete = _luadb.delete, + select = _luadb.select, + gselect = _luadb.gselect, + rselect = _luadb.rselect, + grselect = _luadb.grselect, + update = _luadb.update, + pinsert = function(...) return pcall(_luadb.insert, ...) end, + pdelete = function(...) return pcall(_luadb.delete, ...) end, + pselect = function(...) return pcall(_luadb.select, ...) end, + pgselect = function(...) return pcall(_luadb.gselect, ...) end, + prselect = function(...) return pcall(_luadb.rselect, ...) end, + pgrselect = function(...) return pcall(_luadb.grselect, ...) end, + pupdate = function(...) return pcall(_luadb.update, ...) end, + numrows = _luadb.numrows, + numfields = _luadb.numfields, + nextrow = _luadb.nextrow, + count = _luadb.count, + restrict = _luadb.restrict, + restricter = _luadb.restricter, + empty = _luadb.empty, + _ = { + tablename = tablename, + tname = tname, + db = db, + ddl = ddl, + conditions = "1=1", + }, + } + end, + opentable = function(db, tablename, ddl, force_create) + local tname + if db._.prefix and db._.prefix ~= "" and db._.odbc_name == "oracle" then + tname = db._.fq .. db._.prefix .. db._.fq .. '.' .. db._.fq .. db.sql_escape(tablename) .. db._.fq + else + tname = db._.fq .. db._.prefix .. db.sql_escape(tablename) .. db._.fq + end + if not ddl then return _luadb.newtable(tablename, tname, db, ddl) end local fields, alters, keys, extras = _luadb.generate_fields(db, tablename, ddl) - local tname = db._.fq .. db._.prefix .. db.sql_escape(tablename) .. db._.fq local operations = 0 - local dfields = db._.Desc(db, tablename) + local dfields = db:Desc(tablename) if force_create or dfields == nil then -- table doesn't exist, create it @@ -337,32 +376,7 @@ END; end end - return { - insert = _luadb.insert, - delete = _luadb.delete, - select = _luadb.select, - gselect = _luadb.gselect, - update = _luadb.update, - pinsert = function(...) return pcall(_luadb.insert, ...) end, - pdelete = function(...) return pcall(_luadb.delete, ...) end, - pselect = function(...) return pcall(_luadb.select, ...) end, - pgselect = function(...) return pcall(_luadb.gselect, ...) end, - pupdate = function(...) return pcall(_luadb.update, ...) end, - numrows = _luadb.numrows, - numfields = _luadb.numfields, - nextrow = _luadb.nextrow, - count = _luadb.count, - restrict = _luadb.restrict, - restricter = _luadb.restricter, - empty = _luadb.empty, - _ = { - tablename = tablename, - tname = tname, - db = db, - ddl = ddl, - conditions = "1", - }, - }, operations + return newtable(tablename, tname, db, ddl), operations end, compare_fields = function(db, ddl, field) @@ -625,7 +639,7 @@ END; end if foreign then - local foreign_conds = "1" + local foreign_conds = "1=1" stmt = stmt .. " FROM " .. t._.tname local found_table, fname, f for k, v in pairs(foreign) do @@ -718,6 +732,10 @@ END; return _luadb.iselect(false, ...) end, + rselect = function(...) + return _luadb.iselect(true, ...) + end, + numrows = function(t) if t._.db._.odbc_name == "mysql" then return t._.db._.conn:NumRows() @@ -749,6 +767,11 @@ END; return t.nextrow, t end, + grselect = function(t, ...) + _luadb.iselect(true, t, ...) + return t.nextrow, t + end, + nextrow = function(t) if t._.db._.odbc_name == "mysql" then return t._.db._.conn:FetchRow() @@ -756,7 +779,7 @@ END; local row = nil if t._.db._.rset:next() ~= 0 then row = {} - for k, v in t._.db._.fieldsNames do + for k, v in pairs(t._.db._.fieldsNames) do row[v] = t._.db._.rset:getString(k) end end @@ -827,7 +850,7 @@ END; restrict = function(t, conditions) -- all in all, "conditions" can just be a direct string. Let the programmer do what he wants, after all. - if conditions == nil or conditions == "" then conditions = "1" end + if conditions == nil or conditions == "" then conditions = "1=1" end t._.conditions = conditions end, @@ -861,7 +884,7 @@ END; oracle = { _SafeQuery = function(db, str, query_type, no_commit) local r = -1 - + if luadb.debugmode then print(str) end @@ -999,7 +1022,7 @@ END; elseif col.PRECISION_NUM then row.Type = row.Type .. "(" .. col.PRECISION_NUM .. ")" else - if row.Type == "NUMBER" and (col.SCALE + 0) == 0 then + if row.Type == "NUMBER" and (not col.SCALE or ((col.SCALE + 0) == 0)) then row.Type = "INT" end row.Type = row.Type .. "(" .. col.LENGTH .. ")" @@ -1065,6 +1088,7 @@ luadb = { ErrNO = function(db) return db._.conn:ErrNO() end, Error = function(db) return db._.conn:Error() end, ErrorStr = function(db) return db._.conn:ErrNO() .. " - " .. db._.conn:Error() end, + Desc = _luadb.mysql.Desc, _ = { fq = '`', eq = '"', @@ -1075,7 +1099,6 @@ luadb = { base = base, prefix = sql_escape(prefix or ""), odbc_name = "mysql", - Desc = _luadb.mysql.Desc, }, } end, }, @@ -1106,6 +1129,7 @@ luadb = { ErrNO = function(db) return db._.errNO end, Error = function(db) return db._.errStr end, ErrorStr = function(db) return db._.errStr end, + Desc = _luadb.oracle.Desc, _ = { fq = '"', eq = "'", @@ -1116,7 +1140,6 @@ luadb = { base = base, prefix = sql_escape(prefix or ""), odbc_name = "oracle", - Desc = _luadb.oracle.Desc, }, } |