You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by John McNally <jm...@collab.net> on 2001/12/26 23:24:21 UTC
Re: BUG ! Insert or Update of Byte values is not possible.
I added code to BasePeer (Torque repo) to handle Byte.
john mcnally
Patrick Tonidandel wrote:
>
> Dear gentlemen,
>
> I have a Table in my DB that contains columns of type TINYINT. The generated
> schema.xml - file
> look like this :
>
> <table name="DocHead">
> <column name="Doc_NUserID" primaryKey="true" required="true"
> type="INTEGER"/>
> <column name="Doc_NDocID" primaryKey="true" required="true"
> type="INTEGER"/>
> <column name="Doc_NCustID" type="INTEGER"/>
> <column name="Doc_NSellID" type="SMALLINT"/>
> <column name="Doc_NArea" type="INTEGER"/>
> <column name="Doc_NDocType" type="TINYINT"/>
> <column name="Doc_DDocDate" type="TIMESTAMP"/>
> <column name="Doc_DDocCreateDate" type="TIMESTAMP"/>
> <column name="Doc_NPayType" type="INTEGER"/>
> <column name="Doc_NPayStart" type="SMALLINT"/>
> <column name="Doc_NDays1" type="TINYINT"/>
> <column name="Doc_NDays2" type="TINYINT"/>
> <column name="Doc_NDays3" type="TINYINT"/>
> <column name="Doc_NInvoice" type="SMALLINT"/>
> <column name="Doc_NSendType" type="TINYINT"/>
> <column name="Doc_NTransCharges" type="NUMERIC"/>
> <column name="Doc_NRest" type="TINYINT"/>
> <column name="Doc_NDestID" type="TINYINT"/>
> </table>
>
> Torque generates the Peer-classes for this Table and uses Byte-values to
> modifiy the data in such columns.
>
> After calling the doUpdate or doInsert -methods i noticed that nothing
> happens
> to my columns data.
>
> The doUpdate-method leaves the data unchanged.
> The doInsert-method inserts nothing and so i find NULL there.
>
> I suppose that the reason is, in following source code.
>
> -------------------------------------------------------------------------->
> CODE
> private static void insertOrUpdateRecord(Record rec,
> String tableName,
> Criteria criteria)
> throws Exception
> {
> DatabaseMap dbMap = Torque.getDatabaseMap( criteria.getDbName() );
>
> ColumnMap[] columnMaps = dbMap.getTable( tableName ).getColumns();
> boolean shouldSave = false;
> for (int j=0; j<columnMaps.length; j++)
> {
> ColumnMap colMap = columnMaps[j];
> String key = new StringBuffer(colMap.getTableName())
> .append('.').append(colMap.getColumnName()).toString();
> if ( criteria.containsKey(key) )
> {
> // A village Record.setValue( String, Object ) would
> // be nice here.
> Object obj = criteria.getValue(key);
> if ( obj instanceof SimpleKey )
> {
> obj = ((SimpleKey)obj).getValue();
> }
> if (obj == null)
> {
> rec.setValueNull(colMap.getColumnName());
> }
> else if ( obj instanceof String )
> {
> rec.setValue( colMap.getColumnName(),
> (String)obj );
> }
> else if ( obj instanceof Integer)
> {
> rec.setValue( colMap.getColumnName(),
> criteria.getInt(key) );
> }
> else if ( obj instanceof BigDecimal)
> {
> rec.setValue( colMap.getColumnName(),
> (BigDecimal)obj );
> }
> else if ( obj instanceof Long)
> {
> rec.setValue( colMap.getColumnName(),
> criteria.getLong(key) );
> }
> else if ( obj instanceof java.util.Date)
> {
> rec.setValue( colMap.getColumnName(),
> (java.util.Date)obj );
> }
> else if ( obj instanceof Float)
> {
> rec.setValue( colMap.getColumnName(),
> criteria.getFloat(key) );
> }
> else if ( obj instanceof Double)
> {
> rec.setValue( colMap.getColumnName(),
> criteria.getDouble(key) );
> }
> else if ( obj instanceof Hashtable )
> {
> rec.setValue( colMap.getColumnName(),
> hashtableToByteArray( (Hashtable)obj ) );
> }
> else if ( obj instanceof byte[])
> {
> rec.setValue( colMap.getColumnName(),
> (byte[])obj);
> }
> else if ( obj instanceof Boolean)
> {
> rec.setValue( colMap.getColumnName(),
> criteria.getBoolean(key) ? 1 : 0);
> }
> shouldSave = true;
> }
> }
>
> if ( shouldSave )
> {
> rec.save();
> }
> else
> {
> throw new Exception ( "BasePeer.doInsert() - Nothing to
> insert" );
> }
> }
> --------------------------------------------------------------------------<
> CODE
>
> The method insertOrUpdateRecord of BasePeer.java misses if-clause for
> Byte-types.
>
> Regards
> Patrick Tonidandel
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>