示例#1
0
 /**
  * 事务查询
  * @param string $sql
  */
 protected function query($sql)
 {
     try {
         if ($this->driver->query($sql, null, true)) {
             $status = true;
         } else {
             $status = false;
         }
     } catch (\Exception $e) {
         $status = false;
     }
     return $status;
 }
示例#2
0
 /**
  * @param mixed $link
  */
 private function free($link)
 {
     $query = $this->controller->getQuery($this->driver, $link);
     if ($query) {
         try {
             $this->driver->query($link, $query->getExpression());
             $this->active->attach($link, $query);
         } catch (\Exception $err) {
             $this->active->detach($link);
             $query->reject($err);
         }
     } else {
         $this->active->detach($link);
     }
 }
示例#3
0
 /**
  * @param Driver $driver
  * @param Table $table
  * @param Query $query
  * @param bool $asArray
  */
 public function __construct(Driver $driver, Table $table, Query $query, $asArray = false)
 {
     $this->asArray = $asArray;
     $this->table = $table;
     $params = [];
     $this->tableName = $table->getName();
     if (!$this->asArray) {
         $this->recordClasses = [$this->tableName => $table->getDatabase()->getClassMapper()->getClassForRecord($this->tableName)];
     }
     $sql = $query->getRawSql();
     if ($sql === null) {
         $sql = $driver->buildSQL($table, $query, $params);
         $this->fetchStyle = \PDO::FETCH_NUM;
         foreach ($table->getColumns() as $column) {
             if ($column->isPrimaryKey()) {
                 $this->primaryKeyOrdinals[$this->tableName][$column->getOrdinal()] = true;
             }
             $this->columnOrdinalMap[$this->tableName][$column->getOrdinal()] = $column->getName();
         }
         $offset = count($table->getColumns());
         foreach ($query->getJoins() as $join) {
             if (isset($join['cardinality'])) {
                 $joinedTableName = $join['table'];
                 $joinedTable = $table->getDatabase()->getTable($joinedTableName);
                 $this->joinedTables[$joinedTableName] = $joinedTable;
                 if (!$this->asArray) {
                     $this->recordClasses[$joinedTableName] = $joinedTable->getDatabase()->getClassMapper()->getClassForRecord($joinedTableName);
                 }
                 foreach ($joinedTable->getColumns() as $column) {
                     if ($column->isPrimaryKey()) {
                         $this->primaryKeyOrdinals[$joinedTableName][$offset + $column->getOrdinal()] = true;
                     }
                     $this->columnOrdinalMap[$joinedTableName][$offset + $column->getOrdinal()] = $column->getName();
                 }
                 $this->cardinalities[$joinedTableName] = $join['cardinality'];
                 if ($join['cardinality'] === Query::CARDINALITY_ONE_TO_MANY) {
                     $this->properties[$joinedTableName] = $joinedTableName;
                 } else {
                     $this->properties[$joinedTableName] = array_keys($join['on']);
                 }
                 $offset += count($joinedTable->getColumns());
             }
         }
     } else {
         $this->fetchStyle = \PDO::FETCH_ASSOC;
         $this->rawSql = true;
     }
     $this->result = $driver->query($sql, $params);
     $this->fetchNextRow();
 }
示例#4
0
 /**
  * @param int $timeout
  * @param string $statement query statement
  * @param array $vars [optional]
  * @return Statement object
  * @throws ConnectionException
  */
 protected function cacheQuery($timeout, $statement, array $vars = null)
 {
     if ($this->cache !== null) {
         $queryId = $this->cache->getQueryId($statement, $vars);
         $st = $this->cache->read($queryId, $timeout);
         if (!$st) {
             // Cache miss
             $this->debug("Cache miss!");
             $tmpSt = $this->connection->query($statement, $vars);
             $st = Cache::createCacheableEstatement($tmpSt);
             $this->cache->write($queryId, $st, $timeout);
         }
         return $st;
     } else {
         user_error('No cache engine found!', E_USER_WARNING);
         return $this->query($statement, $vars);
     }
 }
示例#5
0
 /**
  * Tests Result->affectedRows()
  */
 public function testAffectedRows()
 {
     $res = $this->driver->query("SELECT 1, 2");
     $this->assertEquals(1, $res->affectedRows());
 }
示例#6
0
 public function query(array $parameters = [])
 {
     return $this->driver->query($this->get(), $parameters + $this->parameters);
 }