Greg Monroe wrote:
All record objects and table Peer objects will have a getTableMap() function. You can use this to access all the schema information. E.g.:rec.getTableMap().getColumn(fieldName).getType();
Think you, this work, but there is one small catch.
In the database I have a field called
name varchar(255) not nul,
And to get the class I use
BaseObject p;
Class myClass=p.getTableMap().getColumn("name").getType().getClass();
And this works fine. I get the class back. But if I want to use
p.getByName() to get the value of the field
I have to call with
p.getByName("Name");
That is: Give name with big N.
I don't know if this is a bug(I use torque 3.3 RC3) or a feature, but
it's rather confusing that the name of the column depend on where I call
from.
Martin Tilsted
Will return a "sample object" of the same type as the field. Note that the XML can defined the objects beingreturned via the getFieldName() methods as primitives. Since you can't return a primitive, the getType() returns the Object version of the primitive. You mayneed to check the usePrimitive property to verify the actual type.-----Original Message-----From: Martin Tilsted [mailto:[EMAIL PROTECTED] Sent: Thursday, January 17, 2008 5:27 PMTo: [email protected] Subject: Get type of fields in auto generated classseIs there a way to make a method, that given a field name, and any auto generated object, can return the type of that field?Something like boolean isFieldAnInteger(BaseObject obj,String fieldName) {// What here. (And is BaseObject the correct class to use, if you want to accept something that can be any torque auto generated class?) }At first I thought I could doClass c=obj. getByName(field).getClass(); But that don't work if obj is a newly created object, becasue getByName will return null.Martin --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]DukeCE Privacy Statement: Please be advised that this e-mail and any files transmitted with it are confidential communication or may otherwise be privileged or confidential and are intended solely for the individual or entity to whom they are addressed. If you are not the intended recipient you may not rely on the contents of this email or any attachments, and we ask that you please not read, copy or retransmit this communication, but reply to the sender and destroy the email, its contents, and all copies thereof immediately. Any unauthorized dissemination, distribution or copying of this communication is strictly prohibited. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
