コード例 #1
0
        /// <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;
            }
        }
コード例 #2
0
        internal static void SetResult(this sqlite3_context ctx, ISQLiteValue value)
        {
            switch (value.SQLiteType)
            {
            case SQLiteType.Blob:
                if (value is ZeroBlob)
                {
                    raw.sqlite3_result_zeroblob(ctx, value.Length);
                }
                else
                {
                    raw.sqlite3_result_blob(ctx, value.ToBlob());
                }
                return;

            case SQLiteType.Null:
                raw.sqlite3_result_null(ctx);
                return;

            case SQLiteType.Text:
                raw.sqlite3_result_text(ctx, value.ToString());
                return;

            case SQLiteType.Float:
                raw.sqlite3_result_double(ctx, value.ToDouble());
                return;

            case SQLiteType.Integer:
                raw.sqlite3_result_int64(ctx, value.ToInt64());
                return;
            }
        }
コード例 #3
0
        private void compare(ISQLiteValue expected, ISQLiteValue test)
        {
            Assert.Equal(test.Length, expected.Length);
            Assert.Equal(test.SQLiteType, expected.SQLiteType);

            Assert.Equal(test.ToDouble(), expected.ToDouble(), 15);
            Assert.Equal(test.ToInt64(), expected.ToInt64());
            Assert.Equal(test.ToInt(), expected.ToInt());
            Assert.Equal(test.ToString(), expected.ToString());
            Assert.Equal(test.ToBlob().ToArray(), expected.ToBlob().ToArray());
        }
コード例 #4
0
        private void compare(ISQLiteValue expected, ISQLiteValue test)
        {
            Assert.Equal(expected.Length, test.Length);
            Assert.Equal(expected.SQLiteType, test.SQLiteType);

            // FIXME: Testing double equality is imprecise
            //Assert.Equal(expected.ToDouble(), test.ToDouble());
            Assert.Equal(expected.ToInt64(), test.ToInt64());
            Assert.Equal(expected.ToInt(), test.ToInt());
            Assert.Equal(expected.ToString(), test.ToString());
            Assert.Equal(expected.ToBlob(), test.ToBlob());
        }
コード例 #5
0
        private void compare(ISQLiteValue expected, ISQLiteValue test)
        {
            Assert.Equal(expected.Length, test.Length);
            Assert.Equal(expected.SQLiteType, test.SQLiteType);

            // FIXME: Testing double equality is imprecise
            //Assert.Equal(expected.ToDouble(), test.ToDouble());
            Assert.Equal(expected.ToInt64(), test.ToInt64());
            Assert.Equal(expected.ToInt(), test.ToInt());
            Assert.Equal(expected.ToString(), test.ToString());
            Assert.Equal(expected.ToBlob(), test.ToBlob());
        }
コード例 #6
0
        internal static void SetResult(this sqlite3_context ctx, ISQLiteValue value)
        {
            switch (value.SQLiteType)
            {
                case SQLiteType.Blob:
                    if (value is ZeroBlob)
                    {
                        raw.sqlite3_result_zeroblob(ctx, value.Length);
                    }
                    else
                    {
                        raw.sqlite3_result_blob(ctx, value.ToBlob());
                    }
                    return;

                case SQLiteType.Null:
                    raw.sqlite3_result_null(ctx);
                    return;

                case SQLiteType.Text:
                    raw.sqlite3_result_text(ctx, value.ToString());
                    return;

                case SQLiteType.Float:
                    raw.sqlite3_result_double(ctx, value.ToDouble());
                    return;

                case SQLiteType.Integer:
                    raw.sqlite3_result_int64(ctx, value.ToInt64());
                    return;
            }
        }
コード例 #7
0
 /// <summary>
 /// Returns the SQLiteValue as a <see cref="sbyte"/>.
 /// </summary>
 public static sbyte ToSByte(this ISQLiteValue This)
 {
     Contract.Requires(This != null);
     return(Convert.ToSByte(This.ToInt64()));
 }
