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
dea79e7b
Commit
dea79e7b
authored
Oct 23, 2011
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DDC-217 - More tests and fixes for some edge cases
parent
3932a5a7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
31 deletions
+47
-31
ResultCacheStatement.php
lib/Doctrine/DBAL/Cache/ResultCacheStatement.php
+10
-1
Connection.php
lib/Doctrine/DBAL/Connection.php
+2
-0
ResultCacheTest.php
tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php
+35
-30
No files found.
lib/Doctrine/DBAL/Cache/ResultCacheStatement.php
View file @
dea79e7b
...
@@ -73,6 +73,11 @@ class ResultCacheStatement implements ResultStatement
...
@@ -73,6 +73,11 @@ class ResultCacheStatement implements ResultStatement
*/
*/
private
$emptied
=
false
;
private
$emptied
=
false
;
/**
* @var array
*/
private
$data
;
/**
/**
* @param Statement $stmt
* @param Statement $stmt
* @param Cache $resultCache
* @param Cache $resultCache
...
@@ -97,7 +102,7 @@ class ResultCacheStatement implements ResultStatement
...
@@ -97,7 +102,7 @@ class ResultCacheStatement implements ResultStatement
public
function
closeCursor
()
public
function
closeCursor
()
{
{
$this
->
statement
->
closeCursor
();
$this
->
statement
->
closeCursor
();
if
(
$this
->
emptied
&&
$this
->
data
)
{
if
(
$this
->
emptied
&&
$this
->
data
!==
null
)
{
$data
=
$this
->
resultCache
->
fetch
(
$this
->
cacheKey
);
$data
=
$this
->
resultCache
->
fetch
(
$this
->
cacheKey
);
if
(
!
$data
)
{
if
(
!
$data
)
{
$data
=
array
();
$data
=
array
();
...
@@ -151,6 +156,10 @@ class ResultCacheStatement implements ResultStatement
...
@@ -151,6 +156,10 @@ class ResultCacheStatement implements ResultStatement
*/
*/
public
function
fetch
(
$fetchStyle
=
PDO
::
FETCH_BOTH
)
public
function
fetch
(
$fetchStyle
=
PDO
::
FETCH_BOTH
)
{
{
if
(
$this
->
data
===
null
)
{
$this
->
data
=
array
();
}
$row
=
$this
->
statement
->
fetch
(
PDO
::
FETCH_ASSOC
);
$row
=
$this
->
statement
->
fetch
(
PDO
::
FETCH_ASSOC
);
if
(
$row
)
{
if
(
$row
)
{
$this
->
data
[]
=
$row
;
$this
->
data
[]
=
$row
;
...
...
lib/Doctrine/DBAL/Connection.php
View file @
dea79e7b
...
@@ -659,6 +659,8 @@ class Connection implements DriverConnection
...
@@ -659,6 +659,8 @@ class Connection implements DriverConnection
// is the real key part of this row pointers map or is the cache only pointing to other cache keys?
// is the real key part of this row pointers map or is the cache only pointing to other cache keys?
if
(
isset
(
$data
[
$realKey
]))
{
if
(
isset
(
$data
[
$realKey
]))
{
return
new
ArrayStatement
(
$data
[
$realKey
]);
return
new
ArrayStatement
(
$data
[
$realKey
]);
}
else
if
(
array_key_exists
(
$realKey
,
$data
))
{
return
new
ArrayStatement
(
array
());
}
}
}
}
return
new
ResultCacheStatement
(
$this
->
executeQuery
(
$query
,
$params
,
$types
),
$resultCache
,
$cacheKey
,
$realKey
,
$qcp
->
getLifetime
());
return
new
ResultCacheStatement
(
$this
->
executeQuery
(
$query
,
$params
,
$types
),
$resultCache
,
$cacheKey
,
$realKey
,
$qcp
->
getLifetime
());
...
...
tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php
View file @
dea79e7b
...
@@ -73,21 +73,13 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
...
@@ -73,21 +73,13 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
}
}
$stmt
=
$this
->
_conn
->
executeQuery
(
"SELECT * FROM caching"
,
array
(),
array
(),
new
QueryCacheProfile
(
10
,
"testcachekey"
));
$stmt
=
$this
->
_conn
->
executeQuery
(
"SELECT * FROM caching"
,
array
(),
array
(),
new
QueryCacheProfile
(
10
,
"testcachekey"
));
$data
=
array
();
$data
=
$this
->
hydrateStmt
(
$stmt
,
\PDO
::
FETCH_ASSOC
);
while
(
$row
=
$stmt
->
fetch
(
\PDO
::
FETCH_ASSOC
))
{
$data
[]
=
$row
;
}
$stmt
->
closeCursor
();
$this
->
assertEquals
(
$this
->
expectedResult
,
$data
);
$this
->
assertEquals
(
$this
->
expectedResult
,
$data
);
$stmt
=
$this
->
_conn
->
executeQuery
(
"SELECT * FROM caching"
,
array
(),
array
(),
new
QueryCacheProfile
(
10
,
"testcachekey"
));
$stmt
=
$this
->
_conn
->
executeQuery
(
"SELECT * FROM caching"
,
array
(),
array
(),
new
QueryCacheProfile
(
10
,
"testcachekey"
));
$data
=
array
();
$data
=
$this
->
hydrateStmt
(
$stmt
,
\PDO
::
FETCH_NUM
);
while
(
$row
=
$stmt
->
fetch
(
\PDO
::
FETCH_NUM
))
{
$data
[]
=
$row
;
}
$stmt
->
closeCursor
();
$this
->
assertEquals
(
$numExpectedResult
,
$data
);
$this
->
assertEquals
(
$numExpectedResult
,
$data
);
}
}
...
@@ -120,45 +112,58 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
...
@@ -120,45 +112,58 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
$stmt
=
$this
->
_conn
->
executeQuery
(
"SELECT * FROM caching"
,
array
(),
array
(),
new
QueryCacheProfile
(
10
,
"testcachekey"
));
$stmt
=
$this
->
_conn
->
executeQuery
(
"SELECT * FROM caching"
,
array
(),
array
(),
new
QueryCacheProfile
(
10
,
"testcachekey"
));
$data
=
array
();
$data
=
$this
->
hydrateStmt
(
$stmt
,
\PDO
::
FETCH_NUM
);
while
(
$row
=
$stmt
->
fetch
(
\PDO
::
FETCH_NUM
))
{
$data
[]
=
$row
;
}
$stmt
->
closeCursor
();
$this
->
assertEquals
(
2
,
count
(
$this
->
sqlLogger
->
queries
));
$this
->
assertEquals
(
2
,
count
(
$this
->
sqlLogger
->
queries
));
}
}
public
function
assertCacheNonCacheSelectSameFetchModeAreEqual
(
$expectedResult
,
$fetchStyle
)
public
function
assertCacheNonCacheSelectSameFetchModeAreEqual
(
$expectedResult
,
$fetchStyle
)
{
{
$s
=
microtime
(
true
);
$stmt
=
$this
->
_conn
->
executeQuery
(
"SELECT * FROM caching"
,
array
(),
array
(),
new
QueryCacheProfile
(
10
,
"testcachekey"
));
$stmt
=
$this
->
_conn
->
executeQuery
(
"SELECT * FROM caching"
,
array
(),
array
(),
new
QueryCacheProfile
(
10
,
"testcachekey"
));
$this
->
assertEquals
(
2
,
$stmt
->
columnCount
());
$this
->
assertEquals
(
2
,
$stmt
->
columnCount
());
$data
=
$this
->
hydrateStmt
(
$stmt
,
$fetchStyle
);
$data
=
array
();
while
(
$row
=
$stmt
->
fetch
(
$fetchStyle
))
{
$data
[]
=
$row
;
}
$stmt
->
closeCursor
();
#echo number_format(microtime(true)-$s, 6)."\n";
$this
->
assertEquals
(
$expectedResult
,
$data
);
$this
->
assertEquals
(
$expectedResult
,
$data
);
$s
=
microtime
(
true
);
$stmt
=
$this
->
_conn
->
executeQuery
(
"SELECT * FROM caching"
,
array
(),
array
(),
new
QueryCacheProfile
(
10
,
"testcachekey"
));
$stmt
=
$this
->
_conn
->
executeQuery
(
"SELECT * FROM caching"
,
array
(),
array
(),
new
QueryCacheProfile
(
10
,
"testcachekey"
));
$this
->
assertEquals
(
2
,
$stmt
->
columnCount
());
$this
->
assertEquals
(
2
,
$stmt
->
columnCount
());
$data
=
$this
->
hydrateStmt
(
$stmt
,
$fetchStyle
);
$this
->
assertEquals
(
$expectedResult
,
$data
);
$this
->
assertEquals
(
1
,
count
(
$this
->
sqlLogger
->
queries
),
"just one dbal hit"
);
}
public
function
testEmptyResultCache
()
{
$stmt
=
$this
->
_conn
->
executeQuery
(
"SELECT * FROM caching WHERE test_int > 500"
,
array
(),
array
(),
new
QueryCacheProfile
(
10
,
"emptycachekey"
));
$data
=
$this
->
hydrateStmt
(
$stmt
);
$stmt
=
$this
->
_conn
->
executeQuery
(
"SELECT * FROM caching WHERE test_int > 500"
,
array
(),
array
(),
new
QueryCacheProfile
(
10
,
"emptycachekey"
));
$data
=
$this
->
hydrateStmt
(
$stmt
);
$this
->
assertEquals
(
1
,
count
(
$this
->
sqlLogger
->
queries
),
"just one dbal hit"
);
}
public
function
testChangeCacheImpl
()
{
$stmt
=
$this
->
_conn
->
executeQuery
(
"SELECT * FROM caching WHERE test_int > 500"
,
array
(),
array
(),
new
QueryCacheProfile
(
10
,
"emptycachekey"
));
$data
=
$this
->
hydrateStmt
(
$stmt
);
$secondCache
=
new
\Doctrine\Common\Cache\ArrayCache
;
$stmt
=
$this
->
_conn
->
executeQuery
(
"SELECT * FROM caching WHERE test_int > 500"
,
array
(),
array
(),
new
QueryCacheProfile
(
10
,
"emptycachekey"
,
$secondCache
));
$data
=
$this
->
hydrateStmt
(
$stmt
);
$this
->
assertEquals
(
2
,
count
(
$this
->
sqlLogger
->
queries
),
"two hits"
);
$this
->
assertEquals
(
1
,
count
(
$secondCache
->
fetch
(
"emptycachekey"
)));
}
private
function
hydrateStmt
(
$stmt
,
$fetchStyle
=
\PDO
::
FETCH_ASSOC
)
{
$data
=
array
();
$data
=
array
();
while
(
$row
=
$stmt
->
fetch
(
$fetchStyle
))
{
while
(
$row
=
$stmt
->
fetch
(
$fetchStyle
))
{
$data
[]
=
$row
;
$data
[]
=
$row
;
}
}
$stmt
->
closeCursor
();
$stmt
->
closeCursor
();
#echo number_format(microtime(true)-$s, 6)."\n";
return
$data
;
$this
->
assertEquals
(
$expectedResult
,
$data
);
$this
->
assertEquals
(
1
,
count
(
$this
->
sqlLogger
->
queries
),
"just one dbal hit"
);
}
}
}
}
\ No newline at end of file
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