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
8110cf8e
Commit
8110cf8e
authored
Dec 29, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mysql string > 255 now converts to TEXT type
parent
64923b58
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
73 additions
and
50 deletions
+73
-50
Doctrine.php
lib/Doctrine.php
+5
-1
Connection.php
lib/Doctrine/Connection.php
+6
-6
Mysql.php
lib/Doctrine/DataDict/Mysql.php
+12
-6
Oracle.php
lib/Doctrine/Export/Oracle.php
+45
-36
MysqlTestCase.php
tests/DataDict/MysqlTestCase.php
+5
-0
PgsqlTestCase.php
tests/Export/PgsqlTestCase.php
+0
-1
No files found.
lib/Doctrine.php
View file @
8110cf8e
...
...
@@ -132,7 +132,11 @@ final class Doctrine {
* default table type attribute
*/
const
ATTR_DEFAULT_TABLE_TYPE
=
21
;
const
ATTR_DEF_TEXT_LENGTH
=
30
;
const
ATTR_DEF_VARCHAR_LENGTH
=
31
;
const
ATTR_DEF_TABLESPACE
=
32
;
const
ATTR_EMULATE_DATABASE
=
33
;
const
ATTR_DB_NAME_FORMAT
=
34
;
/** TODO: REMOVE THE FOLLOWING CONSTANTS AND UPDATE THE DOCS ! */
...
...
lib/Doctrine/Connection.php
View file @
8110cf8e
...
...
@@ -148,8 +148,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @return Doctrine_Connection_Module connection module
*/
public
function
__get
(
$name
)
{
if
(
isset
(
$this
->
properties
[
$name
]))
return
$this
->
properties
[
$name
];
if
(
!
isset
(
$this
->
modules
[
$name
]))
throw
new
Doctrine_Connection_Exception
(
'Unknown module '
.
$name
);
throw
new
Doctrine_Connection_Exception
(
'Unknown module
/ property
'
.
$name
);
if
(
$this
->
modules
[
$name
]
===
false
)
{
switch
(
$name
)
{
...
...
@@ -160,10 +163,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$class
=
'Doctrine_'
.
ucwords
(
$name
)
.
'_'
.
$this
->
getName
();
$this
->
modules
[
$name
]
=
new
$class
(
$this
);
}
}
if
(
isset
(
$this
->
properties
[
$name
]))
return
$this
->
properties
[
$name
];
}
return
$this
->
modules
[
$name
];
}
...
...
@@ -223,7 +223,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public
function
quoteIdentifier
(
$str
,
$checkOption
=
true
)
{
if
(
$checkOption
&&
!
$this
->
getAttribute
(
Doctrine
::
ATTR_QUOTE_IDENTIFIER
))
{
return
$str
;
}
}
$str
=
str_replace
(
$this
->
properties
[
'identifier_quoting'
][
'end'
],
$this
->
properties
[
'identifier_quoting'
][
'escape'
]
.
$this
->
properties
[
'identifier_quoting'
][
'end'
],
$str
);
...
...
lib/Doctrine/DataDict/Mysql.php
View file @
8110cf8e
...
...
@@ -130,7 +130,8 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict {
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
*/
public
function
getNativeDeclaration
(
$field
)
{
public
function
getNativeDeclaration
(
$field
)
{
switch
(
$field
[
'type'
])
{
case
'char'
:
$length
=
(
!
empty
(
$field
[
'length'
]))
?
$field
[
'length'
]
:
false
;
...
...
@@ -140,12 +141,17 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict {
case
'array'
:
case
'object'
:
case
'string'
:
if
(
empty
(
$field
[
'length'
])
&&
array_key_exists
(
'default'
,
$field
))
{
$field
[
'length'
]
=
$this
->
conn
->
varchar_max_length
;
if
(
!
isset
(
$field
[
'length'
]))
{
if
(
array_key_exists
(
'default'
,
$field
))
{
$field
[
'length'
]
=
$this
->
conn
->
varchar_max_length
;
}
else
{
$field
[
'length'
]
=
false
;
}
}
$length
=
(
!
empty
(
$field
[
'length'
])
)
?
$field
[
'length'
]
:
false
;
$fixed
=
(
!
empty
(
$field
[
'fixed'
]))
?
$field
[
'fixed'
]
:
false
;
$length
=
(
$field
[
'length'
]
<
$this
->
conn
->
varchar_max_length
)
?
$field
[
'length'
]
:
false
;
$fixed
=
(
isset
(
$field
[
'fixed'
]))
?
$field
[
'fixed'
]
:
false
;
return
$fixed
?
(
$length
?
'CHAR('
.
$length
.
')'
:
'CHAR(255)'
)
:
(
$length
?
'VARCHAR('
.
$length
.
')'
:
'TEXT'
);
...
...
lib/Doctrine/Export/Oracle.php
View file @
8110cf8e
...
...
@@ -40,26 +40,28 @@ class Doctrine_Export_Oracle extends Doctrine_Export {
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
public
function
createDatabase
(
$name
)
{
if
(
!
$db
->
options
[
'emulate_database'
])
throw
new
Doctrine_Export_Oracle_Exception
(
'database creation is only supported if the "emulate_database" option is enabled'
);
public
function
createDatabase
(
$name
)
{
if
(
!
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_EMULATE_DATABASE
))
throw
new
Doctrine_Export_Oracle_Exception
(
'database creation is only supported if the "emulate_database" attribute is enabled'
);
$username
=
$db
->
options
[
'database_name_prefix'
]
.
$name
;
$password
=
$db
->
dsn
[
'password'
]
?
$db
->
dsn
[
'password'
]
:
$name
;
$tablespace
=
$db
->
options
[
'default_tablespace'
]
?
' DEFAULT TABLESPACE '
.
$db
->
options
[
'default_tablespace'
]
:
''
;
$username
=
sprintf
(
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_DB_NAME_FORMAT
),
$name
);
$password
=
$this
->
conn
->
dsn
[
'password'
]
?
$this
->
conn
->
dsn
[
'password'
]
:
$name
;
$
query
=
'CREATE USER '
.
$username
.
' IDENTIFIED BY '
.
$password
.
$tablespace
;
$result
=
$db
->
standaloneQuery
(
$query
,
null
,
true
)
;
$
tablespace
=
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_DB_NAME_FORMAT
)
?
' DEFAULT TABLESPACE '
.
$this
->
conn
->
options
[
'default_tablespace'
]
:
''
;
$query
=
'GRANT CREATE SESSION, CREATE TABLE, UNLIMITED TABLESPACE, CREATE SEQUENCE, CREATE TRIGGER TO '
.
$username
;
$result
=
$db
->
standaloneQuery
(
$query
,
null
,
true
);
$query
=
'CREATE USER '
.
$username
.
' IDENTIFIED BY '
.
$password
.
$tablespace
;
$result
=
$this
->
conn
->
query
(
$query
);
$query
=
'GRANT CREATE SESSION, CREATE TABLE, UNLIMITED TABLESPACE, CREATE SEQUENCE, CREATE TRIGGER TO '
.
$username
;
$result
=
$this
->
conn
->
query
(
$query
);
if
(
PEAR
::
isError
(
$result
))
{
$query
=
'DROP USER '
.
$username
.
' CASCADE'
;
$result2
=
$
db
->
standaloneQuery
(
$query
,
null
,
true
);
$result2
=
$
this
->
conn
->
query
(
$query
);
if
(
PEAR
::
isError
(
$result2
))
{
return
$
db
->
raiseError
(
$result2
,
null
,
null
,
return
$
this
->
conn
->
raiseError
(
$result2
,
null
,
null
,
'could not setup the database user'
,
__FUNCTION__
);
}
return
$result
;
...
...
@@ -68,19 +70,21 @@ class Doctrine_Export_Oracle extends Doctrine_Export {
/**
* drop an existing database
*
* @param object $
db
database object that is extended by this class
* @param object $
this->conn
database object that is extended by this class
* @param string $name name of the database that should be dropped
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
public
function
dropDatabase
(
$name
)
{
if
(
!
$db
->
options
[
'emulate_database'
])
public
function
dropDatabase
(
$name
)
{
if
(
!
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_EMULATE_DATABASE
))
throw
new
Doctrine_Export_Oracle_Exception
(
'database dropping is only supported if the
"emulate_database" option is enabled'
);
$username
=
$db
->
options
[
'database_name_prefix'
]
.
$name
;
return
$db
->
standaloneQuery
(
'DROP USER '
.
$username
.
' CASCADE'
,
null
,
true
);
$username
=
sprintf
(
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_DB_NAME_FORMAT
),
$name
);
return
$this
->
conn
->
query
(
'DROP USER '
.
$username
.
' CASCADE'
);
}
/**
* add an autoincrement sequence + trigger
...
...
@@ -91,7 +95,8 @@ class Doctrine_Export_Oracle extends Doctrine_Export {
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access private
*/
public
function
_makeAutoincrement
(
$name
,
$table
,
$start
=
1
)
{
public
function
_makeAutoincrement
(
$name
,
$table
,
$start
=
1
)
{
$table
=
strtoupper
(
$table
);
$index_name
=
$table
.
'_AI_PK'
;
$definition
=
array
(
...
...
@@ -102,27 +107,27 @@ class Doctrine_Export_Oracle extends Doctrine_Export {
/**
if (PEAR::isError($result)) {
return $
db
->raiseError($result, null, null,
return $
this->conn
->raiseError($result, null, null,
'primary key for autoincrement PK could not be created', __FUNCTION__);
}
*/
if
(
is_null
(
$start
))
{
$
db
->
beginTransaction
();
$query
=
'SELECT MAX('
.
$
db
->
quoteIdentifier
(
$name
,
true
)
.
') FROM '
.
$db
->
quoteIdentifier
(
$table
,
true
);
$
this
->
conn
->
beginTransaction
();
$query
=
'SELECT MAX('
.
$
this
->
conn
->
quoteIdentifier
(
$name
,
true
)
.
') FROM '
.
$this
->
conn
->
quoteIdentifier
(
$table
,
true
);
$start
=
$this
->
db
->
queryOne
(
$query
,
'integer'
);
if
(
PEAR
::
isError
(
$start
))
{
return
$start
;
}
++
$start
;
$result
=
$this
->
createSequence
(
$table
,
$start
);
$
db
->
commit
();
$
this
->
conn
->
commit
();
}
else
{
$result
=
$this
->
createSequence
(
$table
,
$start
);
}
/**
if (PEAR::isError($result)) {
return $
db
->raiseError($result, null, null,
return $
this->conn
->raiseError($result, null, null,
'sequence for autoincrement PK could not be created', __FUNCTION__);
}
*/
...
...
@@ -160,7 +165,8 @@ END;
* @param string $table name of the table
* @return void
*/
public
function
dropAutoincrement
(
$table
)
{
public
function
dropAutoincrement
(
$table
)
{
$table
=
strtoupper
(
$table
);
$trigger_name
=
$table
.
'_AI_PK'
;
$trigger_name_quoted
=
$this
->
conn
->
getDbh
()
->
quote
(
$trigger_name
);
...
...
@@ -169,7 +175,7 @@ END;
$trigger
=
$this
->
conn
->
fetchOne
(
$query
);
if
(
$trigger
)
{
$trigger_name
=
$
db
->
quoteIdentifier
(
$table
.
'_AI_PK'
,
true
);
$trigger_name
=
$
this
->
conn
->
quoteIdentifier
(
$table
.
'_AI_PK'
,
true
);
$trigger_sql
=
'DROP TRIGGER '
.
$trigger_name
;
// if throws exception, trigger for autoincrement PK could not be dropped
...
...
@@ -215,7 +221,8 @@ END;
*
* @return void
*/
public
function
createTable
(
$name
,
$fields
,
$options
=
array
())
{
public
function
createTable
(
$name
,
$fields
,
$options
=
array
())
{
$this
->
conn
->
beginTransaction
();
$result
=
parent
::
createTable
(
$name
,
$fields
,
$options
);
...
...
@@ -236,11 +243,12 @@ END;
* @param string $name name of the table that should be dropped
* @return void
*/
public
function
dropTable
(
$name
)
{
//$db->beginNestedTransaction();
public
function
dropTable
(
$name
)
{
//$this->conn->beginNestedTransaction();
$result
=
$this
->
dropAutoincrement
(
$name
);
$result
=
parent
::
dropTable
(
$name
);
//$
db
->completeNestedTransaction();
//$
this->conn
->completeNestedTransaction();
return
$result
;
}
/**
...
...
@@ -331,10 +339,11 @@ END;
* actually perform them otherwise.
* @return void
*/
public
function
alterTable
(
$name
,
array
$changes
,
$check
)
{
public
function
alterTable
(
$name
,
array
$changes
,
$check
)
{
foreach
(
$changes
as
$change
_n
ame
=>
$change
)
{
switch
(
$change
_n
ame
)
{
foreach
(
$changes
as
$change
N
ame
=>
$change
)
{
switch
(
$change
N
ame
)
{
case
'add'
:
case
'remove'
:
case
'change'
:
...
...
@@ -343,7 +352,7 @@ END;
break
;
default
:
return
$this
->
conn
->
raiseError
(
MDB2_ERROR_CANNOT_ALTER
,
null
,
null
,
'change type "'
.
$change
_n
ame
.
'" not yet supported'
,
__FUNCTION__
);
'change type "'
.
$change
N
ame
.
'" not yet supported'
,
__FUNCTION__
);
}
}
...
...
@@ -408,7 +417,7 @@ END;
/**
* create sequence
*
* @param object $
db
database object that is extended by this class
* @param object $
this->conn
database object that is extended by this class
* @param string $seqName name of the sequence to be created
* @param string $start start value of the sequence; default is 1
* @return void
...
...
@@ -422,7 +431,7 @@ END;
/**
* drop existing sequence
*
* @param object $
db
database object that is extended by this class
* @param object $
this->conn
database object that is extended by this class
* @param string $seqName name of the sequence to be dropped
* @return void
*/
...
...
tests/DataDict/MysqlTestCase.php
View file @
8110cf8e
...
...
@@ -76,6 +76,11 @@ class Doctrine_DataDict_Mysql_TestCase extends Doctrine_Driver_UnitTestCase {
$this
->
assertEqual
(
$this
->
dataDict
->
GetNativeDeclaration
(
$a
),
'TEXT'
);
}
public
function
testGetNativeDeclarationSupportsStringTypeWithLongLength
()
{
$a
=
array
(
'type'
=>
'string'
,
'length'
=>
2000
);
$this
->
assertEqual
(
$this
->
dataDict
->
GetNativeDeclaration
(
$a
),
'TEXT'
);
}
public
function
testGetNativeDeclarationSupportsArrayType2
()
{
$a
=
array
(
'type'
=>
'array'
);
...
...
tests/Export/PgsqlTestCase.php
View file @
8110cf8e
...
...
@@ -2,7 +2,6 @@
class
Doctrine_Export_Pgsql_TestCase
extends
Doctrine_UnitTestCase
{
public
function
testCreateDatabaseExecutesSql
()
{
$this
->
export
->
createDatabase
(
'db'
);
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
'CREATE DATABASE db'
);
}
public
function
testDropDatabaseExecutesSql
()
{
...
...
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