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
a0beed0a
Commit
a0beed0a
authored
May 10, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
ac34484c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
33 deletions
+95
-33
Hydrate.php
draft/new-core/Hydrate.php
+63
-30
NewCoreTestCase.php
tests/NewCoreTestCase.php
+32
-3
No files found.
draft/new-core/Hydrate.php
View file @
a0beed0a
...
...
@@ -32,7 +32,7 @@ Doctrine::autoload('Doctrine_Access');
* @version $Revision: 1255 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
abstract
class
Doctrine_Hydrate2
extends
Doctrine_Access
class
Doctrine_Hydrate2
extends
Doctrine_Access
{
/**
* QUERY TYPE CONSTANTS
...
...
@@ -177,12 +177,6 @@ abstract class Doctrine_Hydrate2 extends Doctrine_Access
return
$obj
;
}
/**
* getQuery
*
* @return string
*/
abstract
public
function
getQuery
();
/**
* limitSubqueryUsed
*
...
...
@@ -284,13 +278,12 @@ abstract class Doctrine_Hydrate2 extends Doctrine_Access
$this
->
params
=
$params
;
}
/**
*
execute
*
executes the dql query and populates all collections
*
_fetch
*
*
* @param string $params
* @return Doctrine_Collection the root collection
*/
public
function
execute
(
$params
=
array
(),
$return
=
Doctrine
::
FETCH_RECORD
)
{
public
function
_fetch
(
$params
=
array
(),
$return
=
Doctrine
::
FETCH_RECORD
)
{
$params
=
$this
->
conn
->
convertBooleans
(
array_merge
(
$this
->
params
,
$params
));
if
(
!
$this
->
view
)
{
...
...
@@ -306,28 +299,68 @@ abstract class Doctrine_Hydrate2 extends Doctrine_Access
}
$stmt
=
$this
->
conn
->
execute
(
$query
,
$params
);
if
(
count
(
$this
->
tables
)
==
0
)
{
throw
new
Doctrine_Query_Exception
(
'No components selected'
);
}
$keys
=
array_keys
(
$this
->
tables
);
$root
=
$keys
[
0
];
$previd
=
array
();
return
$this
->
parseData
(
$stmt
);
}
public
function
setAliasMap
(
$map
)
{
$this
->
_aliasMap
=
$map
;
}
public
function
getAliasMap
()
{
return
$this
->
_aliasMap
;
}
/**
* execute
* executes the dql query and populates all collections
*
* @param string $params
* @return Doctrine_Collection the root collection
*/
public
function
execute
(
$params
=
array
(),
$return
=
Doctrine
::
FETCH_RECORD
)
{
$array
=
$this
->
_fetch
(
$params
=
array
(),
$return
=
Doctrine
::
FETCH_RECORD
);
$coll
=
$this
->
getCollection
(
$root
);
$coll
=
new
Doctrine_Collection
(
key
(
$this
->
_aliasMap
)
);
$prev
[
$root
]
=
$coll
;
if
(
$this
->
aggregate
)
{
$return
=
Doctrine
::
FETCH_ARRAY
;
$previd
=
array
();
/**
* iterate over the fetched data
* here $data is a two dimensional array
*/
foreach
(
$array
as
$data
)
{
/**
* remove duplicated data rows and map data into objects
*/
foreach
(
$data
as
$key
=>
$row
)
{
if
(
empty
(
$row
))
{
continue
;
}
}
}
}
/**
* execute
* executes the dql query and populates all collections
*
* @param string $params
* @return Doctrine_Collection the root collection
*/
public
function
execute2
(
$params
=
array
(),
$return
=
Doctrine
::
FETCH_RECORD
)
{
$array
=
$this
->
_fetch
(
$params
=
array
(),
$return
=
Doctrine
::
FETCH_RECORD
);
$array
=
$this
->
parseData
(
$stmt
);
if
(
$return
==
Doctrine
::
FETCH_ARRAY
)
{
return
$array
;
}
$keys
=
array_keys
(
$this
->
tables
);
$root
=
$keys
[
0
];
$previd
=
array
();
/**
* iterate over the fetched data
* here $data is a two dimensional array
*/
foreach
(
$array
as
$data
)
{
/**
* remove duplicated data rows and map data into objects
...
...
@@ -628,10 +661,10 @@ abstract class Doctrine_Hydrate2 extends Doctrine_Access
foreach
(
$data
as
$key
=>
$value
)
{
$e
=
explode
(
'__'
,
$key
);
$field
=
strtolower
(
array_pop
(
$e
));
$
component
=
strtolower
(
implode
(
'__'
,
$e
));
$field
=
strtolower
(
array_pop
(
$e
));
$
tableAlias
=
strtolower
(
implode
(
'__'
,
$e
));
$data
[
$
component
][
$field
]
=
$value
;
$data
[
$
tableAlias
][
$field
]
=
$value
;
unset
(
$data
[
$key
]);
}
...
...
tests/NewCoreTestCase.php
View file @
a0beed0a
...
...
@@ -22,7 +22,7 @@
require_once
(
'../draft/new-core/Record.php'
);
require_once
(
'../draft/new-core/Hydrate.php'
);
require_once
(
'../draft/new-core/Query.php'
);
require_once
(
'../draft/new-core/Query.php'
);
require_once
(
'../draft/new-core/Collection.php'
);
/**
...
...
@@ -42,7 +42,36 @@ class Doctrine_NewCore_TestCase extends Doctrine_UnitTestCase
{
public
function
testHydrate
()
{
$q
=
new
Doctrine_Query2
();
$q
->
from
(
'User u LEFT JOIN u.Phonenumber p'
)
->
execute
();
$h
=
new
Doctrine_Hydrate_Mock
();
$h
->
setData
(
array
(
array
(
'e'
=>
array
(
'id'
=>
1
,
'name'
=>
'zYne'
),
'p'
=>
array
(
'id'
=>
1
,
'phonenumber'
=>
'123 123'
,
'user_id'
=>
1
)
),
array
(
'e'
=>
array
(
'id'
=>
2
,
'name'
=>
'John'
),
'p'
=>
array
(
'id'
=>
2
,
'phonenumber'
=>
'222 222'
,
'user_id'
=>
2
)
),
array
(
'e'
=>
array
(
'id'
=>
3
,
'name'
=>
'Arnold'
),
'p'
=>
array
(
'id'
=>
3
,
'phonenumber'
=>
'333 333'
,
'user_id'
=>
3
)
)
)
);
$h
->
setAliasMap
(
array
(
'u'
=>
array
(
'table'
=>
$this
->
conn
->
getTable
(
'User'
))));
}
}
class
Doctrine_Hydrate_Mock
extends
Doctrine_Hydrate2
{
protected
$data
;
public
function
setData
(
$data
)
{
$this
->
data
=
$data
;
}
public
function
_fetch
(
$params
=
array
(),
$return
=
Doctrine
::
FETCH_RECORD
)
{
return
$this
->
data
;
}
}
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