diff options
-rw-r--r-- | kamailio-listtables-html.lsp | 9 | ||||
-rw-r--r-- | kamailio-model.lua | 82 |
2 files changed, 91 insertions, 0 deletions
diff --git a/kamailio-listtables-html.lsp b/kamailio-listtables-html.lsp index 38dd4f0..f8bdd33 100644 --- a/kamailio-listtables-html.lsp +++ b/kamailio-listtables-html.lsp @@ -5,6 +5,7 @@ <H1><%= html.html_escape(form.label) %></H1> <DL> +<<<<<<< HEAD <% for i,v in ipairs(form.value) do %> <li> <% if viewlibrary.check_permission("viewtable") then %> @@ -15,6 +16,14 @@ <% end %> <% else %> <%= html.html_escape("("..v.schema..") "..v.table) %> +======= +<% for i,table in ipairs(form.value) do %> + <li> + <% if viewlibrary.check_permission("viewtable") then %> + <%= html.link{value = "viewtable?table=" .. table, label=table} %> + <% else %> + <%= html.html_escape(table) %> +>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96 <% end %> <% end %> <% if #form.value == 0 and viewlibrary.check_permission("createdatabase") then %> diff --git a/kamailio-model.lua b/kamailio-model.lua index ed05f85..bee2cb8 100644 --- a/kamailio-model.lua +++ b/kamailio-model.lua @@ -103,9 +103,15 @@ end local listtables = function() local result = {} if DBENGINE == "PGSQL" then +<<<<<<< HEAD local tab = getselectresponse("SELECT tablename, schemaname FROM pg_tables WHERE tablename !~* 'pg_*' ORDER BY schemaname, tablename ASC") for i,t in ipairs(tab) do result[#result+1] = {schema=t.schemaname, table=t.tablename} +======= + local tab = getselectresponse("SELECT tablename FROM pg_tables WHERE tablename !~* 'pg_*' ORDER BY tablename ASC") + for i,t in ipairs(tab) do + result[#result+1] = t.tablename +>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96 end else -- untested @@ -114,6 +120,7 @@ local listtables = function() return result end +<<<<<<< HEAD local listcolumns = function(table, schema) local result = {} if DBENGINE == "PGSQL" then @@ -124,6 +131,12 @@ local listcolumns = function(table, schema) col = getselectresponse("SELECT column_name AS field FROM information_schema.columns WHERE table_name='"..table.."' ORDER BY ordinal_position") end +======= +local listcolumns = function(table) + local result = {} + if DBENGINE == "PGSQL" then + local col = getselectresponse("SELECT a.attname AS field FROM pg_class c, pg_attribute a, pg_type t WHERE c.relname = '"..table.."' AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid ORDER BY a.attnum") +>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96 for i,c in ipairs(col) do result[#result+1] = c.field end @@ -319,6 +332,7 @@ function list_tables() return cfe({ type="list", value=retval, label="List of Database Tables", errtxt=errtxt }) end +<<<<<<< HEAD function list_table_entries(req_table) local retval = {} -- split up the schema from the table @@ -329,6 +343,11 @@ function list_table_entries(req_table) table = req_table end retval.table = cfe({ value=req_table or "", label="Table" }) +======= +function list_table_entries(table) + local retval = {} + retval.table = cfe({ value=table or "", label="Table" }) +>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96 retval.fields = cfe({ type="list", value={}, label="List of Table Fields" }) retval.entries = cfe({ type="structure", value={}, label="List of Database Entries" }) local errtxt @@ -339,6 +358,7 @@ function list_table_entries(req_table) retval.table.errtxt = "Table does not exist" errtxt = "Table does not exist" for i,t in ipairs(tables) do +<<<<<<< HEAD if t.table == table then retval.table.errtxt = nil errtxt = nil @@ -349,6 +369,13 @@ function list_table_entries(req_table) retval.entries.value = getselectresponse("SELECT * FROM "..table) or {} end retval.fields.value = listcolumns(table, schema) or {} +======= + if t == table then + retval.table.errtxt = nil + errtxt = nil + retval.entries.value = getselectresponse("SELECT * FROM "..table.." ORDER BY id ASC") or {} + retval.fields.value = listcolumns(table) or {} +>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96 end end if connected then databasedisconnect() end @@ -356,6 +383,7 @@ function list_table_entries(req_table) if not res and err then errtxt = err end +<<<<<<< HEAD return cfe({ type="group", value=retval, label="Database Table Entries", errtxt=errtxt }) end @@ -371,28 +399,51 @@ function get_table_entry(req_table, id) retval.table = cfe({ value=req_table or "", label="Table", errtxt="Table does not exist", seq=0 }) local errtxt = "Table does not exist" if req_table and req_table ~= "" then +======= + + return cfe({ type="group", value=retval, label="Database Table Entries", errtxt=errtxt }) +end + +function get_table_entry(table, id) + local retval = {} + retval.table = cfe({ value=table or "", label="Table", errtxt="Table does not exist", seq=0 }) + local errtxt = "Table does not exist" + if table and table ~= "" then +>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96 local res, err = pcall(function() local connected = databaseconnect() local tables = listtables() for i,t in ipairs(tables) do +<<<<<<< HEAD if t.table == table then +======= + if t == table then +>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96 retval.table.errtxt = nil errtxt = nil break end end if not errtxt then +<<<<<<< HEAD local fields = listcolumns(table, schema) +======= + local fields = listcolumns(table) +>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96 for i,f in ipairs(fields) do retval[f] = cfe({ label=f, seq=i }) end if id and id ~= "" then +<<<<<<< HEAD local entry if schema then entry = getselectresponse("SELECT * FROM "..schema.."."..table.." WHERE id='"..escape(id).."'") else entry = getselectresponse("SELECT * FROM "..table.." WHERE id='"..escape(id).."'") end +======= + local entry = getselectresponse("SELECT * FROM "..table.." WHERE id='"..escape(id).."'") +>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96 if entry and #entry > 0 then for n,v in pairs(entry[1]) do if retval[n] then retval[n].value = v end @@ -435,6 +486,7 @@ function update_table_entry(entry, create) local res, err = pcall(function() local connected = databaseconnect() local tables = listtables() +<<<<<<< HEAD local schema, tablename schema, tablename = string.match(entry.value.table.value, "(.+)%.(.+)") success = false @@ -444,6 +496,12 @@ function update_table_entry(entry, create) entry.value.table.errtxt = "Table does not exist" for i,t in ipairs(tables) do if t.table == tablename then +======= + success = false + entry.value.table.errtxt = "Table does not exist" + for i,t in ipairs(tables) do + if t == entry.value.table.value then +>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96 success = true entry.value.table.errtxt = nil break @@ -462,6 +520,7 @@ function update_table_entry(entry, create) local values = {} for n,v in pairs(entry.value) do if n ~= "table" and n ~= "id" then +<<<<<<< HEAD --- !!! HACK !!! --- --- Fix for DISTributary Phone System Tool: ASHP --- @@ -474,6 +533,8 @@ function update_table_entry(entry, create) v.value = "0" end end +======= +>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96 names[#names+1] = n values[#values+1] = escape(v.value) end @@ -502,6 +563,7 @@ function update_table_entry(entry, create) return entry end +<<<<<<< HEAD function delete_table_entry(req_table, id) local result = "" local errtxt @@ -513,6 +575,12 @@ function delete_table_entry(req_table, id) table = req_table end if not req_table or req_table == "" then +======= +function delete_table_entry(table, id) + local result = "" + local errtxt + if not table or table == "" then +>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96 errtxt = "Invalid table" elseif not id or id == "" then errtxt = "Invalid entry" @@ -522,18 +590,26 @@ function delete_table_entry(req_table, id) errtxt = "Invalid table" local tables = listtables() for i,t in ipairs(tables) do +<<<<<<< HEAD if t.table == table then +======= + if t == table then +>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96 errtxt = nil break end end if not errtxt then +<<<<<<< HEAD local sql if schema then sql = "DELETE FROM "..schema.."."..table.." WHERE id='"..escape(id).."'" else sql = "DELETE FROM "..table.." WHERE id='"..escape(id).."'" end +======= + local sql = "DELETE FROM "..table.." WHERE id='"..escape(id).."'" +>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96 runsqlcommand(sql) result = "Entry Deleted" end @@ -564,9 +640,15 @@ function search_database(id, value, comparison) local connected = databaseconnect() local tables = listtables() or {} for i,t in ipairs(tables) do +<<<<<<< HEAD local columns = listcolumns(t.table) or {} for i,c in ipairs(columns) do retval.id.option[#retval.id.option + 1] = t.table.."."..c +======= + local columns = listcolumns(t) or {} + for i,c in ipairs(columns) do + retval.id.option[#retval.id.option + 1] = t.."."..c +>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96 end end -- Get the rows from the DB |