public static string SqlDecl(TableMapping.Column p, bool storeDateTimeAsTicks, IBlobSerializer serializer, IDictionary<Type, string> extraTypeMappings) { string decl = "\"" + p.Name + "\" " + SqlType(p, storeDateTimeAsTicks, serializer, extraTypeMappings) + " "; if (p.IsPK) { decl += "primary key "; } if (p.IsAutoInc) { decl += "autoincrement "; } if (!p.IsNullable) { decl += "not null "; } if (!string.IsNullOrEmpty(p.Collation)) { decl += "collate " + p.Collation + " "; } if (p.DefaultValue != null) { decl += "default('" + p.DefaultValue + "') "; } return decl; }
public static string SqlType(TableMapping.Column p, bool storeDateTimeAsTicks, IBlobSerializer serializer) { Type clrType = p.ColumnType; var interfaces = clrType.GetTypeInfo().ImplementedInterfaces.ToList(); if (clrType == typeof(Boolean) || clrType == typeof(Byte) || clrType == typeof(UInt16) || clrType == typeof(SByte) || clrType == typeof(Int16) || clrType == typeof(Int32) || interfaces.Contains(typeof(ISerializable<Boolean>)) || interfaces.Contains(typeof(ISerializable<Byte>)) || interfaces.Contains(typeof(ISerializable<UInt16>)) || interfaces.Contains(typeof(ISerializable<SByte>)) || interfaces.Contains(typeof(ISerializable<Int16>)) || interfaces.Contains(typeof(ISerializable<Int32>))) { return "integer"; } if (clrType == typeof(UInt32) || clrType == typeof(Int64) || interfaces.Contains(typeof(ISerializable<UInt32>)) || interfaces.Contains(typeof(ISerializable<Int64>))) { return "bigint"; } if (clrType == typeof(Single) || clrType == typeof(Double) || clrType == typeof(Decimal) || interfaces.Contains(typeof(ISerializable<Single>)) || interfaces.Contains(typeof(ISerializable<Double>)) || interfaces.Contains(typeof(ISerializable<Decimal>))) { return "float"; } if (clrType == typeof(String) || interfaces.Contains(typeof(ISerializable<String>))) { int len = p.MaxStringLength; return "varchar(" + len + ")"; } if (clrType == typeof(TimeSpan) || interfaces.Contains(typeof(ISerializable<TimeSpan>))) { return "bigint"; } if (clrType == typeof(DateTime) || interfaces.Contains(typeof(ISerializable<DateTime>))) { return storeDateTimeAsTicks ? "bigint" : "datetime"; } if (clrType.GetTypeInfo().IsEnum) { return "integer"; } if (clrType == typeof(byte[]) || interfaces.Contains(typeof(ISerializable<byte[]>))) { return "blob"; } if (clrType == typeof(Guid) || interfaces.Contains(typeof(ISerializable<Guid>))) { return "varchar(36)"; } if (serializer != null && serializer.CanDeserialize(clrType)) { return "blob"; } throw new NotSupportedException("Don't know about " + clrType); }
public ListSerializer(Type type, Type innerType) { Type[] typeParams = {innerType}; add = type.GetMethod("Add", typeParams); listType = type; from = BlobTypedReader.GetSerializerForType(innerType); }
public SQLiteConnectionString(string databasePath, bool storeDateTimeAsTicks, IBlobSerializer serializer = null) { ConnectionString = databasePath; StoreDateTimeAsTicks = storeDateTimeAsTicks; DatabasePath = databasePath; Serializer = serializer; }
public DictionarySerializer(Type type, Type leftType, Type innerType) { Type[] typeParams = { leftType, innerType }; add = type.GetMethod("Add", typeParams); this.dictType = type; this.leftType = leftType; this.from = BlobTypedReader.GetSerializerForType(innerType); }
public SqLiteConfig( string databaseName, bool storeDateTimeAsTicks = true, IBlobSerializer serializer = null, IContractResolver resolver = null) { DatabaseName = databaseName; StoreDateTimeAsTicks = storeDateTimeAsTicks; BlobSerializer = serializer; }
public SQLiteConnectionString(string databasePath, bool storeDateTimeAsTicks, IBlobSerializer serializer = null, IContractResolver resolver = null) { ConnectionString = databasePath; StoreDateTimeAsTicks = storeDateTimeAsTicks; DatabasePath = databasePath; Serializer = serializer; Resolver = resolver ?? ContractResolver.Current; }
public static string SqlDecl(TableMapping.Column p, bool storeDateTimeAsTicks, IBlobSerializer serializer) { var result = String.Format("\"{0}\" {1} {2} {3} {4} ", p.Name, SqlType(p, storeDateTimeAsTicks, serializer), p.IsAutoInc ? "primary key autoincrement" : null, !p.IsNullable ? "not null" : null, !String.IsNullOrEmpty(p.Collation) ? "collate " + p.Collation : null ); return result; }
public SqLiteConfig( string databaseName, bool storeDateTimeAsTicks = true, IBlobSerializer serializer = null, IContractResolver resolver = null, SQLiteOpenFlags? openFlags = null) { DatabaseName = databaseName; StoreDateTimeAsTicks = storeDateTimeAsTicks; BlobSerializer = serializer; //OpenFlags = openFlags ?? SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create; }
public SQLiteConnectionString(string databasePath, bool storeDateTimeAsTicks, IBlobSerializer serializer = null, IContractResolver resolver = null, SQLiteOpenFlags? openFlags = null) { ConnectionString = databasePath; StoreDateTimeAsTicks = storeDateTimeAsTicks; DatabasePath = databasePath; Serializer = serializer; Resolver = resolver ?? ContractResolver.Current; OpenFlags = openFlags ?? SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create; }
public static string SqlType(TableMapping.Column p, bool storeDateTimeAsTicks, IBlobSerializer serializer) { Type clrType = p.ColumnType; if (clrType == typeof (Boolean) || clrType == typeof (Byte) || clrType == typeof (UInt16) || clrType == typeof (SByte) || clrType == typeof (Int16) || clrType == typeof (Int32)) { return "integer"; } if (clrType == typeof (UInt32) || clrType == typeof (Int64)) { return "bigint"; } if (clrType == typeof (Single) || clrType == typeof (Double) || clrType == typeof (Decimal)) { return "float"; } if (clrType == typeof (String)) { int len = p.MaxStringLength; return "varchar(" + len + ")"; } if (clrType == typeof (TimeSpan)) { return "bigint"; } if (clrType == typeof (DateTime)) { return storeDateTimeAsTicks ? "bigint" : "datetime"; } if (clrType.IsEnum) { return "integer"; } if (clrType == typeof (byte[])) { return "blob"; } if (clrType == typeof (Guid)) { return "varchar(36)"; } if (serializer != null && serializer.CanDeserialize(clrType)) { return "blob"; } throw new NotSupportedException("Don't know about " + clrType); }
public static string SqlDecl(TableMapping.Column p, bool storeDateTimeAsTicks, IBlobSerializer serializer) { string decl = "\"" + p.Name + "\" " + SqlType(p, storeDateTimeAsTicks, serializer) + " "; if (p.IsPK) { decl += "primary key "; } if (p.IsAutoInc) { decl += "autoincrement "; } if (!p.IsNullable) { decl += "not null "; } if (!string.IsNullOrEmpty(p.Collation)) { decl += "collate " + p.Collation + " "; } return decl; }
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 DateTimeOffset) { isqLite3Api.BindInt64(stmt, index, ((DateTimeOffset)value).UtcTicks); } 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()); } } }
public BlobDatabase(IBlobSerializer serializer) : base(new SQLitePlatformTest(), TestPath.CreateTemporaryDatabase(), false, serializer) { DropTable <ComplexOrder>(); }
private static string SqlType(TableMapping.Column p, bool storeDateTimeAsTicks, IBlobSerializer serializer, IDictionary<Type, string> extraTypeMappings) { var clrType = p.ColumnType; var interfaces = clrType.GetTypeInfo().ImplementedInterfaces.ToList(); string extraMapping; if (extraTypeMappings.TryGetValue(clrType, out extraMapping)) { return extraMapping; } if (clrType == typeof (bool) || clrType == typeof (byte) || clrType == typeof (ushort) || clrType == typeof (sbyte) || clrType == typeof (short) || clrType == typeof (int) || clrType == typeof (uint) || clrType == typeof (long) || interfaces.Contains(typeof (ISerializable<bool>)) || interfaces.Contains(typeof (ISerializable<byte>)) || interfaces.Contains(typeof (ISerializable<ushort>)) || interfaces.Contains(typeof (ISerializable<sbyte>)) || interfaces.Contains(typeof (ISerializable<short>)) || interfaces.Contains(typeof (ISerializable<int>)) || interfaces.Contains(typeof (ISerializable<uint>)) || interfaces.Contains(typeof (ISerializable<long>)) || interfaces.Contains(typeof (ISerializable<ulong>))) { return "integer"; } if (clrType == typeof (float) || clrType == typeof (double) || clrType == typeof (decimal) || interfaces.Contains(typeof (ISerializable<float>)) || interfaces.Contains(typeof (ISerializable<double>)) || interfaces.Contains(typeof (ISerializable<decimal>))) { return "float"; } if (clrType == typeof (string) || interfaces.Contains(typeof (ISerializable<string>))) { var len = p.MaxStringLength; if (len.HasValue) { return "varchar(" + len.Value + ")"; } return "varchar"; } if (clrType == typeof (TimeSpan) || interfaces.Contains(typeof (ISerializable<TimeSpan>))) { return "bigint"; } if (clrType == typeof (DateTime) || interfaces.Contains(typeof (ISerializable<DateTime>))) { return storeDateTimeAsTicks ? "bigint" : "datetime"; } if (clrType == typeof (DateTimeOffset)) { return "bigint"; } if (clrType.GetTypeInfo().IsEnum) { return "integer"; } if (clrType == typeof (byte[]) || interfaces.Contains(typeof (ISerializable<byte[]>))) { return "blob"; } if (clrType == typeof (Guid) || interfaces.Contains(typeof (ISerializable<Guid>))) { return "varchar(36)"; } if (serializer != null && serializer.CanDeserialize(clrType)) { return "blob"; } throw new NotSupportedException("Don't know about " + clrType); }
/// <summary> /// Constructor for locable sqlite connection /// </summary> public LockableSQLiteConnection(ISQLitePlatform sqlitePlatform, String databasePath, SQLiteOpenFlags openFlags, bool storeDateTimeAsTicks = true, IBlobSerializer serializer = null, IDictionary <String, TableMapping> tableMappings = null, IDictionary <Type, String> extraTypeMappings = null, IContractResolver resolver = null) : base(sqlitePlatform, databasePath, openFlags, storeDateTimeAsTicks, serializer, tableMappings, extraTypeMappings, resolver, ApplicationContext.Current.GetCurrentContextSecurityKey()) { }
public PropertySerializer(PropertyInfo prop) { this.prop = prop; this.from = BlobTypedReader.GetSerializerForType(prop.PropertyType); }
public FieldSerializer(FieldInfo field) { this.field = field; this.from = BlobTypedReader.GetSerializerForType(field.FieldType); }
public static BlobDeserializer BuildDeserializer(IBlobSerializer source) { JITContext ctx = new JITContext(source.ExpectedType); source.EmitRead(ctx); ctx.Return(); return (BlobDeserializer)ctx.method.CreateDelegate(typeof(BlobDeserializer)); }
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) { long ticks = ((DateTime)value).ToUniversalTime().Ticks; isqLite3Api.BindInt64(stmt, index, ticks); } else { string val = ((DateTime)value).ToUniversalTime().ToString(DateTimeFormat, CultureInfo.InvariantCulture); isqLite3Api.BindText16(stmt, index, val, -1, NegativePointer); } } else if (value is DateTimeOffset) { isqLite3Api.BindInt64(stmt, index, ((DateTimeOffset)value).UtcTicks); } else if (value is ISerializable <DateTime> ) { if (storeDateTimeAsTicks) { long ticks = ((ISerializable <DateTime>)value).Serialize().ToUniversalTime().Ticks; isqLite3Api.BindInt64(stmt, index, ticks); } else { string val = ((ISerializable <DateTime>)value).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[]) { 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()); } } }
public ReadonlySQLiteConnection(ISQLitePlatform sqlitePlatform, String databasePath, SQLiteOpenFlags openFlags, bool storeDateTimeAsTicks = true, IBlobSerializer serializer = null, IDictionary <String, TableMapping> tableMappings = null, IDictionary <Type, String> extraTypeMappings = null, IContractResolver resolver = null) : base(sqlitePlatform, databasePath, openFlags, storeDateTimeAsTicks, serializer, tableMappings, extraTypeMappings, resolver) { }