public Type MapDbToClr(string dbType) { switch (dbType) { case "CHAR": case "VARCHAR": case "VARCHAR2": case "ROWID": case "LONG": case "CLOB": return(typeof(string)); case "NUMBER": return(typeof(decimal)); case "DATE": return(typeof(DateTime)); case "BLOB": case "RAW": return(typeof(byte[])); default: GenerateExceptionHelper.ThrowUnknownMapType(dbType); return(typeof(void)); } }
public string MapClrToDb(Type clrType) { if (clrType.IsGenericType && clrType.GetGenericTypeDefinition() == typeof(Nullable <>)) { clrType = Nullable.GetUnderlyingType(clrType); } if (clrType.IsEnum) { return(" int "); } switch (Type.GetTypeCode(clrType)) { case TypeCode.String: case TypeCode.Char: return(" nvarchar"); case TypeCode.Int16: case TypeCode.Int32: case TypeCode.UInt16: case TypeCode.UInt32: return(" int "); case TypeCode.Int64: case TypeCode.UInt64: return(" long "); case TypeCode.DateTime: return(" datetime "); case TypeCode.Boolean: return(" bit "); case TypeCode.Decimal: return(" decimal "); case TypeCode.Single: return(" real "); case TypeCode.Byte: return(" tinyint "); default: if (clrType == typeof(Guid)) { return(" uniqueidentifier "); } else if (clrType == typeof(byte[])) { return(" binary "); } else { GenerateExceptionHelper.ThrowUnknownMapType(clrType); return(string.Empty); } } }
public override string PagedQuery(IQuery query, uint numberPerPage, uint page) { query.ThrowIfNullArgument(nameof(query)); if (page == 0 || numberPerPage == 0) { GenerateExceptionHelper.ThrowMustGreaterThanZero(); } if (query.Order == null) { GenerateExceptionHelper.ThrowPagedQueryMustSpecifyOrder(); } try { IReadOnlyList <SingleEntityView> svList = _vv.VisitAlias(query.View); StringBuilder sql = new StringBuilder(); if (page == 1) { sql.Append(_tr.Select).AppendFormat(TOP_N, numberPerPage); sql.Append(_cb.BuildSelectColumns(query.View)); sql.Append(_tr.From).Append(_vv.BuildJoinClause(query.View)); if (query.Criteria != null) { sql.Append(_tr.Where); sql.Append(_cv.BuildWhereFilters(query.Criteria, svList)); } sql.Append(_tr.OrderBy).Append(_ov.BuildOrderClause(query.Order, svList)); return(sql.ToString()); } else { StringBuilder sub = new StringBuilder(); sub.Append(_tr.Select).AppendFormat(TOP_N, (page - 1) * numberPerPage).Append(_ov.BuildOrderSelectColumns(query.Order, svList)); sub.Append(_tr.From).Append(_vv.BuildJoinClause(query.View)); if (query.Criteria != null) { sub.Append(_tr.Where).Append(_cv.BuildWhereFilters(query.Criteria, svList)); } sub.Append(_tr.OrderBy).Append(_ov.BuildOrderClause(query.Order, svList)); sql.Append(_tr.Select).AppendFormat(TOP_N, numberPerPage).Append(_cb.BuildSelectColumns(query.View)); sql.Append(_tr.From).Append(_vv.BuildJoinClause(query.View)); sql.Append(_tr.Where).Append(_ov.BuildOrderSelectColumns(query.Order, svList)).Append(_tr.NotIn).Append(sub.Bracketing(StringPair.Parenthesis)); if (query.Criteria != null) { sql.Append(_tr.And).Append(_cv.BuildWhereFilters(query.Criteria, svList)); } sql.Append(_tr.OrderBy).Append(_ov.BuildOrderClause(query.Order, svList)); return(sql.ToString()); } } catch (Exception ex) { throw ex.CreateWrapException <SQLGenerateException>(); } }
public Type MapDbToClr(string dbType) { switch (dbType) { case "int": case "int identity": return(typeof(int)); case "bigint": return(typeof(long)); case "bit": return(typeof(bool)); case "decimal": case "numeric": return(typeof(decimal)); case "varchar": case "nvarchar": case "char": case "nchar": case "text": return(typeof(string)); case "float": return(typeof(double)); case "real": return(typeof(float)); case "uniqueidentifier": return(typeof(Guid)); case "date": case "datetime": case "datetime2": return(typeof(DateTime)); case "binary": case "varbinary": return(typeof(byte[])); case "smallint": return(typeof(short)); case "tinyint": return(typeof(byte)); default: GenerateExceptionHelper.ThrowUnknownMapType(dbType); return(typeof(void)); } }
public string MapClrToDb(Type clrType) { if (clrType.IsGenericType && clrType.GetGenericTypeDefinition() == typeof(Nullable <>)) { clrType = Nullable.GetUnderlyingType(clrType); } if (clrType.IsEnum) { return(" integer "); } switch (Type.GetTypeCode(clrType)) { case TypeCode.String: case TypeCode.Char: return(" varchar2"); case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: return(" integer "); case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Decimal: case TypeCode.Single: case TypeCode.Double: return(" decimal "); case TypeCode.DateTime: return(" date "); case TypeCode.Boolean: return(" integer "); default: if (clrType == typeof(Guid)) { return(" varchar2(64) "); } else if (clrType == typeof(byte[])) { return(" BLOB "); } else { GenerateExceptionHelper.ThrowUnknownMapType(clrType); return(string.Empty); } } }
public Type MapDbToClr(string dbType) { switch (dbType) { case "130": case "202": return(typeof(string)); case "128": return(typeof(byte[])); case "20": return(typeof(long)); case "3": return(typeof(int)); case "11": return(typeof(bool)); case "6": case "14": case "131": return(typeof(decimal)); case "7": case "133": case "134": return(typeof(DateTime)); case "72": return(typeof(Guid)); case "2": return(typeof(short)); case "4": return(typeof(float)); case "16": return(typeof(byte)); default: GenerateExceptionHelper.ThrowUnknownMapType(dbType); return(typeof(void)); } }
public override IPropertyMapInfo GetPrimaryKeyNeedBinding <T>() { IObjectMapInfo map = _cache.GetMapInfo(typeof(T), true); if (map.PrimaryKeyGenerate == PrimaryKeyGenerate.Customized && map.PKGenerateString.StartsWith(ConstantString.SEQ_Prefix)) { if (map.PKStatus == PrimaryKeyStatus.Single) { return(map.PrimaryKeyMaps.First()); } else { GenerateExceptionHelper.ThrowPrimaryKeyDefineNotSupport(typeof(T)); } } return(null); }
public override string PagedQuery(IQuery query, uint numberPerPage, uint page) { query.ThrowIfNullArgument(nameof(query)); if (page == 0 || numberPerPage == 0) { GenerateExceptionHelper.ThrowMustGreaterThanZero(); } if (query.Order == null) { GenerateExceptionHelper.ThrowPagedQueryMustSpecifyOrder(); } try { string pagedQuery = "SELECT * FROM (SELECT row_.*, rownum rownum_ FROM ({0}) row_ WHERE rownum <= {1}) WHERE rownum_ > {2}"; var n1 = numberPerPage * page; var n2 = numberPerPage * (page - 1); var svList = _vv.VisitAlias(query.View); StringBuilder str = new StringBuilder(); str.Append(_tr.Select).Append(_cb.BuildSelectColumns(query.View)); str.Append(_tr.From).Append(_vv.BuildJoinClause(query.View)); if (query.Criteria != null) { str.Append(_tr.Where).Append(_cv.BuildWhereFilters(query.Criteria, svList)); } str.Append(_tr.OrderBy).Append(_ov.BuildOrderClause(query.Order, svList)); return(string.Format(pagedQuery, str, n1, n2)); } catch (Exception ex) { throw ex.CreateWrapException <SQLGenerateException>(); } }