public virtual void Long_literal_generated_correctly() { var typeMapping = new LongTypeMapping("long", DbType.Int64); Test_GenerateSqlLiteral_helper(typeMapping, long.MinValue, "-9223372036854775808"); Test_GenerateSqlLiteral_helper(typeMapping, long.MaxValue, "9223372036854775807"); }
public virtual void GenerateSqlLiteral_for_Long_works_for_range_limits() { var typeMapping = new LongTypeMapping("long", DbType.Int64); var literal = typeMapping.GenerateSqlLiteral(long.MinValue); Assert.Equal("-9223372036854775808", literal); literal = typeMapping.GenerateSqlLiteral(long.MaxValue); Assert.Equal("9223372036854775807", literal); }
public FbTypeMappingSource( TypeMappingSourceDependencies dependencies, RelationalTypeMappingSourceDependencies relationalDependencies, IFbOptions options) : base(dependencies, relationalDependencies) { _isLegacy = options.IsLegacyDialect; _bigint = new LongTypeMapping( _isLegacy ? "INTEGER" : "BIGINT", DbType.Int64); _boolean = new FbBoolTypeMapping( _isLegacy ? "SMALLINT" : "BOOLEAN"); _storeTypeMappings = new Dictionary <string, RelationalTypeMapping>(StringComparer.OrdinalIgnoreCase) { { "BOOLEAN", _boolean }, { "SMALLINT", _smallint }, { "INTEGER", _integer }, { "BIGINT", _bigint }, { "CHAR", _char }, { "VARCHAR", _varchar }, { "BLOB SUB_TYPE TEXT", _clob }, { "BLOB SUB_TYPE BINARY", _binary }, { "FLOAT", _float }, { "DOUBLE PRECISION", _double }, { "DECIMAL", _decimal }, { "NUMERIC", _decimal }, { "TIMESTAMP", _timeStamp }, { "DATE", _date }, { "TIME", _time }, { "CHAR(16) CHARACTER SET OCTETS", _guid }, }; _clrTypeMappings = new Dictionary <Type, RelationalTypeMapping>() { { typeof(bool), _boolean }, { typeof(short), _smallint }, { typeof(int), _integer }, { typeof(long), _bigint }, { typeof(float), _float }, { typeof(double), _double }, { typeof(decimal), _decimal }, { typeof(byte[]), _binary }, { typeof(DateTime), _timeStamp }, { typeof(TimeSpan), _time }, { typeof(Guid), _guid } }; }
void AddCustomizedMappings() { // Mappings where we need literal string generation _baseClrMappings[typeof(string)] = _storeTypeMappings["text"] = new NpgsqlStringTypeMapping("text", NpgsqlDbType.Text); _storeTypeMappings["varchar"] = new NpgsqlStringTypeMapping("varchar", NpgsqlDbType.Varchar); _storeTypeMappings["char"] = new NpgsqlStringTypeMapping("char", NpgsqlDbType.Char); _storeTypeMappings["citext"] = new NpgsqlStringTypeMapping("citext", NpgsqlDbType.Citext); _storeTypeMappings["json"] = new NpgsqlStringTypeMapping("json", NpgsqlDbType.Json); _storeTypeMappings["jsonb"] = new NpgsqlStringTypeMapping("jsonb", NpgsqlDbType.Jsonb); _baseClrMappings[typeof(char)] = new CharTypeMapping("text", DbType.String); _baseClrMappings[typeof(DateTime)] = _storeTypeMappings["timestamp"] = new DateTimeTypeMapping("timestamp", DbType.DateTime); _baseClrMappings[typeof(DateTimeOffset)] = _storeTypeMappings["timestamptz"] = new NpgsqlDateTimeOffsetTypeMapping("timestamptz", DbType.DateTimeOffset); _baseClrMappings[typeof(TimeSpan)] = _storeTypeMappings["interval"] = new NpgsqlTimeSpanTypeMapping(); _baseClrMappings[typeof(bool)] = _storeTypeMappings["bool"] = new NpgsqlBoolTypeMapping(); _baseClrMappings[typeof(decimal)] = new DecimalTypeMapping("numeric", DbType.Decimal); // Note that "decimal" in PostgreSQL is just an alias for numeric, PostgreSQL itself always reports numeric for column types. _baseClrMappings[typeof(Guid)] = _storeTypeMappings["uuid"] = new GuidTypeMapping("uuid", DbType.Guid); _baseClrMappings[typeof(byte[])] = _storeTypeMappings["bytea"] = new NpgsqlByteArrayTypeMapping(); // The following isn't necessary for int itself - a simple ToString() (the default) produces the right // literal representation. However, with an explicit int mapping the standard mapping would be returned // for enums, and there a simple ToString produces the enum *name*. // Example for test for enum literal: InheritanceNpgsqlTest.Can_query_just_roses _baseClrMappings[typeof(short)] = _storeTypeMappings["int2"] = new ShortTypeMapping("int2", DbType.Int16); _baseClrMappings[typeof(int)] = _storeTypeMappings["int4"] = new IntTypeMapping("int4", DbType.Int32); _baseClrMappings[typeof(long)] = _storeTypeMappings["int8"] = new LongTypeMapping("int8", DbType.Int64); // uint is special: there are three internal system uint types: oid, xid, cid. None are supposed to // be truly user-facing, so we don't want to automatically map uint properties to any of them. // However, if the user explicitly sets the properties store type to oid/xid/cid, we want to allow // that (especially since the xmin system column is important for optimistic concurrency). // EFCore doesn't allow a situation where a CLR type has no default store type, so we arbitrarily // choose oid. _baseClrMappings[typeof(uint)] = new NpgsqlBaseTypeMapping("oid", typeof(uint), NpgsqlDbType.Oid); }