Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
PSDI Army
yii2
Commits
8f15fd41
Commit
8f15fd41
authored
Aug 10, 2011
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
w
parent
760fdf98
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
90 additions
and
102 deletions
+90
-102
Command.php
framework/db/dao/Command.php
+0
-0
Connection.php
framework/db/dao/Connection.php
+6
-6
DataReader.php
framework/db/dao/DataReader.php
+30
-26
Transaction.php
framework/db/dao/Transaction.php
+52
-68
Validator.php
framework/validators/Validator.php
+2
-2
No files found.
framework/db/dao/Command.php
View file @
8f15fd41
This diff is collapsed.
Click to expand it.
framework/db/dao/Connection.php
View file @
8f15fd41
...
@@ -56,7 +56,7 @@ namespace yii\db\dao;
...
@@ -56,7 +56,7 @@ namespace yii\db\dao;
* $transaction->commit();
* $transaction->commit();
* }
* }
* catch(Exception $e) {
* catch(Exception $e) {
* $transaction->rollBack();
*
$transaction->rollBack();
* }
* }
* ~~~
* ~~~
*
*
...
@@ -580,12 +580,12 @@ class Connection extends \yii\base\ApplicationComponent
...
@@ -580,12 +580,12 @@ class Connection extends \yii\base\ApplicationComponent
public
function
getStats
()
public
function
getStats
()
{
{
$logger
=
\Yii
::
getLogger
();
$logger
=
\Yii
::
getLogger
();
$timings
=
$logger
->
getProfiling
Results
(
null
,
'yii\db\dao\Command::query'
);
$timings
=
$logger
->
getProfiling
(
array
(
'yii\db\dao\Command::query'
,
'yii\db\dao\Command::execute'
)
);
$count
=
count
(
$timings
);
$count
=
count
(
$timings
);
$time
=
array_sum
(
$timings
)
;
$time
=
0
;
$timings
=
$logger
->
getProfilingResults
(
null
,
'yii\db\dao\Command::execute'
);
foreach
(
$timings
as
$timing
)
{
$count
+=
count
(
$timings
)
;
$time
+=
$timing
[
1
]
;
$time
+=
array_sum
(
$timings
);
}
return
array
(
$count
,
$time
);
return
array
(
$count
,
$time
);
}
}
}
}
framework/db/dao/DataReader.php
View file @
8f15fd41
<?php
<?php
/**
/**
*
CDb
DataReader class file
* DataReader class file
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
/**
/**
*
CDb
DataReader represents a forward-only stream of rows from a query result set.
* DataReader represents a forward-only stream of rows from a query result set.
*
*
* To read the current row of data, call
{@link read}. The method {@link readAll}
* To read the current row of data, call
[[read]]. The method [[readAll]]
* returns all the rows in a single array.
* returns all the rows in a single array.
*
*
* One can also retrieve the rows of data in CDbDataReader by using foreach:
* One can also retrieve the rows of data in DataReader by using `foreach`:
* <pre>
*
* foreach($reader as $row)
* ~~~
* foreach($reader as $row) {
* // $row represents a row of data
* // $row represents a row of data
* </pre>
* }
* Since CDbDataReader is a forward-only stream, you can only traverse it once.
* ~~~
*
* Since DataReader is a forward-only stream, you can only traverse it once.
*
*
* It is possible to use a specific mode of data fetching by setting
* It is possible to use a specific mode of data fetching by setting
*
{@link setFetchMode FetchMode}. See {@link http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php}
*
[[fetchMode]]. See the [PHP manual](http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php)
* for more details.
* for more details
about possible fetch mode
.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id: CDbDataReader.php 3204 2011-05-05 21:36:32Z alexander.makarow $
* @since 2.0
* @package system.db
* @since 1.0
*/
*/
class
CDbDataReader
extends
CComponent
implements
Iterator
,
Countable
class
DataReader
extends
\yii\base\Component
implements
\Iterator
,
\
Countable
{
{
private
$_statement
;
private
$_statement
;
private
$_closed
=
false
;
private
$_closed
=
false
;
...
@@ -39,12 +40,12 @@ class CDbDataReader extends CComponent implements Iterator, Countable
...
@@ -39,12 +40,12 @@ class CDbDataReader extends CComponent implements Iterator, Countable
/**
/**
* Constructor.
* Constructor.
* @param C
DbC
ommand $command the command generating the query result
* @param Command $command the command generating the query result
*/
*/
public
function
__construct
(
C
DbC
ommand
$command
)
public
function
__construct
(
Command
$command
)
{
{
$this
->
_statement
=
$command
->
getPdoStatement
();
$this
->
_statement
=
$command
->
getPdoStatement
();
$this
->
_statement
->
setFetchMode
(
PDO
::
FETCH_ASSOC
);
$this
->
_statement
->
setFetchMode
(
\
PDO
::
FETCH_ASSOC
);
}
}
/**
/**
...
@@ -60,10 +61,12 @@ class CDbDataReader extends CComponent implements Iterator, Countable
...
@@ -60,10 +61,12 @@ class CDbDataReader extends CComponent implements Iterator, Countable
*/
*/
public
function
bindColumn
(
$column
,
&
$value
,
$dataType
=
null
)
public
function
bindColumn
(
$column
,
&
$value
,
$dataType
=
null
)
{
{
if
(
$dataType
===
null
)
if
(
$dataType
===
null
)
{
$this
->
_statement
->
bindColumn
(
$column
,
$value
);
$this
->
_statement
->
bindColumn
(
$column
,
$value
);
else
}
else
{
$this
->
_statement
->
bindColumn
(
$column
,
$value
,
$dataType
);
$this
->
_statement
->
bindColumn
(
$column
,
$value
,
$dataType
);
}
}
}
/**
/**
...
@@ -125,8 +128,9 @@ class CDbDataReader extends CComponent implements Iterator, Countable
...
@@ -125,8 +128,9 @@ class CDbDataReader extends CComponent implements Iterator, Countable
*/
*/
public
function
nextResult
()
public
function
nextResult
()
{
{
if
((
$result
=
$this
->
_statement
->
nextRowset
())
!==
false
)
if
((
$result
=
$this
->
_statement
->
nextRowset
())
!==
false
)
{
$this
->
_index
=
-
1
;
$this
->
_index
=
-
1
;
}
return
$result
;
return
$result
;
}
}
...
@@ -186,17 +190,17 @@ class CDbDataReader extends CComponent implements Iterator, Countable
...
@@ -186,17 +190,17 @@ class CDbDataReader extends CComponent implements Iterator, Countable
/**
/**
* Resets the iterator to the initial state.
* Resets the iterator to the initial state.
* This method is required by the interface Iterator.
* This method is required by the interface Iterator.
* @throws
C
Exception if this method is invoked twice
* @throws Exception if this method is invoked twice
*/
*/
public
function
rewind
()
public
function
rewind
()
{
{
if
(
$this
->
_index
<
0
)
if
(
$this
->
_index
<
0
)
{
{
$this
->
_row
=
$this
->
_statement
->
fetch
();
$this
->
_row
=
$this
->
_statement
->
fetch
();
$this
->
_index
=
0
;
$this
->
_index
=
0
;
}
}
else
else
{
throw
new
CDbException
(
Yii
::
t
(
'yii'
,
'CDbDataReader cannot rewind. It is a forward-only reader.'
));
throw
new
Exception
(
'DataReader cannot rewind. It is a forward-only reader.'
);
}
}
}
/**
/**
...
...
framework/db/dao/Transaction.php
View file @
8f15fd41
<?php
<?php
/**
/**
*
CDbTransaction class file
*
Transaction class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\db\dao
;
/**
/**
* CDbTransaction represents a DB transaction.
* Transaction represents a DB transaction.
*
* It is usually created by calling [[Connection::beginTransaction]].
*
*
* It is usually created by calling {@link CDbConnection::beginTransaction}.
* The following code is a typical example of using transactions (note that some
* DBMS may not support transactions):
*
*
* The following code is a common scenario of using transactions:
* ~~~
* <pre>
* $transaction = $connection->beginTransaction();
* $transaction=$connection->beginTransaction();
* try {
* try
* $connection->createCommand($sql1)->execute();
* {
* $connection->createCommand($sql2)->execute();
* $connection->createCommand($sql1)->execute();
* //.... other SQL executions
* $connection->createCommand($sql2)->execute();
* $transaction->commit();
* //.... other SQL executions
* $transaction->commit();
* }
* }
* catch(Exception $e)
* catch(Exception $e) {
* {
* $transaction->rollBack();
* $transaction->rollBack();
* }
* }
*
</pre>
*
~~~
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id: CDbTransaction.php 3069 2011-03-14 00:28:38Z qiang.xue $
* @since 2.0
* @package system.db
* @since 1.0
*/
*/
class
CDbTransaction
extends
C
Component
class
Transaction
extends
\yii\base\
Component
{
{
private
$_connection
=
null
;
/**
private
$_active
;
* @var boolean whether this transaction is active. Only an active transaction
* can [[commit]] or [[rollBack]]. This property is set true when the transaction is started.
*/
public
$active
;
/**
* @var Connection the database connection that this transaction is associated with.
* This property is set true when the transaction is started.
*/
public
$connection
;
/**
/**
* Constructor.
* Constructor.
* @param C
DbC
onnection $connection the connection associated with this transaction
* @param Connection $connection the connection associated with this transaction
* @see C
DbC
onnection::beginTransaction
* @see Connection::beginTransaction
*/
*/
public
function
__construct
(
CDbConnection
$connection
)
public
function
__construct
(
$connection
)
{
{
$this
->
_connection
=
$connection
;
$this
->
active
=
true
;
$this
->
_active
=
true
;
$this
->
connection
=
$connection
;
}
}
/**
/**
* Commits a transaction.
* Commits a transaction.
* @throws
C
Exception if the transaction or the DB connection is not active.
* @throws Exception if the transaction or the DB connection is not active.
*/
*/
public
function
commit
()
public
function
commit
()
{
{
if
(
$this
->
_active
&&
$this
->
_connection
->
getActive
())
if
(
$this
->
active
&&
$this
->
connection
->
getActive
())
{
{
Yii
::
trace
(
'Committing transaction'
,
__CLASS__
);
Yii
::
trace
(
'Committing transaction'
,
'system.db.CDbTransaction'
);
$this
->
connection
->
pdo
->
commit
();
$this
->
_connection
->
getPdoInstance
()
->
commit
();
$this
->
active
=
false
;
$this
->
_active
=
false
;
}
else
{
throw
new
Exception
(
'Transaction is inactive and cannot perform commit operation.'
);
}
}
else
throw
new
CDbException
(
Yii
::
t
(
'yii'
,
'CDbTransaction is inactive and cannot perform commit or roll back operations.'
));
}
}
/**
/**
* Rolls back a transaction.
* Rolls back a transaction.
* @throws
C
Exception if the transaction or the DB connection is not active.
* @throws Exception if the transaction or the DB connection is not active.
*/
*/
public
function
rollback
()
public
function
rollback
()
{
{
if
(
$this
->
_active
&&
$this
->
_connection
->
getActive
())
if
(
$this
->
active
&&
$this
->
connection
->
getActive
())
{
{
Yii
::
trace
(
'Rolling back transaction'
,
__CLASS__
);
Yii
::
trace
(
'Rolling back transaction'
,
'system.db.CDbTransaction'
);
$this
->
connection
->
pdo
->
rollBack
();
$this
->
_connection
->
getPdoInstance
()
->
rollBack
();
$this
->
active
=
false
;
$this
->
_active
=
false
;
}
else
{
throw
new
Exception
(
'Transaction is inactive and cannot perform roll back operation.'
);
}
}
else
throw
new
CDbException
(
Yii
::
t
(
'yii'
,
'CDbTransaction is inactive and cannot perform commit or roll back operations.'
));
}
/**
* @return CDbConnection the DB connection for this transaction
*/
public
function
getConnection
()
{
return
$this
->
_connection
;
}
/**
* @return boolean whether this transaction is active
*/
public
function
getActive
()
{
return
$this
->
_active
;
}
/**
* @param boolean $value whether this transaction is active
*/
protected
function
setActive
(
$value
)
{
$this
->
_active
=
$value
;
}
}
}
}
framework/validators/Validator.php
View file @
8f15fd41
...
@@ -95,9 +95,9 @@ abstract class Validator extends \yii\base\Component
...
@@ -95,9 +95,9 @@ abstract class Validator extends \yii\base\Component
public
$on
;
public
$on
;
/**
/**
* @var boolean whether this validation rule should be skipped if the attribute being validated
* @var boolean whether this validation rule should be skipped if the attribute being validated
* already has some validation error according to the previous rules. Defaults to
fals
e.
* already has some validation error according to the previous rules. Defaults to
tru
e.
*/
*/
public
$skipOnError
=
fals
e
;
public
$skipOnError
=
tru
e
;
/**
/**
* @var boolean whether attributes listed with this validator should be considered safe for
* @var boolean whether attributes listed with this validator should be considered safe for
* massive assignment. Defaults to true.
* massive assignment. Defaults to true.
...
...
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