db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jakob Braeuchi <jbraeu...@gmx.ch>
Subject Re: Bug Fix for SqlQueryStatement.appendInCriteria()
Date Sat, 04 Sep 2004 16:20:10 GMT
hi andrew,

thanks for the patch. unfortunately hsqldb does not like an empty in criteria ( 
WHERE A0.x IN () ) imo the best thing is to completely skip the criteria if it 
is empty.

jakob

Clute, Andrew schrieb:
> There is a bug with appendInCriteria that assumes that there is at least
> one value in the In Collection. 
> 
> Causes wicked problems if you pass in an empty Collection
> (ArrayIndexOutOfBoundsException) when it does the the values[size - 1]
> call.
> 
> Below is the simple fix for it:
> 
> 
> -Andrew
> 
>     /**
>      * Answer the SQL-Clause for an InCriteria
>      *
>      * @param alias
>      * @param pathInfo
>      * @param c InCriteria
>      * @param buf
>      */
>     private void appendInCriteria(TableAlias alias, PathInfo pathInfo,
> InCriteria c, StringBuffer buf)
>     {
>         appendColName(alias, pathInfo, c.isTranslateAttribute(), buf);
>         buf.append(c.getClause());
> 
>         if (c.getValue() instanceof Collection)
>         {
>             Object[] values = ((Collection) c.getValue()).toArray();
>             int size = ((Collection) c.getValue()).size();
> 
>             buf.append("(");
> 	if (size > 0)
> 	{
>            		for (int i = 0; i < size - 1; i++)
>             	{
>                 		appendParameter(values[i], buf);
>                 		buf.append(",");
>             	}
>             	appendParameter(values[size - 1], buf);
> 	}
>             buf.append(")");
>         }
>         else
>         {
>             appendParameter(c.getValue(), buf);
>         }
>     }
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message