Exemplo n.º 1
0
 public function assertQuery($queryid, $params = array(), $orderby = false)
 {
     //make sure we have been initialized
     if (!isset(self::$instance)) {
         return false;
     }
     if ($this->debugDisplayNextQuerySql) {
         $params[vB_dB_Query::DEBUG_QUERY] = 1;
     }
     // get the query object
     $query = vB_dB_Query::getQuery($queryid, $params, self::$db, self::$userinfo, self::$dbtype, self::$dbSlave);
     if (isset($params[vB_dB_Query::DEBUG_QUERY])) {
         unset($params[vB_dB_Query::DEBUG_QUERY]);
     }
     if ($this->debugDisplayNextQuerySql) {
         $this->debugDisplayNextQuerySql = false;
         $query->debugDisplayNextQuerySql();
     }
     //set the parameters. The children will raise an error if they don't have enough data.
     $check = $query->setQuery($params, $orderby);
     /**If we are in development mode, record this query **/
     if ($this->debug) {
         $this->queryCount += 1;
         /**for performance measuring- number of queries on this page **/
         if (!empty($_REQUEST['querylist'])) {
             $displayParams = $params;
             unset($displayParams[vB_dB_Query::TYPE_KEY]);
             $displayParam = var_export($displayParams, true);
             if (strlen($displayParam) > 256) {
                 $this->queries[] = $queryid . ': ' . substr($displayParam, 0, 256) . '...';
             } else {
                 $this->queries[] = $queryid . ': ' . $displayParam;
             }
         }
     }
     if ($this->debugLog) {
         $starttime = microtime(true);
         //We don't want a full trace.
         $stack = array();
         $trace = debug_backtrace(false);
         foreach ($trace as $key => $step) {
             $line = "Step {$key}: in " . $step['function'];
             foreach (array('line', 'step', 'file') as $field) {
                 if (!empty($step[$field])) {
                     $line .= ' ' . $field . ' ' . $step[$field];
                 }
             }
             $stack[] = $line;
         }
         $info = "---------------------\nQuery: " . $queryid . "\n" . var_export($params, true) . "\n" . implode("\n", $stack) . "\n";
         if (isset($params[vB_dB_Query::TYPE_KEY])) {
             vB::getLogger("dbAssertor.{$queryid}." . $params[vB_dB_Query::TYPE_KEY])->info($info);
         } else {
             vB::getLogger("dbAssertor.{$queryid}")->info($info);
         }
         $result = $query->execSQL();
         vB::getLogger("dbAssertor.{$queryid}")->info("time: " . (microtime(true) - $starttime));
         return $result;
     }
     return $query->execSQL();
 }