Exemplo n.º 1
0
    /**
     * Helper method for testing methods.
     *
     * @param \Cake\Datasource\ConnectionInterface $connection
     * @return void
     */
    protected function _createTables($connection)
    {
        $this->_needsConnection();
        $connection->execute('DROP TABLE IF EXISTS schema_articles');
        $connection->execute('DROP TABLE IF EXISTS schema_authors');
        $table = <<<SQL
CREATE TABLE schema_authors (
id INT(11) PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50),
bio TEXT,
created DATETIME
)ENGINE=InnoDB
SQL;
        $connection->execute($table);
        $table = <<<SQL
CREATE TABLE schema_articles (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(20) COMMENT 'A title',
body TEXT,
author_id INT(11) NOT NULL,
published BOOLEAN DEFAULT 0,
allow_comments TINYINT(1) DEFAULT 0,
created DATETIME,
KEY `author_idx` (`author_id`),
UNIQUE KEY `length_idx` (`title`(4)),
FOREIGN KEY `author_idx` (`author_id`) REFERENCES `schema_authors`(`id`) ON UPDATE CASCADE ON DELETE RESTRICT
) ENGINE=InnoDB COLLATE=utf8_general_ci
SQL;
        $connection->execute($table);
    }
Exemplo n.º 2
0
    /**
     * Helper method for testing methods.
     *
     * @param \Cake\Datasource\ConnectionInterface $connection
     * @return void
     */
    protected function _createTables($connection)
    {
        $this->_needsConnection();
        $connection->execute('DROP TABLE IF EXISTS schema_articles');
        $connection->execute('DROP TABLE IF EXISTS schema_authors');
        $table = <<<SQL
CREATE TABLE schema_authors (
id SERIAL,
name VARCHAR(50) DEFAULT 'bob',
bio DATE,
position INT DEFAULT 1,
created TIMESTAMP,
PRIMARY KEY (id),
CONSTRAINT "unique_position" UNIQUE ("position")
)
SQL;
        $connection->execute($table);
        $table = <<<SQL
CREATE TABLE schema_articles (
id BIGINT PRIMARY KEY,
title VARCHAR(20),
body TEXT,
author_id INTEGER NOT NULL,
published BOOLEAN DEFAULT false,
views SMALLINT DEFAULT 0,
readingtime TIME,
created TIMESTAMP,
CONSTRAINT "content_idx" UNIQUE ("title", "body"),
CONSTRAINT "author_idx" FOREIGN KEY ("author_id") REFERENCES "schema_authors" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
)
SQL;
        $connection->execute($table);
        $connection->execute('COMMENT ON COLUMN "schema_articles"."title" IS \'a title\'');
        $connection->execute('CREATE INDEX "author_idx" ON "schema_articles" ("author_id")');
    }
 /**
  * Helper method for running each step of the reflection process.
  *
  * @param \CakeDC\OracleDriver\Database\Schema\Method $method Object with method metadata.
  * @param string $name The table name.
  * @param array $config The config data.
  * @return void
  * @throws \Cake\Database\Exception on query failure.
  */
 protected function _reflect($method, $name, $config)
 {
     list($sql, $params) = $this->_dialect->describeParametersSql($name, $config);
     if (empty($sql)) {
         return;
     }
     try {
         $statement = $this->_connection->execute($sql, $params);
     } catch (PDOException $e) {
         throw new Exception($e->getMessage(), 500, $e);
     }
     foreach ($statement->fetchAll('assoc') as $row) {
         $this->_dialect->convertParametersDescription($method, $row);
     }
     $statement->closeCursor();
 }
Exemplo n.º 4
0
 /**
  * Helper method for running each step of the reflection process.
  *
  * @param string $stage The stage name.
  * @param string $name The table name.
  * @param array $config The config data.
  * @param \Cake\Database\Schema\Table $table The table instance
  * @return void
  * @throws \Cake\Database\Exception on query failure.
  */
 protected function _reflect($stage, $name, $config, $table)
 {
     $describeMethod = "describe{$stage}Sql";
     $convertMethod = "convert{$stage}Description";
     list($sql, $params) = $this->_dialect->{$describeMethod}($name, $config);
     if (empty($sql)) {
         return;
     }
     try {
         $statement = $this->_connection->execute($sql, $params);
     } catch (PDOException $e) {
         throw new Exception($e->getMessage(), 500, $e);
     }
     foreach ($statement->fetchAll('assoc') as $row) {
         $this->_dialect->{$convertMethod}($table, $row);
     }
     $statement->closeCursor();
 }
 /**
  * Get the table hash from MySQL for a specific table
  *
  * @param ConnectionInterface $db
  * @return string
  */
 protected function _hash(ConnectionInterface $db)
 {
     $sth = $db->execute("CHECKSUM TABLE " . $this->table);
     $result = $sth->fetch('assoc');
     $checksum = $result['Checksum'];
     return $checksum;
 }