db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joe Carter" <joe.car...@excite.com>
Subject RE: Prepared statements
Date Thu, 25 May 2006 11:41:12 GMT
Hi,

I think I've fixed my problems using PreparedStatements.
I've had to add a few cases to the parameter types that seem
to have been missed. I'm unsure if this is the appropriate place
as it seems NumberKey should handle some of this, but I'm
not all that familiar with the Torque code.
I had to manually modify the Torque generated code to alter
the "BasePeer.doSelect" to "BasePeer.doPSSelect".
I need to fix the generator template for this properly.

I changed two classes in the torque runtime:

In Criteria.appendPsTo()

                    if (value instanceof java.util.Date)
                    {
                        params.add(new java.sql.Date(
                                           ((java.util.Date)
value).getTime()));
                    }
                    else if (value instanceof DateKey)
                    {
                        params.add(new java.sql.Date(
                                           ((DateKey)
value).getDate().getTime()));
                    }
                    else if (value instanceof NumberKey)
                    {
                        params.add(value);
                    }
// new code here
                    else if (value instanceof BigDecimal)
                    {
                        params.add(value);
                    }
                    else if (value instanceof Number)
                    {
                        params.add(value);
                    }
// end of new code
                    else
                    {
                        params.add(value.toString());
                    }

In BasePeer.doPSSelect()
                if (param instanceof java.sql.Date)
                {
                    statement.setDate(i + 1, (java.sql.Date) param);
                }
                else if (param instanceof NumberKey)
                {
                    statement.setBigDecimal(i + 1,
                        ((NumberKey) param).getBigDecimal());
                }
// new code
                else if (param instanceof BigDecimal)
                {
                    statement.setBigDecimal(i + 1, (BigDecimal)param);
                }
                else if (param instanceof Long)
                {
                    statement.setLong(i + 1, ((Long)param).longValue());
                }
                else if (param instanceof Integer)
                {
                    statement.setInt(i + 1, ((Integer)param).intValue());
                }
// end of new code
                else
                {
                    statement.setString(i + 1, param.toString());
                }

It'd be appreciated if someone would let me know whether I'm doing
something inappropriate here. The above changes pass my JUnit tests but
I'm only doing relatively simple SQL calls.

Cheers

Joe

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message