Skip to content

NH-3749 - Unnecessary comma in CREATE TABLE statement #1037

@nhibernate-bot

Description

@nhibernate-bot

Alexey Lesnyh created an issue — 20th January 2015, 13:25:42:

I develop NHibernate Driver for DBMS Linter SQL and found a problem in file Nhibernate\Mapping\Table.cs. The problem is in the following code:

foreach (UniqueKey uk in UniqueKeyIterator) 
{ 
	buf.Append(',').Append(uk.SqlConstraintString(dialect)); 
}

This code produces unnecessary comma in CREATE TABLE statement if dialect doesn't support not null unique constraints. For example, in test Nhibernate.Test.Component.Basic.ComponentWithUniqueConstraintTests.CanBePersistedWithUniqueValues we have the following query:

create table Employee (Id BIGINT not null, Name VARCHAR(255) null, Dob DATE null, HireDate DATE null, primary key (Id),); 

I suggest that we check property dialect.SupportsNotNullUnique before running foreach loop. Something like this:

if (dialect.SupportsNotNullUnique)
{
	foreach (UniqueKey uk in UniqueKeyIterator)
	{
		buf.Append(',').Append(uk.SqlConstraintString(dialect));
	}
}

Ricardo Peres added a comment — 20th January 2015, 13:36:30:

Can you submit a pull request with your solution and a unit test? It makes it easier to test and integrate.


Alexey Lesnyh added a comment — 20th January 2015, 13:37:09:

I've created a pull request:
#393

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions