コード例 #1
0
ファイル: DBTest.php プロジェクト: thornberger/empire
 /**
  * Tests getting the number of affected rows.
  *
  * @depends testCreateTable
  * @covers empire\framework\db\DB::affectedRows
  *
  * @param DB[] $dbs the database objects to work on
  */
 public function testAffectedRows($dbs)
 {
     foreach ($dbs as $db) {
         /* @var $db DB */
         $bindings = array(':::table' => self::$table->getName());
         $db->execute('DELETE FROM :::table', $bindings);
         $bindings = array(':::table' => self::$table->getName(), '::field' => self::$testField->getName(), ':value' => 42);
         $db->execute('INSERT INTO :::table (::field) VALUES (:value)', $bindings);
         $this->assertSame(1, $db->affectedRows());
         $bindings = array(':::table' => self::$table->getName(), '::field' => self::$testField->getName(), ':value' => 99);
         $db->execute('INSERT INTO :::table (::field) VALUES (:value)', $bindings);
         $this->assertSame(1, $db->affectedRows());
         $bindings = array(':::table' => self::$table->getName(), '::field' => self::$testField->getName());
         $result = $db->getResult('SELECT * FROM :::table', $bindings);
         $this->assertSame(2, $db->affectedRows());
         $bindings = array(':::table' => self::$table->getName());
         $db->execute('DELETE FROM :::table', $bindings);
     }
 }
コード例 #2
0
ファイル: FieldTest.php プロジェクト: thornberger/empire
 /**
  * Tests getting the defined types for fields.
  *
  * @covers empire\framework\db\schema\Field::getDefinedTypes
  */
 public function testGetDefinedTypes()
 {
     $types = Field::getDefinedTypes();
     $this->assertContainsOnly('string', $types);
 }
コード例 #3
0
ファイル: MysqlDDLDriver.php プロジェクト: thornberger/empire
 /**
  * Builds a column definition from a <code>Field</code> that can be used in CREATE or ALTER
  * statements.
  *
  * @param Field $field the <code>Field</code> object to be parsed
  * @return string a string that can be used in a statement
  */
 private function buildColumnDefinition(Field $field)
 {
     $type = $this->mapInternalType($field->getType()->getName());
     $length = $field->getType()->getLength();
     $res = $field->getName() . ' ' . $type;
     if ($field->getType()->getName() === 'BOOLEAN') {
         $length = '1';
     }
     if ($length !== null) {
         $res .= '(' . $length . ')';
     }
     if ($field->getNullAllowed()) {
         $res .= ' NULL';
     } else {
         $res .= ' NOT NULL';
     }
     $default = $field->getDefault();
     if ($default === null) {
         if ($field->getNullAllowed()) {
             $res .= ' DEFAULT NULL';
         }
     } else {
         if ($field->getType()->getName() === 'BOOLEAN') {
             $res .= ' DEFAULT ';
             if ($field->getDefault() === true) {
                 $res .= '1';
             } else {
                 $res .= '0';
             }
         } elseif (strlen($default) > 0) {
             $default = $this->pdoDriver->escapeString($default);
         }
         if (strlen($default) !== 0) {
             $res .= ' DEFAULT ' . $default;
         }
     }
     if ($field->getAutoIncrement()) {
         $res .= ' AUTO_INCREMENT';
     }
     $fieldComment = $field->getComment();
     if (strlen($fieldComment) > 0) {
         $res .= ' COMMENT ' . $this->pdoDriver->escapeString($fieldComment);
     }
     return $res;
 }
コード例 #4
0
ファイル: Table.php プロジェクト: thornberger/empire
 /**
  * Adds a field to this table.
  *
  * @param Field $field the field to add
  */
 public final function addField(Field $field)
 {
     $this->fields[$field->getName()] = $field;
 }