Example #1
0
 /**
  * Internally called method to assist with calling Qcubed Query for this class
  * on load methods.
  * @param QQueryBuilder &$objQueryBuilder the QueryBuilder object that will be created
  * @param QQCondition $objConditions any conditions on the query, itself
  * @param QQClause[] $objOptionalClausees additional optional QQClause object or array of QQClause objects for this query
  * @param mixed[] $mixParameterArray a array of name-value pairs to perform PrepareStatement with (sending in null will skip the PrepareStatement step)
  * @param boolean $blnCountOnly only select a rowcount
  * @return string the query statement
  */
 protected static function BuildQueryStatement(&$objQueryBuilder, QQCondition $objConditions, $objOptionalClauses, $mixParameterArray, $blnCountOnly)
 {
     // Get the Database Object for this Class
     $objDatabase = User::GetDatabase();
     // Create/Build out the QueryBuilder object with User-specific SELET and FROM fields
     $objQueryBuilder = new QQueryBuilder($objDatabase, 'user');
     User::GetSelectFields($objQueryBuilder);
     $objQueryBuilder->AddFromItem('user');
     // Set "CountOnly" option (if applicable)
     if ($blnCountOnly) {
         $objQueryBuilder->SetCountOnlyFlag();
     }
     // Apply Any Conditions
     if ($objConditions) {
         try {
             $objConditions->UpdateQueryBuilder($objQueryBuilder);
         } catch (QCallerException $objExc) {
             $objExc->IncrementOffset();
             throw $objExc;
         }
     }
     // Iterate through all the Optional Clauses (if any) and perform accordingly
     if ($objOptionalClauses) {
         if ($objOptionalClauses instanceof QQClause) {
             $objOptionalClauses->UpdateQueryBuilder($objQueryBuilder);
         } else {
             if (is_array($objOptionalClauses)) {
                 foreach ($objOptionalClauses as $objClause) {
                     $objClause->UpdateQueryBuilder($objQueryBuilder);
                 }
             } else {
                 throw new QCallerException('Optional Clauses must be a QQClause object or an array of QQClause objects');
             }
         }
     }
     // Get the SQL Statement
     $strQuery = $objQueryBuilder->GetStatement();
     // Prepare the Statement with the Query Parameters (if applicable)
     if ($mixParameterArray) {
         if (is_array($mixParameterArray)) {
             if (count($mixParameterArray)) {
                 $strQuery = $objDatabase->PrepareStatement($strQuery, $mixParameterArray);
             }
             // Ensure that there are no other Unresolved Named Parameters
             if (strpos($strQuery, chr(QQNamedValue::DelimiterCode) . '{') !== false) {
                 throw new QCallerException('Unresolved named parameters in the query');
             }
         } else {
             throw new QCallerException('Parameter Array must be an array of name-value parameter pairs');
         }
     }
     // Return the Objects
     return $strQuery;
 }