Commit 48a82fb1 authored by Ted Trask's avatar Ted Trask
Browse files

Fixed adhocquery to return columns in proper order

parent cc7cd9d7
......@@ -16,9 +16,7 @@ html = require("acf.html")
<% else %>
<TABLE>
<TR style="font-weight:bold;">
<% names = {}
for name,val in pairs(form.value.result.value[1]) do
names[#names+1] = name %>
<% for i,name in ipairs(form.value.names.value) do %>
<TD class="header"><%= html.html_escape(name) %></TD>
<% end %>
</TR>
......@@ -27,7 +25,7 @@ html = require("acf.html")
local mark = ''
if (b == 0) then mark=' class="mark"' end %>
<TR<%= mark %>>
<% for j,name in ipairs(names) do %>
<% for j,name in ipairs(form.value.names.value) do %>
<TD><%= html.html_escape(row[name]) %></TD>
<% end %>
</TR>
......
......@@ -86,14 +86,10 @@ function mymodule.downloadadhocquery(self)
local file = cfe({ type="longtext", value="", label="weblogadhocquery.tab" })
if retval.value.result and #retval.value.result.value > 0 then
local columns = {}
for name,val in pairs(retval.value.result.value[1]) do
columns[#columns+1] = name
end
local content = {table.concat(columns, "\t")}
local content = {table.concat(retval.value.names.value, "\t")}
for i,entry in ipairs(retval.value.result.value) do
local line = {}
for i,name in ipairs(columns) do
for i,name in ipairs(retval.value.names.value) do
line[#line+1] = entry[name] or ""
end
content[#content+1] = table.concat(line, "\t")
......
......@@ -1357,6 +1357,10 @@ function mymodule.adhocquery(self, query)
query.value.query.errtxt = err or "Select failed"
query.errtxt = "Query failed"
else
query.value.names = cfe({ type="list", value={}, label="Column names" })
query.value.names.value = cur:getcolnames()
query.value.types = cfe({ type="list", value={}, label="Column types" })
query.value.types.value = cur:getcoltypes()
query.value.result = cfe({ type="list", value={}, label="Select result" })
local result = query.value.result.value
local row = cur:fetch ({}, "a")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment