Home > Niagara > BQL Query to array of BObjects

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();
 
   // Note we're assuming column 0 is "slotPath"     
   Column slotPathColumn = columns.get(0);
   TableCursor c = (TableCursor) result.cursor();
 
   // Create the Array of BObjects to return
   BObject[] objs = new BObject[result.size()];
 
   int i = 0;
   while (c.next())
   {      
      curOrd = BOrd.make(c.get(slotPathColumn).toString());
 
      // Resolve each ord to a BObject, store in our Array
      objs[i++] = (BObject)curOrd.resolve(station).get();
   }
 
   return objs;   
}

Example to get an Array of all BStatusNumerics in ‘fault’:


getObjectsFromBql("select slotPath from baja:StatusNumeric where status.isFault")

Note: You must specify ’slotPath’ as the first column in the query

  • Share/Save/Bookmark

Tucker Niagara ,

  1. No comments yet.
  1. No trackbacks yet.