Tag: oo_pqsdbc_01
User: jbu     
Date: 2008-07-07 21:37:13+0000
Modified:
   dba/connectivity/source/drivers/postgresql/makefile.mk
   dba/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx
   dba/connectivity/source/drivers/postgresql/pq_tools.hxx
   dba/connectivity/source/drivers/postgresql/pq_tools.cxx
   dba/connectivity/workben/postgresql/preparedstatement.py

Log:
 #i85849# decimal fields are now supported in OOo2.4.x

File Changes:

Directory: /dba/connectivity/source/drivers/postgresql/
=======================================================

File [changed]: makefile.mk
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/makefile.mk?r1=1.1.2.13&r2=1.1.2.14
Delta lines:  +3 -3
-------------------
--- makefile.mk 2007-08-28 21:22:23+0000        1.1.2.13
+++ makefile.mk 2008-07-07 21:37:11+0000        1.1.2.14
@@ -2,9 +2,9 @@
 #
 #   $RCSfile: makefile.mk,v $
 #
-#   $Revision: 1.1.2.13 $
+#   $Revision: 1.1.2.14 $
 #
-#   last change: $Author: jbu $ $Date: 2007/08/28 21:22:23 $
+#   last change: $Author: jbu $ $Date: 2008/07/07 21:37:11 $
 #
 #   The Contents of this file are made available subject to the terms of
 #   either of the following licenses
@@ -81,7 +81,7 @@
 
 PQ_SDBC_MAJOR=0
 PQ_SDBC_MINOR=7
-PQ_SDBC_MICRO=5
+PQ_SDBC_MICRO=6
 .IF "$(SYSTEM_POSTGRESQL)" == "YES"
 POSTGRESQL_MAJOR=`pg_config --version | awk '{ print $$2 }' | cut -d. -f1`
 POSTGRESQL_MINOR=`pg_config --version | awk '{ print $$2 }' | cut -d. -f2`

File [changed]: pq_preparedstatement.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx?r1=1.1.2.9&r2=1.1.2.10
Delta lines:  +40 -8
--------------------
--- pq_preparedstatement.cxx    2007-08-26 20:40:40+0000        1.1.2.9
+++ pq_preparedstatement.cxx    2008-07-07 21:37:11+0000        1.1.2.10
@@ -2,9 +2,9 @@
  *
  *  $RCSfile: pq_preparedstatement.cxx,v $
  *
- *  $Revision: 1.1.2.9 $
+ *  $Revision: 1.1.2.10 $
  *
- *  last change: $Author: jbu $ $Date: 2007/08/26 20:40:40 $
+ *  last change: $Author: jbu $ $Date: 2008/07/07 21:37:11 $
  *
  *  The Contents of this file are made available subject to the terms of
  *  either of the following licenses
