public function getDeviceFallBackTree($wurflID)
 {
     if ($this->use_nested_set) {
         return $this->getDeviceFallBackTree_NS($wurflID);
     }
     $data = array();
     $this->numQueries++;
     $query = sprintf("CALL " . TeraWurflConfig::$TABLE_PREFIX . "_FallBackDevices(%s)", $this->SQLPrep($wurflID));
     $this->dbcon->multi_query($query);
     $i = 0;
     do {
         if ($res = $this->dbcon->store_result()) {
             $row = $res->fetch_row();
             $data[$i++] = unserialize($row[0]);
             $res->free();
         }
     } while ($this->dbcon->more_results() && $this->dbcon->next_result());
     if ($i == 0) {
         $tw = new TeraWurfl();
         $tw->toLog("Tera-WURFL Error: database fallback procedure returned no records, verify that " . TeraWurflConfig::$TABLE_PREFIX . "_FallBackDevices exists.", LOG_ERR, __CLASS__ . '::' . __FUNCTION__);
     } else {
         if ($data[$i - 1]['id'] != WurflConstants::NO_MATCH) {
             $tw = new TeraWurfl();
             $tw->toLog("WURFL Error: device {$data[$i - 1]['id']} falls back on an inexistent device: {$data[$i - 1]['fall_back']}", LOG_ERR, __CLASS__ . '::' . __FUNCTION__);
         }
     }
     return $data;
 }
Exemple #2
0
 public function multiQuery($sSQL)
 {
     $start = microtime(true);
     $this->connect();
     // Increase the counter
     $this->query_counter++;
     $result = $this->connection->multi_query(trim($sSQL));
     // FLUSH RESULTS
     // @TODO make these usable
     do {
         $r = $this->connection->store_result();
         if ($r) {
             $r->free();
         }
         if (!$this->connection->more_results()) {
             break;
         }
         //$this->connection->next_result();
     } while ($this->connection->next_result());
     $duration = microtime(true) - $start;
     $this->addQueryLog($sSQL, $duration);
     if (!$result) {
         //var_dump (debug_backtrace ());
         //$data = debug_backtrace ();
         //print_r ($data);
         //echo $sSQL;
         $ex = new DbException('MySQL Error: ' . $this->connection->error);
         $ex->setQuery($sSQL);
         throw $ex;
     } elseif ($result instanceof MySQLi_Result) {
         return new Result($result);
     }
     // Insert ID will return zero if this query was not insert or update.
     $this->insert_id = intval($this->connection->insert_id);
     // Affected rows
     $this->affected_rows = intval($this->connection->affected_rows);
     if ($this->insert_id > 0) {
         return $this->insert_id;
     }
     if ($this->affected_rows > 0) {
         return $this->affected_rows;
     }
     return $result;
 }
Exemple #3
0
 protected function _multiQuery($query)
 {
     $this->connect();
     $this->_driver->multi_query($query);
     if ($this->_driver->error) {
         throw new Miaox_SphinxQl_Connection_Exception('[' . $this->_driver->errno . '] ' . $this->_driver->error . ' [ ' . $query . ']');
     }
     $result = array();
     $count = 0;
     do {
         if (false !== ($resource = $this->_driver->store_result())) {
             $result[$count] = array();
             while (!is_null($row = $resource->fetch_assoc())) {
                 $result[$count][] = $row;
             }
             $resource->free_result();
         }
         $count++;
     } while ($this->_driver->more_results() && $this->_driver->next_result());
     return $result;
 }
 public static function mysqli_multi_query($query, $resultmode = MYSQL_STORE_RESULT)
 {
     $instance = Instrumentation::get_instance();
     $retry_count = 0;
     while ($retry_count < MySQLi_perf::$deadlock_try_limit) {
         $query = $this->instrument_query($query, $retry_count);
         $instance->increment('mysql_query_count', 1);
         $retry_count = 0;
         $sql = Instrumentation::get_instance()->timer();
         $r = parent::multi_query($query, $resultmode);
         $time = $instance->timer();
         $instance->increment('mysql_query_exec_time', $time);
         $instance->push_query_log($query, $time);
         //1213 (ER_LOCK_DEADLOCK)
         if ($this->errno() == 1213) {
             //Deadlock detected retry operation
             $instance->increment('mysql_deadlock_count', 1);
             ++$retry_count;
             continue;
             // loop to the start of the while loop
         }
         break;
     }
     return $result;
 }
Exemple #5
0
 /**
  * Runs a query and returns a result object
  *  
  * @param string $query
  * @return Application_Model_Queryresult
  */
 public function query($query)
 {
     // If there is no query we can't really do anything
     if (!$query) {
         $this->error = 'No query was requested.';
         return false;
     }
     // If there is no connection handle, get one
     if (!$this->_dbh) {
         $this->_getDbh();
     }
     $return = false;
     // Check again to make sure we are good
     if ($this->_dbh) {
         // Start stacking
         Application_Model_Queryprofiler::setQuery($query);
         // Start the timer
         $start = microtime(true);
         // Handle processing of the result data setting
         //$rs = $this->_dbh->query($query);
         $result = new Application_Model_Queryresult();
         if ($this->_dbh->multi_query($query)) {
             do {
                 if (($rs = $this->_dbh->use_result()) !== false) {
                     $result->setResult($rs);
                     $rs->free();
                 } else {
                     if ($this->_dbh->errno) {
                         // there was an error
                         $this->error .= ' ' . $this->_dbh->error;
                     }
                 }
             } while ($this->_dbh->more_results() && $this->_dbh->next_result());
         } else {
             if (($rs = $this->_dbh->query($query)) !== false) {
                 $result->setResult($rs);
                 $rs->free();
             } else {
                 if ($this->_dbh->errno) {
                     $this->error = $this->_dbh->error;
                 }
             }
         }
         // Stop the time
         $stop = microtime(true);
         // Handle errors
         //if ($this->_dbh->error) {
         //	$this->error = $this->_dbh->error;
         //}
         // Handle timer
         $totaltime = $stop - $start;
         Application_Model_Queryprofiler::setQueryTime($totaltime);
         Application_Model_Queryprofiler::setQueryError($this->error);
         // Set the result sets, record sets and statistics
         $result->setResultStats();
         //$return = $rs;
         $return = $result;
     } else {
         $this->error = 'There is no database connector.';
     }
     return $return;
 }