BQL Query to array of BObjects
February 10th, 2009
Sometimes the batch editor doesn’t cut it and I’m required to write a program to interact with a certain type of component. I could write a robot to traverse through the nav tree but I usually use a BQL query to do the work. The following is a method I often use to grab an Array of BObjects for a given BQL query.
public BObject[] getObjectsFromBql(String bqlString) { BOrd curOrd; // Grab reference to local station BStation station = (BStation) BOrd.make("station:|slot:/").get(); // Run the BQL query and get the resulting table BITable result = (BITable) BOrd.make(bqlString).get(station); ColumnList columns = result.getColumns(); TableCursor c = (TableCursor) result.cursor(); // Create the Array of BObjects to return BObject[] objs = new BObject[result.size()]; int i = 0; while (c.next()) { objs[i++] = c.get(); } return objs; }
Example to get an Array of all BStatusNumerics in ‘fault’:
getObjectsFromBql("select * from baja:StatusNumeric where status.isFault")
Is it possible not to use one column ( the slotPath ) but the columns given in the select of the query. BObject could hold all types I think.
Something like this: select name,out,parent.toPathString from baja:Value where parent.type=’baja:Component’ to get also the properties to subscribe too.
@Peter van Raamsdonk
Thanks! I’m not sure where I learned the trick of using a slotPath column to resolve a BObject but I’ve since been casting directly from the TableCursor.