Hi.

Nobody  (sadly  :)  responded  to  my  bug  report  e-mail  sent earlier. I
understand - the vacation period is in full bloom :)

Anyway,  I  think  I've found the buggy code in HsqlQueryExpression class -
a  hashmap  of  table aliases was not used properly in method "addTables" -
take a look:

>     private void addTables(StringBuffer buffer, Hashtable tables, boolean first)
>     {
>       Enumeration enum = tables.elements();
>       while ( enum.hasMoreElements() )
>       {
>         if ( first )
>           first = false;
>         else
>           buffer.append( JDBCSyntax.TableSeparator );
> 
>         buffer.append( _factory.quoteName( (String) enum.nextElement() ) );
>       }
>     }

Now,  the  aliases  are  not  used  at  all,  and JDBCQueryExpression class
(superclass  of  HsqlQueryExpression  class)  generates  joins  USING those
aliases, this results in invalid SQL expressions I reported earlier.

The corrected addTables method (ripped shamelessly from JDBCQueryExpression
class) should look like this:

>     private void addTables(StringBuffer buffer, Hashtable tables, boolean first)
>     {
>       Enumeration enum = tables.keys();
>         while ( enum.hasMoreElements() ) {
>                   if ( first )
>                       first = false;
>                   else
>                       buffer.append( JDBCSyntax.TableSeparator );
>                   
>                   String tableAlias = (String) enum.nextElement();
>                   String tableName = (String) tables.get( tableAlias );
>                   if( tableAlias.equals( tableName ) ) {
>                       buffer.append( _factory.quoteName( tableName ) );
>                   } else {
>                       buffer.append( _factory.quoteName( tableName ) + " " +
>                                   _factory.quoteName( tableAlias ) );
>                   }
>         }
>     }

Now,  this  works fine for me... although there are still many vague points
about   HsqlQueryExpression   class.   Like   the   fact that it subclasses
JDBCQueryExpression  and  at  the same time almost completely redefines the
SQL generation methods... what's the sense of this?

Anyway,  patch  diff  included  below.  Hope  this  helps  in fixing HSQLDB
generation, because HSQLDB rocks :)

Dawid


--

265,274c265,280
<       Enumeration enum = tables.elements();
<       while ( enum.hasMoreElements() )
<       {
<         if ( first )
<           first = false;
<         else
<           buffer.append( JDBCSyntax.TableSeparator );
<
<         buffer.append( _factory.quoteName( (String) enum.nextElement() ) );
<       }
---
>       Enumeration enum = tables.keys();
>         while ( enum.hasMoreElements() ) {
>                   if ( first )
>                       first = false;
>                   else
>                       buffer.append( JDBCSyntax.TableSeparator );
>
>                   String tableAlias = (String) enum.nextElement();
>                   String tableName = (String) tables.get( tableAlias );
>                   if( tableAlias.equals( tableName ) ) {
>                       buffer.append( _factory.quoteName( tableName ) );
>                   } else {
>                       buffer.append( _factory.quoteName( tableName ) + " " +
>                                   _factory.quoteName( tableAlias ) );
>                   }
>         }

_______________________
Dawid Weiss, http://www.cs.put.poznan.pl/dweiss
Laboratory of Intelligent Decision Support Systems, Poznan UT, Poland

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to