6 Replies Latest reply on Jul 6, 2006 12:12 AM by dailo10

    Oracle10g dialect

    jc7442

      Last implemented dialect for Oracle is Oracle9Dialect. Is there a dialect for Oracle10g ?

      It seems that with Oracle java.land.Double.NaN or java.lang.Float.NaN is not supported. Is there some known workaround ?

        • 1. Re: Oracle10g dialect
          jc7442

          An answer to my own question:
          It seems that an oracle10gDialect may be usefull (see http://builder.com.com/5100-6388-5224536.html)

          It may look like:

          public class Oracle10gDialect extends Oracle9Dialect {
           public Oracle10gDialect() {
           super();
           // override properties
           registerColumnType( Types.FLOAT, "binary_float" );
           registerColumnType( Types.DOUBLE, "binary_double" );
           }
          }


          It does not fix the problem for the NaN. For Double.NaN, it looks like a bug in the oracle JDBC driver, a small patch in the DoubleBinder class fixes the problem.

          • 2. Re: Oracle10g dialect
            atodorov

            Just curious... why do you need to persist the NaN values?

            • 3. Re: Oracle10g dialect
              jc7442

              I use a library that may send in its results list a NaN. I do not want to filter all double to detect NaN value and replace it by something (I do not know what).

              Moreover since oracle 10g release 2 NaN is a valide value for Oracle database.

              Why not using it ?

              • 4. Re: Oracle10g dialect
                dailo10

                 

                "jc7442" wrote:
                An answer to my own question:
                It seems that an oracle10gDialect may be usefull (see http://builder.com.com/5100-6388-5224536.html)

                It may look like:
                public class Oracle10gDialect extends Oracle9Dialect {
                 public Oracle10gDialect() {
                 super();
                 // override properties
                 registerColumnType( Types.FLOAT, "binary_float" );
                 registerColumnType( Types.DOUBLE, "binary_double" );
                 }
                }


                It does not fix the problem for the NaN. For Double.NaN, it looks like a bug in the oracle JDBC driver, a small patch in the DoubleBinder class fixes the problem.



                Hi there.

                I am dealing with a similar situation. Do you know where I might find this patch for the DoubleBinder class?

                Thanks!



                • 5. Re: Oracle10g dialect
                  jc7442

                  From what I remember hook is at line 42. We reported bugs to Oracle bug, ...

                  package oracle.jdbc.driver;
                  
                  import java.sql.SQLException;
                  
                  import oracle.core.lmx.CoreException;
                  
                  // Referenced classes of package oracle.jdbc.driver:
                  // VarnumBinder, OraclePreparedStatement
                  
                  class DoubleBinder extends VarnumBinder
                  {
                  
                   DoubleBinder()
                   {
                   digits = new char[20];
                   }
                  
                   void bind(OraclePreparedStatement stmt, int bindPosition, int rankInBuffer, int rank, byte bindBytes[], char bindChars[], short bindIndicators[],
                   int bytePitch, int charPitch, int byteoffset, int charoffset, int lenoffset, int indoffset, boolean clearPriorBindValues)
                   throws SQLException
                   {
                  
                   byte b[] = bindBytes;
                   int offset = byteoffset + 1;
                   double val = stmt.parameterDouble[rank][bindPosition];
                   int len = 0;
                   if(val == 0.0D)
                   {
                   b[offset] = -128;
                   len = 1;
                   } else
                   if(val == (1.0D / 0.0D))
                   {
                   b[offset] = -1;
                   b[offset + 1] = 101;
                   len = 2;
                   } else
                   if(val == (-1.0D / 0.0D))
                   {
                   b[offset] = 0;
                   len = 1;
                   } else if (Double.isNaN(val)) {
                   b[offset] = -1;
                   b[offset+1] = (byte)0xf8;
                   len = 2;
                   } else
                   {
                   boolean neg = val < 0.0D;
                   if(neg)
                   val = -val;
                   long bits = Double.doubleToLongBits(val);
                   int rawExponent = (int)(bits >> 52 & 2047L);
                   int guess = (rawExponent <= 1023 ? 127 : 126) - (int)((double)(rawExponent - 1023) / 6.6438561897747253D);
                   if(guess < 0)
                   {
                   SQLException ex = new SQLException(CoreException.getMessage((byte)3) + " trying to bind " + val);
                   throw ex;
                   }
                   if(guess > 192)
                   {
                   SQLException ex = new SQLException(CoreException.getMessage((byte)2) + " trying to bind " + val);
                   throw ex;
                   }
                   if(val > factorTable[guess])
                   while(guess > 0 && val > factorTable[--guess]) ;
                   else
                   for(; guess < 193 && val <= factorTable[guess + 1]; guess++);
                   if(val == factorTable[guess])
                   {
                   if(guess < 65)
                   {
                   SQLException ex = new SQLException(CoreException.getMessage((byte)3) + " trying to bind " + val);
                   throw ex;
                   }
                   if(guess > 192)
                   {
                   SQLException ex = new SQLException(CoreException.getMessage((byte)2) + " trying to bind " + val);
                   throw ex;
                   }
                   if(neg)
                   {
                   b[offset] = (byte)(62 - (127 - guess));
                   b[offset + 1] = 100;
                   b[offset + 2] = 102;
                   len = 3;
                   } else
                   {
                   b[offset] = (byte)(192 + (128 - guess));
                   b[offset + 1] = 2;
                   len = 2;
                   }
                   } else
                   {
                   if(guess < 64)
                   {
                   SQLException ex = new SQLException(CoreException.getMessage((byte)3) + " trying to bind " + val);
                   throw ex;
                   }
                   if(guess > 191)
                   {
                   SQLException ex = new SQLException(CoreException.getMessage((byte)2) + " trying to bind " + val);
                   throw ex;
                   }
                   long dBits = neg ? bits & 0x7fffffffffffffffL : bits;
                   long fractBits = dBits & 0xfffffffffffffL;
                   int binExp = rawExponent;
                   char digits[] = stmt.digits;
                   int nSignificantBits;
                   if(binExp == 0)
                   {
                   while((fractBits & 0x10000000000000L) == 0L)
                   {
                   fractBits <<= 1;
                   binExp--;
                   }
                   nSignificantBits = 53 + binExp;
                   binExp++;
                   } else
                   {
                   fractBits |= 0x10000000000000L;
                   nSignificantBits = 53;
                   }
                   binExp -= 1023;
                   len = dtoa(b, offset, val, neg, false, digits, binExp, fractBits, nSignificantBits);
                   }
                   }
                   b[byteoffset] = (byte)len;
                   bindIndicators[indoffset] = 0;
                   bindIndicators[lenoffset] = (short)(len + 1);
                   }
                  
                   char digits[];
                  }
                  


                  • 6. Re: Oracle10g dialect
                    dailo10


                    Merci beaucoup!