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
b6368617
Commit
b6368617
authored
Jan 04, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Doctrine_Db now supports pending attributes => lazy connecting now possible
parent
f900a51a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
9 deletions
+29
-9
Db.php
lib/Doctrine/Db.php
+29
-9
No files found.
lib/Doctrine/Db.php
View file @
b6368617
...
@@ -51,15 +51,15 @@
...
@@ -51,15 +51,15 @@
class
Doctrine_Db
implements
Countable
,
IteratorAggregate
,
Doctrine_Adapter_Interface
class
Doctrine_Db
implements
Countable
,
IteratorAggregate
,
Doctrine_Adapter_Interface
{
{
/**
/**
* @var array $instances all the instances of this class
* @var array $instances
all the instances of this class
*/
*/
protected
static
$instances
=
array
();
protected
static
$instances
=
array
();
/**
/**
* @var array $isConnected whether or not a connection has been established
* @var array $isConnected
whether or not a connection has been established
*/
*/
protected
$isConnected
=
false
;
protected
$isConnected
=
false
;
/**
/**
* @var PDO $dbh the database handler
* @var PDO $dbh
the database handler
*/
*/
protected
$dbh
;
protected
$dbh
;
/**
/**
...
@@ -69,6 +69,12 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
...
@@ -69,6 +69,12 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
'username'
=>
null
,
'username'
=>
null
,
'password'
=>
null
,
'password'
=>
null
,
);
);
/**
* @var array $pendingAttributes An array of pending attributes. When setting attributes
* no connection is needed. When connected all the pending
* attributes are passed to the underlying PDO instance.
*/
protected
$pendingAttributes
=
array
();
/**
/**
* @var Doctrine_Db_EventListener_Interface|Doctrine_Overloadable $listener
* @var Doctrine_Db_EventListener_Interface|Doctrine_Overloadable $listener
* listener for listening events
* listener for listening events
...
@@ -186,6 +192,11 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
...
@@ -186,6 +192,11 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
$this
->
dbh
=
new
PDO
(
$this
->
options
[
'dsn'
],
$this
->
options
[
'username'
],
$this
->
options
[
'password'
]);
$this
->
dbh
=
new
PDO
(
$this
->
options
[
'dsn'
],
$this
->
options
[
'username'
],
$this
->
options
[
'password'
]);
$this
->
dbh
->
setAttribute
(
PDO
::
ATTR_ERRMODE
,
PDO
::
ERRMODE_EXCEPTION
);
$this
->
dbh
->
setAttribute
(
PDO
::
ATTR_ERRMODE
,
PDO
::
ERRMODE_EXCEPTION
);
$this
->
dbh
->
setAttribute
(
PDO
::
ATTR_STATEMENT_CLASS
,
array
(
"Doctrine_Db_Statement"
,
array
(
$this
)));
$this
->
dbh
->
setAttribute
(
PDO
::
ATTR_STATEMENT_CLASS
,
array
(
"Doctrine_Db_Statement"
,
array
(
$this
)));
foreach
(
$this
->
pendingAttributes
as
$attr
=>
$value
)
{
$this
->
dbh
->
setAttribute
(
$attr
,
$value
);
}
$this
->
isConnected
=
true
;
$this
->
isConnected
=
true
;
return
true
;
return
true
;
}
}
...
@@ -275,6 +286,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
...
@@ -275,6 +286,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
default
:
default
:
throw
new
Doctrine_Db_Exception
(
'Unknown driver '
.
$parts
[
'scheme'
]);
throw
new
Doctrine_Db_Exception
(
'Unknown driver '
.
$parts
[
'scheme'
]);
}
}
$this
->
pendingAttributes
[
PDO
::
ATTR_DRIVER_NAME
]
=
$parts
[
'scheme'
];
return
$parts
;
return
$parts
;
}
}
...
@@ -463,9 +475,15 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
...
@@ -463,9 +475,15 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
*/
*/
public
function
getAttribute
(
$attribute
)
public
function
getAttribute
(
$attribute
)
{
{
$this
->
connect
();
if
(
$this
->
isConnected
)
{
return
$this
->
dbh
->
getAttribute
(
$attribute
);
return
$this
->
dbh
->
getAttribute
(
$attribute
);
}
else
{
if
(
!
isset
(
$this
->
pendingAttributes
[
$attribute
]))
{
throw
new
Doctrine_Db_Exception
(
'Attribute '
.
$attribute
.
' not found.'
);
}
return
$this
->
pendingAttributes
[
$attribute
];
}
}
}
/**
/**
* returns an array of available PDO drivers
* returns an array of available PDO drivers
...
@@ -484,9 +502,11 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
...
@@ -484,9 +502,11 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
*/
*/
public
function
setAttribute
(
$attribute
,
$value
)
public
function
setAttribute
(
$attribute
,
$value
)
{
{
$this
->
connect
();
if
(
$this
->
isConnected
)
{
$this
->
dbh
->
setAttribute
(
$attribute
,
$value
);
$this
->
dbh
->
setAttribute
(
$attribute
,
$value
);
}
else
{
$this
->
pendingAttributes
[
$attribute
]
=
$value
;
}
}
}
/**
/**
* getIterator
* getIterator
...
...
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