db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Deepa Remesh <drem...@gmail.com>
Subject Question about DERBY-680
Date Fri, 18 Nov 2005 22:15:27 GMT
Can someone please take a look at DERBY-680 and provide me comments/suggestions?

Thanks,
Deepa

On 11/14/05, Deepa Remesh (JIRA) <derby-dev@db.apache.org> wrote:
>     [ http://issues.apache.org/jira/browse/DERBY-680?page=comments#action_12357621 ]
>
> Deepa Remesh commented on DERBY-680:
> ------------------------------------
>
> By changing the above code to check for the value returned by ps.getMetaData() , the
prepared statements q10 and q11 listed in the description above work. The test lang/cast.sql
also passes with JSR169.
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>                                                 // In J2ME there is no object that represents
>                                                 // a DECIMAL value. By default use String
to
>                                                 // pass values around, but for integral
types
>                                                 // first convert to a integral type from
the DECIMAL
>                                                 // because strings like 3.4 are not convertible
to
>                                                 // an integral type.
>                                                 ResultSetMetaData  psmd = ps.getMetaData();
>                                                 if(psmd != null) {
>                                                         switch (psmd.getColumnType(c))
>                                                         {
>                                                         case Types.BIGINT:
>                                                                 ps.setLong(c, rs.getLong(c));
>                                                             break;
>                                                         case Types.INTEGER:
>                                                         case Types.SMALLINT:
>                                                         case Types.TINYINT:
>                                                                 ps.setInt(c, rs.getInt(c));
>                                                                 break;
>                                                         default:
>                                                                 ps.setString(c,rs.getString(c));
>                                                             break;
>                                                         }
>                                                 }
>                                                 else {
>                                                         ps.setString(c,rs.getString(c));
>                                                 }
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> But the following case does not work because there is no way to get parameter metadata
in JSR169 since ParameterMetaData is not available. So, there is no equivalent to "switch
(ps.getMetaData().getColumnType(c))" to determine the the column/parameter type and call the
corresponding setXXX method.
>
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> ij> create table int_tab (i int);
> ij> prepare i1  as 'insert into int_tab values (?)';
> ij> execute i1 using 'values 3.4';
> IJ WARNING: Autocommit may close using result set
> ERROR 22018: Invalid character string format for type INTEGER.
> ERROR 22018: Invalid character string format for type INTEGER.
>         at org.apache.derby.iapi.error.StandardException.newException(StandardEx
> ception.java:311)
>         at org.apache.derby.iapi.types.DataType.invalidFormat(DataType.java:1049
> )
>         at org.apache.derby.iapi.types.SQLInteger.setValue(SQLInteger.java:340)
>         at org.apache.derby.impl.jdbc.EmbedPreparedStatement.setString(EmbedPrep
> aredStatement.java:452)
>         at org.apache.derby.impl.tools.ij.util.DisplayMulti(util.java:684)
>         at org.apache.derby.impl.tools.ij.utilMain.displayResult(utilMain.java:3
> 98)
>         at org.apache.derby.impl.tools.ij.utilMain.go(utilMain.java:290)
>         at org.apache.derby.impl.tools.ij.Main.go(Main.java:203)
>         at org.apache.derby.impl.tools.ij.Main.mainCore(Main.java:169)
>         at org.apache.derby.impl.tools.ij.Main.main(Main.java:75)
>         at org.apache.derby.tools.ij.main(ij.java:56)
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> I would like to know if anyone has suggestions to handle this. Thanks.
>
>
> > In ij, executing a prepared statement with numeric/decimal parameter fails with
NullPointerException in J2ME/CDC/FP
> > -------------------------------------------------------------------------------------------------------------------
> >
> >          Key: DERBY-680
> >          URL: http://issues.apache.org/jira/browse/DERBY-680
> >      Project: Derby
> >         Type: Bug
> >   Components: Tools
> >     Versions: 10.2.0.0
> >  Environment: j9_foundation VM in IBM WCTME 5.7
> >     Reporter: Deepa Remesh
> >     Assignee: Deepa Remesh
>
> >
> > NPE is thrown in ij when executing prepared statement which
> > - has numeric/decimal parameters
> > - does not return any result set
> > Repro for this problem is the test lang/cast.sql. This test currently fails in CDC/FP.
> > The following lines in the test throw NPE:
> > execute q10 using 'values 123456.78';
> > execute q11 using 'values 123456.78';
> > where q10 is "prepare q10 as 'insert into t1 (num) values cast(? as numeric(18))';"
> > and q11 is "prepare q11 as 'insert into t1 (dc) values cast(? as decimal(18))';"
> > The stack trace for failure is:
> > java.lang.NullPointerException
> >         at org.apache.derby.impl.tools.ij.util.DisplayMulti(util.java:666)
> >         at org.apache.derby.impl.tools.ij.utilMain.displayResult(utilMain.java:398)
> >         at org.apache.derby.impl.tools.ij.utilMain.go(utilMain.java:290)
> >         at org.apache.derby.impl.tools.ij.Main.go(Main.java:203)
> >         at org.apache.derby.impl.tools.ij.Main.mainCore(Main.java:169)
> >         at org.apache.derby.impl.tools.ij.Main.main(Main.java:75)
> >         at org.apache.derby.tools.ij.main(ij.java:56)
> > This happens in the following code. Since the above prepared statements do not return
result sets, call to getMetaData() will return null. But in the code, no check is done to
see if getMetaData() returns null before calling getColumnType.
> > -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> >                                               // In J2ME there is no object that
represents
> >                                               // a DECIMAL value. By default use
String to
> >                                               // pass values around, but for integral
types
> >                                               // first convert to a integral type
from the DECIMAL
> >                                               // because strings like 3.4 are not
convertible to
> >                                               // an integral type.
> >                                               switch (ps.getMetaData().getColumnType(c))
> >                                               {
> >                                               case Types.BIGINT:
> >                                                       ps.setLong(c, rs.getLong(c));
> >                                                   break;
> >                                               case Types.INTEGER:
> >                                               case Types.SMALLINT:
> >                                               case Types.TINYINT:
> >                                                       ps.setInt(c, rs.getInt(c));
> >                                                       break;
> >                                               default:
> >                                                       ps.setString(c,rs.getString(c));
> >                                                   break;
> >                                               }
> > -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> --
> This message is automatically generated by JIRA.
> -
> If you think it was sent incorrectly contact one of the administrators:
>    http://issues.apache.org/jira/secure/Administrators.jspa
> -
> For more information on JIRA, see:
>    http://www.atlassian.com/software/jira
>
>

Mime
View raw message