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
c6274acf
Commit
c6274acf
authored
Aug 12, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ensure postgres boolean values are handled correctly
also fixed an issue with default value loading of bool columns. fixes #3489, fixes #4085, fixes #3920 related to #4672
parent
92d65ab7
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
91 additions
and
1 deletion
+91
-1
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
Schema.php
framework/db/pgsql/Schema.php
+2
-0
postgres.sql
tests/unit/data/postgres.sql
+3
-1
PostgreSQLActiveRecordTest.php
tests/unit/framework/db/pgsql/PostgreSQLActiveRecordTest.php
+51
-0
PostgreSQLQueryTest.php
tests/unit/framework/db/pgsql/PostgreSQLQueryTest.php
+24
-0
PostgreSQLSchemaTest.php
tests/unit/framework/db/pgsql/PostgreSQLSchemaTest.php
+10
-0
No files found.
framework/CHANGELOG.md
View file @
c6274acf
...
...
@@ -57,6 +57,7 @@ Yii Framework 2 Change Log
-
Bug #3863: Fixed incorrect js selector for
`\yii\widgets\ActiveForm::errorSummaryCssClass`
when it contains multiple classes (creocoder, umneeq)
-
Bug #3893: Headers did not overwrite default setting by webserver (cebe)
-
Bug #3909:
`Html::to()`
should not prefix base URL to URLs that already contain scheme (qiangxue)
-
Bug #3920: Fixed issue with loading default values of PostgreSQL boolean columns (cebe)
-
Bug #3934: yii.handleAction() in yii.js does not correctly detect if a hyperlink contains useful URL or not (joni-jones, qiangxue)
-
Bug #3968: Messages logged in shutdown functions are not handled (qiangxue)
-
Bug #3989: Fixed yii
\l
og
\F
ileTarget::$rotateByCopy to avoid any rename (cebe)
...
...
framework/db/pgsql/Schema.php
View file @
c6274acf
...
...
@@ -412,6 +412,8 @@ SQL;
}
elseif
(
$column
->
defaultValue
)
{
if
(
$column
->
type
===
'timestamp'
&&
$column
->
defaultValue
===
'now()'
)
{
$column
->
defaultValue
=
new
Expression
(
$column
->
defaultValue
);
}
elseif
(
$column
->
type
===
'boolean'
)
{
$column
->
defaultValue
=
(
$column
->
defaultValue
===
'true'
);
}
elseif
(
stripos
(
$column
->
dbType
,
'bit'
)
===
0
||
stripos
(
$column
->
dbType
,
'varbit'
)
===
0
)
{
$column
->
defaultValue
=
bindec
(
trim
(
$column
->
defaultValue
,
'B\''
));
}
elseif
(
preg_match
(
"/^'(.*?)'::/"
,
$column
->
defaultValue
,
$matches
))
{
...
...
tests/unit/data/postgres.sql
View file @
c6274acf
...
...
@@ -116,7 +116,9 @@ CREATE TABLE "type" (
CREATE
TABLE
"bool_values"
(
id
serial
not
null
primary
key
,
bool_col
bool
bool_col
bool
,
default_true
bool
not
null
default
true
,
default_false
boolean
not
null
default
false
);
INSERT
INTO
"profile"
(
description
)
VALUES
(
'profile customer 1'
);
...
...
tests/unit/framework/db/pgsql/PostgreSQLActiveRecordTest.php
View file @
c6274acf
...
...
@@ -2,6 +2,7 @@
namespace
yiiunit\framework\db\pgsql
;
use
yiiunit\data\ar\ActiveRecord
;
use
yiiunit\framework\db\ActiveRecordTest
;
/**
...
...
@@ -11,4 +12,53 @@ use yiiunit\framework\db\ActiveRecordTest;
class
PostgreSQLActiveRecordTest
extends
ActiveRecordTest
{
protected
$driverName
=
'pgsql'
;
public
function
testBooleanValues
()
{
$db
=
$this
->
getConnection
();
$command
=
$db
->
createCommand
();
$command
->
batchInsert
(
'bool_values'
,
[
'bool_col'
],
[
[
true
],
[
false
],
]
)
->
execute
();
$this
->
assertEquals
(
1
,
BoolAR
::
find
()
->
where
(
'bool_col = TRUE'
)
->
count
(
'*'
,
$db
));
$this
->
assertEquals
(
1
,
BoolAR
::
find
()
->
where
(
'bool_col = FALSE'
)
->
count
(
'*'
,
$db
));
$this
->
assertEquals
(
2
,
BoolAR
::
find
()
->
where
(
'bool_col IN (TRUE, FALSE)'
)
->
count
(
'*'
,
$db
));
$this
->
assertEquals
(
1
,
BoolAR
::
find
()
->
where
([
'bool_col'
=>
true
])
->
count
(
'*'
,
$db
));
$this
->
assertEquals
(
1
,
BoolAR
::
find
()
->
where
([
'bool_col'
=>
false
])
->
count
(
'*'
,
$db
));
$this
->
assertEquals
(
2
,
BoolAR
::
find
()
->
where
([
'bool_col'
=>
[
true
,
false
]])
->
count
(
'*'
,
$db
));
$this
->
assertEquals
(
1
,
BoolAR
::
find
()
->
where
(
'bool_col = :bool_col'
,
[
'bool_col'
=>
true
])
->
count
(
'*'
,
$db
));
$this
->
assertEquals
(
1
,
BoolAR
::
find
()
->
where
(
'bool_col = :bool_col'
,
[
'bool_col'
=>
false
])
->
count
(
'*'
,
$db
));
$this
->
assertSame
(
true
,
BoolAR
::
find
()
->
where
([
'bool_col'
=>
true
])
->
one
(
$db
)
->
bool_col
);
$this
->
assertSame
(
false
,
BoolAR
::
find
()
->
where
([
'bool_col'
=>
false
])
->
one
(
$db
)
->
bool_col
);
}
public
function
testBooleanDefaultValues
()
{
$model
=
new
BoolAR
();
$this
->
assertNull
(
$model
->
bool_col
);
$this
->
assertNull
(
$model
->
default_true
);
$this
->
assertNull
(
$model
->
default_false
);
$model
->
loadDefaultValues
();
$this
->
assertNull
(
$model
->
bool_col
);
$this
->
assertSame
(
true
,
$model
->
default_true
);
$this
->
assertSame
(
false
,
$model
->
default_false
);
$this
->
assertTrue
(
$model
->
save
(
false
));
}
}
class
BoolAR
extends
ActiveRecord
{
public
static
function
tableName
()
{
return
'bool_values'
;
}
}
\ No newline at end of file
tests/unit/framework/db/pgsql/PostgreSQLQueryTest.php
View file @
c6274acf
...
...
@@ -3,6 +3,7 @@
namespace
yiiunit\framework\db\pgsql
;
use
yii\db\pgsql\Schema
;
use
yii\db\Query
;
use
yiiunit\framework\db\QueryTest
;
use
yiiunit\framework\db\SchemaTest
;
...
...
@@ -13,4 +14,27 @@ use yiiunit\framework\db\SchemaTest;
class
PostgreSQLQueryTest
extends
QueryTest
{
public
$driverName
=
'pgsql'
;
public
function
testBooleanValues
()
{
$db
=
$this
->
getConnection
();
$command
=
$db
->
createCommand
();
$command
->
batchInsert
(
'bool_values'
,
[
'bool_col'
],
[
[
true
],
[
false
],
]
)
->
execute
();
$this
->
assertEquals
(
1
,
(
new
Query
())
->
from
(
'bool_values'
)
->
where
(
'bool_col = TRUE'
)
->
count
(
'*'
,
$db
));
$this
->
assertEquals
(
1
,
(
new
Query
())
->
from
(
'bool_values'
)
->
where
(
'bool_col = FALSE'
)
->
count
(
'*'
,
$db
));
$this
->
assertEquals
(
2
,
(
new
Query
())
->
from
(
'bool_values'
)
->
where
(
'bool_col IN (TRUE, FALSE)'
)
->
count
(
'*'
,
$db
));
$this
->
assertEquals
(
1
,
(
new
Query
())
->
from
(
'bool_values'
)
->
where
([
'bool_col'
=>
true
])
->
count
(
'*'
,
$db
));
$this
->
assertEquals
(
1
,
(
new
Query
())
->
from
(
'bool_values'
)
->
where
([
'bool_col'
=>
false
])
->
count
(
'*'
,
$db
));
$this
->
assertEquals
(
2
,
(
new
Query
())
->
from
(
'bool_values'
)
->
where
([
'bool_col'
=>
[
true
,
false
]])
->
count
(
'*'
,
$db
));
$this
->
assertEquals
(
1
,
(
new
Query
())
->
from
(
'bool_values'
)
->
where
(
'bool_col = :bool_col'
,
[
'bool_col'
=>
true
])
->
count
(
'*'
,
$db
));
$this
->
assertEquals
(
1
,
(
new
Query
())
->
from
(
'bool_values'
)
->
where
(
'bool_col = :bool_col'
,
[
'bool_col'
=>
false
])
->
count
(
'*'
,
$db
));
}
}
tests/unit/framework/db/pgsql/PostgreSQLSchemaTest.php
View file @
c6274acf
...
...
@@ -80,4 +80,14 @@ class PostgreSQLSchemaTest extends SchemaTest
}
fclose
(
$fp
);
}
public
function
testBooleanDefaultValues
()
{
/* @var $schema Schema */
$schema
=
$this
->
getConnection
()
->
schema
;
$table
=
$schema
->
getTableSchema
(
'bool_values'
);
$this
->
assertSame
(
true
,
$table
->
getColumn
(
'default_true'
)
->
defaultValue
);
$this
->
assertSame
(
false
,
$table
->
getColumn
(
'default_false'
)
->
defaultValue
);
}
}
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