Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mssqlnative: drop/alter column not working if column has default constraint #290

Closed
obmsch opened this issue Nov 11, 2016 · 3 comments
Closed
Labels
bug mssqlnative Native driver for SQL Server driver (Tier 1)
Milestone

Comments

@obmsch
Copy link
Contributor

obmsch commented Nov 11, 2016

With MSSQL it is not possible to drop or alter a column with an existing constraint.
This constraint has to be removed before the drop or alter takes place.
In 'datadict-mssqlnative.inc.php' AlterColumnSQL is commented out and DropColumnSQL
doesn't care.

The attached patch tries to remedy this with the smallest possible impact.

  • Fix DropColumnSQL, to allow the drop even with a constraint on that given column.
    We drop so any default doesn't matter.

  • Fix AlterColumnSql, to allow changes if and only if(!) either a 'new' default is
    given for an existing default, or there is no existing one at all. So something
    like 'ALTER TABLE t ALTER COLUMN c INT NOT NULL' with an existing constraint on c
    will still fail. I can't decide, if keep or remove the constraint is implied here.

datadict-mssqlnative.inc.php.patch.txt

@dregad dregad added bug mssqlnative Native driver for SQL Server driver (Tier 1) labels Nov 11, 2016
@dregad
Copy link
Member

dregad commented Nov 11, 2016

@obmsch Thanks for your contribution. If you can, it would be more convenient for us if you could provide your patch as a pull request instead of an attachment.

For the record: this originated from discussion at https://www.mantisbt.org/bugs/view.php?id=21883

@mnewnham it would be great if you could take a look at this.

@obmsch
Copy link
Contributor Author

obmsch commented Nov 14, 2016

Revised patch attached, with handles altering the column with no 'new' default and
an existing default constraint on that column. The existing constraint is dropped now.

datadict-mssqlnative.inc.php.patch.txt

@mnewnham
Copy link
Contributor

As @dregad mentioned, if you could provide us a pull request it would be great. I don't have the means to work with this patch file at the moment.

@dregad dregad added this to the 5.20.8 milestone Dec 17, 2016
dregad pushed a commit that referenced this issue Dec 17, 2016
With MSSQL it is not possible to drop or alter a column with an
existing constraint. The constraint has to be removed before the
operation takes place.

In 'datadict-mssqlnative.inc.php' AlterColumnSQL is commented out and
DropColumnSQL doesn't care.

This tries to fix the problem with the smallest possible impact:

- Fix DropColumnSQL(), to allow the drop even with a constraint on that
  given column. We drop, so any default doesn't matter.
- Fix AlterColumnSql(), to allow changes if (and only if !) either a
  'new' default is given for an existing default, or there is no
  existing one at all. So something like
  'ALTER TABLE t ALTER COLUMN c INT NOT NULL'
  with an existing constraint on c will still fail since it can't be
  determined if keeping or removing the constraint is implied here.

Fixes #290 via #297

Changes to original commit:
- split long lines, whitespace
- Added commit message text from issue #290's description

Signed-off-by: Damien Regad <dregad@mantisbt.org>
@dregad dregad closed this as completed Dec 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mssqlnative Native driver for SQL Server driver (Tier 1)
Projects
None yet
Development

No branches or pull requests

3 participants