Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
fa5ab7d2
Commit
fa5ab7d2
authored
Jan 10, 2008
by
lsmith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- moved getIntegerDeclaration to export since we already have getDeclaration in there
parent
b1df27b1
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
177 additions
and
185 deletions
+177
-185
Mysql.php
lib/Doctrine/DataDict/Mysql.php
+0
-51
Pgsql.php
lib/Doctrine/DataDict/Pgsql.php
+0
-54
Sqlite.php
lib/Doctrine/DataDict/Sqlite.php
+1
-57
Export.php
lib/Doctrine/Export.php
+2
-3
Mysql.php
lib/Doctrine/Export/Mysql.php
+51
-0
Pgsql.php
lib/Doctrine/Export/Pgsql.php
+59
-10
Sqlite.php
lib/Doctrine/Export/Sqlite.php
+64
-10
No files found.
lib/Doctrine/DataDict/Mysql.php
View file @
fa5ab7d2
...
...
@@ -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
;
}
}
lib/Doctrine/DataDict/Pgsql.php
View file @
fa5ab7d2
...
...
@@ -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
...
...
lib/Doctrine/DataDict/Sqlite.php
View file @
fa5ab7d2
...
...
@@ -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
;
}
}
\ No newline at end of file
}
lib/Doctrine/Export.php
View file @
fa5ab7d2
...
...
@@ -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
);
...
...
lib/Doctrine/Export/Mysql.php
View file @
fa5ab7d2
...
...
@@ -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
...
...
lib/Doctrine/Export/Pgsql.php
View file @
fa5ab7d2
...
...
@@ -43,7 +43,7 @@ class Doctrine_Export_Pgsql extends Doctrine_Export
public
function
createDatabaseSql
(
$name
)
{
$query
=
'CREATE DATABASE '
.
$this
->
conn
->
quoteIdentifier
(
$name
);
return
$query
;
}
...
...
@@ -57,7 +57,7 @@ class Doctrine_Export_Pgsql extends Doctrine_Export
public
function
dropDatabaseSql
(
$name
)
{
$query
=
'DROP DATABASE '
.
$this
->
conn
->
quoteIdentifier
(
$name
);
return
$query
;
}
...
...
@@ -124,7 +124,7 @@ class Doctrine_Export_Pgsql extends Doctrine_Export
if
(
$check
)
{
return
true
;
}
$sql
=
array
();
if
(
isset
(
$changes
[
'add'
])
&&
is_array
(
$changes
[
'add'
]))
{
...
...
@@ -177,10 +177,10 @@ class Doctrine_Export_Pgsql extends Doctrine_Export
$changeName
=
$this
->
conn
->
quoteIdentifier
(
$changes
[
'name'
],
true
);
$sql
[]
=
'ALTER TABLE '
.
$name
.
' RENAME TO '
.
$changeName
;
}
return
$sql
;
}
/**
* alter an existing table
*
...
...
@@ -276,7 +276,7 @@ class Doctrine_Export_Pgsql extends Doctrine_Export
foreach
(
$sql
as
$query
)
{
$this
->
conn
->
exec
(
$query
);
}
return
true
;
return
true
;
}
/**
...
...
@@ -324,7 +324,7 @@ class Doctrine_Export_Pgsql extends Doctrine_Export
if
(
!
$name
)
{
throw
new
Doctrine_Export_Exception
(
'no valid table name specified'
);
}
if
(
empty
(
$fields
))
{
throw
new
Doctrine_Export_Exception
(
'no fields specified for table '
.
$name
);
}
...
...
@@ -347,7 +347,7 @@ class Doctrine_Export_Pgsql extends Doctrine_Export
$sql
[]
=
$this
->
createIndexSql
(
$name
,
$index
,
$definition
);
}
}
if
(
isset
(
$options
[
'foreignKeys'
]))
{
foreach
((
array
)
$options
[
'foreignKeys'
]
as
$k
=>
$definition
)
{
...
...
@@ -356,8 +356,57 @@ class Doctrine_Export_Pgsql extends Doctrine_Export
}
}
}
return
$sql
;
}
}
\ No newline at end of file
/**
* 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
;
}
}
lib/Doctrine/Export/Sqlite.php
View file @
fa5ab7d2
...
...
@@ -100,7 +100,7 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
* Obtain DBMS specific SQL code portion needed to set an index
* declaration to be used in statements like CREATE TABLE.
*
* @return string
* @return string
*/
public
function
getIndexFieldDeclarationList
(
array
$fields
)
{
...
...
@@ -162,15 +162,15 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
if
(
!
$name
)
{
throw
new
Doctrine_Export_Exception
(
'no valid table name specified'
);
}
if
(
empty
(
$fields
))
{
throw
new
Doctrine_Export_Exception
(
'no fields specified for table '
.
$name
);
}
$queryFields
=
$this
->
getFieldDeclarationList
(
$fields
);
$autoinc
=
false
;
foreach
(
$fields
as
$field
)
{
if
(
isset
(
$field
[
'autoincrement'
])
&&
$field
[
'autoincrement'
]
||
if
(
isset
(
$field
[
'autoincrement'
])
&&
$field
[
'autoincrement'
]
||
(
isset
(
$field
[
'autoinc'
])
&&
$field
[
'autoinc'
]))
{
$autoinc
=
true
;
break
;
...
...
@@ -204,8 +204,8 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
}
}
return
$query
;
/**
try {
...
...
@@ -309,7 +309,7 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
$this
->
conn
->
exec
(
'INSERT INTO '
.
$sequenceName
.
' ('
.
$seqcolName
.
') VALUES ('
.
(
$start
-
1
)
.
')'
);
return
true
;
}
catch
(
Doctrine_Connection_Exception
$e
)
{
// Handle error
// Handle error
try
{
$result
=
$db
->
exec
(
'DROP TABLE '
.
$sequenceName
);
...
...
@@ -332,7 +332,7 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
return
'DROP TABLE '
.
$sequenceName
;
}
public
function
alterTableSql
(
$name
,
array
$changes
,
$check
=
false
)
{
if
(
!
$name
)
{
...
...
@@ -388,7 +388,7 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
$oldFieldName
=
$fieldName
;
}
$oldFieldName
=
$this
->
conn
->
quoteIdentifier
(
$oldFieldName
,
true
);
$query
.=
'CHANGE '
.
$oldFieldName
.
' '
$query
.=
'CHANGE '
.
$oldFieldName
.
' '
.
$this
->
getDeclaration
(
$fieldName
,
$field
[
'definition'
]);
}
}
...
...
@@ -410,7 +410,61 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
}
$name
=
$this
->
conn
->
quoteIdentifier
(
$name
,
true
);
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
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment