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
702476d8
Commit
702476d8
authored
Dec 28, 2011
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
1295fbe2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
36 additions
and
32 deletions
+36
-32
Model.php
framework/base/Model.php
+13
-13
ModelBehavior.php
framework/base/ModelBehavior.php
+4
-4
QueryBuilder.php
framework/db/dao/QueryBuilder.php
+0
-0
QueryBuilder.php
framework/db/dao/mysql/QueryBuilder.php
+10
-6
QueryBuilder.php
framework/db/dao/sqlite/QueryBuilder.php
+7
-7
CommandTest.php
tests/unit/framework/db/dao/CommandTest.php
+2
-2
No files found.
framework/base/Model.php
View file @
702476d8
...
...
@@ -22,9 +22,9 @@ namespace yii\base;
*
* Model also provides a set of events for further customization:
*
* - [[onAfter
Construct]]: an event raised at the end of constructor
* - [[onBeforeValidate]]: an event raised at the beginning of [[validate]]
* - [[onAfterValidate]]: an event raised at the end of [[validate]]
* - [[onAfter
Init]]: an event raised at the end of [[init()]]
* - [[onBeforeValidate]]: an event raised at the beginning of [[validate
()
]]
* - [[onAfterValidate]]: an event raised at the end of [[validate
()
]]
*
* You may directly use Model to store model data, or extend it with customization.
* You may also customize Model by attaching [[ModelBehavior|model behaviors]].
...
...
@@ -46,7 +46,6 @@ class Model extends Component implements Initable, \IteratorAggregate, \ArrayAcc
public
function
__construct
(
$scenario
=
''
)
{
$this
->
_scenario
=
$scenario
;
$this
->
afterConstruct
();
}
/**
...
...
@@ -62,6 +61,7 @@ class Model extends Component implements Initable, \IteratorAggregate, \ArrayAcc
public
function
init
()
{
$this
->
attachBehaviors
(
$this
->
behaviors
());
$this
->
afterInit
();
}
/**
...
...
@@ -136,7 +136,7 @@ class Model extends Component implements Initable, \IteratorAggregate, \ArrayAcc
* - validator type: required, specifies the validator to be used. It can be the name of a model
* class method, the name of a built-in validator, or a validator class (or its path alias).
* - on: optional, specifies the [[scenario|scenarios]] (separated by commas) when the validation
* rule can be applied. If this option is not set, the rule will apply to a
ny scenario
.
* rule can be applied. If this option is not set, the rule will apply to a
ll scenarios
.
* - additional name-value pairs can be specified to initialize the corresponding validator properties.
* Please refer to individual validator class API for possible properties.
*
...
...
@@ -232,15 +232,15 @@ class Model extends Component implements Initable, \IteratorAggregate, \ArrayAcc
}
/**
* This method is invoked at the end of
model constructor
.
* The default implementation raises the [[onAfter
Construc
t]] event.
* This method is invoked at the end of
[[init()]]
.
* The default implementation raises the [[onAfter
Ini
t]] event.
* You may override this method to do postprocessing after model creation.
* Make sure you call the parent implementation so that the event is raised properly.
*/
public
function
after
Construc
t
()
public
function
after
Ini
t
()
{
if
(
$this
->
hasEventHandlers
(
'onAfter
Construc
t'
))
{
$this
->
onAfter
Construc
t
(
new
Event
(
$this
));
if
(
$this
->
hasEventHandlers
(
'onAfter
Ini
t'
))
{
$this
->
onAfter
Ini
t
(
new
Event
(
$this
));
}
}
...
...
@@ -285,10 +285,10 @@ class Model extends Component implements Initable, \IteratorAggregate, \ArrayAcc
}
/**
* This event is raised a
fter the model instance is created by new operator
.
* This event is raised a
t the end of [[init()]]
.
* @param Event $event the event parameter
*/
public
function
onAfter
Construc
t
(
$event
)
public
function
onAfter
Ini
t
(
$event
)
{
$this
->
raiseEvent
(
__FUNCTION__
,
$event
);
}
...
...
@@ -584,7 +584,7 @@ class Model extends Component implements Initable, \IteratorAggregate, \ArrayAcc
public
function
onUnsafeAttribute
(
$name
,
$value
)
{
if
(
YII_DEBUG
)
{
\Yii
::
warning
(
sprintf
(
'Failed to set unsafe attribute "%s" in "%s".'
,
$name
,
get_class
(
$this
))
);
\Yii
::
warning
(
"Failed to set unsafe attribute '
$name
' in '"
.
get_class
(
$this
)
.
"'."
);
}
}
...
...
framework/base/ModelBehavior.php
View file @
702476d8
...
...
@@ -24,7 +24,7 @@ class ModelBehavior extends Behavior
* Declares event handlers for owner's events.
* The default implementation returns the following event handlers:
*
* - `onAfter
Construct` event: [[afterConstruc
t]]
* - `onAfter
Init` event: [[afterIni
t]]
* - `onBeforeValidate` event: [[beforeValidate]]
* - `onAfterValidate` event: [[afterValidate]]
*
...
...
@@ -34,18 +34,18 @@ class ModelBehavior extends Behavior
public
function
events
()
{
return
array
(
'onAfter
Construct'
=>
'afterConstruc
t'
,
'onAfter
Init'
=>
'afterIni
t'
,
'onBeforeValidate'
=>
'beforeValidate'
,
'onAfterValidate'
=>
'afterValidate'
,
);
}
/**
* Responds to [[Model::onAfter
Construc
t]] event.
* Responds to [[Model::onAfter
Ini
t]] event.
* Override this method if you want to handle the corresponding event of the [[owner]].
* @param Event $event event parameter
*/
public
function
after
Construc
t
(
$event
)
public
function
after
Ini
t
(
$event
)
{
}
...
...
framework/db/dao/QueryBuilder.php
View file @
702476d8
This diff is collapsed.
Click to expand it.
framework/db/dao/mysql/QueryBuilder.php
View file @
702476d8
...
...
@@ -50,7 +50,7 @@ class QueryBuilder extends \yii\db\dao\QueryBuilder
*/
public
function
renameColumn
(
$table
,
$oldName
,
$newName
)
{
$quotedTable
=
$this
->
driver
->
quoteTableName
(
$table
);
$quotedTable
=
$this
->
quoteTableName
(
$table
);
$row
=
$this
->
connection
->
createCommand
(
'SHOW CREATE TABLE '
.
$quotedTable
)
->
queryRow
();
if
(
$row
===
false
)
{
throw
new
Exception
(
"Unable to find '
$oldName
' in table '
$table
'."
);
...
...
@@ -64,13 +64,17 @@ class QueryBuilder extends \yii\db\dao\QueryBuilder
if
(
preg_match_all
(
'/^\s*`(.*?)`\s+(.*?),?$/m'
,
$sql
,
$matches
))
{
foreach
(
$matches
[
1
]
as
$i
=>
$c
)
{
if
(
$c
===
$oldName
)
{
return
"ALTER TABLE
$quotedTable
CHANGE "
.
$this
->
driver
->
quoteColumnName
(
$oldName
)
.
' '
.
$this
->
driver
->
quoteColumnName
(
$newName
)
.
' '
.
$matches
[
2
][
$i
];
return
"ALTER TABLE
$quotedTable
CHANGE "
.
$this
->
quoteColumnName
(
$oldName
,
true
)
.
' '
.
$this
->
quoteColumnName
(
$newName
,
true
)
.
' '
.
$matches
[
2
][
$i
];
}
}
}
// try to give back a SQL anyway
return
"ALTER TABLE
$quotedTable
CHANGE "
.
$this
->
driver
->
quoteColumnName
(
$oldName
)
.
' '
.
$newName
;
return
"ALTER TABLE
$quotedTable
CHANGE "
.
$this
->
quoteColumnName
(
$oldName
,
true
)
.
' '
.
$this
->
quoteColumnName
(
$newName
,
true
);
}
/**
...
...
@@ -81,7 +85,7 @@ class QueryBuilder extends \yii\db\dao\QueryBuilder
*/
public
function
dropForeignKey
(
$name
,
$table
)
{
return
'ALTER TABLE '
.
$this
->
driver
->
quoteTableName
(
$table
)
.
' DROP FOREIGN KEY '
.
$this
->
driver
->
quoteColumnName
(
$name
);
return
'ALTER TABLE '
.
$this
->
quoteTableName
(
$table
)
.
' DROP FOREIGN KEY '
.
$this
->
quoteColumnName
(
$name
);
}
}
framework/db/dao/sqlite/QueryBuilder.php
View file @
702476d8
...
...
@@ -83,7 +83,7 @@ class QueryBuilder extends \yii\db\dao\QueryBuilder
*/
public
function
truncateTable
(
$table
)
{
return
"DELETE FROM "
.
$this
->
driver
->
quoteTableName
(
$table
);
return
"DELETE FROM "
.
$this
->
quoteTableName
(
$table
);
}
/**
...
...
@@ -94,7 +94,7 @@ class QueryBuilder extends \yii\db\dao\QueryBuilder
*/
public
function
dropIndex
(
$name
,
$table
)
{
return
'DROP INDEX '
.
$this
->
driver
->
quoteTableName
(
$name
);
return
'DROP INDEX '
.
$this
->
quoteTableName
(
$name
);
}
/**
...
...
@@ -105,7 +105,7 @@ class QueryBuilder extends \yii\db\dao\QueryBuilder
*/
public
function
dropColumn
(
$table
,
$column
)
{
throw
new
Exception
(
'Dropping DB column
is not supported by SQLite.'
);
throw
new
Exception
(
__METHOD__
.
'
is not supported by SQLite.'
);
}
/**
...
...
@@ -117,7 +117,7 @@ class QueryBuilder extends \yii\db\dao\QueryBuilder
*/
public
function
renameColumn
(
$table
,
$oldName
,
$newName
)
{
throw
new
Exception
(
'Renaming a DB column
is not supported by SQLite.'
);
throw
new
Exception
(
__METHOD__
.
'
is not supported by SQLite.'
);
}
/**
...
...
@@ -136,7 +136,7 @@ class QueryBuilder extends \yii\db\dao\QueryBuilder
*/
public
function
addForeignKey
(
$name
,
$table
,
$columns
,
$refTable
,
$refColumns
,
$delete
=
null
,
$update
=
null
)
{
throw
new
Exception
(
'Adding a foreign key constraint to an existing table
is not supported by SQLite.'
);
throw
new
Exception
(
__METHOD__
.
'
is not supported by SQLite.'
);
}
/**
...
...
@@ -147,7 +147,7 @@ class QueryBuilder extends \yii\db\dao\QueryBuilder
*/
public
function
dropForeignKey
(
$name
,
$table
)
{
throw
new
Exception
(
'Dropping a foreign key constraint
is not supported by SQLite.'
);
throw
new
Exception
(
__METHOD__
.
'
is not supported by SQLite.'
);
}
/**
...
...
@@ -162,6 +162,6 @@ class QueryBuilder extends \yii\db\dao\QueryBuilder
*/
public
function
alterColumn
(
$table
,
$column
,
$type
)
{
throw
new
Exception
(
'Altering a DB column
is not supported by SQLite.'
);
throw
new
Exception
(
__METHOD__
.
'
is not supported by SQLite.'
);
}
}
tests/unit/framework/db/dao/CommandTest.php
View file @
702476d8
...
...
@@ -26,14 +26,14 @@ class CommandTest extends \yiiunit\MysqlTestCase
$query
=
new
Query
;
$query
->
select
(
'id'
)
->
from
(
'tbl_user'
);
$command
=
$db
->
createCommand
(
$query
);
$this
->
assertEquals
(
"SELECT `id`
\n
FROM `tbl_user`"
,
$command
->
sql
);
$this
->
assertEquals
(
"SELECT `id`
FROM `tbl_user`"
,
$command
->
sql
);
// array
$command
=
$db
->
createCommand
(
array
(
'select'
=>
'name'
,
'from'
=>
'tbl_user'
,
));
$this
->
assertEquals
(
"SELECT `name`
\n
FROM `tbl_user`"
,
$command
->
sql
);
$this
->
assertEquals
(
"SELECT `name`
FROM `tbl_user`"
,
$command
->
sql
);
}
function
testGetSetSql
()
...
...
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