Tag: cws_dev300_dba31c
User: fs      
Date: 2008-09-25 13:04:53+0000
Modified:
   dba/connectivity/source/drivers/odbc/OPreparedStatement.cxx

Log:
 #i94027# when writing binary data, don't loop endlessly

File Changes:

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

File [changed]: OPreparedStatement.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/odbc/OPreparedStatement.cxx?r1=1.49&r2=1.49.64.1
Delta lines:  +26 -84
---------------------
--- OPreparedStatement.cxx      2008-04-10 10:30:31+0000        1.49
+++ OPreparedStatement.cxx      2008-09-25 13:04:51+0000        1.49.64.1
@@ -7,7 +7,7 @@
  * OpenOffice.org - a multi-platform office productivity suite
  *
  * $RCSfile: OPreparedStatement.cxx,v $
- * $Revision: 1.49 $
+ * $Revision: 1.49.64.1 $
  *
  * This file is part of OpenOffice.org.
  *
@@ -61,10 +61,6 @@
 using namespace com::sun::star::io;
 using namespace com::sun::star::util;
 
-int OBoundParam::ASCII   = 1;
-int OBoundParam::UNICODE = 2;
-int OBoundParam::BINARY  = 3;
-
 
IMPLEMENT_SERVICE_INFO(OPreparedStatement,"com.sun.star.sdbcx.OPreparedStatement","com.sun.star.sdbc.PreparedStatement");
 
 
@@ -200,7 +196,7 @@
                        // If the parameter index is -1, there is no
                        // more data required
 
-                       if (*paramIndex == -1)
+                       if ( !paramIndex || ( *paramIndex == -1 ) )
                                needData = sal_False;
                        else
                        {
@@ -586,13 +582,13 @@
 
 void SAL_CALL OPreparedStatement::setCharacterStream( sal_Int32 
parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, 
sal_Int32 length ) throw(SQLException, RuntimeException)
 {
-       setStream (parameterIndex, x, length, 
DataType::LONGVARCHAR,OBoundParam::ASCII);
+       setStream (parameterIndex, x, length, DataType::LONGVARCHAR);
 }
 // -------------------------------------------------------------------------
 
 void SAL_CALL OPreparedStatement::setBinaryStream( sal_Int32 parameterIndex, 
const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) 
throw(SQLException, RuntimeException)
 {
-       setStream (parameterIndex, x, length, 
DataType::LONGVARBINARY,OBoundParam::BINARY);
+       setStream (parameterIndex, x, length, DataType::LONGVARBINARY);
 }
 // -------------------------------------------------------------------------
 
@@ -765,13 +761,8 @@
                return;
        }
 
-       // We'll transfer up to maxLen at a time
-       sal_Int32       maxLen = MAX_PUT_DATA_LENGTH;
-       sal_Int32       bufLen;
-       sal_Int32       realLen;
-       //      sal_Int8*       buf = new sal_Int8[maxLen];
-       Sequence< sal_Int8 > buf(maxLen);
-       sal_Bool        endOfStream = sal_False;
+       // We'll transfer up to MAX_PUT_DATA_LENGTH at a time
+    Sequence< sal_Int8 > buf( MAX_PUT_DATA_LENGTH );
 
        // Get the information about the input stream
 
@@ -782,78 +773,35 @@
                *this,
                        ::rtl::OUString(),0,Any());
        }
-       sal_Int32 inputStreamLen = boundParams[index - 1].getInputStreamLen ();
-       sal_Int32 inputStreamType = boundParams[index - 1].getStreamType ();
+
+       sal_Int32 maxBytesLeft = boundParams[index - 1].getInputStreamLen ();
 
        // Loop while more data from the input stream
+    sal_Int32 haveRead = 0;
        try
        {
 
-               while (!endOfStream)
+               do
                {
+            sal_Int32 toReadThisRound = ::std::min( MAX_PUT_DATA_LENGTH, 
maxBytesLeft );
 
                        // Read some data from the input stream
-                       bufLen = inputStream->readBytes(buf,maxLen);
-
-                       // -1 as the number of bytes read indicates that
-                       // there is no more data in the input stream
-
-                       if (bufLen == -1)
-                       {
-
-                               // Sanity check to ensure that all the data we 
said we
-                               // had was read.  If not, raise an exception
+                       haveRead = inputStream->readBytes( buf, toReadThisRound 
);
+            OSL_ENSURE( haveRead == buf.getLength(), 
"OPreparedStatement::putParamData: inconsistency!" );
 
-                               if (inputStreamLen != 0)
-                               {
-                                       throw SQLException 
(::rtl::OUString::createFromAscii("End of InputStream reached before satisfying 
length specified when InputStream was set"),
-                                       *this,
-                                               ::rtl::OUString(),0,Any());
-                               }
-                               endOfStream = sal_True;
+            if ( !haveRead )
+                // no more data in the stream - the given stream length was a 
maximum which could not be
+                // fulfilled by the stream
                                break;
-                       }
-
-                       // If we got more bytes than necessary, truncate
-                       // the buffer by re-setting the buffer length.  Also,
-                       // indicate that we don't need to read any more.
-
-                       if (bufLen > inputStreamLen)
-                       {
-                               bufLen = inputStreamLen;
-                               endOfStream = sal_True;
-                       }
-
-                       realLen = bufLen;
-
-                       // For UNICODE streams, strip off the high sal_Int8 and 
set the
-                       // number of actual bytes present.  It is assumed that
-                       // there are 2 bytes present for every UNICODE 
character - if
-                       // not, then that's not our problem
-
-                       if (inputStreamType == OBoundParam::UNICODE)
-                       {
-                               realLen = bufLen / 2;
-
-                               for (sal_Int32 ii = 0; ii < realLen; ii++)
-                                       buf[ii] = buf[(ii * 2) + 1];
-                       }
 
                        // Put the data
-                       OSL_ENSURE(m_aStatementHandle,"StatementHandle is 
null!");
-
-                       N3SQLPutData (m_aStatementHandle, buf.getArray(), 
realLen);
+            OSL_ENSURE( m_aStatementHandle, "OPreparedStatement::putParamData: 
StatementHandle is null!" );
+                   N3SQLPutData ( m_aStatementHandle, buf.getArray(), 
buf.getLength() );
 
-                       // Decrement the number of bytes still needed
-
-                       inputStreamLen -= bufLen;
-
-
-                       // If there is no more data to be read, exit loop
-
-                       if (inputStreamLen == 0)
-                               endOfStream = sal_True;
+                       // decrement the number of bytes still needed
+                       maxBytesLeft -= haveRead;
                }
+        while ( maxBytesLeft > 0 );
        }
        catch (const IOException& ex)
        {
@@ -897,8 +845,7 @@
                                                                        
sal_Int32 ParameterIndex,
                                                                        const 
Reference< XInputStream>& x,
                                                                        
sal_Int32 length,
-                                                                       
sal_Int32 SQLtype,
-                                                                       
sal_Int32 streamType)
+                                                                       
sal_Int32 SQLtype)
                                                                        
throw(SQLException)
 {
        ::osl::MutexGuard aGuard( m_aMutex );
@@ -941,12 +888,7 @@
                                                (SDWORD*)lenBuf);
 
        // Save the input stream
-
        boundParams[ParameterIndex - 1].setInputStream (x, length);
-
-       // Set the stream type
-
-       boundParams[ParameterIndex - 1].setStreamType (streamType);
 }
 // -------------------------------------------------------------------------
 




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

Reply via email to