コード例 #8
0
 /// <summary>
 /// Returns the SQLiteValue as a <see cref="short"/>.
 /// </summary>
 public static short ToShort(this ISQLiteValue This)
 {
     Contract.Requires(This != null);
     return(Convert.ToInt16(This.ToInt64()));
 }
コード例 #9
0
 /// <summary>
 /// Returns the SQLiteValue as a <see cref="uint"/>.
 /// </summary>
 public static uint ToUInt32(this ISQLiteValue This)
 {
     Contract.Requires(This != null);
     return(Convert.ToUInt32(This.ToInt64()));
 }
コード例 #10
0
 /// <summary>
 /// Returns the SQLiteValue as a <see cref="DateTimeOffset"/>.
 /// </summary>
 public static DateTimeOffset ToDateTimeOffset(this ISQLiteValue This)
 {
     Contract.Requires(This != null);
     return(new DateTimeOffset(This.ToInt64(), TimeSpan.Zero));
 }
コード例 #11
0
 /// <summary>
 /// Returns the SQLiteValue as a <see cref="DateTime"/>.
 /// </summary>
 public static DateTime ToDateTime(this ISQLiteValue This)
 {
     Contract.Requires(This != null);
     return(new DateTime(This.ToInt64()));
 }
コード例 #12
0
 /// <summary>
 /// Returns the SQLiteValue as a <see cref="TimeSpan"/>.
 /// </summary>
 public static TimeSpan ToTimeSpan(this ISQLiteValue This)
 {
     Contract.Requires(This != null);
     return(new TimeSpan(This.ToInt64()));
 }
コード例 #13
0
 /// <summary>
 /// Returns the SQLiteValue as a <see cref="bool"/>.
 /// </summary>
 public static bool ToBool(this ISQLiteValue This)
 {
     Contract.Requires(This != null);
     return(Convert.ToBoolean(This.ToInt64()));
 }
コード例 #14
0
        private static object ToObject(this ISQLiteValue value, Type clrType)
        {
            // Just in case the clrType is nullable
            clrType = clrType.GetUnderlyingType();

            if (value.SQLiteType == SQLiteType.Null)
            {
                return(null);
            }
            else if (clrType == typeof(String))
            {
                return(value.ToString());
            }
            else if (clrType == typeof(Int32))
            {
                return(value.ToInt());
            }
            else if (clrType == typeof(Boolean))
            {
                return(value.ToBool());
            }
            else if (clrType == typeof(double))
            {
                return(value.ToDouble());
            }
            else if (clrType == typeof(float))
            {
                return(value.ToFloat());
            }
            else if (clrType == typeof(TimeSpan))
            {
                return(value.ToTimeSpan());
            }
            else if (clrType == typeof(DateTime))
            {
                return(value.ToDateTime());
            }
            else if (clrType == typeof(DateTimeOffset))
            {
                return(value.ToDateTimeOffset());
            }
            else if (clrType.GetTypeInfo().IsEnum)
            {
                return(value.ToInt());
            }
            else if (clrType == typeof(Int64))
            {
                return(value.ToInt64());
            }
            else if (clrType == typeof(UInt32))
            {
                return(value.ToUInt32());
            }
            else if (clrType == typeof(decimal))
            {
                return(value.ToDecimal());
            }
            else if (clrType == typeof(Byte))
            {
                return(value.ToByte());
            }
            else if (clrType == typeof(UInt16))
            {
                return(value.ToUInt16());
            }
            else if (clrType == typeof(Int16))
            {
                return(value.ToShort());
            }
            else if (clrType == typeof(sbyte))
            {
                return(value.ToSByte());
            }
            else if (clrType == typeof(byte[]))
            {
                return(value.ToBlob());
            }
            else if (clrType == typeof(Guid))
            {
                return(value.ToGuid());
            }
            else if (clrType == typeof(Uri))
            {
                return(value.ToUri());
            }
            else
            {
                throw new NotSupportedException($"Don't know how to read {clrType}");
            }
        }
コード例 #15
0
        /// <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;
            }
        }