You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Richard Frovarp <rf...@apache.org> on 2011/09/29 20:23:13 UTC

Modeling object queries

I'm trying to figure out how to model a couple of named queries, 
preferably in the object modeler:

I've got this working

Qualifier: status = $status

I can't get this working

Qualifier: status = "Completed"

In fact, that query returns nothing, but

status != "Completed"

Returns everything, including objects where status = "Completed".

RE: Modeling object queries

Posted by "Durchholz, Joachim" <Jo...@hennig-fahrzeugteile.de>.
> If you are using the modeler, you can just say:
> 
> status = "Completed"
> 
> without escaping the quotes.

I can see how that happens, but I'd still suggest using single quotes.
Almost all database (with the notable exception of Mysql) use double quotes around table/column names and similar. Single quotes are the universally-accepted SQL-standard delimiter for strings.

Reasons:
a) (Not sure if this holds water) If Modeler does not interpret the input but passes it through unchanged, and the SQL backend you're using happens to use " for string delimiters, you'll be in for a nasty surprise as soon as you swich to a more standard-compliant backend.
b) Even if Modeler interprets those quotes by itself, the Modeler team might decide that double quotes should be interpreted as in the SQL standard. There might be very good reasons to do that. Again, you'll be in for a nasty surprise.
c) If modeler interprets those quotes, you're hitting less-well-tested code paths inside Modeler, triggering bugs with a higher probability. (This might actually be a good thing in your eyes, depending on project status and policy.)
d) You might as well train yourself for using the right quotes, so you don't make silly mistakes when writing SQL.

Just my experience with such things in general. I'm not currently using Modeler, so there might be considerations that I couldn't know.

Regards,
Jo

Re: Modeling object queries

Posted by Richard Frovarp <rf...@apache.org>.
Thanks. Looking at the output it was doing what I wanted to do. I was 
able to see my error. If you are using the modeler, you can just say:

status = "Completed"

without escaping the quotes.

On 09/29/2011 01:34 PM, John Huss wrote:
> http://cayenne.apache.org/doc30/building-expressions.htmlThat looks right
> according to this page:
>
> Character constants should be enclosed in single or double quotes:
>
> // e1 and e2 are equivalentExpression e1 = Expression.fromString("name
> = 'ABC'");
> Expression e2 = Expression.fromString("name = \"ABC\"");
>
> One link the to formal grammer that I see in a couple places is broken:
> formal grammar<http://incubator.apache.org/cayenne/1_2/grammar/ExpressionParser.html>
>
> But this one works:
> http://cayenne.apache.org/doc30/bnf-for-expressionparser.html
>
> It says:
>
> simpleCondition 	::= 	scalarExpression ( simpleNotCondition |
>                                       ( "=" | "==" ) scalarExpression |
>                                       ( "!=" | "<>" ) scalarExpression |
>
> I would check the SQL that is outputted and run it against the database
> manually - it may be your expectation that is wrong.
>
> John
>
> On Thu, Sep 29, 2011 at 1:23 PM, Richard Frovarp<rf...@apache.org>wrote:
>
>> I'm trying to figure out how to model a couple of named queries, preferably
>> in the object modeler:
>>
>> I've got this working
>>
>> Qualifier: status = $status
>>
>> I can't get this working
>>
>> Qualifier: status = "Completed"
>>
>> In fact, that query returns nothing, but
>>
>> status != "Completed"
>>
>> Returns everything, including objects where status = "Completed".
>>
>


Re: Modeling object queries

Posted by John Huss <jo...@gmail.com>.
http://cayenne.apache.org/doc30/building-expressions.htmlThat looks right
according to this page:

Character constants should be enclosed in single or double quotes:

// e1 and e2 are equivalentExpression e1 = Expression.fromString("name
= 'ABC'");
Expression e2 = Expression.fromString("name = \"ABC\"");

One link the to formal grammer that I see in a couple places is broken:
formal grammar<http://incubator.apache.org/cayenne/1_2/grammar/ExpressionParser.html>

But this one works:
http://cayenne.apache.org/doc30/bnf-for-expressionparser.html

It says:

simpleCondition 	::= 	scalarExpression ( simpleNotCondition |
                                     ( "=" | "==" ) scalarExpression |
                                     ( "!=" | "<>" ) scalarExpression |

I would check the SQL that is outputted and run it against the database
manually - it may be your expectation that is wrong.

John

On Thu, Sep 29, 2011 at 1:23 PM, Richard Frovarp <rf...@apache.org>wrote:

> I'm trying to figure out how to model a couple of named queries, preferably
> in the object modeler:
>
> I've got this working
>
> Qualifier: status = $status
>
> I can't get this working
>
> Qualifier: status = "Completed"
>
> In fact, that query returns nothing, but
>
> status != "Completed"
>
> Returns everything, including objects where status = "Completed".
>