Skip to content

Commit

Permalink
Don't attempt to apply AUTOINCREMENT for non-identity, primary key co…
Browse files Browse the repository at this point in the history
…lumns in Sqlite. Fixes issue #1737
  • Loading branch information
schambers committed Mar 15, 2024
1 parent 6720e1b commit 7da19ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ protected override string FormatIdentity(ColumnDefinition column)
throw new ArgumentException($"Cannot create identity constraint on column {column.Name}. SQLite only supports identity on a single integer, primary key column.");
}

return "AUTOINCREMENT";
if (column.IsPrimaryKey) {
return "AUTOINCREMENT";
}
}

return string.Empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ public void IsEscapingTableNameCorrectlyOnColumnExists()
Processor.ColumnExists(null, _tableNameThatMustBeEscaped, columnName).ShouldBeTrue();
}

[Test]
public void PrimaryKeyNonIdentityColumnsSupported()
{
var expression = new CreateTableExpression { TableName = _tableName };
expression.Columns.Add(new ColumnDefinition {Name = "Id", Type = DbType.Int32, IsPrimaryKey = false, IsIdentity = true, IsNullable = false });
expression.Columns.Add(new ColumnDefinition {Name = "Key1", Type = DbType.String, IsPrimaryKey = true, IsIdentity = false, IsNullable = false });
expression.Columns.Add(new ColumnDefinition {Name = "Key2", Type = DbType.String, IsPrimaryKey = true, IsIdentity = false, IsNullable = false });

Processor.Process(expression);
Processor.ColumnExists(null, _tableName, "Id").ShouldBeTrue();
Processor.ColumnExists(null, _tableName, "Key1").ShouldBeTrue();
Processor.ColumnExists(null, _tableName, "Key2").ShouldBeTrue();
}

[Test]
public void AGuidCanBeInsertedAndReadAgain([Values] bool binaryGuid)
{
Expand Down

0 comments on commit 7da19ee

Please sign in to comment.