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 Jon August <jo...@internection.com> on 2006/12/13 23:38:07 UTC

BigDecimal and MySQL decimal

Hey,

I'm using decimal (in the schema) to store a dollar amount in my  
MySQL database.  I get the value from a web page and convert it to a  
BigDecimal before storing it.  For some reason, the decimal portion  
gets truncated and $10.32 gets stored as 10.  Should I be using  
something other than BigDecimal or is there something else wrong?

Sorry if this is not a torque question.

-Jon

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


Re: retrieve columns returned by doSelect(Criteria) query

Posted by David Zhao <wz...@gmail.com>.
Thanks Shane, actually, I found criteria.getSelectColumns() is what I needed.

David

On 12/14/06, Shane Beasley <sb...@acm.org> wrote:
> David Zhao wrote:
>
> >  If I did this:
> >
> >  Criteria crit = new Criteria(); crit.addJoin(Table1Peer.ID1,
> >  Table2Peer.ID2, Criteria.INNER_JOIN );
> >  crit.addSelectColumn(Table1Peer.ID1);
> >  crit.addSelectColumn(Table2Peer.NAME);
> >  crit.addSelectColumn(Table2Peer.NOTES); List list = null; try { list
> >  = BasePeer.doSelect(crit); } catch (Exception e) { Log.error("Error
> >  runnnnning query: " + e.getMessage()); }
> >
> >  How can I retrieve the list of columns returned by the query?
>
> //
> http://www.softwareforge.de/projects/village/apidocs/com/workingdogs/village/Record.html
> //
> http://www.softwareforge.de/projects/village/apidocs/com/workingdogs/village/Value.html
>
> import com.workingdogs.village.Record;
> import com.workingdogs.village.Value;
>
> final List<Record> records = BasePeer.doSelect(crit);
>
> for (final Record record : records) {
>   final Value v_id1 = record.get(1);
>   final int id1 = v_id1.asInt();
>   final Value v_name = record.get(2);
>   final String name = v_name.asString();
>   // ...
> }
>
> Shane
>
> ---------------------------------------------------------------------
> 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: retrieve columns returned by doSelect(Criteria) query

Posted by Shane Beasley <sb...@acm.org>.
David Zhao wrote:

>  If I did this:
>
>  Criteria crit = new Criteria(); crit.addJoin(Table1Peer.ID1,
>  Table2Peer.ID2, Criteria.INNER_JOIN );
>  crit.addSelectColumn(Table1Peer.ID1);
>  crit.addSelectColumn(Table2Peer.NAME);
>  crit.addSelectColumn(Table2Peer.NOTES); List list = null; try { list
>  = BasePeer.doSelect(crit); } catch (Exception e) { Log.error("Error
>  runnnnning query: " + e.getMessage()); }
>
>  How can I retrieve the list of columns returned by the query?

// 
http://www.softwareforge.de/projects/village/apidocs/com/workingdogs/village/Record.html
// 
http://www.softwareforge.de/projects/village/apidocs/com/workingdogs/village/Value.html

import com.workingdogs.village.Record;
import com.workingdogs.village.Value;

final List<Record> records = BasePeer.doSelect(crit);

for (final Record record : records) {
  final Value v_id1 = record.get(1);
  final int id1 = v_id1.asInt();
  final Value v_name = record.get(2);
  final String name = v_name.asString();
  // ...
}

Shane

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


retrieve columns returned by doSelect(Criteria) query

Posted by David Zhao <wz...@gmail.com>.
Hi there,

If I did this:

		Criteria crit = new Criteria();
		crit.addJoin(Table1Peer.ID1,
Table2Peer.ID2,
			     Criteria.INNER_JOIN
			     );
		crit.addSelectColumn(Table1Peer.ID1);
		crit.addSelectColumn(Table2Peer.NAME);
		crit.addSelectColumn(Table2Peer.NOTES);
		List list = null;
		try {
			list = BasePeer.doSelect(crit);
		} catch (Exception e) {
			Log.error("Error runnnnning query: " +
e.getMessage());
		}

How can I retrieve the list of columns returned by the query?
Thanks very much in advance!

David

-- 
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.15.18/586 - Release Date: 12/13/2006
6:13 PM
 


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


Re: BigDecimal and MySQL decimal

Posted by Jon August <jo...@internection.com>.
Hey Alvaro,

Thanks for the suggestion.  I tried this:

     <column name="price"                scale="2" size="7"  
type="DECIMAL" />

but I get this error when I run "maven torque":

org.apache.torque.engine.EngineException: org.xml.sax.SAXException:  
Error while parsing wp-schema.xml at line 13 column 77 : Attribute  
"scale" must be declared for element type "column".


Is my syntax incorrect?

-Jon





On Dec 14, 2006, at 7:24 AM, Alvaro Coronel wrote:

> I have had no trouble using it just as you do. Maybe you haven't  
> set the scale yet.
>
> This is an excerpt of my schema.xml file:
>
> <column name="moncotiza"
>              required="true"
>              scale="2"
>              size="7"
>              type="DECIMAL" />
>
> What I usually do is to define the schema.xml file and from it  
> obtain the .sql file via ant to create the database.
>
> Good luck,
> Álvaro.
>
> Jon August <jo...@internection.com> wrote: Hey,
>
> I'm using decimal (in the schema) to store a dollar amount in my
> MySQL database.  I get the value from a web page and convert it to a
> BigDecimal before storing it.  For some reason, the decimal portion
> gets truncated and $10.32 gets stored as 10.  Should I be using
> something other than BigDecimal or is there something else wrong?
>
> Sorry if this is not a torque question.
>
> -Jon
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
>
>
>
> ---------------------------------
> Want to start your own business? Learn how on Yahoo! Small Business.


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


Re: BigDecimal and MySQL decimal

Posted by Alvaro Coronel <al...@yahoo.com>.
I have had no trouble using it just as you do. Maybe you haven't set the scale yet.

This is an excerpt of my schema.xml file:

<column name="moncotiza" 
             required="true" 
             scale="2" 
             size="7" 
             type="DECIMAL" />

What I usually do is to define the schema.xml file and from it obtain the .sql file via ant to create the database.

Good luck,
Álvaro.

Jon August <jo...@internection.com> wrote: Hey,

I'm using decimal (in the schema) to store a dollar amount in my  
MySQL database.  I get the value from a web page and convert it to a  
BigDecimal before storing it.  For some reason, the decimal portion  
gets truncated and $10.32 gets stored as 10.  Should I be using  
something other than BigDecimal or is there something else wrong?

Sorry if this is not a torque question.

-Jon

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



 
---------------------------------
Want to start your own business? Learn how on Yahoo! Small Business.