1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_dbaccess.hxx"
#include "resultcolumn.hxx"
#include <com/sun/star/lang/DisposedException.hpp>
#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
#include <com/sun/star/sdbc/DataType.hpp>
#include <com/sun/star/sdbc/ColumnValue.hpp>
#include <cppuhelper/typeprovider.hxx>
#include <tools/debug.hxx>
#include <tools/diagnose_ex.h>
#include "dbastrings.hrc"
#include "apitools.hxx"
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <cppuhelper/exc_hlp.hxx>
#include <osl/thread.h>
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::container;
using namespace ::osl;
using namespace ::comphelper;
using namespace ::cppu;
using namespace dbaccess;
DBG_NAME(OResultColumn)
//--------------------------------------------------------------------------
OResultColumn::OResultColumn( const Reference < XResultSetMetaData >& _xMetaData, sal_Int32 _nPos,
const Reference< XDatabaseMetaData >& _rxDBMeta )
:OColumn( true )
,m_xMetaData( _xMetaData )
,m_xDBMetaData( _rxDBMeta )
,m_nPos( _nPos )
{
DBG_CTOR(OResultColumn,NULL);
}
// -----------------------------------------------------------------------------
void OResultColumn::impl_determineIsRowVersion_nothrow()
{
if ( m_aIsRowVersion.hasValue() )
return;
m_aIsRowVersion <<= (sal_Bool)(sal_False);
OSL_ENSURE( m_xDBMetaData.is(), "OResultColumn::impl_determineIsRowVersion_nothrow: no DBMetaData!" );
if ( !m_xDBMetaData.is() )
return;
try
{
::rtl::OUString sCatalog, sSchema, sTable, sColumnName;
getPropertyValue( PROPERTY_CATALOGNAME ) >>= sCatalog;
getPropertyValue( PROPERTY_SCHEMANAME ) >>= sSchema;
getPropertyValue( PROPERTY_TABLENAME ) >>= sTable;
getPropertyValue( PROPERTY_NAME ) >>= sColumnName;
try
{
Reference< XResultSet > xVersionColumns = m_xDBMetaData->getVersionColumns(
makeAny( sCatalog ), sSchema, sTable );
if ( xVersionColumns.is() ) // allowed to be NULL
{
Reference< XRow > xResultRow( xVersionColumns, UNO_QUERY_THROW );
while ( xVersionColumns->next() )
{
if ( xResultRow->getString( 2 ) == sColumnName )
{
m_aIsRowVersion <<= (sal_Bool)(sal_True);
break;
}
}
}
}
catch(const SQLException&)
{
}
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
}
// -----------------------------------------------------------------------------
OResultColumn::~OResultColumn()
{
DBG_DTOR(OResultColumn,NULL);
}
// com::sun::star::lang::XTypeProvider
//--------------------------------------------------------------------------
Sequence< sal_Int8 > OResultColumn::getImplementationId() throw (RuntimeException)
{
static OImplementationId * pId = 0;
if (! pId)
{
MutexGuard aGuard( Mutex::getGlobalMutex() );
if (! pId)
{
static OImplementationId aId;
pId = &aId;
}
}
return pId->getImplementationId();
}
// XServiceInfo
//------------------------------------------------------------------------------
rtl::OUString OResultColumn::getImplementationName( ) throw(RuntimeException)
{
return rtl::OUString::createFromAscii("com.sun.star.sdb.OResultColumn");
}
//------------------------------------------------------------------------------
Sequence< ::rtl::OUString > OResultColumn::getSupportedServiceNames( ) throw (RuntimeException)
{
Sequence< ::rtl::OUString > aSNS( 2 );
aSNS[0] = SERVICE_SDBCX_COLUMN;
aSNS[1] = SERVICE_SDB_RESULTCOLUMN;
return aSNS;
}
// OComponentHelper
//------------------------------------------------------------------------------
void OResultColumn::disposing()
{
OColumn::disposing();
MutexGuard aGuard(m_aMutex);
m_xMetaData = NULL;
}
// comphelper::OPropertyArrayUsageHelper
//------------------------------------------------------------------------------
::cppu::IPropertyArrayHelper* OResultColumn::createArrayHelper( ) const
{
BEGIN_PROPERTY_HELPER(21)
DECL_PROP1(CATALOGNAME, ::rtl::OUString, READONLY);
DECL_PROP1(DISPLAYSIZE, sal_Int32, READONLY);
DECL_PROP1_BOOL(ISAUTOINCREMENT, READONLY);
DECL_PROP1_BOOL(ISCASESENSITIVE, READONLY);
DECL_PROP1_BOOL(ISCURRENCY, READONLY);
DECL_PROP1_BOOL(ISDEFINITELYWRITABLE, READONLY);
DECL_PROP1(ISNULLABLE, sal_Int32, READONLY);
DECL_PROP1_BOOL(ISREADONLY, READONLY);
DECL_PROP1_BOOL(ISROWVERSION, READONLY);
DECL_PROP1_BOOL(ISSEARCHABLE, READONLY);
DECL_PROP1_BOOL(ISSIGNED, READONLY);
DECL_PROP1_BOOL(ISWRITABLE, READONLY);
DECL_PROP1(LABEL, ::rtl::OUString, READONLY);
DECL_PROP1(NAME, ::rtl::OUString, READONLY);
DECL_PROP1(PRECISION, sal_Int32, READONLY);
DECL_PROP1(SCALE, sal_Int32, READONLY);
DECL_PROP1(SCHEMANAME, ::rtl::OUString, READONLY);
DECL_PROP1(SERVICENAME, ::rtl::OUString, READONLY);
DECL_PROP1(TABLENAME, ::rtl::OUString, READONLY);
DECL_PROP1(TYPE, sal_Int32, READONLY);
DECL_PROP1(TYPENAME, ::rtl::OUString, READONLY);
END_PROPERTY_HELPER();
}
// cppu::OPropertySetHelper
//------------------------------------------------------------------------------
::cppu::IPropertyArrayHelper& OResultColumn::getInfoHelper()
{
return *static_cast< ::comphelper::OPropertyArrayUsageHelper< OResultColumn >* >(this)->getArrayHelper();
}
//------------------------------------------------------------------------------
namespace
{
template< typename TYPE >
void obtain( Any& _out_rValue, ::boost::optional< TYPE > _rCache, const sal_Int32 _nPos, const Reference < XResultSetMetaData >& _rxResultMeta, TYPE (SAL_CALL XResultSetMetaData::*Getter)( sal_Int32 ) )
{
if ( !_rCache )
_rCache.reset( (_rxResultMeta.get()->*Getter)( _nPos ) );
_out_rValue <<= *_rCache;
}
}
//------------------------------------------------------------------------------
void OResultColumn::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
{
try
{
if ( OColumn::isRegisteredProperty( nHandle ) )
{
OColumn::getFastPropertyValue( rValue, nHandle );
}
else
{
switch (nHandle)
{
case PROPERTY_ID_ISROWVERSION:
const_cast< OResultColumn* >( this )->impl_determineIsRowVersion_nothrow();
rValue = m_aIsRowVersion;
break;
case PROPERTY_ID_TABLENAME:
rValue <<= m_xMetaData->getTableName(m_nPos);
break;
case PROPERTY_ID_SCHEMANAME:
rValue <<= m_xMetaData->getSchemaName(m_nPos);
break;
case PROPERTY_ID_CATALOGNAME:
rValue <<= m_xMetaData->getCatalogName(m_nPos);
break;
case PROPERTY_ID_ISSIGNED:
obtain( rValue, m_isSigned, m_nPos, m_xMetaData, &XResultSetMetaData::isSigned );
break;
case PROPERTY_ID_ISCURRENCY:
obtain( rValue, m_isCurrency, m_nPos, m_xMetaData, &XResultSetMetaData::isCurrency );
break;
case PROPERTY_ID_ISSEARCHABLE:
obtain( rValue, m_bSearchable, m_nPos, m_xMetaData, &XResultSetMetaData::isSearchable );
break;
case PROPERTY_ID_ISCASESENSITIVE:
obtain( rValue, m_isCaseSensitive, m_nPos, m_xMetaData, &XResultSetMetaData::isCaseSensitive );
break;
case PROPERTY_ID_ISREADONLY:
obtain( rValue, m_isReadOnly, m_nPos, m_xMetaData, &XResultSetMetaData::isReadOnly );
break;
case PROPERTY_ID_ISWRITABLE:
obtain( rValue, m_isWritable, m_nPos, m_xMetaData, &XResultSetMetaData::isWritable );
break;
case PROPERTY_ID_ISDEFINITELYWRITABLE:
obtain( rValue, m_isDefinitelyWritable, m_nPos, m_xMetaData, &XResultSetMetaData::isDefinitelyWritable );
break;
case PROPERTY_ID_ISAUTOINCREMENT:
obtain( rValue, m_isAutoIncrement, m_nPos, m_xMetaData, &XResultSetMetaData::isAutoIncrement );
break;
case PROPERTY_ID_SERVICENAME:
rValue <<= m_xMetaData->getColumnServiceName(m_nPos);
break;
case PROPERTY_ID_LABEL:
obtain( rValue, m_sColumnLabel, m_nPos, m_xMetaData, &XResultSetMetaData::getColumnLabel );
break;
case PROPERTY_ID_DISPLAYSIZE:
obtain( rValue, m_nColumnDisplaySize, m_nPos, m_xMetaData, &XResultSetMetaData::getColumnDisplaySize );
break;
case PROPERTY_ID_TYPE:
obtain( rValue, m_nColumnType, m_nPos, m_xMetaData, &XResultSetMetaData::getColumnType );
break;
case PROPERTY_ID_PRECISION:
obtain( rValue, m_nPrecision, m_nPos, m_xMetaData, &XResultSetMetaData::getPrecision );
break;
case PROPERTY_ID_SCALE:
obtain( rValue, m_nScale, m_nPos, m_xMetaData, &XResultSetMetaData::getScale );
break;
case PROPERTY_ID_ISNULLABLE:
obtain( rValue, m_isNullable, m_nPos, m_xMetaData, &XResultSetMetaData::isNullable );
break;
case PROPERTY_ID_TYPENAME:
rValue <<= m_xMetaData->getColumnTypeName(m_nPos);
break;
default:
OSL_ENSURE( false, "OResultColumn::getFastPropertyValue: unknown property handle!" );
break;
}
}
}
catch (SQLException& )
{
// default handling if we caught an exception
switch (nHandle)
{
case PROPERTY_ID_LABEL:
case PROPERTY_ID_TYPENAME:
case PROPERTY_ID_SERVICENAME:
case PROPERTY_ID_TABLENAME:
case PROPERTY_ID_SCHEMANAME:
case PROPERTY_ID_CATALOGNAME:
// empty string'S
rValue <<= rtl::OUString();
break;
case PROPERTY_ID_ISROWVERSION:
case PROPERTY_ID_ISAUTOINCREMENT:
case PROPERTY_ID_ISWRITABLE:
case PROPERTY_ID_ISDEFINITELYWRITABLE:
case PROPERTY_ID_ISCASESENSITIVE:
case PROPERTY_ID_ISSEARCHABLE:
case PROPERTY_ID_ISCURRENCY:
case PROPERTY_ID_ISSIGNED:
{
sal_Bool bVal = sal_False;
rValue.setValue(&bVal, getBooleanCppuType());
} break;
case PROPERTY_ID_ISREADONLY:
{
sal_Bool bVal = sal_True;
rValue.setValue(&bVal, getBooleanCppuType());
} break;
case PROPERTY_ID_SCALE:
case PROPERTY_ID_PRECISION:
case PROPERTY_ID_DISPLAYSIZE:
rValue <<= sal_Int32(0);
break;
case PROPERTY_ID_TYPE:
rValue <<= sal_Int32(DataType::SQLNULL);
break;
case PROPERTY_ID_ISNULLABLE:
rValue <<= ColumnValue::NULLABLE_UNKNOWN;
break;
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|