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
651e6a3f
Commit
651e6a3f
authored
Jun 25, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added support for BIT default values
fixes #422
parent
4f95fcd9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
42 additions
and
10 deletions
+42
-10
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
Schema.php
framework/db/cubrid/Schema.php
+13
-2
Schema.php
framework/db/mysql/Schema.php
+3
-1
Schema.php
framework/db/pgsql/Schema.php
+6
-4
cubrid.sql
tests/unit/data/cubrid.sql
+2
-1
mysql.sql
tests/unit/data/mysql.sql
+2
-1
postgres.sql
tests/unit/data/postgres.sql
+2
-1
SchemaTest.php
tests/unit/framework/db/SchemaTest.php
+12
-0
SqliteSchemaTest.php
tests/unit/framework/db/sqlite/SqliteSchemaTest.php
+1
-0
No files found.
framework/CHANGELOG.md
View file @
651e6a3f
...
...
@@ -57,6 +57,7 @@ Yii Framework 2 Change Log
-
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)
-
Bug: Fixed Object of class Imagick could not be converted to string in CaptchaAction (eXprojects, cebe)
-
Enh #422: Added Support for BIT(M) data type default values in Schema (cebe)
-
Enh #2264:
`CookieCollection::has()`
will return false for expired or removed cookies (qiangxue)
-
Enh #2435:
`yii\db\IntegrityException`
is now thrown on database integrity errors instead of general
`yii\db\Exception`
(samdark)
-
Enh #2558: Enhanced support for memcached by adding
`yii\caching\MemCache::persistentId`
and
`yii\caching\MemCache::options`
(qiangxue)
...
...
framework/db/cubrid/Schema.php
View file @
651e6a3f
...
...
@@ -55,8 +55,8 @@ class Schema extends \yii\db\Schema
'blob'
=>
self
::
TYPE_BINARY
,
'clob'
=>
self
::
TYPE_BINARY
,
// Bit string data types
'bit'
=>
self
::
TYPE_
STRING
,
'bit varying'
=>
self
::
TYPE_
STRING
,
'bit'
=>
self
::
TYPE_
INTEGER
,
'bit varying'
=>
self
::
TYPE_
INTEGER
,
// Collection data types (considered strings for now)
'set'
=>
self
::
TYPE_STRING
,
'multiset'
=>
self
::
TYPE_STRING
,
...
...
@@ -223,6 +223,15 @@ class Schema extends \yii\db\Schema
if
(
isset
(
$values
[
1
]))
{
$column
->
scale
=
(
int
)
$values
[
1
];
}
if
(
$column
->
size
===
1
&&
$type
===
'bit'
)
{
$column
->
type
=
'boolean'
;
}
elseif
(
$type
===
'bit'
)
{
if
(
$column
->
size
>
32
)
{
$column
->
type
=
'bigint'
;
}
elseif
(
$column
->
size
===
32
)
{
$column
->
type
=
'integer'
;
}
}
}
}
}
...
...
@@ -239,6 +248,8 @@ class Schema extends \yii\db\Schema
$column
->
type
===
'time'
&&
$info
[
'Default'
]
===
'SYS_TIME'
)
{
$column
->
defaultValue
=
new
Expression
(
$info
[
'Default'
]);
}
elseif
(
isset
(
$type
)
&&
$type
===
'bit'
)
{
$column
->
defaultValue
=
hexdec
(
trim
(
$info
[
'Default'
],
'X\''
));
}
else
{
$column
->
defaultValue
=
$column
->
typecast
(
$info
[
'Default'
]);
}
...
...
framework/db/mysql/Schema.php
View file @
651e6a3f
...
...
@@ -24,7 +24,7 @@ class Schema extends \yii\db\Schema
*/
public
$typeMap
=
[
'tinyint'
=>
self
::
TYPE_SMALLINT
,
'bit'
=>
self
::
TYPE_
SMALLINT
,
'bit'
=>
self
::
TYPE_
INTEGER
,
'smallint'
=>
self
::
TYPE_SMALLINT
,
'mediumint'
=>
self
::
TYPE_INTEGER
,
'int'
=>
self
::
TYPE_INTEGER
,
...
...
@@ -172,6 +172,8 @@ class Schema extends \yii\db\Schema
if
(
!
$column
->
isPrimaryKey
)
{
if
(
$column
->
type
===
'timestamp'
&&
$info
[
'Default'
]
===
'CURRENT_TIMESTAMP'
)
{
$column
->
defaultValue
=
new
Expression
(
'CURRENT_TIMESTAMP'
);
}
elseif
(
isset
(
$type
)
&&
$type
===
'bit'
)
{
$column
->
defaultValue
=
bindec
(
trim
(
$info
[
'Default'
],
'b\''
));
}
else
{
$column
->
defaultValue
=
$column
->
typecast
(
$info
[
'Default'
]);
}
...
...
framework/db/pgsql/Schema.php
View file @
651e6a3f
...
...
@@ -29,9 +29,9 @@ class Schema extends \yii\db\Schema
* @see http://www.postgresql.org/docs/current/static/datatype.html#DATATYPE-TABLE
*/
public
$typeMap
=
[
'bit'
=>
self
::
TYPE_
STRING
,
'bit varying'
=>
self
::
TYPE_
STRING
,
'varbit'
=>
self
::
TYPE_
STRING
,
'bit'
=>
self
::
TYPE_
INTEGER
,
'bit varying'
=>
self
::
TYPE_
INTEGER
,
'varbit'
=>
self
::
TYPE_
INTEGER
,
'bool'
=>
self
::
TYPE_BOOLEAN
,
'boolean'
=>
self
::
TYPE_BOOLEAN
,
...
...
@@ -408,7 +408,9 @@ SQL;
}
$column
->
defaultValue
=
null
;
}
elseif
(
$column
->
defaultValue
)
{
if
(
preg_match
(
"/^'(.*?)'::/"
,
$column
->
defaultValue
,
$matches
)
||
preg_match
(
"/^(.*?)::/"
,
$column
->
defaultValue
,
$matches
))
{
if
(
stripos
(
$column
->
dbType
,
'bit'
)
===
0
||
stripos
(
$column
->
dbType
,
'varbit'
)
===
0
)
{
$column
->
defaultValue
=
bindec
(
trim
(
$column
->
defaultValue
,
'B\''
));
}
elseif
(
preg_match
(
"/^'(.*?)'::/"
,
$column
->
defaultValue
,
$matches
)
||
preg_match
(
"/^(.*?)::/"
,
$column
->
defaultValue
,
$matches
))
{
$column
->
defaultValue
=
$matches
[
1
];
}
}
...
...
tests/unit/data/cubrid.sql
View file @
651e6a3f
...
...
@@ -111,7 +111,8 @@ CREATE TABLE "type" (
"time"
timestamp
NOT
NULL
DEFAULT
'2002-01-01 00:00:00'
,
"bool_col"
tinyint
NOT
NULL
,
"bool_col2"
tinyint
DEFAULT
'1'
,
"ts_default"
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
"ts_default"
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
"bit_col"
BIT
(
8
)
NOT
NULL
DEFAULT
b
'10000010'
);
CREATE
TABLE
"composite_fk"
(
...
...
tests/unit/data/mysql.sql
View file @
651e6a3f
...
...
@@ -121,7 +121,8 @@ CREATE TABLE `type` (
`time`
timestamp
NOT
NULL
DEFAULT
'2002-01-01 00:00:00'
,
`bool_col`
tinyint
(
1
)
NOT
NULL
,
`bool_col2`
tinyint
(
1
)
DEFAULT
'1'
,
`ts_default`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
`ts_default`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`bit_col`
BIT
(
8
)
NOT
NULL
DEFAULT
b
'10000010'
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
INSERT
INTO
`profile`
(
description
)
VALUES
(
'profile customer 1'
);
...
...
tests/unit/data/postgres.sql
View file @
651e6a3f
...
...
@@ -100,7 +100,8 @@ CREATE TABLE "type" (
time
timestamp
NOT
NULL
DEFAULT
'2002-01-01 00:00:00'
,
bool_col
smallint
NOT
NULL
,
bool_col2
smallint
DEFAULT
'1'
,
ts_default
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
ts_default
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
bit_col
BIT
NOT
NULL
DEFAULT
B
'10000010'
);
INSERT
INTO
"profile"
(
description
)
VALUES
(
'profile customer 1'
);
...
...
tests/unit/framework/db/SchemaTest.php
View file @
651e6a3f
...
...
@@ -263,6 +263,18 @@ class SchemaTest extends DatabaseTestCase
'scale'
=>
null
,
'defaultValue'
=>
new
Expression
(
'CURRENT_TIMESTAMP'
),
],
'bit_col'
=>
[
'type'
=>
'integer'
,
'dbType'
=>
'bit(8)'
,
'phpType'
=>
'integer'
,
'allowNull'
=>
false
,
'autoIncrement'
=>
false
,
'enumValues'
=>
null
,
'size'
=>
8
,
'precision'
=>
8
,
'scale'
=>
null
,
'defaultValue'
=>
130
,
// b'10000010'
],
];
}
...
...
tests/unit/framework/db/sqlite/SqliteSchemaTest.php
View file @
651e6a3f
...
...
@@ -15,6 +15,7 @@ class SqliteSchemaTest extends SchemaTest
{
$columns
=
parent
::
getExpectedColumns
();
unset
(
$columns
[
'enum_col'
]);
unset
(
$columns
[
'bit_col'
]);
$columns
[
'int_col'
][
'dbType'
]
=
'integer'
;
$columns
[
'int_col'
][
'size'
]
=
null
;
$columns
[
'int_col'
][
'precision'
]
=
null
;
...
...
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