Skip to content

Commit c687b88

Browse files
committed
Removing unused methods. Refactored object deserialization to make it support better type creation.
1 parent 11ecdb7 commit c687b88

File tree

6 files changed

+10
-70
lines changed

6 files changed

+10
-70
lines changed

SQLite.Net.Tests/DefaultAttributeTest.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,6 @@ public object GetValue(MemberInfo m, object obj)
9696
};
9797
}
9898

99-
public bool TryBindParameter(ISQLiteApi isqLite3Api, IDbStatement stmt, int index, object value)
100-
{
101-
return false;
102-
}
103-
104-
public bool TryGetSqliteColumnType(Type type, out string sqliteType)
105-
{
106-
sqliteType = string.Empty;
107-
return false;
108-
}
109-
110-
public bool TryReadCol(ISQLiteApi isqLite3Api, IDbStatement stmt, int index, Type clrType, out object? value)
111-
{
112-
value = null;
113-
return false;
114-
}
115-
11699
public bool IsIgnored(MemberInfo p)
117100
{
118101
return false;

SQLite.Net.Tests/IgnoreTest.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,6 @@ public object GetValue(MemberInfo m, object obj)
5454
};
5555
}
5656

57-
public bool TryBindParameter(ISQLiteApi isqLite3Api, IDbStatement stmt, int index, object value)
58-
{
59-
return false;
60-
}
61-
62-
public bool TryGetSqliteColumnType(Type type, out string sqliteType)
63-
{
64-
sqliteType = string.Empty;
65-
return false;
66-
}
67-
68-
public bool TryReadCol(ISQLiteApi isqLite3Api, IDbStatement stmt, int index, Type clrType, out object? value)
69-
{
70-
value = null;
71-
return false;
72-
}
73-
7457
public bool IsIgnored(MemberInfo p)
7558
{
7659
return p.IsDefined(typeof (TestIgnoreAttribute), true);

src/SQLite.Net/Orm.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,6 @@ private static string SqlType(TableMapping.Column p, bool storeDateTimeAsTicks,
134134
{
135135
return "text";
136136
}
137-
if (ColumnInformationProvider.TryGetSqliteColumnType(clrType, out var result))
138-
{
139-
return result;
140-
}
141137
if (serializer != null && serializer.CanDeserialize(clrType))
142138
{
143139
return "blob";

src/SQLite.Net/SQLiteCommand.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,14 @@ public IEnumerable<T> ExecuteDeferredQuery<T>(TableMapping map)
171171

172172
while (sqlite.Step(stmt) == Result.Row)
173173
{
174-
var obj = isPrimitiveType ? null : _conn.Resolver.CreateObject(map.MappedType);
175-
if (_conn.ColumnInformationProvider.TryReadObject(obj, sqlite, stmt))
174+
var obj = _conn.ColumnInformationProvider.TryReadObject(map, sqlite, stmt);
175+
if (obj != null)
176176
{
177177
yield return (T)obj;
178178
}
179179
else
180180
{
181+
obj = isPrimitiveType ? null : _conn.Resolver.CreateObject(map.MappedType);
181182
for (var i = 0; i < cols.Length; i++)
182183
{
183184
ColType colType;
@@ -443,10 +444,6 @@ internal static void BindParameter(ISQLiteApi isqLite3Api, IDbStatement stmt, in
443444
isqLite3Api.BindText16(stmt, index, val, -1, NegativePointer);
444445
}
445446
}
446-
else if (Orm.ColumnInformationProvider.TryBindParameter(isqLite3Api, stmt, index, value))
447-
{
448-
return;
449-
}
450447
else if (value.GetType().GetTypeInfo().IsEnum)
451448
{
452449
isqLite3Api.BindInt(stmt, index, Convert.ToInt32(value));
@@ -634,10 +631,6 @@ private object ReadCol(IDbStatement stmt, int index, ColType type, Type clrType)
634631
var value = (sbyte) sqlite.ColumnInt(stmt, index);
635632
return _conn.Resolver.CreateObject(clrType, new object[] {value});
636633
}
637-
if (_conn.ColumnInformationProvider.TryReadCol(sqlite, stmt, index, clrType, out var obj))
638-
{
639-
return obj!;
640-
}
641634
if (clrType == typeof (byte[]))
642635
{
643636
return sqlite.ColumnByteArray(stmt, index).ToArray();

src/SQLite.Net/Tools/DefaultColumnInformationProvider.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,6 @@ public object GetValue(MemberInfo m, object obj)
132132
_ => throw new NotSupportedException($"{m.GetType()} is not supported.")
133133
};
134134
}
135-
136-
public virtual bool TryBindParameter(ISQLiteApi isqLite3Api, IDbStatement stmt, int index, object value)
137-
{
138-
return false;
139-
}
140-
141-
public virtual bool TryGetSqliteColumnType(Type type, out string sqliteType)
142-
{
143-
sqliteType = string.Empty;
144-
return false;
145-
}
146-
147-
public virtual bool TryReadCol(ISQLiteApi isqLite3Api, IDbStatement stmt, int index, Type clrType, out object? value)
148-
{
149-
value = null;
150-
return false;
151-
}
152135
#endregion
153136
}
154137
}

src/SQLite.Net/Tools/IColumnInformationProvider.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ public interface IColumnInformationProvider
1717
string GetColumnName(Type containedType, MemberInfo p, int tupleElementIndex);
1818
Type GetMemberType(MemberInfo m);
1919
object GetValue(MemberInfo m, object obj);
20+
2021
/// <summary>
21-
/// Attempts to read an object from <see cref="stmt"/>. Returns true if successful.
22+
/// Attempts to read an object from <see cref="stmt"/>. Returns non-null if the object is supported.
2223
/// </summary>
23-
bool TryReadObject(object obj, ISQLiteApi sqLiteApi, IDbStatement stmt) => false;
24-
bool TryBindParameter(ISQLiteApi isqLite3Api, IDbStatement stmt, int index, object value);
25-
bool TryGetSqliteColumnType(Type type, out string sqliteType);
26-
bool TryReadCol(ISQLiteApi isqLite3Api, IDbStatement stmt, int index, Type clrType, out object? value);
24+
/// <param name="mapping">Table mapping for the type to return</param>
25+
/// <param name="sqLiteApi">SQLite API</param>
26+
/// <param name="stmt">Statement row to read from.</param>
27+
/// <returns>An object or null if the table/type is not supported.</returns>
28+
object? TryReadObject(TableMapping mapping, ISQLiteApi sqLiteApi, IDbStatement stmt) => null;
2729
}
2830
}
2931

0 commit comments

Comments
 (0)