/** * Tests getting a table comment. * * @depends testCreateTable * @covers empire\framework\db\DB::getTableComment * * @param DB[] $dbs the database objects to work on */ public function testGetTableComment($dbs) { foreach ($dbs as $db) { /* @var $db DB */ $this->assertSame(self::$table->getComment(), $db->getTableComment('test')); } }
public function createTable(Table $table) { $createDefinition = array(); $fields = $table->getFields(); if (empty($fields)) { throw new SQLException('A table must have at least one field'); } foreach ($fields as $field) { $createDefinition[] = $this->buildColumnDefinition($field); } $primary = $table->getPrimaryKey(); if ($primary != null) { $createDefinition[] = $this->buildPrimaryKeyDefinition($primary); } $indices = $table->getIndices(); foreach ($indices as $index) { $createDefinition[] = $this->buildIndexDefinition($index); } $foreignKeys = $table->getForeignKeys(); foreach ($foreignKeys as $foreignKey) { $createDefinition[] = $this->buildForeignKeyDefinition($foreignKey); } $query = 'CREATE TABLE ' . $this->addPrefix($table->getName()) . "(\n"; $query .= implode(",\n", $createDefinition) . "\n)"; $query .= " ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; $comment = $table->getComment(); if (strlen($comment) > 0) { $query .= ' COMMENT=' . $this->pdoDriver->escapeString($comment); } $query .= ';'; $this->pdoDriver->executeQuery($query, null, false); }