private static object GetQueryValue(IDatabaseQuery query, int index, FieldMetadata fieldMetadata) { if (query.IsColumnNull(index)) { return(null); } if (fieldMetadata is ByteFieldMetadata) { return(query.GetByte(index)); } if (fieldMetadata is IntegerFieldMetadata) { return(query.GetInt32(index)); } if (fieldMetadata is StringFieldMetadata) { return(query.GetString(index)); } if (fieldMetadata is DoubleFieldMetadata) { return(Convert.ToDouble(query.GetFloat(index))); } if (fieldMetadata is FloatFieldMetadata) { return(query.GetFloat(index)); } if (fieldMetadata is DateTimeFieldMetadata) { return(query.GetDateTime(index)); } if (fieldMetadata is BooleanFieldMetadata) { return(query.GetBool(index)); } throw new NotSupportedException(fieldMetadata.GetType().Name); }
private static void AppendQueryValue(StringBuilder builder, object value, FieldMetadata fieldMetadata, IDatabase database) { if (value == null) { AppendQueryNull(builder); } else if (value is int || value.GetType().IsEnum) { var iVal = (int)value; if (iVal == 0 && fieldMetadata is ForeignKeyFieldMetadata) { AppendQueryNull(builder); } else { builder.Append(iVal); } } else if (value is string) { var sVal = (string)value; if (sVal.Length == 0) { AppendQueryNull(builder); } else { builder.AppendFormat("'{0}'", database.Escape(sVal)); } } else if (value is double) { var dVal = (double)value; builder.Append(dVal); } else if (value is float) { var dVal = (float)value; builder.Append(dVal); } else if (value is DateTime) { var dttm = (DateTime)value; builder.AppendFormat("#{0}#", dttm); } else if (value is Date) { var date = (Date)value; builder.AppendFormat("#{0}/{1}/{2}#", date.Month, date.Day, date.Year); } else if (value is bool) { if ((bool)value) { builder.Append("YES"); } else { builder.Append("NO"); } } else { throw new NotSupportedException(fieldMetadata.GetType().Name); } }