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
Expand all
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 {
/**
* 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.
*/
const
INSERT
=
4
;
const
INSERT
=
4
;
/**
* Updating existing information in the database, such as SQL's UPDATE.
...
...
@@ -123,6 +123,10 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
$this
->
listener
=
new
Doctrine_DB_EventListener
();
}
public
function
nextQuerySequence
()
{
return
++
$this
->
querySequence
;
}
/**
* getQuerySequence
*/
...
...
@@ -351,13 +355,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
public
function
prepare
(
$statement
)
{
$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
);
$this
->
listener
->
onPrepare
(
$
this
,
$statement
,
$args
,
$this
->
querySequence
);
$this
->
listener
->
onPrepare
(
$
event
);
$this
->
querySequence
++
;
...
...
@@ -372,15 +376,17 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
*/
public
function
query
(
$statement
,
array
$params
=
array
())
{
$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
);
else
$stmt
=
$this
->
dbh
->
query
(
$statement
);
$this
->
listener
->
onQuery
(
$
this
,
$statement
,
$params
,
$this
->
querySequence
);
$this
->
listener
->
onQuery
(
$
event
);
$this
->
querySequence
++
;
...
...
@@ -409,12 +415,14 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
$this
->
connect
();
$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
);
$this
->
listener
->
onExec
(
$
this
,
$statement
,
$args
);
$this
->
listener
->
onExec
(
$
event
);
return
$rows
;
}
...
...
@@ -463,11 +471,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
* @return boolean
*/
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
();
$this
->
listener
->
onBeginTransaction
(
$
this
);
$this
->
listener
->
onBeginTransaction
(
$
event
);
return
$return
;
}
...
...
@@ -477,11 +487,13 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
* @return boolean
*/
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
();
$this
->
listener
->
onCommit
(
$
this
);
$this
->
listener
->
onCommit
(
$
event
);
return
$return
;
}
...
...
@@ -492,8 +504,14 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
*/
public
function
rollBack
()
{
$this
->
connect
();
$event
=
new
Doctrine_Db_Event
(
$this
,
Doctrine_Db_Event
::
ROLLBACK
);
$this
->
listener
->
onPreRollback
(
$event
);
$this
->
dbh
->
rollBack
();
$this
->
listener
->
onRollback
(
$event
);
}
/**
* getAttribute
...
...
lib/Doctrine/DataDict/Oracle.php
View file @
fef149dd
...
...
@@ -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
* @return array containing the various possible types, length, sign, fixed
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @throws Doctrine_DataDict_Oracle_Exception
*/
function
mapNativeDatatype
(
$field
)
{
public
function
mapNativeDatatype
(
array
$field
)
{
$db_type
=
strtolower
(
$field
[
'type'
]);
$type
=
array
();
$length
=
$unsigned
=
$fixed
=
null
;
...
...
lib/Doctrine/DataDict/Pgsql.php
View file @
fef149dd
...
...
@@ -58,6 +58,8 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict {
case
'string'
:
case
'array'
:
case
'object'
:
case
'varchar'
:
case
'char'
:
$length
=
!
empty
(
$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 @@
* @package Doctrine
*/
class
Doctrine_Db_EventListener
implements
Doctrine_Db_EventListener_Interface
{
public
function
onPreQuery
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
)
{
}
public
function
onQuery
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
,
$queryId
)
{
}
public
function
onPreQuery
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onQuery
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onPrePrepare
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
)
{
}
public
function
onPrepare
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
,
$queryId
)
{
}
public
function
onPrePrepare
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onPrepare
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onPreCommit
(
Doctrine_D
B2
$dbh
)
{
}
public
function
onCommit
(
Doctrine_D
B2
$dbh
)
{
}
public
function
onPreCommit
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onCommit
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onPreExec
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
)
{
}
public
function
onExec
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
)
{
}
public
function
onPreExec
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onExec
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onPreRollBack
(
Doctrine_D
B2
$dbh
)
{
}
public
function
onRollBack
(
Doctrine_D
B2
$dbh
)
{
}
public
function
onPreRollBack
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onRollBack
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onPreBeginTransaction
(
Doctrine_D
B2
$dbh
)
{
}
public
function
onBeginTransaction
(
Doctrine_D
B2
$dbh
)
{
}
public
function
onPreBeginTransaction
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onBeginTransaction
(
Doctrine_D
b_Event
$event
)
{
}
public
function
onPreExecute
(
Doctrine_Db_
Statement
$stmt
,
array
$params
)
{
}
public
function
onExecute
(
Doctrine_Db_
Statement
$stmt
,
array
$params
)
{
}
public
function
onPreExecute
(
Doctrine_Db_
Event
$event
)
{
}
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
public
function
onQuery
(
Doctrine_DB2
$dbh
,
$statement
,
array
$args
,
$queryId
)
{
foreach
(
$this
->
listeners
as
$listener
)
{
$listener
->
on
Pre
Query
(
$dbh
,
$args
);
$listener
->
onQuery
(
$dbh
,
$args
);
}
}
public
function
onPreQuery
(
Doctrine_DB2
$dbh
,
$statement
,
array
$args
)
{
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
)
{
$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
)
{
$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
)
{
$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
)
{
$listener
->
onPrepare
(
$dbh
,
$args
);
}
...
...
lib/Doctrine/Db/EventListener/Interface.php
View file @
fef149dd
...
...
@@ -26,24 +26,24 @@
* @package Doctrine
*/
interface
Doctrine_Db_EventListener_Interface
{
public
function
onPreQuery
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
);
public
function
onQuery
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
,
$queryId
);
public
function
onPreQuery
(
Doctrine_D
b_Event
$event
);
public
function
onQuery
(
Doctrine_D
b_Event
$event
);
public
function
onPrePrepare
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
);
public
function
onPrepare
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
,
$queryId
);
public
function
onPrePrepare
(
Doctrine_D
b_Event
$event
);
public
function
onPrepare
(
Doctrine_D
b_Event
$event
);
public
function
onPreExec
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
);
public
function
onExec
(
Doctrine_D
B2
$dbh
,
$statement
,
array
$args
);
public
function
onPreExec
(
Doctrine_D
b_Event
$event
);
public
function
onExec
(
Doctrine_D
b_Event
$event
);
public
function
onPreCommit
(
Doctrine_D
B2
$dbh
);
public
function
onCommit
(
Doctrine_D
B2
$dbh
);
public
function
onPreCommit
(
Doctrine_D
b_Event
$event
);
public
function
onCommit
(
Doctrine_D
b_Event
$event
);
public
function
onPreRollBack
(
Doctrine_D
B2
$dbh
);
public
function
onRollBack
(
Doctrine_D
B2
$dbh
);
public
function
onPreRollBack
(
Doctrine_D
b_Event
$event
);
public
function
onRollBack
(
Doctrine_D
b_Event
$event
);
public
function
onPreBeginTransaction
(
Doctrine_D
B2
$dbh
);
public
function
onBeginTransaction
(
Doctrine_D
B2
$dbh
);
public
function
onPreBeginTransaction
(
Doctrine_D
b_Event
$event
);
public
function
onBeginTransaction
(
Doctrine_D
b_Event
$event
);
public
function
onPreExecute
(
Doctrine_Db_
Statement
$stmt
,
array
$params
);
public
function
onExecute
(
Doctrine_Db_
Statement
$stmt
,
array
$params
);
public
function
onPreExecute
(
Doctrine_Db_
Event
$event
);
public
function
onExecute
(
Doctrine_Db_
Event
$event
);
}
lib/Doctrine/Db/Profiler.php
View file @
fef149dd
This diff is collapsed.
Click to expand it.
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 {
*
* @param string $query
* @param int $queryType
* @return bool
*/
public
function
__construct
(
$query
,
$prepareTime
=
null
)
{
public
function
__construct
(
$query
,
$prepareTime
=
null
)
{
$this
->
query
=
$query
;
$this
->
prepareTime
=
$prepareTime
;
$this
->
startedMicrotime
=
microtime
(
true
);
return
true
;
if
(
$prepareTime
!==
null
)
{
$this
->
prepareTime
=
$prepareTime
;
}
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.
...
...
lib/Doctrine/Db/Statement.php
View file @
fef149dd
...
...
@@ -29,26 +29,43 @@ class Doctrine_Db_Statement extends PDOStatement {
protected
$dbh
;
protected
$querySequence
;
protected
$baseSequence
;
protected
$executed
=
false
;
protected
function
__construct
(
$dbh
)
{
$this
->
dbh
=
$dbh
;
$this
->
querySequence
=
$this
->
dbh
->
getQuerySequence
();
$this
->
baseSequence
=
$this
->
querySequence
=
$this
->
dbh
->
getQuerySequence
();
}
public
function
getQuerySequence
()
{
return
$this
->
querySequence
;
}
public
function
getBaseSequence
()
{
return
$this
->
baseSequence
;
}
public
function
getQuery
()
{
return
$this
->
queryString
;
}
public
function
isExecuted
(
$executed
=
null
)
{
if
(
$executed
===
null
)
return
$this
->
executed
;
$this
->
executed
=
(
bool
)
$executed
;
}
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
);
$this
->
dbh
->
getListener
()
->
onExecute
(
$this
,
$params
);
$this
->
dbh
->
getListener
()
->
onExecute
(
$event
);
return
$this
;
}
}
tests/DbProfilerTestCase.php
View file @
fef149dd
...
...
@@ -15,51 +15,56 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase {
$this
->
dbh
->
query
(
'CREATE TABLE test (id INT)'
);
$this
->
assertEqual
(
$this
->
profiler
->
lastQuery
()
->
getQuery
(),
'CREATE TABLE test (id INT)'
);
$this
->
assertTrue
(
$this
->
profiler
->
lastQuery
()
->
hasEnded
());
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastQuery
()
->
getElapsedSecs
()));
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
'CREATE TABLE test (id INT)'
);
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getType
(),
Doctrine_Db_Event
::
QUERY
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
$this
->
assertEqual
(
$this
->
dbh
->
count
(),
1
);
}
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
->
assertFalse
(
$this
->
profiler
->
lastQuery
()
->
hasEnded
());
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastQuery
()
->
getElapsedSecs
()));
$this
->
assertEqual
(
$event
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getType
(),
Doctrine_Db_Event
::
PREPARE
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
$stmt
->
execute
(
array
(
1
));
$this
->
assertEqual
(
$this
->
profiler
->
lastQuery
()
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertTrue
(
$this
->
profiler
->
lastQuery
()
->
hasEnded
());
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastQuery
()
->
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
()));
$this
->
assertEqual
(
$this
->
dbh
->
count
(),
2
);
}
public
function
testMultiplePrepareAndExecute
()
{
$stmt
=
$this
->
dbh
->
prepare
(
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertEqual
(
$this
->
profiler
->
lastQuery
()
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertFalse
(
$this
->
profiler
->
lastQuery
()
->
hasEnded
());
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastQuery
()
->
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
::
PREPARE
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
$stmt2
=
$this
->
dbh
->
prepare
(
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertEqual
(
$this
->
profiler
->
lastQuery
()
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertFalse
(
$this
->
profiler
->
lastQuery
()
->
hasEnded
());
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastQuery
()
->
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
::
PREPARE
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
getElapsedSecs
()));
$stmt
->
execute
(
array
(
1
));
$stmt2
->
execute
(
array
(
1
));
$this
->
assertEqual
(
$this
->
profiler
->
lastQuery
()
->
getQuery
(),
'INSERT INTO test (id) VALUES (?)'
);
$this
->
assertTrue
(
$this
->
profiler
->
lastQuery
()
->
hasEnded
());
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastQuery
()
->
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
()));
$this
->
assertEqual
(
$this
->
dbh
->
count
(),
4
);
}
/**
public
function
testExecuteStatementMultipleTimes
()
{
try
{
$stmt
=
$this
->
dbh
->
prepare
(
'INSERT INTO test (id) VALUES (?)'
);
...
...
@@ -67,15 +72,66 @@ class Doctrine_Db_Profiler_TestCase extends Doctrine_UnitTestCase {
$stmt
->
execute
(
array
(
1
));
$this
->
pass
();
}
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->assertTrue(is_numeric($this->profiler->lastQuery()->getElapsedSecs()));
$this->assertEqual($this->profiler->lastQuery()->getQuery(), 'INSERT INTO test (id) VALUES (?)');
$this->assertTrue($this->profiler->lastQuery()->hasEnded());
$this->assertTrue(is_numeric($this->profiler->lastQuery()->getElapsedSecs()));
} */
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getQuery
(),
null
);
$this
->
assertTrue
(
$this
->
profiler
->
lastEvent
()
->
hasEnded
());
$this
->
assertEqual
(
$this
->
profiler
->
lastEvent
()
->
getType
(),
Doctrine_Db_Event
::
ROLLBACK
);
$this
->
assertTrue
(
is_numeric
(
$this
->
profiler
->
lastEvent
()
->
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>';
$test
=
new
GroupTest
(
'Doctrine Framework Unit Tests'
);
//
$test->addTestCase(new Doctrine_Db_Profiler_TestCase());
//$test->addTestCase(new Doctrine_DB
_TestCase());
$test
->
addTestCase
(
new
Doctrine_Db_Profiler_TestCase
());
/**
$test->addTestCase(new Doctrine_Db
_TestCase());
$test->addTestCase(new Doctrine_Query_MultiJoin_TestCase());
...
...
@@ -154,14 +154,15 @@ $test->addTestCase(new Doctrine_Query_Where_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_Update_TestCase());
$test->addTestCase(new Doctrine_Query_Limit_TestCase());
*/
$test
->
addTestCase
(
new
Doctrine_Query_Select_TestCase
());
//$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