Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * Effective License of whole file:
5 : *
6 : * This library is free software; you can redistribute it and/or
7 : * modify it under the terms of the GNU Lesser General Public
8 : * License version 2.1, as published by the Free Software Foundation.
9 : *
10 : * This library is distributed in the hope that it will be useful,
11 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 : * Lesser General Public License for more details.
14 : *
15 : * You should have received a copy of the GNU Lesser General Public
16 : * License along with this library; if not, write to the Free Software
17 : * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18 : * MA 02111-1307 USA
19 : *
20 : * Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
21 : *
22 : * The Contents of this file are made available subject to the terms of
23 : * the GNU Lesser General Public License Version 2.1
24 : *
25 : * Copyright: 2000 by Sun Microsystems, Inc.
26 : *
27 : * Contributor(s): Joerg Budischewski
28 : *
29 : * All parts contributed on or after August 2011:
30 : *
31 : * Version: MPL 1.1 / GPLv3+ / LGPLv2.1+
32 : *
33 : * The contents of this file are subject to the Mozilla Public License Version
34 : * 1.1 (the "License"); you may not use this file except in compliance with
35 : * the License or as specified alternatively below. You may obtain a copy of
36 : * the License at http://www.mozilla.org/MPL/
37 : *
38 : * Software distributed under the License is distributed on an "AS IS" basis,
39 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
40 : * for the specific language governing rights and limitations under the
41 : * License.
42 : *
43 : * Major Contributor(s):
44 : * [ Copyright (C) 2011 Lionel Elie Mamane <lionel@mamane.lu> ]
45 : *
46 : * All Rights Reserved.
47 : *
48 : * For minor contributions see the git repository.
49 : *
50 : * Alternatively, the contents of this file may be used under the terms of
51 : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
52 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPLv2.1+"),
53 : * in which case the provisions of the GPLv3+ or the LGPLv2.1+ are applicable
54 : * instead of those above.
55 : *
56 : ************************************************************************/
57 :
58 : #include "pq_statics.hxx"
59 : #include "pq_updateableresultset.hxx"
60 : #include <com/sun/star/sdbc/DataType.hpp>
61 : #include <com/sun/star/beans/PropertyAttribute.hpp>
62 :
63 : #include <string.h>
64 :
65 : using rtl::OUString;
66 : using com::sun::star::uno::Sequence;
67 : using com::sun::star::uno::Any;
68 : using com::sun::star::uno::Type;
69 :
70 : using com::sun::star::beans::PropertyAttribute::READONLY;
71 : using com::sun::star::beans::PropertyAttribute::BOUND;
72 : using com::sun::star::beans::Property;
73 :
74 : namespace pq_sdbc_driver
75 : {
76 :
77 : struct DefColumnMetaData
78 : {
79 : const sal_Char * columnName;
80 : const sal_Char * tableName;
81 : const sal_Char * schemaTableName;
82 : const sal_Char * typeName;
83 : sal_Int32 type;
84 : sal_Int32 precision;
85 : sal_Int32 scale;
86 : sal_Bool isCurrency;
87 : sal_Bool isNullable;
88 : sal_Bool isAutoIncrement;
89 : sal_Bool isReadOnly;
90 : sal_Bool isSigned;
91 : };
92 :
93 : #define ASCII_STR(x) OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
94 : struct BaseTypeDef { const char * typeName; sal_Int32 value; };
95 :
96 0 : static Sequence< OUString > createStringSequence( const char * names[] )
97 : {
98 0 : int length = 0;
99 0 : while (names[length])
100 0 : ++length;
101 :
102 0 : Sequence< OUString > seq( length );
103 0 : for( int i = 0; i < length; i ++ )
104 : {
105 0 : seq[i] = OUString( names[i] , strlen( names[i] ), RTL_TEXTENCODING_ASCII_US );
106 : }
107 0 : return seq;
108 : }
109 :
110 0 : struct PropertyDef
111 : {
112 0 : PropertyDef( const OUString &str, const Type &t )
113 0 : : name( str ) , type( t ) {}
114 : ::rtl::OUString name;
115 : com::sun::star::uno::Type type;
116 : };
117 :
118 0 : struct PropertyDefEx : public PropertyDef
119 : {
120 0 : PropertyDefEx( const OUString & str, const Type &t , sal_Int32 a )
121 0 : : PropertyDef( str, t ) , attribute( a )
122 0 : {}
123 : sal_Int32 attribute;
124 : };
125 :
126 0 : static cppu::IPropertyArrayHelper * createPropertyArrayHelper(
127 : PropertyDef *props, int count , sal_Int16 attr )
128 : {
129 0 : Sequence< Property > seq( count );
130 0 : for( int i = 0 ; i < count ; i ++ )
131 : {
132 0 : seq[i] = Property( props[i].name, i, props[i].type, attr );
133 : }
134 0 : return new cppu::OPropertyArrayHelper( seq, sal_True );
135 : }
136 :
137 0 : static cppu::IPropertyArrayHelper * createPropertyArrayHelper(
138 : PropertyDefEx *props, int count )
139 : {
140 0 : Sequence< Property > seq( count );
141 0 : for( int i = 0 ; i < count ; i ++ )
142 : {
143 0 : seq[i] = Property( props[i].name, i, props[i].type, props[i].attribute );
144 : }
145 0 : return new cppu::OPropertyArrayHelper( seq, sal_True );
146 : }
147 :
148 0 : Statics & getStatics()
149 : {
150 : static Statics * p;
151 0 : if( ! p )
152 : {
153 0 : ::osl::MutexGuard guard( ::osl::Mutex::getGlobalMutex() );
154 0 : if( ! p )
155 : {
156 0 : static Statics statics ;
157 0 : statics.SYSTEM_TABLE = ASCII_STR( "SYSTEM TABLE" );
158 0 : statics.TABLE = ASCII_STR( "TABLE" );
159 0 : statics.VIEW = ASCII_STR( "VIEW" );
160 0 : statics.UNKNOWN = ASCII_STR( "UNKNOWN" );
161 0 : statics.YES = ASCII_STR( "YES" );
162 0 : statics.NO = ASCII_STR( "NO" );
163 0 : statics.NO_NULLS = ASCII_STR( "NO_NULLS" );
164 0 : statics.NULABLE = ASCII_STR( "NULABLE" );
165 0 : statics.NULLABLE_UNKNOWN = ASCII_STR( "NULLABLE_UNKNOWN" );
166 0 : statics.cPERCENT = ASCII_STR( "%" );
167 :
168 0 : statics.TYPE = ASCII_STR( "Type" );
169 0 : statics.TYPE_NAME = ASCII_STR( "TypeName" );
170 0 : statics.NAME = ASCII_STR( "Name" );
171 0 : statics.SCHEMA_NAME = ASCII_STR( "SchemaName" );
172 0 : statics.CATALOG_NAME = ASCII_STR( "CatalogName" );
173 0 : statics.DESCRIPTION = ASCII_STR( "Description" );
174 0 : statics.PRIVILEGES = ASCII_STR( "Privileges" );
175 :
176 0 : statics.DEFAULT_VALUE = ASCII_STR( "DefaultValue" );
177 0 : statics.IS_AUTO_INCREMENT = ASCII_STR( "IsAutoIncrement" );
178 0 : statics.IS_CURRENCY = ASCII_STR( "IsCurrency" );
179 0 : statics.IS_NULLABLE = ASCII_STR( "IsNullable" );
180 0 : statics.IS_ROW_VERSISON = ASCII_STR( "IsRowVersion" );
181 0 : statics.PRECISION = ASCII_STR( "Precision" );
182 0 : statics.SCALE = ASCII_STR( "Scale" );
183 :
184 0 : statics.cPERCENT = ASCII_STR( "%" );
185 0 : statics.BEGIN = ASCII_STR( "BEGIN" );
186 0 : statics.COMMIT = ASCII_STR( "COMMIT" );
187 0 : statics.ROLLBACK = ASCII_STR( "ROLLBACK" );
188 :
189 0 : statics.KEY = ASCII_STR( "Key" );
190 0 : statics.REFERENCED_TABLE = ASCII_STR( "ReferencedTable" );
191 0 : statics.UPDATE_RULE = ASCII_STR( "UpdateRule" );
192 0 : statics.DELETE_RULE = ASCII_STR( "DeleteRule" );
193 0 : statics.PRIVATE_COLUMNS = ASCII_STR( "PrivateColumns" );
194 0 : statics.PRIVATE_FOREIGN_COLUMNS = ASCII_STR( "PrivateForeignColumns" );
195 :
196 0 : statics.KEY_COLUMN = ASCII_STR( "KeyColumn" );
197 0 : statics.RELATED_COLUMN = ASCII_STR( "RelatedColumn" );
198 0 : statics.PASSWORD = ASCII_STR( "Password" );
199 0 : statics.USER = ASCII_STR( "User" );
200 :
201 0 : statics.CURSOR_NAME = ASCII_STR( "CursorName" );
202 0 : statics.ESCAPE_PROCESSING = ASCII_STR( "EscapeProcessing" );
203 0 : statics.FETCH_DIRECTION = ASCII_STR( "FetchDirection" );
204 0 : statics.FETCH_SIZE = ASCII_STR( "FetchSize" );
205 0 : statics.IS_BOOKMARKABLE = ASCII_STR( "IsBookmarkable" );
206 0 : statics.RESULT_SET_CONCURRENCY = ASCII_STR( "ResultSetConcurrency" );
207 0 : statics.RESULT_SET_TYPE = ASCII_STR( "ResultSetType" );
208 :
209 0 : statics.COMMAND = ASCII_STR( "Command" );
210 0 : statics.CHECK_OPTION = ASCII_STR( "CheckOption" );
211 :
212 0 : statics.TRUE = ASCII_STR( "t" );
213 0 : statics.FALSE = ASCII_STR( "f" );
214 0 : statics.IS_PRIMARY_KEY_INDEX = ASCII_STR( "IsPrimaryKeyIndex" );
215 0 : statics.IS_CLUSTERED = ASCII_STR( "IsClustered" );
216 0 : statics.IS_UNIQUE = ASCII_STR( "IsUnique" );
217 0 : statics.IS_ASCENDING = ASCII_STR( "IsAscending" );
218 0 : statics.PRIVATE_COLUMN_INDEXES = ASCII_STR( "PrivateColumnIndexes" );
219 0 : statics.HELP_TEXT = ASCII_STR( "HelpText" );
220 :
221 0 : statics.CATALOG = ASCII_STR( "Catalog" );
222 :
223 0 : Type tString = getCppuType( (rtl::OUString *) 0 );
224 0 : Type tInt = getCppuType( (sal_Int32 * ) 0 );
225 0 : Type tBool = getBooleanCppuType();
226 0 : Type tStringSequence = getCppuType( (com::sun::star::uno::Sequence< ::rtl::OUString > *) 0);
227 :
228 : // Table props set
229 0 : ImplementationStatics &ist = statics.refl.table;
230 0 : ist.implName = ASCII_STR( "org.openoffice.comp.pq.sdbcx.Table" );
231 0 : ist.serviceNames = Sequence< OUString > ( 1 );
232 0 : ist.serviceNames[0] = ASCII_STR( "com.sun.star.sdbcx.Table" );
233 : PropertyDef tableDef[] =
234 : {
235 : PropertyDef( statics.CATALOG_NAME , tString ),
236 : PropertyDef( statics.DESCRIPTION , tString ),
237 : PropertyDef( statics.NAME , tString ),
238 : PropertyDef( statics.PRIVILEGES , tInt ),
239 : PropertyDef( statics.SCHEMA_NAME , tString ),
240 : PropertyDef( statics.TYPE , tString )
241 0 : };
242 : ist.pProps = createPropertyArrayHelper(
243 0 : tableDef, sizeof(tableDef)/sizeof(PropertyDef), READONLY );
244 :
245 : statics.refl.tableDescriptor.implName =
246 0 : ASCII_STR( "org.openoffice.comp.pq.sdbcx.TableDescriptor" );
247 0 : statics.refl.tableDescriptor.serviceNames = Sequence< OUString > (1);
248 0 : statics.refl.tableDescriptor.serviceNames[0] =
249 0 : ASCII_STR( "com.sun.star.sdbcx.TableDescriptor" );
250 : PropertyDef tableDescDef[] =
251 : {
252 : PropertyDef( statics.CATALOG_NAME , tString ),
253 : PropertyDef( statics.DESCRIPTION , tString ),
254 : PropertyDef( statics.NAME , tString ),
255 : PropertyDef( statics.PRIVILEGES , tInt ),
256 : PropertyDef( statics.SCHEMA_NAME , tString )
257 0 : };
258 : statics.refl.tableDescriptor.pProps = createPropertyArrayHelper(
259 0 : tableDescDef, sizeof(tableDescDef)/sizeof(PropertyDef), 0 );
260 :
261 : // Column props set
262 0 : statics.refl.column.implName = ASCII_STR( "org.openoffice.comp.pq.sdbcx.Column" );
263 0 : statics.refl.column.serviceNames = Sequence< OUString > ( 1 );
264 0 : statics.refl.column.serviceNames[0] = ASCII_STR( "com.sun.star.sdbcx.Column" );
265 : PropertyDefEx columnDef[] =
266 : {
267 : PropertyDefEx( statics.CATALOG_NAME , tString, READONLY ),
268 : PropertyDefEx( statics.DEFAULT_VALUE, tString, READONLY ),
269 : PropertyDefEx( statics.DESCRIPTION , tString, READONLY ),
270 : // PropertyDefEx( statics.HELP_TEXT , tString, BOUND ),
271 : PropertyDefEx( statics.IS_AUTO_INCREMENT, tBool, READONLY ),
272 : PropertyDefEx( statics.IS_CURRENCY, tBool, READONLY ),
273 : PropertyDefEx( statics.IS_NULLABLE, tInt, READONLY ),
274 : PropertyDefEx( statics.IS_ROW_VERSISON, tBool,READONLY ),
275 : PropertyDefEx( statics.NAME , tString,READONLY ),
276 : PropertyDefEx( statics.PRECISION , tInt, READONLY ),
277 : PropertyDefEx( statics.SCALE , tInt ,READONLY),
278 : PropertyDefEx( statics.TYPE , tInt ,READONLY),
279 : PropertyDefEx( statics.TYPE_NAME , tString ,READONLY)
280 0 : };
281 : statics.refl.column.pProps = createPropertyArrayHelper(
282 0 : columnDef, sizeof(columnDef)/sizeof(PropertyDefEx) );
283 :
284 : statics.refl.columnDescriptor.implName =
285 0 : ASCII_STR( "org.openoffice.comp.pq.sdbcx.ColumnDescriptor" );
286 0 : statics.refl.columnDescriptor.serviceNames = Sequence< OUString > ( 1 );
287 0 : statics.refl.columnDescriptor.serviceNames[0] =
288 0 : ASCII_STR( "com.sun.star.sdbcx.ColumnDescriptor" );
289 : PropertyDef columnDescDef[] =
290 : {
291 : PropertyDef( statics.CATALOG_NAME , tString ),
292 : PropertyDef( statics.DEFAULT_VALUE, tString ),
293 : PropertyDef( statics.DESCRIPTION , tString ),
294 : // PropertyDef( statics.HELP_TEXT , tString ),
295 : PropertyDef( statics.IS_AUTO_INCREMENT, tBool ),
296 : PropertyDef( statics.IS_CURRENCY, tBool ),
297 : PropertyDef( statics.IS_NULLABLE, tInt ),
298 : PropertyDef( statics.IS_ROW_VERSISON, tBool ),
299 : PropertyDef( statics.NAME , tString ),
300 : PropertyDef( statics.PRECISION , tInt ),
301 : PropertyDef( statics.SCALE , tInt ),
302 : PropertyDef( statics.TYPE , tInt ),
303 : PropertyDef( statics.TYPE_NAME , tString )
304 0 : };
305 :
306 : statics.refl.columnDescriptor.pProps = createPropertyArrayHelper(
307 0 : columnDescDef, sizeof(columnDescDef)/sizeof(PropertyDef), 0 );
308 :
309 : // Key properties
310 0 : statics.refl.key.implName = ASCII_STR( "org.openoffice.comp.pq.sdbcx.Key" );
311 0 : statics.refl.key.serviceNames = Sequence< OUString > ( 1 );
312 0 : statics.refl.key.serviceNames[0] = ASCII_STR( "com.sun.star.sdbcx.Key" );
313 : PropertyDef keyDef[] =
314 : {
315 : PropertyDef( statics.DELETE_RULE, tInt ),
316 : PropertyDef( statics.NAME, tString ),
317 : PropertyDef( statics.PRIVATE_COLUMNS, tStringSequence ),
318 : PropertyDef( statics.PRIVATE_FOREIGN_COLUMNS, tStringSequence ),
319 : PropertyDef( statics.REFERENCED_TABLE, tString ),
320 : PropertyDef( statics.TYPE, tInt ),
321 : PropertyDef( statics.UPDATE_RULE, tInt )
322 0 : };
323 : statics.refl.key.pProps = createPropertyArrayHelper(
324 0 : keyDef, sizeof(keyDef)/sizeof(PropertyDef), READONLY );
325 :
326 :
327 : // Key properties
328 : statics.refl.keyDescriptor.implName =
329 0 : ASCII_STR( "org.openoffice.comp.pq.sdbcx.KeyDescriptor" );
330 0 : statics.refl.keyDescriptor.serviceNames = Sequence< OUString > ( 1 );
331 0 : statics.refl.keyDescriptor.serviceNames[0] =
332 0 : ASCII_STR( "com.sun.star.sdbcx.KeyDescriptor" );
333 : PropertyDef keyDescDef[] =
334 : {
335 : PropertyDef( statics.DELETE_RULE, tInt ),
336 : PropertyDef( statics.NAME, tString ),
337 : PropertyDef( statics.REFERENCED_TABLE, tString ),
338 : PropertyDef( statics.TYPE, tInt ),
339 : PropertyDef( statics.UPDATE_RULE, tInt )
340 0 : };
341 : statics.refl.keyDescriptor.pProps = createPropertyArrayHelper(
342 0 : keyDescDef, sizeof(keyDescDef)/sizeof(PropertyDef), 0 );
343 :
344 :
345 :
346 : // KeyColumn props set
347 0 : statics.refl.keycolumn.implName = ASCII_STR( "org.openoffice.comp.pq.sdbcx.KeyColumn" );
348 0 : statics.refl.keycolumn.serviceNames = Sequence< OUString > ( 1 );
349 0 : statics.refl.keycolumn.serviceNames[0] = ASCII_STR( "com.sun.star.sdbcx.KeyColumn" );
350 : PropertyDef keycolumnDef[] =
351 : {
352 : PropertyDef( statics.CATALOG_NAME , tString ),
353 : PropertyDef( statics.DEFAULT_VALUE, tString ),
354 : PropertyDef( statics.DESCRIPTION , tString ),
355 : PropertyDef( statics.IS_AUTO_INCREMENT, tBool ),
356 : PropertyDef( statics.IS_CURRENCY, tBool ),
357 : PropertyDef( statics.IS_NULLABLE, tInt ),
358 : PropertyDef( statics.IS_ROW_VERSISON, tBool ),
359 : PropertyDef( statics.NAME , tString ),
360 : PropertyDef( statics.PRECISION , tInt ),
361 : PropertyDef( statics.RELATED_COLUMN, tString ),
362 : PropertyDef( statics.SCALE , tInt ),
363 : PropertyDef( statics.TYPE , tInt ),
364 : PropertyDef( statics.TYPE_NAME , tString )
365 0 : };
366 : statics.refl.keycolumn.pProps = createPropertyArrayHelper(
367 0 : keycolumnDef, sizeof(keycolumnDef)/sizeof(PropertyDef), READONLY );
368 :
369 : // KeyColumn props set
370 : statics.refl.keycolumnDescriptor.implName =
371 0 : ASCII_STR( "org.openoffice.comp.pq.sdbcx.KeyColumnDescriptor" );
372 0 : statics.refl.keycolumnDescriptor.serviceNames = Sequence< OUString > ( 1 );
373 0 : statics.refl.keycolumnDescriptor.serviceNames[0] =
374 0 : ASCII_STR( "com.sun.star.sdbcx.KeyColumnDescriptor" );
375 : PropertyDef keycolumnDescDef[] =
376 : {
377 : PropertyDef( statics.NAME , tString ),
378 : PropertyDef( statics.RELATED_COLUMN, tString )
379 0 : };
380 : statics.refl.keycolumnDescriptor.pProps = createPropertyArrayHelper(
381 0 : keycolumnDescDef, sizeof(keycolumnDescDef)/sizeof(PropertyDef), 0 );
382 :
383 : // view props set
384 0 : statics.refl.view.implName = ASCII_STR( "org.openoffice.comp.pq.sdbcx.View");
385 0 : statics.refl.view.serviceNames = Sequence< OUString > ( 1 );
386 0 : statics.refl.view.serviceNames[0] = ASCII_STR( "com.sun.star.sdbcx.View" );
387 : PropertyDef viewDef[] =
388 : {
389 : PropertyDef( statics.CATALOG_NAME , tString ),
390 : PropertyDef( statics.CHECK_OPTION , tInt ),
391 : PropertyDef( statics.COMMAND , tString ),
392 : PropertyDef( statics.NAME , tString ),
393 : PropertyDef( statics.SCHEMA_NAME , tString )
394 0 : };
395 : statics.refl.view.pProps = createPropertyArrayHelper(
396 0 : viewDef, sizeof(viewDef)/sizeof(PropertyDef), READONLY );
397 :
398 : // view props set
399 0 : statics.refl.viewDescriptor.implName = ASCII_STR( "org.openoffice.comp.pq.sdbcx.ViewDescriptor");
400 0 : statics.refl.viewDescriptor.serviceNames = Sequence< OUString > ( 1 );
401 0 : statics.refl.viewDescriptor.serviceNames[0] = ASCII_STR( "com.sun.star.sdbcx.ViewDescriptor" );
402 : statics.refl.viewDescriptor.pProps = createPropertyArrayHelper(
403 0 : viewDef, sizeof(viewDef)/sizeof(PropertyDef), 0 ); // reuse view, as it is identical
404 : // user props set
405 0 : statics.refl.user.implName = ASCII_STR( "org.openoffice.comp.pq.sdbcx.User");
406 0 : statics.refl.user.serviceNames = Sequence< OUString > ( 1 );
407 0 : statics.refl.user.serviceNames[0] = ASCII_STR( "com.sun.star.sdbcx.User" );
408 : PropertyDef userDefRO[] =
409 : {
410 : PropertyDef( statics.NAME , tString )
411 0 : };
412 : statics.refl.user.pProps = createPropertyArrayHelper(
413 0 : userDefRO, sizeof(userDefRO)/sizeof(PropertyDef), READONLY );
414 :
415 : // user props set
416 : statics.refl.userDescriptor.implName =
417 0 : ASCII_STR( "org.openoffice.comp.pq.sdbcx.UserDescriptor");
418 0 : statics.refl.userDescriptor.serviceNames = Sequence< OUString > ( 1 );
419 0 : statics.refl.userDescriptor.serviceNames[0] =
420 0 : ASCII_STR( "com.sun.star.sdbcx.UserDescriptor" );
421 : PropertyDef userDefWR[] =
422 : {
423 : PropertyDef( statics.NAME , tString ),
424 : PropertyDef( statics.PASSWORD , tString )
425 0 : };
426 : statics.refl.userDescriptor.pProps = createPropertyArrayHelper(
427 0 : userDefWR, sizeof(userDefWR)/sizeof(PropertyDef), 0 );
428 :
429 : // index props set
430 0 : statics.refl.index.implName = ASCII_STR( "org.openoffice.comp.pq.sdbcx.Index");
431 0 : statics.refl.index.serviceNames = Sequence< OUString > ( 1 );
432 0 : statics.refl.index.serviceNames[0] = ASCII_STR( "com.sun.star.sdbcx.Index" );
433 : PropertyDef indexDef[] =
434 : {
435 : PropertyDef( statics.CATALOG , tString ),
436 : PropertyDef( statics.IS_CLUSTERED, tBool ),
437 : PropertyDef( statics.IS_PRIMARY_KEY_INDEX, tBool ),
438 : PropertyDef( statics.IS_UNIQUE, tBool ),
439 : PropertyDef( statics.NAME , tString ),
440 : PropertyDef( statics.PRIVATE_COLUMN_INDEXES, tStringSequence )
441 0 : };
442 : statics.refl.index.pProps = createPropertyArrayHelper(
443 0 : indexDef, sizeof(indexDef)/sizeof(PropertyDef), READONLY );
444 :
445 : // index props set
446 : statics.refl.indexDescriptor.implName =
447 0 : ASCII_STR( "org.openoffice.comp.pq.sdbcx.IndexDescriptor");
448 0 : statics.refl.indexDescriptor.serviceNames = Sequence< OUString > ( 1 );
449 0 : statics.refl.indexDescriptor.serviceNames[0] =
450 0 : ASCII_STR( "com.sun.star.sdbcx.IndexDescriptor" );
451 : statics.refl.indexDescriptor.pProps = createPropertyArrayHelper(
452 0 : indexDef, sizeof(indexDef)/sizeof(PropertyDef), 0 );
453 :
454 : // indexColumn props set
455 0 : statics.refl.indexColumn.implName = ASCII_STR( "org.openoffice.comp.pq.sdbcx.IndexColumn");
456 0 : statics.refl.indexColumn.serviceNames = Sequence< OUString > ( 1 );
457 0 : statics.refl.indexColumn.serviceNames[0] = ASCII_STR("com.sun.star.sdbcx.IndexColumn");
458 : PropertyDef indexColumnDef[] =
459 : {
460 : PropertyDef( statics.CATALOG_NAME , tString ),
461 : PropertyDef( statics.DEFAULT_VALUE, tString ),
462 : PropertyDef( statics.DESCRIPTION , tString ),
463 : PropertyDef( statics.IS_ASCENDING, tBool ),
464 : PropertyDef( statics.IS_AUTO_INCREMENT, tBool ),
465 : PropertyDef( statics.IS_CURRENCY, tBool ),
466 : PropertyDef( statics.IS_NULLABLE, tInt ),
467 : PropertyDef( statics.IS_ROW_VERSISON, tBool ),
468 : PropertyDef( statics.NAME , tString ),
469 : PropertyDef( statics.PRECISION , tInt ),
470 : PropertyDef( statics.SCALE , tInt ),
471 : PropertyDef( statics.TYPE , tInt ),
472 : PropertyDef( statics.TYPE_NAME , tString )
473 0 : };
474 : statics.refl.indexColumn.pProps = createPropertyArrayHelper(
475 0 : indexColumnDef, sizeof(indexColumnDef)/sizeof(PropertyDef), READONLY );
476 :
477 : // indexColumn props set
478 : statics.refl.indexColumnDescriptor.implName =
479 0 : ASCII_STR( "org.openoffice.comp.pq.sdbcx.IndexColumnDescriptor");
480 0 : statics.refl.indexColumnDescriptor.serviceNames = Sequence< OUString > ( 1 );
481 0 : statics.refl.indexColumnDescriptor.serviceNames[0] =
482 0 : ASCII_STR("com.sun.star.sdbcx.IndexColumnDescriptor");
483 : PropertyDef indexColumnDescDef[] =
484 : {
485 : PropertyDef( statics.IS_ASCENDING, tBool ),
486 : PropertyDef( statics.NAME , tString )
487 0 : };
488 : statics.refl.indexColumnDescriptor.pProps = createPropertyArrayHelper(
489 0 : indexColumnDescDef, sizeof(indexColumnDescDef)/sizeof(PropertyDef), 0 );
490 :
491 : // resultset
492 0 : statics.refl.resultSet.implName = ASCII_STR( "org.openoffice.comp.pq.ResultSet");
493 0 : statics.refl.resultSet.serviceNames = Sequence< OUString > ( 1 );
494 0 : statics.refl.resultSet.serviceNames[0] = ASCII_STR( "com.sun.star.sdbc.ResultSet" );
495 0 : statics.refl.resultSet.types = UpdateableResultSet::getStaticTypes( false /* updateable */ );
496 : PropertyDef resultSet[] =
497 : {
498 : PropertyDef( statics.CURSOR_NAME , tString ),
499 : PropertyDef( statics.ESCAPE_PROCESSING , tBool ),
500 : PropertyDef( statics.FETCH_DIRECTION , tInt ),
501 : PropertyDef( statics.FETCH_SIZE , tInt ),
502 : PropertyDef( statics.IS_BOOKMARKABLE , tBool ),
503 : PropertyDef( statics.RESULT_SET_CONCURRENCY , tInt ),
504 : PropertyDef( statics.RESULT_SET_TYPE , tInt )
505 0 : };
506 : statics.refl.resultSet.pProps = createPropertyArrayHelper(
507 0 : resultSet, sizeof(resultSet)/sizeof(PropertyDef), 0 );
508 :
509 : // updateableResultset
510 0 : statics.refl.updateableResultSet.implName = ASCII_STR( "org.openoffice.comp.pq.UpdateableResultSet");
511 0 : statics.refl.updateableResultSet.serviceNames = Sequence< OUString > ( 1 );
512 0 : statics.refl.updateableResultSet.serviceNames[0] = ASCII_STR( "com.sun.star.sdbc.ResultSet" );
513 0 : statics.refl.updateableResultSet.types = UpdateableResultSet::getStaticTypes( true /* updateable */ );
514 : statics.refl.updateableResultSet.pProps = createPropertyArrayHelper(
515 0 : resultSet, sizeof(resultSet)/sizeof(PropertyDef), 0 );
516 :
517 : // databasemetadata
518 0 : statics.tablesRowNames = Sequence< OUString > ( 5 );
519 0 : statics.tablesRowNames[TABLE_INDEX_CATALOG] = ASCII_STR( "TABLE_CAT" );
520 0 : statics.tablesRowNames[TABLE_INDEX_SCHEMA] = ASCII_STR( "TABLE_SCHEM" );
521 0 : statics.tablesRowNames[TABLE_INDEX_NAME] = ASCII_STR( "TABLE_NAME" );
522 0 : statics.tablesRowNames[TABLE_INDEX_TYPE] = ASCII_STR( "TABLE_TYPE" );
523 0 : statics.tablesRowNames[TABLE_INDEX_REMARKS] = ASCII_STR( "REMARKS" );
524 :
525 0 : statics.primaryKeyNames = Sequence< OUString > ( 6 );
526 0 : statics.primaryKeyNames[0] = ASCII_STR( "TABLE_CAT" );
527 0 : statics.primaryKeyNames[1] = ASCII_STR( "TABLE_SCHEM" );
528 0 : statics.primaryKeyNames[2] = ASCII_STR( "TABLE_NAME" );
529 0 : statics.primaryKeyNames[3] = ASCII_STR( "COLUMN_NAME" );
530 0 : statics.primaryKeyNames[4] = ASCII_STR( "KEY_SEQ" );
531 0 : statics.primaryKeyNames[5] = ASCII_STR( "PK_NAME" );
532 :
533 0 : statics.SELECT = ASCII_STR( "SELECT" );
534 0 : statics.UPDATE = ASCII_STR( "UPDATE" );
535 0 : statics.INSERT = ASCII_STR( "INSERT" );
536 0 : statics.DELETE = ASCII_STR( "DELETE" );
537 0 : statics.RULE = ASCII_STR( "RULE" );
538 0 : statics.REFERENCES = ASCII_STR( "REFERENCES" );
539 0 : statics.TRIGGER = ASCII_STR( "TRIGGER" );
540 0 : statics.EXECUTE = ASCII_STR( "EXECUTE" );
541 0 : statics.USAGE = ASCII_STR( "USAGE" );
542 0 : statics.CREATE = ASCII_STR( "CREATE" );
543 0 : statics.TEMPORARY = ASCII_STR( "TEMPORARY" );
544 0 : statics.INDEX = ASCII_STR( "Index" );
545 0 : statics.INDEX_COLUMN = ASCII_STR( "IndexColumn" );
546 :
547 0 : statics.schemaNames = Sequence< OUString > ( 1 );
548 0 : statics.schemaNames[0] = ASCII_STR( "TABLE_SCHEM" );
549 :
550 0 : statics.tableTypeData = Sequence< Sequence< Any > >( 2 );
551 :
552 0 : statics.tableTypeData[0] = Sequence< Any > ( 1 );
553 0 : statics.tableTypeData[0][0] <<= statics.TABLE;
554 :
555 : // statics.tableTypeData[2] = Sequence< Any > ( 1 );
556 : // statics.tableTypeData[2][0] <<= statics.VIEW;
557 :
558 0 : statics.tableTypeData[1] = Sequence< Any > ( 1 );
559 0 : statics.tableTypeData[1][0] <<= statics.SYSTEM_TABLE;
560 :
561 0 : statics.tableTypeNames = Sequence< OUString > ( 1 );
562 0 : statics.tableTypeNames[0] = ASCII_STR( "TABLE_TYPE" );
563 :
564 : static const char *tablePrivilegesNames[] =
565 : {
566 : "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "GRANTOR", "GRANTEE", "PRIVILEGE",
567 : "IS_GRANTABLE" , 0
568 : };
569 : statics.tablePrivilegesNames =
570 0 : createStringSequence( tablePrivilegesNames );
571 :
572 : static const char * columnNames[] =
573 : {
574 : "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME",
575 : "DATA_TYPE", "TYPE_NAME", "COLUMN_SIZE", "BUFFER_LENGTH",
576 : "DECIMAL_DIGITS", "NUM_PREC_RADIX", "NULLABLE", "REMARKS",
577 : "COLUMN_DEF", "SQL_DATA_TYPE", "SQL_DATETIME_SUB", "CHAR_OCTET_LENGTH",
578 : "ORDINAL_POSITION", "IS_NULLABLE", 0
579 : };
580 : statics.columnRowNames =
581 0 : createStringSequence( columnNames );
582 :
583 : static const char * typeinfoColumnNames[] =
584 : {
585 : "TYPE_NAME", "DATA_TYPE", "PRECISION", "LITERAL_PREFIX",
586 : "LITERAL_SUFFIX", "CREATE_PARAMS", "NULLABLE", "CASE_SENSITIVE",
587 : "SEARCHABLE", "UNSIGNED_ATTRIBUTE", "FIXED_PREC_SCALE",
588 : "AUTO_INCREMENT", "LOCAL_TYPE_NAME", "MINIMUM_SCALE",
589 : "MAXIMUM_SCALE", "SQL_DATA_TYPE", "SQL_DATETIME_SUB",
590 : "NUM_PREC_RADIX", 0
591 : };
592 0 : statics.typeinfoColumnNames = createStringSequence( typeinfoColumnNames );
593 :
594 : static const char * indexinfoColumnNames[] =
595 : {
596 : "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME",
597 : "NON_UNIQUE", "INDEX_QUALIFIER", "INDEX_NAME",
598 : "TYPE", "ORDINAL_POSITION", "COLUMN_NAME",
599 : "ASC_OR_DESC", "CARDINALITY", "PAGES", "FILTER_CONDITION",0
600 : };
601 0 : statics.indexinfoColumnNames = createStringSequence( indexinfoColumnNames );
602 :
603 : static const char * importedKeysColumnNames[] =
604 : {
605 : "PKTABLE_CAT" ,
606 : "PKTABLE_SCHEM",
607 : "PKTABLE_NAME" ,
608 : "PKCOLUMN_NAME",
609 : "FKTABLE_CAT" ,
610 : "FKTABLE_SCHEM",
611 : "FKTABLE_NAME" ,
612 : "FKCOLUMN_NAME",
613 : "KEY_SEQ" ,
614 : "UPDATE_RULE",
615 : "DELETE_RULE",
616 : "FK_NAME" ,
617 : "PK_NAME" ,
618 : "DEFERRABILITY" ,
619 : 0
620 : };
621 : statics.importedKeysColumnNames =
622 0 : createStringSequence( importedKeysColumnNames );
623 :
624 : static const char * resultSetArrayColumnNames[] = { "INDEX" , "VALUE", 0 };
625 : statics.resultSetArrayColumnNames =
626 0 : createStringSequence( resultSetArrayColumnNames );
627 :
628 : // LEM TODO see if a refresh is needed; obtain automatically from pg_catalog.pg_type?
629 : BaseTypeDef baseTypeDefs[] =
630 : {
631 : { "bool" , com::sun::star::sdbc::DataType::BIT },
632 : { "bytea", com::sun::star::sdbc::DataType::VARBINARY },
633 : { "char" , com::sun::star::sdbc::DataType::CHAR },
634 :
635 : { "int8" , com::sun::star::sdbc::DataType::BIGINT },
636 : { "serial8" , com::sun::star::sdbc::DataType::BIGINT },
637 :
638 :
639 : { "int2" , com::sun::star::sdbc::DataType::SMALLINT },
640 :
641 : { "int4" , com::sun::star::sdbc::DataType::INTEGER },
642 : // { "regproc" , com::sun::star::sdbc::DataType::INTEGER },
643 : // { "oid" , com::sun::star::sdbc::DataType::INTEGER },
644 : // { "xid" , com::sun::star::sdbc::DataType::INTEGER },
645 : // { "cid" , com::sun::star::sdbc::DataType::INTEGER },
646 : // { "serial", com::sun::star::sdbc::DataType::INTEGER },
647 : // { "serial4", com::sun::star::sdbc::DataType::INTEGER },
648 :
649 : { "text", com::sun::star::sdbc::DataType::VARCHAR },
650 : { "bpchar", com::sun::star::sdbc::DataType::CHAR },
651 : { "varchar", com::sun::star::sdbc::DataType::VARCHAR },
652 :
653 : { "float4", com::sun::star::sdbc::DataType::REAL },
654 : { "float8", com::sun::star::sdbc::DataType::DOUBLE },
655 :
656 : { "numeric", com::sun::star::sdbc::DataType::NUMERIC },
657 : { "decimal", com::sun::star::sdbc::DataType::DECIMAL },
658 :
659 : { "date", com::sun::star::sdbc::DataType::DATE },
660 : { "time", com::sun::star::sdbc::DataType::TIME },
661 : { "timestamp", com::sun::star::sdbc::DataType::TIMESTAMP },
662 :
663 : // { "_bool" , com::sun::star::sdbc::DataType::ARRAY },
664 : // { "_bytea", com::sun::star::sdbc::DataType::ARRAY },
665 : // { "_char" , com::sun::star::sdbc::DataType::ARRAY },
666 :
667 : // { "_int8" , com::sun::star::sdbc::DataType::ARRAY },
668 : // { "_serial8" , com::sun::star::sdbc::DataType::ARRAY },
669 :
670 :
671 : // { "_int2" , com::sun::star::sdbc::DataType::ARRAY },
672 :
673 : // { "_int4" , com::sun::star::sdbc::DataType::ARRAY },
674 : // { "_regproc" , com::sun::star::sdbc::DataType::ARRAY },
675 : // { "_oid" , com::sun::star::sdbc::DataType::ARRAY },
676 : // { "_xid" , com::sun::star::sdbc::DataType::ARRAY },
677 : // { "_cid" , com::sun::star::sdbc::DataType::ARRAY },
678 :
679 : // { "_text", com::sun::star::sdbc::DataType::ARRAY },
680 : // { "_bpchar", com::sun::star::sdbc::DataType::ARRAY },
681 : // { "_varchar", com::sun::star::sdbc::DataType::ARRAY },
682 :
683 : // { "_float4", com::sun::star::sdbc::DataType::ARRAY },
684 : // { "_float8", com::sun::star::sdbc::DataType::ARRAY },
685 :
686 : // { "_numeric", com::sun::star::sdbc::DataType::ARRAY },
687 : // { "_decimal", com::sun::star::sdbc::DataType::ARRAY },
688 :
689 : // { "_date", com::sun::star::sdbc::DataType::ARRAY }, // switch to date later
690 : // { "_time", com::sun::star::sdbc::DataType::ARRAY }, // switch to time later
691 :
692 : { 0, 0 }
693 0 : };
694 : int i;
695 0 : for( i = 0 ; baseTypeDefs[i].typeName ; i ++ )
696 : {
697 : statics.baseTypeMap[
698 0 : OUString::createFromAscii( baseTypeDefs[i].typeName) ] =
699 0 : baseTypeDefs[i].value;
700 : }
701 :
702 : // This is the metadata for the columns of the recordset returned
703 : // by ::com::sun::star::sdbc::XDatabaseMetaData::getTypeInfo(),
704 : // that is what is returned by getTypeInfo().getMetaData()
705 : DefColumnMetaData defTypeInfoMetaData[] =
706 : {
707 : { "TYPE_NAME", "TYPEINFO", "pg_catalog", "", com::sun::star::sdbc::DataType::VARCHAR, 0,50,0,0,0,0, false }, // 0
708 : { "DATA_TYPE", "TYPEINFO", "pg_catalog", "", com::sun::star::sdbc::DataType::SMALLINT, 0,50,0,0,0,0, true }, // 1
709 : { "PRECISION", "TYPEINFO", "pg_catalog", "", com::sun::star::sdbc::DataType::INTEGER, 0,50,0,0,0,0, true }, // 2
710 : { "LITERAL_PREFIX", "TYPEINFO", "pg_catalog", "", com::sun::star::sdbc::DataType::VARCHAR, 0,50,0,0,0,0, false }, // 3
711 : { "LITERAL_SUFFIX", "TYPEINFO", "pg_catalog", "", com::sun::star::sdbc::DataType::VARCHAR, 0,50,0,0,0,0, false }, // 4
712 : { "CREATE_PARAMS", "TYPEINFO", "pg_catalog", "", com::sun::star::sdbc::DataType::VARCHAR, 0,50,0,0,0,0, false }, // 5
713 : { "NULLABLE", "TYPEINFO", "pg_catalog", "", com::sun::star::sdbc::DataType::INTEGER, 0,50,0,0,0,0, true }, // 6
714 : { "CASE_SENSITIVE", "TYPEINFO", "pg_catalog", "", com::sun::star::sdbc::DataType::BIT, 0,50,0,0,0,0, false }, // 7
715 : { "SEARCHABLE", "TYPEINFO", "pg_catalog", "", com::sun::star::sdbc::DataType::SMALLINT, 0,50,0,0,0,0, true }, // 8
716 : { "UNSIGNED_ATTRIBUTE", "TYPEINFO", "pg_catalog", "", com::sun::star::sdbc::DataType::BIT, 0,50,0,0,0,0, false }, // 9
717 : { "FIXED_PREC_SCALE", "TYPEINFO", "pg_catalog", "", com::sun::star::sdbc::DataType::BIT, 0,50,0,0,0,0, false }, // 10
718 : { "AUTO_INCREMENT", "TYPEINFO", "pg_catalog", "", com::sun::star::sdbc::DataType::BIT, 0,50,0,0,0,0, false }, // 11
719 : { "LOCAL_TYPE_NAME", "TYPEINFO", "pg_catalog", "", com::sun::star::sdbc::DataType::VARCHAR, 0,50,0,0,0,0, false }, // 12
720 : { "MINIMUM_SCALE", "TYPEINFO", "pg_catalog", "", com::sun::star::sdbc::DataType::SMALLINT, 0,50,0,0,0,0, true}, // 13
721 : { "MAXIMUM_SCALE", "TYPEINFO", "pg_catalog", "", com::sun::star::sdbc::DataType::SMALLINT, 0,50,0,0,0,0, true }, // 14
722 : { "SQL_DATA_TYPE", "TYPEINFO", "pg_catalog", "", com::sun::star::sdbc::DataType::INTEGER, 0,50,0,0,0,0, true }, // 15
723 : { "SQL_DATETIME_SUB", "TYPEINFO", "pg_catalog", "", com::sun::star::sdbc::DataType::INTEGER, 0,50,0,0,0,0 , true}, // 16
724 : { "NUM_PREC_RADIX", "TYPEINFO", "pg_catalog", "", com::sun::star::sdbc::DataType::INTEGER, 0,50,0,0,0,0, true }, // 17
725 : {0,0,0,0,0,0,0,0,0,0,0, 0}
726 0 : };
727 :
728 0 : for( i = 0 ; defTypeInfoMetaData[i].columnName ; i++ )
729 : {
730 : statics.typeInfoMetaData.push_back(
731 : ColumnMetaData(
732 : rtl::OUString::createFromAscii( defTypeInfoMetaData[i].columnName ),
733 : rtl::OUString::createFromAscii( defTypeInfoMetaData[i].tableName ),
734 : rtl::OUString::createFromAscii( defTypeInfoMetaData[i].schemaTableName ),
735 : rtl::OUString::createFromAscii( defTypeInfoMetaData[i].typeName ),
736 : defTypeInfoMetaData[i].type,
737 : defTypeInfoMetaData[i].precision,
738 : defTypeInfoMetaData[i].scale,
739 : defTypeInfoMetaData[i].isCurrency,
740 : defTypeInfoMetaData[i].isNullable,
741 : defTypeInfoMetaData[i].isAutoIncrement,
742 : defTypeInfoMetaData[i].isReadOnly,
743 0 : defTypeInfoMetaData[i].isSigned ) );
744 : }
745 :
746 0 : p = &statics;
747 0 : }
748 : }
749 0 : return *p;
750 : }
751 :
752 :
753 :
754 : }
|