One way you could workaround this is to implement your own automatic
HTML generation in your procedure. This is actually a very good option
since it gives you full control over how the HTML table will be
formatted.
I have written a function called dynamic_sql_to_html that takes in a
query string as input, and returns a string containing the a formatted
HTML string that exactly mimics the built-in HTML support in the
server. It uses the sa_describe_query() procedure to analyze the
result set of the input sql query string, and dynamically builds a new
query to return a properly formatted HTML result set.
create function dynamic_sql_to_html(dynamic_sql_query long varchar)
returns long varchar
begin
declare html_table_header long varchar;
declare xml_query long varchar;
declare temp_table_definition long varchar;
declare temp_table_column_list long varchar;
declare res long varchar;
call sa_set_http_header('Content-type', 'text/html');
select
XMLELEMENT(name tr, XMLATTRIBUTES('header' as class), XMLAGG
(XMLELEMENT(name th, XMLCONCAT(XMLELEMENT(name small,
"base_table_name"), XMLELEMENT(name br), XMLELEMENT(name b,
"name"))))),
'XMLAGG(XMLELEMENT(name tr, xmlconcat(' || list('XMLELEMENT(name
td, "' || "name" || '")') || ')) order by
sa_maintain_order_of_derived_table)',
'declare local temporary table sa_foo
(sa_maintain_order_of_derived_table int default autoincrement, ' ||
list('"' || "name" || '" ' || "domain_name_with_size", ',') || ')',
LIST('"' || "name" || '"', ',')
into html_table_header, xml_query, temp_table_definition,
temp_table_column_list
from sa_describe_query(dynamic_sql_query);
execute immediate temp_table_definition;
execute immediate 'insert into sa_foo(' || temp_table_column_list ||
') ' || dynamic_sql_query;
execute immediate
'select ''<html><head><title>'
|| HTTP_HEADER('@HttpURI')
|| '</title></head><body><h3>'
|| HTTP_HEADER('@HttpURI')
|| '</h3><table border=1>'
|| html_table_header
|| ''' || '
|| xml_query
|| ' || ''</table></body><br><hr><address>SQLAnywhere/'
|| @@version
|| '</address></html>'' into res from sa_foo';
return res;
end;
As an example of using this function, you could create a web service
such as:
create service root
authorization off
user dba
type 'raw'
url on
as select dynamic_sql_to_html(:url);
Using that service, you could then pass in queries directly through
the URL. For example,
http://localhost/SELECT * FROM SYSTABLE
would return a properly formatted HTML result for the query 'SELECT *
FROM SYSTABLE". Of course, there are huge security implications of
allowing any arbitrary query to be executed through the URL, I was
simply using that service it as a simple example to show of how to use
dynamic_sql_to_html() function. And, as I said earlier, since the
dynamic_sql_to_html() code is in your control, you can tweak it to
output the HTML however you like.
Will that workaround work?