Revert cleanup

This commit is contained in:
Natsumi
2023-06-07 18:14:29 +12:00
parent f674b61b73
commit 09c4087ed4

243
SQLite.cs
View File

@@ -407,7 +407,7 @@ namespace SQLite
Handle = handle; Handle = handle;
if (r != SQLite3.Result.OK) { if (r != SQLite3.Result.OK) {
throw SQLiteException.New (r, string.Format ("Could not open database file: {0} ({1})", DatabasePath, r)); throw SQLiteException.New (r, String.Format ("Could not open database file: {0} ({1})", DatabasePath, r));
} }
_open = true; _open = true;
@@ -505,6 +505,7 @@ namespace SQLite
{ {
var utf8Length = System.Text.Encoding.UTF8.GetByteCount (s); var utf8Length = System.Text.Encoding.UTF8.GetByteCount (s);
var bytes = new byte [utf8Length + 1]; var bytes = new byte [utf8Length + 1];
utf8Length = System.Text.Encoding.UTF8.GetBytes(s, 0, s.Length, bytes, 0);
return bytes; return bytes;
} }
#endif #endif
@@ -815,7 +816,7 @@ namespace SQLite
public int CreateIndex (string indexName, string tableName, string[] columnNames, bool unique = false) public int CreateIndex (string indexName, string tableName, string[] columnNames, bool unique = false)
{ {
const string sqlFormat = "create {2} index if not exists \"{3}\" on \"{0}\"(\"{1}\")"; const string sqlFormat = "create {2} index if not exists \"{3}\" on \"{0}\"(\"{1}\")";
var sql = string.Format (sqlFormat, tableName, string.Join ("\", \"", columnNames), unique ? "unique" : string.Empty, indexName); var sql = String.Format (sqlFormat, tableName, string.Join ("\", \"", columnNames), unique ? "unique" : string.Empty, indexName);
return Execute (sql); return Execute (sql);
} }
@@ -1488,7 +1489,7 @@ namespace SQLite
// Rolling back without a TO clause rolls backs all transactions // Rolling back without a TO clause rolls backs all transactions
// and leaves the transaction stack empty. // and leaves the transaction stack empty.
try { try {
if (string.IsNullOrEmpty (savepoint)) { if (String.IsNullOrEmpty (savepoint)) {
if (Interlocked.Exchange (ref _transactionDepth, 0) > 0) { if (Interlocked.Exchange (ref _transactionDepth, 0) > 0) {
Execute ("rollback"); Execute ("rollback");
} }
@@ -1540,23 +1541,22 @@ namespace SQLite
// Validate the savepoint // Validate the savepoint
int firstLen = savepoint.IndexOf ('D'); int firstLen = savepoint.IndexOf ('D');
if (firstLen >= 2 && savepoint.Length > firstLen + 1) { if (firstLen >= 2 && savepoint.Length > firstLen + 1) {
if (int.TryParse(savepoint.Substring(firstLen + 1), out int depth)) int depth;
{ if (Int32.TryParse (savepoint.Substring (firstLen + 1), out depth)) {
// TODO: Mild race here, but inescapable without locking almost everywhere. // TODO: Mild race here, but inescapable without locking almost everywhere.
if (0 <= depth && depth < _transactionDepth) if (0 <= depth && depth < _transactionDepth) {
{
#if NETFX_CORE || USE_SQLITEPCL_RAW || NETCORE #if NETFX_CORE || USE_SQLITEPCL_RAW || NETCORE
Volatile.Write (ref _transactionDepth, depth); Volatile.Write (ref _transactionDepth, depth);
#elif SILVERLIGHT #elif SILVERLIGHT
_transactionDepth = depth; _transactionDepth = depth;
#else #else
Thread.VolatileWrite(ref _transactionDepth, depth); Thread.VolatileWrite (ref _transactionDepth, depth);
#endif #endif
Execute(cmd + savepoint); Execute (cmd + savepoint);
return; return;
} }
} }
} }
throw new ArgumentException ("savePoint is not valid, and should be the result of a call to SaveTransactionPoint.", "savePoint"); throw new ArgumentException ("savePoint is not valid, and should be the result of a call to SaveTransactionPoint.", "savePoint");
} }
@@ -2231,8 +2231,10 @@ namespace SQLite
void OnTableChanged (TableMapping table, NotifyTableChangedAction action) void OnTableChanged (TableMapping table, NotifyTableChangedAction action)
{ {
TableChanged?.Invoke(this, new NotifyTableChangedEventArgs(table, action)); var ev = TableChanged;
} if (ev != null)
ev (this, new NotifyTableChangedEventArgs (table, action));
}
public event EventHandler<NotifyTableChangedEventArgs> TableChanged; public event EventHandler<NotifyTableChangedEventArgs> TableChanged;
} }
@@ -2642,7 +2644,9 @@ namespace SQLite
public void SetAutoIncPK (object obj, long id) public void SetAutoIncPK (object obj, long id)
{ {
_autoPk?.SetValue (obj, Convert.ChangeType (id, _autoPk.ColumnType, null)); if (_autoPk != null) {
_autoPk.SetValue (obj, Convert.ChangeType (id, _autoPk.ColumnType, null));
}
} }
public Column[] InsertColumns { public Column[] InsertColumns {
@@ -2674,7 +2678,7 @@ namespace SQLite
public class Column public class Column
{ {
private readonly MemberInfo _member; MemberInfo _member;
public string Name { get; private set; } public string Name { get; private set; }
@@ -2830,13 +2834,13 @@ namespace SQLite
public static EnumCacheInfo GetInfo (Type type) public static EnumCacheInfo GetInfo (Type type)
{ {
lock (Cache) { lock (Cache) {
if (!Cache.TryGetValue(type, out EnumCacheInfo info)) EnumCacheInfo info = null;
{ if (!Cache.TryGetValue (type, out info)) {
info = new EnumCacheInfo(type); info = new EnumCacheInfo (type);
Cache[type] = info; Cache[type] = info;
} }
return info; return info;
} }
} }
} }
@@ -2851,9 +2855,10 @@ namespace SQLite
{ {
if (obj == null) if (obj == null)
return typeof (object); return typeof (object);
if (obj is IReflectableType rt) var rt = obj as IReflectableType;
return rt.GetTypeInfo().AsType(); if (rt != null)
return obj.GetType (); return rt.GetTypeInfo ().AsType ();
return obj.GetType ();
} }
public static string SqlDecl (TableMapping.Column p, bool storeDateTimeAsTicks, bool storeTimeSpanAsTicks) public static string SqlDecl (TableMapping.Column p, bool storeDateTimeAsTicks, bool storeTimeSpanAsTicks)
@@ -2879,13 +2884,13 @@ namespace SQLite
public static string SqlType (TableMapping.Column p, bool storeDateTimeAsTicks, bool storeTimeSpanAsTicks) public static string SqlType (TableMapping.Column p, bool storeDateTimeAsTicks, bool storeTimeSpanAsTicks)
{ {
var clrType = p.ColumnType; var clrType = p.ColumnType;
if (clrType == typeof (bool) || clrType == typeof (byte) || clrType == typeof (ushort) || clrType == typeof (sbyte) || clrType == typeof (short) || clrType == typeof (int) || clrType == typeof (uint) || clrType == typeof (long)) { if (clrType == typeof (Boolean) || clrType == typeof (Byte) || clrType == typeof (UInt16) || clrType == typeof (SByte) || clrType == typeof (Int16) || clrType == typeof (Int32) || clrType == typeof (UInt32) || clrType == typeof (Int64)) {
return "integer"; return "integer";
} }
else if (clrType == typeof (float) || clrType == typeof (double) || clrType == typeof (decimal)) { else if (clrType == typeof (Single) || clrType == typeof (Double) || clrType == typeof (Decimal)) {
return "float"; return "float";
} }
else if (clrType == typeof (string) || clrType == typeof (StringBuilder) || clrType == typeof (Uri) || clrType == typeof (UriBuilder)) { else if (clrType == typeof (String) || clrType == typeof (StringBuilder) || clrType == typeof (Uri) || clrType == typeof (UriBuilder)) {
int? len = p.MaxStringLength; int? len = p.MaxStringLength;
if (len.HasValue) if (len.HasValue)
@@ -3019,8 +3024,8 @@ namespace SQLite
public partial class SQLiteCommand public partial class SQLiteCommand
{ {
private readonly SQLiteConnection _conn; SQLiteConnection _conn;
private readonly List<Binding> _bindings; private List<Binding> _bindings;
public string CommandText { get; set; } public string CommandText { get; set; }
@@ -3037,9 +3042,10 @@ namespace SQLite
_conn.Tracer?.Invoke ("Executing: " + this); _conn.Tracer?.Invoke ("Executing: " + this);
} }
var stmt = Prepare (); var r = SQLite3.Result.OK;
var r = SQLite3.Step(stmt); var stmt = Prepare ();
Finalize (stmt); r = SQLite3.Step (stmt);
Finalize (stmt);
if (r == SQLite3.Result.Done) { if (r == SQLite3.Result.Done) {
int rowsAffected = SQLite3.Changes (_conn.Handle); int rowsAffected = SQLite3.Changes (_conn.Handle);
return rowsAffected; return rowsAffected;
@@ -3153,7 +3159,7 @@ namespace SQLite
_conn.Tracer?.Invoke ("Executing Query: " + this); _conn.Tracer?.Invoke ("Executing Query: " + this);
} }
T val = default; T val = default (T);
var stmt = Prepare (); var stmt = Prepare ();
@@ -3193,7 +3199,7 @@ namespace SQLite
var colType = SQLite3.ColumnType (stmt, 0); var colType = SQLite3.ColumnType (stmt, 0);
var val = ReadCol (stmt, 0, colType, typeof (T)); var val = ReadCol (stmt, 0, colType, typeof (T));
if (val == null) { if (val == null) {
yield return default; yield return default (T);
} }
else { else {
yield return (T)val; yield return (T)val;
@@ -3265,57 +3271,57 @@ namespace SQLite
SQLite3.BindNull (stmt, index); SQLite3.BindNull (stmt, index);
} }
else { else {
if (value is int) { if (value is Int32) {
SQLite3.BindInt (stmt, index, (int)value); SQLite3.BindInt (stmt, index, (int)value);
} }
else if (value is string) { else if (value is String) {
SQLite3.BindText (stmt, index, (string)value, -1, NegativePointer); SQLite3.BindText (stmt, index, (string)value, -1, NegativePointer);
} }
else if (value is byte || value is ushort || value is sbyte || value is short) { else if (value is Byte || value is UInt16 || value is SByte || value is Int16) {
SQLite3.BindInt (stmt, index, Convert.ToInt32 (value)); SQLite3.BindInt (stmt, index, Convert.ToInt32 (value));
} }
else if (value is bool) { else if (value is Boolean) {
SQLite3.BindInt (stmt, index, (bool)value ? 1 : 0); SQLite3.BindInt (stmt, index, (bool)value ? 1 : 0);
} }
else if (value is uint || value is long) { else if (value is UInt32 || value is Int64) {
SQLite3.BindInt64 (stmt, index, Convert.ToInt64 (value)); SQLite3.BindInt64 (stmt, index, Convert.ToInt64 (value));
} }
else if (value is float || value is double || value is decimal) { else if (value is Single || value is Double || value is Decimal) {
SQLite3.BindDouble (stmt, index, Convert.ToDouble (value)); SQLite3.BindDouble (stmt, index, Convert.ToDouble (value));
} }
else if (value is TimeSpan span) { else if (value is TimeSpan) {
if (storeTimeSpanAsTicks) { if (storeTimeSpanAsTicks) {
SQLite3.BindInt64 (stmt, index, span.Ticks); SQLite3.BindInt64 (stmt, index, ((TimeSpan)value).Ticks);
} }
else { else {
SQLite3.BindText (stmt, index, span.ToString (), -1, NegativePointer); SQLite3.BindText (stmt, index, ((TimeSpan)value).ToString (), -1, NegativePointer);
} }
} }
else if (value is DateTime time) { else if (value is DateTime) {
if (storeDateTimeAsTicks) { if (storeDateTimeAsTicks) {
SQLite3.BindInt64 (stmt, index, time.Ticks); SQLite3.BindInt64 (stmt, index, ((DateTime)value).Ticks);
} }
else { else {
SQLite3.BindText (stmt, index, time.ToString (dateTimeStringFormat, System.Globalization.CultureInfo.InvariantCulture), -1, NegativePointer); SQLite3.BindText (stmt, index, ((DateTime)value).ToString (dateTimeStringFormat, System.Globalization.CultureInfo.InvariantCulture), -1, NegativePointer);
} }
} }
else if (value is DateTimeOffset offset) { else if (value is DateTimeOffset) {
SQLite3.BindInt64 (stmt, index, offset.UtcTicks); SQLite3.BindInt64 (stmt, index, ((DateTimeOffset)value).UtcTicks);
} }
else if (value is byte[] v) { else if (value is byte[]) {
SQLite3.BindBlob (stmt, index, v, v.Length, NegativePointer); SQLite3.BindBlob (stmt, index, (byte[])value, ((byte[])value).Length, NegativePointer);
} }
else if (value is Guid guid) { else if (value is Guid) {
SQLite3.BindText (stmt, index, guid.ToString (), 72, NegativePointer); SQLite3.BindText (stmt, index, ((Guid)value).ToString (), 72, NegativePointer);
} }
else if (value is Uri uri) { else if (value is Uri) {
SQLite3.BindText (stmt, index, uri.ToString (), -1, NegativePointer); SQLite3.BindText (stmt, index, ((Uri)value).ToString (), -1, NegativePointer);
} }
else if (value is StringBuilder builder) { else if (value is StringBuilder) {
SQLite3.BindText (stmt, index, builder.ToString (), -1, NegativePointer); SQLite3.BindText (stmt, index, ((StringBuilder)value).ToString (), -1, NegativePointer);
} }
else if (value is UriBuilder builder1) { else if (value is UriBuilder) {
SQLite3.BindText (stmt, index, builder1.ToString (), -1, NegativePointer); SQLite3.BindText (stmt, index, ((UriBuilder)value).ToString (), -1, NegativePointer);
} }
else { else {
// Now we could possibly get an enum, retrieve cached info // Now we could possibly get an enum, retrieve cached info
@@ -3356,13 +3362,13 @@ namespace SQLite
clrTypeInfo = clrType.GetTypeInfo (); clrTypeInfo = clrType.GetTypeInfo ();
} }
if (clrType == typeof (string)) { if (clrType == typeof (String)) {
return SQLite3.ColumnString (stmt, index); return SQLite3.ColumnString (stmt, index);
} }
else if (clrType == typeof (int)) { else if (clrType == typeof (Int32)) {
return SQLite3.ColumnInt(stmt, index); return (int)SQLite3.ColumnInt (stmt, index);
} }
else if (clrType == typeof (bool)) { else if (clrType == typeof (Boolean)) {
return SQLite3.ColumnInt (stmt, index) == 1; return SQLite3.ColumnInt (stmt, index) == 1;
} }
else if (clrType == typeof (double)) { else if (clrType == typeof (double)) {
@@ -3408,22 +3414,22 @@ namespace SQLite
else else
return SQLite3.ColumnInt (stmt, index); return SQLite3.ColumnInt (stmt, index);
} }
else if (clrType == typeof (long)) { else if (clrType == typeof (Int64)) {
return SQLite3.ColumnInt64 (stmt, index); return SQLite3.ColumnInt64 (stmt, index);
} }
else if (clrType == typeof (uint)) { else if (clrType == typeof (UInt32)) {
return (uint)SQLite3.ColumnInt64 (stmt, index); return (uint)SQLite3.ColumnInt64 (stmt, index);
} }
else if (clrType == typeof (decimal)) { else if (clrType == typeof (decimal)) {
return (decimal)SQLite3.ColumnDouble (stmt, index); return (decimal)SQLite3.ColumnDouble (stmt, index);
} }
else if (clrType == typeof (byte)) { else if (clrType == typeof (Byte)) {
return (byte)SQLite3.ColumnInt (stmt, index); return (byte)SQLite3.ColumnInt (stmt, index);
} }
else if (clrType == typeof (ushort)) { else if (clrType == typeof (UInt16)) {
return (ushort)SQLite3.ColumnInt (stmt, index); return (ushort)SQLite3.ColumnInt (stmt, index);
} }
else if (clrType == typeof (short)) { else if (clrType == typeof (Int16)) {
return (short)SQLite3.ColumnInt (stmt, index); return (short)SQLite3.ColumnInt (stmt, index);
} }
else if (clrType == typeof (sbyte)) { else if (clrType == typeof (sbyte)) {
@@ -3483,17 +3489,17 @@ namespace SQLite
clrTypeInfo = clrType.GetTypeInfo (); clrTypeInfo = clrType.GetTypeInfo ();
} }
if (clrType == typeof (string)) { if (clrType == typeof (String)) {
fastSetter = CreateTypedSetterDelegate<T, string> (column, (stmt, index) => { fastSetter = CreateTypedSetterDelegate<T, string> (column, (stmt, index) => {
return SQLite3.ColumnString (stmt, index); return SQLite3.ColumnString (stmt, index);
}); });
} }
else if (clrType == typeof (int)) { else if (clrType == typeof (Int32)) {
fastSetter = CreateNullableTypedSetterDelegate<T, int> (column, (stmt, index)=>{ fastSetter = CreateNullableTypedSetterDelegate<T, int> (column, (stmt, index)=>{
return SQLite3.ColumnInt (stmt, index); return SQLite3.ColumnInt (stmt, index);
}); });
} }
else if (clrType == typeof (bool)) { else if (clrType == typeof (Boolean)) {
fastSetter = CreateNullableTypedSetterDelegate<T, bool> (column, (stmt, index) => { fastSetter = CreateNullableTypedSetterDelegate<T, bool> (column, (stmt, index) => {
return SQLite3.ColumnInt (stmt, index) == 1; return SQLite3.ColumnInt (stmt, index) == 1;
}); });
@@ -3517,11 +3523,11 @@ namespace SQLite
else { else {
fastSetter = CreateNullableTypedSetterDelegate<T, TimeSpan> (column, (stmt, index) => { fastSetter = CreateNullableTypedSetterDelegate<T, TimeSpan> (column, (stmt, index) => {
var text = SQLite3.ColumnString (stmt, index); var text = SQLite3.ColumnString (stmt, index);
if (!TimeSpan.TryParseExact(text, "c", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.TimeSpanStyles.None, out TimeSpan resultTime)) TimeSpan resultTime;
{ if (!TimeSpan.TryParseExact (text, "c", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.TimeSpanStyles.None, out resultTime)) {
resultTime = TimeSpan.Parse(text); resultTime = TimeSpan.Parse (text);
} }
return resultTime; return resultTime;
}); });
} }
} }
@@ -3534,11 +3540,11 @@ namespace SQLite
else { else {
fastSetter = CreateNullableTypedSetterDelegate<T, DateTime> (column, (stmt, index) => { fastSetter = CreateNullableTypedSetterDelegate<T, DateTime> (column, (stmt, index) => {
var text = SQLite3.ColumnString (stmt, index); var text = SQLite3.ColumnString (stmt, index);
if (!DateTime.TryParseExact(text, conn.DateTimeStringFormat, System.Globalization.CultureInfo.InvariantCulture, conn.DateTimeStyle, out DateTime resultDate)) DateTime resultDate;
{ if (!DateTime.TryParseExact (text, conn.DateTimeStringFormat, System.Globalization.CultureInfo.InvariantCulture, conn.DateTimeStyle, out resultDate)) {
resultDate = DateTime.Parse(text); resultDate = DateTime.Parse (text);
} }
return resultDate; return resultDate;
}); });
} }
} }
@@ -3550,13 +3556,13 @@ namespace SQLite
else if (clrTypeInfo.IsEnum) { else if (clrTypeInfo.IsEnum) {
// NOTE: Not sure of a good way (if any?) to do a strongly-typed fast setter like this for enumerated types -- for now, return null and column sets will revert back to the safe (but slow) Reflection-based method of column prop.Set() // NOTE: Not sure of a good way (if any?) to do a strongly-typed fast setter like this for enumerated types -- for now, return null and column sets will revert back to the safe (but slow) Reflection-based method of column prop.Set()
} }
else if (clrType == typeof (long)) { else if (clrType == typeof (Int64)) {
fastSetter = CreateNullableTypedSetterDelegate<T, long> (column, (stmt, index) => { fastSetter = CreateNullableTypedSetterDelegate<T, Int64> (column, (stmt, index) => {
return SQLite3.ColumnInt64 (stmt, index); return SQLite3.ColumnInt64 (stmt, index);
}); });
} }
else if (clrType == typeof (uint)) { else if (clrType == typeof (UInt32)) {
fastSetter = CreateNullableTypedSetterDelegate<T, uint> (column, (stmt, index) => { fastSetter = CreateNullableTypedSetterDelegate<T, UInt32> (column, (stmt, index) => {
return (uint)SQLite3.ColumnInt64 (stmt, index); return (uint)SQLite3.ColumnInt64 (stmt, index);
}); });
} }
@@ -3565,18 +3571,18 @@ namespace SQLite
return (decimal)SQLite3.ColumnDouble (stmt, index); return (decimal)SQLite3.ColumnDouble (stmt, index);
}); });
} }
else if (clrType == typeof (byte)) { else if (clrType == typeof (Byte)) {
fastSetter = CreateNullableTypedSetterDelegate<T, byte> (column, (stmt, index) => { fastSetter = CreateNullableTypedSetterDelegate<T, Byte> (column, (stmt, index) => {
return (byte)SQLite3.ColumnInt (stmt, index); return (byte)SQLite3.ColumnInt (stmt, index);
}); });
} }
else if (clrType == typeof (ushort)) { else if (clrType == typeof (UInt16)) {
fastSetter = CreateNullableTypedSetterDelegate<T, ushort> (column, (stmt, index) => { fastSetter = CreateNullableTypedSetterDelegate<T, UInt16> (column, (stmt, index) => {
return (ushort)SQLite3.ColumnInt (stmt, index); return (ushort)SQLite3.ColumnInt (stmt, index);
}); });
} }
else if (clrType == typeof (short)) { else if (clrType == typeof (Int16)) {
fastSetter = CreateNullableTypedSetterDelegate<T, short> (column, (stmt, index) => { fastSetter = CreateNullableTypedSetterDelegate<T, Int16> (column, (stmt, index) => {
return (short)SQLite3.ColumnInt (stmt, index); return (short)SQLite3.ColumnInt (stmt, index);
}); });
} }
@@ -3798,12 +3804,14 @@ namespace SQLite
List<Ordering> _orderBys; List<Ordering> _orderBys;
int? _limit; int? _limit;
int? _offset; int? _offset;
BaseTableQuery _joinInner;
Expression _joinInnerKeySelector; BaseTableQuery _joinInner;
BaseTableQuery _joinOuter; Expression _joinInnerKeySelector;
Expression _joinOuterKeySelector; BaseTableQuery _joinOuter;
Expression _joinSelector; Expression _joinOuterKeySelector;
Expression _selector; Expression _joinSelector;
Expression _selector;
TableQuery (SQLiteConnection conn, TableMapping table) TableQuery (SQLiteConnection conn, TableMapping table)
{ {
@@ -3931,7 +3939,7 @@ namespace SQLite
/// </summary> /// </summary>
public TableQuery<T> OrderBy<U> (Expression<Func<T, U>> orderExpr) public TableQuery<T> OrderBy<U> (Expression<Func<T, U>> orderExpr)
{ {
return AddOrderBy(orderExpr, true); return AddOrderBy<U> (orderExpr, true);
} }
/// <summary> /// <summary>
@@ -3939,7 +3947,7 @@ namespace SQLite
/// </summary> /// </summary>
public TableQuery<T> OrderByDescending<U> (Expression<Func<T, U>> orderExpr) public TableQuery<T> OrderByDescending<U> (Expression<Func<T, U>> orderExpr)
{ {
return AddOrderBy(orderExpr, false); return AddOrderBy<U> (orderExpr, false);
} }
/// <summary> /// <summary>
@@ -3947,7 +3955,7 @@ namespace SQLite
/// </summary> /// </summary>
public TableQuery<T> ThenBy<U> (Expression<Func<T, U>> orderExpr) public TableQuery<T> ThenBy<U> (Expression<Func<T, U>> orderExpr)
{ {
return AddOrderBy(orderExpr, true); return AddOrderBy<U> (orderExpr, true);
} }
/// <summary> /// <summary>
@@ -3955,7 +3963,7 @@ namespace SQLite
/// </summary> /// </summary>
public TableQuery<T> ThenByDescending<U> (Expression<Func<T, U>> orderExpr) public TableQuery<T> ThenByDescending<U> (Expression<Func<T, U>> orderExpr)
{ {
return AddOrderBy(orderExpr, false); return AddOrderBy<U> (orderExpr, false);
} }
TableQuery<T> AddOrderBy<U> (Expression<Func<T, U>> orderExpr, bool asc) TableQuery<T> AddOrderBy<U> (Expression<Func<T, U>> orderExpr, bool asc)
@@ -3963,7 +3971,7 @@ namespace SQLite
if (orderExpr.NodeType == ExpressionType.Lambda) { if (orderExpr.NodeType == ExpressionType.Lambda) {
var lambda = (LambdaExpression)orderExpr; var lambda = (LambdaExpression)orderExpr;
MemberExpression mem; MemberExpression mem = null;
var unary = lambda.Body as UnaryExpression; var unary = lambda.Body as UnaryExpression;
if (unary != null && unary.NodeType == ExpressionType.Convert) { if (unary != null && unary.NodeType == ExpressionType.Convert) {
@@ -4247,23 +4255,22 @@ namespace SQLite
var m = (PropertyInfo)mem.Member; var m = (PropertyInfo)mem.Member;
val = m.GetValue (obj, null); val = m.GetValue (obj, null);
} }
else if (mem.Member is FieldInfo m) else if (mem.Member is FieldInfo) {
{ var m = (FieldInfo)mem.Member;
val = m.GetValue(obj); val = m.GetValue (obj);
} }
else else {
{ throw new NotSupportedException ("MemberExpr: " + mem.Member.GetType ());
throw new NotSupportedException("MemberExpr: " + mem.Member.GetType()); }
}
// //
// Work special magic for enumerables // Work special magic for enumerables
// //
if (val != null && val is IEnumerable enumerable && !(val is string) && !(val is IEnumerable<byte>)) { if (val != null && val is System.Collections.IEnumerable && !(val is string) && !(val is System.Collections.Generic.IEnumerable<byte>)) {
var sb = new StringBuilder (); var sb = new System.Text.StringBuilder ();
sb.Append ("("); sb.Append ("(");
var head = string.Empty; var head = string.Empty;
foreach (var a in enumerable) { foreach (var a in (System.Collections.IEnumerable)val) {
queryArgs.Add (a); queryArgs.Add (a);
sb.Append (head); sb.Append (head);
sb.Append ("?"); sb.Append ("?");