You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Ricardo Lecheta <ri...@brturbo.com> on 2003/04/11 06:57:26 UTC

SELECT TABLE.FIELD FROM TABLE. How do I do this?

This is my table:

CREATE TABLE PESSOA
(
id INTEGER NOT NULL,
nome VARCHAR (50) NOT NULL,
fone VARCHAR (50) NOT NULL,
PRIMARY KEY(id)
);

I would like to do a sql statement like the following one:

SELECT TABLE.FIELD FROM TABLE // only a field of the table

but I can´t.

I tried to do it like this:

Criteria c = new Criteria();
c.addSelectColumn(PessoaPeer.NOME);
PessoaPeer.doSelect(c);

SQL Statement generated by Torque: Current Query SQL (may not be complete or applicable): SELECT PESSOA.NOME FROM PESSOA

the sql statement is correct, but the following mistake occurs:
com.workingdogs.village.DataSetException: Bad conversion: java.lang.NumberFormatException: For input string: "Ricardo"

I have noticed that this is happening because Torque doesn´t understand I want to select only one field of the table.

So, on method populateObject(...) of BasePessoaPeer Class, Torque tries to recuperate fields that didn´t appear on my research.

try{

obj.setId(row.getValue(offset + 0).asInt());   // INVALID TYPECAST, this field doesn´t exist in my query.
obj.setNome(row.getValue(offset + 1).asString());
obj.setFone(row.getValue(offset + 2).asString());
}

catch (DataSetException e){

throw new TorqueException(e); // THIS EXCPETION IS RAISED

}

Could you please tell me the right way to do it ?

Thank you

Ricardo.



AW: SELECT TABLE.FIELD FROM TABLE. How do I do this?

Posted by Jürgen Hoffmann <jh...@byteaction.de>.
Hi,

this will not work. Because the column Count of the returned Record ist 1
and your Pessoa Objects have more than one field they are filled with. How
should the fields be populated? There is no chance for village/Torque to
find that out.

If you really want Pessoa Objects returned by the query use the normal way,
or produce as many columns as the object has and then you can use a List of
Record Objects to populate the corresponding Objects generated by Torque.
You can use the method

PessoaPeer.populateObjects(recordList);

kind regards

Jürgen Hoffmann

-----Ursprüngliche Nachricht-----
Von: Ricardo Lecheta [mailto:ricardolecheta@brturbo.com]
Gesendet: Samstag, 12. April 2003 07:00
An: Turbine Torque Users List
Betreff: Re: SELECT TABLE.FIELD FROM TABLE. How do I do this?


Thank you Gareth, the code worked, but it shows a list of Record objects. I
would like that the list was of Pessoa objects.
----- Original Message -----
From: "Gareth Boden" <ga...@egsgroup.com>
To: "Turbine Torque Users List" <to...@db.apache.org>
Sent: Friday, April 11, 2003 1:16 AM
Subject: Re: SELECT TABLE.FIELD FROM TABLE. How do I do this?

Is there a way to do it?

Ricardo



> SELECT TABLE.FIELD FROM TABLE // only a field of the table
> I tried to do it like this:
>
> Criteria c = new Criteria();
> c.addSelectColumn(PessoaPeer.NOME);
> PessoaPeer.doSelect(c);

> Could you please tell me the right way to do it ?

Use something like:
List l = PessoaPeer.doSelectVillageRecords(c);
for (Iterator it = l.iterator(); it.hasNext(); ) {
Record r = (Record) it.next();
Object valueInColumn1 = r.getValue(1).asObject();
}

Gareth

---
Development Team Leader, eGS, 5-7 Singer Street, London EC2A 4BQ. +44
(0)20 7336 1440

CONFIDENTIALITY: This is email is confidential and intended solely for
the use of the individual to whom it is addressed. Any views or
opinions presented are solely those of the author and do not
necessarily represent those of eGovernment Solutions (UK) Ltd. If you
are not the intended recipient, be advised that you have received this
email in error and that any use, dissemination, forwarding, or copying
of this email is strictly prohibited. If you have received this email
in error please contact the sender.


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





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




Re: SELECT TABLE.FIELD FROM TABLE. How do I do this?

Posted by Ricardo Lecheta <ri...@brturbo.com>.
Thank you Gareth, the code worked, but it shows a list of Record objects. I
would like that the list was of Pessoa objects.
----- Original Message -----
From: "Gareth Boden" <ga...@egsgroup.com>
To: "Turbine Torque Users List" <to...@db.apache.org>
Sent: Friday, April 11, 2003 1:16 AM
Subject: Re: SELECT TABLE.FIELD FROM TABLE. How do I do this?

Is there a way to do it?

Ricardo



> SELECT TABLE.FIELD FROM TABLE // only a field of the table
> I tried to do it like this:
>
> Criteria c = new Criteria();
> c.addSelectColumn(PessoaPeer.NOME);
> PessoaPeer.doSelect(c);

> Could you please tell me the right way to do it ?

Use something like:
List l = PessoaPeer.doSelectVillageRecords(c);
for (Iterator it = l.iterator(); it.hasNext(); ) {
Record r = (Record) it.next();
Object valueInColumn1 = r.getValue(1).asObject();
}

Gareth

---
Development Team Leader, eGS, 5-7 Singer Street, London EC2A 4BQ. +44
(0)20 7336 1440

CONFIDENTIALITY: This is email is confidential and intended solely for
the use of the individual to whom it is addressed. Any views or
opinions presented are solely those of the author and do not
necessarily represent those of eGovernment Solutions (UK) Ltd. If you
are not the intended recipient, be advised that you have received this
email in error and that any use, dissemination, forwarding, or copying
of this email is strictly prohibited. If you have received this email
in error please contact the sender.


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





Re: SELECT TABLE.FIELD FROM TABLE. How do I do this?

Posted by Gareth Boden <ga...@egsgroup.com>.
> SELECT TABLE.FIELD FROM TABLE // only a field of the table
> I tried to do it like this:
>
> Criteria c = new Criteria();
> c.addSelectColumn(PessoaPeer.NOME);
> PessoaPeer.doSelect(c);

> Could you please tell me the right way to do it ?

Use something like:
	List l = PessoaPeer.doSelectVillageRecords(c);
	for (Iterator it = l.iterator(); it.hasNext(); ) {
		Record r = (Record) it.next();
		Object valueInColumn1 = r.getValue(1).asObject();
	}

Gareth

---
Development Team Leader, eGS, 5-7 Singer Street, London EC2A 4BQ. +44 
(0)20 7336 1440

CONFIDENTIALITY: This is email is confidential and intended solely for 
the use of the individual to whom it is addressed.  Any views or 
opinions presented are solely those of the author and do not 
necessarily represent those of eGovernment Solutions (UK) Ltd.  If you 
are not the intended recipient, be advised that you have received this 
email in error and that any use, dissemination, forwarding, or copying 
of this email is strictly prohibited.  If you have received this email 
in error please contact the sender.