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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
8899aaeb
Commit
8899aaeb
authored
Oct 14, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved getPdoType() to Schema.
parent
8b528243
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
48 deletions
+49
-48
Command.php
framework/yii/db/Command.php
+6
-25
Schema.php
framework/yii/db/Schema.php
+20
-0
CommandTest.php
tests/unit/framework/db/CommandTest.php
+0
-23
SchemaTest.php
tests/unit/framework/db/SchemaTest.php
+23
-0
No files found.
framework/yii/db/Command.php
View file @
8899aaeb
...
...
@@ -181,8 +181,9 @@ class Command extends \yii\base\Component
{
$this
->
prepare
();
if
(
$dataType
===
null
)
{
$this
->
pdoStatement
->
bindParam
(
$name
,
$value
,
$this
->
getPdoType
(
$value
));
}
elseif
(
$length
===
null
)
{
$dataType
=
$this
->
db
->
getSchema
()
->
getPdoType
(
$value
);
}
if
(
$length
===
null
)
{
$this
->
pdoStatement
->
bindParam
(
$name
,
$value
,
$dataType
);
}
elseif
(
$driverOptions
===
null
)
{
$this
->
pdoStatement
->
bindParam
(
$name
,
$value
,
$dataType
,
$length
);
...
...
@@ -208,10 +209,9 @@ class Command extends \yii\base\Component
{
$this
->
prepare
();
if
(
$dataType
===
null
)
{
$this
->
pdoStatement
->
bindValue
(
$name
,
$value
,
$this
->
getPdoType
(
$value
));
}
else
{
$this
->
pdoStatement
->
bindValue
(
$name
,
$value
,
$dataType
);
$dataType
=
$this
->
db
->
getSchema
()
->
getPdoType
(
$value
);
}
$this
->
pdoStatement
->
bindValue
(
$name
,
$value
,
$dataType
);
$this
->
_params
[
$name
]
=
$value
;
return
$this
;
}
...
...
@@ -236,7 +236,7 @@ class Command extends \yii\base\Component
$type
=
$value
[
1
];
$value
=
$value
[
0
];
}
else
{
$type
=
$this
->
getPdoType
(
$value
);
$type
=
$this
->
db
->
getSchema
()
->
getPdoType
(
$value
);
}
$this
->
pdoStatement
->
bindValue
(
$name
,
$value
,
$type
);
$this
->
_params
[
$name
]
=
$value
;
...
...
@@ -246,25 +246,6 @@ class Command extends \yii\base\Component
}
/**
* Determines the PDO type for the given PHP data value.
* @param mixed $data the data whose PDO type is to be determined
* @return integer the PDO type
* @see http://www.php.net/manual/en/pdo.constants.php
*/
protected
function
getPdoType
(
$data
)
{
static
$typeMap
=
array
(
// php type => PDO type
'boolean'
=>
\PDO
::
PARAM_BOOL
,
'integer'
=>
\PDO
::
PARAM_INT
,
'string'
=>
\PDO
::
PARAM_STR
,
'resource'
=>
\PDO
::
PARAM_LOB
,
'NULL'
=>
\PDO
::
PARAM_NULL
,
);
$type
=
gettype
(
$data
);
return
isset
(
$typeMap
[
$type
])
?
$typeMap
[
$type
]
:
\PDO
::
PARAM_STR
;
}
/**
* Executes the SQL statement.
* This method should only be used for executing non-query SQL statement, such as `INSERT`, `DELETE`, `UPDATE` SQLs.
* No result set will be returned.
...
...
framework/yii/db/Schema.php
View file @
8899aaeb
...
...
@@ -187,6 +187,26 @@ abstract class Schema extends Object
}
/**
* Determines the PDO type for the given PHP data value.
* @param mixed $data the data whose PDO type is to be determined
* @return integer the PDO type
* @see http://www.php.net/manual/en/pdo.constants.php
*/
public
function
getPdoType
(
$data
)
{
static
$typeMap
=
array
(
// php type => PDO type
'boolean'
=>
\PDO
::
PARAM_BOOL
,
'integer'
=>
\PDO
::
PARAM_INT
,
'string'
=>
\PDO
::
PARAM_STR
,
'resource'
=>
\PDO
::
PARAM_LOB
,
'NULL'
=>
\PDO
::
PARAM_NULL
,
);
$type
=
gettype
(
$data
);
return
isset
(
$typeMap
[
$type
])
?
$typeMap
[
$type
]
:
\PDO
::
PARAM_STR
;
}
/**
* Refreshes the schema.
* This method cleans up all cached table schemas so that they can be re-created later
* to reflect the database schema change.
...
...
tests/unit/framework/db/CommandTest.php
View file @
8899aaeb
...
...
@@ -219,29 +219,6 @@ class CommandTest extends DatabaseTestCase
$this
->
assertTrue
(
is_array
(
$result
)
&&
isset
(
$result
[
0
]));
}
// getPDOType is currently private
// public function testGetPDOType()
// {
// $values = array(
// array(null, \PDO::PARAM_NULL),
// array('', \PDO::PARAM_STR),
// array('hello', \PDO::PARAM_STR),
// array(0, \PDO::PARAM_INT),
// array(1, \PDO::PARAM_INT),
// array(1337, \PDO::PARAM_INT),
// array(true, \PDO::PARAM_BOOL),
// array(false, \PDO::PARAM_BOOL),
// array($fp=fopen(__FILE__, 'rb'), \PDO::PARAM_LOB),
// );
//
// $command = $this->getConnection()->createCommand();
//
// foreach($values as $value) {
// $this->assertEquals($value[1], $command->getPdoType($value[0]));
// }
// fclose($fp);
// }
public
function
testInsert
()
{
}
...
...
tests/unit/framework/db/SchemaTest.php
View file @
8899aaeb
...
...
@@ -67,4 +67,27 @@ class SchemaTest extends DatabaseTestCase
$this
->
assertEquals
(
'order_id'
,
$table
->
foreignKeys
[
0
][
'order_id'
]);
$this
->
assertEquals
(
'item_id'
,
$table
->
foreignKeys
[
0
][
'item_id'
]);
}
public
function
testGetPDOType
()
{
$values
=
array
(
array
(
null
,
\PDO
::
PARAM_NULL
),
array
(
''
,
\PDO
::
PARAM_STR
),
array
(
'hello'
,
\PDO
::
PARAM_STR
),
array
(
0
,
\PDO
::
PARAM_INT
),
array
(
1
,
\PDO
::
PARAM_INT
),
array
(
1337
,
\PDO
::
PARAM_INT
),
array
(
true
,
\PDO
::
PARAM_BOOL
),
array
(
false
,
\PDO
::
PARAM_BOOL
),
array
(
$fp
=
fopen
(
__FILE__
,
'rb'
),
\PDO
::
PARAM_LOB
),
);
/** @var Schema $schema */
$schema
=
$this
->
getConnection
()
->
schema
;
foreach
(
$values
as
$value
)
{
$this
->
assertEquals
(
$value
[
1
],
$schema
->
getPdoType
(
$value
[
0
]));
}
fclose
(
$fp
);
}
}
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