|
Interesting problem. It's a long shot, but perhaps you could try
prepending
'INSERT INTO TEMP' before the user's SELECT, and then doing a
'DESCRIBE'
or
equivalent on the resulting temp table to recover its column
names.
This
is only a sketch of a possible approach, and depending on the
detailed
syntax
of the SQL you're using it may not work. For example, I think
some
SQLs
may require you to name the temp table columns
explicitly.
HTH
Cheers
John
Ramsden
Hi!
I have a problem I hope somebody can help me
with!
I've written a script that takes a user defined
SQL _expression_ and makes an Excel-file of the result, the problem I have is
the column names! I've tried the following:
* using fetchrow_hashref() for each value, I now
get the column names but in "wrong" order (the hash rearanges
them).
* using fetchrow_array() for each value, I don't
get any column names at all but all the data in correct order
* using selectall_arrayref() and I get the same
result as above but with less code for me
Since I can't tell how the SQL-_expression_ will
look (and the syntax may vary as there are different databases such as MySQL
and MSSQL) I can't parse it correctly and get the fieldnames from it and I
don't want to impose any restrictions on the person writing the SQL-_expression_
to a specific syntax.
My question is, given a SQL-_expression_, is there
any way to get the column names from it in the correct order as reported from
the SQL-server? I.e. had I've been using a single table "sp_columns" had done
the trick in MSSQL and "SHOW FIELDS" in MySQL. I can run the _expression_ twice
if needed!
TIA,
Magnus
Lindgren _____________________________________________________________________ This
e-mail has been scanned for viruses by MCI's Internet Managed Scanning
Services - powered by MessageLabs. For further information visit
http://www.mci.com
|