/** * Instantiate an array of Counters from a Database Result * @param DatabaseResultBase $objDbResult * @param string $strExpandAsArrayNodes * @param string[] $strColumnAliasArray * @return Counter[] */ public static function InstantiateDbResult(QDatabaseResultBase $objDbResult, $strExpandAsArrayNodes = null, $strColumnAliasArray = null) { $objToReturn = array(); if (!$strColumnAliasArray) { $strColumnAliasArray = array(); } // If blank resultset, then return empty array if (!$objDbResult) { return $objToReturn; } // Load up the return array with each row if ($strExpandAsArrayNodes) { $objLastRowItem = null; while ($objDbRow = $objDbResult->GetNextRow()) { $objItem = Counter::InstantiateDbRow($objDbRow, null, $strExpandAsArrayNodes, $objLastRowItem, $strColumnAliasArray); if ($objItem) { $objToReturn[] = $objItem; $objLastRowItem = $objItem; } } } else { while ($objDbRow = $objDbResult->GetNextRow()) { $objToReturn[] = Counter::InstantiateDbRow($objDbRow, null, null, null, $strColumnAliasArray); } } return $objToReturn; }
/** * Instantiate a single Counter object from a query cursor (e.g. a DB ResultSet). * Cursor is automatically moved to the "next row" of the result set. * Will return NULL if no cursor or if the cursor has no more rows in the resultset. * @param QDatabaseResultBase $objDbResult cursor resource * @return Counter next row resulting from the query */ public static function InstantiateCursor(QDatabaseResultBase $objDbResult) { // If blank resultset, then return empty result if (!$objDbResult) { return null; } // If empty resultset, then return empty result $objDbRow = $objDbResult->GetNextRow(); if (!$objDbRow) { return null; } // We need the Column Aliases $strColumnAliasArray = $objDbResult->QueryBuilder->ColumnAliasArray; if (!$strColumnAliasArray) { $strColumnAliasArray = array(); } // Pull Expansions (if applicable) $strExpandAsArrayNodes = $objDbResult->QueryBuilder->ExpandAsArrayNodes; // Load up the return result with a row and return it return Counter::InstantiateDbRow($objDbRow, null, $strExpandAsArrayNodes, null, $strColumnAliasArray); }