- moved getIntegerDeclaration to export since we already have getDeclaration in there
This commit is contained in:
parent
b1df27b1ac
commit
fa5ab7d2b1
@ -413,55 +413,4 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict
|
||||
{
|
||||
return 'COLLATE ' . $collation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain DBMS specific SQL code portion needed to declare an integer type
|
||||
* field to be used in statements like CREATE TABLE.
|
||||
*
|
||||
* @param string $name name the field to be declared.
|
||||
* @param string $field associative array with the name of the properties
|
||||
* of the field being declared as array indexes.
|
||||
* Currently, the types of supported field
|
||||
* properties are as follows:
|
||||
*
|
||||
* unsigned
|
||||
* Boolean flag that indicates whether the field
|
||||
* should be declared as unsigned integer if
|
||||
* possible.
|
||||
*
|
||||
* default
|
||||
* Integer value to be used as default for this
|
||||
* field.
|
||||
*
|
||||
* notnull
|
||||
* Boolean flag that indicates whether this field is
|
||||
* constrained to not be set to null.
|
||||
* @return string DBMS specific SQL code portion that should be used to
|
||||
* declare the specified field.
|
||||
*/
|
||||
public function getIntegerDeclaration($name, $field)
|
||||
{
|
||||
$default = $autoinc = '';
|
||||
if ( ! empty($field['autoincrement'])) {
|
||||
$autoinc = ' AUTO_INCREMENT';
|
||||
} elseif (array_key_exists('default', $field)) {
|
||||
if ($field['default'] === '') {
|
||||
$field['default'] = empty($field['notnull']) ? null : 0;
|
||||
}
|
||||
if (is_null($field['default'])) {
|
||||
$default = ' DEFAULT NULL';
|
||||
} else {
|
||||
$default = ' DEFAULT '.$this->conn->quote($field['default']);
|
||||
}
|
||||
} elseif (empty($field['notnull'])) {
|
||||
$default = ' DEFAULT NULL';
|
||||
}
|
||||
|
||||
$notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : '';
|
||||
$unsigned = (isset($field['unsigned']) && $field['unsigned']) ? ' UNSIGNED' : '';
|
||||
|
||||
$name = $this->conn->quoteIdentifier($name, true);
|
||||
|
||||
return $name . ' ' . $this->getNativeDeclaration($field) . $unsigned . $default . $notnull . $autoinc;
|
||||
}
|
||||
}
|
||||
|
@ -559,60 +559,6 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict
|
||||
'fixed' => $fixed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain DBMS specific SQL code portion needed to declare an integer type
|
||||
* field to be used in statements like CREATE TABLE.
|
||||
*
|
||||
* @param string $name name the field to be declared.
|
||||
* @param array $field associative array with the name of the properties
|
||||
* of the field being declared as array indexes. Currently, the types
|
||||
* of supported field properties are as follows:
|
||||
*
|
||||
* unsigned
|
||||
* Boolean flag that indicates whether the field should be
|
||||
* declared as unsigned integer if possible.
|
||||
*
|
||||
* default
|
||||
* Integer value to be used as default for this field.
|
||||
*
|
||||
* notnull
|
||||
* Boolean flag that indicates whether this field is constrained
|
||||
* to not be set to null.
|
||||
* @return string DBMS specific SQL code portion that should be used to
|
||||
* declare the specified field.
|
||||
*/
|
||||
public function getIntegerDeclaration($name, $field)
|
||||
{
|
||||
/**
|
||||
if ( ! empty($field['unsigned'])) {
|
||||
$this->conn->warnings[] = "unsigned integer field \"$name\" is being declared as signed integer";
|
||||
}
|
||||
*/
|
||||
|
||||
if ( ! empty($field['autoincrement'])) {
|
||||
$name = $this->conn->quoteIdentifier($name, true);
|
||||
return $name . ' ' . $this->getNativeDeclaration($field);
|
||||
}
|
||||
|
||||
$default = '';
|
||||
if (array_key_exists('default', $field)) {
|
||||
if ($field['default'] === '') {
|
||||
$field['default'] = empty($field['notnull']) ? null : 0;
|
||||
}
|
||||
$default = ' DEFAULT '.$this->conn->quote($field['default'], $field['type']);
|
||||
}
|
||||
/**
|
||||
TODO: is this needed ?
|
||||
elseif (empty($field['notnull'])) {
|
||||
$default = ' DEFAULT NULL';
|
||||
}
|
||||
*/
|
||||
|
||||
$notnull = empty($field['notnull']) ? '' : ' NOT NULL';
|
||||
$name = $this->conn->quoteIdentifier($name, true);
|
||||
return $name . ' ' . $this->getNativeDeclaration($field) . $default . $notnull;
|
||||
}
|
||||
|
||||
/**
|
||||
* parseBoolean
|
||||
* parses a literal boolean value and returns
|
||||
|
@ -241,60 +241,4 @@ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict
|
||||
'unsigned' => $unsigned,
|
||||
'fixed' => $fixed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain DBMS specific SQL code portion needed to declare an integer type
|
||||
* field to be used in statements like CREATE TABLE.
|
||||
*
|
||||
* @param string $name name the field to be declared.
|
||||
* @param array $field associative array with the name of the properties
|
||||
* of the field being declared as array indexes.
|
||||
* Currently, the types of supported field
|
||||
* properties are as follows:
|
||||
*
|
||||
* unsigned
|
||||
* Boolean flag that indicates whether the field
|
||||
* should be declared as unsigned integer if
|
||||
* possible.
|
||||
*
|
||||
* default
|
||||
* Integer value to be used as default for this
|
||||
* field.
|
||||
*
|
||||
* notnull
|
||||
* Boolean flag that indicates whether this field is
|
||||
* constrained to not be set to null.
|
||||
* @return string DBMS specific SQL code portion that should be used to
|
||||
* declare the specified field.
|
||||
* @access protected
|
||||
*/
|
||||
public function getIntegerDeclaration($name, array $field)
|
||||
{
|
||||
$default = $autoinc = '';
|
||||
$type = $this->getNativeDeclaration($field);
|
||||
|
||||
$autoincrement = isset($field['autoincrement']) && $field['autoincrement'];
|
||||
|
||||
if ($autoincrement) {
|
||||
$autoinc = ' PRIMARY KEY AUTOINCREMENT';
|
||||
$type = 'INTEGER';
|
||||
} elseif (array_key_exists('default', $field)) {
|
||||
if ($field['default'] === '') {
|
||||
$field['default'] = empty($field['notnull']) ? null : 0;
|
||||
}
|
||||
$default = ' DEFAULT ' . $this->conn->quote($field['default'], $field['type']);
|
||||
}/**
|
||||
elseif (empty($field['notnull'])) {
|
||||
$default = ' DEFAULT NULL';
|
||||
}
|
||||
*/
|
||||
|
||||
$notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : '';
|
||||
|
||||
// sqlite does not support unsigned attribute for autoinremented fields
|
||||
$unsigned = (isset($field['unsigned']) && $field['unsigned'] && !$autoincrement) ? ' UNSIGNED' : '';
|
||||
|
||||
$name = $this->conn->quoteIdentifier($name, true);
|
||||
return $name . ' ' . $type . $unsigned . $default . $notnull . $autoinc;
|
||||
}
|
||||
}
|
@ -693,11 +693,10 @@ class Doctrine_Export extends Doctrine_Connection_Module
|
||||
*/
|
||||
public function getDeclaration($name, array $field)
|
||||
{
|
||||
|
||||
$method = 'get' . $field['type'] . 'Declaration';
|
||||
|
||||
if (method_exists($this->conn->dataDict, $method)) {
|
||||
return $this->conn->dataDict->$method($name, $field);
|
||||
if (method_exists($this, $method)) {
|
||||
return $this->$method($name, $field);
|
||||
}
|
||||
|
||||
$default = $this->getDefaultFieldDeclaration($field);
|
||||
|
@ -502,6 +502,57 @@ class Doctrine_Export_Mysql extends Doctrine_Export
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain DBMS specific SQL code portion needed to declare an integer type
|
||||
* field to be used in statements like CREATE TABLE.
|
||||
*
|
||||
* @param string $name name the field to be declared.
|
||||
* @param string $field associative array with the name of the properties
|
||||
* of the field being declared as array indexes.
|
||||
* Currently, the types of supported field
|
||||
* properties are as follows:
|
||||
*
|
||||
* unsigned
|
||||
* Boolean flag that indicates whether the field
|
||||
* should be declared as unsigned integer if
|
||||
* possible.
|
||||
*
|
||||
* default
|
||||
* Integer value to be used as default for this
|
||||
* field.
|
||||
*
|
||||
* notnull
|
||||
* Boolean flag that indicates whether this field is
|
||||
* constrained to not be set to null.
|
||||
* @return string DBMS specific SQL code portion that should be used to
|
||||
* declare the specified field.
|
||||
*/
|
||||
public function getIntegerDeclaration($name, $field)
|
||||
{
|
||||
$default = $autoinc = '';
|
||||
if ( ! empty($field['autoincrement'])) {
|
||||
$autoinc = ' AUTO_INCREMENT';
|
||||
} elseif (array_key_exists('default', $field)) {
|
||||
if ($field['default'] === '') {
|
||||
$field['default'] = empty($field['notnull']) ? null : 0;
|
||||
}
|
||||
if (is_null($field['default'])) {
|
||||
$default = ' DEFAULT NULL';
|
||||
} else {
|
||||
$default = ' DEFAULT '.$this->conn->quote($field['default']);
|
||||
}
|
||||
} elseif (empty($field['notnull'])) {
|
||||
$default = ' DEFAULT NULL';
|
||||
}
|
||||
|
||||
$notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : '';
|
||||
$unsigned = (isset($field['unsigned']) && $field['unsigned']) ? ' UNSIGNED' : '';
|
||||
|
||||
$name = $this->conn->quoteIdentifier($name, true);
|
||||
|
||||
return $name . ' ' . $this->conn->dataDict->getNativeDeclaration($field) . $unsigned . $default . $notnull . $autoinc;
|
||||
}
|
||||
|
||||
/**
|
||||
* getDefaultDeclaration
|
||||
* Obtain DBMS specific SQL code portion needed to set a default value
|
||||
|
@ -360,4 +360,53 @@ class Doctrine_Export_Pgsql extends Doctrine_Export
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain DBMS specific SQL code portion needed to declare an integer type
|
||||
* field to be used in statements like CREATE TABLE.
|
||||
*
|
||||
* @param string $name name the field to be declared.
|
||||
* @param array $field associative array with the name of the properties
|
||||
* of the field being declared as array indexes. Currently, the types
|
||||
* of supported field properties are as follows:
|
||||
*
|
||||
* unsigned
|
||||
* Boolean flag that indicates whether the field should be
|
||||
* declared as unsigned integer if possible.
|
||||
*
|
||||
* default
|
||||
* Integer value to be used as default for this field.
|
||||
*
|
||||
* notnull
|
||||
* Boolean flag that indicates whether this field is constrained
|
||||
* to not be set to null.
|
||||
* @return string DBMS specific SQL code portion that should be used to
|
||||
* declare the specified field.
|
||||
*/
|
||||
public function getIntegerDeclaration($name, $field)
|
||||
{
|
||||
/**
|
||||
if ( ! empty($field['unsigned'])) {
|
||||
$this->conn->warnings[] = "unsigned integer field \"$name\" is being declared as signed integer";
|
||||
}
|
||||
*/
|
||||
|
||||
if ( ! empty($field['autoincrement'])) {
|
||||
$name = $this->conn->quoteIdentifier($name, true);
|
||||
return $name . ' ' . $this->conn->dataDict->getNativeDeclaration($field);
|
||||
}
|
||||
|
||||
$default = '';
|
||||
if (array_key_exists('default', $field)) {
|
||||
if ($field['default'] === '') {
|
||||
$field['default'] = empty($field['notnull']) ? null : 0;
|
||||
}
|
||||
$default = ' DEFAULT '.$this->conn->quote($field['default'], $field['type']);
|
||||
} elseif (empty($field['notnull'])) {
|
||||
$default = ' DEFAULT NULL';
|
||||
}
|
||||
|
||||
$notnull = empty($field['notnull']) ? '' : ' NOT NULL';
|
||||
$name = $this->conn->quoteIdentifier($name, true);
|
||||
return $name . ' ' . $this->conn->dataDict->getNativeDeclaration($field) . $default . $notnull;
|
||||
}
|
||||
}
|
@ -413,4 +413,58 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
|
||||
|
||||
return 'ALTER TABLE ' . $name . ' ' . $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain DBMS specific SQL code portion needed to declare an integer type
|
||||
* field to be used in statements like CREATE TABLE.
|
||||
*
|
||||
* @param string $name name the field to be declared.
|
||||
* @param array $field associative array with the name of the properties
|
||||
* of the field being declared as array indexes.
|
||||
* Currently, the types of supported field
|
||||
* properties are as follows:
|
||||
*
|
||||
* unsigned
|
||||
* Boolean flag that indicates whether the field
|
||||
* should be declared as unsigned integer if
|
||||
* possible.
|
||||
*
|
||||
* default
|
||||
* Integer value to be used as default for this
|
||||
* field.
|
||||
*
|
||||
* notnull
|
||||
* Boolean flag that indicates whether this field is
|
||||
* constrained to not be set to null.
|
||||
* @return string DBMS specific SQL code portion that should be used to
|
||||
* declare the specified field.
|
||||
* @access protected
|
||||
*/
|
||||
public function getIntegerDeclaration($name, array $field)
|
||||
{
|
||||
$default = $autoinc = '';
|
||||
$type = $this->conn->dataDict->getNativeDeclaration($field);
|
||||
|
||||
$autoincrement = isset($field['autoincrement']) && $field['autoincrement'];
|
||||
|
||||
if ($autoincrement) {
|
||||
$autoinc = ' PRIMARY KEY AUTOINCREMENT';
|
||||
$type = 'INTEGER';
|
||||
} elseif (array_key_exists('default', $field)) {
|
||||
if ($field['default'] === '') {
|
||||
$field['default'] = empty($field['notnull']) ? null : 0;
|
||||
}
|
||||
$default = ' DEFAULT ' . $this->conn->quote($field['default'], $field['type']);
|
||||
} elseif (empty($field['notnull'])) {
|
||||
$default = ' DEFAULT NULL';
|
||||
}
|
||||
|
||||
$notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : '';
|
||||
|
||||
// sqlite does not support unsigned attribute for autoinremented fields
|
||||
$unsigned = (isset($field['unsigned']) && $field['unsigned'] && !$autoincrement) ? ' UNSIGNED' : '';
|
||||
|
||||
$name = $this->conn->quoteIdentifier($name, true);
|
||||
return $name . ' ' . $type . $unsigned . $default . $notnull . $autoinc;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user