public static void Insert(CharStream sqlStream, MemberMap memberMap, valueType value, ConstantConverter converter) { #if NOJIT if (fields != null) { object[] sqlColumnParameters = null, castParameters = null, parameters = null; byte isNext = 0; foreach (sqlModel.insertField field in fields) { if (memberMap.IsMember(field.Field.MemberMapIndex)) { if (isNext == 0) { isNext = 1; } else { sqlStream.Write(','); } AutoCSer.code.cSharp.sqlModel.fieldInfo fieldInfo = field.Field; if (fieldInfo.IsSqlColumn) { if (sqlColumnParameters == null) { sqlColumnParameters = new object[] { sqlStream, null, converter } } ; sqlColumnParameters[1] = fieldInfo.Field.GetValue(value); field.SqlColumnMethod.Invoke(null, sqlColumnParameters); } else { object memberValue = fieldInfo.Field.GetValue(value); if (fieldInfo.ToSqlCastMethod != null) { if (castParameters == null) { castParameters = new object[1]; } castParameters[0] = memberValue; memberValue = fieldInfo.ToSqlCastMethod.Invoke(null, castParameters); } if (parameters == null) { parameters = new object[] { sqlStream, null } } ; parameters[1] = memberValue; fieldInfo.ToSqlMethod.Invoke(converter, parameters); } } } } #else if (inserter != null) { inserter(sqlStream, memberMap, value, converter); } #endif }
/// <summary> /// 设置字段信息 /// </summary> /// <param name="field"></param> public void Set(AutoCSer.code.cSharp.sqlModel.fieldInfo field) { Field = field; if (field.IsSqlColumn) { SqlColumnMethod = sqlColumn.verifyDynamicMethod.GetTypeVerifyer(field.DataType); } }
public static void Write(valueType value, object[] values, ref int index) { #if NOJIT if (fields != null) { object[] sqlColumnParameters = null, castParameters = null; object objectValue = value; foreach (sqlModel.toArrayField field in fields) { AutoCSer.code.cSharp.sqlModel.fieldInfo fieldInfo = field.Field; if (fieldInfo.IsSqlColumn) { if (sqlColumnParameters == null) { sqlColumnParameters = new object[] { null, values, null } } ; sqlColumnParameters[0] = fieldInfo.Field.GetValue(objectValue); sqlColumnParameters[2] = index; field.SqlColumnMethod.Invoke(null, sqlColumnParameters); index = (int)sqlColumnParameters[2]; } else { object memberValue = fieldInfo.Field.GetValue(objectValue); if (field.NullableHasValueMethod == null) { if (fieldInfo.ToSqlCastMethod != null) { if (castParameters == null) { castParameters = new object[1]; } castParameters[0] = memberValue; memberValue = fieldInfo.ToSqlCastMethod.Invoke(null, castParameters); } } else { memberValue = (bool)field.NullableHasValueMethod.Invoke(memberValue, null) ? field.NullableValueMethod.Invoke(memberValue, null) : null; } values[index++] = memberValue; } } } #else if (defaultWriter != null) { defaultWriter(value, values, ref index); } #endif else if (custom != null) { custom.ToArray(value, values, ref index); } }
public static void Set(DbDataReader reader, modelType value, MemberMap memberMap) { #if NOJIT if (fields != null) { int index = 0; object[] sqlColumnParameters = null, castParameters = null; foreach (sqlModel.setField field in fields) { AutoCSer.code.cSharp.sqlModel.fieldInfo fieldInfo = field.Field; if (memberMap.IsMember(fieldInfo.MemberMapIndex)) { if (fieldInfo.DataReaderMethod == null) { if (sqlColumnParameters == null) { sqlColumnParameters = new object[] { reader, null, null } } ; sqlColumnParameters[1] = null; sqlColumnParameters[2] = index; field.SqlColumnMethod.Invoke(null, sqlColumnParameters); fieldInfo.Field.SetValue(value, sqlColumnParameters[1]); index = (int)sqlColumnParameters[2]; } else { object memberValue; if (fieldInfo.DataType == fieldInfo.NullableDataType && (fieldInfo.DataType.IsValueType || !fieldInfo.DataMember.IsNull)) { memberValue = reader[index++]; if (fieldInfo.ToModelCastMethod != null) { if (castParameters == null) { castParameters = new object[1]; } castParameters[0] = memberValue; memberValue = fieldInfo.ToModelCastMethod.Invoke(null, castParameters); } } else if (reader.IsDBNull(index)) { memberValue = null; ++index; } else { memberValue = reader[index++]; if (fieldInfo.ToModelCastMethod != null && fieldInfo.DataType == fieldInfo.NullableDataType) { if (castParameters == null) { castParameters = new object[1]; } castParameters[0] = memberValue; memberValue = fieldInfo.ToModelCastMethod.Invoke(null, castParameters); } } fieldInfo.Field.SetValue(value, memberValue); } } } } #else if (setter != null) { setter(reader, value, memberMap); } #endif }
public static bool Verify(modelType value, MemberMap memberMap, Table sqlTool) { #if NOJIT if (fields != null) { object[] sqlColumnParameters = null, castParameters = null; foreach (sqlModel.verifyField field in fields) { AutoCSer.code.cSharp.sqlModel.fieldInfo fieldInfo = field.Field; if (memberMap.IsMember(fieldInfo.MemberMapIndex)) { object memberValue = fieldInfo.Field.GetValue(value); if (field.IsSqlVerify) { if (!fieldInfo.Field.FieldType.IsValueType && memberValue == null) { return(false); } if (!(bool)((AutoCSer.emit.sqlTable.ISqlVerify)memberValue).IsSqlVeify()) { return(false); } } else if (fieldInfo.IsSqlColumn) { if (sqlColumnParameters == null) { sqlColumnParameters = new object[] { null, sqlTool, null } } ; sqlColumnParameters[0] = memberValue; sqlColumnParameters[2] = fieldInfo.Field.Name; if (!(bool)field.SqlColumnMethod.Invoke(null, sqlColumnParameters)) { return(false); } } else if (fieldInfo.DataType == typeof(string)) { if (fieldInfo.ToSqlCastMethod != null) { if (castParameters == null) { castParameters = new object[1]; } castParameters[0] = memberValue; memberValue = fieldInfo.ToSqlCastMethod.Invoke(null, castParameters); } dataMember dataMember = fieldInfo.DataMember; if (!sqlTool.StringVerify(fieldInfo.Field.Name, (string)memberValue, dataMember.MaxStringLength, dataMember.IsAscii, dataMember.IsNull)) { return(false); } } else { if (fieldInfo.ToSqlCastMethod != null && !fieldInfo.IsUnknownJson) { if (castParameters == null) { castParameters = new object[1]; } castParameters[0] = memberValue; memberValue = fieldInfo.ToSqlCastMethod.Invoke(null, castParameters); } if (memberValue == null) { sqlTool.NullVerify(fieldInfo.Field.Name); return(false); } } } } } return(true); #else return(verifyer == null || verifyer(value, memberMap, sqlTool)); #endif }
public static bool Verify(valueType value, Table sqlTool, string columnName) { #if NOJIT if (fields != null) { string[] columnNames = GetColumnNames(columnName); object[] sqlColumnParameters = null, castParameters = null; object objectValue = value; int index = 0; foreach (sqlColumn.verifyDynamicMethod.field field in fields) { AutoCSer.code.cSharp.sqlModel.fieldInfo fieldInfo = field.Field; object memberValue = fieldInfo.Field.GetValue(objectValue); if (fieldInfo.IsSqlColumn) { if (sqlColumnParameters == null) { sqlColumnParameters = new object[] { null, sqlTool, null } } ; sqlColumnParameters[0] = memberValue; sqlColumnParameters[2] = columnNames[index]; if (!(bool)field.SqlColumnMethod.Invoke(null, sqlColumnParameters)) { return(false); } } else if (fieldInfo.DataType == typeof(string)) { if (fieldInfo.ToSqlCastMethod != null) { if (castParameters == null) { castParameters = new object[1]; } castParameters[0] = memberValue; memberValue = fieldInfo.ToSqlCastMethod.Invoke(null, castParameters); } dataMember dataMember = fieldInfo.DataMember; if (!sqlTool.StringVerify(columnNames[index], (string)memberValue, dataMember.MaxStringLength, dataMember.IsAscii, dataMember.IsNull)) { return(false); } } else { if (fieldInfo.ToSqlCastMethod != null && !fieldInfo.IsUnknownJson) { if (castParameters == null) { castParameters = new object[1]; } castParameters[0] = memberValue; memberValue = fieldInfo.ToSqlCastMethod.Invoke(null, castParameters); } if (memberValue == null) { sqlTool.NullVerify(columnNames[index]); return(false); } } ++index; } return(true); } #else if (verifyer != null) { return(verifyer(value, sqlTool, GetColumnNames(columnName))); } #endif return(custom == null || custom.Verify(value, sqlTool, columnName)); }