diff --git a/src/SQLite.Net/SQLiteCommand.cs b/src/SQLite.Net/SQLiteCommand.cs index 9db0d705b..53e6fa2c5 100755 --- a/src/SQLite.Net/SQLiteCommand.cs +++ b/src/SQLite.Net/SQLiteCommand.cs @@ -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) { @@ -128,7 +129,8 @@ public IEnumerable ExecuteDeferredQuery(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) @@ -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]