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
bed3a371
Commit
bed3a371
authored
Sep 27, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added fetch* methods to new Doctrine_DB
parent
a1d3e137
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
143 additions
and
31 deletions
+143
-31
DB.php
draft/DB.php
+44
-19
Statement.php
lib/Doctrine/DB/Statement.php
+1
-1
DBTestCase.php
tests/DBTestCase.php
+94
-7
run.php
tests/run.php
+4
-4
No files found.
draft/DB.php
View file @
bed3a371
...
...
@@ -36,14 +36,6 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
* @var array $instances all the instances of this class
*/
protected
static
$instances
=
array
();
/**
* @var array $queries all the executed queries
*/
protected
$queries
=
array
();
/**
* @var array $exectimes execution times of the executed queries
*/
protected
$exectimes
=
array
();
/**
* @var array $isConnected whether or not a connection has been established
*/
...
...
@@ -104,12 +96,16 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
}
/**
* getUsername
*
* @return string
*/
public
function
getUsername
()
{
return
$this
->
username
;
}
/**
* getPassword
*
* @return string
*/
public
function
getPassword
()
{
return
$this
->
password
;
...
...
@@ -165,7 +161,7 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
$this
->
dbh
=
new
PDO
(
$this
->
dsn
,
$this
->
username
,
$this
->
password
);
$this
->
dbh
->
setAttribute
(
PDO
::
ATTR_ERRMODE
,
PDO
::
ERRMODE_EXCEPTION
);
$this
->
dbh
->
setAttribute
(
PDO
::
ATTR_STATEMENT_CLASS
,
array
(
"Doctrine_DB_Statement"
,
array
(
$this
)));
$this
->
isConnected
=
true
;
return
true
;
}
...
...
@@ -303,6 +299,8 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
* @param string $statement
*/
public
function
prepare
(
$statement
)
{
$this
->
connect
();
$args
=
func_get_args
();
$this
->
listener
->
onPrePrepare
(
$this
,
$args
);
...
...
@@ -319,14 +317,17 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
* @param string $statement
* @return Doctrine_DB_Statement|boolean
*/
public
function
query
(
$statement
,
$fetchMode
=
null
,
$arg
=
null
,
$arg2
=
null
)
{
$args
=
func_get_args
();
$this
->
listener
->
onPreQuery
(
$this
,
$args
);
public
function
query
(
$statement
,
array
$params
=
array
())
{
$this
->
connect
();
$stmt
=
$this
->
dbh
->
query
(
$statement
,
$fetchMode
,
$arg
,
$arg2
);
$this
->
listener
->
onPreQuery
(
$this
,
$params
);
if
(
!
empty
(
$params
))
$stmt
=
$this
->
dbh
->
query
(
$statement
)
->
execute
(
$params
);
else
$stmt
=
$this
->
dbh
->
query
(
$statement
);
$this
->
listener
->
onQuery
(
$this
,
$
arg
s
);
$this
->
listener
->
onQuery
(
$this
,
$
param
s
);
return
$stmt
;
}
...
...
@@ -350,6 +351,8 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
* @return integer
*/
public
function
exec
(
$statement
)
{
$this
->
connect
();
$args
=
func_get_args
();
$this
->
listener
->
onPreExec
(
$this
,
$args
);
...
...
@@ -362,15 +365,37 @@ class Doctrine_DB2 implements Countable, IteratorAggregate {
}
/**
* fetchAll
*
* @return array
*/
public
function
fetchAssoc
(
$statement
,
$params
=
array
())
{
if
(
!
$params
)
$this
->
query
(
$statement
);
public
function
fetchAll
(
$statement
,
array
$params
=
array
())
{
return
$this
->
query
(
$statement
,
$params
)
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
}
public
function
fetchOne
(
$statement
,
array
$params
=
array
())
{
return
current
(
$this
->
query
(
$statement
,
$params
)
->
fetch
(
PDO
::
FETCH_NUM
));
}
public
function
fetchRow
(
$statement
,
array
$params
=
array
())
{
return
$this
->
query
(
$statement
,
$params
)
->
fetch
(
PDO
::
FETCH_ASSOC
);
}
public
function
fetchArray
(
$statement
,
array
$params
=
array
())
{
return
$this
->
query
(
$statement
,
$params
)
->
fetch
(
PDO
::
FETCH_NUM
);
}
public
function
fetchColumn
(
$statement
,
array
$params
=
array
())
{
return
$this
->
query
(
$statement
,
$params
)
->
fetchAll
(
PDO
::
FETCH_COLUMN
);
}
public
function
fetchAssoc
(
$statement
,
array
$params
=
array
())
{
return
$this
->
query
(
$statement
,
$params
)
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
}
public
function
fetchBoth
(
$statement
,
array
$params
=
array
())
{
return
$this
->
query
(
$statement
,
$params
)
->
fetchAll
(
PDO
::
FETCH_BOTH
);
}
/**
* lastInsertId
*
*
*
@return integer
*/
public
function
lastInsertId
()
{
$this
->
connect
();
...
...
lib/Doctrine/DB/Statement.php
View file @
bed3a371
...
...
@@ -39,6 +39,6 @@ class Doctrine_DB_Statement extends PDOStatement {
$this
->
dbh
->
getListener
()
->
onExecute
(
$this
,
$params
);
return
$
ret
;
return
$
this
;
}
}
tests/DBTestCase.php
View file @
bed3a371
...
...
@@ -22,6 +22,100 @@ class Doctrine_DB_TestCase extends Doctrine_UnitTestCase {
public
function
prepareTables
()
{
}
public
function
init
()
{
}
public
function
testFetchAll
()
{
$dbh
=
Doctrine_DB2
::
getConnection
(
'sqlite::memory:'
);
$dbh
->
connect
();
$dbh
->
query
(
'CREATE TABLE entity (id INTEGER, name TEXT)'
);
$dbh
->
query
(
"INSERT INTO entity (id, name) VALUES (1, 'zYne')"
);
$dbh
->
query
(
"INSERT INTO entity (id, name) VALUES (2, 'John')"
);
$a
=
$dbh
->
fetchAll
(
'SELECT * FROM entity'
);
$this
->
assertEqual
(
$a
,
array
(
0
=>
array
(
'id'
=>
'1'
,
'name'
=>
'zYne'
,
),
1
=>
array
(
'id'
=>
'2'
,
'name'
=>
'John'
,
),
));
}
public
function
testFetchOne
()
{
$dbh
=
Doctrine_DB2
::
getConnection
(
'sqlite::memory:'
);
$c
=
$dbh
->
fetchOne
(
'SELECT COUNT(1) FROM entity'
);
$this
->
assertEqual
(
$c
,
2
);
$c
=
$dbh
->
fetchOne
(
'SELECT COUNT(1) FROM entity WHERE id = ?'
,
array
(
1
));
$this
->
assertEqual
(
$c
,
1
);
}
public
function
testFetchAssoc
()
{
}
public
function
testFetchColumn
()
{
$dbh
=
Doctrine_DB2
::
getConnection
(
'sqlite::memory:'
);
$a
=
$dbh
->
fetchColumn
(
'SELECT * FROM entity'
);
$this
->
assertEqual
(
$a
,
array
(
0
=>
'1'
,
1
=>
'2'
,
));
$a
=
$dbh
->
fetchColumn
(
'SELECT * FROM entity WHERE id = ?'
,
array
(
1
));
$this
->
assertEqual
(
$a
,
array
(
0
=>
'1'
,
));
}
public
function
testFetchArray
()
{
$dbh
=
Doctrine_DB2
::
getConnection
(
'sqlite::memory:'
);
$a
=
$dbh
->
fetchArray
(
'SELECT * FROM entity'
);
$this
->
assertEqual
(
$a
,
array
(
0
=>
'1'
,
1
=>
'zYne'
,
));
$a
=
$dbh
->
fetchArray
(
'SELECT * FROM entity WHERE id = ?'
,
array
(
1
));
$this
->
assertEqual
(
$a
,
array
(
0
=>
'1'
,
1
=>
'zYne'
,
));
}
public
function
testFetchRow
()
{
$dbh
=
Doctrine_DB2
::
getConnection
(
'sqlite::memory:'
);
$c
=
$dbh
->
fetchRow
(
'SELECT * FROM entity'
);
$this
->
assertEqual
(
$c
,
array
(
'id'
=>
'1'
,
'name'
=>
'zYne'
,
));
$c
=
$dbh
->
fetchRow
(
'SELECT * FROM entity WHERE id = ?'
,
array
(
1
));
$this
->
assertEqual
(
$c
,
array
(
'id'
=>
'1'
,
'name'
=>
'zYne'
,
));
}
public
function
testFetchPairs
()
{
}
public
function
testAddValidEventListener
()
{
$dbh
=
Doctrine_DB2
::
getConnection
(
'sqlite::memory:'
);
...
...
@@ -77,14 +171,7 @@ class Doctrine_DB_TestCase extends Doctrine_UnitTestCase {
$dbh
=
Doctrine_DB2
::
getConnection
(
'sqlite::memory:'
);
$dbh
->
connect
();
$dbh
->
setListener
(
new
Doctrine_DB_TestLogger
());
$dbh
->
query
(
'CREATE TABLE entity (id INT)'
);
$listener
=
$dbh
->
getListener
();
$this
->
assertEqual
(
$listener
->
pop
(),
'onQuery'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'onPreQuery'
);
$stmt
=
$dbh
->
prepare
(
'INSERT INTO entity (id) VALUES(?)'
);
$this
->
assertEqual
(
$listener
->
pop
(),
'onPrepare'
);
...
...
tests/run.php
View file @
bed3a371
...
...
@@ -38,7 +38,7 @@ error_reporting(E_ALL);
$test
=
new
GroupTest
(
"Doctrine Framework Unit Tests"
);
$test
->
addTestCase
(
new
Doctrine_DB_TestCase
());
/**
$test->addTestCase(new Doctrine_ConnectionTestCase());
$test->addTestCase(new Doctrine_RecordTestCase());
...
...
@@ -74,11 +74,11 @@ $test->addTestCase(new Doctrine_ValueHolder_TestCase());
$test->addTestCase(new Doctrine_RawSql_TestCase());
$test->addTestCase(new Doctrine_Query_Limit_TestCase());
*/
//$test->addTestCase(new Doctrine_SchemaTestCase());
//$test->addTestCase(new Doctrine_ImportTestCase());
/**
$test->addTestCase(new Doctrine_CollectionTestCase());
$test->addTestCase(new Doctrine_Query_ReferenceModel_TestCase());
...
...
@@ -94,7 +94,7 @@ $test->addTestCase(new Doctrine_RelationAccessTestCase());
$test->addTestCase(new Doctrine_EventListener_Chain_TestCase());
$test->addTestCase(new Doctrine_DataDict_Sqlite_TestCase());
*/
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$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