.
query_sql_str.pro

Last modification date:
Wed Jun 20 11:07:52 2007

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)

Returns
A structure with fields equivalent to the titles of the columns returned by the query. Also gives a brief report to the shell about what has gone on.
Examples
result = query_sql_str('select * from agebin')

Requires
An account on the MPA/GAVO webaccess to SQL servers.
Version
$Id: query_sql_str.html,v 1.1 2009-03-24 17:10:48 glemson Exp $
History
Originally created Jan 2006 by Ben Panter.

Modifications and improvements suggested by Viv Wild, Manfred Kitzbichler, Eric Hayashi and Jeremy Blaizot. All SQL servers maintained by Gerard Lemson

Author
Ben Panter

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

Keywords
my_struct
- supply you own struct to avoid problems with incorrect format guessing or provide your own field names
quiet
- suppresses any messages to the shell, both by IDL and wget.
truncated
- this allows you to read the last complete line if a query was truncated due to a time out. You may then resumbit the query using that information if your original query included a sort statement.
_extra
allows keywords to be passed to subroutines:

server - Change the server from the default value to something else (this can be changed permanently in sql_query.pro if desired)

login - Force a new attempt at logging in.

no_cookies - Do not use cookies to maintain a session on the server. For compatability with early wget versions


Produced by IDLdoc 1.6 on Wed Jun 20 11:10:40 2007