示例#1
0
 /**
  * Creates the table.
  *
  * @param string $name the table name
  */
 private function createTable($name)
 {
     $table = new Table($name);
     $table->addField(new Field('id', new Type(Field::TYPE_VARCHAR, 32), '', false, false));
     $table->addField(new Field('username', new Type(Field::TYPE_VARCHAR, 255), null, true, false));
     $table->addField(new Field('fullName', Field::TYPE_TEXT, null, true, false));
     $table->addField(new Field('email', new Type(Field::TYPE_VARCHAR, 255), null, true, false));
     $table->addField(new Field('birthdate', Field::TYPE_DATE, null, true, false));
     $table->addField(new Field('gender', new Type(Field::TYPE_VARCHAR, 255), '', true, false));
     $table->addField(new Field('timezoneOffset', new Type(Field::TYPE_SMALLINT, 4), 0, false, false));
     $table->addField(new Field('locale', new Type(Field::TYPE_VARCHAR, 10), 'en-US', false, false));
     $table->addField(new Field('lastLogin', new Type(Field::TYPE_INT, 12), -1, false, false));
     $table->addField(new Field('secret', Field::TYPE_TEXT, '', false, false));
     $table->setPrimaryKey(new PrimaryKey($name, array('id')));
     $table->addIndex(new Index('username', $name, true, array('username')));
     $table->addIndex(new Index('email', $name, true, array('email')));
     $this->db->createTable($table);
 }
示例#2
0
 /**
  * Creates the table.
  *
  * @param string $name the table name
  */
 private function createTable($name)
 {
     $table = new Table($name);
     $table->addField(new Field('id', Field::TYPE_INT, '', false, true));
     $table->addField(new Field('gid', new Type(Field::TYPE_VARCHAR, 32), '', false, false));
     $table->addField(new Field('token', Field::TYPE_TEXT, '', false, false));
     $table->setPrimaryKey(new PrimaryKey($name, array('id')));
     $table->addIndex(new Index('gid', $name, true, array('gid')));
     $this->db->createTable($table);
 }
示例#3
0
 /**
  * Returns the table skeleton.
  *
  * This is the basic table with ID, GID and parent fields.
  *
  * @return Table the table skeleton
  */
 protected function getTableSkeleton()
 {
     $table = new Table($this->tableName, '');
     $table->addField(new Field('id', new Type(Field::TYPE_INT, 20), '', false, true, 'The local ID'));
     $table->addField(new Field('gid', new Type(Field::TYPE_VARCHAR, 32), '-1', false, false, 'The global ID (GID)'));
     $table->addField(new Field('parent', new Type(Field::TYPE_VARCHAR, 32), '-1', false, false, 'The parent GID'));
     $table->setPrimaryKey(new PrimaryKey($this->tableName, array('id')));
     $table->addIndex(new Index('gid', $this->tableName, true, array('gid')));
     $table->addIndex(new Index('parent', $this->tableName, false, array('parent')));
     return $table;
 }
示例#4
0
 /**
  * Tests dropping an index from a table.
  *
  * @depends testCreateTable
  * @covers empire\framework\db\DB::dropIndex
  *
  * @param DB[] $dbs the database objects to work on
  */
 public function testDropIndex($dbs)
 {
     foreach ($dbs as $db) {
         /* @var $db DB */
         $table = new Table('testidx');
         $table->addField(new Field('pk', new Type(Field::TYPE_INT)));
         $table->addIndex(new Index('tmpIndex', 'testidx', true, array('pk')));
         $db->createTable($table);
         $db->dropIndex('testidx', 'tmpIndex');
         $this->assertSame(null, $db->getIndex('testidx', 'tmpIndex'));
         $db->dropTable('testidx');
     }
 }