/// <summary> /// Bind the parameter to an <see cref="ISQLiteValue"/>. /// </summary> /// <param name="This">The bind parameter.</param> /// <param name="value">A <see cref="ISQLiteValue"/>.</param> public static void Bind(this IBindParameter This, ISQLiteValue value) { Contract.Requires(This != null); Contract.Requires(value != null); switch (value.SQLiteType) { case SQLiteType.Blob: if (value is ZeroBlob) { This.BindZeroBlob(value.Length); } else { This.Bind(value.ToBlob()); } return; case SQLiteType.Null: This.BindNull(); return; case SQLiteType.Text: This.Bind(value.ToString()); return; case SQLiteType.Float: This.Bind(value.ToDouble()); return; case SQLiteType.Integer: This.Bind(value.ToInt64()); return; } }
public static void TryBind(this IStatement statement, int index, DateTimeOffset value, bool enableMsPrecision) { IBindParameter bindParam = statement.BindParameters[index]; if (enableMsPrecision) { bindParam.Bind(value.ToUnixTimeMilliseconds()); } else { bindParam.Bind(value.ToUnixTimeSeconds()); } }
/// <summary> /// Bind the parameter to a <see cref="Uri"/>. /// </summary> /// <param name="This">The bind parameter.</param> /// <param name="value">A <see cref="Stream"/>.</param> public static void Bind(this IBindParameter This, Uri value) { Contract.Requires(This != null); Contract.Requires(value != null); This.Bind(value.ToString()); }
public static void TryBind(this IStatement statement, int index, string value) { IBindParameter bindParam = statement.BindParameters[index]; if (value == null) { bindParam.BindNull(); } else { #if EMBY bindParam.Bind(value.AsSpan()); #else bindParam.Bind(value); #endif } }
public static void TryBind(this IStatement statement, int index, bool?value) { IBindParameter bindParam = statement.BindParameters[index]; if (value == null) { bindParam.BindNull(); } else { bindParam.Bind(value.Value); } }
/// <summary> /// Bind the parameter to an <see cref="decimal"/>. /// </summary> /// <param name="This">The bind parameter.</param> /// <param name="value">A <see cref="decimal"/>.</param> public static void Bind(this IBindParameter This, decimal value) { Contract.Requires(This != null); This.Bind(Convert.ToDouble(value)); }
/// <summary> /// Bind the parameter to an <see cref="DateTimeOffset"/>. /// </summary> /// <param name="This">The bind parameter.</param> /// <param name="value">A <see cref="DateTimeOffset"/>.</param> public static void Bind(this IBindParameter This, DateTimeOffset value) { Contract.Requires(This != null); This.Bind(value.ToOffset(TimeSpan.Zero).Ticks); }
/// <summary> /// Bind the parameter to an <see cref="DateTime"/>. /// </summary> /// <param name="This">The bind parameter.</param> /// <param name="value">A <see cref="DateTime"/>.</param> public static void Bind(this IBindParameter This, DateTime value) { Contract.Requires(This != null); This.Bind(value.Ticks); }
/// <summary> /// Bind the parameter to an <see cref="bool"/>. /// </summary> /// <param name="This">The bind parameter.</param> /// <param name="value">A <see cref="bool"/>.</param> public static void Bind(this IBindParameter This, bool value) { Contract.Requires(This != null); This.Bind(Convert.ToInt64(value)); }
/// <summary> /// Bind the parameter to a value based upon its runtime type. /// </summary> /// <param name="This">The bind parameter.</param> /// <param name="obj"> /// An object that is either <see langword="null"/> or any numeric type, <see cref="string"/>, /// byte[], <see cref="ISQLiteValue"/> or <see cref="Stream"/>. /// </param> /// <exception cref="ArgumentException"> /// If the <see cref="Type"/> of the value is not supported /// -or- /// A non-readable stream is provided as a value. /// </exception> public static void Bind(this IBindParameter This, object obj) { Contract.Requires(This != null); // I miss F# pattern matching if (obj == null) { This.BindNull(); return; } Type t = obj.GetType(); if (typeof(string) == t) { This.Bind((string)obj); } else if ( (typeof(Int32) == t) || (typeof(Boolean) == t) || (typeof(Byte) == t) || (typeof(UInt16) == t) || (typeof(Int16) == t) || (typeof(sbyte) == t) || (typeof(Int64) == t) || (typeof(UInt32) == t)) { This.Bind((long)Convert.ChangeType(obj, typeof(long))); } else if ((typeof(double) == t) || (typeof(float) == t) || (typeof(decimal) == t)) { This.Bind((double)Convert.ChangeType(obj, typeof(double))); } else if (typeof(byte[]) == t) { This.Bind((byte[])obj); } else if (t.GetTypeInfo().ImplementedInterfaces.Contains(typeof(ISQLiteValue))) { This.Bind((ISQLiteValue)obj); } else if (obj is TimeSpan span) { This.Bind(span); } else if (obj is DateTime time) { This.Bind(time); } else if (obj is DateTimeOffset offset) { This.Bind(offset); } else if (obj is Guid guid) { This.Bind(guid); } else if (obj is Stream stream) { This.Bind(stream); } else if (obj is Uri uri) { This.Bind(uri); } else { ThrowHelper.ThrowArgumentException($"Invalid type conversion {t}"); } }
public static void TryBind(this IStatement statement, int index, ReadOnlySpan <byte> value) { IBindParameter bindParam = statement.BindParameters[index]; bindParam.Bind(value); }
public static void TryBind(this IStatement statement, int index, long value) { IBindParameter bindParam = statement.BindParameters[index]; bindParam.Bind(value); }
public static void TryBind(this IStatement statement, int index, Guid value) { IBindParameter bindParam = statement.BindParameters[index]; bindParam.Bind(value.ToGuidBlob()); }