You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2005/04/23 20:43:40 UTC

cvs commit: db-torque/xdocs changes.xml

tfischer    2005/04/23 11:43:40

  Modified:    src/java/org/apache/torque/util SQLBuilder.java
               xdocs    changes.xml
  Log:
  Added support for using sql functions in order by clause
  See TRQS251 in Scarab
  
  Revision  Changes    Path
  1.4       +18 -8     db-torque/src/java/org/apache/torque/util/SQLBuilder.java
  
  Index: SQLBuilder.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/java/org/apache/torque/util/SQLBuilder.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SQLBuilder.java	18 Feb 2005 10:04:37 -0000	1.3
  +++ SQLBuilder.java	23 Apr 2005 18:43:40 -0000	1.4
  @@ -470,7 +470,10 @@
               for (int i = 0; i < orderBy.size(); i++)
               {
                   String orderByColumn = (String) orderBy.get(i);
  -                int dotPos = orderByColumn.lastIndexOf('.');
  +
  +                String strippedColumnName 
  +                        = removeSQLFunction(orderByColumn);
  +                int dotPos = strippedColumnName.lastIndexOf('.');
                   if (dotPos == -1)
                   {
                       throwMalformedColumnNameException(
  @@ -478,8 +481,7 @@
                               orderByColumn);
                   }
   
  -                String tableName =
  -                        orderByColumn.substring(0, dotPos);
  +                String tableName = strippedColumnName.substring(0, dotPos);
                   String table = crit.getTableForAlias(tableName);
                   if (table == null)
                   {
  @@ -488,20 +490,28 @@
   
                   // See if there's a space (between the column list and sort
                   // order in ORDER BY table.column DESC).
  -                int spacePos = orderByColumn.indexOf(' ');
  +                int spacePos = strippedColumnName.indexOf(' ');
                   String columnName;
                   if (spacePos == -1)
                   {
                       columnName =
  -                            orderByColumn.substring(dotPos + 1);
  +                            strippedColumnName.substring(dotPos + 1);
                   }
                   else
                   {
  -                    columnName = orderByColumn.substring(dotPos + 1, spacePos);
  +                    columnName = strippedColumnName.substring(
  +                            dotPos + 1,
  +                            spacePos);
                   }
                   ColumnMap column = dbMap.getTable(table).getColumn(columnName);
  -                if (column.getType() instanceof String)
  +                
  +                // only ignore case in order by for string columns
  +                // which do not have a function around them
  +                if (column.getType() instanceof String
  +                        && orderByColumn.indexOf('(') == -1) 
                   {
  +                    // find space pos relative to orderByColumn
  +                    spacePos = orderByColumn.indexOf(' ');
                       if (spacePos == -1)
                       {
                           orderByClause.add(
  
  
  
  1.154     +3 -0      db-torque/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/db-torque/xdocs/changes.xml,v
  retrieving revision 1.153
  retrieving revision 1.154
  diff -u -r1.153 -r1.154
  --- changes.xml	17 Apr 2005 10:45:43 -0000	1.153
  +++ changes.xml	23 Apr 2005 18:43:40 -0000	1.154
  @@ -28,6 +28,9 @@
     <body>
   
     <release version="3.2-dev" date="in CVS">
  +    <action type="add" dev="tfischer" issue="TRQS251">
  +      Added support for using SQL functions in "order by" 
  +    </action>
       <action type="update" dev="tfischer">
         Unify the behaviour of primary key columns. Until now, 
         primary key columns were not filled automatically for
  
  
  

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