Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/SQLite.Net/SQLiteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class SQLiteCommand
private readonly SQLiteConnection _conn;
private readonly ISQLitePlatform _sqlitePlatform;
private const string DateTimeFormat = "yyyy-MM-ddTHH:mm:ss.fffffffZ";
private readonly char[] identifierEscapeCharacters = new [] { '"', '`', '[', ']' };

internal SQLiteCommand(ISQLitePlatform platformImplementation, SQLiteConnection conn)
{
Expand Down Expand Up @@ -128,7 +129,8 @@ public IEnumerable<T> ExecuteDeferredQuery<T>(TableMapping map)
for (var i = 0; i < cols.Length; i++)
{
var name = _sqlitePlatform.SQLiteApi.ColumnName16(stmt, i);
cols[i] = map.FindColumn(name);
var trimmedName = TrimIdentifierKeywordEscapeCharacters(name);
cols[i] = map.FindColumn(trimmedName);
}

while (_sqlitePlatform.SQLiteApi.Step(stmt) == Result.Row)
Expand Down Expand Up @@ -585,6 +587,21 @@ private object ReadCol(IDbStatement stmt, int index, ColType type, Type clrType)
throw new NotSupportedException("Don't know how to read " + clrType);
}

private string TrimIdentifierKeywordEscapeCharacters(string identifier)
{
string trimmedIdentifier = identifier;
if (identifierEscapeCharacters.Contains(trimmedIdentifier[0]))
{
trimmedIdentifier = trimmedIdentifier.Remove(0, 1);
}
int lastCharIndex = trimmedIdentifier.Length - 1;
if (identifierEscapeCharacters.Contains(trimmedIdentifier[lastCharIndex]))
{
trimmedIdentifier = trimmedIdentifier.Remove(lastCharIndex);
}
return trimmedIdentifier;
}

private class Binding
{
[CanBeNull]
Expand Down