I think this should currently work:

crit.addSelectColumn("table.bar AS bla");

is there any reason why you do not want to use this?

WBR,

Fedor


On Tuesday 08 May 2001 02:42, you wrote:
> Hi,
>
> for a project I need the ability to do SQL selects like this:
>
> SELECT table.foo, table.bar AS bla FROM table
>
> as this seems not to be possible with the current Criteria, this is a
> patch which adds a method
>
> Criterion::addAsColumn(String key, String definition)
>
> so it is possible to do
>
> Criterion myCrit = new Criterion();
>
> myCrit.addSelectColumn(MyPeer.FOO);
> myCrit.addAsColumn("bla", MyPeer.BAR);
>
>
>       Regards
>               Henning
>
> diff --exclude=CVS --exclude=*class -Nurb
> jakarta-turbine-20010505.preimport/bin/src/org/apache/turbine/om/peer/BaseP
>eer.java
> jakarta-turbine-20010505/bin/src/org/apache/turbine/om/peer/BasePeer.java
> ---
> jakarta-turbine-20010505.preimport/bin/src/org/apache/turbine/om/peer/BaseP
>eer.java       Sat May  5 11:55:34 2001 +++
> jakarta-turbine-20010505/bin/src/org/apache/turbine/om/peer/BasePeer.java     T
>ue May  8 01:20:47 2001 @@ -861,6 +861,7 @@
>          StringStackBuffer orderBy = criteria.getOrderByColumns();
>          boolean ignoreCase = criteria.isIgnoreCase();
>          StringStackBuffer select = criteria.getSelectColumns();
> +        Hashtable aliases = criteria.getAsColumns();
>          StringStackBuffer modifiers = criteria.getSelectModifiers();
>
>          for (int i=0; i<modifiers.size(); i++)
> @@ -872,6 +873,7 @@
>          {
>              String columnName = select.get(i);
>              String tableName = null;
> +
>              selectClause.add(columnName);
>              int parenPos = columnName.indexOf('(');
>              if (parenPos == -1)
> @@ -899,6 +901,14 @@
>              }
>          }
>
> +     Iterator it = aliases.keySet().iterator();
> +
> +     while(it.hasNext())
> +     {
> +       String key = (String)it.next();
> +       selectClause.add((String)aliases.get(key) + " AS " + key);
> +     }
> +
>          Enumeration e = criteria.keys();
>          while (e.hasMoreElements())
>          {
> @@ -1936,6 +1946,7 @@
>          StringStackBuffer orderBy = criteria.getOrderByColumns();
>          boolean ignoreCase = criteria.isIgnoreCase();
>          StringStackBuffer select = criteria.getSelectColumns();
> +        Hashtable aliases = criteria.getAsColumns();
>          StringStackBuffer modifiers = criteria.getSelectModifiers();
>
>          for (int i=0; i<modifiers.size(); i++)
> @@ -1979,6 +1990,13 @@
>              }
>          }
>
> +     Iterator it = aliases.keySet().iterator();
> +
> +     while(it.hasNext())
> +     {
> +       String key = (String)it.next();
> +       selectClause.add((String)aliases.get(key) + " AS " + key);
> +     }
>
>          Enumeration e = criteria.keys();
>          while (e.hasMoreElements())
> diff --exclude=CVS --exclude=*class -Nurb
> jakarta-turbine-20010505.preimport/bin/src/org/apache/turbine/util/db/Crite
>ria.java
> jakarta-turbine-20010505/bin/src/org/apache/turbine/util/db/Criteria.java
> ---
> jakarta-turbine-20010505.preimport/bin/src/org/apache/turbine/util/db/Crite
>ria.java       Sat May  5 13:55:55 2001 +++
> jakarta-turbine-20010505/bin/src/org/apache/turbine/util/db/Criteria.java     T
>ue May  8 01:14:38 2001 @@ -190,6 +190,7 @@
>      private StringStackBuffer selectModifiers = new StringStackBuffer();
>      private StringStackBuffer selectColumns = new StringStackBuffer();
>      private StringStackBuffer orderByColumns = new StringStackBuffer();
> +    private Hashtable asColumns = new Hashtable(8);
>      private ArrayList joinL = null;
>      private ArrayList joinR = null;
>
> @@ -1103,6 +1104,43 @@
>      }
>
>      /**
> +   * Add an AS clause to the select columns. Usage:
> +   * <p>
> +   * <code>
> +   *
> +   * Criteria myCrit = new Criteria();
> +   * myCrit.addAsColumn("alias", "ALIAS("+MyPeer.ID+")");
> +   *
> +   * </code>
> +   *
> +   * @param name  wanted Name of the column
> +   * @param clause SQL clause to select from the table
> +   *
> +   * If the name already exists, it is replaced by the new clause.
> +   *
> +   * @return A modified Criteria object.
> +   */
> +
> +  public Criteria addAsColumn(String name,
> +                           String clause)
> +  {
> +    asColumns.put(name, clause);
> +    return this;
> +  }
> +
> +  /**
> +   * Get the column aliases.
> +   *
> +   * @return A Hashtable which map the column alias names
> +   * to the alias clauses.
> +   */
> +
> +  public Hashtable getAsColumns()
> +  {
> +    return asColumns;
> +  }
> +
> +    /**
>       * Get select modifiers.
>       *
>       * @return A StringStackBuffer with the select modifiers.
> @@ -1225,6 +1263,7 @@
>                   && selectModifiers.equals(criteria.getSelectModifiers())
>                   && selectColumns.equals(criteria.getSelectColumns())
>                   && orderByColumns.equals(criteria.getOrderByColumns())
> +              && asColumns.equals(criteria.getAsColumns())
>                 )
>              {
>                  isEquiv = true;

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to