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; } }
/// <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; } }
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()); }
/// <summary> /// Returns the SQLiteValue as a <see cref="decimal"/>. /// </summary> public static decimal ToDecimal(this ISQLiteValue This) { Contract.Requires(This != null); return(Convert.ToDecimal(This.ToDouble())); }
/// <summary> /// Returns the SQLiteValue as a <see cref="float"/>. /// </summary> public static float ToFloat(this ISQLiteValue This) { Contract.Requires(This != null); return((float)This.ToDouble()); }
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}"); } }