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
e0cd52fb
Commit
e0cd52fb
authored
Jan 15, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved Connection::getPdoType() to Command.
parent
5d90e6da
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
29 deletions
+20
-29
Command.php
framework/db/Command.php
+20
-3
Connection.php
framework/db/Connection.php
+0
-17
ConnectionTest.php
tests/unit/framework/db/ConnectionTest.php
+0
-9
No files found.
framework/db/Command.php
View file @
e0cd52fb
...
@@ -144,7 +144,7 @@ class Command extends \yii\base\Component
...
@@ -144,7 +144,7 @@ class Command extends \yii\base\Component
{
{
$this
->
prepare
();
$this
->
prepare
();
if
(
$dataType
===
null
)
{
if
(
$dataType
===
null
)
{
$this
->
pdoStatement
->
bindParam
(
$name
,
$value
,
$this
->
connection
->
getPdoType
(
gettype
(
$value
)));
$this
->
pdoStatement
->
bindParam
(
$name
,
$value
,
$this
->
getPdoType
(
gettype
(
$value
)));
}
elseif
(
$length
===
null
)
{
}
elseif
(
$length
===
null
)
{
$this
->
pdoStatement
->
bindParam
(
$name
,
$value
,
$dataType
);
$this
->
pdoStatement
->
bindParam
(
$name
,
$value
,
$dataType
);
}
elseif
(
$driverOptions
===
null
)
{
}
elseif
(
$driverOptions
===
null
)
{
...
@@ -171,7 +171,7 @@ class Command extends \yii\base\Component
...
@@ -171,7 +171,7 @@ class Command extends \yii\base\Component
{
{
$this
->
prepare
();
$this
->
prepare
();
if
(
$dataType
===
null
)
{
if
(
$dataType
===
null
)
{
$this
->
pdoStatement
->
bindValue
(
$name
,
$value
,
$this
->
connection
->
getPdoType
(
gettype
(
$value
)));
$this
->
pdoStatement
->
bindValue
(
$name
,
$value
,
$this
->
getPdoType
(
gettype
(
$value
)));
}
else
{
}
else
{
$this
->
pdoStatement
->
bindValue
(
$name
,
$value
,
$dataType
);
$this
->
pdoStatement
->
bindValue
(
$name
,
$value
,
$dataType
);
}
}
...
@@ -199,7 +199,7 @@ class Command extends \yii\base\Component
...
@@ -199,7 +199,7 @@ class Command extends \yii\base\Component
$type
=
$value
[
1
];
$type
=
$value
[
1
];
$value
=
$value
[
0
];
$value
=
$value
[
0
];
}
else
{
}
else
{
$type
=
$this
->
connection
->
getPdoType
(
gettype
(
$value
));
$type
=
$this
->
getPdoType
(
gettype
(
$value
));
}
}
$this
->
pdoStatement
->
bindValue
(
$name
,
$value
,
$type
);
$this
->
pdoStatement
->
bindValue
(
$name
,
$value
,
$type
);
$this
->
_params
[
$name
]
=
$value
;
$this
->
_params
[
$name
]
=
$value
;
...
@@ -209,6 +209,23 @@ class Command extends \yii\base\Component
...
@@ -209,6 +209,23 @@ class Command extends \yii\base\Component
}
}
/**
/**
* Determines the PDO type for the give PHP data type.
* @param string $type The PHP type (obtained by `gettype()` call).
* @return integer the corresponding PDO type
* @see http://www.php.net/manual/en/pdo.constants.php
*/
private
function
getPdoType
(
$type
)
{
static
$typeMap
=
array
(
'boolean'
=>
\PDO
::
PARAM_BOOL
,
'integer'
=>
\PDO
::
PARAM_INT
,
'string'
=>
\PDO
::
PARAM_STR
,
'NULL'
=>
\PDO
::
PARAM_NULL
,
);
return
isset
(
$typeMap
[
$type
])
?
$typeMap
[
$type
]
:
\PDO
::
PARAM_STR
;
}
/**
* Executes the SQL statement.
* Executes the SQL statement.
* This method should only be used for executing non-query SQL statement, such as `INSERT`, `DELETE`, `UPDATE` SQLs.
* This method should only be used for executing non-query SQL statement, such as `INSERT`, `DELETE`, `UPDATE` SQLs.
* No result set will be returned.
* No result set will be returned.
...
...
framework/db/Connection.php
View file @
e0cd52fb
...
@@ -550,23 +550,6 @@ class Connection extends \yii\base\ApplicationComponent
...
@@ -550,23 +550,6 @@ class Connection extends \yii\base\ApplicationComponent
}
}
/**
/**
* Determines the PDO type for the give PHP data type.
* @param string $type The PHP type (obtained by `gettype()` call).
* @return integer the corresponding PDO type
* @see http://www.php.net/manual/en/pdo.constants.php
*/
public
function
getPdoType
(
$type
)
{
static
$typeMap
=
array
(
'boolean'
=>
\PDO
::
PARAM_BOOL
,
'integer'
=>
\PDO
::
PARAM_INT
,
'string'
=>
\PDO
::
PARAM_STR
,
'NULL'
=>
\PDO
::
PARAM_NULL
,
);
return
isset
(
$typeMap
[
$type
])
?
$typeMap
[
$type
]
:
\PDO
::
PARAM_STR
;
}
/**
* Returns the name of the DB driver for the current [[dsn]].
* Returns the name of the DB driver for the current [[dsn]].
* @return string name of the DB driver
* @return string name of the DB driver
*/
*/
...
...
tests/unit/framework/db/ConnectionTest.php
View file @
e0cd52fb
...
@@ -76,15 +76,6 @@ class ConnectionTest extends \yiiunit\MysqlTestCase
...
@@ -76,15 +76,6 @@ class ConnectionTest extends \yiiunit\MysqlTestCase
$this
->
assertEquals
(
'(column)'
,
$connection
->
quoteColumnName
(
'(column)'
));
$this
->
assertEquals
(
'(column)'
,
$connection
->
quoteColumnName
(
'(column)'
));
}
}
function
testGetPdoType
()
{
$connection
=
$this
->
getConnection
(
false
);
$this
->
assertEquals
(
\PDO
::
PARAM_BOOL
,
$connection
->
getPdoType
(
'boolean'
));
$this
->
assertEquals
(
\PDO
::
PARAM_INT
,
$connection
->
getPdoType
(
'integer'
));
$this
->
assertEquals
(
\PDO
::
PARAM_STR
,
$connection
->
getPdoType
(
'string'
));
$this
->
assertEquals
(
\PDO
::
PARAM_NULL
,
$connection
->
getPdoType
(
'NULL'
));
}
function
testAttribute
()
function
testAttribute
()
{
{
...
...
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