Пример #1
0
 internal static void BindParameter(ISQLiteApi isqLite3Api, IDbStatement stmt, int index, object value, bool storeDateTimeAsTicks,
                                    IBlobSerializer serializer)
 {
     if (value == null)
     {
         isqLite3Api.BindNull(stmt, index);
     }
     else
     {
         if (value is int)
         {
             isqLite3Api.BindInt(stmt, index, (int)value);
         }
         else if (value is ISerializable <int> )
         {
             isqLite3Api.BindInt(stmt, index, ((ISerializable <int>)value).Serialize());
         }
         else if (value is string)
         {
             isqLite3Api.BindText16(stmt, index, (string)value, -1, NegativePointer);
         }
         else if (value is ISerializable <string> )
         {
             isqLite3Api.BindText16(stmt, index, ((ISerializable <string>)value).Serialize(), -1, NegativePointer);
         }
         else if (value is byte || value is ushort || value is sbyte || value is short)
         {
             isqLite3Api.BindInt(stmt, index, Convert.ToInt32(value));
         }
         else if (value is ISerializable <byte> )
         {
             isqLite3Api.BindInt(stmt, index, Convert.ToInt32(((ISerializable <byte>)value).Serialize()));
         }
         else if (value is ISerializable <ushort> )
         {
             isqLite3Api.BindInt(stmt, index, Convert.ToInt32(((ISerializable <ushort>)value).Serialize()));
         }
         else if (value is ISerializable <sbyte> )
         {
             isqLite3Api.BindInt(stmt, index, Convert.ToInt32(((ISerializable <sbyte>)value).Serialize()));
         }
         else if (value is ISerializable <short> )
         {
             isqLite3Api.BindInt(stmt, index, Convert.ToInt32(((ISerializable <short>)value).Serialize()));
         }
         else if (value is bool)
         {
             isqLite3Api.BindInt(stmt, index, (bool)value ? 1 : 0);
         }
         else if (value is ISerializable <bool> )
         {
             isqLite3Api.BindInt(stmt, index, ((ISerializable <bool>)value).Serialize() ? 1 : 0);
         }
         else if (value is uint || value is long)
         {
             isqLite3Api.BindInt64(stmt, index, Convert.ToInt64(value));
         }
         else if (value is ISerializable <uint> )
         {
             isqLite3Api.BindInt64(stmt, index, Convert.ToInt64(((ISerializable <uint>)value).Serialize()));
         }
         else if (value is ISerializable <long> )
         {
             isqLite3Api.BindInt64(stmt, index, Convert.ToInt64(((ISerializable <long>)value).Serialize()));
         }
         else if (value is float || value is double || value is decimal)
         {
             isqLite3Api.BindDouble(stmt, index, Convert.ToDouble(value));
         }
         else if (value is ISerializable <float> )
         {
             isqLite3Api.BindDouble(stmt, index, Convert.ToDouble(((ISerializable <float>)value).Serialize()));
         }
         else if (value is ISerializable <double> )
         {
             isqLite3Api.BindDouble(stmt, index, Convert.ToDouble(((ISerializable <double>)value).Serialize()));
         }
         else if (value is ISerializable <decimal> )
         {
             isqLite3Api.BindDouble(stmt, index, Convert.ToDouble(((ISerializable <decimal>)value).Serialize()));
         }
         else if (value is TimeSpan)
         {
             isqLite3Api.BindInt64(stmt, index, ((TimeSpan)value).Ticks);
         }
         else if (value is ISerializable <TimeSpan> )
         {
             isqLite3Api.BindInt64(stmt, index, ((ISerializable <TimeSpan>)value).Serialize().Ticks);
         }
         else if (value is DateTime)
         {
             if (storeDateTimeAsTicks)
             {
                 isqLite3Api.BindInt64(stmt, index, ((DateTime)value).ToUniversalTime().Ticks);
             }
             else
             {
                 isqLite3Api.BindText16(stmt, index, ((DateTime)value).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"), -1, NegativePointer);
             }
         }
         else if (value is DateTimeOffset)
         {
             isqLite3Api.BindInt64(stmt, index, ((DateTimeOffset)value).UtcTicks);
         }
         else if (value is ISerializable <DateTime> )
         {
             if (storeDateTimeAsTicks)
             {
                 isqLite3Api.BindInt64(stmt, index, ((ISerializable <DateTime>)value).Serialize().ToUniversalTime().Ticks);
             }
             else
             {
                 isqLite3Api.BindText16(stmt, index,
                                        ((ISerializable <DateTime>)value).Serialize().ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"), -1, NegativePointer);
             }
         }
         else if (value.GetType().GetTypeInfo().IsEnum)
         {
             isqLite3Api.BindInt(stmt, index, Convert.ToInt32(value));
         }
         else if (value is byte[])
         {
             isqLite3Api.BindBlob(stmt, index, (byte[])value, ((byte[])value).Length, NegativePointer);
         }
         else if (value is ISerializable <byte[]> )
         {
             isqLite3Api.BindBlob(stmt, index, ((ISerializable <byte[]>)value).Serialize(), ((ISerializable <byte[]>)value).Serialize().Length,
                                  NegativePointer);
         }
         else if (value is Guid)
         {
             isqLite3Api.BindText16(stmt, index, ((Guid)value).ToString(), 72, NegativePointer);
         }
         else if (value is ISerializable <Guid> )
         {
             isqLite3Api.BindText16(stmt, index, ((ISerializable <Guid>)value).Serialize().ToString(), 72, NegativePointer);
         }
         else if (serializer != null && serializer.CanDeserialize(value.GetType()))
         {
             var bytes = serializer.Serialize(value);
             isqLite3Api.BindBlob(stmt, index, bytes, bytes.Length, NegativePointer);
         }
         else
         {
             throw new NotSupportedException("Cannot store type: " + value.GetType());
         }
     }
 }
Пример #2
0
 internal static void BindParameter(ISQLiteApi isqLite3Api, IDbStatement stmt, int index, object value,
                                    bool storeDateTimeAsTicks)
 {
     if (value == null)
     {
         isqLite3Api.BindNull(stmt, index);
     }
     else
     {
         if (value is Int32)
         {
             isqLite3Api.BindInt(stmt, index, (int)value);
         }
         else if (value is String)
         {
             isqLite3Api.BindText16(stmt, index, (string)value, -1, NegativePointer);
         }
         else if (value is Byte || value is UInt16 || value is SByte || value is Int16)
         {
             isqLite3Api.BindInt(stmt, index, Convert.ToInt32(value));
         }
         else if (value is Boolean)
         {
             isqLite3Api.BindInt(stmt, index, (bool)value ? 1 : 0);
         }
         else if (value is UInt32 || value is Int64)
         {
             isqLite3Api.BindInt64(stmt, index, Convert.ToInt64(value));
         }
         else if (value is Single || value is Double || value is Decimal)
         {
             isqLite3Api.BindDouble(stmt, index, Convert.ToDouble(value));
         }
         else if (value is DateTime)
         {
             if (storeDateTimeAsTicks)
             {
                 isqLite3Api.BindInt64(stmt, index, ((DateTime)value).Ticks);
             }
             else
             {
                 isqLite3Api.BindText16(stmt, index, ((DateTime)value).ToString("yyyy-MM-dd HH:mm:ss"), -1,
                                        NegativePointer);
             }
         }
         else if (value.GetType().IsEnum)
         {
             isqLite3Api.BindInt(stmt, index, Convert.ToInt32(value));
         }
         else if (value is byte[])
         {
             isqLite3Api.BindBlob(stmt, index, (byte[])value, ((byte[])value).Length, NegativePointer);
         }
         else if (value is Guid)
         {
             isqLite3Api.BindText16(stmt, index, ((Guid)value).ToString(), 72, NegativePointer);
         }
         else
         {
             throw new NotSupportedException("Cannot store type: " + value.GetType());
         }
     }
 }
Пример #3
0
 internal static void BindParameter(ISQLiteApi isqLite3Api, IDbStatement stmt, int index, object value,
                                    bool storeDateTimeAsTicks, IBlobSerializer serializer)
 {
     if (value == null)
     {
         isqLite3Api.BindNull(stmt, index);
     }
     else
     {
         if (value is Int32)
         {
             isqLite3Api.BindInt(stmt, index, (int)value);
         }
         else if (value is ISerializable <int> )
         {
             isqLite3Api.BindInt(stmt, index, ((ISerializable <int>)value).Serialize());
         }
         else if (value is String)
         {
             isqLite3Api.BindText16(stmt, index, (string)value, -1, NegativePointer);
         }
         else if (value is ISerializable <String> )
         {
             isqLite3Api.BindText16(stmt, index, ((ISerializable <String>)value).Serialize(), -1, NegativePointer);
         }
         else if (value is Byte || value is UInt16 || value is SByte || value is Int16)
         {
             isqLite3Api.BindInt(stmt, index, Convert.ToInt32(value));
         }
         else if (value is ISerializable <Byte> )
         {
             isqLite3Api.BindInt(stmt, index, Convert.ToInt32(((ISerializable <Byte>)value).Serialize()));
         }
         else if (value is ISerializable <UInt16> )
         {
             isqLite3Api.BindInt(stmt, index, Convert.ToInt32(((ISerializable <UInt16>)value).Serialize()));
         }
         else if (value is ISerializable <SByte> )
         {
             isqLite3Api.BindInt(stmt, index, Convert.ToInt32(((ISerializable <SByte>)value).Serialize()));
         }
         else if (value is ISerializable <Int16> )
         {
             isqLite3Api.BindInt(stmt, index, Convert.ToInt32(((ISerializable <Int16>)value).Serialize()));
         }
         else if (value is Boolean)
         {
             isqLite3Api.BindInt(stmt, index, (bool)value ? 1 : 0);
         }
         else if (value is ISerializable <Boolean> )
         {
             isqLite3Api.BindInt(stmt, index, ((ISerializable <bool>)value).Serialize() ? 1 : 0);
         }
         else if (value is UInt32 || value is Int64)
         {
             isqLite3Api.BindInt64(stmt, index, Convert.ToInt64(value));
         }
         else if (value is ISerializable <UInt32> )
         {
             isqLite3Api.BindInt64(stmt, index, Convert.ToInt64(((ISerializable <UInt32>)value).Serialize()));
         }
         else if (value is ISerializable <Int64> )
         {
             isqLite3Api.BindInt64(stmt, index, Convert.ToInt64(((ISerializable <Int64>)value).Serialize()));
         }
         else if (value is Single || value is Double || value is Decimal)
         {
             isqLite3Api.BindDouble(stmt, index, Convert.ToDouble(value));
         }
         else if (value is ISerializable <Single> )
         {
             isqLite3Api.BindDouble(stmt, index, Convert.ToDouble(((ISerializable <Single>)value).Serialize()));
         }
         else if (value is ISerializable <Double> )
         {
             isqLite3Api.BindDouble(stmt, index, Convert.ToDouble(((ISerializable <Double>)value).Serialize()));
         }
         else if (value is ISerializable <Decimal> )
         {
             isqLite3Api.BindDouble(stmt, index, Convert.ToDouble(((ISerializable <Decimal>)value).Serialize()));
         }
         else if (value is TimeSpan)
         {
             isqLite3Api.BindInt64(stmt, index, ((TimeSpan)value).Ticks);
         }
         else if (value is ISerializable <TimeSpan> )
         {
             isqLite3Api.BindInt64(stmt, index, ((ISerializable <TimeSpan>)value).Serialize().Ticks);
         }
         else if (value is DateTime)
         {
             if (storeDateTimeAsTicks)
             {
                 isqLite3Api.BindInt64(stmt, index, ((DateTime)value).Ticks);
             }
             else
             {
                 isqLite3Api.BindText16(stmt, index, ((DateTime)value).ToString("yyyy-MM-dd HH:mm:ss"), -1, NegativePointer);
             }
         }
         else if (value is ISerializable <DateTime> )
         {
             if (storeDateTimeAsTicks)
             {
                 isqLite3Api.BindInt64(stmt, index, ((ISerializable <DateTime>)value).Serialize().Ticks);
             }
             else
             {
                 isqLite3Api.BindText16(stmt, index, ((ISerializable <DateTime>)value).Serialize().ToString("yyyy-MM-dd HH:mm:ss"), -1, NegativePointer);
             }
         }
         else if (value.GetType().GetTypeInfo().IsEnum)
         {
             isqLite3Api.BindInt(stmt, index, Convert.ToInt32(value));
         }
         else if (value is byte[])
         {
             isqLite3Api.BindBlob(stmt, index, (byte[])value, ((byte[])value).Length, NegativePointer);
         }
         else if (value is ISerializable <byte[]> )
         {
             isqLite3Api.BindBlob(stmt, index, ((ISerializable <byte[]>)value).Serialize(), ((ISerializable <byte[]>)value).Serialize().Length, NegativePointer);
         }
         else if (value is Guid)
         {
             isqLite3Api.BindText16(stmt, index, ((Guid)value).ToString(), 72, NegativePointer);
         }
         else if (value is ISerializable <Guid> )
         {
             isqLite3Api.BindText16(stmt, index, ((ISerializable <Guid>)value).Serialize().ToString(), 72, NegativePointer);
         }
         else if (serializer != null && serializer.CanDeserialize(value.GetType()))
         {
             var bytes = serializer.Serialize(value);
             isqLite3Api.BindBlob(stmt, index, bytes, bytes.Length, NegativePointer);
         }
         else
         {
             throw new NotSupportedException("Cannot store type: " + value.GetType());
         }
     }
 }
Пример #4
0
 private static void BindParameter(ISQLiteApi isqLite3Api, IDbStatement stmt, int index, object value, bool storeDateTimeAsTicks,
                                   IBlobSerializer serializer)
 {
     if (value == null)
     {
         isqLite3Api.BindNull(stmt, index);
     }
     else
     {
         if (value is int)
         {
             isqLite3Api.BindInt(stmt, index, (int)value);
         }
         else if (value is ISerializable <int> serializable)
         {
             isqLite3Api.BindInt(stmt, index, (serializable).Serialize());
         }
         else if (value is string valueAsString)
         {
             isqLite3Api.BindText16(stmt, index, valueAsString, -1, NegativePointer);
         }
         else if (value is ISerializable <string> stringSerializable)
         {
             isqLite3Api.BindText16(stmt, index, (stringSerializable).Serialize(), -1, NegativePointer);
         }
         else if (value is byte || value is ushort || value is sbyte || value is short)
         {
             isqLite3Api.BindInt(stmt, index, Convert.ToInt32(value));
         }
         else if (value is ISerializable <byte> byteSerializable)
         {
             isqLite3Api.BindInt(stmt, index, Convert.ToInt32(byteSerializable.Serialize()));
         }
         else if (value is ISerializable <ushort> ushortSerializable)
         {
             isqLite3Api.BindInt(stmt, index, Convert.ToInt32(ushortSerializable.Serialize()));
         }
         else if (value is ISerializable <sbyte> sbyteSerializable)
         {
             isqLite3Api.BindInt(stmt, index, Convert.ToInt32(sbyteSerializable.Serialize()));
         }
         else if (value is ISerializable <short> shortSerializable)
         {
             isqLite3Api.BindInt(stmt, index, Convert.ToInt32((shortSerializable).Serialize()));
         }
         else if (value is bool valueAsBool)
         {
             isqLite3Api.BindInt(stmt, index, valueAsBool ? 1 : 0);
         }
         else if (value is ISerializable <bool> boolSerializable)
         {
             isqLite3Api.BindInt(stmt, index, boolSerializable.Serialize() ? 1 : 0);
         }
         else if (value is uint || value is long)
         {
             isqLite3Api.BindInt64(stmt, index, Convert.ToInt64(value));
         }
         else if (value is ISerializable <uint> uintSerializable)
         {
             isqLite3Api.BindInt64(stmt, index, Convert.ToInt64(uintSerializable.Serialize()));
         }
         else if (value is ISerializable <long> longSerializable)
         {
             isqLite3Api.BindInt64(stmt, index, Convert.ToInt64(longSerializable.Serialize()));
         }
         else if (value is float || value is double || value is decimal)
         {
             isqLite3Api.BindDouble(stmt, index, Convert.ToDouble(value));
         }
         else if (value is ISerializable <float> floatSerializable)
         {
             isqLite3Api.BindDouble(stmt, index, Convert.ToDouble(floatSerializable.Serialize()));
         }
         else if (value is ISerializable <double> doubleSerializable)
         {
             isqLite3Api.BindDouble(stmt, index, Convert.ToDouble(doubleSerializable.Serialize()));
         }
         else if (value is ISerializable <decimal> decimSerializable)
         {
             isqLite3Api.BindDouble(stmt, index, Convert.ToDouble(decimSerializable.Serialize()));
         }
         else if (value is TimeSpan timeSpan)
         {
             isqLite3Api.BindInt64(stmt, index, timeSpan.Ticks);
         }
         else if (value is ISerializable <TimeSpan> timeSerializable)
         {
             isqLite3Api.BindInt64(stmt, index, timeSerializable.Serialize().Ticks);
         }
         else if (value is DateTime dateTime)
         {
             if (storeDateTimeAsTicks)
             {
                 var ticks = dateTime.ToUniversalTime().Ticks;
                 isqLite3Api.BindInt64(stmt, index, ticks);
             }
             else
             {
                 var val = ((DateTime)value).ToUniversalTime().ToString(DateTimeFormat, CultureInfo.InvariantCulture);
                 isqLite3Api.BindText16(stmt, index, val, -1, NegativePointer);
             }
         }
         else if (value is DateTimeOffset dateTimeOffset)
         {
             isqLite3Api.BindInt64(stmt, index, dateTimeOffset.UtcTicks);
         }
         else if (value is ISerializable <DateTime> datetSerializable)
         {
             if (storeDateTimeAsTicks)
             {
                 var ticks = datetSerializable.Serialize().ToUniversalTime().Ticks;
                 isqLite3Api.BindInt64(stmt, index, ticks);
             }
             else
             {
                 var val = datetSerializable.Serialize().ToUniversalTime().ToString(DateTimeFormat, CultureInfo.InvariantCulture);
                 isqLite3Api.BindText16(stmt, index, val, -1, NegativePointer);
             }
         }
         else if (value.GetType().GetTypeInfo().IsEnum)
         {
             isqLite3Api.BindInt(stmt, index, Convert.ToInt32(value));
         }
         else if (value is byte[] bytes2)
         {
             isqLite3Api.BindBlob(stmt, index, bytes2, bytes2.Length, NegativePointer);
         }
         else if (value is ISerializable <byte[]> byteSerializable2)
         {
             var serialized = byteSerializable2.Serialize();
             isqLite3Api.BindBlob(stmt, index, serialized, serialized.Length, NegativePointer);
         }
         else if (value is Guid guid)
         {
             isqLite3Api.BindText16(stmt, index, guid.ToString(), 72, NegativePointer);
         }
         else if (value is ISerializable <Guid> guiSerializable)
         {
             isqLite3Api.BindText16(stmt, index, guiSerializable.Serialize().ToString(), 72, NegativePointer);
         }
         else if (serializer != null && serializer.CanDeserialize(value.GetType()))
         {
             var bytes = serializer.Serialize(value);
             isqLite3Api.BindBlob(stmt, index, bytes, bytes.Length, NegativePointer);
         }
         else
         {
             throw new NotSupportedException("Cannot store type: " + value.GetType());
         }
     }
 }