xref: /trunk/main/connectivity/source/drivers/odbcbase/OStatement.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_odbcbase.hxx"
26 
27 #include <stdio.h>
28 #include <osl/diagnose.h>
29 #include "odbc/OStatement.hxx"
30 #include "odbc/OConnection.hxx"
31 #include "odbc/OResultSet.hxx"
32 #include <comphelper/property.hxx>
33 #include "odbc/OTools.hxx"
34 #include <comphelper/uno3.hxx>
35 #include <osl/thread.h>
36 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
37 #include <com/sun/star/sdbc/ResultSetType.hpp>
38 #include <com/sun/star/sdbc/FetchDirection.hpp>
39 #include <com/sun/star/lang/DisposedException.hpp>
40 #include <comphelper/sequence.hxx>
41 #include <cppuhelper/typeprovider.hxx>
42 #include <comphelper/extract.hxx>
43 #include <comphelper/types.hxx>
44 #include "diagnose_ex.h"
45 #include <algorithm>
46 #include "resource/common_res.hrc"
47 #include "connectivity/dbexception.hxx"
48 
49 using namespace ::comphelper;
50 
51 #define THROW_SQL(x) \
52     OTools::ThrowException(m_pConnection,x,m_aStatementHandle,SQL_HANDLE_STMT,*this)
53 
54 #if OSL_DEBUG_LEVEL > 1
55 #define DEBUG_THROW                 \
56     try                                 \
57     {                                   \
58         THROW_SQL(nRetCode);            \
59     }                                   \
60     catch(SQLException&)                \
61     {                                   \
62         OSL_ENSURE(0,"Exception in odbc catched"); \
63     }
64 #endif
65 
66 
67 
68 using namespace connectivity::odbc;
69 //------------------------------------------------------------------------------
70 using namespace com::sun::star::uno;
71 using namespace com::sun::star::lang;
72 using namespace com::sun::star::beans;
73 using namespace com::sun::star::sdbc;
74 using namespace com::sun::star::sdbcx;
75 using namespace com::sun::star::container;
76 using namespace com::sun::star::io;
77 using namespace com::sun::star::util;
78 //------------------------------------------------------------------------------
OStatement_Base(OConnection * _pConnection)79 OStatement_Base::OStatement_Base(OConnection* _pConnection )
80     :OStatement_BASE(m_aMutex)
81     ,OPropertySetHelper(OStatement_BASE::rBHelper)
82     ,m_pConnection(_pConnection)
83     ,m_aStatementHandle(SQL_NULL_HANDLE)
84     ,m_pRowStatusArray(0)
85     ,rBHelper(OStatement_BASE::rBHelper)
86 {
87     osl_incrementInterlockedCount( &m_refCount );
88     m_pConnection->acquire();
89     m_aStatementHandle = m_pConnection->createStatementHandle();
90 
91     //setMaxFieldSize(0);
92     // Don't do this. By ODBC spec, "0" is the default for the SQL_ATTR_MAX_LENGTH attribute. We once introduced
93     // this line since an PostgreSQL ODBC driver had a default other than 0. However, current drivers (at least 8.3
94     // and later) have a proper default of 0, so there should be no need anymore.
95     // On the other hand, the NotesSQL driver (IBM's ODBC driver for the Lotus Notes series) wrongly interprets
96     // "0" as "0", whereas the ODBC spec says it should in fact mean "unlimited".
97     // So, removing this line seems to be the best option for now.
98     // If we ever again encounter a ODBC driver which needs this option, then we should introduce a data source
99     // setting for it, instead of unconditionally doing it.
100 
101     osl_decrementInterlockedCount( &m_refCount );
102 }
103 // -----------------------------------------------------------------------------
~OStatement_Base()104 OStatement_Base::~OStatement_Base()
105 {
106     OSL_ENSURE(!m_aStatementHandle,"Sohould ne null here!");
107 }
108 //------------------------------------------------------------------------------
disposeResultSet()109 void OStatement_Base::disposeResultSet()
110 {
111     // free the cursor if alive
112     Reference< XComponent > xComp(m_xResultSet.get(), UNO_QUERY);
113     if (xComp.is())
114         xComp->dispose();
115     m_xResultSet = Reference< XResultSet>();
116 }
117 // -----------------------------------------------------------------------------
disposing(void)118 void SAL_CALL OStatement_Base::disposing(void)
119 {
120     ::osl::MutexGuard aGuard(m_aMutex);
121 
122     disposeResultSet();
123     ::comphelper::disposeComponent(m_xGeneratedStatement);
124 
125     OSL_ENSURE(m_aStatementHandle,"OStatement_BASE2::disposing: StatementHandle is null!");
126     if (m_pConnection)
127     {
128         m_pConnection->freeStatementHandle(m_aStatementHandle);
129         m_pConnection->release();
130         m_pConnection = NULL;
131     }
132     OSL_ENSURE(!m_aStatementHandle,"Sohould ne null here!");
133 
134     OStatement_BASE::disposing();
135 }
136 //------------------------------------------------------------------------------
disposing()137 void OStatement_BASE2::disposing()
138 {
139     ::osl::MutexGuard aGuard(m_aMutex);
140 
141     dispose_ChildImpl();
142     OStatement_Base::disposing();
143 }
144 //-----------------------------------------------------------------------------
release()145 void SAL_CALL OStatement_BASE2::release() throw()
146 {
147     relase_ChildImpl();
148 }
149 //-----------------------------------------------------------------------------
queryInterface(const Type & rType)150 Any SAL_CALL OStatement_Base::queryInterface( const Type & rType )
151 {
152     if ( m_pConnection && !m_pConnection->isAutoRetrievingEnabled() && rType == ::getCppuType( (const Reference< XGeneratedResultSet > *)0 ) )
153         return Any();
154     Any aRet = OStatement_BASE::queryInterface(rType);
155     return aRet.hasValue() ? aRet : OPropertySetHelper::queryInterface(rType);
156 }
157 // -------------------------------------------------------------------------
getTypes()158 Sequence< Type > SAL_CALL OStatement_Base::getTypes(  )
159 {
160     ::cppu::OTypeCollection aTypes( ::getCppuType( (const Reference< XMultiPropertySet > *)0 ),
161                                     ::getCppuType( (const Reference< XFastPropertySet > *)0 ),
162                                     ::getCppuType( (const Reference< XPropertySet > *)0 ));
163     Sequence< Type > aOldTypes = OStatement_BASE::getTypes();
164     if ( m_pConnection && !m_pConnection->isAutoRetrievingEnabled() )
165     {
166         ::std::remove(aOldTypes.getArray(),aOldTypes.getArray() + aOldTypes.getLength(),
167                         ::getCppuType( (const Reference< XGeneratedResultSet > *)0 ));
168         aOldTypes.realloc(aOldTypes.getLength() - 1);
169     }
170 
171     return ::comphelper::concatSequences(aTypes.getTypes(),aOldTypes);
172 }
173 // -------------------------------------------------------------------------
getGeneratedValues()174 Reference< XResultSet > SAL_CALL OStatement_Base::getGeneratedValues(  )
175 {
176     OSL_ENSURE( m_pConnection && m_pConnection->isAutoRetrievingEnabled(),"Illegal call here. isAutoRetrievingEnabled is false!");
177     Reference< XResultSet > xRes;
178     if ( m_pConnection )
179     {
180         ::rtl::OUString sStmt = m_pConnection->getTransformedGeneratedStatement(m_sSqlStatement);
181         if ( sStmt.getLength() )
182         {
183             ::comphelper::disposeComponent(m_xGeneratedStatement);
184             m_xGeneratedStatement = m_pConnection->createStatement();
185             xRes = m_xGeneratedStatement->executeQuery(sStmt);
186         }
187     }
188     return xRes;
189 }
190 // -----------------------------------------------------------------------------
cancel()191 void SAL_CALL OStatement_Base::cancel(  )
192 {
193     ::osl::MutexGuard aGuard( m_aMutex );
194     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
195 
196     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
197     OTools::ThrowException(m_pConnection,N3SQLCancel(m_aStatementHandle),m_aStatementHandle,SQL_HANDLE_STMT,*this);
198 }
199 // -------------------------------------------------------------------------
200 
close()201 void SAL_CALL OStatement_Base::close(  )
202 {
203     {
204         ::osl::MutexGuard aGuard( m_aMutex );
205         checkDisposed(OStatement_BASE::rBHelper.bDisposed);
206 
207     }
208     dispose();
209 }
210 // -------------------------------------------------------------------------
211 
clearBatch()212 void SAL_CALL OStatement::clearBatch(  )
213 {
214 
215 }
216 // -------------------------------------------------------------------------
217 
reset()218 void OStatement_Base::reset()
219 {
220     ::osl::MutexGuard aGuard( m_aMutex );
221     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
222 
223 
224     clearWarnings ();
225 
226     if (m_xResultSet.get().is())
227     {
228         clearMyResultSet();
229     }
230     if(m_aStatementHandle)
231     {
232         THROW_SQL(N3SQLFreeStmt(m_aStatementHandle, SQL_CLOSE));
233     }
234 }
235 //--------------------------------------------------------------------
236 // clearMyResultSet
237 // If a ResultSet was created for this Statement, close it
238 //--------------------------------------------------------------------
239 
clearMyResultSet()240 void OStatement_Base::clearMyResultSet ()
241 {
242     ::osl::MutexGuard aGuard( m_aMutex );
243     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
244 
245     try
246     {
247         Reference<XCloseable> xCloseable;
248         if ( ::comphelper::query_interface( m_xResultSet.get(), xCloseable ) )
249             xCloseable->close();
250     }
251     catch( const DisposedException& ) { }
252 
253     m_xResultSet = Reference< XResultSet >();
254 }
255 //--------------------------------------------------------------------
getRowCount()256 SQLLEN OStatement_Base::getRowCount ()
257 {
258     ::osl::MutexGuard aGuard( m_aMutex );
259     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
260 
261 
262     SQLLEN numRows = 0;
263 
264     try {
265         THROW_SQL(N3SQLRowCount(m_aStatementHandle,&numRows));
266     }
267     catch (SQLException&)
268     {
269     }
270     return numRows;
271 }
272 //--------------------------------------------------------------------
273 // lockIfNecessary
274 // If the given SQL statement contains a 'FOR UPDATE' clause, change
275 // the concurrency to lock so that the row can then be updated.  Returns
276 // true if the concurrency has been changed
277 //--------------------------------------------------------------------
278 
lockIfNecessary(const::rtl::OUString & sql)279 sal_Bool OStatement_Base::lockIfNecessary (const ::rtl::OUString& sql)
280 {
281     sal_Bool rc = sal_False;
282 
283     // First, convert the statement to upper case
284 
285     ::rtl::OUString sqlStatement = sql.toAsciiUpperCase ();
286 
287     // Now, look for the FOR UPDATE keywords.  If there is any extra white
288     // space between the FOR and UPDATE, this will fail.
289 
290     sal_Int32 index = sqlStatement.indexOf(::rtl::OUString::createFromAscii(" FOR UPDATE"));
291 
292     // We found it.  Change our concurrency level to ensure that the
293     // row can be updated.
294 
295     if (index > 0)
296     {
297         OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
298         try
299         {
300             SQLUINTEGER nLock = SQL_CONCUR_LOCK;
301             THROW_SQL(N3SQLSetStmtAttr(m_aStatementHandle, SQL_CONCURRENCY,(SQLPOINTER)nLock,SQL_IS_UINTEGER));
302         }
303         catch (SQLWarning& warn)
304         {
305             // Catch any warnings and place on the warning stack
306             setWarning (warn);
307         }
308         rc = sal_True;
309     }
310 
311     return rc;
312 }
313 //--------------------------------------------------------------------
314 // setWarning
315 // Sets the warning
316 //--------------------------------------------------------------------
317 
setWarning(const SQLWarning & ex)318 void OStatement_Base::setWarning (const SQLWarning &ex)
319 {
320     ::osl::MutexGuard aGuard( m_aMutex );
321     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
322 
323 
324     m_aLastWarning = ex;
325 }
326 
327 //--------------------------------------------------------------------
328 // getColumnCount
329 // Return the number of columns in the ResultSet
330 //--------------------------------------------------------------------
331 
getColumnCount()332 sal_Int32 OStatement_Base::getColumnCount ()
333 {
334     ::osl::MutexGuard aGuard( m_aMutex );
335     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
336 
337 
338     sal_Int16   numCols = 0;
339     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
340 
341     try {
342         THROW_SQL(N3SQLNumResultCols(m_aStatementHandle,&numCols));
343     }
344     catch (SQLException&)
345     {
346     }
347     return numCols;
348 }
349 // -------------------------------------------------------------------------
350 
execute(const::rtl::OUString & sql)351 sal_Bool SAL_CALL OStatement_Base::execute( const ::rtl::OUString& sql )
352 {
353     ::osl::MutexGuard aGuard( m_aMutex );
354     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
355     m_sSqlStatement = sql;
356 
357 
358     ::rtl::OString aSql(::rtl::OUStringToOString(sql,getOwnConnection()->getTextEncoding()));
359 
360     sal_Bool hasResultSet = sal_False;
361     SQLWarning aWarning;
362 
363     // Reset the statement handle and warning
364 
365     reset();
366 
367     // Check for a 'FOR UPDATE' statement.  If present, change
368     // the concurrency to lock
369 
370     lockIfNecessary (sql);
371 
372     // Call SQLExecDirect
373     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
374 
375     try {
376         THROW_SQL(N3SQLExecDirect(m_aStatementHandle, (SDB_ODBC_CHAR*)aSql.getStr(),aSql.getLength()));
377     }
378     catch (SQLWarning& ex) {
379 
380         // Save pointer to warning and save with ResultSet
381         // object once it is created.
382 
383         aWarning = ex;
384     }
385 
386     // Now determine if there is a result set associated with
387     // the SQL statement that was executed.  Get the column
388     // count, and if it is not zero, there is a result set.
389 
390     if (getColumnCount () > 0)
391     {
392         hasResultSet = sal_True;
393     }
394 
395     return hasResultSet;
396 }
397 //--------------------------------------------------------------------
398 // getResultSet
399 // getResultSet returns the current result as a ResultSet.  It
400 // returns NULL if the current result is not a ResultSet.
401 //--------------------------------------------------------------------
getResultSet(sal_Bool checkCount)402 Reference< XResultSet > OStatement_Base::getResultSet (sal_Bool checkCount)
403 {
404     ::osl::MutexGuard aGuard( m_aMutex );
405     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
406 
407 
408     if (m_xResultSet.get().is())  // if resultset already retrieved,
409     {
410         // throw exception to avoid sequence error
411         ::dbtools::throwFunctionSequenceException(*this,Any());
412     }
413 
414     OResultSet* pRs = NULL;
415     sal_Int32 numCols = 1;
416 
417     // If we already know we have result columns, checkCount
418     // is false.  This is an optimization to prevent unneeded
419     // calls to getColumnCount
420 
421     if (checkCount)
422         numCols = getColumnCount ();
423 
424     // Only return a result set if there are result columns
425 
426     if (numCols > 0)
427     {
428         OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
429         pRs = createResulSet();
430         pRs->construct();
431 
432         // Save a copy of our last result set
433         // Changed to save copy at getResultSet.
434         //m_xResultSet = rs;
435     }
436     else
437         clearMyResultSet ();
438 
439     return pRs;
440 }
441 //--------------------------------------------------------------------
442 // getStmtOption
443 // Invoke SQLGetStmtOption with the given option.
444 //--------------------------------------------------------------------
445 
getStmtOption(short fOption) const446 sal_Int32 OStatement_Base::getStmtOption (short fOption) const
447 {
448     SQLLEN  result = 0;
449     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
450     N3SQLGetStmtAttr(m_aStatementHandle, fOption,&result,SQL_IS_INTEGER,NULL);
451     return result;
452 }
453 // -------------------------------------------------------------------------
454 
executeQuery(const::rtl::OUString & sql)455 Reference< XResultSet > SAL_CALL OStatement_Base::executeQuery( const ::rtl::OUString& sql )
456 {
457     ::osl::MutexGuard aGuard( m_aMutex );
458     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
459 
460 
461     Reference< XResultSet > xRS = NULL;
462 
463     // Execute the statement.  If execute returns true, a result
464     // set exists.
465 
466     if (execute (sql))
467     {
468         xRS = getResultSet (sal_False);
469         m_xResultSet = xRS;
470     }
471     else
472     {
473         // No ResultSet was produced.  Raise an exception
474         m_pConnection->throwGenericSQLException(STR_NO_RESULTSET,*this);
475     }
476     return xRS;
477 }
478 // -------------------------------------------------------------------------
479 
getConnection()480 Reference< XConnection > SAL_CALL OStatement_Base::getConnection(  )
481 {
482     ::osl::MutexGuard aGuard( m_aMutex );
483     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
484 
485     return (Reference< XConnection >)m_pConnection;
486 }
487 // -------------------------------------------------------------------------
488 
queryInterface(const Type & rType)489 Any SAL_CALL OStatement::queryInterface( const Type & rType )
490 {
491     Any aRet = ::cppu::queryInterface(rType,static_cast< XBatchExecution*> (this));
492     return aRet.hasValue() ? aRet : OStatement_Base::queryInterface(rType);
493 }
494 // -------------------------------------------------------------------------
495 
addBatch(const::rtl::OUString & sql)496 void SAL_CALL OStatement::addBatch( const ::rtl::OUString& sql )
497 {
498     ::osl::MutexGuard aGuard( m_aMutex );
499     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
500 
501 
502     m_aBatchList.push_back(sql);
503 }
504 // -------------------------------------------------------------------------
executeBatch()505 Sequence< sal_Int32 > SAL_CALL OStatement::executeBatch(  )
506 {
507     ::osl::MutexGuard aGuard( m_aMutex );
508     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
509 
510 
511     ::rtl::OString aBatchSql;
512     sal_Int32 nLen = 0;
513     for(::std::list< ::rtl::OUString>::const_iterator i=m_aBatchList.begin();i != m_aBatchList.end();++i,++nLen)
514     {
515         aBatchSql += ::rtl::OUStringToOString(*i,getOwnConnection()->getTextEncoding());
516         aBatchSql += ";";
517     }
518 
519     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
520     THROW_SQL(N3SQLExecDirect(m_aStatementHandle, (SDB_ODBC_CHAR*)aBatchSql.getStr(),aBatchSql.getLength()));
521 
522     Sequence< sal_Int32 > aRet(nLen);
523     sal_Int32* pArray = aRet.getArray();
524     for(sal_Int32 j=0;j<nLen;++j)
525     {
526         SQLRETURN nError = N3SQLMoreResults(m_aStatementHandle);
527         if(nError == SQL_SUCCESS)
528         {
529             SQLLEN nRowCount=0;
530             N3SQLRowCount(m_aStatementHandle,&nRowCount);
531             pArray[j] = nRowCount;
532         }
533     }
534     return aRet;
535 }
536 // -------------------------------------------------------------------------
537 
538 
executeUpdate(const::rtl::OUString & sql)539 sal_Int32 SAL_CALL OStatement_Base::executeUpdate( const ::rtl::OUString& sql )
540 {
541     ::osl::MutexGuard aGuard( m_aMutex );
542     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
543 
544 
545     sal_Int32 numRows = -1;
546 
547     // Execute the statement.  If execute returns false, a
548     // row count exists.
549 
550     if (!execute (sql)) {
551         numRows = getUpdateCount();
552     }
553     else {
554 
555         // No update count was produced (a ResultSet was).  Raise
556         // an exception
557 
558         ::connectivity::SharedResources aResources;
559         const ::rtl::OUString sError( aResources.getResourceString(STR_NO_ROWCOUNT));
560         throw SQLException (sError, *this,::rtl::OUString(),0,Any());
561     }
562     return numRows;
563 
564 }
565 // -------------------------------------------------------------------------
566 
getResultSet()567 Reference< XResultSet > SAL_CALL OStatement_Base::getResultSet(  )
568 {
569     ::osl::MutexGuard aGuard( m_aMutex );
570     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
571 
572 
573     m_xResultSet = getResultSet(sal_True);
574     return m_xResultSet;
575 }
576 // -------------------------------------------------------------------------
577 
getUpdateCount()578 sal_Int32 SAL_CALL OStatement_Base::getUpdateCount(  )
579 {
580     ::osl::MutexGuard aGuard( m_aMutex );
581     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
582 
583 
584     sal_Int32 rowCount = -1;
585 
586     // Only return a row count for SQL statements that did not
587     // return a result set.
588 
589     if (getColumnCount () == 0)
590         rowCount = getRowCount ();
591 
592     return rowCount;
593 }
594 // -------------------------------------------------------------------------
595 
getMoreResults()596 sal_Bool SAL_CALL OStatement_Base::getMoreResults(  )
597 {
598     ::osl::MutexGuard aGuard( m_aMutex );
599     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
600 
601 
602     SQLWarning  warning;
603     sal_Bool hasResultSet = sal_False;
604 
605     // clear previous warnings
606 
607     clearWarnings ();
608 
609     // Call SQLMoreResults
610     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
611 
612     try {
613         hasResultSet = N3SQLMoreResults(m_aStatementHandle) == SQL_SUCCESS;
614     }
615     catch (SQLWarning &ex) {
616 
617         // Save pointer to warning and save with ResultSet
618         // object once it is created.
619 
620         warning = ex;
621     }
622 
623     // There are more results (it may not be a result set, though)
624 
625     if (hasResultSet)
626     {
627 
628         // Now determine if there is a result set associated
629         // with the SQL statement that was executed.  Get the
630         // column count, and if it is zero, there is not a
631         // result set.
632 
633         if (getColumnCount () == 0)
634             hasResultSet = sal_False;
635     }
636 
637     // Set the warning for the statement, if one was generated
638 
639     setWarning (warning);
640 
641     // Return the result set indicator
642 
643     return hasResultSet;
644 }
645 // -------------------------------------------------------------------------
646 
647 // -------------------------------------------------------------------------
getWarnings()648 Any SAL_CALL OStatement_Base::getWarnings(  )
649 {
650     ::osl::MutexGuard aGuard( m_aMutex );
651     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
652 
653 
654     return makeAny(m_aLastWarning);
655 }
656 // -------------------------------------------------------------------------
657 
658 // -------------------------------------------------------------------------
clearWarnings()659 void SAL_CALL OStatement_Base::clearWarnings(  )
660 {
661     ::osl::MutexGuard aGuard( m_aMutex );
662     checkDisposed(OStatement_BASE::rBHelper.bDisposed);
663 
664 
665     m_aLastWarning = SQLWarning();
666 }
667 // -------------------------------------------------------------------------
668 //------------------------------------------------------------------------------
getQueryTimeOut() const669 sal_Int32 OStatement_Base::getQueryTimeOut() const
670 {
671     return getStmtOption(SQL_ATTR_QUERY_TIMEOUT);
672 }
673 //------------------------------------------------------------------------------
getMaxRows() const674 sal_Int32 OStatement_Base::getMaxRows() const
675 {
676     return getStmtOption(SQL_ATTR_MAX_ROWS);
677 }
678 //------------------------------------------------------------------------------
getResultSetConcurrency() const679 sal_Int32 OStatement_Base::getResultSetConcurrency() const
680 {
681     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
682     SQLULEN nValue;
683     SQLRETURN nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CONCURRENCY,&nValue,SQL_IS_UINTEGER,0);
684     OSL_UNUSED( nRetCode );
685     if(nValue == SQL_CONCUR_READ_ONLY)
686         nValue = ResultSetConcurrency::READ_ONLY;
687     else
688         nValue = ResultSetConcurrency::UPDATABLE;
689     return nValue;
690 }
691 //------------------------------------------------------------------------------
getResultSetType() const692 sal_Int32 OStatement_Base::getResultSetType() const
693 {
694     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
695     SQLULEN nValue = SQL_CURSOR_FORWARD_ONLY;
696     SQLRETURN nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_SENSITIVITY,&nValue,SQL_IS_UINTEGER,0);
697     nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,&nValue,SQL_IS_UINTEGER,0);
698     switch(nValue)
699     {
700         case SQL_CURSOR_FORWARD_ONLY:
701             nValue = ResultSetType::FORWARD_ONLY;
702             break;
703         case SQL_CURSOR_KEYSET_DRIVEN:
704         case SQL_CURSOR_STATIC:
705             nValue = ResultSetType::SCROLL_INSENSITIVE;
706             break;
707         case SQL_CURSOR_DYNAMIC:
708             nValue = ResultSetType::SCROLL_SENSITIVE;
709             break;
710     }
711 
712     return nValue;
713 }
714 //------------------------------------------------------------------------------
getFetchDirection() const715 sal_Int32 OStatement_Base::getFetchDirection() const
716 {
717     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
718     SQLULEN nValue = 0;
719     SQLRETURN nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_SCROLLABLE,&nValue,SQL_IS_UINTEGER,0);
720     OSL_UNUSED( nRetCode );
721 
722     switch(nValue)
723     {
724         case SQL_SCROLLABLE:
725             nValue = FetchDirection::REVERSE;
726             break;
727         default:
728             nValue = FetchDirection::FORWARD;
729             break;
730     }
731 
732     return nValue;
733 }
734 //------------------------------------------------------------------------------
getFetchSize() const735 sal_Int32 OStatement_Base::getFetchSize() const
736 {
737     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
738     SQLULEN nValue;
739     SQLRETURN nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE,&nValue,SQL_IS_UINTEGER,0);
740     OSL_UNUSED( nRetCode );
741     return nValue;
742 }
743 //------------------------------------------------------------------------------
getMaxFieldSize() const744 sal_Int32 OStatement_Base::getMaxFieldSize() const
745 {
746     return getStmtOption(SQL_ATTR_MAX_LENGTH);
747 }
748 //------------------------------------------------------------------------------
getCursorName() const749 ::rtl::OUString OStatement_Base::getCursorName() const
750 {
751     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
752     SQLCHAR pName[258];
753     SQLSMALLINT nRealLen = 0;
754     SQLRETURN nRetCode = N3SQLGetCursorName(m_aStatementHandle,(SQLCHAR*)pName,256,&nRealLen);
755     OSL_UNUSED( nRetCode );
756     return ::rtl::OUString::createFromAscii((const char*)pName);
757 }
758 //------------------------------------------------------------------------------
setQueryTimeOut(sal_Int32 seconds)759 void OStatement_Base::setQueryTimeOut(sal_Int32 seconds)
760 {
761     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
762     SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_QUERY_TIMEOUT,(SQLPOINTER)seconds,SQL_IS_UINTEGER);
763     OSL_UNUSED( nRetCode );
764 }
765 //------------------------------------------------------------------------------
setMaxRows(sal_Int32 _par0)766 void OStatement_Base::setMaxRows(sal_Int32 _par0)
767 {
768     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
769     SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_MAX_ROWS, (SQLPOINTER)_par0,SQL_IS_UINTEGER);
770     OSL_UNUSED( nRetCode );
771 }
772 //------------------------------------------------------------------------------
setResultSetConcurrency(sal_Int32 _par0)773 void OStatement_Base::setResultSetConcurrency(sal_Int32 _par0)
774 {
775     SQLUINTEGER nSet;
776     if(_par0 == ResultSetConcurrency::READ_ONLY)
777         nSet = SQL_CONCUR_READ_ONLY;
778     else
779         nSet = SQL_CONCUR_VALUES;
780 
781     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
782     N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CONCURRENCY,(SQLPOINTER)nSet,SQL_IS_UINTEGER);
783 
784 }
785 //------------------------------------------------------------------------------
setResultSetType(sal_Int32 _par0)786 void OStatement_Base::setResultSetType(sal_Int32 _par0)
787 {
788 
789     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
790     SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_ROW_BIND_TYPE,(SQLPOINTER)SQL_BIND_BY_COLUMN,SQL_IS_UINTEGER);
791     OSL_UNUSED( nRetCode );
792 
793     sal_Bool bUseBookmark = isUsingBookmarks();
794     SQLUINTEGER nSet( SQL_UNSPECIFIED );
795     switch(_par0)
796     {
797         case ResultSetType::FORWARD_ONLY:
798             nSet =  SQL_UNSPECIFIED;
799             break;
800         case ResultSetType::SCROLL_INSENSITIVE:
801             nSet =  SQL_INSENSITIVE;
802             N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CURSOR_TYPE,(SQLPOINTER)SQL_CURSOR_KEYSET_DRIVEN,SQL_IS_UINTEGER);
803             break;
804         case ResultSetType::SCROLL_SENSITIVE:
805             if(bUseBookmark)
806             {
807                 SQLUINTEGER nCurProp = getCursorProperties(SQL_CURSOR_DYNAMIC,sal_True);
808                 if((nCurProp & SQL_CA1_BOOKMARK) != SQL_CA1_BOOKMARK) // check if bookmark for this type isn't supported
809                 { // we have to test the next one
810                     nCurProp = getCursorProperties(SQL_CURSOR_KEYSET_DRIVEN,sal_True);
811                     sal_Bool bNotBookmarks = ((nCurProp & SQL_CA1_BOOKMARK) != SQL_CA1_BOOKMARK);
812                     nCurProp = getCursorProperties(SQL_CURSOR_KEYSET_DRIVEN,sal_False);
813                     nSet = SQL_CURSOR_KEYSET_DRIVEN;
814                     if( bNotBookmarks ||
815                         ((nCurProp & SQL_CA2_SENSITIVITY_DELETIONS) != SQL_CA2_SENSITIVITY_DELETIONS) ||
816                         ((nCurProp & SQL_CA2_SENSITIVITY_ADDITIONS) != SQL_CA2_SENSITIVITY_ADDITIONS))
817                     {
818                         // bookmarks for keyset isn't supported so reset bookmark setting
819                         setUsingBookmarks(sal_False);
820                         nSet = SQL_CURSOR_DYNAMIC;
821                     }
822                 }
823                 else
824                     nSet = SQL_CURSOR_DYNAMIC;
825             }
826             else
827                 nSet = SQL_CURSOR_DYNAMIC;
828             if(N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CURSOR_TYPE,(SQLPOINTER)nSet,SQL_IS_UINTEGER) != SQL_SUCCESS)
829             {
830                 nSet = SQL_CURSOR_KEYSET_DRIVEN;
831                 N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CURSOR_TYPE,(SQLPOINTER)nSet,SQL_IS_UINTEGER);
832             }
833             nSet =  SQL_SENSITIVE;
834             break;
835         default:
836             OSL_ENSURE( false, "OStatement_Base::setResultSetType: invalid result set type!" );
837             break;
838     }
839 
840 
841     N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CURSOR_SENSITIVITY,(SQLPOINTER)nSet,SQL_IS_UINTEGER);
842 }
843 //------------------------------------------------------------------------------
setEscapeProcessing(const sal_Bool _bEscapeProc)844 void OStatement_Base::setEscapeProcessing( const sal_Bool _bEscapeProc )
845 {
846     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
847     SQLUINTEGER nEscapeProc( _bEscapeProc ? SQL_NOSCAN_OFF : SQL_NOSCAN_ON );
848     SQLRETURN nRetCode = N3SQLSetStmtAttr( m_aStatementHandle, SQL_ATTR_NOSCAN, (SQLPOINTER)nEscapeProc, SQL_IS_UINTEGER );
849     (void)nRetCode;
850 }
851 
852 //------------------------------------------------------------------------------
setFetchDirection(sal_Int32 _par0)853 void OStatement_Base::setFetchDirection(sal_Int32 _par0)
854 {
855     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
856     SQLUINTEGER nCursType = 0;
857     SQLRETURN nRetCode  = SQL_SUCCESS;
858     if(_par0 == FetchDirection::FORWARD)
859     {
860         nCursType = SQL_NONSCROLLABLE;
861         nRetCode = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_SCROLLABLE,(SQLPOINTER)nCursType,SQL_IS_UINTEGER);
862     }
863     else if(_par0 == FetchDirection::REVERSE)
864     {
865         nCursType = SQL_SCROLLABLE;
866         nRetCode = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_SCROLLABLE,(SQLPOINTER)nCursType,SQL_IS_UINTEGER);
867     }
868     OSL_UNUSED( nRetCode );
869 }
870 //------------------------------------------------------------------------------
setFetchSize(sal_Int32 _par0)871 void OStatement_Base::setFetchSize(sal_Int32 _par0)
872 {
873     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
874     OSL_ENSURE(_par0>0,"Illegal fetch size!");
875     if ( _par0 > 0 )
876     {
877 
878         SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE,(SQLPOINTER)_par0,SQL_IS_UINTEGER);
879 
880         delete m_pRowStatusArray;
881         m_pRowStatusArray = new SQLUSMALLINT[_par0];
882         nRetCode = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_STATUS_PTR,m_pRowStatusArray,SQL_IS_POINTER);
883     }
884 }
885 //------------------------------------------------------------------------------
setMaxFieldSize(sal_Int32 _par0)886 void OStatement_Base::setMaxFieldSize(sal_Int32 _par0)
887 {
888     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
889     N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_MAX_LENGTH,(SQLPOINTER)_par0,SQL_IS_UINTEGER);
890 }
891 //------------------------------------------------------------------------------
setCursorName(const::rtl::OUString & _par0)892 void OStatement_Base::setCursorName(const ::rtl::OUString &_par0)
893 {
894     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
895     ::rtl::OString aName(::rtl::OUStringToOString(_par0,getOwnConnection()->getTextEncoding()));
896     N3SQLSetCursorName(m_aStatementHandle,(SDB_ODBC_CHAR*)aName.getStr(),(SQLSMALLINT)aName.getLength());
897 }
898 // -------------------------------------------------------------------------
isUsingBookmarks() const899 sal_Bool OStatement_Base::isUsingBookmarks() const
900 {
901     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
902     SQLULEN nValue = SQL_UB_OFF;
903     SQLRETURN nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_USE_BOOKMARKS,&nValue,SQL_IS_UINTEGER,NULL);
904     OSL_UNUSED( nRetCode );
905     return nValue != SQL_UB_OFF;
906 }
907 // -------------------------------------------------------------------------
getEscapeProcessing() const908 sal_Bool OStatement_Base::getEscapeProcessing() const
909 {
910     OSL_ENSURE( m_aStatementHandle, "StatementHandle is null!" );
911     SQLULEN nValue = SQL_NOSCAN_OFF;
912     SQLRETURN nRetCode = N3SQLGetStmtAttr( m_aStatementHandle, SQL_ATTR_NOSCAN, &nValue, SQL_IS_UINTEGER, NULL );
913     (void)nRetCode;
914     return nValue == SQL_NOSCAN_OFF;
915 }
916 // -------------------------------------------------------------------------
setUsingBookmarks(sal_Bool _bUseBookmark)917 void OStatement_Base::setUsingBookmarks(sal_Bool _bUseBookmark)
918 {
919     OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
920     SQLUINTEGER nValue = _bUseBookmark ? SQL_UB_VARIABLE : SQL_UB_OFF;
921     SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_USE_BOOKMARKS,(SQLPOINTER)nValue,SQL_IS_UINTEGER);
922     OSL_UNUSED( nRetCode );
923 }
924 // -------------------------------------------------------------------------
createArrayHelper() const925 ::cppu::IPropertyArrayHelper* OStatement_Base::createArrayHelper( ) const
926 {
927     Sequence< Property > aProps(10);
928     Property* pProperties = aProps.getArray();
929     sal_Int32 nPos = 0;
930     DECL_PROP0(CURSORNAME,  ::rtl::OUString);
931     DECL_BOOL_PROP0(ESCAPEPROCESSING);
932     DECL_PROP0(FETCHDIRECTION,sal_Int32);
933     DECL_PROP0(FETCHSIZE,   sal_Int32);
934     DECL_PROP0(MAXFIELDSIZE,sal_Int32);
935     DECL_PROP0(MAXROWS,     sal_Int32);
936     DECL_PROP0(QUERYTIMEOUT,sal_Int32);
937     DECL_PROP0(RESULTSETCONCURRENCY,sal_Int32);
938     DECL_PROP0(RESULTSETTYPE,sal_Int32);
939     DECL_BOOL_PROP0(USEBOOKMARKS);
940 
941     return new ::cppu::OPropertyArrayHelper(aProps);
942 }
943 
944 // -------------------------------------------------------------------------
getInfoHelper()945 ::cppu::IPropertyArrayHelper & OStatement_Base::getInfoHelper()
946 {
947     return *const_cast<OStatement_Base*>(this)->getArrayHelper();
948 }
949 // -------------------------------------------------------------------------
convertFastPropertyValue(Any & rConvertedValue,Any & rOldValue,sal_Int32 nHandle,const Any & rValue)950 sal_Bool OStatement_Base::convertFastPropertyValue(
951                             Any & rConvertedValue,
952                             Any & rOldValue,
953                             sal_Int32 nHandle,
954                             const Any& rValue )
955 {
956     sal_Bool bConverted = sal_False;
957     try
958     {
959         switch(nHandle)
960         {
961             case PROPERTY_ID_QUERYTIMEOUT:
962                 bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getQueryTimeOut());
963                 break;
964 
965             case PROPERTY_ID_MAXFIELDSIZE:
966                 bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxFieldSize());
967                 break;
968 
969             case PROPERTY_ID_MAXROWS:
970                 bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxRows());
971                 break;
972 
973             case PROPERTY_ID_CURSORNAME:
974                 bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getCursorName());
975                 break;
976 
977             case PROPERTY_ID_RESULTSETCONCURRENCY:
978                 bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetConcurrency());
979                 break;
980 
981             case PROPERTY_ID_RESULTSETTYPE:
982                 bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetType());
983                 break;
984 
985             case PROPERTY_ID_FETCHDIRECTION:
986                 bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection());
987                 break;
988 
989             case PROPERTY_ID_FETCHSIZE:
990                 bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize());
991                 break;
992 
993             case PROPERTY_ID_USEBOOKMARKS:
994                 bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, isUsingBookmarks());
995                 break;
996 
997             case PROPERTY_ID_ESCAPEPROCESSING:
998                 bConverted = ::comphelper::tryPropertyValue( rConvertedValue, rOldValue, rValue, getEscapeProcessing() );
999                 break;
1000 
1001         }
1002     }
1003     catch(const SQLException&)
1004     {
1005         //  throw Exception(e.Message,*this);
1006     }
1007     return bConverted;
1008 }
1009 // -------------------------------------------------------------------------
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any & rValue)1010 void OStatement_Base::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)
1011 {
1012     try
1013     {
1014         switch(nHandle)
1015         {
1016             case PROPERTY_ID_QUERYTIMEOUT:
1017                 setQueryTimeOut(comphelper::getINT32(rValue));
1018                 break;
1019             case PROPERTY_ID_MAXFIELDSIZE:
1020                 setMaxFieldSize(comphelper::getINT32(rValue));
1021                 break;
1022             case PROPERTY_ID_MAXROWS:
1023                 setMaxRows(comphelper::getINT32(rValue));
1024                 break;
1025             case PROPERTY_ID_CURSORNAME:
1026                 setCursorName(comphelper::getString(rValue));
1027                 break;
1028             case PROPERTY_ID_RESULTSETCONCURRENCY:
1029                 setResultSetConcurrency(comphelper::getINT32(rValue));
1030                 break;
1031             case PROPERTY_ID_RESULTSETTYPE:
1032                 setResultSetType(comphelper::getINT32(rValue));
1033                 break;
1034             case PROPERTY_ID_FETCHDIRECTION:
1035                 setFetchDirection(comphelper::getINT32(rValue));
1036                 break;
1037             case PROPERTY_ID_FETCHSIZE:
1038                 setFetchSize(comphelper::getINT32(rValue));
1039                 break;
1040             case PROPERTY_ID_USEBOOKMARKS:
1041                 setUsingBookmarks(comphelper::getBOOL(rValue));
1042                 break;
1043             case PROPERTY_ID_ESCAPEPROCESSING:
1044                 setEscapeProcessing( ::comphelper::getBOOL( rValue ) );
1045                 break;
1046             default:
1047                 OSL_ENSURE( false, "OStatement_Base::setFastPropertyValue_NoBroadcast: what property?" );
1048                 break;
1049         }
1050     }
1051     catch(const SQLException& )
1052     {
1053         //  throw Exception(e.Message,*this);
1054     }
1055 }
1056 // -------------------------------------------------------------------------
getFastPropertyValue(Any & rValue,sal_Int32 nHandle) const1057 void OStatement_Base::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const
1058 {
1059     switch(nHandle)
1060     {
1061         case PROPERTY_ID_QUERYTIMEOUT:
1062             rValue <<= getQueryTimeOut();
1063             break;
1064         case PROPERTY_ID_MAXFIELDSIZE:
1065             rValue <<= getMaxFieldSize();
1066             break;
1067         case PROPERTY_ID_MAXROWS:
1068             rValue <<= getMaxRows();
1069             break;
1070         case PROPERTY_ID_CURSORNAME:
1071             rValue <<= getCursorName();
1072             break;
1073         case PROPERTY_ID_RESULTSETCONCURRENCY:
1074             rValue <<= getResultSetConcurrency();
1075             break;
1076         case PROPERTY_ID_RESULTSETTYPE:
1077             rValue <<= getResultSetType();
1078             break;
1079         case PROPERTY_ID_FETCHDIRECTION:
1080             rValue <<= getFetchDirection();
1081             break;
1082         case PROPERTY_ID_FETCHSIZE:
1083             rValue <<= getFetchSize();
1084             break;
1085         case PROPERTY_ID_USEBOOKMARKS:
1086             rValue <<= isUsingBookmarks();
1087             break;
1088         case PROPERTY_ID_ESCAPEPROCESSING:
1089             rValue <<= getEscapeProcessing();
1090             break;
1091         default:
1092             OSL_ENSURE( false, "OStatement_Base::getFastPropertyValue: what property?" );
1093             break;
1094     }
1095 }
1096 // -------------------------------------------------------------------------
1097 IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbcx.OStatement","com.sun.star.sdbc.Statement");
1098 // -----------------------------------------------------------------------------
acquire()1099 void SAL_CALL OStatement_Base::acquire() throw()
1100 {
1101     OStatement_BASE::acquire();
1102 }
1103 // -----------------------------------------------------------------------------
release()1104 void SAL_CALL OStatement_Base::release() throw()
1105 {
1106     OStatement_BASE::release();
1107 }
1108 // -----------------------------------------------------------------------------
acquire()1109 void SAL_CALL OStatement::acquire() throw()
1110 {
1111     OStatement_BASE2::acquire();
1112 }
1113 // -----------------------------------------------------------------------------
release()1114 void SAL_CALL OStatement::release() throw()
1115 {
1116     OStatement_BASE2::release();
1117 }
1118 // -----------------------------------------------------------------------------
createResulSet()1119 OResultSet* OStatement_Base::createResulSet()
1120 {
1121     return new OResultSet(m_aStatementHandle,this);
1122 }
1123 // -----------------------------------------------------------------------------
getPropertySetInfo()1124 Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OStatement_Base::getPropertySetInfo(  )
1125 {
1126     return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
1127 }
1128 // -----------------------------------------------------------------------------
getCursorProperties(SQLINTEGER _nCursorType,sal_Bool bFirst)1129 SQLUINTEGER OStatement_Base::getCursorProperties(SQLINTEGER _nCursorType,sal_Bool bFirst)
1130 {
1131     SQLUINTEGER nValueLen = 0;
1132     try
1133     {
1134         SQLUSMALLINT nAskFor = SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2;
1135         if(SQL_CURSOR_KEYSET_DRIVEN == _nCursorType)
1136             nAskFor = bFirst ? SQL_KEYSET_CURSOR_ATTRIBUTES1 : SQL_KEYSET_CURSOR_ATTRIBUTES2;
1137         else if(SQL_CURSOR_STATIC  == _nCursorType)
1138             nAskFor = bFirst ? SQL_STATIC_CURSOR_ATTRIBUTES1 : SQL_STATIC_CURSOR_ATTRIBUTES2;
1139         else if(SQL_CURSOR_FORWARD_ONLY == _nCursorType)
1140             nAskFor = bFirst ? SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES1 : SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2;
1141         else if(SQL_CURSOR_DYNAMIC == _nCursorType)
1142             nAskFor = bFirst ? SQL_DYNAMIC_CURSOR_ATTRIBUTES1 : SQL_DYNAMIC_CURSOR_ATTRIBUTES2;
1143 
1144 
1145         OTools::GetInfo(getOwnConnection(),getConnectionHandle(),nAskFor,nValueLen,NULL);
1146     }
1147     catch(Exception&)
1148     { // we don't want our result destroy here
1149         nValueLen = 0;
1150     }
1151     return nValueLen;
1152 }
1153 // -----------------------------------------------------------------------------
1154