示例#1
0
 /// <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));
 }
示例#2
0
 /// <summary>
 /// Bind the parameter to an <see cref="TimeSpan"/>.
 /// </summary>
 /// <param name="This">The bind parameter.</param>
 /// <param name="value">A <see cref="TimeSpan"/>.</param>
 public static void Bind(this IBindParameter This, TimeSpan value)
 {
     Contract.Requires(This != null);
     This.Bind(value.Ticks);
 }
示例#3
0
        /// <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)
            {
                This.Bind((TimeSpan)obj);
            }
            else if (obj is DateTime)
            {
                This.Bind((DateTime)obj);
            }
            else if (obj is DateTimeOffset)
            {
                This.Bind((DateTimeOffset)obj);
            }
            else if (obj is Guid)
            {
                This.Bind((Guid)obj);
            }
            else if (obj is Stream)
            {
                This.Bind((Stream)obj);
            }
            else if (obj is Uri)
            {
                This.Bind((Uri)obj);
            }
            else
            {
                throw new ArgumentException($"Invalid type conversion {t}");
            }
        }
示例#4
0
        public static void TryBindNull(this IStatement statement, int index)
        {
            IBindParameter bindParam = statement.BindParameters[index];

            bindParam.BindNull();
        }
示例#5
0
        public static void TryBind(this IStatement statement, int index, ReadOnlySpan <byte> value)
        {
            IBindParameter bindParam = statement.BindParameters[index];

            bindParam.Bind(value);
        }
示例#6
0
        public static void TryBind(this IStatement statement, int index, long value)
        {
            IBindParameter bindParam = statement.BindParameters[index];

            bindParam.Bind(value);
        }
示例#7
0
        public static void TryBind(this IStatement statement, int index, Guid value)
        {
            IBindParameter bindParam = statement.BindParameters[index];

            bindParam.Bind(value.ToGuidBlob());
        }