Exemplo n.º 1
0
 /**
  * Pre-processes a query specification and returns a string representation
  * of the query.
  * This method will call parent::preprocessQuery(). Additionally it will
  * verify $query['limit'] and $query['offset'].
  *
  * @param mixed  &$query     A string or an array containing the element 'query'.
  * @param string $configPath The config path; used for exception messages.
  *
  * @return string The query statement as a string.
  * @throws XML_Query2XML_ConfigException If $query['limit'] or $query['offset']
  *                                       is set but not numeric. This exception
  *                                       might also bubble up from
  *                                       parent::preprocessQuery().
  */
 public function preprocessQuery(&$query, $configPath)
 {
     // will make $query an array if it is not already
     $queryString = parent::preprocessQuery($query, $configPath);
     foreach (array('limit', 'offset') as $sqlOption) {
         if (isset($query[$sqlOption])) {
             if (!is_numeric($query[$sqlOption])) {
                 /*
                  * unit test: getXML/
                  *  offsetlimit_throwConfigException_limit_not_numeric.phpt
                  *  offsetlimit_throwConfigException_offset_not_numeric.phpt
                  */
                 throw new XML_Query2XML_ConfigException($configPath . '[' . $sqlOption . ']: integer expected, ' . gettype($query[$sqlOption]) . ' given.');
             }
         }
     }
     if (isset($query['limit'])) {
         if ($query['limit'] == 0) {
             // setting limit to 0 is like not setting it at all
             unset($query['limit']);
         } else {
             if (!isset($query['offset'])) {
                 // offset defaults to 0
                 $query['offset'] = 0;
             }
             $queryString .= '; LIMIT:' . $query['limit'];
             $queryString .= '; OFFSET:' . $query['offset'];
         }
     }
     return $queryString;
 }