Пример #1
0
 public function disableWriteConnection(Connection $connection)
 {
     if ($this->currentWriteConnection === $connection) {
         if ($this->currentReadConnection === $connection) {
             $this->currentReadConnection = null;
         }
         $this->currentWriteConnection->close();
         $this->currentWriteConnection = null;
     }
     foreach ($this->writeConnections as $index => $writeConnection) {
         if ($writeConnection === $connection) {
             unset($this->writeConnections[$index]);
         }
     }
     $this->writeConnections = array_values($this->writeConnections);
 }
Пример #2
0
 public function rollback()
 {
     if ($this->transactionCount == 0) {
         return false;
     }
     $result = $this->transactionConnection->rollback();
     $this->popTransaction();
     return $result;
 }
    /**
     * Returns all indexes of the given table.
     *
     * @param Table  $table
     * @param Schema $schema
     *
     * @return mixed[]
     */
    private function buildIndexes(Table $table, Schema $schema = null)
    {
        $schemaFilter = 'DATABASE()';
        if ($schema !== null) {
            $schemaFilter = '\'' . $schema->getName() . '\'';
        }
        $statement = '
          SELECT
            s.INDEX_NAME,
            s.COLUMN_NAME,
            tc.CONSTRAINT_TYPE
		  FROM information_schema.statistics s
		  LEFT OUTER JOIN
		    information_schema.TABLE_CONSTRAINTS tc
		    ON tc.CONSTRAINT_NAME = s.INDEX_NAME AND tc.TABLE_SCHEMA = s.TABLE_SCHEMA AND tc.TABLE_NAME = s.TABLE_NAME
		  WHERE
			  s.TABLE_SCHEMA = ' . $schemaFilter . ' AND
			  s.TABLE_NAME = \'' . $table->getName() . '\'
          ORDER BY s.INDEX_NAME, s.SEQ_IN_INDEX
        ';
        $rows = $this->connection->execute($statement);
        $indexes = [];
        foreach ($rows->all() as $row) {
            $name = $row['INDEX_NAME'];
            if (!isset($indexes[$name])) {
                if ($row['CONSTRAINT_TYPE'] == 'PRIMARY KEY') {
                    $type = 'PRIMARY';
                } elseif ($row['CONSTRAINT_TYPE'] == 'UNIQUE') {
                    $type = 'UNIQUE';
                } else {
                    $type = 'INDEX';
                }
                $indexes[$name] = ['type' => $type, 'columns' => []];
            }
            $indexes[$name]['columns'][] = $row['COLUMN_NAME'];
        }
        return $indexes;
    }