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
92d65ab7
Commit
92d65ab7
authored
Aug 12, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix issue with postgreSQL and batch inserting boolean values
fixes #4654
parent
f1dd83e2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
4 deletions
+69
-4
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
Schema.php
framework/db/Schema.php
+3
-1
QueryBuilder.php
framework/db/pgsql/QueryBuilder.php
+40
-0
PostgreSQLCommandTest.php
tests/unit/framework/db/pgsql/PostgreSQLCommandTest.php
+25
-3
No files found.
framework/CHANGELOG.md
View file @
92d65ab7
...
...
@@ -80,6 +80,7 @@ Yii Framework 2 Change Log
-
Bug #4514: Fixed Request class crashing when empty CSRF token value is sent in cookie (cebe)
-
Bug #4519:
`yii\base\Model::isAttributeRequired()`
should check if the
`when`
option of the validator is set (thiagotalma)
-
Bug #4592: Fixed
`yii help`
command was listing incorrect action names for methods like
`actionSayNO`
(samdark)
-
Bug #4654: Fixed issue with PostgreSQL and inserting boolean values with batch insert (cebe)
-
Bug: Fixed inconsistent return of
`\yii\console\Application::runAction()`
(samdark)
-
Bug: URL encoding for the route parameter added to
`\yii\web\UrlManager`
(klimov-paul)
-
Bug: Fixed the bug that requesting protected or private action methods would cause 500 error instead of 404 (qiangxue)
...
...
framework/db/Schema.php
View file @
92d65ab7
...
...
@@ -84,11 +84,13 @@ abstract class Schema extends Object
*/
private
$_builder
;
/**
* @return \yii\db\ColumnSchema
* @throws \yii\base\InvalidConfigException
*/
protected
function
createColumnSchema
()
{
protected
function
createColumnSchema
()
{
return
Yii
::
createObject
(
'yii\db\ColumnSchema'
);
}
...
...
framework/db/pgsql/QueryBuilder.php
View file @
92d65ab7
...
...
@@ -159,4 +159,44 @@ class QueryBuilder extends \yii\db\QueryBuilder
.
$this
->
db
->
quoteColumnName
(
$column
)
.
' TYPE '
.
$this
->
getColumnType
(
$type
);
}
/**
* @inheritdoc
*/
public
function
batchInsert
(
$table
,
$columns
,
$rows
)
{
if
((
$tableSchema
=
$this
->
db
->
getTableSchema
(
$table
))
!==
null
)
{
$columnSchemas
=
$tableSchema
->
columns
;
}
else
{
$columnSchemas
=
[];
}
$values
=
[];
foreach
(
$rows
as
$row
)
{
$vs
=
[];
foreach
(
$row
as
$i
=>
$value
)
{
if
(
!
is_array
(
$value
)
&&
isset
(
$columnSchemas
[
$columns
[
$i
]]))
{
$value
=
$columnSchemas
[
$columns
[
$i
]]
->
dbTypecast
(
$value
);
}
if
(
is_string
(
$value
))
{
$value
=
$this
->
db
->
quoteValue
(
$value
);
}
elseif
(
$value
===
true
)
{
$value
=
'TRUE'
;
}
elseif
(
$value
===
false
)
{
$value
=
'FALSE'
;
}
elseif
(
$value
===
null
)
{
$value
=
'NULL'
;
}
$vs
[]
=
$value
;
}
$values
[]
=
'('
.
implode
(
', '
,
$vs
)
.
')'
;
}
foreach
(
$columns
as
$i
=>
$name
)
{
$columns
[
$i
]
=
$this
->
db
->
quoteColumnName
(
$name
);
}
return
'INSERT INTO '
.
$this
->
db
->
quoteTableName
(
$table
)
.
' ('
.
implode
(
', '
,
$columns
)
.
') VALUES '
.
implode
(
', '
,
$values
);
}
}
tests/unit/framework/db/pgsql/PostgreSQLCommandTest.php
View file @
92d65ab7
...
...
@@ -20,11 +20,27 @@ class PostgreSQLCommandTest extends CommandTest
$this
->
assertEquals
(
'SELECT "id", "t"."name" FROM "customer" t'
,
$command
->
sql
);
}
public
function
testB
atch
Insert
()
public
function
testB
ooleanValues
Insert
()
{
parent
::
testBatchInsert
();
$db
=
$this
->
getConnection
();
$command
=
$db
->
createCommand
();
$command
->
insert
(
'bool_values'
,
[
'bool_col'
=>
true
]);
$this
->
assertEquals
(
1
,
$command
->
execute
());
$command
=
$this
->
getConnection
()
->
createCommand
();
$command
=
$db
->
createCommand
();
$command
->
insert
(
'bool_values'
,
[
'bool_col'
=>
false
]);
$this
->
assertEquals
(
1
,
$command
->
execute
());
$command
=
$db
->
createCommand
(
'SELECT COUNT(*) FROM "bool_values" WHERE bool_col = TRUE;'
);
$this
->
assertEquals
(
1
,
$command
->
queryScalar
());
$command
=
$db
->
createCommand
(
'SELECT COUNT(*) FROM "bool_values" WHERE bool_col = FALSE;'
);
$this
->
assertEquals
(
1
,
$command
->
queryScalar
());
}
public
function
testBooleanValuesBatchInsert
()
{
$db
=
$this
->
getConnection
();
$command
=
$db
->
createCommand
();
$command
->
batchInsert
(
'bool_values'
,
[
'bool_col'
],
[
[
true
],
...
...
@@ -32,5 +48,10 @@ class PostgreSQLCommandTest extends CommandTest
]
);
$this
->
assertEquals
(
2
,
$command
->
execute
());
$command
=
$db
->
createCommand
(
'SELECT COUNT(*) FROM "bool_values" WHERE bool_col = TRUE;'
);
$this
->
assertEquals
(
1
,
$command
->
queryScalar
());
$command
=
$db
->
createCommand
(
'SELECT COUNT(*) FROM "bool_values" WHERE bool_col = FALSE;'
);
$this
->
assertEquals
(
1
,
$command
->
queryScalar
());
}
}
\ No newline at end of file
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