@@ -655,9 +655,13 @@
 void PreparedStatement::setObject( sal_Int32 parameterIndex, const Any& x )
     throw (SQLException, RuntimeException)
 {
-    throw SQLException(
-        ASCII_STR( "pq_preparedstatement: setObject not implemented" ),
-        *this, OUString(), 1, Any () );
+    if( ! implSetObject( this, parameterIndex, x ))
+    {
+        OUStringBuffer buf;
+        buf.append( ASCII_STR("pq_preparedstatement::setObject: can't convert 
value of type " ) );
+        buf.append( x.getValueTypeName() );
+        throw SQLException( buf.makeStringAndClear(), *this, OUString(), 1, 
Any () );
+    }
 }
 
 void PreparedStatement::setObjectWithInfo(
@@ -667,9 +671,37 @@
     sal_Int32 scale )
     throw (SQLException, RuntimeException)
 {
-    throw SQLException(
-        ASCII_STR( "pq_preparedstatement: setObjectWithInfo not implemented" ),
-        *this, OUString(), 1, Any () );
+    if( com::sun::star::sdbc::DataType::DECIMAL == targetSqlType ||
+        com::sun::star::sdbc::DataType::NUMERIC == targetSqlType )
+    {
+        double myDouble;
+        OUString myString;
+        if( x >>= myDouble )
+        {
+            myString = OUString::valueOf( myDouble );
+        }
+        else  
+        {
+            x >>= myString;
+        }
+        if( myString.getLength() )
+        {
+//              printf( "setObjectWithInfo %s\n", 
OUStringToOString(myString,RTL_TEXTENCODING_ASCII_US).getStr());
+            setString( parameterIndex, myString );
+        }
+        else
+        {
+            OUStringBuffer buf;
+            buf.append( ASCII_STR("pq_preparedstatement::setObjectWithInfo: 
can't convert value of type " ) );
+            buf.append( x.getValueTypeName() );
+            buf.append( ASCII_STR(" to type DECIMAL or NUMERIC" ) );
+            throw SQLException( buf.makeStringAndClear(), *this, OUString(), 
1, Any () );
+        }
+    }
+    else 
+    {
+        setObject( parameterIndex, x );
+    }
     
 }
 

File [changed]: pq_tools.hxx
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/pq_tools.hxx?r1=1.1.2.6&r2=1.1.2.7
Delta lines:  +7 -2
-------------------
--- pq_tools.hxx        2006-05-01 19:19:07+0000        1.1.2.6
+++ pq_tools.hxx        2008-07-07 21:37:11+0000        1.1.2.7
@@ -2,9 +2,9 @@
  *
  *  $RCSfile: pq_tools.hxx,v $
  *
- *  $Revision: 1.1.2.6 $
+ *  $Revision: 1.1.2.7 $
  *
- *  last change: $Author: jbu $ $Date: 2006/05/01 19:19:07 $
+ *  last change: $Author: jbu $ $Date: 2008/07/07 21:37:11 $
  *
  *  The Contents of this file are made available subject to the terms of
  *  either of the following licenses
@@ -63,6 +63,7 @@
 #define _PQ_TOOLS_
 
 #include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/sdbc/XParameters.hpp>
 #include <com/sun/star/util/Date.hpp>
 #include <com/sun/star/util/Time.hpp>
 #include <com/sun/star/util/DateTime.hpp>
@@ -169,6 +170,10 @@
 void extractNameValuePairsFromInsert( String2StringMap & map, const 
rtl::OString & lastQuery );
 sal_Int32 typeNameToDataType( const rtl::OUString &typeName, const 
rtl::OUString &typtype );
 
+// copied from connectivity/source/dbtools, can't use the function directly
+bool implSetObject(    const com::sun::star::uno::Reference< 
com::sun::star::sdbc::XParameters >& _rxParameters,
+                    const sal_Int32 _nColumnIndex, const 
com::sun::star::uno::Any& _rValue);
+
 class DisposeGuard
 {
     com::sun::star::uno::Reference< com::sun::star::uno::XInterface > d;

File [changed]: pq_tools.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/postgresql/pq_tools.cxx?r1=1.1.2.9&r2=1.1.2.10
Delta lines:  +91 -0
--------------------
--- pq_tools.cxx        2007-08-28 20:31:17+0000        1.1.2.9
+++ pq_tools.cxx        2008-07-07 21:37:11+0000        1.1.2.10
@@ -1138,4 +1138,95 @@
 }
 
 
+// copied from connectivity/source/dbtools, can't use the function directly
+bool implSetObject(    const Reference< XParameters >& _rxParameters,
+                                               const sal_Int32 _nColumnIndex, 
const Any& _rValue) SAL_THROW ( ( SQLException, RuntimeException ) )
+{
+       sal_Bool bSuccessfullyReRouted = sal_True;
+       switch (_rValue.getValueTypeClass())
+       {
+               case typelib_TypeClass_HYPER:
+               {
+                       sal_Int64 nValue = 0;
+                       _rxParameters->setLong( _nColumnIndex, nValue );
+               }
+               break;
+
+               case typelib_TypeClass_VOID:
+                       
_rxParameters->setNull(_nColumnIndex,com::sun::star::sdbc::DataType::VARCHAR);
+                       break;
+
+               case typelib_TypeClass_STRING:
+                       _rxParameters->setString(_nColumnIndex, 
*(rtl::OUString*)_rValue.getValue());
+                       break;
+
+               case typelib_TypeClass_BOOLEAN:
+                       _rxParameters->setBoolean(_nColumnIndex, *(sal_Bool 
*)_rValue.getValue());
+                       break;
+
+               case typelib_TypeClass_BYTE:
+                       _rxParameters->setByte(_nColumnIndex, *(sal_Int8 
*)_rValue.getValue());
+                       break;
+
+               case typelib_TypeClass_UNSIGNED_SHORT:
+               case typelib_TypeClass_SHORT:
+                       _rxParameters->setShort(_nColumnIndex, 
*(sal_Int16*)_rValue.getValue());
+                       break;
+
+               case typelib_TypeClass_CHAR:
+                       _rxParameters->setString(_nColumnIndex, 
::rtl::OUString((sal_Unicode *)_rValue.getValue(),1));
+                       break;
+
+               case typelib_TypeClass_UNSIGNED_LONG:
+               case typelib_TypeClass_LONG:
+                       _rxParameters->setInt(_nColumnIndex, 
*(sal_Int32*)_rValue.getValue());
+                       break;
+
+               case typelib_TypeClass_FLOAT:
+                       _rxParameters->setFloat(_nColumnIndex, 
*(float*)_rValue.getValue());
+                       break;
+
+               case typelib_TypeClass_DOUBLE:
+                       _rxParameters->setDouble(_nColumnIndex, 
*(double*)_rValue.getValue());
+                       break;
+
+               case typelib_TypeClass_SEQUENCE:
+                       if (_rValue.getValueType() == ::getCppuType((const 
Sequence< sal_Int8 > *)0))
+                       {
+                               _rxParameters->setBytes(_nColumnIndex, 
*(Sequence<sal_Int8>*)_rValue.getValue());
+                       }
+                       else
+                               bSuccessfullyReRouted = sal_False;
+                       break;
+               case typelib_TypeClass_STRUCT:
+                       if (_rValue.getValueType() == ::getCppuType((const 
com::sun::star::util::DateTime*)0))
+                               _rxParameters->setTimestamp(_nColumnIndex, 
*(com::sun::star::util::DateTime*)_rValue.getValue());
+                       else if (_rValue.getValueType() == ::getCppuType((const 
com::sun::star::util::Date*)0))
+                               _rxParameters->setDate(_nColumnIndex, 
*(com::sun::star::util::Date*)_rValue.getValue());
+                       else if (_rValue.getValueType() == ::getCppuType((const 
com::sun::star::util::Time*)0))
+                               _rxParameters->setTime(_nColumnIndex, 
*(com::sun::star::util::Time*)_rValue.getValue());
+                       else
+                               bSuccessfullyReRouted = sal_False;
+                       break;
+
+               case typelib_TypeClass_INTERFACE:
+        {
+            Reference< com::sun::star::io::XInputStream >  xStream;
+                       if (_rValue >>= xStream)
+                       {
+                               _rValue >>= xStream;
+                               _rxParameters->setBinaryStream(_nColumnIndex, 
xStream, xStream->available());
+                               break;
+                       }
+        }
+                       // run through
+               default:
+                       bSuccessfullyReRouted = sal_False;
+
+       }
+
+       return bSuccessfullyReRouted;
+}
+
+
 }

Directory: /dba/connectivity/workben/postgresql/
================================================

File [changed]: preparedstatement.py
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/workben/postgresql/preparedstatement.py?r1=1.1.2.8&r2=1.1.2.9
Delta lines:  +24 -3
--------------------
--- preparedstatement.py        2007-08-28 20:41:25+0000        1.1.2.8
+++ preparedstatement.py        2008-07-07 21:37:11+0000        1.1.2.9
@@ -2,9 +2,9 @@
 #
 #   $RCSfile: preparedstatement.py,v $
 #
-#   $Revision: 1.1.2.8 $
+#   $Revision: 1.1.2.9 $
 #
-#   last change: $Author: jbu $ $Date: 2007/08/28 20:41:25 $
+#   last change: $Author: jbu $ $Date: 2008/07/07 21:37:11 $
 #
 #   The Contents of this file are made available subject to the terms of
 #   either of the following licenses
@@ -63,6 +63,7 @@
 from uno import ByteSequence
 from com.sun.star.sdbc import SQLException
 from com.sun.star.sdbc.ResultSetConcurrency import UPDATABLE
+from com.sun.star.sdbc.DataType import NUMERIC,VARCHAR
 
 def suite(ctx,dburl):
     suite = unittest.TestSuite()
@@ -103,7 +104,8 @@
           for stmt in stmts:
               prepstmt = self.connection.prepareStatement( stmt )
               prepstmt.setDouble( 1, 5.80 )
-              prepstmt.setDouble( 2, 7. )
+              prepstmt.setObjectWithInfo( 2, 7. , NUMERIC, 2)
+              prepstmt.setObjectWithInfo( 2, "7.0000", NUMERIC, 2 )
               rs = prepstmt.executeQuery( )
               self.failUnless( rs.getMetaData().getColumnCount() == 1 )
               self.failUnless( rs.getMetaData().getColumnName(1) == "id")
@@ -142,6 +144,25 @@
           stmt = self.connection.createStatement()
           rs =  stmt.executeQuery( "SELECT * FROM \"public\".\"customer\"" )
           
+          stmt.executeUpdate( "DELETE FROM product where id='PAS5'" )
+          prepstmt =self.connection.prepareStatement(
+              "INSERT INTO product VALUES(?,'Ravioli',?,NULL)" );
+          prepstmt.setObjectWithInfo( 1, "PAS5" ,VARCHAR,0)
+          prepstmt.setObjectWithInfo( 2, "9.223" ,NUMERIC,2)
+          prepstmt.executeUpdate()
+          rs= stmt.executeQuery( "SELECT price FROM product WHERE id = 'PAS5'" 
)
+          self.failUnless( rs.next() )
+          self.failUnless( rs.getString( 1 ).strip() == "9.22" )
+          
+          stmt.executeUpdate( "DELETE FROM product where id='PAS5'" )
+          prepstmt =self.connection.prepareStatement(
+              "INSERT INTO product VALUES('PAS5','Ravioli',?,NULL)" );
+          prepstmt.setObjectWithInfo( 1, 9.223,NUMERIC,2 )
+          prepstmt.executeUpdate()
+          rs= stmt.executeQuery( "SELECT price FROM product WHERE id = 'PAS5'" 
)
+          self.failUnless( rs.next() )
+          self.failUnless( rs.getString( 1 ).strip() == "9.22" )
+          
       def testGeneratedResultSet( self ):
           prepstmt = self.connection.prepareStatement(
               "INSERT INTO customer VALUES( ?, ? )" )




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to