Friday, September 25, 2009

Multiple Recordsets

It can be very useful to put multiple queries into one web-service request. You get multiple query responses, and only suffer the request overhead for one request.

Rdbhost now supports returning multiple record sets for one request.

If you have multiple Postgresql statements in your request 'q' param, delimited by ';', each is processed in sequence, and the results for each are added to the list of record sets. Instead of one group in the results called 'records', you have an outer group called 'result_sets', and a group within that for each statement. The details differ between the json, json-easy, xml, and xml-easy formats, but the above description applies to each.

json format for multiple result-sets looks like:


{
"status": [
"complete",
"OK"
],
"result_sets": [
{
"status": [
"complete",
"OK"
],
"records": {
"header": {
"id": 23
},
"rows": [
{
"id": 1
}
]
},
"row_count": [
1,
"1 Rows Affected"
]
},
{
...
}
]
}

for comparison, the single recordset variant looks like:


{
"status": [
"complete",
"OK"
],
"records": {
"header": {
"id": 23
},
"rows": [
{
"id": 1
}
]
},
"row_count": [
1,
"1 Rows Affected"
]
}

The single result-set variant puts the count, status, and records all in the root.

The multiple result-set variant puts creates a result-set group, containing count, status, and records, for each statement in the request. There is also one status element in the root, and if the status is 'error', there will be no result sets.

The xml formats have similar layout:


<xml xmlns="http://www.rdbhost.com/xml.html">
<status value="complete">OK</status>
<result_sets>
<result_set>
<row_count value="1">1 Rows Affected</row_count>
<status value="complete"/>
<records>
<header>
<fld type="23">id</fld>
</header>
<rec>
<fld>1</fld>
</rec>
</records>
</result_set>
<result_set>
...
</result_set>
</result_sets>
</xml>


The xml formats have a 'result_sets' container element, and multiple 'result_set' container elements within that.

The service is free; you can learn more about it by registering for an account, reading the online documentation, and experimenting.

http://www.rdbhost.com

No comments:

Post a Comment