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
23767304
Commit
23767304
authored
Jun 04, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better check of existence of tables.
parent
cbf642d9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
5 deletions
+11
-5
ActiveRecord.php
framework/yii/db/ActiveRecord.php
+7
-1
Schema.php
framework/yii/db/mysql/Schema.php
+4
-4
No files found.
framework/yii/db/ActiveRecord.php
View file @
23767304
...
...
@@ -275,10 +275,16 @@ class ActiveRecord extends Model
/**
* Returns the schema information of the DB table associated with this AR class.
* @return TableSchema the schema information of the DB table associated with this AR class.
* @throws InvalidConfigException if the table for the AR class does not exist.
*/
public
static
function
getTableSchema
()
{
return
static
::
getDb
()
->
getTableSchema
(
static
::
tableName
());
$schema
=
static
::
getDb
()
->
getTableSchema
(
static
::
tableName
());
if
(
$schema
!==
null
)
{
return
$schema
;
}
else
{
throw
new
InvalidConfigException
(
"The table does not exist: "
.
static
::
tableName
());
}
}
/**
...
...
framework/yii/db/mysql/Schema.php
View file @
23767304
...
...
@@ -181,12 +181,12 @@ class Schema extends \yii\db\Schema
*/
protected
function
findColumns
(
$table
)
{
$sql
=
'SHOW FULL COLUMNS FROM '
.
$this
->
quoteSimpleTableName
(
$table
->
name
);
try
{
$columns
=
$this
->
db
->
createCommand
(
$sql
)
->
queryAll
();
}
catch
(
\Exception
$e
)
{
$rows
=
$this
->
db
->
createCommand
(
"SHOW TABLES LIKE "
.
$this
->
quoteValue
(
$table
->
name
))
->
queryAll
();
if
(
count
(
$rows
)
===
0
)
{
return
false
;
}
$sql
=
'SHOW FULL COLUMNS FROM '
.
$this
->
quoteSimpleTableName
(
$table
->
name
);
$columns
=
$this
->
db
->
createCommand
(
$sql
)
->
queryAll
();
foreach
(
$columns
as
$info
)
{
$column
=
$this
->
loadColumnSchema
(
$info
);
$table
->
columns
[
$column
->
name
]
=
$column
;
...
...
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