public SQLiteTypeRegistry(SQLiteDbDriver driver) : base(driver) { var realTypes = new Type[] { typeof(Single), typeof(double), typeof(decimal) }; var stringTypes = new Type[] { typeof(string), typeof(char), /*typeof(DateTime), typeof(TimeSpan)*/ }; var blobTypes = new Type[] { typeof(Guid), typeof(Vita.Common.Binary), typeof(byte[]) }; var intTypes = new Type[] { typeof(byte), typeof(sbyte), typeof(Int16), typeof(UInt16), typeof(Int32), typeof(UInt32), }; var int64Types = new Type[] { typeof(Int64), typeof(UInt64) }; // Note: we associate multiple int types with single storage class, but intercept in particular cases // (in GetDbTypeInfo below), and provide specific DbType values and converters // We have to put Int32 into a separate class for enum types to work AddType("INT", DbType.Int32, typeof(Int32), clrTypes: intTypes, dbFirstClrType: typeof(Int32), aliases: "integer"); AddType("INT64", DbType.Int64, typeof(Int64), clrTypes: int64Types, dbFirstClrType: typeof(Int64)); AddType("REAL", DbType.Double, typeof(double), clrTypes: realTypes, dbFirstClrType: typeof(double)); AddType("TEXT", DbType.String, typeof(string), supportsMemo: true, clrTypes: stringTypes, dbFirstClrType: typeof(string)); AddType("BLOB", DbType.Binary, typeof(byte[]), supportsMemo: true, clrTypes: blobTypes, dbFirstClrType: typeof(Vita.Common.Binary), valueToLiteral: ConvertBinaryToLiteral); AddType("Date", DbType.DateTime, typeof(DateTime)); AddType("Time", DbType.DateTimeOffset, typeof(TimeSpan)); AddType("Bool", DbType.Boolean, typeof(bool)); Converters.AddConverter <string, TimeSpan>(x => TimeSpan.Parse((string)x), x => ((TimeSpan)x).ToString("G")); Converters.AddConverter <Int64, bool>(x => (Int64)x == 1, x => (bool)x ? 1L : 0L); RegisterAutoMemoTypes("TEXT", "BLOB"); }
public SQLiteTypeRegistry(SQLiteDbDriver driver) : base(driver) { // For all int types SQLite provider returns Int64, not sure about actual storage; so we set ColOutType to Int64 here for Int32 type var tdInt = AddDbTypeDef("int", typeof(Int32), mapColumnType: false, aliases: "integer"); MapMany(new[] { typeof(byte), typeof(sbyte), typeof(Int16), typeof(UInt16), typeof(Int32), typeof(UInt32) }, tdInt); IntTypeDef = tdInt; var tdInt64 = AddDbTypeDef("int64", typeof(Int64)); MapMany(new[] { typeof(Int64), typeof(UInt64) }, tdInt64); Int64TypeDef = tdInt64; var tdReal = AddDbTypeDef("real", typeof(double)); MapMany(new[] { typeof(Single), typeof(double), typeof(decimal) }, tdReal); var tdText = AddDbTypeDef("text", typeof(string)); MapMany(new[] { typeof(string), typeof(char) }, tdText); SpecialTypeDefs[DbSpecialType.String] = tdText; SpecialTypeDefs[DbSpecialType.StringAnsi] = tdText; SpecialTypeDefs[DbSpecialType.StringUnlimited] = tdText; SpecialTypeDefs[DbSpecialType.StringAnsiUnlimited] = tdText; var tdBlob = AddDbTypeDef("blob", typeof(byte[]), toLiteral: BytesToLiteral); MapMany(new Type[] { typeof(Guid), typeof(Vita.Entities.Binary), typeof(byte[]) }, tdBlob); SpecialTypeDefs[DbSpecialType.Binary] = tdBlob; SpecialTypeDefs[DbSpecialType.BinaryUnlimited] = tdBlob; // SQLite data provider can automatically handle 'date' values, if there's 'date' column association // it returns DateTime values from these columns. But in this case it cuts off milliseconds. // So we store dates/time as strings and handle conversion in code; DbReader still sometimes returns value as DateTime - // we handle it in code. // Important - we need to to set type name (affinity) to smth special, not just 'date' - otherwise provider recognizes // it and starts converting dates in DbReader and this blows up. Did not find any reliable way to disable this behavior var tdDate = AddDbTypeDef("date", typeof(string), mapColumnType: false, toLiteral: DateTimeToLiteral); Map(typeof(DateTime), tdDate); var tdTime = AddDbTypeDef("time", typeof(string), mapColumnType: false, toLiteral: TimeSpanToLiteral); Map(typeof(TimeSpan), tdTime); var tdBool = AddDbTypeDef("bool", typeof(Int32), mapColumnType: false, toLiteral: BoolToBitLiteral); Map(typeof(bool), tdBool); Converters.AddConverter <string, TimeSpan>(ParseTimeSpan, TimeSpanToString); Converters.AddConverter <Int32, bool>(IntToBool, x => (bool)x ? 1 : 0); Converters.AddConverter <string, DateTime>(ParseDateTime, DateTimeToString); }
public SQLiteDbSqlDialect(SQLiteDbDriver driver) : base(driver) { base.MaxParamCount = 999; // there's no form for offset-only query, so we just set limit (rowcount) to 10 million base.OffsetTemplate = new SqlTemplate(" LIMIT 10000000 OFFSET {0} "); base.OffsetLimitTemplate = new SqlTemplate(" LIMIT {1} OFFSET {0} "); base.DynamicSqlParameterPrefix = "@P"; base.BatchBeginTransaction = new TextSqlFragment("BEGIN;"); base.BatchCommitTransaction = new TextSqlFragment("COMMIT;"); // Change concat operation from Concat(a,b,c) -> a || b || c base.SqlTemplateConcatMany = new SqlTemplate("{0}"); base.SqlConcatListDelimiter = new TextSqlFragment("||"); }
public SQLiteTypeRegistry(SQLiteDbDriver driver) : base(driver) { var realTypes = new Type[] {typeof(Single), typeof(double), typeof(decimal)}; var stringTypes = new Type[] { typeof(string), typeof(char), typeof(DateTime), typeof(TimeSpan) }; var blobTypes = new Type[] { typeof(Guid), typeof(Vita.Common.Binary), typeof(byte[]) }; var intTypes = new Type[] { typeof(byte), typeof(sbyte), typeof(Int16), typeof(UInt16), typeof(Int32), typeof(UInt32), typeof(Int64), typeof(UInt64), typeof(bool), }; AddType("INTEGER", DbType.Int64, typeof(Int64), clrTypes: intTypes, dbFirstClrType: typeof(Int64), aliases: "int"); AddType("REAL", DbType.Double, typeof(double), clrTypes: realTypes, dbFirstClrType: typeof(double)); AddType("TEXT", DbType.String, typeof(string), supportsMemo: true, clrTypes: stringTypes, dbFirstClrType: typeof(string)); AddType("BLOB", DbType.Binary, typeof(byte[]), supportsMemo: true, clrTypes: blobTypes, dbFirstClrType: typeof(Vita.Common.Binary), valueToLiteral: ConvertBinaryToLiteral); Converters.AddConverter<string, DateTime>(x => StringToDateTime(x), x => DateTimeToString(x)); Converters.AddConverter<string, TimeSpan>(x => TimeSpan.Parse((string)x), x => ((TimeSpan)x).ToString("G")); Converters.AddConverter<Int64, bool>(x => (Int64)x == 1, x => (bool)x ? 1L : 0L); RegisterAutoMemoTypes("TEXT", "BLOB"); }