©2008-2017 David V Keeney All rights reserved.
RdbHost provides databases as a webservice. Accessing your RdbHost database can be accomplished via Python http calls, through the standard library.
The recommended way to access RdbHost databases from Python is via the DB API module, but this page documents lower-level methods available where the DB API will not serve.
The urllib and urllib2 modules provide the tools to retrieve xml pages from remote servers.
Here is a simple example that uses the server as a simple calculator, adding 1 and 1. This will work with any valid role on any database, as no specific privileges are required on any resource within the database.
The above example is a complete working script that executes the addition query on the server and prints the result page.
The customization per-query is in lines 11 and 12. Other query parameters can be added to the flds list in line 12. Now let's look at the returned page:
Line 2 contains the status. That value will be 'complete', 'incomplete', or 'error'.
The next tag (line 3) is the rowcount tag, showing how many affected rows the server reported.
Since this query returned one result, there is a 'records' container tag, containing a header and a row. In line 6, the only field is described as type "23", which is PostgreSQL's identifier for array-of-int, and named 'sum', per the query.
If there was an error, the text of the status tag would contain the name of any error, and the next tag would be an error tag, with error code and error message.
The error code (see line 3) for RdbHost's own errors is always '-'. Other error codes and error messages are pass-throughs from the relevant subsystem, such as PostgreSQL or the XML library.
The example above will not function as is, because the example password is invalid. It will work for you, though, if you create a free account and substitute the correct role and password.
Line 12d provides one argument. The query, 'q', in line 12 has an interpolation token '%s'. arg000, 1, will be safely interpolated into the query before execution of a query.
Here is a JSON-style error page.