Skip to content

Commit

Permalink
Fix for Issue #53, adding ExpandAsArray support to QuerySingle in cod…
Browse files Browse the repository at this point in the history
…egen templates
  • Loading branch information
mikeho committed Aug 11, 2010
1 parent 627304b commit e763efe
Showing 1 changed file with 24 additions and 2 deletions.
Expand Up @@ -82,9 +82,31 @@
throw $objExc;
}

// Perform the Query, Get the First Row, and Instantiate a new <%= $objTable->ClassName %> object
// Perform the Query
$objDbResult = $objQueryBuilder->Database->Query($strQuery);
return <%= $objTable->ClassName %>::InstantiateDbRow($objDbResult->GetNextRow(), null, null, null, $objQueryBuilder->ColumnAliasArray);

// Instantiate a new <%= $objTable->ClassName %> object and return it

// Do we have to expand anything?
if ($objQueryBuilder->ExpandAsArrayNodes) {
$objToReturn = array();
while ($objDbRow = $objDbResult->GetNextRow()) {
$objItem = <%= $objTable->ClassName %>::InstantiateDbRow($objDbRow, null, $objQueryBuilder->ExpandAsArrayNodes, $objToReturn, $objQueryBuilder->ColumnAliasArray);
if ($objItem) $objToReturn[] = $objItem;
}

if (count($objToReturn)) {
// Since we only want the object to return, lets return the object and not the array.
return $objToReturn[0];
} else {
return null;
}
} else {
// No expands just return the first row
$objDbRow = $objDbResult->GetNextRow();
if (is_null($objDbRow)) return null;
return <%= $objTable->ClassName %>::InstantiateDbRow($objDbRow, null, null, null, $objQueryBuilder->ColumnAliasArray);
}
}

/**
Expand Down

0 comments on commit e763efe

Please sign in to comment.