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
fef149dd
Commit
fef149dd
authored
Nov 07, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Doctrine_Db_* updates
parent
21cde0e7
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
352 additions
and
304 deletions
+352
-304
DB.php
draft/DB.php
+34
-16
Oracle.php
lib/Doctrine/DataDict/Oracle.php
+2
-2
Pgsql.php
lib/Doctrine/DataDict/Pgsql.php
+2
-0
Event.php
lib/Doctrine/Db/Event.php
+83
-0
EventListener.php
lib/Doctrine/Db/EventListener.php
+14
-14
Chain.php
lib/Doctrine/Db/EventListener/Chain.php
+6
-6
Interface.php
lib/Doctrine/Db/EventListener/Interface.php
+14
-14
Profiler.php
lib/Doctrine/Db/Profiler.php
+43
-204
Exception.php
lib/Doctrine/Db/Profiler/Exception.php
+29
-0
Query.php
lib/Doctrine/Db/Profiler/Query.php
+9
-6
Statement.php
lib/Doctrine/Db/Statement.php
+24
-7
DbProfilerTestCase.php
tests/DbProfilerTestCase.php
+86
-30
run.php
tests/run.php
+6
-5
No files found.
draft/DB.php
View file @
fef149dd
...
@@ -37,12 +37,12 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
...
@@ -37,12 +37,12 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
/**
/**
* Any general database query that does not fit into the other constants.
* Any general database query that does not fit into the other constants.
*/
*/
const
QUERY
=
2
;
const
QUERY
=
2
;
/**
/**
* Adding new data to the database, such as SQL's INSERT.
* Adding new data to the database, such as SQL's INSERT.
*/
*/
const
INSERT
=
4
;
const
INSERT
=
4
;
/**
/**
* Updating existing information in the database, such as SQL's UPDATE.
* Updating existing information in the database, such as SQL's UPDATE.
...
@@ -123,6 +123,10 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
...
@@ -123,6 +123,10 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
$this
->
listener
=
new
Doctrine_DB_EventListener
();
$this
->
listener
=
new
Doctrine_DB_EventListener
();
}
}
public
function
nextQuerySequence
()
{
return
++
$this
->
querySequence
;
}
/**
/**
* getQuerySequence
* getQuerySequence
*/
*/
...
@@ -351,13 +355,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
...
@@ -351,13 +355,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
public
function
prepare
(
$statement
)
{
public
function
prepare
(
$statement
)
{
$this
->
connect
();
$this
->
connect
();
$
args
=
func_get_args
(
);
$
event
=
new
Doctrine_Db_Event
(
$this
,
Doctrine_Db_Event
::
PREPARE
,
$statement
);
$this
->
listener
->
onPrePrepare
(
$
this
,
$statement
,
$args
);
$this
->
listener
->
onPrePrepare
(
$
event
);
$stmt
=
$this
->
dbh
->
prepare
(
$statement
);
$stmt
=
$this
->
dbh
->
prepare
(
$statement
);
$this
->
listener
->
onPrepare
(
$
this
,
$statement
,
$args
,
$this
->
querySequence
);
$this
->
listener
->
onPrepare
(
$
event
);
$this
->
querySequence
++
;
$this
->
querySequence
++
;
...
@@ -372,15 +376,17 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
...
@@ -372,15 +376,17 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
*/
*/
public
function
query
(
$statement
,
array
$params
=
array
())
{
public
function
query
(
$statement
,
array
$params
=
array
())
{
$this
->
connect
();
$this
->
connect
();
$this
->
listener
->
onPreQuery
(
$this
,
$statement
,
$params
);
if
(
!
empty
(
$params
))
$event
=
new
Doctrine_Db_Event
(
$this
,
Doctrine_Db_Event
::
QUERY
,
$statement
);
$this
->
listener
->
onPreQuery
(
$event
);
if
(
!
empty
(
$params
))
$stmt
=
$this
->
dbh
->
query
(
$statement
)
->
execute
(
$params
);
$stmt
=
$this
->
dbh
->
query
(
$statement
)
->
execute
(
$params
);
else
else
$stmt
=
$this
->
dbh
->
query
(
$statement
);
$stmt
=
$this
->
dbh
->
query
(
$statement
);
$this
->
listener
->
onQuery
(
$
this
,
$statement
,
$params
,
$this
->
querySequence
);
$this
->
listener
->
onQuery
(
$
event
);
$this
->
querySequence
++
;
$this
->
querySequence
++
;
...
@@ -409,12 +415,14 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
...
@@ -409,12 +415,14 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
$this
->
connect
();
$this
->
connect
();
$args
=
func_get_args
();
$args
=
func_get_args
();
$event
=
new
Doctrine_Db_Event
(
$this
,
Doctrine_Db_Event
::
EXEC
,
$statement
);
$this
->
listener
->
onPreExec
(
$
this
,
$statement
,
$args
);
$this
->
listener
->
onPreExec
(
$
event
);
$rows
=
$this
->
dbh
->
exec
(
$statement
);
$rows
=
$this
->
dbh
->
exec
(
$statement
);
$this
->
listener
->
onExec
(
$
this
,
$statement
,
$args
);
$this
->
listener
->
onExec
(
$
event
);
return
$rows
;
return
$rows
;
}
}
...
@@ -463,11 +471,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
...
@@ -463,11 +471,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
* @return boolean
* @return boolean
*/
*/
public
function
beginTransaction
()
{
public
function
beginTransaction
()
{
$this
->
listener
->
onPreBeginTransaction
(
$this
);
$event
=
new
Doctrine_Db_Event
(
$this
,
Doctrine_Db_Event
::
BEGIN
);
$this
->
listener
->
onPreBeginTransaction
(
$event
);
$return
=
$this
->
dbh
->
beginTransaction
();
$return
=
$this
->
dbh
->
beginTransaction
();
$this
->
listener
->
onBeginTransaction
(
$
this
);
$this
->
listener
->
onBeginTransaction
(
$
event
);
return
$return
;
return
$return
;
}
}
...
@@ -477,11 +487,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
...
@@ -477,11 +487,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
* @return boolean
* @return boolean
*/
*/
public
function
commit
()
{
public
function
commit
()
{
$this
->
listener
->
onPreCommit
(
$this
);
$event
=
new
Doctrine_Db_Event
(
$this
,
Doctrine_Db_Event
::
COMMIT
);
$this
->
listener
->
onPreCommit
(
$event
);
$return
=
$this
->
dbh
->
commit
();
$return
=
$this
->
dbh
->
commit
();
$this
->
listener
->
onCommit
(
$
this
);
$this
->
listener
->
onCommit
(
$
event
);
return
$return
;
return
$return
;
}
}
...
@@ -492,8 +504,14 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
...
@@ -492,8 +504,14 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
*/
*/
public
function
rollBack
()
{
public
function
rollBack
()
{
$this
->
connect
();
$this
->
connect
();
$event
=
new
Doctrine_Db_Event
(
$this
,
Doctrine_Db_Event
::
ROLLBACK
);
$this
->
listener
->
onPreRollback
(
$event
);
$this
->
dbh
->
rollBack
();
$this
->
dbh
->
rollBack
();
$this
->
listener
->
onRollback
(
$event
);
}
}
/**
/**
* getAttribute
* getAttribute
...
...
lib/Doctrine/DataDict/Oracle.php
View file @
fef149dd
...
@@ -82,14 +82,14 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict {
...
@@ -82,14 +82,14 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict {
}
}
}
}
/**
/**
* Maps a native array description of a field to a
MDB2
datatype and length
* Maps a native array description of a field to a
doctrine
datatype and length
*
*
* @param array $field native field description
* @param array $field native field description
* @return array containing the various possible types, length, sign, fixed
* @return array containing the various possible types, length, sign, fixed
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @throws Doctrine_DataDict_Oracle_Exception
* @throws Doctrine_DataDict_Oracle_Exception
*/
*/
function
mapNativeDatatype
(
$field
)
{
public
function
mapNativeDatatype
(
array
$field
)
{
$db_type
=
strtolower
(
$field
[
'type'
]);
$db_type
=
strtolower
(
$field
[
'type'
]);
$type
=
array
();
$type
=
array
();
$length
=
$unsigned
=
$fixed
=
null
;
$length
=
$unsigned
=
$fixed
=
null
;
...
...
lib/Doctrine/DataDict/Pgsql.php
View file @
fef149dd
...
@@ -58,6 +58,8 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict {
...
@@ -58,6 +58,8 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict {
case
'string'
:
case
'string'
:
case
'array'
:
case
'array'
:
case
'object'
:
case
'object'
:
case
'varchar'
:
case
'char'
:
$length
=
!
empty
(
$field
[
'length'
])
$length
=
!
empty
(
$field
[
'length'
])
?
$field
[
'length'
]
:
$db
->
options
[
'default_text_field_length'
];
?
$field
[
'length'
]
:
$db
->
options
[
'default_text_field_length'
];
...
...
lib/Doctrine/Db/Event.php
0 → 100644
View file @
fef149dd
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Db_Event
*
* @author Konsta Vesterinen
* @license LGPL
* @package Doctrine
*/
class
Doctrine_Db_Event
{
const
QUERY
=
1
;
const
EXEC
=
2
;
const
EXECUTE
=
4
;
const
PREPARE
=
8
;
const
BEGIN
=
16
;
const
COMMIT
=
32
;
const
ROLLBACK
=
64
;
protected
$invoker
;
protected
$query
;
protected
$type
;
protected
$startedMicrotime
;
protected
$endedMicrotime
;
public
function
__construct
(
$invoker
,
$type
,
$query
=
null
)
{
$this
->
invoker
=
$invoker
;
$this
->
type
=
$type
;
$this
->
query
=
$query
;
}
public
function
getQuery
()
{
return
$this
->
query
;
}
public
function
getType
()
{
return
$this
->
type
;
}
public
function
start
()
{
$this
->
startedMicrotime
=
microtime
(
true
);
}
public
function
hasEnded
()
{
return
(
$this
->
endedMicrotime
!=
null
);
}
public
function
end
()
{
$this
->
endedMicrotime
=
microtime
(
true
);
}
public
function
getInvoker
()
{
return
$this
->
invoker
;
}
/**
* Get the elapsed time (in seconds) that the query ran. If the query has
* not yet ended, return false.
*
* @return mixed
*/
public
function
getElapsedSecs
()
{
if
(
is_null
(
$this
->
endedMicrotime
))
return
false
;
return
(
$this
->
endedMicrotime
-
$this
->
startedMicrotime
);
}
}
lib/Doctrine/Db/EventListener.php
View file @
fef149dd
...
@@ -26,24 +26,24 @@
...
@@ -26,24 +26,24 @@
* @package Doctrine
* @package Doctrine
*/
*/
class
Doctrine_Db_EventListener
implements
Doctrine_Db_EventListener_Interface
{
class
Doctrine_Db_EventListener
implements
Doctrine_Db_EventListener_Interface
{
public
function
onPreQuery
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
)
{
}
public
function
onPreQuery
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onQuery
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
,
$queryId
)
{
}
public
function
onQuery
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onPrePrepare
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
)
{
}
public
function
onPrePrepare
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onPrepare
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
,
$queryId
)
{
}
public
function
onPrepare
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onPreCommit
(
Doctrine_D
B2
$dbh
)
{
}
public
function
onPreCommit
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onCommit
(
Doctrine_D
B2
$dbh
)
{
}
public
function
onCommit
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onPreExec
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
)
{
}
public
function
onPreExec
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onExec
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
)
{
}
public
function
onExec
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onPreRollBack
(
Doctrine_D
B2
$dbh
)
{
}
public
function
onPreRollBack
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onRollBack
(
Doctrine_D
B2
$dbh
)
{
}
public
function
onRollBack
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onPreBeginTransaction
(
Doctrine_D
B2
$dbh
)
{
}
public
function
onPreBeginTransaction
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onBeginTransaction
(
Doctrine_D
B2
$dbh
)
{
}
public
function
onBeginTransaction
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onPreExecute
(
Doctrine_Db_
Statement
$stmt
,
array
$params
)
{
}
public
function
onPreExecute
(
Doctrine_Db_
Event
$event
)
{
}
public
function
onExecute
(
Doctrine_Db_
Statement
$stmt
,
array
$params
)
{
}
public
function
onExecute
(
Doctrine_Db_
Event
$event
)
{
}
}
}
lib/Doctrine/Db/EventListener/Chain.php
View file @
fef149dd
...
@@ -56,32 +56,32 @@ class Doctrine_Db_EventListener_Chain extends Doctrine_Access implements Doctrin
...
@@ -56,32 +56,32 @@ class Doctrine_Db_EventListener_Chain extends Doctrine_Access implements Doctrin
public
function
onQuery
(
Doctrine_DB2
$dbh
,
$statement
,
array
$args
,
$queryId
)
{
public
function
onQuery
(
Doctrine_DB2
$dbh
,
$statement
,
array
$args
,
$queryId
)
{
foreach
(
$this
->
listeners
as
$listener
)
{
foreach
(
$this
->
listeners
as
$listener
)
{
$listener
->
on
Pre
Query
(
$dbh
,
$args
);
$listener
->
onQuery
(
$dbh
,
$args
);
}
}
}
}
public
function
onPreQuery
(
Doctrine_DB2
$dbh
,
$statement
,
array
$args
)
{
public
function
onPreQuery
(
Doctrine_DB2
$dbh
,
$statement
,
array
$args
)
{
foreach
(
$this
->
listeners
as
$listener
)
{
foreach
(
$this
->
listeners
as
$listener
)
{
$listener
->
onQuery
(
$dbh
,
$args
);
$listener
->
on
Pre
Query
(
$dbh
,
$args
);
}
}
}
}
public
function
onPreExec
(
Doctrine_DB2
$dbh
,
array
$args
)
{
public
function
onPreExec
(
Doctrine_DB2
$dbh
,
$statement
,
array
$args
)
{
foreach
(
$this
->
listeners
as
$listener
)
{
foreach
(
$this
->
listeners
as
$listener
)
{
$listener
->
onPreExec
(
$dbh
,
$args
);
$listener
->
onPreExec
(
$dbh
,
$args
);
}
}
}
}
public
function
onExec
(
Doctrine_DB2
$dbh
,
array
$args
)
{
public
function
onExec
(
Doctrine_DB2
$dbh
,
$statement
,
array
$args
)
{
foreach
(
$this
->
listeners
as
$listener
)
{
foreach
(
$this
->
listeners
as
$listener
)
{
$listener
->
onExec
(
$dbh
,
$args
);
$listener
->
onExec
(
$dbh
,
$args
);
}
}
}
}
public
function
onPrePrepare
(
Doctrine_DB2
$dbh
,
array
$args
)
{
public
function
onPrePrepare
(
Doctrine_DB2
$dbh
,
$statement
,
array
$args
)
{
foreach
(
$this
->
listeners
as
$listener
)
{
foreach
(
$this
->
listeners
as
$listener
)
{
$listener
->
onPrePrepare
(
$dbh
,
$args
);
$listener
->
onPrePrepare
(
$dbh
,
$args
);
}
}
}
}
public
function
onPrepare
(
Doctrine_DB2
$dbh
,
array
$args
)
{
public
function
onPrepare
(
Doctrine_DB2
$dbh
,
$statement
,
array
$args
,
$queryId
)
{
foreach
(
$this
->
listeners
as
$listener
)
{
foreach
(
$this
->
listeners
as
$listener
)
{
$listener
->
onPrepare
(
$dbh
,
$args
);
$listener
->
onPrepare
(
$dbh
,
$args
);
}
}
...
...
lib/Doctrine/Db/EventListener/Interface.php
View file @
fef149dd
...
@@ -26,24 +26,24 @@
...
@@ -26,24 +26,24 @@
* @package Doctrine
* @package Doctrine
*/
*/
interface
Doctrine_Db_EventListener_Interface
{
interface
Doctrine_Db_EventListener_Interface
{
public
function
onPreQuery
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
);
public
function
onPreQuery
(
Doctrine_D
b_Event
$event
);
public
function
onQuery
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
,
$queryId
);
public
function
onQuery
(
Doctrine_D
b_Event
$event
);
public
function
onPrePrepare
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
);
public
function
onPrePrepare
(
Doctrine_D
b_Event
$event
);
public
function
onPrepare
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
,
$queryId
);
public
function
onPrepare
(
Doctrine_D
b_Event
$event
);
public
function
onPreExec
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
);
public
function
onPreExec
(
Doctrine_D
b_Event
$event
);
public
function
onExec
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
);
public
function
onExec
(
Doctrine_D
b_Event
$event
);
public
function
onPreCommit
(
Doctrine_D
B2
$dbh
);
public
function
onPreCommit
(
Doctrine_D
b_Event
$event
);
public
function
onCommit
(
Doctrine_D
B2
$dbh
);
public
function
onCommit
(
Doctrine_D
b_Event
$event
);
public
function
onPreRollBack
(
Doctrine_D
B2
$dbh
);
public
function
onPreRollBack
(
Doctrine_D
b_Event
$event
);
public
function
onRollBack
(
Doctrine_D
B2
$dbh
);
public
function
onRollBack
(
Doctrine_D
b_Event
$event
);
public
function
onPreBeginTransaction
(
Doctrine_D
B2
$dbh
);
public
function
onPreBeginTransaction
(
Doctrine_D
b_Event
$event
);
public
function
onBeginTransaction
(
Doctrine_D
B2
$dbh
);
public
function
onBeginTransaction
(
Doctrine_D
b_Event
$event
);
public
function
onPreExecute
(
Doctrine_Db_
Statement
$stmt
,
array
$params
);
public
function
onPreExecute
(
Doctrine_Db_
Event
$event
);
public
function
onExecute
(
Doctrine_Db_
Statement
$stmt
,
array
$params
);
public
function
onExecute
(
Doctrine_Db_
Event
$event
);
}
}
lib/Doctrine/Db/Profiler.php
View file @
fef149dd
...
@@ -25,226 +25,65 @@
...
@@ -25,226 +25,65 @@
* @license LGPL
* @license LGPL
* @package Doctrine
* @package Doctrine
*/
*/
class
Doctrine_Db_Profiler
extends
Doctrine_Db_EventListener
{
class
Doctrine_Db_Profiler
implements
Doctrine_Overloadable
{
public
function
onPreQuery
(
Doctrine_DB2
$dbh
,
$statement
,
array
$args
)
{
$this
->
queryStart
(
$statement
);
}
public
function
onQuery
(
Doctrine_DB2
$dbh
,
$statement
,
array
$args
,
$queryId
)
{
$this
->
queryEnd
(
$queryId
);
}
public
function
onPrePrepare
(
Doctrine_DB2
$dbh
,
$statement
,
array
$args
)
{
$this
->
prepareTimes
[
$dbh
->
getQuerySequence
()]
=
microtime
(
true
);
}
public
function
onPrepare
(
Doctrine_DB2
$dbh
,
$statement
,
array
$args
,
$queryId
)
{
$this
->
prepareTimes
[
$queryId
]
=
(
microtime
(
true
)
-
$this
->
prepareTimes
[
$queryId
]);
}
public
function
onPreCommit
(
Doctrine_DB2
$dbh
)
{
}
public
function
onCommit
(
Doctrine_DB2
$dbh
)
{
}
public
function
onPreRollBack
(
Doctrine_DB2
$dbh
)
{
}
public
function
onRollBack
(
Doctrine_DB2
$dbh
)
{
}
public
function
onPreBeginTransaction
(
Doctrine_DB2
$dbh
)
{
}
public
function
onBeginTransaction
(
Doctrine_DB2
$dbh
)
{
}
public
function
onPreExecute
(
Doctrine_Db_Statement
$stmt
,
array
$params
)
{
$this
->
queryStart
(
$stmt
->
getQuery
(),
$stmt
->
getQuerySequence
());
}
public
function
onExecute
(
Doctrine_Db_Statement
$stmt
,
array
$params
)
{
$this
->
queryEnd
(
$stmt
->
getQuerySequence
());
}
/**
/**
* Array of Zend_Db_Profiler_Query objects.
* @param array $listeners an array containing all availible listeners
*
* @var Zend_Db_Profiler_Query
*/
*/
protected
$_queryProfiles
=
array
();
private
$listeners
=
array
(
'query'
,
'prepare'
,
'commit'
,
protected
$_prepareTimes
=
array
();
'rollback'
,
'begintransaction'
,
'exec'
,
'execute'
,
);
/**
/**
* Stores the number of seconds to filter. NULL if filtering by time is
* @param array $events an array containing all listened events
* disabled. If an integer is stored here, profiles whose elapsed time
* is less than this value in seconds will be unset from
* the self::$_queryProfiles array.
*
* @var integer
*/
*/
protected
$_filterElapsedSecs
=
null
;
private
$events
=
array
();
/**
/**
* Logical OR of any of the filter constants. NULL if filtering by query
* method overloader
* type is disable. If an integer is stored here, it is the logical OR of
* this method is used for invoking different listeners, for the full
* any of the query type constants. When the query ends, if it is not
* list of availible listeners, see Doctrine_Db_EventListener
* one of the types specified, it will be unset from the
* self::$_queryProfiles array.
*
*
* @var integer
* @param string $m the name of the method
* @param array $a method arguments
* @see Doctrine_Db_EventListener
* @return void
*/
*/
protected
$_filterTypes
=
null
;
public
function
__call
(
$m
,
$a
)
{
// first argument should be an instance of Doctrine_Db_Event
if
(
!
(
$a
[
0
]
instanceof
Doctrine_Db_Event
))
/**
throw
new
Doctrine_Db_Profiler_Exception
(
"Couldn't listen event. Event should be an instance of Doctrine_Db_Event."
);
* Start a query. Creates a new query profile object (Zend_Db_Profiler_Query)
* and returns the "query profiler handle". Run the query, then call
// event methods should start with 'on'
* queryEnd() and pass it this handle to make the query as ended and
if
(
substr
(
$m
,
0
,
2
)
!==
'on'
)
* record the time. If the profiler is not enabled, this takes no
throw
new
Doctrine_Db_Profiler_Exception
(
"Couldn't invoke listener
$m
."
);
* action and immediately runs.
*
if
(
substr
(
$m
,
2
,
3
)
===
'Pre'
&&
in_array
(
strtolower
(
substr
(
$m
,
3
)),
$this
->
listeners
))
{
* @param string $queryText SQL statement
// pre-event listener found
* @param int $queryType Type of query, one of the Zend_Db_Profiler::* constants
$a
[
0
]
->
start
();
* @return mixed
}
else
{
*/
// after-event listener found
public
function
queryStart
(
$queryText
,
$querySequence
=
-
1
)
{
$a
[
0
]
->
end
();
$prepareTime
=
(
isset
(
$this
->
prepareTimes
[
$querySequence
]))
?
$this
->
prepareTimes
[
$querySequence
]
:
null
;
$this
->
_queryProfiles
[]
=
new
Doctrine_Db_Profiler_Query
(
$queryText
,
$prepareTime
);
}
/**
* Ends a query. Pass it the handle that was returned by queryStart().
* This will mark the query as ended and save the time.
*
* @param integer $queryId
* @throws Zend_Db_Profiler_Exception
* @return boolean
*/
public
function
queryEnd
(
$queryId
=
null
)
{
// Check for a valid query handle.
if
(
$queryId
===
null
)
$qp
=
end
(
$this
->
_queryProfiles
);
else
$qp
=
$this
->
_queryProfiles
[
$queryId
];
if
(
$qp
===
null
||
$qp
->
hasEnded
())
{
throw
new
Zend_Db_Profiler_Exception
(
'Query with profiler handle "'
.
$queryId
.
'" has already ended.'
);
}
}
// End the query profile so that the elapsed time can be calculated.
$this
->
events
[]
=
$a
[
0
];
$qp
->
end
();
}
}
/**
/**
* Get a profile for a query. Pass it the same handle that was returned
* Get the Doctrine_Db_Event object for the last query that was run, regardless if it has
* by queryStart() and it will return a Zend_Db_Profiler_Query object.
* ended or not. If the event has not ended, it's end time will be Null.
*
* @param int $queryId
* @throws Zend_Db_Profiler_Exception
* @return Zend_Db_Profiler_Query
*/
public
function
getQueryProfile
(
$queryId
)
{
if
(
!
array_key_exists
(
$queryId
,
$this
->
_queryProfiles
))
{
throw
new
Zend_Db_Profiler_Exception
(
"Query handle
\"
$queryId
\"
not found in profiler log."
);
}
return
$this
->
_queryProfiles
[
$queryId
];
}
/**
* Get an array of query profiles (Zend_Db_Profiler_Query objects). If $queryType
* is set to one of the Zend_Db_Profiler::* constants then only queries of that
* type will be returned. Normally, queries that have not yet ended will
* not be returned unless $showUnfinished is set to True. If no
* queries were found, False is returned.
*
* @param string $queryType
* @param bool $showUnfinished
* @return mixed
*/
public
function
getQueryProfiles
(
$queryType
=
null
,
$showUnfinished
=
false
)
{
$queryProfiles
=
array
();
foreach
(
$this
->
_queryProfiles
as
$key
=>
$qp
)
{
/* @var $qp Zend_Db_Profiler_Query */
if
(
$queryType
===
null
)
{
$condition
=
true
;
}
else
{
$condition
=
(
$qp
->
getQueryType
()
&
$queryType
);
}
if
((
$qp
->
hasEnded
()
||
$showUnfinished
)
&&
$condition
)
{
$queryProfiles
[
$key
]
=
$qp
;
}
}
if
(
empty
(
$queryProfiles
))
{
$queryProfiles
=
false
;
}
return
$queryProfiles
;
}
/**
* Get the total elapsed time (in seconds) of all of the profiled queries.
* Only queries that have ended will be counted. If $queryType is set to
* one of the Zend_Db_Profiler::* constants, the elapsed time will be calculated
* only for queries of that type.
*
* @param int $queryType
* @return int
*/
public
function
getTotalElapsedSecs
(
$queryType
=
null
)
{
$elapsedSecs
=
0
;
foreach
(
$this
->
_queryProfiles
as
$key
=>
$qp
)
{
/* @var $qp Zend_Db_Profiler_Query */
is_null
(
$queryType
)
?
$condition
=
true
:
$condition
=
(
$qp
->
getQueryType
()
&
$queryType
);
if
((
$qp
->
hasEnded
())
&&
$condition
)
{
$elapsedSecs
+=
$qp
->
getElapsedSecs
();
}
}
return
$elapsedSecs
;
}
/**
* Get the total number of queries that have been profiled. Only queries that have ended will
* be counted. If $queryType is set to one of the Zend_Db_Profiler::* constants, only queries of
* that type will be counted.
*
* @param int $queryType
* @return int
*/
public
function
getTotalNumQueries
(
$queryType
=
null
)
{
if
(
is_null
(
$queryType
))
{
return
sizeof
(
$this
->
_queryProfiles
);
}
$numQueries
=
0
;
foreach
(
$this
->
_queryProfiles
as
$qp
)
{
/* @var $qp Zend_Db_Profiler_Query */
is_null
(
$queryType
)
?
$condition
=
true
:
$condition
=
(
$qp
->
getQueryType
()
&
$queryType
);
if
(
$qp
->
hasEnded
()
&&
$condition
)
{
$numQueries
++
;
}
}
return
$numQueries
;
}
public
function
pop
()
{
return
array_pop
(
$this
->
_queryProfiles
);
}
/**
* Get the Zend_Db_Profiler_Query object for the last query that was run, regardless if it has
* ended or not. If the query has not ended, it's end time will be Null.
*
*
* @return
Zend_Db_Profiler_Query
* @return
Doctrine_Db_Event
*/
*/
public
function
last
Query
()
{
public
function
last
Event
()
{
if
(
empty
(
$this
->
_queryProfile
s
))
{
if
(
empty
(
$this
->
event
s
))
{
return
false
;
return
false
;
}
}
end
(
$this
->
_queryProfile
s
);
end
(
$this
->
event
s
);
return
current
(
$this
->
_queryProfile
s
);
return
current
(
$this
->
event
s
);
}
}
}
}
lib/Doctrine/Db/Profiler/Exception.php
0 → 100644
View file @
fef149dd
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine
::
autoload
(
'Doctrine_Db_Exception'
);
/**
* Doctrine_Db_Exception
*
* @author Konsta Vesterinen
* @license LGPL
* @package Doctrine
*/
class
Doctrine_Db_Profiler_Exception
extends
Doctrine_Db_Exception
{
}
lib/Doctrine/Db/Profiler/Query.php
View file @
fef149dd
...
@@ -58,14 +58,17 @@ class Doctrine_Db_Profiler_Query {
...
@@ -58,14 +58,17 @@ class Doctrine_Db_Profiler_Query {
*
*
* @param string $query
* @param string $query
* @param int $queryType
* @param int $queryType
* @return bool
*/
*/
public
function
__construct
(
$query
,
$prepareTime
=
null
)
public
function
__construct
(
$query
,
$prepareTime
=
null
)
{
{
$this
->
query
=
$query
;
$this
->
query
=
$query
;
$this
->
prepareTime
=
$prepareTime
;
if
(
$prepareTime
!==
null
)
{
$this
->
startedMicrotime
=
microtime
(
true
);
$this
->
prepareTime
=
$prepareTime
;
return
true
;
}
else
{
$this
->
startedMicrotime
=
microtime
(
true
);
}
}
public
function
start
()
{
$this
->
startedMicrotime
=
microtime
(
true
);
}
}
/**
/**
* The query has ended. Record the time so that the elapsed time can be determined later.
* The query has ended. Record the time so that the elapsed time can be determined later.
...
...
lib/Doctrine/Db/Statement.php
View file @
fef149dd
...
@@ -29,26 +29,43 @@ class Doctrine_Db_Statement extends PDOStatement {
...
@@ -29,26 +29,43 @@ class Doctrine_Db_Statement extends PDOStatement {
protected
$dbh
;
protected
$dbh
;
protected
$querySequence
;
protected
$querySequence
;
protected
$baseSequence
;
protected
$executed
=
false
;
protected
function
__construct
(
$dbh
)
{
protected
function
__construct
(
$dbh
)
{
$this
->
dbh
=
$dbh
;
$this
->
dbh
=
$dbh
;
$this
->
querySequence
=
$this
->
dbh
->
getQuerySequence
();
$this
->
baseSequence
=
$this
->
querySequence
=
$this
->
dbh
->
getQuerySequence
();
}
}
public
function
getQuerySequence
()
{
public
function
getQuerySequence
()
{
return
$this
->
querySequence
;
return
$this
->
querySequence
;
}
}
public
function
getBaseSequence
()
{
return
$this
->
baseSequence
;
}
public
function
getQuery
()
{
public
function
getQuery
()
{
return
$this
->
queryString
;
return
$this
->
queryString
;
}
}
public
function
isExecuted
(
$executed
=
null
)
{
if
(
$executed
===
null
)
return
$this
->
executed
;
$this
->
executed
=
(
bool
)
$executed
;
}
public
function
execute
(
array
$params
)
{
public
function
execute
(
array
$params
)
{
$this
->
dbh
->
getListener
()
->
onPreExecute
(
$this
,
$params
);
$event
=
new
Doctrine_Db_Event
(
$this
,
Doctrine_Db_Event
::
EXECUTE
,
$this
->
queryString
);
$this
->
dbh
->
getListener
()
->
onPreExecute
(
$event
);
$ret
=
parent
::
execute
(
$params
);
$ret
=
parent
::
execute
(
$params
);
$this
->
dbh
->
getListener
()
->
onExecute
(
$this
,
$params
);
$this
->
dbh
->
getListener
()
->
onExecute
(
$event
);
return
$this
;
return
$this
;
}
}
}
}
tests/DbProfilerTestCase.php
View file @
fef149dd
...
@@ -15,51 +15,56 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase {
...
@@ -15,51 +15,56 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase {
$this
->
dbh
->
query
(
'CREATE TABLE test (id INT)'
);
$this
->
dbh
->
query
(
'CREATE TABLE test (id INT)'
);
$this
->
assertEqual
(
$this
->
profiler
->
lastQuery
()
->
getQuery
(),
'CREATE TABLE test (id INT)'
);
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
'CREATE TABLE test (id INT)'
);
$this
->
assertTrue
(
$this
->
profiler
->
lastQuery
()
->
hasEnded
());
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastQuery
()
->
getElapsedSecs
()));
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getType
(),
Doctrine_Db_Event
::
QUERY
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
$this
->
assertEqual
(
$this
->
dbh
->
count
(),
1
);
$this
->
assertEqual
(
$this
->
dbh
->
count
(),
1
);
}
}
public
function
testPrepareAndExecute
()
{
public
function
testPrepareAndExecute
()
{
$stmt
=
$this
->
dbh
->
prepare
(
'INSERT INTO test (id) VALUES (?)'
);
$stmt
=
$this
->
dbh
->
prepare
(
'INSERT INTO test (id) VALUES (?)'
);
$event
=
$this
->
profiler
->
lastEvent
();
$this
->
assertEqual
(
$this
->
profiler
->
lastQuery
()
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertEqual
(
$event
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertFalse
(
$this
->
profiler
->
lastQuery
()
->
hasEnded
());
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastQuery
()
->
getElapsedSecs
()));
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getType
(),
Doctrine_Db_Event
::
PREPARE
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
$stmt
->
execute
(
array
(
1
));
$stmt
->
execute
(
array
(
1
));
$this
->
assertEqual
(
$this
->
profiler
->
lastQuery
()
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertTrue
(
$this
->
profiler
->
lastQuery
()
->
hasEnded
());
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastQuery
()
->
getElapsedSecs
()));
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getType
(),
Doctrine_Db_Event
::
EXECUTE
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
$this
->
assertEqual
(
$this
->
dbh
->
count
(),
2
);
$this
->
assertEqual
(
$this
->
dbh
->
count
(),
2
);
}
}
public
function
testMultiplePrepareAndExecute
()
{
public
function
testMultiplePrepareAndExecute
()
{
$stmt
=
$this
->
dbh
->
prepare
(
'INSERT INTO test (id) VALUES (?)'
);
$stmt
=
$this
->
dbh
->
prepare
(
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertEqual
(
$this
->
profiler
->
lastQuery
()
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertFalse
(
$this
->
profiler
->
lastQuery
()
->
hasEnded
());
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastQuery
()
->
getElapsedSecs
()));
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getType
(),
Doctrine_Db_Event
::
PREPARE
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
$stmt2
=
$this
->
dbh
->
prepare
(
'INSERT INTO test (id) VALUES (?)'
);
$stmt2
=
$this
->
dbh
->
prepare
(
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertEqual
(
$this
->
profiler
->
lastQuery
()
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertFalse
(
$this
->
profiler
->
lastQuery
()
->
hasEnded
());
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastQuery
()
->
getElapsedSecs
()));
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getType
(),
Doctrine_Db_Event
::
PREPARE
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
$stmt
->
execute
(
array
(
1
));
$stmt
->
execute
(
array
(
1
));
$stmt2
->
execute
(
array
(
1
));
$stmt2
->
execute
(
array
(
1
));
$this
->
assertEqual
(
$this
->
profiler
->
lastQuery
()
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertTrue
(
$this
->
profiler
->
lastQuery
()
->
hasEnded
());
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastQuery
()
->
getElapsedSecs
()));
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getType
(),
Doctrine_Db_Event
::
EXECUTE
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
$this
->
assertEqual
(
$this
->
dbh
->
count
(),
4
);
$this
->
assertEqual
(
$this
->
dbh
->
count
(),
4
);
}
}
/**
public
function
testExecuteStatementMultipleTimes
()
{
public
function
testExecuteStatementMultipleTimes
()
{
try
{
try
{
$stmt
=
$this
->
dbh
->
prepare
(
'INSERT INTO test (id) VALUES (?)'
);
$stmt
=
$this
->
dbh
->
prepare
(
'INSERT INTO test (id) VALUES (?)'
);
...
@@ -67,15 +72,66 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase {
...
@@ -67,15 +72,66 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase {
$stmt
->
execute
(
array
(
1
));
$stmt
->
execute
(
array
(
1
));
$this
->
pass
();
$this
->
pass
();
}
catch
(
Doctrine_Db_Exception
$e
)
{
}
catch
(
Doctrine_Db_Exception
$e
)
{
$this->fail();
$this
->
fail
(
$e
->
__toString
());
}
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getType
(),
Doctrine_Db_Event
::
EXECUTE
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getType
(),
Doctrine_Db_Event
::
EXECUTE
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
}
public
function
testTransactionRollback
()
{
try
{
$this
->
dbh
->
beginTransaction
();
$this
->
pass
();
}
catch
(
Doctrine_Db_Exception
$e
)
{
$this
->
fail
(
$e
->
__toString
());
}
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
null
);
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getType
(),
Doctrine_Db_Event
::
BEGIN
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
try
{
$this
->
dbh
->
rollback
();
$this
->
pass
();
}
catch
(
Doctrine_Db_Exception
$e
)
{
$this
->
fail
(
$e
->
__toString
());
}
}
$this->assertEqual($this->profiler->lastQuery()->getQuery(), 'INSERT INTO test (id) VALUES (?)');
$this->assertTrue($this->profiler->lastQuery()->hasEnded());
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
null
);
$this->assertTrue(is_numeric($this->profiler->lastQuery()->getElapsedSecs()));
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getType
(),
Doctrine_Db_Event
::
ROLLBACK
);
$this->assertEqual($this->profiler->lastQuery()->getQuery(), 'INSERT INTO test (id) VALUES (?)');
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
$this->assertTrue($this->profiler->lastQuery()->hasEnded());
}
$this->assertTrue(is_numeric($this->profiler->lastQuery()->getElapsedSecs()));
public
function
testTransactionCommit
()
{
} */
try
{
$this
->
dbh
->
beginTransaction
();
$this
->
pass
();
}
catch
(
Doctrine_Db_Exception
$e
)
{
$this
->
fail
(
$e
->
__toString
());
}
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
null
);
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getType
(),
Doctrine_Db_Event
::
BEGIN
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
try
{
$this
->
dbh
->
commit
();
$this
->
pass
();
}
catch
(
Doctrine_Db_Exception
$e
)
{
$this
->
fail
(
$e
->
__toString
());
}
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
null
);
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getType
(),
Doctrine_Db_Event
::
COMMIT
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
}
}
}
?>
?>
tests/run.php
View file @
fef149dd
...
@@ -68,9 +68,9 @@ print '<pre>';
...
@@ -68,9 +68,9 @@ print '<pre>';
$test
=
new
GroupTest
(
'Doctrine Framework Unit Tests'
);
$test
=
new
GroupTest
(
'Doctrine Framework Unit Tests'
);
//
$test->addTestCase(new Doctrine_Db_Profiler_TestCase());
$test
->
addTestCase
(
new
Doctrine_Db_Profiler_TestCase
());
/**
//$test->addTestCase(new Doctrine_DB
_TestCase());
$test->addTestCase(new Doctrine_Db
_TestCase());
$test->addTestCase(new Doctrine_Query_MultiJoin_TestCase());
$test->addTestCase(new Doctrine_Query_MultiJoin_TestCase());
...
@@ -154,14 +154,15 @@ $test->addTestCase(new Doctrine_Query_Where_TestCase());
...
@@ -154,14 +154,15 @@ $test->addTestCase(new Doctrine_Query_Where_TestCase());
$test->addTestCase(new Doctrine_Query_From_TestCase());
$test->addTestCase(new Doctrine_Query_From_TestCase());
$test
->
addTestCase
(
new
Doctrine_Query_Select_TestCase
());
$test->addTestCase(new Doctrine_Query_Delete_TestCase());
$test->addTestCase(new Doctrine_Query_Delete_TestCase());
$test->addTestCase(new Doctrine_Query_Update_TestCase());
$test->addTestCase(new Doctrine_Query_Update_TestCase());
$test->addTestCase(new Doctrine_Query_Limit_TestCase());
$test->addTestCase(new Doctrine_Query_Limit_TestCase());
*/
$test
->
addTestCase
(
new
Doctrine_Query_Select_TestCase
());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
...
...
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