示例#1
0
 /**
  * {@inheritdoc}
  */
 public function createTable(SchemaBuilder $schema)
 {
     $sql = 'CREATE TABLE "' . $this->db->tableName($schema->getName()) . '" (';
     $columns = $schema->getFields();
     $first = true;
     $primaryKey = $schema->getPrimaryKey();
     $singlePrimary = count($primaryKey) == 1;
     foreach ($columns as $column) {
         $type = $schema->{$column};
         if (!$first) {
             $sql .= ', ';
         } else {
             $first = false;
         }
         $sql .= $column;
         $sql .= ' ' . $this->fromDataType($type, $singlePrimary and $primaryKey[0] == $column);
     }
     if (!$singlePrimary) {
         $sql .= ', PRIMARY KEY (' . implode(', ', $schema->getPrimaryKey()) . ')';
     }
     $sql .= ')';
     $this->db->rawQuery($sql);
     foreach ($schema->getIndexes() as $index => $options) {
         if ($index == 'PRIMARY') {
             continue;
         }
         $sql = 'CREATE';
         if ($options['unique']) {
             $sql .= ' UNIQUE';
         }
         $sql .= ' INDEX "';
         $sql .= $this->db->tableName($schema->getName()) . '_' . $index;
         $sql .= '" ON "' . $this->db->tableName($schema->getName());
         $sql .= '" (';
         $sql .= implode(', ', $options['columns']) . ')';
         $this->db->rawQuery($sql);
     }
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function createTable(SchemaBuilder $schema)
 {
     $table = $schema->getName();
     $this->tables[] = $table;
     $this->schemas[$table] = $schema;
     $this->reload();
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function createTable(SchemaBuilder $schema)
 {
     $table = $schema->getName();
     $sql = 'CREATE TABLE ' . $this->db->quoteModel($table) . ' (';
     $columns = $schema->getFields();
     $first = true;
     foreach ($columns as $column) {
         $type = $schema->{$column};
         if (!$first) {
             $sql .= ', ';
         } else {
             $first = false;
         }
         $sql .= $this->db->quoteField($column);
         $sql .= ' ' . $this->fromDataType($type);
     }
     $pk = $schema->getPrimaryKey();
     if (count($pk) > 0) {
         $sql .= ', CONSTRAINT "' . $this->db->tableName($table) . '_PRIMARY" PRIMARY KEY (';
         $pk = array_map(array($this->db, 'quoteField'), $pk);
         $sql .= implode(', ', $pk) . ')';
     }
     $sql .= ')';
     $this->db->rawQuery($sql);
     foreach ($schema->getIndexes() as $index => $options) {
         if ($index == 'PRIMARY') {
             continue;
         }
         $sql = 'CREATE';
         if ($options['unique']) {
             $sql .= ' UNIQUE';
         }
         $sql .= ' INDEX "' . $this->db->tableName($table) . '_' . $index . '"';
         $sql .= ' ON ' . $this->db->quoteModel($table);
         $columns = array_map(array($this->db, 'quoteField'), $options['columns']);
         $sql .= ' (' . implode(', ', $columns) . ')';
         $this->db->rawQuery($sql);
     }
 }
示例#4
0
 /**
  * {@inheritdoc}
  */
 public function createTable(SchemaBuilder $schema)
 {
     $sql = 'CREATE TABLE `' . $this->db->tableName($schema->getName()) . '` (';
     $columns = $schema->getFields();
     $first = true;
     foreach ($columns as $column) {
         $type = $schema->{$column};
         if (!$first) {
             $sql .= ', ';
         } else {
             $first = false;
         }
         $sql .= $column;
         $sql .= ' ' . $this->fromDataType($type);
     }
     foreach ($schema->getIndexes() as $index => $options) {
         $sql .= ', ';
         if ($index == 'PRIMARY') {
             $sql .= 'PRIMARY KEY (';
         } else {
             if ($options['unique']) {
                 $sql .= 'UNIQUE (';
             } else {
                 $sql .= 'INDEX (';
             }
         }
         $sql .= implode(', ', $options['columns']) . ')';
     }
     $sql .= ') CHARACTER SET utf8';
     $this->db->rawQuery($sql);
 }