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
ef13a11f
Commit
ef13a11f
authored
Sep 18, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved getPDOType() back to Command to avoid dependency on Schema
fixes #854
parent
cc09ef56
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
70 additions
and
96 deletions
+70
-96
Command.php
framework/yii/db/Command.php
+22
-3
Schema.php
framework/yii/db/Schema.php
+0
-19
Schema.php
framework/yii/db/cubrid/Schema.php
+0
-19
cubrid.sql
tests/unit/data/cubrid.sql
+1
-3
CommandTest.php
tests/unit/framework/db/CommandTest.php
+23
-0
SchemaTest.php
tests/unit/framework/db/SchemaTest.php
+0
-23
CubridActiveRecordTest.php
tests/unit/framework/db/cubrid/CubridActiveRecordTest.php
+23
-0
CubridCommandTest.php
tests/unit/framework/db/cubrid/CubridCommandTest.php
+1
-7
CubridSchemaTest.php
tests/unit/framework/db/cubrid/CubridSchemaTest.php
+0
-22
No files found.
framework/yii/db/Command.php
View file @
ef13a11f
...
...
@@ -181,7 +181,7 @@ class Command extends \yii\base\Component
{
$this
->
prepare
();
if
(
$dataType
===
null
)
{
$this
->
pdoStatement
->
bindParam
(
$name
,
$value
,
$this
->
db
->
schema
->
getPdoType
(
$value
));
$this
->
pdoStatement
->
bindParam
(
$name
,
$value
,
$this
->
getPdoType
(
$value
));
}
elseif
(
$length
===
null
)
{
$this
->
pdoStatement
->
bindParam
(
$name
,
$value
,
$dataType
);
}
elseif
(
$driverOptions
===
null
)
{
...
...
@@ -208,7 +208,7 @@ class Command extends \yii\base\Component
{
$this
->
prepare
();
if
(
$dataType
===
null
)
{
$this
->
pdoStatement
->
bindValue
(
$name
,
$value
,
$this
->
db
->
schema
->
getPdoType
(
$value
));
$this
->
pdoStatement
->
bindValue
(
$name
,
$value
,
$this
->
getPdoType
(
$value
));
}
else
{
$this
->
pdoStatement
->
bindValue
(
$name
,
$value
,
$dataType
);
}
...
...
@@ -236,7 +236,7 @@ class Command extends \yii\base\Component
$type
=
$value
[
1
];
$value
=
$value
[
0
];
}
else
{
$type
=
$this
->
db
->
schema
->
getPdoType
(
$value
);
$type
=
$this
->
getPdoType
(
$value
);
}
$this
->
pdoStatement
->
bindValue
(
$name
,
$value
,
$type
);
$this
->
_params
[
$name
]
=
$value
;
...
...
@@ -246,6 +246,25 @@ 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
*/
private
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 @
ef13a11f
...
...
@@ -377,23 +377,4 @@ abstract class Schema extends Object
return
'string'
;
}
}
/**
* Determines the PDO type for the give 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
;
}
}
framework/yii/db/cubrid/Schema.php
View file @
ef13a11f
...
...
@@ -237,23 +237,4 @@ class Schema extends \yii\db\Schema
}
return
$tableNames
;
}
/**
* Determines the PDO type for the give 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
(
'boolean'
=>
\PDO
::
PARAM_INT
,
// CUBRID PDO does not support 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
;
}
}
tests/unit/data/cubrid.sql
View file @
ef13a11f
...
...
@@ -72,9 +72,7 @@ CREATE TABLE `tbl_type` (
`float_col2`
double
DEFAULT
'1.23'
,
`blob_col`
blob
,
`numeric_col`
decimal
(
5
,
2
)
DEFAULT
'33.22'
,
`time`
timestamp
NOT
NULL
DEFAULT
'2002-01-01 00:00:00'
,
`bool_col`
smallint
NOT
NULL
,
`bool_col2`
smallint
DEFAULT
1
`time`
timestamp
NOT
NULL
DEFAULT
'2002-01-01 00:00:00'
);
CREATE
TABLE
`tbl_composite_fk`
(
...
...
tests/unit/framework/db/CommandTest.php
View file @
ef13a11f
...
...
@@ -219,6 +219,29 @@ 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 @
ef13a11f
...
...
@@ -11,29 +11,6 @@ use yii\db\Schema;
*/
class
SchemaTest
extends
DatabaseTestCase
{
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
),
);
$schema
=
$this
->
getConnection
()
->
schema
;
foreach
(
$values
as
$value
)
{
$this
->
assertEquals
(
$value
[
1
],
$schema
->
getPdoType
(
$value
[
0
]));
}
fclose
(
$fp
);
}
public
function
testFindTableNames
()
{
/** @var Schema $schema */
...
...
tests/unit/framework/db/cubrid/CubridActiveRecordTest.php
View file @
ef13a11f
<?php
namespace
yiiunit\framework\db\cubrid
;
use
yiiunit\data\ar\Customer
;
use
yiiunit\framework\db\ActiveRecordTest
;
/**
...
...
@@ -10,4 +11,26 @@ use yiiunit\framework\db\ActiveRecordTest;
class
CubridActiveRecordTest
extends
ActiveRecordTest
{
public
$driverName
=
'cubrid'
;
/**
* cubrid PDO does not support boolean values.
* Make sure this does not affect AR layer.
*/
public
function
testBooleanAttribute
()
{
$customer
=
new
Customer
();
$customer
->
name
=
'boolean customer'
;
$customer
->
email
=
'mail@example.com'
;
$customer
->
status
=
true
;
$customer
->
save
(
false
);
$customer
->
refresh
();
$this
->
assertEquals
(
1
,
$customer
->
status
);
$customer
->
status
=
false
;
$customer
->
save
(
false
);
$customer
->
refresh
();
$this
->
assertEquals
(
0
,
$customer
->
status
);
}
}
tests/unit/framework/db/cubrid/CubridCommandTest.php
View file @
ef13a11f
...
...
@@ -31,7 +31,7 @@ class CubridCommandTest extends CommandTest
$command
->
bindParam
(
':email'
,
$email
);
$this
->
assertEquals
(
$name
,
$command
->
queryScalar
());
$sql
=
"INSERT INTO tbl_type (int_col, char_col, char_col2, enum_col, float_col, blob_col, numeric_col
, bool_col, bool_col2) VALUES (:int_col, '', :char_col, :enum_col, :float_col, CHAR_TO_BLOB(:blob_col), :numeric_col, :bool_col, :bool_col2
)"
;
$sql
=
"INSERT INTO tbl_type (int_col, char_col, char_col2, enum_col, float_col, blob_col, numeric_col
) VALUES (:int_col, '', :char_col, :enum_col, :float_col, CHAR_TO_BLOB(:blob_col), :numeric_col
)"
;
$command
=
$db
->
createCommand
(
$sql
);
$intCol
=
123
;
$charCol
=
'abc'
;
...
...
@@ -39,16 +39,12 @@ class CubridCommandTest extends CommandTest
$floatCol
=
1.23
;
$blobCol
=
"
\x10\x11\x12
"
;
$numericCol
=
'1.23'
;
$boolCol
=
false
;
$boolCol2
=
true
;
$command
->
bindParam
(
':int_col'
,
$intCol
);
$command
->
bindParam
(
':char_col'
,
$charCol
);
$command
->
bindParam
(
':enum_col'
,
$enumCol
);
$command
->
bindParam
(
':float_col'
,
$floatCol
);
$command
->
bindParam
(
':blob_col'
,
$blobCol
);
$command
->
bindParam
(
':numeric_col'
,
$numericCol
);
$command
->
bindParam
(
':bool_col'
,
$boolCol
);
$command
->
bindParam
(
':bool_col2'
,
$boolCol2
);
$this
->
assertEquals
(
1
,
$command
->
execute
());
$sql
=
'SELECT * FROM tbl_type'
;
...
...
@@ -59,8 +55,6 @@ class CubridCommandTest extends CommandTest
$this
->
assertEquals
(
$floatCol
,
$row
[
'float_col'
]);
$this
->
assertEquals
(
$blobCol
,
fread
(
$row
[
'blob_col'
],
3
));
$this
->
assertEquals
(
$numericCol
,
$row
[
'numeric_col'
]);
$this
->
assertEquals
(
$boolCol
,
$row
[
'bool_col'
]);
$this
->
assertEquals
(
$boolCol2
,
$row
[
'bool_col2'
]);
// bindValue
$sql
=
'INSERT INTO tbl_customer(email, name, address) VALUES (:email, \'user5\', \'address5\')'
;
...
...
tests/unit/framework/db/cubrid/CubridSchemaTest.php
View file @
ef13a11f
...
...
@@ -10,26 +10,4 @@ use yiiunit\framework\db\SchemaTest;
class
CubridSchemaTest
extends
SchemaTest
{
public
$driverName
=
'cubrid'
;
public
function
testGetPDOType
()
{
$values
=
array
(
null
=>
\PDO
::
PARAM_NULL
,
''
=>
\PDO
::
PARAM_STR
,
'hello'
=>
\PDO
::
PARAM_STR
,
0
=>
\PDO
::
PARAM_INT
,
1
=>
\PDO
::
PARAM_INT
,
1337
=>
\PDO
::
PARAM_INT
,
true
=>
\PDO
::
PARAM_INT
,
// CUBRID PDO does not support PARAM_BOOL
false
=>
\PDO
::
PARAM_INT
,
// CUBRID PDO does not support PARAM_BOOL
);
$schema
=
$this
->
getConnection
()
->
schema
;
foreach
(
$values
as
$value
=>
$type
)
{
$this
->
assertEquals
(
$type
,
$schema
->
getPdoType
(
$value
));
}
$this
->
assertEquals
(
\PDO
::
PARAM_LOB
,
$schema
->
getPdoType
(
$fp
=
fopen
(
__FILE__
,
'rb'
)));
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