예제 #1
0
 internal static void ConvertConstantToString <valueType>(ConstantConverter converter, CharStream sqlStream, valueType value)
 {
     if (value == null)
     {
         sqlStream.WriteJsonNull();
     }
     else
     {
         converter.convertString(sqlStream, value.ToString());
     }
 }
예제 #2
0
 /// <summary>
 /// 排序字符串
 /// </summary>
 /// <param name="sqlTable">数据库表格操作工具</param>
 /// <param name="sqlStream">SQL表达式流</param>
 /// <param name="constantConverter"></param>
 /// <param name="query"></param>
 internal void WriteOrder(Table sqlTable, CharStream sqlStream, ConstantConverter constantConverter, ref SelectQuery <modelType> query)
 {
     if (Orders != null)
     {
         int isNext = 0;
         sqlStream.SimpleWriteNotNull(" order by ");
         foreach (KeyValue <LambdaExpression, bool> order in Orders)
         {
             if (isNext == 0)
             {
                 isNext = 1;
             }
             else
             {
                 sqlStream.Write(',');
             }
             if (order.Key == null)
             {
                 throw new ArgumentNullException();
             }
             sqlTable.Client.GetSql(order.Key, sqlStream, ref query);
             if (order.Value)
             {
                 sqlStream.SimpleWriteNotNull(" desc");
             }
         }
     }
     else if (SqlFieldOrders != null)
     {
         int isNext = 0;
         sqlStream.SimpleWriteNotNull(" order by ");
         foreach (KeyValue <Field, bool> order in SqlFieldOrders)
         {
             if (isNext == 0)
             {
                 if (query.IndexFieldName == null)
                 {
                     query.IndexFieldSqlName = constantConverter.ConvertName(query.IndexFieldName = order.Key.FieldInfo.Name);
                 }
                 isNext = 1;
             }
             else
             {
                 sqlStream.Write(',');
             }
             constantConverter.ConvertNameToSqlStream(sqlStream, order.Key.FieldInfo.Name);
             if (order.Value)
             {
                 sqlStream.SimpleWriteNotNull(" desc");
             }
         }
     }
 }
예제 #3
0
        /// <summary>
        /// 字段信息
        /// </summary>
        /// <param name="field">字段信息</param>
        /// <param name="attribute">数据库成员信息</param>
        internal Field(FieldIndex field, MemberAttribute attribute)
        {
            FieldInfo      = field.Member;
            MemberMapIndex = field.MemberIndex;
            DataMember     = format(attribute, FieldInfo.FieldType, ref IsSqlColumn);
            if ((NullableDataType = DataMember.DataType) == null)
            {
                NullableDataType = FieldInfo.FieldType;
            }
            if ((DataReaderMethod = DataReader.GetMethod(DataType = NullableDataType.nullableType() ?? NullableDataType)) == null)
            {
                if (IsSqlColumn)
                {
                    if (isSqlColumn(DataType))
                    {
                        return;
                    }
                    IsSqlColumn = false;
                }
#if NOJIT
                DataType         = NullableDataType = typeof(string);
                DataReaderMethod = DataReader.GetMethodInfo;
#else
                DataReaderMethod = DataReader.GetMethod(DataType = NullableDataType = typeof(string));
#endif
                IsUnknownJson     = true;
                ToSqlCastMethod   = jsonSerializeMethod.MakeGenericMethod(FieldInfo.FieldType);
                ToModelCastMethod = jsonParseMethod.MakeGenericMethod(FieldInfo.FieldType);
            }
            else
            {
                ToSqlCastMethod   = AutoCSer.Emit.CastType.GetMethod(FieldInfo.FieldType, DataType);
                ToModelCastMethod = AutoCSer.Emit.CastType.GetMethod(DataType, FieldInfo.FieldType);
            }
            SqlFieldName = keywordSearcher.SearchLower(FieldInfo.Name) < 0 ? FieldInfo.Name : toSqlName(FieldInfo.Name);
            if (attribute != null && attribute.IsNowTime && FieldInfo.FieldType == typeof(DateTime))
            {
                IsNowTime = true;
            }
            ToSqlMethod = ConstantConverter.GetMethod(DataType);
        }
예제 #4
0
        /// <summary>
        /// 字段信息
        /// </summary>
        /// <param name="field">字段信息</param>
        /// <param name="attribute">数据库成员信息</param>
        internal Field(FieldIndex field, MemberAttribute attribute)
        {
            FieldInfo      = field.Member;
            MemberMapIndex = field.MemberIndex;
            DataMember     = format(attribute, FieldInfo.FieldType, ref IsSqlColumn);
            if ((NullableDataType = DataMember.DataType) == null)
            {
                NullableDataType = FieldInfo.FieldType;
            }
            if ((DataReaderDelegate = DataReader.GetDelegate(DataType = NullableDataType.nullableType() ?? NullableDataType)) == null)
            {
                if (IsSqlColumn)
                {
                    if (isSqlColumn(DataType))
                    {
                        return;
                    }
                    IsSqlColumn = false;
                }
#if NOJIT
                DataType         = NullableDataType = typeof(string);
                DataReaderMethod = DataReader.GetMethodInfo;
#else
                DataReaderDelegate = DataReader.GetDelegate(DataType = NullableDataType = typeof(string));
#endif
                IsUnknownJson = true;
                AutoCSer.Sql.Metadata.GenericType GenericType = AutoCSer.Sql.Metadata.GenericType.Get(FieldInfo.FieldType);
                ToSqlCastMethod   = GenericType.JsonSerializeMethod;
                ToModelCastMethod = GenericType.JsonDeSerializeMethod;
            }
            else
            {
                ToSqlCastMethod   = AutoCSer.Emit.CastType.GetMethod(FieldInfo.FieldType, DataType);
                ToModelCastMethod = AutoCSer.Emit.CastType.GetMethod(DataType, FieldInfo.FieldType);
            }
            if (attribute != null && attribute.NowTimeType != NowTimeType.None && FieldInfo.FieldType == typeof(DateTime))
            {
                NowTimeType = attribute.NowTimeType;
            }
            ToSqlMethod = ConstantConverter.GetMethod(DataType);
        }