Browse Source

#11912: Postgresql negative default values support for integer/float/decimal columns (#11933)

* fixes #11912: Postgresql negative default values support for integer/float/decimal columns

* added more tests

* updated CHANGELOG.md
tags/2.0.10
Evgeniy 8 years ago committed by Carsten Brandt
parent
commit
ad796dbf22
  1. 2
      framework/CHANGELOG.md
  2. 2
      framework/db/pgsql/Schema.php
  3. 9
      tests/data/cubrid.sql
  4. 9
      tests/data/mssql.sql
  5. 9
      tests/data/mysql.sql
  6. 9
      tests/data/oci.sql
  7. 9
      tests/data/postgres.sql
  8. 9
      tests/data/sqlite.sql
  9. 13
      tests/framework/db/SchemaTest.php

2
framework/CHANGELOG.md

@ -4,7 +4,7 @@ Yii Framework 2 Change Log
2.0.10 under development
------------------------
- no changes in this release.
- Bug #11912: Fixed PostgreSQL Schema to support negative default values for integer/float/decimal columns (nsknewbie)

2
framework/db/pgsql/Schema.php

@ -471,7 +471,7 @@ SQL;
$column->defaultValue = bindec(trim($column->defaultValue, 'B\''));
} elseif (preg_match("/^'(.*?)'::/", $column->defaultValue, $matches)) {
$column->defaultValue = $matches[1];
} elseif (preg_match('/^(.*?)::/', $column->defaultValue, $matches)) {
} elseif (preg_match('/^(?:\()?(.*?)(?(1)\))(?:::.+)?$/', $column->defaultValue, $matches)) {
if ($matches[1] === 'NULL') {
$column->defaultValue = null;
} else {

9
tests/data/cubrid.sql

@ -13,6 +13,7 @@ DROP TABLE IF EXISTS "category";
DROP TABLE IF EXISTS "customer";
DROP TABLE IF EXISTS "profile";
DROP TABLE IF EXISTS "null_values";
DROP TABLE IF EXISTS "negative_default_values";
DROP TABLE IF EXISTS "type";
DROP TABLE IF EXISTS "constraints";
DROP TABLE IF EXISTS "animal";
@ -100,6 +101,14 @@ CREATE TABLE null_values (
PRIMARY KEY (id)
);
CREATE TABLE "negative_default_values" (
smallint_col smallint default '-123',
int_col int default '-123',
bigint_col bigint default '-123',
float_col double default '-12345.6789',
numeric_col decimal(5,2) default '-33.22'
);
CREATE TABLE "type" (
"int_col" int(11) NOT NULL,

9
tests/data/mssql.sql

@ -8,6 +8,7 @@ IF OBJECT_ID('[dbo].[customer]', 'U') IS NOT NULL DROP TABLE [dbo].[customer];
IF OBJECT_ID('[dbo].[profile]', 'U') IS NOT NULL DROP TABLE [dbo].[profile];
IF OBJECT_ID('[dbo].[type]', 'U') IS NOT NULL DROP TABLE [dbo].[type];
IF OBJECT_ID('[dbo].[null_values]', 'U') IS NOT NULL DROP TABLE [dbo].[null_values];
IF OBJECT_ID('[dbo].[negative_default_values]', 'U') IS NOT NULL DROP TABLE [dbo].[negative_default_values];
IF OBJECT_ID('[dbo].[animal]', 'U') IS NOT NULL DROP TABLE [dbo].[animal];
IF OBJECT_ID('[dbo].[default_pk]', 'U') IS NOT NULL DROP TABLE [dbo].[default_pk];
IF OBJECT_ID('[dbo].[document]', 'U') IS NOT NULL DROP TABLE [dbo].[document];
@ -96,6 +97,14 @@ CREATE TABLE [dbo].[null_values] (
PRIMARY KEY (id)
);
CREATE TABLE [dbo].[negative_default_values] (
[smallint_col] [tinyint] DEFAULT '-123',
[int_col] [smallint] DEFAULT '-123',
[bigint_col] [int] DEFAULT '-123',
[float_col] [float] DEFAULT '-12345.6789',
[numeric_col] [decimal](5,2) DEFAULT '-33.22'
);
CREATE TABLE [dbo].[type] (
[int_col] [int] NOT NULL,
[int_col2] [int] DEFAULT '1',

9
tests/data/mysql.sql

@ -13,6 +13,7 @@ DROP TABLE IF EXISTS `category` CASCADE;
DROP TABLE IF EXISTS `customer` CASCADE;
DROP TABLE IF EXISTS `profile` CASCADE;
DROP TABLE IF EXISTS `null_values` CASCADE;
DROP TABLE IF EXISTS `negative_default_values` CASCADE;
DROP TABLE IF EXISTS `type` CASCADE;
DROP TABLE IF EXISTS `constraints` CASCADE;
DROP TABLE IF EXISTS `animal` CASCADE;
@ -112,6 +113,14 @@ CREATE TABLE null_values (
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `negative_default_values` (
`smallint_col` smallint default '-123',
`int_col` integer default '-123',
`bigint_col` bigint default '-123',
`float_col` double default '-12345.6789',
`numeric_col` decimal(5,2) default '-33.22'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `type` (
`int_col` integer NOT NULL,
`int_col2` integer DEFAULT '1',

9
tests/data/oci.sql

@ -13,6 +13,7 @@ BEGIN EXECUTE IMMEDIATE 'DROP TABLE "customer"'; EXCEPTION WHEN OTHERS THEN IF S
BEGIN EXECUTE IMMEDIATE 'DROP TABLE "profile"'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;--
BEGIN EXECUTE IMMEDIATE 'DROP TABLE "type"'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;--
BEGIN EXECUTE IMMEDIATE 'DROP TABLE "null_values"'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;--
BEGIN EXECUTE IMMEDIATE 'DROP TABLE "negative_default_values"'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;--
BEGIN EXECUTE IMMEDIATE 'DROP TABLE "constraints"'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;--
BEGIN EXECUTE IMMEDIATE 'DROP TABLE "bool_values"'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;--
BEGIN EXECUTE IMMEDIATE 'DROP TABLE "animal"'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;--
@ -130,6 +131,14 @@ CREATE TABLE "null_values" (
);
CREATE SEQUENCE "null_values_SEQ";
CREATE TABLE "negative_default_values" (
"smallint_col" smallint default -123,
"int_col" integer default -123,
"bigint_col" integer default -123,
"float_col" double precision default -12345.6789,
"numeric_col" decimal(5,2) default -33.22
);
CREATE TABLE "type" (
"int_col" integer NOT NULL,
"int_col2" integer DEFAULT 1,

9
tests/data/postgres.sql

@ -15,6 +15,7 @@ DROP TABLE IF EXISTS "customer" CASCADE;
DROP TABLE IF EXISTS "profile" CASCADE;
DROP TABLE IF EXISTS "type" CASCADE;
DROP TABLE IF EXISTS "null_values" CASCADE;
DROP TABLE IF EXISTS "negative_default_values" CASCADE;
DROP TABLE IF EXISTS "constraints" CASCADE;
DROP TABLE IF EXISTS "bool_values" CASCADE;
DROP TABLE IF EXISTS "animal" CASCADE;
@ -139,6 +140,14 @@ CREATE TABLE "bool_values" (
default_false boolean not null default false
);
CREATE TABLE "negative_default_values" (
smallint_col smallint default '-123',
int_col integer default '-123',
bigint_col bigint default '-123',
float_col double precision default '-12345.6789',
numeric_col decimal(5,2) default '-33.22'
);
CREATE TABLE "animal" (
id serial primary key,
type varchar(255) not null

9
tests/data/sqlite.sql

@ -14,6 +14,7 @@ DROP TABLE IF EXISTS "customer";
DROP TABLE IF EXISTS "profile";
DROP TABLE IF EXISTS "type";
DROP TABLE IF EXISTS "null_values";
DROP TABLE IF EXISTS "negative_default_values";
DROP TABLE IF EXISTS "animal";
DROP TABLE IF EXISTS "default_pk";
DROP TABLE IF EXISTS "document";
@ -95,6 +96,14 @@ CREATE TABLE "null_values" (
stringcol VARCHAR(32) DEFAULT NULL
);
CREATE TABLE "negative_default_values" (
smallint_col integer default '-123',
int_col integer default '-123',
bigint_col integer default '-123',
float_col double default '-12345.6789',
numeric_col decimal(5,2) default '-33.22'
);
CREATE TABLE "type" (
int_col INTEGER NOT NULL,
int_col2 INTEGER DEFAULT '1',

13
tests/framework/db/SchemaTest.php

@ -339,6 +339,19 @@ abstract class SchemaTest extends DatabaseTestCase
];
}
public function testNegativeDefaultValues()
{
/* @var $schema Schema */
$schema = $this->getConnection()->schema;
$table = $schema->getTableSchema('negative_default_values');
$this->assertEquals(-123, $table->getColumn('smallint_col')->defaultValue);
$this->assertEquals(-123, $table->getColumn('int_col')->defaultValue);
$this->assertEquals(-123, $table->getColumn('bigint_col')->defaultValue);
$this->assertEquals(-12345.6789, $table->getColumn('float_col')->defaultValue);
$this->assertEquals(-33.22, $table->getColumn('numeric_col')->defaultValue);
}
public function testColumnSchema()
{
$columns = $this->getExpectedColumns();

Loading…
Cancel
Save