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
1391253a
Commit
1391253a
authored
Jun 25, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed postgres default value parsing
parent
651e6a3f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
12 deletions
+46
-12
Schema.php
framework/db/pgsql/Schema.php
+10
-3
PostgreSQLSchemaTest.php
tests/unit/framework/db/pgsql/PostgreSQLSchemaTest.php
+36
-9
No files found.
framework/db/pgsql/Schema.php
View file @
1391253a
...
...
@@ -7,6 +7,7 @@
namespace
yii\db\pgsql
;
use
yii\db\Expression
;
use
yii\db\TableSchema
;
use
yii\db\ColumnSchema
;
...
...
@@ -408,10 +409,16 @@ SQL;
}
$column
->
defaultValue
=
null
;
}
elseif
(
$column
->
defaultValue
)
{
if
(
stripos
(
$column
->
dbType
,
'bit'
)
===
0
||
stripos
(
$column
->
dbType
,
'varbit'
)
===
0
)
{
if
(
$column
->
type
===
'timestamp'
&&
$column
->
defaultValue
===
'now()'
)
{
$column
->
defaultValue
=
new
Expression
(
$column
->
defaultValue
);
}
elseif
(
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
)
)
{
}
elseif
(
preg_match
(
"/^'(.*?)'::/"
,
$column
->
defaultValue
,
$matches
))
{
$column
->
defaultValue
=
$matches
[
1
];
}
elseif
(
preg_match
(
"/^(.*?)::/"
,
$column
->
defaultValue
,
$matches
))
{
$column
->
defaultValue
=
$column
->
typecast
(
$matches
[
1
]);
}
else
{
$column
->
defaultValue
=
$column
->
typecast
(
$column
->
defaultValue
);
}
}
}
...
...
@@ -438,7 +445,7 @@ SQL;
$column
->
name
=
$info
[
'column_name'
];
$column
->
precision
=
$info
[
'numeric_precision'
];
$column
->
scale
=
$info
[
'numeric_scale'
];
$column
->
size
=
$info
[
'size'
];
$column
->
size
=
$info
[
'size'
]
===
null
?
null
:
(
int
)
$info
[
'size'
]
;
if
(
isset
(
$this
->
typeMap
[
$column
->
dbType
]))
{
$column
->
type
=
$this
->
typeMap
[
$column
->
dbType
];
}
else
{
...
...
tests/unit/framework/db/pgsql/PostgreSQLSchemaTest.php
View file @
1391253a
...
...
@@ -2,6 +2,7 @@
namespace
yiiunit\framework\db\pgsql
;
use
yii\db\Expression
;
use
yii\db\pgsql\Schema
;
use
yiiunit\framework\db\SchemaTest
;
...
...
@@ -17,17 +18,43 @@ class PostgreSQLSchemaTest extends SchemaTest
{
$columns
=
parent
::
getExpectedColumns
();
unset
(
$columns
[
'enum_col'
]);
$columns
[
'int_col'
][
'dbType'
]
=
'int
eger
'
;
$columns
[
'int_col'
][
'dbType'
]
=
'int
4
'
;
$columns
[
'int_col'
][
'size'
]
=
null
;
$columns
[
'int_col'
][
'precision'
]
=
null
;
$columns
[
'int_col2'
][
'dbType'
]
=
'integer'
;
$columns
[
'int_col'
][
'precision'
]
=
32
;
$columns
[
'int_col'
][
'scale'
]
=
0
;
$columns
[
'int_col2'
][
'dbType'
]
=
'int4'
;
$columns
[
'int_col2'
][
'size'
]
=
null
;
$columns
[
'int_col2'
][
'precision'
]
=
null
;
$columns
[
'bool_col'
][
'type'
]
=
'boolean'
;
$columns
[
'bool_col'
][
'phpType'
]
=
'boolean'
;
$columns
[
'bool_col2'
][
'type'
]
=
'boolean'
;
$columns
[
'bool_col2'
][
'phpType'
]
=
'boolean'
;
$columns
[
'bool_col2'
][
'defaultValue'
]
=
true
;
$columns
[
'int_col2'
][
'precision'
]
=
32
;
$columns
[
'int_col2'
][
'scale'
]
=
0
;
$columns
[
'char_col'
][
'dbType'
]
=
'bpchar'
;
$columns
[
'char_col'
][
'precision'
]
=
null
;
$columns
[
'char_col2'
][
'dbType'
]
=
'varchar'
;
$columns
[
'char_col2'
][
'precision'
]
=
null
;
$columns
[
'float_col'
][
'dbType'
]
=
'float8'
;
$columns
[
'float_col'
][
'precision'
]
=
53
;
$columns
[
'float_col'
][
'scale'
]
=
null
;
$columns
[
'float_col'
][
'size'
]
=
null
;
$columns
[
'float_col2'
][
'dbType'
]
=
'float8'
;
$columns
[
'float_col2'
][
'precision'
]
=
53
;
$columns
[
'float_col2'
][
'scale'
]
=
null
;
$columns
[
'float_col2'
][
'size'
]
=
null
;
$columns
[
'blob_col'
][
'dbType'
]
=
'bytea'
;
$columns
[
'blob_col'
][
'phpType'
]
=
'resource'
;
$columns
[
'blob_col'
][
'type'
]
=
'binary'
;
$columns
[
'numeric_col'
][
'dbType'
]
=
'numeric'
;
$columns
[
'numeric_col'
][
'size'
]
=
null
;
$columns
[
'bool_col'
][
'dbType'
]
=
'int2'
;
$columns
[
'bool_col'
][
'size'
]
=
null
;
$columns
[
'bool_col'
][
'precision'
]
=
16
;
$columns
[
'bool_col'
][
'scale'
]
=
0
;
$columns
[
'bool_col2'
][
'dbType'
]
=
'int2'
;
$columns
[
'bool_col2'
][
'size'
]
=
null
;
$columns
[
'bool_col2'
][
'precision'
]
=
16
;
$columns
[
'bool_col2'
][
'scale'
]
=
0
;
$columns
[
'ts_default'
][
'defaultValue'
]
=
new
Expression
(
'now()'
);
$columns
[
'bit_col'
][
'dbType'
]
=
'bit'
;
$columns
[
'bit_col'
][
'size'
]
=
1
;
// TODO should be 8???
$columns
[
'bit_col'
][
'precision'
]
=
null
;
return
$columns
;
}
}
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