1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: KeySet.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef DBACCESS_CORE_API_KEYSET_HXX
37 #ifndef _DBA_CORE_RESOURCE_HXX_
38 #include "core_resource.hxx"
40 #ifndef _DBA_CORE_RESOURCE_HRC_
41 #include "core_resource.hrc"
43 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
44 #include <com/sun/star/beans/XPropertySet.hpp>
46 #ifndef _COM_SUN_STAR_SDBC_XDATABASEMETADATA_HPP_
47 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
49 #include <com/sun/star/sdbc/ColumnValue.hpp>
50 #ifndef _COM_SUN_STAR_SDBC_XPREPAREDSTATEMENT_HPP_
51 #include <com/sun/star/sdbc/XPreparedStatement.hpp>
53 #ifndef _COM_SUN_STAR_SDBCxParameterS_HPP_
54 #include <com/sun/star/sdbc/XParameters.hpp>
56 #ifndef _COM_SUN_STAR_SDBC_XGENERATEDRESULTSET_HPP_
57 #include <com/sun/star/sdbc/XGeneratedResultSet.hpp>
59 #ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYCOMPOSER_HPP_
60 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
62 #ifndef _COM_SUN_STAR_SDBC_XCOLUMNLOCATE_HPP_
63 #include <com/sun/star/sdbc/XColumnLocate.hpp>
65 #ifndef _COM_SUN_STAR_CONTAINER_XINDEXACCESS_HPP_
66 #include <com/sun/star/container/XIndexAccess.hpp>
68 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
69 #include "dbastrings.hrc"
71 #ifndef _DBASHARED_APITOOLS_HXX_
72 #include "apitools.hxx"
74 #ifndef _COM_SUN_STAR_SDBCX_XKEYSSUPPLIER_HPP_
75 #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
77 #ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYCOMPOSER_HPP_
78 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
80 #ifndef _COM_SUN_STAR_SDBCX_XINDEXESSUPPLIER_HPP_
81 #include <com/sun/star/sdbcx/XIndexesSupplier.hpp>
83 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
84 #include <cppuhelper/typeprovider.hxx>
86 #ifndef _COMPHELPER_TYPES_HXX_
87 #include <comphelper/types.hxx>
89 #ifndef _COM_SUN_STAR_SDBCX_KEYTYPE_HPP_
90 #include <com/sun/star/sdbcx/KeyType.hpp>
92 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
93 #include <connectivity/dbtools.hxx>
95 #ifndef _DBHELPER_DBEXCEPTION_HXX_
96 #include <connectivity/dbexception.hxx>
101 #ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_
102 #include <com/sun/star/io/XInputStream.hpp>
104 #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
105 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
107 #ifndef DBACCESS_CORE_API_QUERYCOMPOSER_HXX
108 #include "querycomposer.hxx"
110 #ifndef DBACCESS_SOURCE_CORE_INC_COMPOSERTOOLS_HXX
111 #include "composertools.hxx"
113 #ifndef _TOOLS_DEBUG_HXX
114 #include <tools/debug.hxx>
117 #include <rtl/logfile.hxx>
119 using namespace dbaccess
;
120 using namespace ::connectivity
;
121 using namespace ::dbtools
;
122 using namespace ::com::sun::star::uno
;
123 using namespace ::com::sun::star::beans
;
124 using namespace ::com::sun::star::sdbc
;
125 using namespace ::com::sun::star::sdb
;
126 using namespace ::com::sun::star::sdbcx
;
127 using namespace ::com::sun::star::container
;
128 using namespace ::com::sun::star::lang
;
129 using namespace ::com::sun::star::util
;
130 using namespace ::com::sun::star::io
;
131 using namespace ::com::sun::star
;
132 using namespace ::cppu
;
133 using namespace ::osl
;
137 void lcl_fillIndexColumns(const Reference
<XIndexAccess
>& _xIndexes
, ::std::vector
< Reference
<XNameAccess
> >& _rAllIndexColumns
)
139 if ( _xIndexes
.is() )
141 Reference
<XPropertySet
> xIndexColsSup
;
142 sal_Int32 nCount
= _xIndexes
->getCount();
143 for(sal_Int32 j
= 0 ; j
< nCount
; ++j
)
145 xIndexColsSup
.set(_xIndexes
->getByIndex(j
),UNO_QUERY
);
146 if( xIndexColsSup
.is()
147 && comphelper::getBOOL(xIndexColsSup
->getPropertyValue(PROPERTY_ISUNIQUE
))
148 && !comphelper::getBOOL(xIndexColsSup
->getPropertyValue(PROPERTY_ISPRIMARYKEYINDEX
))
150 _rAllIndexColumns
.push_back(Reference
<XColumnsSupplier
>(xIndexColsSup
,UNO_QUERY
)->getColumns());
156 // -------------------------------------------------------------------------
157 OKeySet::OKeySet(const connectivity::OSQLTable
& _xTable
,
158 const Reference
< XIndexAccess
>& _xTableKeys
,
159 const ::rtl::OUString
& _rUpdateTableName
, // this can be the alias or the full qualified name
160 const Reference
< XSingleSelectQueryAnalyzer
>& _xComposer
,
161 const ORowSetValueVector
& _aParameterValueForCache
)
162 :m_aParameterValueForCache(_aParameterValueForCache
)
163 ,m_pKeyColumnNames(NULL
)
164 ,m_pColumnNames(NULL
)
165 ,m_pForeignColumnNames(NULL
)
167 ,m_xTableKeys(_xTableKeys
)
168 ,m_xComposer(_xComposer
)
169 ,m_sUpdateTableName(_rUpdateTableName
)
170 ,m_bRowCountFinal(sal_False
)
172 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::OKeySet" );
173 DBG_CTOR(OKeySet
,NULL
);
176 // -----------------------------------------------------------------------------
181 ::comphelper::disposeComponent(m_xStatement
);
189 OSL_ENSURE(0,"Unknown Exception occured");
192 delete m_pKeyColumnNames
;
193 delete m_pColumnNames
;
194 delete m_pForeignColumnNames
;
196 DBG_DTOR(OKeySet
,NULL
);
198 // -----------------------------------------------------------------------------
199 void OKeySet::construct(const Reference
< XResultSet
>& _xDriverSet
)
201 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::construct" );
202 OCacheSet::construct(_xDriverSet
);
204 Reference
<XDatabaseMetaData
> xMeta
= m_xConnection
->getMetaData();
205 bool bCase
= (xMeta
.is() && xMeta
->storesMixedCaseQuotedIdentifiers()) ? true : false;
206 m_pKeyColumnNames
= new SelectColumnsMetaData(bCase
);
207 m_pColumnNames
= new SelectColumnsMetaData(bCase
);
208 m_pForeignColumnNames
= new SelectColumnsMetaData(bCase
);
210 Reference
<XNameAccess
> xKeyColumns
= getKeyColumns();
211 Reference
<XColumnsSupplier
> xSup(m_xComposer
,UNO_QUERY
);
212 Reference
<XNameAccess
> xSourceColumns
= m_xTable
->getColumns();
214 ::dbaccess::getColumnPositions(xSup
->getColumns(),xKeyColumns
,m_sUpdateTableName
,(*m_pKeyColumnNames
));
215 ::dbaccess::getColumnPositions(xSup
->getColumns(),xSourceColumns
,m_sUpdateTableName
,(*m_pColumnNames
));
217 SelectColumnsMetaData::const_iterator aPosIter
= (*m_pKeyColumnNames
).begin();
218 SelectColumnsMetaData::const_iterator aPosEnd
= (*m_pKeyColumnNames
).end();
219 for(;aPosIter
!= aPosEnd
;++aPosIter
)
221 if(xSourceColumns
->hasByName(aPosIter
->first
))
223 Reference
<XPropertySet
> xProp(xSourceColumns
->getByName(aPosIter
->first
),UNO_QUERY
);
224 sal_Bool bAuto
= sal_Bool();
225 if( (xProp
->getPropertyValue(PROPERTY_ISAUTOINCREMENT
) >>= bAuto
) && bAuto
)
226 m_aAutoColumns
.push_back(aPosIter
->first
);
230 // the first row is empty because it's now easier for us to distinguish when we are beforefirst or first
231 // without extra varaible to be set
232 m_aKeyMap
.insert(OKeySetMatrix::value_type(0,OKeySetValue(NULL
,0)));
234 m_aKeyIter
= m_aKeyMap
.begin();
236 static ::rtl::OUString aAnd
= ::rtl::OUString::createFromAscii(" AND ");
237 Reference
<XDatabaseMetaData
> xMetaData
= m_xConnection
->getMetaData();
238 ::rtl::OUString aQuote
= getIdentifierQuoteString();
240 ::rtl::OUStringBuffer aFilter
;
241 ::rtl::OUString sCatalog
,sSchema
,sTable
;
243 Reference
<XPropertySet
> xTableProp(m_xTable
,UNO_QUERY
);
244 xTableProp
->getPropertyValue(PROPERTY_CATALOGNAME
) >>= sCatalog
;
245 xTableProp
->getPropertyValue(PROPERTY_SCHEMANAME
) >>= sSchema
;
246 xTableProp
->getPropertyValue(PROPERTY_NAME
) >>= sTable
;
248 m_aSelectComposedTableName
= getComposedTableName(sCatalog
,sSchema
,sTable
);
250 ::rtl::OUString sComposedName
;
251 sCatalog
= sSchema
= sTable
= ::rtl::OUString();
252 ::dbtools::qualifiedNameComponents(xMetaData
,m_sUpdateTableName
,sCatalog
,sSchema
,sTable
,::dbtools::eInDataManipulation
);
253 sComposedName
= ::dbtools::composeTableName( xMetaData
, sCatalog
, sSchema
, sTable
, sal_True
, ::dbtools::eInDataManipulation
);
255 static ::rtl::OUString
s_sDot(RTL_CONSTASCII_USTRINGPARAM("."));
256 static ::rtl::OUString
s_sParam(RTL_CONSTASCII_USTRINGPARAM(" = ?"));
257 // create the where clause
258 aPosEnd
= (*m_pKeyColumnNames
).end();
259 for(aPosIter
= (*m_pKeyColumnNames
).begin();aPosIter
!= aPosEnd
;)
261 aFilter
.append(sComposedName
);
262 aFilter
.append(s_sDot
);
263 aFilter
.append(::dbtools::quoteName( aQuote
,aPosIter
->first
));
264 aFilter
.append(s_sParam
);
266 if(aPosIter
!= aPosEnd
)
267 aFilter
.append(aAnd
);
270 Reference
< XMultiServiceFactory
> xFactory(m_xConnection
, UNO_QUERY_THROW
);
271 Reference
<XSingleSelectQueryComposer
> xAnalyzer(xFactory
->createInstance(SERVICE_NAME_SINGLESELECTQUERYCOMPOSER
),UNO_QUERY
);
272 xAnalyzer
->setQuery(m_xComposer
->getQuery());
273 Reference
<XTablesSupplier
> xTabSup(xAnalyzer
,uno::UNO_QUERY
);
274 Reference
<XNameAccess
> xSelectTables(xTabSup
->getTables(),uno::UNO_QUERY
);
275 const Sequence
< ::rtl::OUString
> aSeq
= xSelectTables
->getElementNames();
276 if ( aSeq
.getLength() > 1 ) // special handling for join
278 const ::rtl::OUString
* pIter
= aSeq
.getConstArray();
279 const ::rtl::OUString
* pEnd
= pIter
+ aSeq
.getLength();
280 for(;pIter
!= pEnd
;++pIter
)
282 if ( *pIter
!= m_sUpdateTableName
)
284 connectivity::OSQLTable
xSelColSup(xSelectTables
->getByName(*pIter
),uno::UNO_QUERY
);
285 Reference
<XPropertySet
> xProp(xSelColSup
,uno::UNO_QUERY
);
286 ::rtl::OUString sSelectTableName
= ::dbtools::composeTableName( xMetaData
, xProp
, ::dbtools::eInDataManipulation
, false, false, false );
287 Reference
<XNameAccess
> xSelectColumns
= xSup
->getColumns();
289 ::dbaccess::getColumnPositions(xSelectColumns
,xSelColSup
->getColumns(),sSelectTableName
,(*m_pForeignColumnNames
));
291 uno::Sequence
< ::rtl::OUString
> aSelectColumnNames
= xSelectColumns
->getElementNames();
292 const ::rtl::OUString
* pSelectColumnName
= aSelectColumnNames
.getConstArray();
293 const ::rtl::OUString
* pSelectColumnEnd
= pSelectColumnName
+ aSelectColumnNames
.getLength();
294 for( ; pSelectColumnName
!= pSelectColumnEnd
; ++pSelectColumnName
)
296 // look for columns not in the source columns to use them as filter as well
297 if ( !xSourceColumns
->hasByName(*pSelectColumnName
) )
299 aFilter
.append(s_sDot
);
300 aFilter
.append(::dbtools::quoteName( aQuote
,*pSelectColumnName
));
301 aFilter
.append(s_sParam
);
302 if ( (pSelectColumnName
+1) != pSelectColumnEnd
)
303 aFilter
.append(aAnd
);
309 } // if ( aSeq.getLength() > 1 ) // special handling for join
310 const ::rtl::OUString sOldFilter
= xAnalyzer
->getFilter();
311 if ( sOldFilter
.getLength() )
313 aFilter
= sOldFilter
+ aAnd
+ aFilter
.makeStringAndClear();
315 xAnalyzer
->setFilter(aFilter
.makeStringAndClear());
316 m_xStatement
= m_xConnection
->prepareStatement(xAnalyzer
->getQueryWithSubstitution());
317 ::comphelper::disposeComponent(xAnalyzer
);
319 // -------------------------------------------------------------------------
320 Any SAL_CALL
OKeySet::getBookmark() throw(SQLException
, RuntimeException
)
322 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getBookmark" );
323 OSL_ENSURE(m_aKeyIter
!= m_aKeyMap
.end() && m_aKeyIter
!= m_aKeyMap
.begin(),
324 "getBookmark is only possible when we stand on a valid row!");
325 return makeAny(m_aKeyIter
->first
);
328 // -------------------------------------------------------------------------
329 sal_Bool SAL_CALL
OKeySet::moveToBookmark( const Any
& bookmark
) throw(SQLException
, RuntimeException
)
331 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::moveToBookmark" );
332 m_bInserted
= m_bUpdated
= m_bDeleted
= sal_False
;
333 m_aKeyIter
= m_aKeyMap
.find(::comphelper::getINT32(bookmark
));
334 return m_aKeyIter
!= m_aKeyMap
.end();
336 // -------------------------------------------------------------------------
337 sal_Bool SAL_CALL
OKeySet::moveRelativeToBookmark( const Any
& bookmark
, sal_Int32 rows
) throw(SQLException
, RuntimeException
)
339 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::moveRelativeToBookmark" );
340 m_bInserted
= m_bUpdated
= m_bDeleted
= sal_False
;
341 m_aKeyIter
= m_aKeyMap
.find(::comphelper::getINT32(bookmark
));
342 if(m_aKeyIter
!= m_aKeyMap
.end())
347 return !isBeforeFirst() && !isAfterLast();
349 // -------------------------------------------------------------------------
350 sal_Int32 SAL_CALL
OKeySet::compareBookmarks( const Any
& _first
, const Any
& _second
) throw(SQLException
, RuntimeException
)
352 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::compareBookmarks" );
353 sal_Int32 nFirst
= 0, nSecond
= 0;
357 return (nFirst
!= nSecond
) ? CompareBookmark::NOT_EQUAL
: CompareBookmark::EQUAL
;
359 // -------------------------------------------------------------------------
360 sal_Bool SAL_CALL
OKeySet::hasOrderedBookmarks( ) throw(SQLException
, RuntimeException
)
362 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::hasOrderedBookmarks" );
365 // -------------------------------------------------------------------------
366 sal_Int32 SAL_CALL
OKeySet::hashBookmark( const Any
& bookmark
) throw(SQLException
, RuntimeException
)
368 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::hashBookmark" );
369 return ::comphelper::getINT32(bookmark
);
371 // -------------------------------------------------------------------------
372 // ::com::sun::star::sdbcx::XDeleteRows
373 Sequence
< sal_Int32
> SAL_CALL
OKeySet::deleteRows( const Sequence
< Any
>& rows
,const connectivity::OSQLTable
& _xTable
) throw(SQLException
, RuntimeException
)
375 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::deleteRows" );
376 Reference
<XPropertySet
> xSet(_xTable
,UNO_QUERY
);
379 ::rtl::OUStringBuffer aSql
= ::rtl::OUString::createFromAscii("DELETE FROM ");
380 aSql
.append(m_aComposedTableName
);
381 aSql
.append(::rtl::OUString::createFromAscii(" WHERE "));
383 // list all cloumns that should be set
384 const ::rtl::OUString aQuote
= getIdentifierQuoteString();
385 static ::rtl::OUString aAnd
= ::rtl::OUString::createFromAscii(" AND ");
386 static ::rtl::OUString aOr
= ::rtl::OUString::createFromAscii(" OR ");
387 static ::rtl::OUString aEqual
= ::rtl::OUString::createFromAscii(" = ?");
390 // use keys and indexes for excat postioning
392 Reference
<XNameAccess
> xKeyColumns
= getKeyColumns();
394 ::rtl::OUStringBuffer aCondition
= ::rtl::OUString::createFromAscii("( ");
396 SelectColumnsMetaData::const_iterator aIter
= (*m_pKeyColumnNames
).begin();
397 SelectColumnsMetaData::const_iterator aPosEnd
= (*m_pKeyColumnNames
).end();
398 for(;aIter
!= aPosEnd
;++aIter
)
400 aCondition
.append(::dbtools::quoteName( aQuote
,aIter
->first
));
401 aCondition
.append(aEqual
);
402 aCondition
.append(aAnd
);
404 aCondition
.setLength(aCondition
.getLength()-5);
405 const ::rtl::OUString
sCon( aCondition
.makeStringAndClear() );
407 const Any
* pBegin
= rows
.getConstArray();
408 const Any
* pEnd
= pBegin
+ rows
.getLength();
410 Sequence
< Any
> aKeys
;
411 for(;pBegin
!= pEnd
;++pBegin
)
416 aSql
.setLength(aSql
.getLength()-3);
418 // now create end execute the prepared statement
420 Reference
< XPreparedStatement
> xPrep(m_xConnection
->prepareStatement(aSql
.makeStringAndClear()));
421 Reference
< XParameters
> xParameter(xPrep
,UNO_QUERY
);
423 pBegin
= rows
.getConstArray();
425 for(;pBegin
!= pEnd
;++pBegin
)
427 m_aKeyIter
= m_aKeyMap
.find(::comphelper::getINT32(*pBegin
));
428 if(m_aKeyIter
!= m_aKeyMap
.end())
430 connectivity::ORowVector
< ORowSetValue
>::Vector::iterator aKeyIter
= m_aKeyIter
->second
.first
->get().begin();
431 connectivity::ORowVector
< ORowSetValue
>::Vector::iterator aKeyEnd
= m_aKeyIter
->second
.first
->get().end();
432 SelectColumnsMetaData::const_iterator aPosIter
= (*m_pKeyColumnNames
).begin();
433 for(sal_uInt16 j
= 0;aKeyIter
!= aKeyEnd
;++aKeyIter
,++j
,++aPosIter
)
435 setParameter(i
++,xParameter
,*aKeyIter
,aPosIter
->second
.nType
,aPosIter
->second
.nScale
);
440 sal_Bool bOk
= xPrep
->executeUpdate() > 0;
441 Sequence
< sal_Int32
> aRet(rows
.getLength());
442 memset(aRet
.getArray(),bOk
,sizeof(sal_Int32
)*aRet
.getLength());
445 pBegin
= rows
.getConstArray();
446 pEnd
= pBegin
+ rows
.getLength();
448 for(;pBegin
!= pEnd
;++pBegin
)
452 if(m_aKeyIter
== m_aKeyMap
.find(nPos
) && m_aKeyIter
!= m_aKeyMap
.end())
454 m_aKeyMap
.erase(nPos
);
455 m_bDeleted
= sal_True
;
460 // -------------------------------------------------------------------------
461 void SAL_CALL
OKeySet::updateRow(const ORowSetRow
& _rInsertRow
,const ORowSetRow
& _rOrginalRow
,const connectivity::OSQLTable
& _xTable
) throw(SQLException
, RuntimeException
)
463 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::updateRow" );
464 Reference
<XPropertySet
> xSet(_xTable
,UNO_QUERY
);
467 ::rtl::OUStringBuffer aSql
= ::rtl::OUString::createFromAscii("UPDATE ");
468 aSql
.append(m_aComposedTableName
);
469 aSql
.append(::rtl::OUString::createFromAscii(" SET "));
470 // list all cloumns that should be set
471 static ::rtl::OUString aPara
= ::rtl::OUString::createFromAscii(" = ?,");
472 ::rtl::OUString aQuote
= getIdentifierQuoteString();
473 static ::rtl::OUString aAnd
= ::rtl::OUString::createFromAscii(" AND ");
474 ::rtl::OUString
sIsNull(RTL_CONSTASCII_USTRINGPARAM(" IS NULL"));
475 ::rtl::OUString
sParam(RTL_CONSTASCII_USTRINGPARAM(" = ?"));
477 // use keys and indexes for excat postioning
479 Reference
<XNameAccess
> xKeyColumns
= getKeyColumns();
481 // second the indexes
482 Reference
<XIndexesSupplier
> xIndexSup(_xTable
,UNO_QUERY
);
483 Reference
<XIndexAccess
> xIndexes
;
484 if ( xIndexSup
.is() )
485 xIndexes
.set(xIndexSup
->getIndexes(),UNO_QUERY
);
488 ::std::vector
< Reference
<XNameAccess
> > aAllIndexColumns
;
489 lcl_fillIndexColumns(xIndexes
,aAllIndexColumns
);
491 ::rtl::OUString aColumnName
;
492 ::rtl::OUStringBuffer sKeyCondition
,sIndexCondition
;
493 ::std::vector
<sal_Int32
> aIndexColumnPositions
;
495 const sal_Int32 nOldLength
= aSql
.getLength();
497 // here we build the condition part for the update statement
498 SelectColumnsMetaData::const_iterator aIter
= m_pColumnNames
->begin();
499 SelectColumnsMetaData::const_iterator aEnd
= m_pColumnNames
->end();
500 for(;aIter
!= aEnd
;++aIter
,++i
)
502 if(xKeyColumns
.is() && xKeyColumns
->hasByName(aIter
->first
))
504 sKeyCondition
.append(::dbtools::quoteName( aQuote
,aIter
->first
));
505 if((_rOrginalRow
->get())[aIter
->second
.nPosition
].isNull())
506 sKeyCondition
.append(sIsNull
);
508 sKeyCondition
.append(sParam
);
509 sKeyCondition
.append(aAnd
);
513 ::std::vector
< Reference
<XNameAccess
> >::const_iterator aIndexEnd
= aAllIndexColumns
.end();
514 for( ::std::vector
< Reference
<XNameAccess
> >::const_iterator aIndexIter
= aAllIndexColumns
.begin();
515 aIndexIter
!= aIndexEnd
;++aIndexIter
)
517 if((*aIndexIter
)->hasByName(aIter
->first
))
519 sIndexCondition
.append(::dbtools::quoteName( aQuote
,aIter
->first
));
520 if((_rOrginalRow
->get())[aIter
->second
.nPosition
].isNull())
521 sIndexCondition
.append(sIsNull
);
524 sIndexCondition
.append(sParam
);
525 aIndexColumnPositions
.push_back(aIter
->second
.nPosition
);
527 sIndexCondition
.append(aAnd
);
532 if((_rInsertRow
->get())[aIter
->second
.nPosition
].isModified())
534 aSql
.append(::dbtools::quoteName( aQuote
,aIter
->first
));
539 if( aSql
.getLength() != nOldLength
)
541 aSql
.setLength(aSql
.getLength()-1);
544 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_VALUE_CHANGED
), SQL_GENERAL_ERROR
, m_xConnection
);
546 if(sKeyCondition
.getLength() || sIndexCondition
.getLength())
548 aSql
.append(::rtl::OUString::createFromAscii(" WHERE "));
549 if(sKeyCondition
.getLength() && sIndexCondition
.getLength())
551 aSql
.append(sKeyCondition
.makeStringAndClear());
552 aSql
.append(sIndexCondition
.makeStringAndClear());
554 else if(sKeyCondition
.getLength())
556 aSql
.append(sKeyCondition
.makeStringAndClear());
558 else if(sIndexCondition
.getLength())
560 aSql
.append(sIndexCondition
.makeStringAndClear());
562 aSql
.setLength(aSql
.getLength()-5); // remove the last AND
565 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_CONDITION_FOR_PK
), SQL_GENERAL_ERROR
, m_xConnection
);
567 // now create end execute the prepared statement
568 Reference
< XPreparedStatement
> xPrep(m_xConnection
->prepareStatement(aSql
.makeStringAndClear()));
569 Reference
< XParameters
> xParameter(xPrep
,UNO_QUERY
);
572 // first the set values
573 aIter
= m_pColumnNames
->begin();
575 for(;aIter
!= aEnd
;++aIter
,++j
)
577 sal_Int32 nPos
= aIter
->second
.nPosition
;
578 if((_rInsertRow
->get())[nPos
].isModified())
580 (_rInsertRow
->get())[nPos
].setSigned((_rOrginalRow
->get())[nPos
].isSigned());
581 setParameter(i
++,xParameter
,(_rInsertRow
->get())[nPos
],aIter
->second
.nType
,aIter
->second
.nScale
);
584 // and then the values of the where condition
585 aIter
= (*m_pKeyColumnNames
).begin();
586 aEnd
= (*m_pKeyColumnNames
).end();
588 for(;aIter
!= aEnd
;++aIter
,++i
,++j
)
590 setParameter(i
,xParameter
,(_rOrginalRow
->get())[aIter
->second
.nPosition
],aIter
->second
.nType
,aIter
->second
.nScale
);
593 // now we have to set the index values
594 ::std::vector
<sal_Int32
>::iterator aIdxColIter
= aIndexColumnPositions
.begin();
595 ::std::vector
<sal_Int32
>::iterator aIdxColEnd
= aIndexColumnPositions
.end();
597 for(;aIdxColIter
!= aIdxColEnd
;++aIdxColIter
,++i
,++j
)
599 setParameter(i
,xParameter
,(_rOrginalRow
->get())[*aIdxColIter
],(_rOrginalRow
->get())[*aIdxColIter
].getTypeKind(),aIter
->second
.nScale
);
602 m_bUpdated
= xPrep
->executeUpdate() > 0;
607 m_aKeyIter
= m_aKeyMap
.find(::comphelper::getINT32((_rInsertRow
->get())[0].getAny()));
608 OSL_ENSURE(m_aKeyIter
!= m_aKeyMap
.end(),"New inserted row not found!");
609 m_aKeyIter
->second
.second
= 2;
610 copyRowValue(_rInsertRow
,m_aKeyIter
->second
.first
);
613 // -------------------------------------------------------------------------
614 void SAL_CALL
OKeySet::insertRow( const ORowSetRow
& _rInsertRow
,const connectivity::OSQLTable
& _xTable
) throw(SQLException
, RuntimeException
)
616 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::insertRow" );
617 ::rtl::OUStringBuffer
aSql(::rtl::OUString::createFromAscii("INSERT INTO "));
618 Reference
<XPropertySet
> xSet(_xTable
,UNO_QUERY
);
621 aSql
.append(m_aComposedTableName
);
622 aSql
.append(::rtl::OUString::createFromAscii(" ( "));
623 // set values and column names
624 ::rtl::OUStringBuffer
aValues(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" VALUES ( ")));
625 static ::rtl::OUString
aPara(RTL_CONSTASCII_USTRINGPARAM("?,"));
626 ::rtl::OUString aQuote
= getIdentifierQuoteString();
627 static ::rtl::OUString
aComma(RTL_CONSTASCII_USTRINGPARAM(","));
629 SelectColumnsMetaData::const_iterator aIter
= m_pColumnNames
->begin();
630 SelectColumnsMetaData::const_iterator aEnd
= m_pColumnNames
->end();
632 sal_Bool bModified
= sal_False
;
633 for(;aIter
!= aEnd
;++aIter
,++j
)
635 if((_rInsertRow
->get())[aIter
->second
.nPosition
].isModified())
637 aSql
.append(::dbtools::quoteName( aQuote
,aIter
->first
));
639 aValues
.append(aPara
);
640 bModified
= sal_True
;
644 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_VALUE_CHANGED
), SQL_GENERAL_ERROR
, m_xConnection
);
646 aSql
.setCharAt(aSql
.getLength()-1,')');
647 aValues
.setCharAt(aValues
.getLength()-1,')');
648 aSql
.append(aValues
.makeStringAndClear());
649 // now create,fill and execute the prepared statement
650 Reference
< XPreparedStatement
> xPrep(m_xConnection
->prepareStatement(aSql
.makeStringAndClear()));
651 Reference
< XParameters
> xParameter(xPrep
,UNO_QUERY
);
653 aIter
= m_pColumnNames
->begin();
654 for(sal_Int32 i
= 1;aIter
!= aEnd
;++aIter
)
656 const sal_Int32 nPos
= aIter
->second
.nPosition
;
657 if((_rInsertRow
->get())[nPos
].isModified())
659 if((_rInsertRow
->get())[nPos
].isNull())
660 xParameter
->setNull(i
++,(_rInsertRow
->get())[nPos
].getTypeKind());
663 (_rInsertRow
->get())[nPos
].setSigned(m_aSignedFlags
[nPos
-1]);
664 setParameter(i
++,xParameter
,(_rInsertRow
->get())[nPos
],aIter
->second
.nType
,aIter
->second
.nScale
);
669 m_bInserted
= xPrep
->executeUpdate() > 0;
670 sal_Bool bAutoValuesFetched
= sal_False
;
673 // first insert the default values into the insertrow
674 aIter
= m_pColumnNames
->begin();
675 for(;aIter
!= aEnd
;++aIter
)
677 if ( !(_rInsertRow
->get())[aIter
->second
.nPosition
].isModified() )
678 (_rInsertRow
->get())[aIter
->second
.nPosition
] = aIter
->second
.sDefaultValue
;
682 Reference
< XGeneratedResultSet
> xGRes(xPrep
, UNO_QUERY
);
685 Reference
< XResultSet
> xRes
= xGRes
->getGeneratedValues();
686 Reference
< XRow
> xRow(xRes
,UNO_QUERY
);
687 if ( xRow
.is() && xRes
->next() )
689 Reference
< XResultSetMetaDataSupplier
> xMdSup(xRes
,UNO_QUERY
);
690 Reference
< XResultSetMetaData
> xMd
= xMdSup
->getMetaData();
691 sal_Int32 nColumnCount
= xMd
->getColumnCount();
692 ::std::vector
< ::rtl::OUString
>::iterator aAutoIter
= m_aAutoColumns
.begin();
693 ::std::vector
< ::rtl::OUString
>::iterator aAutoEnd
= m_aAutoColumns
.end();
694 for (sal_Int32 i
= 1;aAutoIter
!= aAutoEnd
&& i
<= nColumnCount
; ++aAutoIter
,++i
)
696 #if OSL_DEBUG_LEVEL > 1
697 ::rtl::OUString
sColumnName( xMd
->getColumnName(i
) );
699 SelectColumnsMetaData::iterator aFind
= m_pKeyColumnNames
->find(*aAutoIter
);
700 if ( aFind
!= m_pKeyColumnNames
->end() )
701 (_rInsertRow
->get())[aFind
->second
.nPosition
].fill(i
,aFind
->second
.nType
,aFind
->second
.bNullable
,xRow
);
703 bAutoValuesFetched
= sal_True
;
709 OSL_ENSURE(0,"Could not execute GeneratedKeys() stmt");
713 ::comphelper::disposeComponent(xPrep
);
715 if ( !bAutoValuesFetched
&& m_bInserted
)
717 // first check if all key column values were set
718 const ::rtl::OUString
sMax(RTL_CONSTASCII_USTRINGPARAM(" MAX("));
719 const ::rtl::OUString
sMaxEnd(RTL_CONSTASCII_USTRINGPARAM("),"));
720 const ::rtl::OUString sQuote
= getIdentifierQuoteString();
721 ::rtl::OUString sMaxStmt
;
722 aEnd
= m_pKeyColumnNames
->end();
723 ::std::vector
< ::rtl::OUString
>::iterator aAutoIter
= m_aAutoColumns
.begin();
724 ::std::vector
< ::rtl::OUString
>::iterator aAutoEnd
= m_aAutoColumns
.end();
725 for (;aAutoIter
!= aAutoEnd
; ++aAutoIter
)
727 // we will only fetch values which are keycolumns
728 if ( m_pKeyColumnNames
->find(*aAutoIter
) != aEnd
)
731 sMaxStmt
+= ::dbtools::quoteName( sQuote
,*aAutoIter
);
736 if(sMaxStmt
.getLength())
738 sMaxStmt
= sMaxStmt
.replaceAt(sMaxStmt
.getLength()-1,1,::rtl::OUString::createFromAscii(" "));
739 ::rtl::OUString sStmt
= ::rtl::OUString::createFromAscii("SELECT ");
741 sStmt
+= ::rtl::OUString::createFromAscii("FROM ");
742 sStmt
+= m_aSelectComposedTableName
;
745 // now fetch the autoincrement values
746 Reference
<XStatement
> xStatement
= m_xConnection
->createStatement();
747 Reference
<XResultSet
> xRes
= xStatement
->executeQuery(sStmt
);
748 Reference
<XRow
> xRow(xRes
,UNO_QUERY
);
749 if(xRow
.is() && xRes
->next())
751 aAutoIter
= m_aAutoColumns
.begin();
752 for (sal_Int32 i
=1;aAutoIter
!= aAutoEnd
; ++aAutoIter
,++i
)
754 // we will only fetch values which are keycolumns
755 SelectColumnsMetaData::iterator aFind
= m_pKeyColumnNames
->find(*aAutoIter
);
757 (_rInsertRow
->get())[aFind
->second
.nPosition
].fill(i
,aFind
->second
.nType
,aFind
->second
.bNullable
,xRow
);
760 ::comphelper::disposeComponent(xStatement
);
764 OSL_ENSURE(0,"Could not fetch with MAX() ");
770 ORowSetRow aKeyRow
= new connectivity::ORowVector
< ORowSetValue
>((*m_pKeyColumnNames
).size());
771 copyRowValue(_rInsertRow
,aKeyRow
);
773 OKeySetMatrix::iterator aKeyIter
= m_aKeyMap
.end();
775 m_aKeyIter
= m_aKeyMap
.insert(OKeySetMatrix::value_type(aKeyIter
->first
+ 1,OKeySetValue(aKeyRow
,1))).first
;
776 // now we set the bookmark for this row
777 (_rInsertRow
->get())[0] = makeAny((sal_Int32
)m_aKeyIter
->first
);
780 // -----------------------------------------------------------------------------
781 void OKeySet::copyRowValue(const ORowSetRow
& _rInsertRow
,ORowSetRow
& _rKeyRow
)
783 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::copyRowValue" );
784 connectivity::ORowVector
< ORowSetValue
>::Vector::iterator aIter
= _rKeyRow
->get().begin();
785 SelectColumnsMetaData::const_iterator aPosIter
= (*m_pKeyColumnNames
).begin();
786 SelectColumnsMetaData::const_iterator aPosEnd
= (*m_pKeyColumnNames
).end();
787 for(;aPosIter
!= aPosEnd
;++aPosIter
,++aIter
)
789 *aIter
= (_rInsertRow
->get())[aPosIter
->second
.nPosition
];
790 aIter
->setTypeKind(aPosIter
->second
.nType
);
793 // -------------------------------------------------------------------------
794 void SAL_CALL
OKeySet::deleteRow(const ORowSetRow
& _rDeleteRow
,const connectivity::OSQLTable
& _xTable
) throw(SQLException
, RuntimeException
)
796 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::deleteRow" );
797 Reference
<XPropertySet
> xSet(_xTable
,UNO_QUERY
);
800 ::rtl::OUStringBuffer aSql
= ::rtl::OUString::createFromAscii("DELETE FROM ");
801 aSql
.append(m_aComposedTableName
);
802 aSql
.append(::rtl::OUString::createFromAscii(" WHERE "));
804 // list all cloumns that should be set
805 ::rtl::OUString aQuote
= getIdentifierQuoteString();
806 static ::rtl::OUString aAnd
= ::rtl::OUString::createFromAscii(" AND ");
808 // use keys and indexes for excat postioning
809 Reference
<XNameAccess
> xKeyColumns
= getKeyColumns();
810 // second the indexes
811 Reference
<XIndexesSupplier
> xIndexSup(_xTable
,UNO_QUERY
);
812 Reference
<XIndexAccess
> xIndexes
;
813 if ( xIndexSup
.is() )
814 xIndexes
.set(xIndexSup
->getIndexes(),UNO_QUERY
);
816 // Reference<XColumnsSupplier>
817 ::std::vector
< Reference
<XNameAccess
> > aAllIndexColumns
;
818 lcl_fillIndexColumns(xIndexes
,aAllIndexColumns
);
820 ::rtl::OUString aColumnName
;
821 ::rtl::OUStringBuffer sIndexCondition
;
822 ::std::vector
<sal_Int32
> aIndexColumnPositions
;
823 SelectColumnsMetaData::const_iterator aIter
= m_pColumnNames
->begin();
824 SelectColumnsMetaData::const_iterator aEnd
= m_pColumnNames
->end();
827 for(i
= 1;aIter
!= aEnd
;++aIter
,++i
)
829 if(xKeyColumns
.is() && xKeyColumns
->hasByName(aIter
->first
))
831 aSql
.append(::dbtools::quoteName( aQuote
,aIter
->first
));
832 if((_rDeleteRow
->get())[aIter
->second
.nPosition
].isNull())
834 OSL_ENSURE(0,"can a primary key be null");
835 aSql
.append(::rtl::OUString::createFromAscii(" IS NULL"));
838 aSql
.append(::rtl::OUString::createFromAscii(" = ?"));
843 ::std::vector
< Reference
<XNameAccess
> >::const_iterator aIndexEnd
= aAllIndexColumns
.end();
844 for( ::std::vector
< Reference
<XNameAccess
> >::const_iterator aIndexIter
= aAllIndexColumns
.begin();
845 aIndexIter
!= aIndexEnd
;++aIndexIter
)
847 if((*aIndexIter
)->hasByName(aIter
->first
))
849 sIndexCondition
.append(::dbtools::quoteName( aQuote
,aIter
->first
));
850 if((_rDeleteRow
->get())[aIter
->second
.nPosition
].isNull())
851 sIndexCondition
.append(::rtl::OUString::createFromAscii(" IS NULL"));
854 sIndexCondition
.append(::rtl::OUString::createFromAscii(" = ?"));
855 aIndexColumnPositions
.push_back(aIter
->second
.nPosition
);
857 sIndexCondition
.append(aAnd
);
864 aSql
.append(sIndexCondition
.makeStringAndClear());
865 aSql
.setLength(aSql
.getLength()-5);
867 // now create end execute the prepared statement
868 Reference
< XPreparedStatement
> xPrep(m_xConnection
->prepareStatement(aSql
.makeStringAndClear()));
869 Reference
< XParameters
> xParameter(xPrep
,UNO_QUERY
);
871 aIter
= (*m_pKeyColumnNames
).begin();
872 aEnd
= (*m_pKeyColumnNames
).end();
874 for(;aIter
!= aEnd
;++aIter
,++i
)
876 setParameter(i
,xParameter
,(_rDeleteRow
->get())[aIter
->second
.nPosition
],aIter
->second
.nType
,aIter
->second
.nScale
);
879 // now we have to set the index values
880 ::std::vector
<sal_Int32
>::iterator aIdxColIter
= aIndexColumnPositions
.begin();
881 ::std::vector
<sal_Int32
>::iterator aIdxColEnd
= aIndexColumnPositions
.end();
882 for(;aIdxColIter
!= aIdxColEnd
;++aIdxColIter
,++i
)
884 setParameter(i
,xParameter
,(_rDeleteRow
->get())[*aIdxColIter
],(_rDeleteRow
->get())[*aIdxColIter
].getTypeKind(),aIter
->second
.nScale
);
887 m_bDeleted
= xPrep
->executeUpdate() > 0;
891 sal_Int32 nBookmark
= ::comphelper::getINT32((_rDeleteRow
->get())[0].getAny());
892 if(m_aKeyIter
== m_aKeyMap
.find(nBookmark
) && m_aKeyIter
!= m_aKeyMap
.end())
894 m_aKeyMap
.erase(nBookmark
);
895 m_bDeleted
= sal_True
;
898 // -------------------------------------------------------------------------
899 void SAL_CALL
OKeySet::cancelRowUpdates( ) throw(SQLException
, RuntimeException
)
901 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::cancelRowUpdates" );
902 m_bInserted
= m_bUpdated
= m_bDeleted
= sal_False
;
904 // -------------------------------------------------------------------------
905 void SAL_CALL
OKeySet::moveToInsertRow( ) throw(SQLException
, RuntimeException
)
907 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::moveToInsertRow" );
909 // -------------------------------------------------------------------------
910 void SAL_CALL
OKeySet::moveToCurrentRow( ) throw(SQLException
, RuntimeException
)
912 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::moveToCurrentRow" );
914 // -------------------------------------------------------------------------
915 Reference
<XNameAccess
> OKeySet::getKeyColumns() const
917 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getKeyColumns" );
918 // use keys and indexes for excat postioning
921 Reference
<XIndexAccess
> xKeys
= m_xTableKeys
;
924 Reference
<XKeysSupplier
> xKeySup(m_xTable
,UNO_QUERY
);
926 xKeys
= xKeySup
->getKeys();
929 Reference
<XColumnsSupplier
> xKeyColsSup
;
930 Reference
<XNameAccess
> xKeyColumns
;
933 Reference
<XPropertySet
> xProp
;
934 sal_Int32 nCount
= xKeys
->getCount();
935 for(sal_Int32 i
= 0;i
< nCount
;++i
)
937 xProp
.set(xKeys
->getByIndex(i
),UNO_QUERY
);
940 sal_Int32 nKeyType
= 0;
941 xProp
->getPropertyValue(PROPERTY_TYPE
) >>= nKeyType
;
942 if(KeyType::PRIMARY
== nKeyType
)
944 xKeyColsSup
.set(xProp
,UNO_QUERY
);
945 OSL_ENSURE(xKeyColsSup
.is(),"Columnsupplier is null!");
946 xKeyColumns
= xKeyColsSup
->getColumns();
955 // -----------------------------------------------------------------------------
956 sal_Bool SAL_CALL
OKeySet::next( ) throw(SQLException
, RuntimeException
)
958 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::next" );
959 m_bInserted
= m_bUpdated
= m_bDeleted
= sal_False
;
963 if(!m_bRowCountFinal
) // not yet all records fetched
965 ++m_aKeyIter
; // this is possible because we stand on begin() and this is the "beforefirst" row
966 if(m_aKeyIter
== m_aKeyMap
.end() && !fetchRow())
967 m_aKeyIter
= m_aKeyMap
.end();
969 else if(!isAfterLast())
973 return !isAfterLast();
975 // -----------------------------------------------------------------------------
976 sal_Bool SAL_CALL
OKeySet::isBeforeFirst( ) throw(SQLException
, RuntimeException
)
978 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::isBeforeFirst" );
979 return m_aKeyIter
== m_aKeyMap
.begin();
981 // -----------------------------------------------------------------------------
982 sal_Bool SAL_CALL
OKeySet::isAfterLast( ) throw(SQLException
, RuntimeException
)
984 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::isAfterLast" );
985 return m_bRowCountFinal
&& m_aKeyIter
== m_aKeyMap
.end();
987 // -----------------------------------------------------------------------------
988 sal_Bool SAL_CALL
OKeySet::isFirst( ) throw(SQLException
, RuntimeException
)
990 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::isFirst" );
991 OKeySetMatrix::iterator aTemp
= m_aKeyMap
.begin();
993 return m_aKeyIter
== aTemp
&& m_aKeyIter
!= m_aKeyMap
.end();
995 // -----------------------------------------------------------------------------
996 sal_Bool SAL_CALL
OKeySet::isLast( ) throw(SQLException
, RuntimeException
)
998 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::isLast" );
999 if(!m_bRowCountFinal
)
1002 OKeySetMatrix::iterator aTemp
= m_aKeyMap
.end();
1004 return m_aKeyIter
== aTemp
;
1006 // -----------------------------------------------------------------------------
1007 void SAL_CALL
OKeySet::beforeFirst( ) throw(SQLException
, RuntimeException
)
1009 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::beforeFirst" );
1010 m_bInserted
= m_bUpdated
= m_bDeleted
= sal_False
;
1011 m_aKeyIter
= m_aKeyMap
.begin();
1013 ::comphelper::disposeComponent(m_xRow
);
1015 // -----------------------------------------------------------------------------
1016 void SAL_CALL
OKeySet::afterLast( ) throw(SQLException
, RuntimeException
)
1018 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::afterLast" );
1019 m_bInserted
= m_bUpdated
= m_bDeleted
= sal_False
;
1021 m_aKeyIter
= m_aKeyMap
.end();
1023 ::comphelper::disposeComponent(m_xRow
);
1025 // -----------------------------------------------------------------------------
1026 sal_Bool SAL_CALL
OKeySet::first( ) throw(SQLException
, RuntimeException
)
1028 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::first" );
1029 m_bInserted
= m_bUpdated
= m_bDeleted
= sal_False
;
1030 m_aKeyIter
= m_aKeyMap
.begin();
1032 if(m_aKeyIter
== m_aKeyMap
.end() && !fetchRow())
1033 m_aKeyIter
= m_aKeyMap
.end();
1036 return m_aKeyIter
!= m_aKeyMap
.end() && m_aKeyIter
!= m_aKeyMap
.begin();
1038 // -----------------------------------------------------------------------------
1039 sal_Bool SAL_CALL
OKeySet::last( ) throw(SQLException
, RuntimeException
)
1041 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::last" );
1042 m_bInserted
= m_bUpdated
= m_bDeleted
= sal_False
;
1045 m_aKeyIter
= m_aKeyMap
.end();
1048 return m_aKeyIter
!= m_aKeyMap
.end() && m_aKeyIter
!= m_aKeyMap
.begin();
1050 // -----------------------------------------------------------------------------
1051 sal_Int32 SAL_CALL
OKeySet::getRow( ) throw(SQLException
, RuntimeException
)
1053 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getRow" );
1054 OSL_ENSURE(!isAfterLast(),"getRow is not allowed when afterlast record!");
1055 OSL_ENSURE(!isBeforeFirst(),"getRow is not allowed when beforefirst record!");
1057 return ::std::distance(m_aKeyMap
.begin(),m_aKeyIter
);
1059 // -----------------------------------------------------------------------------
1060 sal_Bool SAL_CALL
OKeySet::absolute( sal_Int32 row
) throw(SQLException
, RuntimeException
)
1062 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::absolute" );
1063 m_bInserted
= m_bUpdated
= m_bDeleted
= sal_False
;
1064 OSL_ENSURE(row
,"absolute(0) isn't allowed!");
1067 if(!m_bRowCountFinal
)
1070 for(;row
< 0 && m_aKeyIter
!= m_aKeyMap
.begin();++row
)
1075 if(row
>= (sal_Int32
)m_aKeyMap
.size())
1077 if(!m_bRowCountFinal
)
1079 sal_Bool bNext
= sal_True
;
1080 for(sal_Int32 i
=m_aKeyMap
.size()-1;i
< row
&& bNext
;++i
)
1084 m_aKeyIter
= m_aKeyMap
.end();
1088 m_aKeyIter
= m_aKeyMap
.begin();
1089 for(;row
> 0 && m_aKeyIter
!= m_aKeyMap
.end();--row
)
1095 return m_aKeyIter
!= m_aKeyMap
.end() && m_aKeyIter
!= m_aKeyMap
.begin();
1097 // -----------------------------------------------------------------------------
1098 sal_Bool SAL_CALL
OKeySet::relative( sal_Int32 rows
) throw(SQLException
, RuntimeException
)
1100 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::relative" );
1106 return absolute(getRow()+rows
);
1108 // -----------------------------------------------------------------------------
1109 sal_Bool SAL_CALL
OKeySet::previous( ) throw(SQLException
, RuntimeException
)
1111 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::previous" );
1112 m_bInserted
= m_bUpdated
= m_bDeleted
= sal_False
;
1113 if(m_aKeyIter
!= m_aKeyMap
.begin())
1118 return m_aKeyIter
!= m_aKeyMap
.begin();
1120 // -----------------------------------------------------------------------------
1121 void SAL_CALL
OKeySet::refreshRow() throw(SQLException
, RuntimeException
)
1123 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::refreshRow" );
1124 if(isBeforeFirst() || isAfterLast() || !m_xStatement
.is())
1128 ::comphelper::disposeComponent(m_xRow
);
1129 // we just areassign the base members
1130 Reference
< XParameters
> xParameter(m_xStatement
,UNO_QUERY
);
1131 OSL_ENSURE(xParameter
.is(),"No Parameter interface!");
1132 xParameter
->clearParameters();
1134 connectivity::ORowVector
< ORowSetValue
>::Vector::const_iterator aParaIter
= m_aParameterValueForCache
.get().begin();
1135 connectivity::ORowVector
< ORowSetValue
>::Vector::const_iterator aParaEnd
= m_aParameterValueForCache
.get().end();
1136 for(++aParaIter
;aParaIter
!= aParaEnd
;++aParaIter
,++nPos
)
1138 ::dbtools::setObjectWithInfo( xParameter
, nPos
, aParaIter
->makeAny(), aParaIter
->getTypeKind() );
1140 connectivity::ORowVector
< ORowSetValue
>::Vector::const_iterator aIter
= m_aKeyIter
->second
.first
->get().begin();
1141 SelectColumnsMetaData::const_iterator aPosIter
= (*m_pKeyColumnNames
).begin();
1142 SelectColumnsMetaData::const_iterator aPosEnd
= (*m_pKeyColumnNames
).end();
1143 for(;aPosIter
!= aPosEnd
;++aPosIter
,++aIter
,++nPos
)
1144 setParameter(nPos
,xParameter
,*aIter
,aPosIter
->second
.nType
,aPosIter
->second
.nScale
);
1145 aPosIter
= (*m_pForeignColumnNames
).begin();
1146 aPosEnd
= (*m_pForeignColumnNames
).end();
1147 for(;aPosIter
!= aPosEnd
;++aPosIter
,++aIter
,++nPos
)
1148 setParameter(nPos
,xParameter
,*aIter
,aPosIter
->second
.nType
,aPosIter
->second
.nScale
);
1150 m_xSet
= m_xStatement
->executeQuery();
1151 OSL_ENSURE(m_xSet
.is(),"No resultset form statement!");
1152 sal_Bool bOK
= m_xSet
->next(); (void)bOK
;
1153 OSL_ENSURE(bOK
,"No rows!");
1154 m_xRow
.set(m_xSet
,UNO_QUERY
);
1155 OSL_ENSURE(m_xRow
.is(),"No row form statement!");
1157 // -----------------------------------------------------------------------------
1158 sal_Bool
OKeySet::fetchRow()
1160 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::fetchRow" );
1161 // fetch the next row and append on the keyset
1162 sal_Bool bRet
= sal_False
;
1163 if ( !m_bRowCountFinal
)
1164 bRet
= m_xDriverSet
->next();
1167 ORowSetRow aKeyRow
= new connectivity::ORowVector
< ORowSetValue
>((*m_pKeyColumnNames
).size() + m_pForeignColumnNames
->size());
1168 connectivity::ORowVector
< ORowSetValue
>::Vector::iterator aIter
= aKeyRow
->get().begin();
1169 // first fetch the values needed for the key column
1170 SelectColumnsMetaData::const_iterator aPosIter
= (*m_pKeyColumnNames
).begin();
1171 SelectColumnsMetaData::const_iterator aPosEnd
= (*m_pKeyColumnNames
).end();
1172 for(;aPosIter
!= aPosEnd
;++aPosIter
,++aIter
)
1174 const SelectColumnDescription
& rColDesc
= aPosIter
->second
;
1175 aIter
->fill(rColDesc
.nPosition
,rColDesc
.nType
,rColDesc
.bNullable
,m_xDriverRow
);
1177 // now fetch the values from the missing columns from other tables
1178 aPosIter
= (*m_pForeignColumnNames
).begin();
1179 aPosEnd
= (*m_pForeignColumnNames
).end();
1180 for(;aPosIter
!= aPosEnd
;++aPosIter
,++aIter
)
1182 const SelectColumnDescription
& rColDesc
= aPosIter
->second
;
1183 aIter
->fill(rColDesc
.nPosition
,rColDesc
.nType
,rColDesc
.bNullable
,m_xDriverRow
);
1185 m_aKeyIter
= m_aKeyMap
.insert(OKeySetMatrix::value_type(m_aKeyMap
.rbegin()->first
+1,OKeySetValue(aKeyRow
,0))).first
;
1188 m_bRowCountFinal
= sal_True
;
1191 // -------------------------------------------------------------------------
1192 void OKeySet::fillAllRows()
1194 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::fillAllRows" );
1195 if(!m_bRowCountFinal
)
1202 sal_Bool SAL_CALL
OKeySet::wasNull( ) throw(SQLException
, RuntimeException
)
1204 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::wasNull" );
1205 return m_xRow
->wasNull();
1207 // -------------------------------------------------------------------------
1208 ::rtl::OUString SAL_CALL
OKeySet::getString( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
1210 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getString" );
1211 OSL_ENSURE(m_xRow
.is(),"m_xRow is null!");
1212 return m_xRow
->getString(columnIndex
);
1214 // -------------------------------------------------------------------------
1215 sal_Bool SAL_CALL
OKeySet::getBoolean( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
1217 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getBoolean" );
1218 OSL_ENSURE(m_xRow
.is(),"m_xRow is null!");
1219 return m_xRow
->getBoolean(columnIndex
);
1221 // -------------------------------------------------------------------------
1222 sal_Int8 SAL_CALL
OKeySet::getByte( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
1224 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getByte" );
1225 OSL_ENSURE(m_xRow
.is(),"m_xRow is null!");
1226 return m_xRow
->getByte(columnIndex
);
1228 // -------------------------------------------------------------------------
1229 sal_Int16 SAL_CALL
OKeySet::getShort( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
1231 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getShort" );
1232 OSL_ENSURE(m_xRow
.is(),"m_xRow is null!");
1233 return m_xRow
->getShort(columnIndex
);
1235 // -------------------------------------------------------------------------
1236 sal_Int32 SAL_CALL
OKeySet::getInt( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
1238 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getInt" );
1239 OSL_ENSURE(m_xRow
.is(),"m_xRow is null!");
1240 return m_xRow
->getInt(columnIndex
);
1242 // -------------------------------------------------------------------------
1243 sal_Int64 SAL_CALL
OKeySet::getLong( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
1245 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getLong" );
1246 OSL_ENSURE(m_xRow
.is(),"m_xRow is null!");
1247 return m_xRow
->getLong(columnIndex
);
1249 // -------------------------------------------------------------------------
1250 float SAL_CALL
OKeySet::getFloat( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
1252 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getFloat" );
1253 OSL_ENSURE(m_xRow
.is(),"m_xRow is null!");
1254 return m_xRow
->getFloat(columnIndex
);
1256 // -------------------------------------------------------------------------
1257 double SAL_CALL
OKeySet::getDouble( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
1259 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getDouble" );
1260 OSL_ENSURE(m_xRow
.is(),"m_xRow is null!");
1261 return m_xRow
->getDouble(columnIndex
);
1263 // -------------------------------------------------------------------------
1264 Sequence
< sal_Int8
> SAL_CALL
OKeySet::getBytes( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
1266 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getBytes" );
1267 OSL_ENSURE(m_xRow
.is(),"m_xRow is null!");
1268 return m_xRow
->getBytes(columnIndex
);
1270 // -------------------------------------------------------------------------
1271 ::com::sun::star::util::Date SAL_CALL
OKeySet::getDate( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
1273 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getDate" );
1274 OSL_ENSURE(m_xRow
.is(),"m_xRow is null!");
1275 return m_xRow
->getDate(columnIndex
);
1277 // -------------------------------------------------------------------------
1278 ::com::sun::star::util::Time SAL_CALL
OKeySet::getTime( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
1280 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getTime" );
1281 OSL_ENSURE(m_xRow
.is(),"m_xRow is null!");
1282 return m_xRow
->getTime(columnIndex
);
1284 // -------------------------------------------------------------------------
1285 ::com::sun::star::util::DateTime SAL_CALL
OKeySet::getTimestamp( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
1287 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getTimestamp" );
1288 OSL_ENSURE(m_xRow
.is(),"m_xRow is null!");
1289 return m_xRow
->getTimestamp(columnIndex
);
1291 // -------------------------------------------------------------------------
1292 Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
OKeySet::getBinaryStream( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
1294 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getBinaryStream" );
1295 OSL_ENSURE(m_xRow
.is(),"m_xRow is null!");
1296 return m_xRow
->getBinaryStream(columnIndex
);
1298 // -------------------------------------------------------------------------
1299 Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
OKeySet::getCharacterStream( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
1301 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getCharacterStream" );
1302 OSL_ENSURE(m_xRow
.is(),"m_xRow is null!");
1303 return m_xRow
->getCharacterStream(columnIndex
);
1305 // -------------------------------------------------------------------------
1306 Any SAL_CALL
OKeySet::getObject( sal_Int32 columnIndex
, const Reference
< ::com::sun::star::container::XNameAccess
>& typeMap
) throw(SQLException
, RuntimeException
)
1308 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getObject" );
1309 OSL_ENSURE(m_xRow
.is(),"m_xRow is null!");
1310 return m_xRow
->getObject(columnIndex
,typeMap
);
1312 // -------------------------------------------------------------------------
1313 Reference
< XRef
> SAL_CALL
OKeySet::getRef( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
1315 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getRef" );
1316 OSL_ENSURE(m_xRow
.is(),"m_xRow is null!");
1317 return m_xRow
->getRef(columnIndex
);
1319 // -------------------------------------------------------------------------
1320 Reference
< XBlob
> SAL_CALL
OKeySet::getBlob( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
1322 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getBlob" );
1323 OSL_ENSURE(m_xRow
.is(),"m_xRow is null!");
1324 return m_xRow
->getBlob(columnIndex
);
1326 // -------------------------------------------------------------------------
1327 Reference
< XClob
> SAL_CALL
OKeySet::getClob( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
1329 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getClob" );
1330 OSL_ENSURE(m_xRow
.is(),"m_xRow is null!");
1331 return m_xRow
->getClob(columnIndex
);
1333 // -------------------------------------------------------------------------
1334 Reference
< XArray
> SAL_CALL
OKeySet::getArray( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
1336 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getArray" );
1337 OSL_ENSURE(m_xRow
.is(),"m_xRow is null!");
1338 return m_xRow
->getArray(columnIndex
);
1340 // -------------------------------------------------------------------------
1341 sal_Bool SAL_CALL
OKeySet::rowUpdated( ) throw(SQLException
, RuntimeException
)
1343 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::rowUpdated" );
1344 return m_aKeyIter
!= m_aKeyMap
.begin() && m_aKeyIter
!= m_aKeyMap
.end() && m_aKeyIter
->second
.second
== 2;
1346 // -------------------------------------------------------------------------
1347 sal_Bool SAL_CALL
OKeySet::rowInserted( ) throw(SQLException
, RuntimeException
)
1349 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::rowInserted" );
1350 return m_aKeyIter
!= m_aKeyMap
.begin() && m_aKeyIter
!= m_aKeyMap
.end() && m_aKeyIter
->second
.second
== 1;
1352 // -------------------------------------------------------------------------
1353 sal_Bool SAL_CALL
OKeySet::rowDeleted( ) throw(SQLException
, RuntimeException
)
1355 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::rowDeleted" );
1356 sal_Bool bDeleted
= m_bDeleted
;
1357 m_bDeleted
= sal_False
;
1360 // -----------------------------------------------------------------------------
1361 ::rtl::OUString
OKeySet::getComposedTableName(const ::rtl::OUString
& _sCatalog
,
1362 const ::rtl::OUString
& _sSchema
,
1363 const ::rtl::OUString
& _sTable
)
1365 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::getComposedTableName" );
1366 ::rtl::OUString aComposedName
;
1367 Reference
<XDatabaseMetaData
> xMetaData
= m_xConnection
->getMetaData();
1369 if( xMetaData
.is() && xMetaData
->supportsTableCorrelationNames() )
1371 aComposedName
= ::dbtools::composeTableName( xMetaData
, _sCatalog
, _sSchema
, _sTable
, sal_False
, ::dbtools::eInDataManipulation
);
1372 // first we have to check if the composed tablename is in the select clause or if an alias is used
1373 Reference
<XTablesSupplier
> xTabSup(m_xComposer
,UNO_QUERY
);
1374 Reference
<XNameAccess
> xSelectTables
= xTabSup
->getTables();
1375 OSL_ENSURE(xSelectTables
.is(),"No Select tables!");
1376 if(xSelectTables
.is())
1378 if(!xSelectTables
->hasByName(aComposedName
))
1379 { // the composed name isn't used in the select clause so we have to find out which name is used instead
1380 ::rtl::OUString sCatalog
,sSchema
,sTable
;
1381 ::dbtools::qualifiedNameComponents(xMetaData
,m_sUpdateTableName
,sCatalog
,sSchema
,sTable
,::dbtools::eInDataManipulation
);
1382 aComposedName
= ::dbtools::composeTableNameForSelect( m_xConnection
, sCatalog
, sSchema
, sTable
);
1385 aComposedName
= ::dbtools::composeTableNameForSelect( m_xConnection
, _sCatalog
, _sSchema
, _sTable
);
1389 aComposedName
= ::dbtools::composeTableNameForSelect( m_xConnection
, _sCatalog
, _sSchema
, _sTable
);
1391 return aComposedName
;
1393 // -----------------------------------------------------------------------------
1396 void getColumnPositions(const Reference
<XNameAccess
>& _rxQueryColumns
,
1397 const Reference
<XNameAccess
>& _rxColumns
,
1398 const ::rtl::OUString
& _rsUpdateTableName
,
1399 SelectColumnsMetaData
& _rColumnNames
)
1401 // get the real name of the columns
1402 Sequence
< ::rtl::OUString
> aSelNames(_rxQueryColumns
->getElementNames());
1403 const ::rtl::OUString
* pSelBegin
= aSelNames
.getConstArray();
1404 const ::rtl::OUString
* pSelEnd
= pSelBegin
+ aSelNames
.getLength();
1406 Sequence
< ::rtl::OUString
> aColumnNames(_rxColumns
->getElementNames());
1407 const ::rtl::OUString
* pColumnIter
= aColumnNames
.getConstArray();
1408 const ::rtl::OUString
* pColumnEnd
= pColumnIter
+ aColumnNames
.getLength();
1410 ::comphelper::UStringMixLess
aTmp(_rColumnNames
.key_comp());
1411 ::comphelper::UStringMixEqual
bCase(static_cast< ::comphelper::UStringMixLess
*>(&aTmp
)->isCaseSensitive());
1413 for(sal_Int32 nPos
= 1;pSelBegin
!= pSelEnd
;++pSelBegin
,++nPos
)
1415 Reference
<XPropertySet
> xColumnProp(_rxQueryColumns
->getByName(*pSelBegin
),UNO_QUERY
);
1416 ::rtl::OUString sRealName
,sTableName
;
1417 OSL_ENSURE(xColumnProp
->getPropertySetInfo()->hasPropertyByName(PROPERTY_REALNAME
),"Property REALNAME not available!");
1418 OSL_ENSURE(xColumnProp
->getPropertySetInfo()->hasPropertyByName(PROPERTY_TABLENAME
),"Property TABLENAME not available!");
1419 xColumnProp
->getPropertyValue(PROPERTY_REALNAME
) >>= sRealName
;
1420 xColumnProp
->getPropertyValue(PROPERTY_TABLENAME
) >>= sTableName
;
1422 for(;pColumnIter
!= pColumnEnd
;++pColumnIter
)
1424 if(bCase(sRealName
,*pColumnIter
) && bCase(_rsUpdateTableName
,sTableName
) && _rColumnNames
.find(*pColumnIter
) == _rColumnNames
.end())
1426 sal_Int32 nType
= 0;
1427 xColumnProp
->getPropertyValue(PROPERTY_TYPE
) >>= nType
;
1428 sal_Int32 nScale
= 0;
1429 xColumnProp
->getPropertyValue(PROPERTY_SCALE
) >>= nScale
;
1430 ::rtl::OUString sColumnDefault
;
1431 if ( xColumnProp
->getPropertySetInfo()->hasPropertyByName(PROPERTY_DEFAULTVALUE
) )
1432 xColumnProp
->getPropertyValue(PROPERTY_DEFAULTVALUE
) >>= sColumnDefault
;
1434 sal_Int32 bNullable
= sal_False
;
1435 xColumnProp
->getPropertyValue(PROPERTY_ISNULLABLE
) >>= bNullable
;
1438 _rColumnNames
[sRealName
] = SelectColumnDescription( nPos
, nType
,nScale
,bNullable
!= sdbc::ColumnValue::NO_NULLS
, sColumnDefault
);
1442 pColumnIter
= aColumnNames
.getConstArray();