Skip to content

Commit

Permalink
SQLite Scaffolding: Reverse engineer collation
Browse files Browse the repository at this point in the history
  • Loading branch information
bricelam committed Dec 14, 2022
1 parent 3a62379 commit 3a25db7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ ORDER BY "cid"

_logger.ColumnFound(table.Name, columnName, dataType, notNull, defaultValue);

string? collation = null;
var autoIncrement = 0;
if (connection is SqliteConnection sqliteConnection
&& !(table is DatabaseView))
Expand All @@ -241,7 +242,7 @@ ORDER BY "cid"
table.Name,
columnName,
out _,
out _,
out collation,
out _,
out _,
out autoIncrement);
Expand All @@ -264,7 +265,10 @@ ORDER BY "cid"
: string.Empty,
IsStored = hidden != 3L
? default(bool?)
: true
: true,
Collation = string.Equals(collation, "BINARY", StringComparison.OrdinalIgnoreCase)
? null
: collation
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,26 @@ CREATE TABLE AutoIncTest (
},
"DROP TABLE AutoIncTest");

[ConditionalFact]
public void Column_collation_is_set()
=> Test(
@"
CREATE TABLE ColumnsWithCollation (
Id int,
DefaultCollation text,
NonDefaultCollation text COLLATE NOCASE
);",
Enumerable.Empty<string>(),
Enumerable.Empty<string>(),
dbModel =>
{
var columns = dbModel.Tables.Single().Columns;

Assert.Null(columns.Single(c => c.Name == "DefaultCollation").Collation);
Assert.Equal("NOCASE", columns.Single(c => c.Name == "NonDefaultCollation").Collation);
},
"DROP TABLE ColumnsWithCollation;");

#endregion

#region PrimaryKeyFacets
Expand Down

0 comments on commit 3a25db7

Please sign in to comment.