Skip to content

Commit 3181f80

Browse files
authored
Merge pull request #111 from msallin/#107
Fix for #107.
2 parents d31b747 + 709c90b commit 3181f80

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

SQLite.CodeFirst.Console/Entity/Stadion.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@ public class Stadion
1818
[Key]
1919
[Column(Order = 3)]
2020
public string City { get; set; }
21+
22+
[Column(Order = 4)]
23+
[Index("ReservedKeyWordTest", IsUnique = true)]
24+
public int Order { get; set; }
2125
}
2226
}

SQLite.CodeFirst.Test/IntegrationTests/SqlGenerationTest.cs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class SqlGenerationTest
1717
@"CREATE TABLE ""MyTable"" ([Id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [Name] nvarchar NOT NULL, FOREIGN KEY (Id) REFERENCES ""Coaches""(Id));
1818
CREATE TABLE ""Coaches"" ([Id] INTEGER PRIMARY KEY, [FirstName] nvarchar (50) COLLATE NOCASE, [LastName] nvarchar (50), [Street] nvarchar (100), [City] nvarchar NOT NULL, [CreatedUtc] datetime NOT NULL DEFAULT (DATETIME('now')));
1919
CREATE TABLE ""TeamPlayer"" ([Id] INTEGER PRIMARY KEY, [Number] int NOT NULL, [TeamId] int NOT NULL, [FirstName] nvarchar (50) COLLATE NOCASE, [LastName] nvarchar (50), [Street] nvarchar (100), [City] nvarchar NOT NULL, [CreatedUtc] datetime NOT NULL DEFAULT (DATETIME('now')), [Mentor_Id] int, FOREIGN KEY (Mentor_Id) REFERENCES ""TeamPlayer""(Id), FOREIGN KEY (TeamId) REFERENCES ""MyTable""(Id) ON DELETE CASCADE);
20-
CREATE TABLE ""Stadions"" ([Name] nvarchar (128) NOT NULL, [Street] nvarchar (128) NOT NULL, [City] nvarchar (128) NOT NULL, [Team_Id] int NOT NULL, PRIMARY KEY(Name, Street, City), FOREIGN KEY (Team_Id) REFERENCES ""MyTable""(Id) ON DELETE CASCADE);
20+
CREATE TABLE ""Stadions"" ([Name] nvarchar (128) NOT NULL, [Street] nvarchar (128) NOT NULL, [City] nvarchar (128) NOT NULL, [Order] int NOT NULL, [Team_Id] int NOT NULL, PRIMARY KEY(Name, Street, City), FOREIGN KEY (Team_Id) REFERENCES ""MyTable""(Id) ON DELETE CASCADE);
2121
CREATE TABLE ""Foos"" ([FooId] INTEGER PRIMARY KEY, [Name] nvarchar, [FooSelf1Id] int, [FooSelf2Id] int, [FooSelf3Id] int, FOREIGN KEY (FooSelf1Id) REFERENCES ""Foos""(FooId), FOREIGN KEY (FooSelf2Id) REFERENCES ""Foos""(FooId), FOREIGN KEY (FooSelf3Id) REFERENCES ""Foos""(FooId));
2222
CREATE TABLE ""FooSelves"" ([FooSelfId] INTEGER PRIMARY KEY, [FooId] int NOT NULL, [Number] int NOT NULL, FOREIGN KEY (FooId) REFERENCES ""Foos""(FooId) ON DELETE CASCADE);
2323
CREATE TABLE ""FooSteps"" ([FooStepId] INTEGER PRIMARY KEY, [FooId] int NOT NULL, [Number] int NOT NULL, FOREIGN KEY (FooId) REFERENCES ""Foos""(FooId) ON DELETE CASCADE);
@@ -26,22 +26,23 @@ public class SqlGenerationTest
2626
CREATE TABLE ""FooRelationshipBs"" ([Id] INTEGER PRIMARY KEY, [Name] nvarchar (255));
2727
CREATE TABLE ""FooRelationshipAFooCompositeKeys"" ([FooRelationshipA_Id] int NOT NULL, [FooCompositeKey_Id] int NOT NULL, [FooCompositeKey_Version] nvarchar (20) NOT NULL, PRIMARY KEY(FooRelationshipA_Id, FooCompositeKey_Id, FooCompositeKey_Version), FOREIGN KEY (FooRelationshipA_Id) REFERENCES ""FooRelationshipAs""(Id) ON DELETE CASCADE, FOREIGN KEY (FooCompositeKey_Id, FooCompositeKey_Version) REFERENCES ""FooCompositeKeys""(Id, Version) ON DELETE CASCADE);
2828
CREATE TABLE ""FooRelationshipBFooCompositeKeys"" ([FooRelationshipB_Id] int NOT NULL, [FooCompositeKey_Id] int NOT NULL, [FooCompositeKey_Version] nvarchar (20) NOT NULL, PRIMARY KEY(FooRelationshipB_Id, FooCompositeKey_Id, FooCompositeKey_Version), FOREIGN KEY (FooRelationshipB_Id) REFERENCES ""FooRelationshipBs""(Id) ON DELETE CASCADE, FOREIGN KEY (FooCompositeKey_Id, FooCompositeKey_Version) REFERENCES ""FooCompositeKeys""(Id, Version) ON DELETE CASCADE);
29-
CREATE INDEX ""IX_MyTable_Id"" ON ""MyTable"" (Id);
30-
CREATE INDEX ""IX_Team_TeamsName"" ON ""MyTable"" (Name);
31-
CREATE INDEX ""IX_TeamPlayer_Number"" ON ""TeamPlayer"" (Number);
32-
CREATE UNIQUE INDEX ""IX_TeamPlayer_NumberPerTeam"" ON ""TeamPlayer"" (Number, TeamId);
33-
CREATE INDEX ""IX_TeamPlayer_Mentor_Id"" ON ""TeamPlayer"" (Mentor_Id);
34-
CREATE UNIQUE INDEX ""IX_Stadion_Main"" ON ""Stadions"" (Street, Name);
35-
CREATE INDEX ""IX_Stadion_Team_Id"" ON ""Stadions"" (Team_Id);
36-
CREATE INDEX ""IX_Foo_FooSelf1Id"" ON ""Foos"" (FooSelf1Id);
37-
CREATE INDEX ""IX_Foo_FooSelf2Id"" ON ""Foos"" (FooSelf2Id);
38-
CREATE INDEX ""IX_Foo_FooSelf3Id"" ON ""Foos"" (FooSelf3Id);
39-
CREATE INDEX ""IX_FooSelf_FooId"" ON ""FooSelves"" (FooId);
40-
CREATE INDEX ""IX_FooStep_FooId"" ON ""FooSteps"" (FooId);
41-
CREATE INDEX ""IX_FooRelationshipAFooCompositeKey_FooRelationshipA_Id"" ON ""FooRelationshipAFooCompositeKeys"" (FooRelationshipA_Id);
42-
CREATE INDEX ""IX_FooRelationshipAFooCompositeKey_FooCompositeKey_Id_FooCompositeKey_Version"" ON ""FooRelationshipAFooCompositeKeys"" (FooCompositeKey_Id, FooCompositeKey_Version);
43-
CREATE INDEX ""IX_FooRelationshipBFooCompositeKey_FooRelationshipB_Id"" ON ""FooRelationshipBFooCompositeKeys"" (FooRelationshipB_Id);
44-
CREATE INDEX ""IX_FooRelationshipBFooCompositeKey_FooCompositeKey_Id_FooCompositeKey_Version"" ON ""FooRelationshipBFooCompositeKeys"" (FooCompositeKey_Id, FooCompositeKey_Version);";
29+
CREATE INDEX ""IX_MyTable_Id"" ON ""MyTable"" (""Id"");
30+
CREATE INDEX ""IX_Team_TeamsName"" ON ""MyTable"" (""Name"");
31+
CREATE INDEX ""IX_TeamPlayer_Number"" ON ""TeamPlayer"" (""Number"");
32+
CREATE UNIQUE INDEX ""IX_TeamPlayer_NumberPerTeam"" ON ""TeamPlayer"" (""Number"", ""TeamId"");
33+
CREATE INDEX ""IX_TeamPlayer_Mentor_Id"" ON ""TeamPlayer"" (""Mentor_Id"");
34+
CREATE UNIQUE INDEX ""IX_Stadion_Main"" ON ""Stadions"" (""Street"", ""Name"");
35+
CREATE UNIQUE INDEX ""ReservedKeyWordTest"" ON ""Stadions"" (""Order"");
36+
CREATE INDEX ""IX_Stadion_Team_Id"" ON ""Stadions"" (""Team_Id"");
37+
CREATE INDEX ""IX_Foo_FooSelf1Id"" ON ""Foos"" (""FooSelf1Id"");
38+
CREATE INDEX ""IX_Foo_FooSelf2Id"" ON ""Foos"" (""FooSelf2Id"");
39+
CREATE INDEX ""IX_Foo_FooSelf3Id"" ON ""Foos"" (""FooSelf3Id"");
40+
CREATE INDEX ""IX_FooSelf_FooId"" ON ""FooSelves"" (""FooId"");
41+
CREATE INDEX ""IX_FooStep_FooId"" ON ""FooSteps"" (""FooId"");
42+
CREATE INDEX ""IX_FooRelationshipAFooCompositeKey_FooRelationshipA_Id"" ON ""FooRelationshipAFooCompositeKeys"" (""FooRelationshipA_Id"");
43+
CREATE INDEX ""IX_FooRelationshipAFooCompositeKey_FooCompositeKey_Id_FooCompositeKey_Version"" ON ""FooRelationshipAFooCompositeKeys"" (""FooCompositeKey_Id"", ""FooCompositeKey_Version"");
44+
CREATE INDEX ""IX_FooRelationshipBFooCompositeKey_FooRelationshipB_Id"" ON ""FooRelationshipBFooCompositeKeys"" (""FooRelationshipB_Id"");
45+
CREATE INDEX ""IX_FooRelationshipBFooCompositeKey_FooCompositeKey_Id_FooCompositeKey_Version"" ON ""FooRelationshipBFooCompositeKeys"" (""FooCompositeKey_Id"", ""FooCompositeKey_Version"");";
4546

4647
private static string generatedSql;
4748

SQLite.CodeFirst/Internal/Statement/CreateIndexStatement.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
5+
using SQLite.CodeFirst.Builder.NameCreators;
56

67
namespace SQLite.CodeFirst.Statement
78
{
@@ -23,7 +24,7 @@ public string CreateStatement()
2324
stringBuilder.Replace("{index-name}", Name);
2425
stringBuilder.Replace("{table-name}", Table);
2526

26-
IEnumerable<string> orderedColumnNames = Columns.OrderBy(c => c.Order).Select(c => c.Name);
27+
IEnumerable<string> orderedColumnNames = Columns.OrderBy(c => c.Order).Select(c => c.Name).Select(NameCreator.EscapeName);
2728
string columnDefinition = String.Join(ColumnNameSeperator, orderedColumnNames);
2829
stringBuilder.Replace("{column-def}", columnDefinition);
2930

0 commit comments

Comments
 (0)