Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing unused methods. Refactored object deserialization to make it support better type creation. #22

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
17 changes: 0 additions & 17 deletions SQLite.Net.Tests/DefaultAttributeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,6 @@ public object GetValue(MemberInfo m, object obj)
};
}

public bool TryBindParameter(ISQLiteApi isqLite3Api, IDbStatement stmt, int index, object value)
{
return false;
}

public bool TryGetSqliteColumnType(Type type, out string sqliteType)
{
sqliteType = string.Empty;
return false;
}

public bool TryReadCol(ISQLiteApi isqLite3Api, IDbStatement stmt, int index, Type clrType, out object? value)
{
value = null;
return false;
}

public bool IsIgnored(MemberInfo p)
{
return false;
Expand Down
17 changes: 0 additions & 17 deletions SQLite.Net.Tests/IgnoreTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,6 @@ public object GetValue(MemberInfo m, object obj)
};
}

public bool TryBindParameter(ISQLiteApi isqLite3Api, IDbStatement stmt, int index, object value)
{
return false;
}

public bool TryGetSqliteColumnType(Type type, out string sqliteType)
{
sqliteType = string.Empty;
return false;
}

public bool TryReadCol(ISQLiteApi isqLite3Api, IDbStatement stmt, int index, Type clrType, out object? value)
{
value = null;
return false;
}

public bool IsIgnored(MemberInfo p)
{
return p.IsDefined(typeof (TestIgnoreAttribute), true);
Expand Down
4 changes: 0 additions & 4 deletions src/SQLite.Net/Orm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ private static string SqlType(TableMapping.Column p, bool storeDateTimeAsTicks,
{
return "text";
}
if (ColumnInformationProvider.TryGetSqliteColumnType(clrType, out var result))
{
return result;
}
if (serializer != null && serializer.CanDeserialize(clrType))
{
return "blob";
Expand Down
2 changes: 1 addition & 1 deletion src/SQLite.Net/SQLite.Net2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<Title>sqlite-net2 light ORM for SQLite</Title>
<Description>sqlite-net2 allows applications to manage data in SQLite databases using Entity Framework like queries, but much lighter</Description>
<Product>$(AssemblyName) ($(TargetFramework))</Product>
<VersionSuffix>.10</VersionSuffix>
<VersionSuffix>.11</VersionSuffix>
<PackageVersion>$(Version)$(VersionSuffix)</PackageVersion>
<Authors>Benjamin Mayrargue</Authors>
<Owners>Benjamin Mayrargue</Owners>
Expand Down
13 changes: 3 additions & 10 deletions src/SQLite.Net/SQLiteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,14 @@ public IEnumerable<T> ExecuteDeferredQuery<T>(TableMapping map)

while (sqlite.Step(stmt) == Result.Row)
{
var obj = isPrimitiveType ? null : _conn.Resolver.CreateObject(map.MappedType);
if (_conn.ColumnInformationProvider.TryReadObject(obj, sqlite, stmt))
var obj = _conn.ColumnInformationProvider.TryReadObject(map, sqlite, stmt);
if (obj != null)
{
yield return (T)obj;
}
else
{
obj = isPrimitiveType ? null : _conn.Resolver.CreateObject(map.MappedType);
for (var i = 0; i < cols.Length; i++)
{
ColType colType;
Expand Down Expand Up @@ -443,10 +444,6 @@ internal static void BindParameter(ISQLiteApi isqLite3Api, IDbStatement stmt, in
isqLite3Api.BindText16(stmt, index, val, -1, NegativePointer);
}
}
else if (Orm.ColumnInformationProvider.TryBindParameter(isqLite3Api, stmt, index, value))
{
return;
}
else if (value.GetType().GetTypeInfo().IsEnum)
{
isqLite3Api.BindInt(stmt, index, Convert.ToInt32(value));
Expand Down Expand Up @@ -634,10 +631,6 @@ private object ReadCol(IDbStatement stmt, int index, ColType type, Type clrType)
var value = (sbyte) sqlite.ColumnInt(stmt, index);
return _conn.Resolver.CreateObject(clrType, new object[] {value});
}
if (_conn.ColumnInformationProvider.TryReadCol(sqlite, stmt, index, clrType, out var obj))
{
return obj!;
}
if (clrType == typeof (byte[]))
{
return sqlite.ColumnByteArray(stmt, index).ToArray();
Expand Down
17 changes: 0 additions & 17 deletions src/SQLite.Net/Tools/DefaultColumnInformationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,6 @@ public object GetValue(MemberInfo m, object obj)
_ => throw new NotSupportedException($"{m.GetType()} is not supported.")
};
}

public virtual bool TryBindParameter(ISQLiteApi isqLite3Api, IDbStatement stmt, int index, object value)
{
return false;
}

public virtual bool TryGetSqliteColumnType(Type type, out string sqliteType)
{
sqliteType = string.Empty;
return false;
}

public virtual bool TryReadCol(ISQLiteApi isqLite3Api, IDbStatement stmt, int index, Type clrType, out object? value)
{
value = null;
return false;
}
#endregion
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/SQLite.Net/Tools/IColumnInformationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ public interface IColumnInformationProvider
string GetColumnName(Type containedType, MemberInfo p, int tupleElementIndex);
Type GetMemberType(MemberInfo m);
object GetValue(MemberInfo m, object obj);

/// <summary>
/// Attempts to read an object from <see cref="stmt"/>. Returns true if successful.
/// Attempts to read an object from <see cref="stmt"/>. Returns non-null if the object is supported.
/// </summary>
bool TryReadObject(object obj, ISQLiteApi sqLiteApi, IDbStatement stmt) => false;
bool TryBindParameter(ISQLiteApi isqLite3Api, IDbStatement stmt, int index, object value);
bool TryGetSqliteColumnType(Type type, out string sqliteType);
bool TryReadCol(ISQLiteApi isqLite3Api, IDbStatement stmt, int index, Type clrType, out object? value);
/// <param name="mapping">Table mapping for the type to return</param>
/// <param name="sqLiteApi">SQLite API</param>
/// <param name="stmt">Statement row to read from.</param>
/// <returns>An object or null if the table/type is not supported.</returns>
object? TryReadObject(TableMapping mapping, ISQLiteApi sqLiteApi, IDbStatement stmt) => null;
}
}

Loading