diff options
author | Marius <mariausol@gmail.com> | 2013-04-14 18:00:22 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2013-04-14 18:00:22 +0300 |
commit | f9e6297b56352c1e9035ebff52be3628f5aa730e (patch) | |
tree | d93cdaacd20755044eedf91d70412ae42e3cef14 /tex/context/base/util-sql-imp-swiglib.lua | |
parent | f6ff9314919dcb50694d981613611e3ded95872d (diff) | |
download | context-f9e6297b56352c1e9035ebff52be3628f5aa730e.tar.gz |
beta 2013.04.14 16:51
Diffstat (limited to 'tex/context/base/util-sql-imp-swiglib.lua')
-rw-r--r-- | tex/context/base/util-sql-imp-swiglib.lua | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/tex/context/base/util-sql-imp-swiglib.lua b/tex/context/base/util-sql-imp-swiglib.lua index 9a22477a9..719620a6f 100644 --- a/tex/context/base/util-sql-imp-swiglib.lua +++ b/tex/context/base/util-sql-imp-swiglib.lua @@ -110,7 +110,10 @@ local typemap = mysql.MYSQL_TYPE_VAR_STRING and { -- real_escape_string local function finish(t) - mysql_free_result(t._result_) + local r = t._result_ + if r then + mysql_free_result(r) + end end -- will become metatable magic @@ -203,9 +206,17 @@ local mt = { __index = { numrows = numrows, getcolnames = getcolnames, getcoltypes = getcoltypes, + -- fallback + _result_ = nil, + names = { }, + types = { }, + noffields = 0, + nofrows = 0, } } +local nt = setmetatable({},mt) + -- session local function close(t) @@ -218,24 +229,28 @@ local function execute(t,query) local result = mysql_execute_query(connection,query,#query) if result == 0 then local result = mysql_store_result(connection) - mysql_field_seek(result,0) - local nofrows = mysql_num_rows(result) or 0 - local noffields = mysql_num_fields(result) - local names = { } - local types = { } - for i=1,noffields do - local field = mysql_fetch_field(result) - names[i] = field.name - types[i] = field.type + if result then + mysql_field_seek(result,0) + local nofrows = mysql_num_rows(result) or 0 + local noffields = mysql_num_fields(result) + local names = { } + local types = { } + for i=1,noffields do + local field = mysql_fetch_field(result) + names[i] = field.name + types[i] = field.type + end + local t = { + _result_ = result, + names = names, + types = types, + noffields = noffields, + nofrows = nofrows, + } + return setmetatable(t,mt) + else + return nt end - local t = { - _result_ = result, - names = names, - types = types, - noffields = noffields, - nofrows = nofrows, - } - return setmetatable(t,mt) end end return false |