Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed SQL Server Platform NULL declaration #229

Closed
wants to merge 1 commit into from

3 participants

@Lusitanian

In SQL Server, 'DEFAULT NULL' is invalid for allowing a column to be null -- the 'NULL' keyword is the only required indicator of nullability.

David Desberg Fixed SQL Server Platform NULL declaration
In SQL Server, 'DEFAULT NULL' is invalid for allowing a column to be null -- the 'NULL' keyword is the only required indicator of nullability.
24d228a
@doctrinebot
Collaborator

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DBAL-386

@doctrinebot
Collaborator

Oh btw, I just (automatically) realized that you are not creating this pull request against the master branch.

Unless there are good reasons for this, i would suggest to close and rebase the Pull Request against master and then create it again. Sorry!

@Lusitanian

@doctrinebot The reason for it being based on 2.2 is that it's a bug fix and should be put into earlier versions of the DBAL as well.

@beberlei
Owner

@Lusitanian yes, but we merge bugfixes from master to the stable branches for you. Please rebase onto master and add some tests into tests/Doctrine/DBAL/Tests/Platforms/SQLServerPlatformTest.php

@Lusitanian

Alright, will do shortly :)

@Lusitanian Lusitanian closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 21, 2012
  1. Fixed SQL Server Platform NULL declaration

    David Desberg authored
    In SQL Server, 'DEFAULT NULL' is invalid for allowing a column to be null -- the 'NULL' keyword is the only required indicator of nullability.
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 0 deletions.
  1. +27 −0 lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
View
27 lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
@@ -862,4 +862,31 @@ public function getBlobTypeDeclarationSQL(array $field)
{
return 'VARBINARY(MAX)';
}
+
+ /**
+ * Obtain DBMS specific SQL code portion needed to set a default value
+ * declaration to be used in statements like CREATE TABLE.
+ *
+ * @param array $field field definition array
+ *
+ * @return string DBMS specific SQL code portion needed to set a default value
+ */
+ public function getDefaultValueDeclarationSQL($field)
+ {
+ $default = empty($field['notnull']) ? ' NULL' : '';
+
+ if (isset($field['default'])) {
+ $default = " DEFAULT '".$field['default']."'";
+ if (isset($field['type'])) {
+ if (in_array((string)$field['type'], array("Integer", "BigInteger", "SmallInteger"))) {
+ $default = " DEFAULT ".$field['default'];
+ } else if ((string)$field['type'] == 'DateTime' && $field['default'] == $this->getCurrentTimestampSQL()) {
+ $default = " DEFAULT ".$this->getCurrentTimestampSQL();
+ } else if ((string) $field['type'] == 'Boolean') {
+ $default = " DEFAULT '" . $this->convertBooleans($field['default']) . "'";
+ }
+ }
+ }
+ return $default;
+ }
}
Something went wrong with that request. Please try again.