Exemplo n.º 1
0
 /**
  * Create a new table
  *
  * @param string $name
  * @return void
  */
 public static function createTable($name)
 {
     $table = new CreateTable($name);
     // Primary column
     $primaryColumn = new Integer('id');
     $primaryColumn->setOption('autoincrement', '');
     $table->addColumn($primaryColumn);
     $table->addConstraint(new PrimaryKey('id'));
     // Status column
     $statusColumn = new Boolean(STATUS_COLUMN_NAME, false, STATUS_DRAFT_NUM);
     $table->addColumn($statusColumn);
     $connection = Bootstrap::get('ZendDb');
     $sql = new Sql($connection);
     $connection->query($sql->getSqlStringForSqlObject($table), $connection::QUERY_MODE_EXECUTE);
 }
Exemplo n.º 2
0
 private function createTableLanguages()
 {
     $table = new Ddl\CreateTable('languages');
     $id = new Column\Integer('id');
     $id->setOption('autoincrement', true);
     $table->addColumn($id);
     $table->addColumn(new Column\Varchar('code', 2));
     $table->addColumn(new Column\Varchar('locale', 6));
     $table->addColumn(new Column\Varchar('name', 50));
     $table->addColumn(new Column\Integer('default', false, 0));
     $table->addConstraint(new Constraint\PrimaryKey('id'));
     $table->addConstraint(new Constraint\UniqueKey('code'));
     $table->addConstraint(new Constraint\UniqueKey('locale'));
     $sql = new Sql($this->dbAdapter);
     $this->dbAdapter->query($sql->buildSqlString($table), Adapter::QUERY_MODE_EXECUTE);
 }
Exemplo n.º 3
0
 private function createTablePages()
 {
     $table = new Ddl\CreateTable('pages');
     $id = new Column\Integer('id');
     $id->setOption('AUTO_INCREMENT', 1);
     $table->addColumn($id);
     $table->addColumn(new Column\Varchar('title', 255));
     $table->addColumn(new Column\Text('body'));
     $table->addColumn(new Column\Datetime('dt_created'));
     $table->addColumn(new Column\Datetime('dt_updated', true));
     $table->addConstraint(new Constraint\PrimaryKey('id'));
     $sql = new Sql($this->dbAdapter);
     try {
         $this->dbAdapter->query($sql->buildSqlString($table), Adapter::QUERY_MODE_EXECUTE);
     } catch (PDOException $e) {
         return $e->getMessage() . PHP_EOL;
     }
 }
Exemplo n.º 4
0
 /**
  * @covers Zend\Db\Sql\Ddl\Column\Column::getExpressionData
  */
 public function testGetExpressionData()
 {
     $column = new Integer('foo');
     $this->assertEquals(array(array('%s %s', array('foo', 'INTEGER NOT NULL'), array($column::TYPE_IDENTIFIER, $column::TYPE_LITERAL))), $column->getExpressionData());
 }
 /**
  * @param integer|null $length
  * @return Column\Integer
  */
 public function integer($length = null)
 {
     $column = new Column\Integer(null);
     if (null !== $length && intval($length)) {
         $column->setOption('length', (int) $length);
     }
     return $column;
 }