/** * Tests getting the 'null allowed' property of a field * * @depends testCreateTable * @covers empire\framework\db\DB::getNullAllowed * * @param DB[] $dbs the database objects to work on */ public function testGetNullAllowed($dbs) { foreach ($dbs as $db) { /* @var $db DB */ $this->assertSame(self::$idField->getNullAllowed(), $db->getNullAllowed('test', self::$idField->getName())); $this->assertSame(self::$testField->getNullAllowed(), $db->getNullAllowed('test', self::$testField->getName())); } }
/** * 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; }