protected function initConnection($lockDb, IDatabase $db) { # Let this transaction see lock rows from other transactions $db->query("SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;"); # Do everything in a transaction as it all gets rolled back eventually $db->startAtomic(__CLASS__); }
protected function getWeightScale($index, IDatabase $conn = null) { if (!$conn) { return 0.0; } $weight = 1.0; if ($this->warmCacheRatio > 0) { $res = $conn->query('SHOW STATUS', false); $s = $res ? $conn->fetchObject($res) : false; if ($s === false) { $host = $this->parent->getServerName($index); $this->replLogger->error(__METHOD__ . ": could not get status for {$host}"); } else { // http://dev.mysql.com/doc/refman/5.7/en/server-status-variables.html if ($s->Innodb_buffer_pool_pages_total > 0) { $ratio = $s->Innodb_buffer_pool_pages_data / $s->Innodb_buffer_pool_pages_total; } elseif ($s->Qcache_total_blocks > 0) { $ratio = 1.0 - $s->Qcache_free_blocks / $s->Qcache_total_blocks; } else { $ratio = 1.0; } // Stop caring once $ratio >= $this->warmCacheRatio $weight *= min($ratio / $this->warmCacheRatio, 1.0); } } return $weight; }
/** * 执行一条SQL语句 * @param $sql * @return \Swoole\Database\MySQLiRecord */ public function query($sql) { if ($this->debug) { echo "{$sql}<br />\n<hr />"; } $this->read_times += 1; return $this->_db->query($sql); }
/** * 获取表的字段描述 * @return array */ function desc() { return $this->db->query('describe ' . $this->table)->fetchall(); }
/** * @param string $lockDb * @param IDatabase $db */ protected function initConnection($lockDb, IDatabase $db) { # Let this transaction see lock rows from other transactions $db->query("SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;"); }
private function badLockingMethodImplicit(IDatabase $db) { $lock = $db->getScopedLockAndFlush('meow', __METHOD__, 1); $db->query("SELECT 1"); // trigger DBO_TRX throw new RunTimeException("Uh oh!"); }
protected function sqlDoQuery(IDatabase $db, $line, $dieOnError) { try { $res = $db->query($line); $this->sqlPrintResult($res, $db); } catch (DBQueryError $e) { $this->error($e, $dieOnError); } }