Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Tomáš Trávníček
doctrine-dbal
Commits
9eef7c86
Unverified
Commit
9eef7c86
authored
May 22, 2019
by
Sergei Morozov
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'bpo/2.9/#3547' into 2.9
parents
9a352c80
ed759f54
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
47 deletions
+81
-47
SQLServerPlatform.php
lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
+0
-31
DefaultExpressionTest.php
.../Tests/DBAL/Functional/Platform/DefaultExpressionTest.php
+78
-0
SQLServerSchemaManagerTest.php
...sts/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php
+2
-15
AbstractSQLServerPlatformTestCase.php
...ests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php
+1
-1
No files found.
lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
View file @
9eef7c86
...
@@ -10,7 +10,6 @@ use Doctrine\DBAL\Schema\Identifier;
...
@@ -10,7 +10,6 @@ use Doctrine\DBAL\Schema\Identifier;
use
Doctrine\DBAL\Schema\Index
;
use
Doctrine\DBAL\Schema\Index
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\TableDiff
;
use
Doctrine\DBAL\Schema\TableDiff
;
use
Doctrine\DBAL\Types
;
use
InvalidArgumentException
;
use
InvalidArgumentException
;
use
function
array_merge
;
use
function
array_merge
;
use
function
array_unique
;
use
function
array_unique
;
...
@@ -1591,36 +1590,6 @@ SQL
...
@@ -1591,36 +1590,6 @@ SQL
return
'VARBINARY(MAX)'
;
return
'VARBINARY(MAX)'
;
}
}
/**
* {@inheritDoc}
*/
public
function
getDefaultValueDeclarationSQL
(
$field
)
{
if
(
!
isset
(
$field
[
'default'
]))
{
return
empty
(
$field
[
'notnull'
])
?
' NULL'
:
''
;
}
if
(
!
isset
(
$field
[
'type'
]))
{
return
" DEFAULT '"
.
$field
[
'default'
]
.
"'"
;
}
$type
=
$field
[
'type'
];
if
(
$type
instanceof
Types\PhpIntegerMappingType
)
{
return
' DEFAULT '
.
$field
[
'default'
];
}
if
(
$type
instanceof
Types\PhpDateTimeMappingType
&&
$field
[
'default'
]
===
$this
->
getCurrentTimestampSQL
())
{
return
' DEFAULT '
.
$this
->
getCurrentTimestampSQL
();
}
if
(
$type
instanceof
Types\BooleanType
)
{
return
" DEFAULT '"
.
$this
->
convertBooleans
(
$field
[
'default'
])
.
"'"
;
}
return
" DEFAULT '"
.
$field
[
'default'
]
.
"'"
;
}
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*
*
...
...
tests/Doctrine/Tests/DBAL/Functional/Platform/DefaultExpressionTest.php
0 → 100644
View file @
9eef7c86
<?php
declare
(
strict_types
=
1
);
namespace
Doctrine\Tests\DBAL\Functional\Platform
;
use
Doctrine\DBAL\FetchMode
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Platforms\MySqlPlatform
;
use
Doctrine\DBAL\Platforms\OraclePlatform
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\Tests\DbalFunctionalTestCase
;
use
function
sprintf
;
class
DefaultExpressionTest
extends
DbalFunctionalTestCase
{
public
function
testCurrentDate
()
:
void
{
$platform
=
$this
->
connection
->
getDatabasePlatform
();
if
(
$platform
instanceof
MySqlPlatform
)
{
self
::
markTestSkipped
(
'Not supported on MySQL'
);
}
$this
->
assertDefaultExpression
(
Type
::
DATE
,
static
function
(
AbstractPlatform
$platform
)
:
string
{
return
$platform
->
getCurrentDateSQL
();
});
}
public
function
testCurrentTime
()
:
void
{
$platform
=
$this
->
connection
->
getDatabasePlatform
();
if
(
$platform
instanceof
MySqlPlatform
)
{
self
::
markTestSkipped
(
'Not supported on MySQL'
);
}
if
(
$platform
instanceof
OraclePlatform
)
{
self
::
markTestSkipped
(
'Not supported on Oracle'
);
}
$this
->
assertDefaultExpression
(
Type
::
TIME
,
static
function
(
AbstractPlatform
$platform
)
:
string
{
return
$platform
->
getCurrentTimeSQL
();
});
}
public
function
testCurrentTimestamp
()
:
void
{
$this
->
assertDefaultExpression
(
Type
::
DATETIME
,
static
function
(
AbstractPlatform
$platform
)
:
string
{
return
$platform
->
getCurrentTimestampSQL
();
});
}
private
function
assertDefaultExpression
(
string
$type
,
callable
$expression
)
:
void
{
$platform
=
$this
->
connection
->
getDatabasePlatform
();
$defaultSql
=
$expression
(
$platform
,
$this
);
$table
=
new
Table
(
'default_expr_test'
);
$table
->
addColumn
(
'actual_value'
,
$type
);
$table
->
addColumn
(
'default_value'
,
$type
,
[
'default'
=>
$defaultSql
]);
$this
->
connection
->
getSchemaManager
()
->
dropAndCreateTable
(
$table
);
$this
->
connection
->
exec
(
sprintf
(
'INSERT INTO default_expr_test (actual_value) VALUES (%s)'
,
$defaultSql
)
);
[
$actualValue
,
$defaultValue
]
=
$this
->
connection
->
query
(
'SELECT default_value, actual_value FROM default_expr_test'
)
->
fetch
(
FetchMode
::
NUMERIC
);
self
::
assertEquals
(
$actualValue
,
$defaultValue
);
}
}
tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php
View file @
9eef7c86
...
@@ -54,8 +54,7 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
...
@@ -54,8 +54,7 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
public
function
testDefaultConstraints
()
public
function
testDefaultConstraints
()
{
{
$platform
=
$this
->
schemaManager
->
getDatabasePlatform
();
$table
=
new
Table
(
'sqlsrv_default_constraints'
);
$table
=
new
Table
(
'sqlsrv_default_constraints'
);
$table
->
addColumn
(
'no_default'
,
'string'
);
$table
->
addColumn
(
'no_default'
,
'string'
);
$table
->
addColumn
(
'df_integer'
,
'integer'
,
[
'default'
=>
666
]);
$table
->
addColumn
(
'df_integer'
,
'integer'
,
[
'default'
=>
666
]);
$table
->
addColumn
(
'df_string_1'
,
'string'
,
[
'default'
=>
'foobar'
]);
$table
->
addColumn
(
'df_string_1'
,
'string'
,
[
'default'
=>
'foobar'
]);
...
@@ -63,8 +62,6 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
...
@@ -63,8 +62,6 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
$table
->
addColumn
(
'df_string_3'
,
'string'
,
[
'default'
=>
'another default value'
]);
$table
->
addColumn
(
'df_string_3'
,
'string'
,
[
'default'
=>
'another default value'
]);
$table
->
addColumn
(
'df_string_4'
,
'string'
,
[
'default'
=>
'column to rename'
]);
$table
->
addColumn
(
'df_string_4'
,
'string'
,
[
'default'
=>
'column to rename'
]);
$table
->
addColumn
(
'df_boolean'
,
'boolean'
,
[
'default'
=>
true
]);
$table
->
addColumn
(
'df_boolean'
,
'boolean'
,
[
'default'
=>
true
]);
$table
->
addColumn
(
'df_current_date'
,
'date'
,
[
'default'
=>
$platform
->
getCurrentDateSQL
()]);
$table
->
addColumn
(
'df_current_time'
,
'time'
,
[
'default'
=>
$platform
->
getCurrentTimeSQL
()]);
$this
->
schemaManager
->
createTable
(
$table
);
$this
->
schemaManager
->
createTable
(
$table
);
$columns
=
$this
->
schemaManager
->
listTableColumns
(
'sqlsrv_default_constraints'
);
$columns
=
$this
->
schemaManager
->
listTableColumns
(
'sqlsrv_default_constraints'
);
...
@@ -75,12 +72,10 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
...
@@ -75,12 +72,10 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
self
::
assertEquals
(
'Doctrine rocks!!!'
,
$columns
[
'df_string_2'
]
->
getDefault
());
self
::
assertEquals
(
'Doctrine rocks!!!'
,
$columns
[
'df_string_2'
]
->
getDefault
());
self
::
assertEquals
(
'another default value'
,
$columns
[
'df_string_3'
]
->
getDefault
());
self
::
assertEquals
(
'another default value'
,
$columns
[
'df_string_3'
]
->
getDefault
());
self
::
assertEquals
(
1
,
$columns
[
'df_boolean'
]
->
getDefault
());
self
::
assertEquals
(
1
,
$columns
[
'df_boolean'
]
->
getDefault
());
self
::
assertSame
(
$platform
->
getCurrentDateSQL
(),
$columns
[
'df_current_date'
]
->
getDefault
());
self
::
assertSame
(
$platform
->
getCurrentTimeSQL
(),
$columns
[
'df_current_time'
]
->
getDefault
());
$diff
=
new
TableDiff
(
$diff
=
new
TableDiff
(
'sqlsrv_default_constraints'
,
'sqlsrv_default_constraints'
,
[
new
Column
(
'df_current_timestamp'
,
Type
::
getType
(
'datetime'
),
[
'default'
=>
'CURRENT_TIMESTAMP'
])
],
[],
[
[
'df_integer'
=>
new
ColumnDiff
(
'df_integer'
=>
new
ColumnDiff
(
'df_integer'
,
'df_integer'
,
...
@@ -126,7 +121,6 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
...
@@ -126,7 +121,6 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
$columns
=
$this
->
schemaManager
->
listTableColumns
(
'sqlsrv_default_constraints'
);
$columns
=
$this
->
schemaManager
->
listTableColumns
(
'sqlsrv_default_constraints'
);
self
::
assertNull
(
$columns
[
'no_default'
]
->
getDefault
());
self
::
assertNull
(
$columns
[
'no_default'
]
->
getDefault
());
self
::
assertEquals
(
'CURRENT_TIMESTAMP'
,
$columns
[
'df_current_timestamp'
]
->
getDefault
());
self
::
assertEquals
(
0
,
$columns
[
'df_integer'
]
->
getDefault
());
self
::
assertEquals
(
0
,
$columns
[
'df_integer'
]
->
getDefault
());
self
::
assertNull
(
$columns
[
'df_string_2'
]
->
getDefault
());
self
::
assertNull
(
$columns
[
'df_string_2'
]
->
getDefault
());
self
::
assertEquals
(
'another default value'
,
$columns
[
'df_string_3'
]
->
getDefault
());
self
::
assertEquals
(
'another default value'
,
$columns
[
'df_string_3'
]
->
getDefault
());
...
@@ -140,12 +134,6 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
...
@@ -140,12 +134,6 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
'sqlsrv_default_constraints'
,
'sqlsrv_default_constraints'
,
[],
[],
[
[
'df_current_timestamp'
=>
new
ColumnDiff
(
'df_current_timestamp'
,
new
Column
(
'df_current_timestamp'
,
Type
::
getType
(
'datetime'
)),
[
'default'
],
new
Column
(
'df_current_timestamp'
,
Type
::
getType
(
'datetime'
),
[
'default'
=>
'CURRENT_TIMESTAMP'
])
),
'df_integer'
=>
new
ColumnDiff
(
'df_integer'
=>
new
ColumnDiff
(
'df_integer'
,
'df_integer'
,
new
Column
(
'df_integer'
,
Type
::
getType
(
'integer'
),
[
'default'
=>
666
]),
new
Column
(
'df_integer'
,
Type
::
getType
(
'integer'
),
[
'default'
=>
666
]),
...
@@ -163,7 +151,6 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
...
@@ -163,7 +151,6 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this
->
schemaManager
->
alterTable
(
$diff
);
$this
->
schemaManager
->
alterTable
(
$diff
);
$columns
=
$this
->
schemaManager
->
listTableColumns
(
'sqlsrv_default_constraints'
);
$columns
=
$this
->
schemaManager
->
listTableColumns
(
'sqlsrv_default_constraints'
);
self
::
assertNull
(
$columns
[
'df_current_timestamp'
]
->
getDefault
());
self
::
assertEquals
(
666
,
$columns
[
'df_integer'
]
->
getDefault
());
self
::
assertEquals
(
666
,
$columns
[
'df_integer'
]
->
getDefault
());
}
}
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php
View file @
9eef7c86
...
@@ -1494,7 +1494,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
...
@@ -1494,7 +1494,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
];
];
self
::
assertSame
(
self
::
assertSame
(
" DEFAULT '"
.
$currentDateSql
.
"'"
,
' DEFAULT CONVERT(date, GETDATE())'
,
$this
->
platform
->
getDefaultValueDeclarationSQL
(
$field
)
$this
->
platform
->
getDefaultValueDeclarationSQL
(
$field
)
);
);
}
}
...
...
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