getQueryComment() public static method

getQueryComment 取得要在 db 下 query 時所加上的註解
public static getQueryComment ( ) : null | string
return null | string
Esempio n. 1
0
 /**
  * query 對 db 下 SQL query
  * 
  * @param mixed $sql 
  * @access protected
  * @return Mysqli result
  */
 public function query($sql, $table = null)
 {
     if (Pix_Table::$_log_groups[Pix_Table::LOG_QUERY]) {
         Pix_Table::debug(sprintf("[%s]\t%40s", $this->_link->host_info, $sql));
     }
     // TODO 需要 log SQL Query 功能
     if ($comment = Pix_Table::getQueryComment()) {
         $sql = trim($sql, '; ') . ' #' . $comment;
     }
     $starttime = microtime(true);
     $res = $this->_link->query($sql);
     if ($t = Pix_Table::getLongQueryTime() and ($delta = microtime(true) - $starttime) > $t) {
         Pix_Table::debug(sprintf("[%s]\t%s\t%40s", $this->_link->host_info, $delta, $sql));
     }
     if ($res === false) {
         if ($errno = $this->_link->errno) {
             switch ($errno) {
                 case 1062:
                     throw new Pix_Table_DuplicateException($this->_link->error, $errno);
                 case 1406:
                     throw new Pix_Table_DataTooLongException($this->_link->error, $errno);
                 default:
                     throw new Exception("SQL Error: {$this->_link->error} SQL: {$sql}");
             }
         }
     }
     return $res;
 }
Esempio n. 2
0
 /**
  * query 
  * 
  * @param string $sql 
  * @access protected
  * @return mssql result
  */
 public function query($sql, $table = null)
 {
     if (Pix_Table::$_log_groups[Pix_Table::LOG_QUERY]) {
         Pix_Table::debug(sprintf("[%s]\t%40s", strval($this->_link), $sql));
     }
     // TODO: log sql query
     if ($comment = Pix_Table::getQueryComment()) {
         $sql = trim($sql, '; ') . ' #' . $comment;
     }
     $starttime = microtime(true);
     $res = mssql_query($sql, $this->_link);
     if ($t = Pix_Table::getLongQueryTime() and ($delta = microtime(true) - $starttime) > $t) {
         Pix_Table::debug(sprintf("[%s]\t%s\t%40s", strval($this->_link), $delta, $sql));
     }
     if ($res === false) {
         throw new Exception("SQL Error: {$this->_link} SQL: {$sql}");
     }
     return new Pix_Table_Db_Adapter_MsSQL_Result($res);
 }
Esempio n. 3
0
 public function query($sql, $table = null)
 {
     // 判斷要用 Master 還是 Slave
     $type = 'master';
     if (!Pix_Table::$_force_master and preg_match('#^SELECT #', strtoupper($sql))) {
         $type = 'slave';
     }
     if (Pix_Setting::get('Table:ExplainFileSortEnable')) {
         if (preg_match('#^SELECT #', strtoupper($sql))) {
             $res = $this->_getLink($type)->query("EXPLAIN {$sql}");
             $row = $res->fetch_assoc();
             if (preg_match('#Using filesort#', $row['Extra'])) {
                 trigger_error("Using Filesort Query {$sql}", E_USER_WARNING);
             }
             $res->free_result();
         }
     }
     if (Pix_Setting::get('Table:SQLNoCache')) {
         if (preg_match('#^SELECT #', strtoupper($sql))) {
             $sql = 'SELECT SQL_NO_CACHE ' . substr($sql, 7);
         }
     }
     // 加上 Query Comment
     if ($comment = Pix_Table::getQueryComment()) {
         $sql = trim($sql, '; ') . ' #' . $comment;
     }
     for ($i = 0; $i < 3; $i++) {
         if (!($link = $this->_getLink($type))) {
             throw new Exception('找不到 Link');
         }
         $starttime = microtime(true);
         $res = $link->query($sql);
         $this->insert_id = $link->insert_id;
         $delta = microtime(true) - $starttime;
         if (array_key_exists(Pix_Table::LOG_QUERY, Pix_Table::$_log_groups) and Pix_Table::$_log_groups[Pix_Table::LOG_QUERY]) {
             Pix_Table::debug(sprintf("[%s-%s](%f)%s", strval($link->host_info), $type, $delta, $sql));
         } elseif ($t = Pix_Table::getLongQueryTime() and $delta > $t) {
             Pix_Table::debug(sprintf("[%s-%s](%f)%s", strval($link->host_info), $type, $delta, $sql));
         }
         if ($res === false) {
             if ($errno = $link->errno) {
                 $message = (is_null($table) ? '' : "Table: {$table->getClass()}") . "SQL Error: ({$errno}){$link->error} " . substr($sql, 0, 128);
                 switch ($errno) {
                     case 1146:
                         throw new Pix_Table_TableNotFoundException($message);
                     case 1062:
                         throw new Pix_Table_DuplicateException((is_null($table) ? '' : "(Table: {$table->getClass()})") . $link->error, $errno);
                     case 1406:
                         throw new Pix_Table_DataTooLongException($message);
                     case 2006:
                         // MySQL server gone away
                     // MySQL server gone away
                     case 2013:
                         // Lost connection to MySQL server during query
                         trigger_error("Pix_Table " . $message, E_USER_WARNING);
                         $this->resetConnect();
                         continue 2;
                 }
             }
             throw new Pix_Table_Exception($message);
         }
         if ($link->warning_count) {
             $e = $link->get_warnings();
             do {
                 if (1592 == $e->errno) {
                     continue;
                 }
                 if (Pix_Table::$_throw_incorrect_string_exception and 1366 == $e->errno) {
                     throw new Pix_Table_IncorrectStringException($e->message);
                 }
                 trigger_error("Pix_Table " . (is_null($table) ? '' : "Table: {$table->getClass()}") . "SQL Warning: ({$e->errno}){$e->message} " . substr($sql, 0, 128), E_USER_WARNING);
             } while ($e->next());
         }
         return $res;
     }
     throw new Pix_Table_Exception("query 三次失敗");
 }
 /**
  * 測試 QueryComment 能不能正常被寫入
  */
 public function testSetQueryComment()
 {
     Pix_Table::setQueryComment('test');
     $this->assertEquals(Pix_Table::getQueryComment(), 'test');
     Pix_Table::setQueryComment();
     $this->assertEquals(Pix_Table::getQueryComment(), null);
 }