Hallo Marco,

I don't know how to use OQL count and therefor use CALL SQL instead.

call sql select count(ID) as COUNT from TABLE as SizeJDO

Your table 'TABLE' needs a column 'ID' to use this query and you need an object 
'SizeJDO' with a dummy mapping.

public class SizeJDO {
    private int _size;
    public int getSize() { return _size; }
    public void setSize(int size) { _size = size; }
}

<mapping>
    <class name="SizeJDO" identity="size">
        <map-to table="DUAL"/>
        <field name="size" type="integer">
            <sql name="COUNT" type="numeric"/>
        </field>
    </class>
</mapping>

Note that DUAL is a dummy object defined by oracle in their database.

If you need a generic solution for building the CALL SQL query you can resolve table 
and column names out of the mapping.

Maybe you can get your OQL count to work by appending 'as SizeJDO' too.

Regards
Ralf


----- Original Message ----- 
From: "Marco Herrn" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, February 20, 2004 10:22 AM
Subject: Re: [castor-dev] examples for OQL-Queries (aggregate functions)


> 
> Marco Herrn wrote:
> 
> > Currently I am trying to use the aggregate function count(), but don't 
> > know how to form the query. A normal select would be
> > "SELECT count(kontakt FROM de.devlogix.kontakt.data.Kontakt) kontakt".
> 
> I seems that I found the right form:
> "SELECT count(*) FROM de.devlogix.kontakt.data.Kontakt kontakt".
> Why do I have to use "*" instead of "kontakt"? In the first select I 
> also want _all_ columns. And I get them. As you can see I am not yet 
> very familiar with OQL....
> 
> But anyway, the above Query doesn't work. It returns 1, which isn't 
> correct, since there are much more entries in the DB.
> 
> What is the problem here? Is the syntax still wrong?
> 
> Marco
> 
> ----------------------------------------------------------- 
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>         unsubscribe castor-dev
> 

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

Reply via email to