Skip to content

Support Not Operator #76

Open
Open
@ssteiner

Description

@ssteiner

Hi

I've already implemented this in an older build of the main sqlite-net, but I'm sure it would help some others, so here goes (I'm sorry I'm not really a git user so I've never done a pull request)

In TableQuery.cs, method private CompileResult CompileExpr(Expression expr, List queryArgs), before else if (expr.NodeType == ExpressionType.MemberAccess) you add another else if containing the following code

else if (expr.NodeType == ExpressionType.Not) {

            var n = (UnaryExpression)expr;
            var ty = n.Type;
            var valn = CompileExpr(n.Operand, queryArgs);
            switch (n.Operand.NodeType)
            {
                case ExpressionType.MemberAccess:
                    valn.CommandText += " = 0";
                    break;
                case ExpressionType.Call:
                    valn.CommandText = valn.CommandText.Replace(" like ", " not like ");
                    valn.CommandText = valn.CommandText.Replace(" in ", " not in ");
                    valn.CommandText = valn.CommandText.Replace(" = ", " <> ");
                    break;
                default:
                    break;
            }
            return new CompileResult { CommandText = valn.CommandText };
}

Do that and you get your standard NOT operator support working for booleans, strings, collections and values you can compare with = and <>.

Rather than having to keep my own copy of the lib, I think it would be easier to just mainline it.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions