Querying Data

Probably the second most common use of the ITRDS will be to query data from a table. This is done using the query method.

Say for example I wanted to query all records from the work order table which belong to account ' 2744262'. To do this I would issue the "Query" command on the "oWorkorders" object as follows (note the end parameter of 1 which specifies an XML result);

loITRDS.OWORKORDERS.query("select * where account = ' 2744262'","",1)

Notice that there is no "FROM" part in this select statement. This is because the ITRDS puts that bit in for you so you don't need to know table names. Also one VERY IMPORTANT rule is that you must not use double quotes when specifying strings such as the account number in the above example. You must always use single quotes.

To retrieve the results of this query you simply access the the cResultXML property as follows

lcQueryXML = loITRDS.OWORKORDERS.cResultXML


Alternatively we could have specified that we want the data returned in the "oRows" property by specifying a result data mode of 31 as follows

loITRDS.OWORKORDERS.query("select * where account = ' 2744262'","",31)

Then we could access the data as follows

For ln = 1 to loITRDS.OWORKORDERS.oRows.Count
loRecord = loITRDS.OWORKORDERS.getorowsitem(ln)
* Display the work order number
lcWorkOrder = loRecord.work_order
EndFor

If we are expecting a single row to be returned then you can get the ITRDS to automatically load this record into oData by including an extra parameter as shown below;

lnRecords = loITRDS.OWORKORDERS.query("select * where account = ' 2744262'","",1,,.T.)
lcWorkOrder = loITRDS.OWORKORDERS.oData.work_order



Last Updated: 10/05/2004