. query_sql_str.pro
This program interfaces witht the GAVO millennium / SDSS servers to perform SQL queries and parse the results into IDL structs.
To use, put your query in a string:IDL> query = 'select * from agebin'
then run the search:
IDL> result = query_sql_str(query)
(a little widget will pop up and ask for your username and login. At the moment there are no stars for password, but I'm working on it!)
IDL> print, transpose(result)
result is a csv formated array of strings, one per line of result, with two comments at the top and a list of other things. Later versions will be able to return a structure, but not just yet! You'll need to login for the first query of each session, but shouldn't after that. If you have the wrong login details and need to replace them, simply type /login as a keyword when you call query_sql:
IDL> result = query_sql_str(query, /login)
If you're using a different database, you may need to supply the URL of a seperate server. Something like:
IDL> result = query_sql_str(query, server='http://gavo.mpa-garching.mpg.de/MyMillennium')
Note that there is no final slash on the URL!
The code automatically chooses the tag names of the structure to reflect the field names returned by the query. If there are duplicates, it appends the number of the field to the end of the tag name. If this is not the format you require, or if the variable formatting is incorrect, you can supply a base struct to be replicated using the my_struct=.... keyword The mystruct structure must have the same number of tags as the query returns.
If you find that your query is not as long as you expected it is possible the server timed out before completion. In this case supply a variable for the truncated keyword. This will allow you to inspect the last completed line of the query and resubmit with that as a condition when combined with a sort command
query_sql_str |
function query_sql_str(query, my_struct=my_struct, quiet=quiet, truncated=truncated, _extra=_extra) |
Modifications and improvements suggested by Viv Wild, Manfred Kitzbichler, Eric Hayashi and Jeremy Blaizot. All SQL servers maintained by Gerard Lemson
Parameters | |
query |
sql query in the form of a string. The string may be multiline, the program will compress the string to a single line though |