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
7f705e91
Commit
7f705e91
authored
Sep 02, 2011
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
w
parent
5bdd961d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
24 deletions
+18
-24
QueryBuilder.php
framework/db/dao/QueryBuilder.php
+5
-5
QueryBuilder.php
framework/db/dao/mysql/QueryBuilder.php
+13
-19
No files found.
framework/db/dao/QueryBuilder.php
View file @
7f705e91
...
@@ -21,7 +21,7 @@ class QueryBuilder extends \yii\base\Component
...
@@ -21,7 +21,7 @@ class QueryBuilder extends \yii\base\Component
/**
/**
* @var array the abstract column types mapped to physical column types.
* @var array the abstract column types mapped to physical column types.
*/
*/
public
$
columnTypes
=
array
(
public
$
typeMap
=
array
(
'pk'
=>
'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY'
,
'pk'
=>
'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY'
,
'string'
=>
'varchar(255)'
,
'string'
=>
'varchar(255)'
,
'text'
=>
'text'
,
'text'
=>
'text'
,
...
@@ -379,7 +379,7 @@ class QueryBuilder extends \yii\base\Component
...
@@ -379,7 +379,7 @@ class QueryBuilder extends \yii\base\Component
/**
/**
* Converts an abstract column type into a physical column type.
* Converts an abstract column type into a physical column type.
* The conversion is done using the type map specified in {@link
columnTypes
}.
* The conversion is done using the type map specified in {@link
typeMap
}.
* These abstract column types are supported (using MySQL as example to explain the corresponding
* These abstract column types are supported (using MySQL as example to explain the corresponding
* physical types):
* physical types):
* <ul>
* <ul>
...
@@ -405,12 +405,12 @@ class QueryBuilder extends \yii\base\Component
...
@@ -405,12 +405,12 @@ class QueryBuilder extends \yii\base\Component
*/
*/
public
function
getColumnType
(
$type
)
public
function
getColumnType
(
$type
)
{
{
if
(
isset
(
$this
->
columnTypes
[
$type
]))
{
if
(
isset
(
$this
->
typeMap
[
$type
]))
{
return
$this
->
columnTypes
[
$type
];
return
$this
->
typeMap
[
$type
];
}
}
elseif
((
$pos
=
strpos
(
$type
,
' '
))
!==
false
)
{
elseif
((
$pos
=
strpos
(
$type
,
' '
))
!==
false
)
{
$t
=
substr
(
$type
,
0
,
$pos
);
$t
=
substr
(
$type
,
0
,
$pos
);
return
(
isset
(
$this
->
columnTypes
[
$t
])
?
$this
->
columnTypes
[
$t
]
:
$t
)
.
substr
(
$type
,
$pos
);
return
(
isset
(
$this
->
typeMap
[
$t
])
?
$this
->
typeMap
[
$t
]
:
$t
)
.
substr
(
$type
,
$pos
);
}
}
else
{
else
{
return
$type
;
return
$type
;
...
...
framework/db/dao/mysql/QueryBuilder.php
View file @
7f705e91
...
@@ -49,33 +49,27 @@ class QueryBuilder extends \yii\db\dao\QueryBuilder
...
@@ -49,33 +49,27 @@ class QueryBuilder extends \yii\db\dao\QueryBuilder
*/
*/
public
function
renameColumn
(
$table
,
$name
,
$newName
)
public
function
renameColumn
(
$table
,
$name
,
$newName
)
{
{
$
db
=
$this
->
getDbConnection
(
);
$
quotedTable
=
$this
->
schema
->
quoteTableName
(
$table
);
$row
=
$
db
->
createCommand
(
'SHOW CREATE TABLE '
.
$db
->
quoteTableName
(
$table
)
)
->
queryRow
();
$row
=
$
this
->
connection
->
createCommand
(
'SHOW CREATE TABLE '
.
$quotedTable
)
->
queryRow
();
if
(
$row
===
false
)
if
(
$row
===
false
)
throw
new
CDbException
(
Yii
::
t
(
'yii'
,
'Unable to find "{column}" in table "{table}".'
,
array
(
'{column}'
=>
$name
,
'{table}'
=>
$table
)));
throw
new
CDbException
(
Yii
::
t
(
'yii'
,
'Unable to find "{column}" in table "{table}".'
,
array
(
'{column}'
=>
$name
,
'{table}'
=>
$table
)));
if
(
isset
(
$row
[
'Create Table'
]))
if
(
isset
(
$row
[
'Create Table'
]))
{
$sql
=
$row
[
'Create Table'
];
$sql
=
$row
[
'Create Table'
];
else
}
{
else
{
$row
=
array_values
(
$row
);
$row
=
array_values
(
$row
);
$sql
=
$row
[
1
];
$sql
=
$row
[
1
];
}
}
if
(
preg_match_all
(
'/^\s*`(.*?)`\s+(.*?),?$/m'
,
$sql
,
$matches
))
if
(
preg_match_all
(
'/^\s*`(.*?)`\s+(.*?),?$/m'
,
$sql
,
$matches
))
{
{
foreach
(
$matches
[
1
]
as
$i
=>
$c
)
{
foreach
(
$matches
[
1
]
as
$i
=>
$c
)
if
(
$c
===
$name
)
{
{
return
"ALTER TABLE
$quotedTable
CHANGE "
.
$this
->
schema
->
quoteColumnName
(
$name
)
if
(
$c
===
$name
)
.
' '
.
$this
->
schema
->
quoteColumnName
(
$newName
)
.
' '
.
$matches
[
2
][
$i
];
{
return
"ALTER TABLE "
.
$db
->
quoteTableName
(
$table
)
.
" CHANGE "
.
$db
->
quoteColumnName
(
$name
)
.
' '
.
$db
->
quoteColumnName
(
$newName
)
.
' '
.
$matches
[
2
][
$i
];
}
}
}
}
}
}
// try to give back a SQL anyway
// try to give back a SQL anyway
return
"ALTER TABLE "
.
$db
->
quoteTableName
(
$table
)
return
"ALTER TABLE
$quotedTable
CHANGE "
.
$this
->
schema
->
quoteColumnName
(
$name
)
.
' '
.
$newName
;
.
" CHANGE "
.
$db
->
quoteColumnName
(
$name
)
.
' '
.
$newName
;
}
}
/**
/**
...
@@ -87,7 +81,7 @@ class QueryBuilder extends \yii\db\dao\QueryBuilder
...
@@ -87,7 +81,7 @@ class QueryBuilder extends \yii\db\dao\QueryBuilder
*/
*/
public
function
dropForeignKey
(
$name
,
$table
)
public
function
dropForeignKey
(
$name
,
$table
)
{
{
return
'ALTER TABLE '
.
$this
->
quoteTableName
(
$table
)
return
'ALTER TABLE '
.
$this
->
schema
->
quoteTableName
(
$table
)
.
' DROP FOREIGN KEY '
.
$this
->
quoteColumnName
(
$name
);
.
' DROP FOREIGN KEY '
.
$this
->
schema
->
quoteColumnName
(
$name
);
}
}
}
}
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