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
6e6005b1
Commit
6e6005b1
authored
Jul 20, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored code.
parent
ae1ed5bd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
22 deletions
+21
-22
Schema.php
extensions/sphinx/Schema.php
+5
-5
Command.php
framework/db/Command.php
+2
-2
Connection.php
framework/db/Connection.php
+1
-1
Schema.php
framework/db/Schema.php
+13
-14
No files found.
extensions/sphinx/Schema.php
View file @
6e6005b1
...
...
@@ -502,20 +502,20 @@ class Schema extends Object
}
/**
*
Handles database error
*
Converts a DB exception to a more concrete one if possible.
*
* @param \Exception $e
* @param string $rawSql SQL that produced exception
* @
throws
Exception
* @
return
Exception
*/
public
function
handle
Exception
(
\Exception
$e
,
$rawSql
)
public
function
convert
Exception
(
\Exception
$e
,
$rawSql
)
{
if
(
$e
instanceof
Exception
)
{
throw
$e
;
return
$e
;
}
else
{
$message
=
$e
->
getMessage
()
.
"
\n
The SQL being executed was:
$rawSql
"
;
$errorInfo
=
$e
instanceof
\PDOException
?
$e
->
errorInfo
:
null
;
throw
new
Exception
(
$message
,
$errorInfo
,
(
int
)
$e
->
getCode
(),
$e
);
return
new
Exception
(
$message
,
$errorInfo
,
(
int
)
$e
->
getCode
(),
$e
);
}
}
...
...
framework/db/Command.php
View file @
6e6005b1
...
...
@@ -321,7 +321,7 @@ class Command extends \yii\base\Component
return
$n
;
}
catch
(
\Exception
$e
)
{
Yii
::
endProfile
(
$token
,
__METHOD__
);
$this
->
db
->
getSchema
()
->
handle
Exception
(
$e
,
$rawSql
);
throw
$this
->
db
->
getSchema
()
->
convert
Exception
(
$e
,
$rawSql
);
}
}
...
...
@@ -456,7 +456,7 @@ class Command extends \yii\base\Component
return
$result
;
}
catch
(
\Exception
$e
)
{
Yii
::
endProfile
(
$token
,
'yii\db\Command::query'
);
$this
->
db
->
getSchema
()
->
handle
Exception
(
$e
,
$rawSql
);
throw
$this
->
db
->
getSchema
()
->
convert
Exception
(
$e
,
$rawSql
);
}
}
...
...
framework/db/Connection.php
View file @
6e6005b1
...
...
@@ -432,7 +432,7 @@ class Connection extends Component
}
$token
=
'Opening DB connection: '
.
$this
->
dsn
;
try
{
Yii
::
trace
(
$token
,
__METHOD__
);
Yii
::
info
(
$token
,
__METHOD__
);
Yii
::
beginProfile
(
$token
,
__METHOD__
);
$this
->
pdo
=
$this
->
createPdoInstance
();
$this
->
initConnection
();
...
...
framework/db/Schema.php
View file @
6e6005b1
...
...
@@ -496,28 +496,27 @@ abstract class Schema extends Object
}
/**
*
Handles database error
*
Converts a DB exception to a more concrete one if possible.
*
* @param \Exception $e
* @param string $rawSql SQL that produced exception
* @
throws
Exception
* @
return
Exception
*/
public
function
handle
Exception
(
\Exception
$e
,
$rawSql
)
public
function
convert
Exception
(
\Exception
$e
,
$rawSql
)
{
if
(
$e
instanceof
Exception
)
{
throw
$e
;
}
else
{
$exceptionClass
=
'\yii\db\Exception'
;
foreach
(
$this
->
exceptionMap
as
$error
=>
$class
)
{
if
(
strpos
(
$e
->
getMessage
(),
$error
)
!==
false
)
{
$exceptionClass
=
$class
;
}
}
return
$e
;
}
$message
=
$e
->
getMessage
()
.
"
\n
The SQL being executed was:
$rawSql
"
;
$errorInfo
=
$e
instanceof
\PDOException
?
$e
->
errorInfo
:
null
;
throw
new
$exceptionClass
(
$message
,
$errorInfo
,
(
int
)
$e
->
getCode
(),
$e
);
$exceptionClass
=
'\yii\db\Exception'
;
foreach
(
$this
->
exceptionMap
as
$error
=>
$class
)
{
if
(
strpos
(
$e
->
getMessage
(),
$error
)
!==
false
)
{
$exceptionClass
=
$class
;
}
}
$message
=
$e
->
getMessage
()
.
"
\n
The SQL being executed was:
$rawSql
"
;
$errorInfo
=
$e
instanceof
\PDOException
?
$e
->
errorInfo
:
null
;
return
new
$exceptionClass
(
$message
,
$errorInfo
,
(
int
)
$e
->
getCode
(),
$e
);
}
/**
...
...
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