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
087de88f
Commit
087de88f
authored
Sep 03, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Case insensitive column names
parent
9046569d
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
145 additions
and
22 deletions
+145
-22
Connection.php
Doctrine/Connection.php
+1
-2
Hydrate.php
Doctrine/Hydrate.php
+5
-3
Record.php
Doctrine/Record.php
+20
-9
Table.php
Doctrine/Table.php
+6
-1
Exception.php
Doctrine/Table/Exception.php
+1
-1
RecordTestCase.php
tests/RecordTestCase.php
+43
-2
TableTestCase.php
tests/TableTestCase.php
+54
-2
classes.php
tests/classes.php
+12
-0
run.php
tests/run.php
+3
-2
No files found.
Doctrine/Connection.php
View file @
087de88f
...
@@ -833,7 +833,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
...
@@ -833,7 +833,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$strfields
=
join
(
", "
,
array_keys
(
$array
));
$strfields
=
join
(
", "
,
array_keys
(
$array
));
$strvalues
=
substr
(
str_repeat
(
"?, "
,
count
(
$array
)),
0
,
-
2
);
$strvalues
=
substr
(
str_repeat
(
"?, "
,
count
(
$array
)),
0
,
-
2
);
$sql
=
"INSERT INTO "
.
$record
->
getTable
()
->
getTableName
()
.
" ("
.
$strfields
.
") VALUES ("
.
$strvalues
.
")"
;
$sql
=
"INSERT INTO "
.
$record
->
getTable
()
->
getTableName
()
.
" ("
.
$strfields
.
") VALUES ("
.
$strvalues
.
")"
;
$stmt
=
$this
->
dbh
->
prepare
(
$sql
);
$stmt
=
$this
->
dbh
->
prepare
(
$sql
);
...
...
Doctrine/Hydrate.php
View file @
087de88f
...
@@ -314,7 +314,6 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
...
@@ -314,7 +314,6 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
if
(
empty
(
$row
))
if
(
empty
(
$row
))
continue
;
continue
;
$ids
=
$this
->
tables
[
$key
]
->
getIdentifier
();
$ids
=
$this
->
tables
[
$key
]
->
getIdentifier
();
$emptyID
=
false
;
$emptyID
=
false
;
...
@@ -517,8 +516,11 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
...
@@ -517,8 +516,11 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
foreach
(
$data
as
$key
=>
$value
)
:
foreach
(
$data
as
$key
=>
$value
)
:
$e
=
explode
(
"__"
,
$key
);
$e
=
explode
(
"__"
,
$key
);
$field
=
array_pop
(
$e
);
$field
=
strtolower
(
array_pop
(
$e
)
);
$component
=
implode
(
"__"
,
$e
);
$component
=
strtolower
(
implode
(
"__"
,
$e
)
);
$data
[
$component
][
$field
]
=
$value
;
$data
[
$component
][
$field
]
=
$value
;
unset
(
$data
[
$key
]);
unset
(
$data
[
$key
]);
...
...
Doctrine/Record.php
View file @
087de88f
...
@@ -259,7 +259,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -259,7 +259,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
foreach
(
$this
->
table
->
getColumnNames
()
as
$name
)
{
foreach
(
$this
->
table
->
getColumnNames
()
as
$name
)
{
$type
=
$this
->
table
->
getTypeOf
(
$name
);
$type
=
$this
->
table
->
getTypeOf
(
$name
);
if
(
!
isset
(
$tmp
[
$name
]))
{
$lower
=
strtolower
(
$name
);
if
(
!
isset
(
$tmp
[
$lower
]))
{
//if($type == 'array') {
//if($type == 'array') {
// $this->data[$name] = array();
// $this->data[$name] = array();
//} else
//} else
...
@@ -269,23 +271,23 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -269,23 +271,23 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
case
"array"
:
case
"array"
:
case
"object"
:
case
"object"
:
if
(
$tmp
[
$
name
]
!==
self
::
$null
)
{
if
(
$tmp
[
$
lower
]
!==
self
::
$null
)
{
if
(
is_string
(
$tmp
[
$
name
]))
{
if
(
is_string
(
$tmp
[
$
lower
]))
{
$value
=
unserialize
(
$tmp
[
$
name
]);
$value
=
unserialize
(
$tmp
[
$
lower
]);
if
(
$value
===
false
)
if
(
$value
===
false
)
throw
new
Doctrine_Record_Exception
(
"Unserialization of
$name
failed. "
.
var_dump
(
$tmp
[
$
name
],
true
));
throw
new
Doctrine_Record_Exception
(
"Unserialization of
$name
failed. "
.
var_dump
(
$tmp
[
$
lower
],
true
));
}
else
}
else
$value
=
$tmp
[
$
name
];
$value
=
$tmp
[
$
lower
];
$this
->
data
[
$name
]
=
$value
;
$this
->
data
[
$name
]
=
$value
;
}
}
break
;
break
;
case
"enum"
:
case
"enum"
:
$this
->
data
[
$name
]
=
$this
->
table
->
enumValue
(
$name
,
$tmp
[
$
name
]);
$this
->
data
[
$name
]
=
$this
->
table
->
enumValue
(
$name
,
$tmp
[
$
lower
]);
break
;
break
;
default
:
default
:
$this
->
data
[
$name
]
=
$tmp
[
$
name
];
$this
->
data
[
$name
]
=
$tmp
[
$
lower
];
endswitch
;
endswitch
;
$count
++
;
$count
++
;
}
}
...
@@ -468,6 +470,11 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -468,6 +470,11 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$query
=
$this
->
table
->
getQuery
()
.
" WHERE "
.
implode
(
" = ? AND "
,
$this
->
table
->
getPrimaryKeys
())
.
" = ?"
;
$query
=
$this
->
table
->
getQuery
()
.
" WHERE "
.
implode
(
" = ? AND "
,
$this
->
table
->
getPrimaryKeys
())
.
" = ?"
;
$this
->
data
=
$this
->
table
->
getConnection
()
->
execute
(
$query
,
$id
)
->
fetch
(
PDO
::
FETCH_ASSOC
);
$this
->
data
=
$this
->
table
->
getConnection
()
->
execute
(
$query
,
$id
)
->
fetch
(
PDO
::
FETCH_ASSOC
);
if
(
!
$this
->
data
)
throw
new
Doctrine_Record_Exception
(
'Failed to refresh. Record does not exist anymore'
);
$this
->
data
=
array_change_key_case
(
$this
->
data
,
CASE_LOWER
);
$this
->
modified
=
array
();
$this
->
modified
=
array
();
$this
->
cleanData
();
$this
->
cleanData
();
...
@@ -595,6 +602,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -595,6 +602,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* rawSet
* rawSet
* doctrine uses this function internally, not recommended for developers
* doctrine uses this function internally, not recommended for developers
*
*
* rawSet() works in very same same way as set() with an exception that
* 1. it cannot be used for setting references
* 2. it cannot load uninitialized fields
*
* @param mixed $name name of the property or reference
* @param mixed $name name of the property or reference
* @param mixed $value value of the property or reference
* @param mixed $value value of the property or reference
*/
*/
...
...
Doctrine/Table.php
View file @
087de88f
...
@@ -128,6 +128,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
...
@@ -128,6 +128,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
/**
/**
* the constructor
* the constructor
* @throws Doctrine_ManagerException if there are no opened connections
* @throws Doctrine_ManagerException if there are no opened connections
...
@@ -231,6 +232,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
...
@@ -231,6 +232,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
throw
new
Doctrine_Exception
(
"Class '
$name
' has no table definition."
);
throw
new
Doctrine_Exception
(
"Class '
$name
' has no table definition."
);
}
}
$record
->
setUp
();
$record
->
setUp
();
// save parents
// save parents
...
@@ -285,6 +287,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
...
@@ -285,6 +287,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
$this
->
primaryKeys
[]
=
$name
;
$this
->
primaryKeys
[]
=
$name
;
}
}
}
}
/**
/**
* @return mixed
* @return mixed
*/
*/
...
@@ -772,6 +775,8 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
...
@@ -772,6 +775,8 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
* @return Doctrine_Record
* @return Doctrine_Record
*/
*/
public
function
getRecord
()
{
public
function
getRecord
()
{
$this
->
data
=
array_change_key_case
(
$this
->
data
,
CASE_LOWER
);
$key
=
$this
->
getIdentifier
();
$key
=
$this
->
getIdentifier
();
if
(
!
is_array
(
$key
))
if
(
!
is_array
(
$key
))
...
...
Doctrine/Table/Exception.php
View file @
087de88f
...
@@ -7,7 +7,7 @@ Doctrine::autoload('Doctrine_Exception');
...
@@ -7,7 +7,7 @@ Doctrine::autoload('Doctrine_Exception');
class
Doctrine_Table_Exception
extends
Doctrine_Exception
{
class
Doctrine_Table_Exception
extends
Doctrine_Exception
{
public
function
__construct
()
{
public
function
__construct
()
{
parent
::
__construct
(
"Couldn't initialize table. One instance of this
parent
::
__construct
(
"Couldn't initialize table. One instance of this
tab
k
e already exists. Always use Doctrine_Session::getTable(
\$
name)
tab
l
e already exists. Always use Doctrine_Session::getTable(
\$
name)
to get on instance of a Doctrine_Table."
,
Doctrine
::
ERR_TABLE_INSTANCE
);
to get on instance of a Doctrine_Table."
,
Doctrine
::
ERR_TABLE_INSTANCE
);
}
}
}
}
...
...
tests/RecordTestCase.php
View file @
087de88f
...
@@ -2,11 +2,13 @@
...
@@ -2,11 +2,13 @@
require_once
(
"UnitTestCase.php"
);
require_once
(
"UnitTestCase.php"
);
class
Doctrine_RecordTestCase
extends
Doctrine_UnitTestCase
{
class
Doctrine_RecordTestCase
extends
Doctrine_UnitTestCase
{
public
function
prepareTables
()
{
public
function
prepareTables
()
{
$this
->
tables
[]
=
"enumTest"
;
$this
->
tables
[]
=
"enumTest"
;
parent
::
prepareTables
();
parent
::
prepareTables
();
}
}
public
function
testReferences2
()
{
public
function
testReferences2
()
{
$user
=
new
User
();
$user
=
new
User
();
$user
->
Phonenumber
[
0
]
->
phonenumber
=
'123 123'
;
$user
->
Phonenumber
[
0
]
->
phonenumber
=
'123 123'
;
...
@@ -138,7 +140,9 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
...
@@ -138,7 +140,9 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
}
}
public
function
testEnumType
()
{
public
function
testEnumType
()
{
$enum
=
new
EnumTest
();
$enum
=
new
EnumTest
();
$enum
->
status
=
"open"
;
$enum
->
status
=
"open"
;
$this
->
assertEqual
(
$enum
->
status
,
"open"
);
$this
->
assertEqual
(
$enum
->
status
,
"open"
);
...
@@ -158,6 +162,43 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
...
@@ -158,6 +162,43 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
$enum
->
status
,
"closed"
);
$this
->
assertEqual
(
$enum
->
status
,
"closed"
);
}
}
public
function
testEnumTypeWithCaseConversion
()
{
$this
->
dbh
->
setAttribute
(
PDO
::
ATTR_CASE
,
PDO
::
CASE_UPPER
);
$enum
=
new
EnumTest
();
$enum
->
status
=
"open"
;
$this
->
assertEqual
(
$enum
->
status
,
"open"
);
$enum
->
save
();
$this
->
assertEqual
(
$enum
->
status
,
"open"
);
$enum
->
refresh
();
$this
->
assertEqual
(
$enum
->
status
,
"open"
);
$enum
->
status
=
"closed"
;
$this
->
assertEqual
(
$enum
->
status
,
"closed"
);
$enum
->
save
();
$this
->
assertEqual
(
$enum
->
status
,
"closed"
);
$enum
->
refresh
();
$this
->
assertEqual
(
$enum
->
status
,
"closed"
);
}
public
function
testFailingRefresh
()
{
$enum
=
$this
->
connection
->
getTable
(
'EnumTest'
)
->
find
(
1
);
$this
->
dbh
->
query
(
'DELETE FROM enum_test WHERE id = 1'
);
$f
=
false
;
try
{
$enum
->
refresh
();
}
catch
(
Doctrine_Record_Exception
$e
)
{
$f
=
true
;
}
$this
->
assertTrue
(
$f
);
}
public
function
testSerialize
()
{
public
function
testSerialize
()
{
$user
=
$this
->
connection
->
getTable
(
"User"
)
->
find
(
4
);
$user
=
$this
->
connection
->
getTable
(
"User"
)
->
find
(
4
);
$str
=
serialize
(
$user
);
$str
=
serialize
(
$user
);
...
...
tests/TableTestCase.php
View file @
087de88f
<?php
<?php
require_once
(
"UnitTestCase.php"
);
require_once
(
"UnitTestCase.php"
);
class
Doctrine_TableTestCase
extends
Doctrine_UnitTestCase
{
class
Doctrine_TableTestCase
extends
Doctrine_UnitTestCase
{
public
function
prepareTables
()
{
$this
->
tables
[]
=
"FieldNameTest"
;
parent
::
prepareTables
();
}
public
function
testFieldConversion
()
{
$this
->
dbh
->
setAttribute
(
PDO
::
ATTR_CASE
,
PDO
::
CASE_UPPER
);
$user
=
$this
->
connection
->
getTable
(
'User'
)
->
find
(
5
);
$this
->
assertTrue
(
$user
instanceof
User
);
$t
=
new
FieldNameTest
();
$t
->
someColumn
=
'abc'
;
$t
->
someEnum
=
'php'
;
$t
->
someInt
=
1
;
$t
->
someArray
=
array
();
$obj
=
new
StdClass
();
$t
->
someObject
=
$obj
;
$this
->
assertEqual
(
$t
->
someColumn
,
'abc'
);
$this
->
assertEqual
(
$t
->
someEnum
,
'php'
);
$this
->
assertEqual
(
$t
->
someInt
,
1
);
$this
->
assertEqual
(
$t
->
someArray
,
array
());
$this
->
assertEqual
(
$t
->
someObject
,
$obj
);
$t
->
save
();
$this
->
assertEqual
(
$t
->
someColumn
,
'abc'
);
$this
->
assertEqual
(
$t
->
someEnum
,
'php'
);
$this
->
assertEqual
(
$t
->
someInt
,
1
);
$this
->
assertEqual
(
$t
->
someArray
,
array
());
$this
->
assertEqual
(
$t
->
someObject
,
$obj
);
$t
->
refresh
();
$this
->
assertEqual
(
$t
->
someColumn
,
'abc'
);
$this
->
assertEqual
(
$t
->
someEnum
,
'php'
);
$this
->
assertEqual
(
$t
->
someInt
,
1
);
$this
->
assertEqual
(
$t
->
someArray
,
array
());
$this
->
assertEqual
(
$t
->
someObject
,
$obj
);
$this
->
connection
->
clear
();
$t
=
$this
->
connection
->
getTable
(
'FieldNameTest'
)
->
find
(
1
);
$this
->
assertEqual
(
$t
->
someColumn
,
'abc'
);
$this
->
assertEqual
(
$t
->
someEnum
,
'php'
);
$this
->
assertEqual
(
$t
->
someInt
,
1
);
$this
->
assertEqual
(
$t
->
someArray
,
array
());
$this
->
assertEqual
(
$t
->
someObject
,
$obj
);
}
public
function
testBind
()
{
public
function
testBind
()
{
$table
=
$this
->
connection
->
getTable
(
"User"
);
$table
=
$this
->
connection
->
getTable
(
"User"
);
}
}
...
@@ -70,8 +122,8 @@ class Doctrine_TableTestCase extends Doctrine_UnitTestCase {
...
@@ -70,8 +122,8 @@ class Doctrine_TableTestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
$users
->
count
(),
8
);
$this
->
assertEqual
(
$users
->
count
(),
8
);
$this
->
assertTrue
(
$users
instanceof
Doctrine_Collection
);
$this
->
assertTrue
(
$users
instanceof
Doctrine_Collection
);
}
}
public
function
testFindBy
S
ql
()
{
public
function
testFindBy
D
ql
()
{
$users
=
$this
->
objTable
->
findBy
S
ql
(
"name LIKE '%Arnold%'"
);
$users
=
$this
->
objTable
->
findBy
D
ql
(
"name LIKE '%Arnold%'"
);
$this
->
assertEqual
(
$users
->
count
(),
1
);
$this
->
assertEqual
(
$users
->
count
(),
1
);
$this
->
assertTrue
(
$users
instanceof
Doctrine_Collection
);
$this
->
assertTrue
(
$users
instanceof
Doctrine_Collection
);
}
}
...
...
tests/classes.php
View file @
087de88f
...
@@ -17,6 +17,18 @@ class Entity extends Doctrine_Record {
...
@@ -17,6 +17,18 @@ class Entity extends Doctrine_Record {
$this
->
hasColumn
(
"email_id"
,
"integer"
);
$this
->
hasColumn
(
"email_id"
,
"integer"
);
}
}
}
}
class
FieldNameTest
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"someColumn"
,
"string"
,
200
);
$this
->
hasColumn
(
"someEnum"
,
"enum"
,
4
);
$this
->
hasColumn
(
"someArray"
,
"array"
,
100
);
$this
->
hasColumn
(
"someObject"
,
"array"
,
200
);
$this
->
hasColumn
(
"someInt"
,
"integer"
);
$this
->
setEnumValues
(
"someEnum"
,
array
(
'php'
,
'java'
,
'python'
));
}
}
class
EntityReference
extends
Doctrine_Record
{
class
EntityReference
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"entity1"
,
"integer"
);
$this
->
hasColumn
(
"entity1"
,
"integer"
);
...
...
tests/run.php
View file @
087de88f
...
@@ -32,12 +32,12 @@ error_reporting(E_ALL);
...
@@ -32,12 +32,12 @@ error_reporting(E_ALL);
$test
=
new
GroupTest
(
"Doctrine Framework Unit Tests"
);
$test
=
new
GroupTest
(
"Doctrine Framework Unit Tests"
);
$test
->
addTestCase
(
new
Doctrine_TableTestCase
());
$test
->
addTestCase
(
new
Doctrine_RecordTestCase
());
$test
->
addTestCase
(
new
Doctrine_RecordTestCase
());
$test
->
addTestCase
(
new
Doctrine_ConnectionTestCase
());
$test
->
addTestCase
(
new
Doctrine_ConnectionTestCase
());
$test
->
addTestCase
(
new
Doctrine_TableTestCase
());
$test
->
addTestCase
(
new
Doctrine_ManagerTestCase
());
$test
->
addTestCase
(
new
Doctrine_ManagerTestCase
());
$test
->
addTestCase
(
new
Doctrine_AccessTestCase
());
$test
->
addTestCase
(
new
Doctrine_AccessTestCase
());
...
@@ -75,6 +75,7 @@ $test->addTestCase(new Doctrine_SchemaTestCase());
...
@@ -75,6 +75,7 @@ $test->addTestCase(new Doctrine_SchemaTestCase());
$test
->
addTestCase
(
new
Doctrine_ImportTestCase
());
$test
->
addTestCase
(
new
Doctrine_ImportTestCase
());
$test
->
addTestCase
(
new
Doctrine_CollectionTestCase
());
$test
->
addTestCase
(
new
Doctrine_CollectionTestCase
());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
...
...
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