Exemple #1
0
        static string Equals(Field field, object value, bool equals)
        {
            if (value == null)
            {
                return IsNull(field, equals);
            }
            else
            {
                if (field is IColumn)
                {
                    return ((IColumn)field).Name.SqlEscape() +
                        (equals ? " = " : " <> ") + SqlPreCommandSimple.Encode(value);
                }

                throw new NotSupportedException("Impossible to compare {0} to {1}".FormatWith(field, value));
            }
        }
Exemple #2
0
 static bool IsComplexIB(Field field)
 {
     return field is FieldImplementedBy && ((FieldImplementedBy)field).ImplementationColumns.Count > 1;
 }
Exemple #3
0
        public static string IsNull(Field field, bool equals)
        {
            string isNull = equals ? "{0} IS NULL" : "{0} IS NOT NULL";

            if (field is IColumn)
            {
                var col = ((IColumn)field);

                string result = isNull.FormatWith(col.Name.SqlEscape());

                if (!SqlBuilder.IsString(col.SqlDbType))
                    return result;

                return result + (equals ? " OR " : " AND ") + (col.Name.SqlEscape() + (equals ? " == " : " <> ") + "''");

            }
            else if (field is FieldImplementedBy)
            {
                var ib = (FieldImplementedBy)field;

                return ib.ImplementationColumns.Values.Select(ic => isNull.FormatWith(ic.Name.SqlEscape())).ToString(equals ? " AND " : " OR ");
            }
            else if (field is FieldImplementedByAll)
            {
                var iba = (FieldImplementedByAll)field;

                return isNull.FormatWith(iba.Column.Name.SqlEscape()) +
                    (equals ? " AND " : " OR ") +
                    isNull.FormatWith(iba.ColumnType.Name.SqlEscape());
            }
            else if (field is FieldEmbedded)
            {
                var fe = (FieldEmbedded)field;

                if (fe.HasValue == null)
                    throw new NotSupportedException("{0} is not nullable".FormatWith(field));

                return fe.HasValue.Name.SqlEscape() + " = TRUE";
            }

            throw new NotSupportedException(isNull.FormatWith(field.GetType())); 
        }