1 Sep 2007 08:42
Re: Null pointer in Cayenne 2.0.3 code
Alexander Lamb (dev <alamb <at> mac.com>
2007-09-01 06:42:04 GMT
2007-09-01 06:42:04 GMT
> I see Andrus already replied a bit ...
>
> One thing I'd suggest doing when you go back and re-work it is to
> not do:
>
> Expression q = Expression.fromString("patientPk = '" + pk + "'");
>
> This could cause you problems if your string value ever has single
> quotes in it or other special characters. It is far better to use
> bindings. A better pattern for strings (or just in general) would
> look like:
>
> final Expression expression = Expression.fromString("patientPk =
> $pk");
> Map parameters = new HashMap(1);
> parameters.put("pk", pk);
> SelectQuery query = new SelectQuery(Patient.class,
> expression.expWithParameters(parameters));
> List items = dataContext.performQuery(query);
>
> By creating an expression with substitution parameters, Cayenne will
> quote and escape text correctly for you. Of course, perhaps you
> already know all of this and it was is just test code you were trying
> to get to work.
Exactly... in desperation, you end up trying many different things!
>
> /dev/mrg
>
(Continue reading)
RSS Feed