build fix
[LibreOffice.git] / connectivity / source / drivers / firebird / DatabaseMetaData.cxx
blob9e6d095ab6ff8660ec5bd86c255ace1ca8977b71
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "DatabaseMetaData.hxx"
21 #include "Util.hxx"
23 #include <ibase.h>
24 #include <rtl/ustrbuf.hxx>
25 #include <FDatabaseMetaDataResultSet.hxx>
27 #include <com/sun/star/sdbc/ColumnValue.hpp>
28 #include <com/sun/star/sdbc/DataType.hpp>
29 #include <com/sun/star/sdbc/IndexType.hpp>
30 #include <com/sun/star/sdbc/ResultSetType.hpp>
31 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
32 #include <com/sun/star/sdbc/TransactionIsolation.hpp>
33 #include <com/sun/star/sdbc/XParameters.hpp>
34 #include <com/sun/star/sdbc/XRow.hpp>
35 #include <com/sun/star/sdbc/KeyRule.hpp>
36 #include <com/sun/star/sdbc/Deferrability.hpp>
37 #include <com/sun/star/sdbc/DataType.hpp>
39 using namespace connectivity::firebird;
40 using namespace com::sun::star;
41 using namespace com::sun::star::uno;
42 using namespace com::sun::star::lang;
43 using namespace com::sun::star::beans;
44 using namespace com::sun::star::sdbc;
46 ODatabaseMetaData::ODatabaseMetaData(Connection* _pCon)
47 : m_pConnection(_pCon)
49 SAL_WARN_IF(!m_pConnection.is(), "connectivity.firebird",
50 "ODatabaseMetaData::ODatabaseMetaData: No connection set!");
53 ODatabaseMetaData::~ODatabaseMetaData()
57 //----- Catalog Info -- UNSUPPORTED -------------------------------------------
58 OUString SAL_CALL ODatabaseMetaData::getCatalogSeparator() throw(SQLException, RuntimeException, std::exception)
60 return OUString();
63 sal_Int32 SAL_CALL ODatabaseMetaData::getMaxCatalogNameLength() throw(SQLException, RuntimeException, std::exception)
65 return -1;
68 OUString SAL_CALL ODatabaseMetaData::getCatalogTerm() throw(SQLException, RuntimeException, std::exception)
70 return OUString();
73 sal_Bool SAL_CALL ODatabaseMetaData::isCatalogAtStart() throw(SQLException, RuntimeException, std::exception)
75 return false;
78 sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInTableDefinitions() throw(SQLException, RuntimeException, std::exception)
80 return false;
83 sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInIndexDefinitions() throw(SQLException, RuntimeException, std::exception)
85 return false;
88 sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInDataManipulation( ) throw(SQLException, RuntimeException, std::exception)
90 return false;
93 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getCatalogs() throw(SQLException, RuntimeException, std::exception)
95 OSL_FAIL("Not implemented yet!");
96 // TODO implement
97 return new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eCatalogs);
100 sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInProcedureCalls() throw(SQLException, RuntimeException, std::exception)
102 return false;
105 sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInPrivilegeDefinitions() throw(SQLException, RuntimeException, std::exception)
107 return false;
110 //----- Schema Info -- UNSUPPORTED --------------------------------------------
111 sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInProcedureCalls()
112 throw(SQLException, RuntimeException, std::exception)
114 return false;
117 sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInPrivilegeDefinitions()
118 throw(SQLException, RuntimeException, std::exception)
120 return false;
123 sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInDataManipulation()
124 throw(SQLException, RuntimeException, std::exception)
126 return false;
129 sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInIndexDefinitions()
130 throw(SQLException, RuntimeException, std::exception)
132 return false;
135 sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInTableDefinitions()
136 throw(SQLException, RuntimeException, std::exception)
138 return false;
141 sal_Int32 SAL_CALL ODatabaseMetaData::getMaxSchemaNameLength()
142 throw(SQLException, RuntimeException, std::exception)
144 return -1;
147 OUString SAL_CALL ODatabaseMetaData::getSchemaTerm()
148 throw(SQLException, RuntimeException, std::exception)
150 return OUString();
153 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getSchemas()
154 throw(SQLException, RuntimeException, std::exception)
156 OSL_FAIL("Not implemented yet!");
157 // TODO implement
158 return new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eSchemas);
161 //----- Max Sizes/Lengths -----------------------------------------------------
162 sal_Int32 SAL_CALL ODatabaseMetaData::getMaxBinaryLiteralLength() throw(SQLException, RuntimeException, std::exception)
164 return 32767;
167 sal_Int32 SAL_CALL ODatabaseMetaData::getMaxRowSize() throw(SQLException, RuntimeException, std::exception)
169 return 32767;
172 sal_Int32 SAL_CALL ODatabaseMetaData::getMaxCharLiteralLength() throw(SQLException, RuntimeException, std::exception)
174 return 32767;
177 sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnNameLength() throw(SQLException, RuntimeException, std::exception)
179 return 31;
182 sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInIndex() throw(SQLException, RuntimeException, std::exception)
184 // TODO: No idea.
185 // See: http://www.firebirdsql.org/en/firebird-technical-specifications/
186 return 16;
189 sal_Int32 SAL_CALL ODatabaseMetaData::getMaxCursorNameLength() throw(SQLException, RuntimeException, std::exception)
191 return 32;
194 sal_Int32 SAL_CALL ODatabaseMetaData::getMaxConnections() throw(SQLException, RuntimeException, std::exception)
196 return 100; // Arbitrary
199 sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInTable() throw(SQLException, RuntimeException, std::exception)
201 // May however be smaller.
202 // See: http://www.firebirdsql.org/en/firebird-technical-specifications/
203 return 32767;
206 sal_Int32 SAL_CALL ODatabaseMetaData::getMaxStatementLength() throw(SQLException, RuntimeException, std::exception)
208 return 32767;
211 sal_Int32 SAL_CALL ODatabaseMetaData::getMaxTableNameLength() throw(SQLException, RuntimeException, std::exception)
213 return 31;
216 sal_Int32 SAL_CALL ODatabaseMetaData::getMaxTablesInSelect( ) throw(SQLException, RuntimeException, std::exception)
218 sal_Int32 nValue = 0; // 0 means no limit
219 return nValue;
223 sal_Bool SAL_CALL ODatabaseMetaData::doesMaxRowSizeIncludeBlobs( ) throw(SQLException, RuntimeException, std::exception)
225 return false;
228 // ---- Identifiers -----------------------------------------------------------
229 // Only quoted identifiers are case sensitive, unquoted are case insensitive
230 OUString SAL_CALL ODatabaseMetaData::getIdentifierQuoteString()
231 throw(SQLException, RuntimeException, std::exception)
233 OUString aVal('"');
234 return aVal;
237 sal_Bool SAL_CALL ODatabaseMetaData::supportsMixedCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException, std::exception)
239 return true;
242 sal_Bool SAL_CALL ODatabaseMetaData::storesLowerCaseQuotedIdentifiers()
243 throw(SQLException, RuntimeException, std::exception)
245 return false;
248 sal_Bool SAL_CALL ODatabaseMetaData::storesMixedCaseQuotedIdentifiers()
249 throw(SQLException, RuntimeException, std::exception)
251 // TODO: confirm this -- the documentation is highly ambiguous
252 // However it seems this should be true as quoted identifiers ARE
253 // stored mixed case.
254 return true;
257 sal_Bool SAL_CALL ODatabaseMetaData::storesUpperCaseQuotedIdentifiers()
258 throw(SQLException, RuntimeException, std::exception)
260 return false;
263 // ---- Unquoted Identifiers -------------------------------------------------
264 // All unquoted identifiers are stored upper case.
265 sal_Bool SAL_CALL ODatabaseMetaData::supportsMixedCaseIdentifiers()
266 throw(SQLException, RuntimeException, std::exception)
268 return false;
271 sal_Bool SAL_CALL ODatabaseMetaData::storesLowerCaseIdentifiers()
272 throw(SQLException, RuntimeException, std::exception)
274 return false;
277 sal_Bool SAL_CALL ODatabaseMetaData::storesMixedCaseIdentifiers()
278 throw(SQLException, RuntimeException, std::exception)
280 return false;
283 sal_Bool SAL_CALL ODatabaseMetaData::storesUpperCaseIdentifiers()
284 throw(SQLException, RuntimeException, std::exception)
286 return true;
289 // ---- SQL Feature Support ---------------------------------------------------
290 sal_Bool SAL_CALL ODatabaseMetaData::supportsCoreSQLGrammar()
291 throw(SQLException, RuntimeException, std::exception)
293 return true;
296 sal_Bool SAL_CALL ODatabaseMetaData::supportsMinimumSQLGrammar()
297 throw(SQLException, RuntimeException, std::exception)
299 return true;
302 sal_Bool SAL_CALL ODatabaseMetaData::supportsAlterTableWithAddColumn()
303 throw(SQLException, RuntimeException, std::exception)
305 return true;
308 sal_Bool SAL_CALL ODatabaseMetaData::supportsAlterTableWithDropColumn()
309 throw(SQLException, RuntimeException, std::exception)
311 return true;
314 sal_Bool SAL_CALL ODatabaseMetaData::supportsPositionedDelete()
315 throw(SQLException, RuntimeException, std::exception)
317 return true;
320 sal_Bool SAL_CALL ODatabaseMetaData::supportsPositionedUpdate()
321 throw(SQLException, RuntimeException, std::exception)
323 return true;
326 sal_Bool SAL_CALL ODatabaseMetaData::supportsOuterJoins()
327 throw(SQLException, RuntimeException, std::exception)
329 return true;
332 sal_Bool SAL_CALL ODatabaseMetaData::supportsSelectForUpdate()
333 throw(SQLException, RuntimeException, std::exception)
335 return true;
338 sal_Bool SAL_CALL ODatabaseMetaData::allTablesAreSelectable()
339 throw(SQLException, RuntimeException, std::exception)
341 // TODO: true if embedded, but unsure about remote server
342 return true;
345 sal_Bool SAL_CALL ODatabaseMetaData::supportsConvert(sal_Int32 fromType,
346 sal_Int32 toType)
347 throw(SQLException, RuntimeException, std::exception)
349 (void) fromType;
350 (void) toType;
351 return false;
354 sal_Bool SAL_CALL ODatabaseMetaData::supportsTypeConversion()
355 throw(SQLException, RuntimeException, std::exception)
357 return false;
360 sal_Bool SAL_CALL ODatabaseMetaData::supportsColumnAliasing()
361 throw(SQLException, RuntimeException, std::exception)
363 return true;
366 sal_Bool SAL_CALL ODatabaseMetaData::supportsTableCorrelationNames()
367 throw(SQLException, RuntimeException, std::exception)
369 return true;
372 sal_Int32 SAL_CALL ODatabaseMetaData::getMaxIndexLength( ) throw(SQLException, RuntimeException, std::exception)
374 sal_Int32 nValue = 0; // 0 means no limit
375 return nValue;
378 sal_Bool SAL_CALL ODatabaseMetaData::supportsNonNullableColumns( ) throw(SQLException, RuntimeException, std::exception)
380 return true;
383 OUString SAL_CALL ODatabaseMetaData::getExtraNameCharacters( ) throw(SQLException, RuntimeException, std::exception)
385 OUString aVal;
386 return aVal;
389 sal_Bool SAL_CALL ODatabaseMetaData::supportsDifferentTableCorrelationNames( ) throw(SQLException, RuntimeException, std::exception)
391 return false;
393 // ---- Data definition stuff -------------------------------------------------
394 sal_Bool SAL_CALL ODatabaseMetaData::dataDefinitionIgnoredInTransactions()
395 throw(SQLException, RuntimeException, std::exception)
397 return false;
400 sal_Bool SAL_CALL ODatabaseMetaData::dataDefinitionCausesTransactionCommit()
401 throw(SQLException, RuntimeException, std::exception)
403 return true;
406 sal_Bool SAL_CALL ODatabaseMetaData::supportsDataManipulationTransactionsOnly()
407 throw(SQLException, RuntimeException, std::exception)
409 return true;
412 sal_Bool SAL_CALL ODatabaseMetaData::
413 supportsDataDefinitionAndDataManipulationTransactions()
414 throw(SQLException, RuntimeException, std::exception)
416 return false;
418 //----- Transaction Support --------------------------------------------------
419 sal_Bool SAL_CALL ODatabaseMetaData::supportsTransactions()
420 throw(SQLException, RuntimeException, std::exception)
422 return true;
425 sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenStatementsAcrossRollback()
426 throw(SQLException, RuntimeException, std::exception)
428 return false;
431 sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenStatementsAcrossCommit()
432 throw(SQLException, RuntimeException, std::exception)
434 return false;
437 sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenCursorsAcrossCommit()
438 throw(SQLException, RuntimeException, std::exception)
440 return false;
443 sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenCursorsAcrossRollback()
444 throw(SQLException, RuntimeException, std::exception)
446 return false;
449 sal_Bool SAL_CALL ODatabaseMetaData::supportsMultipleTransactions()
450 throw(SQLException, RuntimeException, std::exception)
452 return true;
455 sal_Bool SAL_CALL ODatabaseMetaData::supportsTransactionIsolationLevel(
456 sal_Int32 aLevel)
457 throw(SQLException, RuntimeException, std::exception)
459 return aLevel == TransactionIsolation::READ_UNCOMMITTED
460 || aLevel == TransactionIsolation::READ_COMMITTED
461 || aLevel == TransactionIsolation::REPEATABLE_READ
462 || aLevel == TransactionIsolation::SERIALIZABLE;
465 sal_Int32 SAL_CALL ODatabaseMetaData::getDefaultTransactionIsolation()
466 throw(SQLException, RuntimeException, std::exception)
468 return TransactionIsolation::REPEATABLE_READ;
472 sal_Bool SAL_CALL ODatabaseMetaData::supportsANSI92FullSQL( ) throw(SQLException, RuntimeException, std::exception)
474 return false;
477 sal_Bool SAL_CALL ODatabaseMetaData::supportsANSI92EntryLevelSQL( ) throw(SQLException, RuntimeException, std::exception)
479 return true; // should be supported at least
482 sal_Bool SAL_CALL ODatabaseMetaData::supportsIntegrityEnhancementFacility( ) throw(SQLException, RuntimeException, std::exception)
484 return true;
487 sal_Int32 SAL_CALL ODatabaseMetaData::getMaxStatements( ) throw(SQLException, RuntimeException, std::exception)
489 sal_Int32 nValue = 0; // 0 means no limit
490 return nValue;
493 sal_Int32 SAL_CALL ODatabaseMetaData::getMaxProcedureNameLength( ) throw(SQLException, RuntimeException, std::exception)
495 sal_Int32 nValue = 31; // TODO: confirm
496 return nValue;
499 sal_Bool SAL_CALL ODatabaseMetaData::allProceduresAreCallable( ) throw(SQLException, RuntimeException, std::exception)
501 return false;
504 sal_Bool SAL_CALL ODatabaseMetaData::supportsStoredProcedures( ) throw(SQLException, RuntimeException, std::exception)
506 return true;
509 sal_Bool SAL_CALL ODatabaseMetaData::isReadOnly( ) throw(SQLException, RuntimeException, std::exception)
511 return m_pConnection->isReadOnly();
514 sal_Bool SAL_CALL ODatabaseMetaData::usesLocalFiles( ) throw(SQLException, RuntimeException, std::exception)
516 return m_pConnection->isEmbedded();
519 sal_Bool SAL_CALL ODatabaseMetaData::usesLocalFilePerTable( ) throw(SQLException, RuntimeException, std::exception)
521 return false;
524 sal_Bool SAL_CALL ODatabaseMetaData::nullPlusNonNullIsNull( ) throw(SQLException, RuntimeException, std::exception)
526 return false;
529 sal_Bool SAL_CALL ODatabaseMetaData::supportsExpressionsInOrderBy( ) throw(SQLException, RuntimeException, std::exception)
531 return false;
534 sal_Bool SAL_CALL ODatabaseMetaData::supportsGroupBy( ) throw(SQLException, RuntimeException, std::exception)
536 return true;
539 sal_Bool SAL_CALL ODatabaseMetaData::supportsGroupByBeyondSelect( ) throw(SQLException, RuntimeException, std::exception)
541 // Unsure
542 return true;
545 sal_Bool SAL_CALL ODatabaseMetaData::supportsGroupByUnrelated( ) throw(SQLException, RuntimeException, std::exception)
547 // Unsure
548 return false;
552 sal_Bool SAL_CALL ODatabaseMetaData::supportsMultipleResultSets( ) throw(SQLException, RuntimeException, std::exception)
554 return false;
557 sal_Bool SAL_CALL ODatabaseMetaData::supportsLikeEscapeClause( ) throw(SQLException, RuntimeException, std::exception)
559 return false;
562 sal_Bool SAL_CALL ODatabaseMetaData::supportsOrderByUnrelated( ) throw(SQLException, RuntimeException, std::exception)
564 return false;
567 sal_Bool SAL_CALL ODatabaseMetaData::supportsUnion( ) throw(SQLException, RuntimeException, std::exception)
569 return true;
572 sal_Bool SAL_CALL ODatabaseMetaData::supportsUnionAll( ) throw(SQLException, RuntimeException, std::exception)
574 return true;
577 sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedAtEnd( ) throw(SQLException, RuntimeException, std::exception)
579 return false;
582 sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedAtStart( ) throw(SQLException, RuntimeException, std::exception)
584 return false;
587 sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedHigh( ) throw(SQLException, RuntimeException, std::exception)
589 return false;
592 sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedLow( ) throw(SQLException, RuntimeException, std::exception)
594 return false;
597 sal_Bool SAL_CALL ODatabaseMetaData::supportsCorrelatedSubqueries( ) throw(SQLException, RuntimeException, std::exception)
599 return false;
602 sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInComparisons( ) throw(SQLException, RuntimeException, std::exception)
604 return false;
607 sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInExists( ) throw(SQLException, RuntimeException, std::exception)
609 return false;
612 sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInIns( ) throw(SQLException, RuntimeException, std::exception)
614 return false;
617 sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInQuantifieds( ) throw(SQLException, RuntimeException, std::exception)
619 return false;
622 sal_Bool SAL_CALL ODatabaseMetaData::supportsANSI92IntermediateSQL( ) throw(SQLException, RuntimeException, std::exception)
624 return false;
627 OUString SAL_CALL ODatabaseMetaData::getURL() throw(SQLException, RuntimeException, std::exception)
629 return m_pConnection->getConnectionURL();
632 OUString SAL_CALL ODatabaseMetaData::getUserName( ) throw(SQLException, RuntimeException, std::exception)
634 OUString aValue;
635 return aValue;
638 OUString SAL_CALL ODatabaseMetaData::getDriverName( ) throw(SQLException, RuntimeException, std::exception)
640 OUString aValue;
641 return aValue;
644 OUString SAL_CALL ODatabaseMetaData::getDriverVersion() throw(SQLException, RuntimeException, std::exception)
646 OUString aValue;
647 return aValue;
650 OUString SAL_CALL ODatabaseMetaData::getDatabaseProductVersion( ) throw(SQLException, RuntimeException, std::exception)
652 OUString aValue;
653 return aValue;
656 OUString SAL_CALL ODatabaseMetaData::getDatabaseProductName( ) throw(SQLException, RuntimeException, std::exception)
658 OUString aValue;
659 return aValue;
662 OUString SAL_CALL ODatabaseMetaData::getProcedureTerm( ) throw(SQLException, RuntimeException, std::exception)
664 OUString aValue;
665 return aValue;
668 sal_Int32 SAL_CALL ODatabaseMetaData::getDriverMajorVersion( ) throw(RuntimeException, std::exception)
670 return 1;
673 sal_Int32 SAL_CALL ODatabaseMetaData::getDriverMinorVersion( ) throw(RuntimeException, std::exception)
675 return 0;
678 OUString SAL_CALL ODatabaseMetaData::getSQLKeywords( ) throw(SQLException, RuntimeException, std::exception)
680 OUString aValue;
681 return aValue;
684 OUString SAL_CALL ODatabaseMetaData::getSearchStringEscape( ) throw(SQLException, RuntimeException, std::exception)
686 OUString aValue;
687 return aValue;
690 OUString SAL_CALL ODatabaseMetaData::getStringFunctions( ) throw(SQLException, RuntimeException, std::exception)
692 return OUString();
695 OUString SAL_CALL ODatabaseMetaData::getTimeDateFunctions( ) throw(SQLException, RuntimeException, std::exception)
697 return OUString();
700 OUString SAL_CALL ODatabaseMetaData::getSystemFunctions( ) throw(SQLException, RuntimeException, std::exception)
702 return OUString();
705 OUString SAL_CALL ODatabaseMetaData::getNumericFunctions( ) throw(SQLException, RuntimeException, std::exception)
707 return OUString();
710 sal_Bool SAL_CALL ODatabaseMetaData::supportsExtendedSQLGrammar( ) throw(SQLException, RuntimeException, std::exception)
712 return false;
715 sal_Bool SAL_CALL ODatabaseMetaData::supportsFullOuterJoins( ) throw(SQLException, RuntimeException, std::exception)
717 return false;
720 sal_Bool SAL_CALL ODatabaseMetaData::supportsLimitedOuterJoins( ) throw(SQLException, RuntimeException, std::exception)
722 return false;
725 sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInGroupBy( ) throw(SQLException, RuntimeException, std::exception)
727 sal_Int32 nValue = 0; // 0 means no limit
728 return nValue;
731 sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInOrderBy( ) throw(SQLException, RuntimeException, std::exception)
733 sal_Int32 nValue = 0; // 0 means no limit
734 return nValue;
737 sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInSelect( ) throw(SQLException, RuntimeException, std::exception)
739 sal_Int32 nValue = 0; // 0 means no limit
740 return nValue;
743 sal_Int32 SAL_CALL ODatabaseMetaData::getMaxUserNameLength( ) throw(SQLException, RuntimeException, std::exception)
745 return 31;
748 sal_Bool SAL_CALL ODatabaseMetaData::supportsResultSetType(sal_Int32 setType)
749 throw(SQLException, RuntimeException, std::exception)
751 switch (setType)
753 case ResultSetType::FORWARD_ONLY:
754 return true;
755 default:
756 return false;
760 sal_Bool SAL_CALL ODatabaseMetaData::supportsResultSetConcurrency(
761 sal_Int32 aResultSetType,
762 sal_Int32 aConcurrency)
763 throw(SQLException, RuntimeException, std::exception)
765 if (aResultSetType == ResultSetType::FORWARD_ONLY
766 && aConcurrency == ResultSetConcurrency::READ_ONLY)
767 return true;
768 else
769 return false;
772 sal_Bool SAL_CALL ODatabaseMetaData::ownUpdatesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException, std::exception)
774 (void) setType;
775 return false;
778 sal_Bool SAL_CALL ODatabaseMetaData::ownDeletesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException, std::exception)
780 (void) setType;
781 return false;
784 sal_Bool SAL_CALL ODatabaseMetaData::ownInsertsAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException, std::exception)
786 (void) setType;
787 return false;
790 sal_Bool SAL_CALL ODatabaseMetaData::othersUpdatesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException, std::exception)
792 (void) setType;
793 return false;
796 sal_Bool SAL_CALL ODatabaseMetaData::othersDeletesAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException, std::exception)
798 (void) setType;
799 return false;
802 sal_Bool SAL_CALL ODatabaseMetaData::othersInsertsAreVisible( sal_Int32 setType ) throw(SQLException, RuntimeException, std::exception)
804 (void) setType;
805 return false;
808 sal_Bool SAL_CALL ODatabaseMetaData::updatesAreDetected( sal_Int32 setType ) throw(SQLException, RuntimeException, std::exception)
810 (void) setType;
811 return false;
814 sal_Bool SAL_CALL ODatabaseMetaData::deletesAreDetected( sal_Int32 setType ) throw(SQLException, RuntimeException, std::exception)
816 (void) setType;
817 return false;
820 sal_Bool SAL_CALL ODatabaseMetaData::insertsAreDetected( sal_Int32 setType ) throw(SQLException, RuntimeException, std::exception)
822 (void) setType;
823 return false;
826 sal_Bool SAL_CALL ODatabaseMetaData::supportsBatchUpdates()
827 throw(SQLException, RuntimeException, std::exception)
829 // No batch support in firebird
830 return false;
833 uno::Reference< XConnection > SAL_CALL ODatabaseMetaData::getConnection()
834 throw(SQLException, RuntimeException, std::exception)
836 return uno::Reference<XConnection>(m_pConnection.get());
839 // here follow all methods which return a resultset
840 // the first methods is an example implementation how to use this resultset
841 // of course you could implement it on your and you should do this because
842 // the general way is more memory expensive
844 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTableTypes( ) throw(SQLException, RuntimeException, std::exception)
846 ODatabaseMetaDataResultSet* pResultSet = new
847 ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTableTypes);
848 uno::Reference< XResultSet > xResultSet = pResultSet;
850 ODatabaseMetaDataResultSet::ORows aResults;
851 ODatabaseMetaDataResultSet::ORow aRow(2);
853 aRow[0] = new ORowSetValueDecorator(); // unused
855 // TODO Put these statics to one place
856 // like postgreSQL's Statics class.
858 aRow[1] = new ORowSetValueDecorator(OUString("TABLE"));
859 aResults.push_back(aRow);
861 aRow[1] = new ORowSetValueDecorator(OUString("VIEW"));
862 aResults.push_back(aRow);
864 aRow[1] = new ORowSetValueDecorator(OUString("SYSTEM TABLE"));
865 aResults.push_back(aRow);
867 pResultSet->setRows(aResults);
868 return xResultSet;
871 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo()
872 throw(SQLException, RuntimeException, std::exception)
874 SAL_INFO("connectivity.firebird", "getTypeInfo()");
876 // this returns an empty resultset where the column-names are already set
877 // in special the metadata of the resultset already returns the right columns
878 ODatabaseMetaDataResultSet* pResultSet =
879 new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTypeInfo);
880 uno::Reference< XResultSet > xResultSet = pResultSet;
881 static ODatabaseMetaDataResultSet::ORows aResults;
883 if(aResults.empty())
885 ODatabaseMetaDataResultSet::ORow aRow(19);
887 // Common data
888 aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue(); // Literal quote marks
889 aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue(); // Literal quote marks
890 aRow[7] = new ORowSetValueDecorator(true); // Nullable
891 aRow[8] = new ORowSetValueDecorator(true); // Case sensitive
892 aRow[10] = new ORowSetValueDecorator(false); // Is unsigned
893 // FIXED_PREC_SCALE: docs state "can it be a money value? " however
894 // in reality this causes Base to treat all numbers as money formatted
895 // by default which is wrong (and formatting as money value is still
896 // possible for all values).
897 aRow[11] = new ORowSetValueDecorator(false);
898 // Localised Type Name -- TODO: implement (but can be null):
899 aRow[13] = new ORowSetValueDecorator();
900 aRow[16] = new ORowSetValueDecorator(); // Unused
901 aRow[17] = new ORowSetValueDecorator(); // Unused
902 aRow[18] = new ORowSetValueDecorator(sal_Int16(10));// Radix
904 // SQL_TEXT
905 aRow[1] = new ORowSetValueDecorator(OUString("CHAR"));
906 aRow[2] = new ORowSetValueDecorator(getColumnTypeFromFBType(SQL_TEXT, 0));
907 aRow[3] = new ORowSetValueDecorator(sal_Int16(32765)); // Prevision = max length
908 aRow[6] = new ORowSetValueDecorator(OUString("length")); // Create Params
909 aRow[9] = new ORowSetValueDecorator(
910 sal_Int16(ColumnSearch::FULL)); // Searchable
911 aRow[12] = new ORowSetValueDecorator(false); // Autoincrement
912 aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale
913 aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale
914 aResults.push_back(aRow);
916 // SQL_VARYING
917 aRow[1] = new ORowSetValueDecorator(OUString("VARCHAR"));
918 aRow[2] = new ORowSetValueDecorator(getColumnTypeFromFBType(SQL_VARYING, 0));
919 aRow[3] = new ORowSetValueDecorator(sal_Int16(32765)); // Prevision = max length
920 aRow[6] = new ORowSetValueDecorator(OUString("length")); // Create Params
921 aRow[9] = new ORowSetValueDecorator(
922 sal_Int16(ColumnSearch::FULL)); // Searchable
923 aRow[12] = new ORowSetValueDecorator(false); // Autoincrement
924 aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale
925 aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale
926 aResults.push_back(aRow);
928 // Integer Types common
930 aRow[6] = new ORowSetValueDecorator(); // Create Params
931 aRow[9] = new ORowSetValueDecorator(
932 sal_Int16(ColumnSearch::FULL)); // Searchable
933 aRow[12] = new ORowSetValueDecorator(true); // Autoincrement
934 aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale
935 aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale
937 // SQL_SHORT
938 aRow[1] = new ORowSetValueDecorator(OUString("SMALLINT"));
939 aRow[2] = new ORowSetValueDecorator(getColumnTypeFromFBType(SQL_SHORT, 0));
940 aRow[3] = new ORowSetValueDecorator(sal_Int16(5)); // Prevision
941 aResults.push_back(aRow);
942 // SQL_LONG
943 aRow[1] = new ORowSetValueDecorator(OUString("INTEGER"));
944 aRow[2] = new ORowSetValueDecorator(getColumnTypeFromFBType(SQL_LONG, 0));
945 aRow[3] = new ORowSetValueDecorator(sal_Int16(10)); // Precision
946 aResults.push_back(aRow);
947 // SQL_INT64
948 aRow[1] = new ORowSetValueDecorator(OUString("BIGINT"));
949 aRow[2] = new ORowSetValueDecorator(getColumnTypeFromFBType(SQL_INT64, 0));
950 aRow[3] = new ORowSetValueDecorator(sal_Int16(20)); // Precision
951 aResults.push_back(aRow);
953 // Decimal Types common
955 aRow[9] = new ORowSetValueDecorator(
956 sal_Int16(ColumnSearch::FULL)); // Searchable
957 aRow[12] = new ORowSetValueDecorator(true); // Autoincrement
960 aRow[6] = new ORowSetValueDecorator(OUString("PRECISION,SCALE")); // Create params
961 // NUMERIC
962 aRow[1] = new ORowSetValueDecorator(OUString("NUMERIC"));
963 aRow[2] = new ORowSetValueDecorator(DataType::NUMERIC);
964 aRow[3] = new ORowSetValueDecorator(sal_Int16(15)); // Precision
965 aRow[14] = new ORowSetValueDecorator(sal_Int16(1)); // Minimum scale
966 aRow[15] = new ORowSetValueDecorator(sal_Int16(15)); // Max scale
967 aResults.push_back(aRow);
968 // DECIMAL
969 aRow[1] = new ORowSetValueDecorator(OUString("DECIMAL"));
970 aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL);
971 aRow[3] = new ORowSetValueDecorator(sal_Int16(15)); // Precision
972 aRow[14] = new ORowSetValueDecorator(sal_Int16(1)); // Minimum scale
973 aRow[15] = new ORowSetValueDecorator(sal_Int16(15)); // Max scale
974 aResults.push_back(aRow);
976 aRow[6] = new ORowSetValueDecorator(); // Create Params
977 // SQL_FLOAT
978 aRow[1] = new ORowSetValueDecorator(OUString("FLOAT"));
979 aRow[2] = new ORowSetValueDecorator(getColumnTypeFromFBType(SQL_FLOAT, 0));
980 aRow[3] = new ORowSetValueDecorator(sal_Int16(7)); // Precision
981 aRow[14] = new ORowSetValueDecorator(sal_Int16(1)); // Minimum scale
982 aRow[15] = new ORowSetValueDecorator(sal_Int16(7)); // Max scale
983 aResults.push_back(aRow);
984 // SQL_DOUBLE
985 aRow[1] = new ORowSetValueDecorator(OUString("DOUBLE PRECISION"));
986 aRow[2] = new ORowSetValueDecorator(getColumnTypeFromFBType(SQL_DOUBLE, 0));
987 aRow[3] = new ORowSetValueDecorator(sal_Int16(15)); // Precision
988 aRow[14] = new ORowSetValueDecorator(sal_Int16(1)); // Minimum scale
989 aRow[15] = new ORowSetValueDecorator(sal_Int16(15)); // Max scale
990 aResults.push_back(aRow);
992 // // SQL_D_FLOAT
993 // aRow[1] = new ORowSetValueDecorator(getColumnTypeNameFromFBType(SQL_D_FLOAT, 0));
994 // aRow[2] = new ORowSetValueDecorator(getColumnTypeFromFBType(SQL_D_FLOAT, 0));
995 // aRow[3] = new ORowSetValueDecorator(sal_Int16(15)); // Precision
996 // aRow[14] = new ORowSetValueDecorator(sal_Int16(1)); // Minimum scale
997 // aRow[15] = new ORowSetValueDecorator(sal_Int16(15)); // Max scale
998 // aResults.push_back(aRow);
999 // TODO: no idea whether D_FLOAT corresponds to an sql type
1001 // SQL_TIMESTAMP
1002 // TODO: precision?
1003 aRow[1] = new ORowSetValueDecorator(OUString("TIMESTAMP"));
1004 aRow[2] = new ORowSetValueDecorator(getColumnTypeFromFBType(SQL_TIMESTAMP, 0));
1005 aRow[3] = new ORowSetValueDecorator(sal_Int32(8)); // Prevision = max length
1006 aRow[6] = new ORowSetValueDecorator(); // Create Params
1007 aRow[9] = new ORowSetValueDecorator(
1008 sal_Int16(ColumnSearch::FULL)); // Searchable
1009 aRow[12] = new ORowSetValueDecorator(false); // Autoincrement
1010 aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale
1011 aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale
1012 aResults.push_back(aRow);
1014 // SQL_TYPE_TIME
1015 // TODO: precision?
1016 aRow[1] = new ORowSetValueDecorator(OUString("TIME"));
1017 aRow[2] = new ORowSetValueDecorator(getColumnTypeFromFBType(SQL_TYPE_TIME, 0));
1018 aRow[3] = new ORowSetValueDecorator(sal_Int32(8)); // Prevision = max length
1019 aRow[6] = new ORowSetValueDecorator(); // Create Params
1020 aRow[9] = new ORowSetValueDecorator(
1021 sal_Int16(ColumnSearch::FULL)); // Searchable
1022 aRow[12] = new ORowSetValueDecorator(false); // Autoincrement
1023 aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale
1024 aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale
1025 aResults.push_back(aRow);
1027 // SQL_TYPE_DATE
1028 // TODO: precision?
1029 aRow[1] = new ORowSetValueDecorator(OUString("DATE"));
1030 aRow[2] = new ORowSetValueDecorator(getColumnTypeFromFBType(SQL_TYPE_DATE, 0));
1031 aRow[3] = new ORowSetValueDecorator(sal_Int32(8)); // Prevision = max length
1032 aRow[6] = new ORowSetValueDecorator(); // Create Params
1033 aRow[9] = new ORowSetValueDecorator(
1034 sal_Int16(ColumnSearch::FULL)); // Searchable
1035 aRow[12] = new ORowSetValueDecorator(false); // Autoincrement
1036 aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale
1037 aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale
1038 aResults.push_back(aRow);
1040 // SQL_BLOB
1041 // TODO: precision?
1042 aRow[1] = new ORowSetValueDecorator(OUString("BLOB"));
1043 aRow[2] = new ORowSetValueDecorator(getColumnTypeFromFBType(SQL_BLOB, 0));
1044 aRow[3] = new ORowSetValueDecorator(sal_Int32(0)); // Prevision = max length
1045 aRow[6] = new ORowSetValueDecorator(); // Create Params
1046 aRow[9] = new ORowSetValueDecorator(
1047 sal_Int16(ColumnSearch::NONE)); // Searchable
1048 aRow[12] = new ORowSetValueDecorator(false); // Autoincrement
1049 aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale
1050 aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale
1051 aResults.push_back(aRow);
1053 // TODO: complete
1054 // case SQL_ARRAY:
1055 // case SQL_NULL:
1056 // case SQL_QUAD: // Is a "Blob ID" according to the docs
1058 pResultSet->setRows(aResults);
1059 return xResultSet;
1062 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumnPrivileges(
1063 const Any& /*aCatalog*/,
1064 const OUString& /*sSchema*/,
1065 const OUString& sTable,
1066 const OUString& sColumnNamePattern)
1067 throw(SQLException, RuntimeException, std::exception)
1069 SAL_INFO("connectivity.firebird", "getColumnPrivileges() with "
1070 "Table: " << sTable
1071 << " & ColumnNamePattern: " << sColumnNamePattern);
1073 ODatabaseMetaDataResultSet* pResultSet = new
1074 ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eColumnPrivileges);
1075 uno::Reference< XResultSet > xResultSet = pResultSet;
1076 uno::Reference< XStatement > statement = m_pConnection->createStatement();
1078 static const char wld[] = "%";
1079 OUStringBuffer queryBuf(
1080 "SELECT "
1081 "priv.RDB$RELATION_NAME, " // 1 Table name
1082 "priv.RDB$GRANTOR," // 2
1083 "priv.RDB$USER, " // 3 Grantee
1084 "priv.RDB$PRIVILEGE, " // 4
1085 "priv.RDB$GRANT_OPTION, " // 5 is Grantable
1086 "priv.RDB$FIELD_NAME " // 6 Column name
1087 "FROM RDB$USER_PRIVILEGES priv ");
1090 OUString sAppend = "WHERE priv.RDB$RELATION_NAME = '%' ";
1091 queryBuf.append(sAppend.replaceAll("%", sTable));
1093 if (!sColumnNamePattern.isEmpty())
1095 OUString sAppend;
1096 if (sColumnNamePattern.match(wld))
1097 sAppend = "AND priv.RDB$FIELD_NAME LIKE '%' ";
1098 else
1099 sAppend = "AND priv.RDB$FIELD_NAME = '%' ";
1101 queryBuf.append(sAppend.replaceAll(wld, sColumnNamePattern));
1104 queryBuf.append(" ORDER BY priv.RDB$FIELD, "
1105 "priv.RDB$PRIVILEGE");
1107 OUString query = queryBuf.makeStringAndClear();
1109 uno::Reference< XResultSet > rs = statement->executeQuery(query.getStr());
1110 uno::Reference< XRow > xRow( rs, UNO_QUERY_THROW );
1111 ODatabaseMetaDataResultSet::ORows aResults;
1113 ODatabaseMetaDataResultSet::ORow aCurrentRow(8);
1114 aCurrentRow[0] = new ORowSetValueDecorator(); // Unused
1115 aCurrentRow[1] = new ORowSetValueDecorator(); // 1. TABLE_CAT Unsupported
1116 aCurrentRow[2] = new ORowSetValueDecorator(); // 1. TABLE_SCHEM Unsupported
1118 while( rs->next() )
1120 // 3. TABLE_NAME
1121 aCurrentRow[3] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(1)));
1122 // 4. COLUMN_NAME
1123 aCurrentRow[4] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(6)));
1124 aCurrentRow[5] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(2))); // 5. GRANTOR
1125 aCurrentRow[6] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(3))); // 6. GRANTEE
1126 aCurrentRow[7] = new ORowSetValueDecorator(xRow->getString(4)); // 7. Privilege
1127 aCurrentRow[7] = new ORowSetValueDecorator(xRow->getBoolean(5)); // 8. Grantable
1129 aResults.push_back(aCurrentRow);
1132 pResultSet->setRows( aResults );
1134 return xResultSet;
1137 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns(
1138 const Any& /*catalog*/,
1139 const OUString& /*schemaPattern*/,
1140 const OUString& tableNamePattern,
1141 const OUString& columnNamePattern)
1142 throw(SQLException, RuntimeException, std::exception)
1144 SAL_INFO("connectivity.firebird", "getColumns() with "
1145 "TableNamePattern: " << tableNamePattern <<
1146 " & ColumnNamePattern: " << columnNamePattern);
1148 OUStringBuffer queryBuf("SELECT "
1149 "relfields.RDB$RELATION_NAME, " // 1
1150 "relfields.RDB$FIELD_NAME, " // 2
1151 "relfields.RDB$DESCRIPTION," // 3
1152 "relfields.RDB$DEFAULT_VALUE, " // 4
1153 "relfields.RDB$FIELD_POSITION, "// 5
1154 "fields.RDB$FIELD_TYPE, " // 6
1155 "fields.RDB$FIELD_SUB_TYPE, " // 7
1156 "fields.RDB$FIELD_LENGTH, " // 8
1157 "fields.RDB$FIELD_PRECISION, " // 9
1158 "fields.RDB$FIELD_SCALE, " // 10
1159 // Specifically use relfields null flag -- the one in fields is used
1160 // for domains, whether a specific field is nullable is set in relfields,
1161 // this is also the one we manually fiddle when changin NULL/NOT NULL
1162 // (see Table.cxx)
1163 "relfields.RDB$NULL_FLAG " // 11
1164 "FROM RDB$RELATION_FIELDS relfields "
1165 "JOIN RDB$FIELDS fields "
1166 "on (fields.RDB$FIELD_NAME = relfields.RDB$FIELD_SOURCE) "
1167 "WHERE (1 = 1) ");
1169 if (!tableNamePattern.isEmpty())
1171 OUString sAppend;
1172 if (tableNamePattern.match("%"))
1173 sAppend = "AND relfields.RDB$RELATION_NAME LIKE '%' ";
1174 else
1175 sAppend = "AND relfields.RDB$RELATION_NAME = '%' ";
1177 queryBuf.append(sAppend.replaceAll("%", tableNamePattern));
1180 if (!columnNamePattern.isEmpty())
1182 OUString sAppend;
1183 if (columnNamePattern.match("%"))
1184 sAppend = "AND relfields.RDB$FIELD_NAME LIKE '%' ";
1185 else
1186 sAppend = "AND relfields.RDB$FIELD_NAME = '%' ";
1188 queryBuf.append(sAppend.replaceAll("%", columnNamePattern));
1191 OUString query = queryBuf.makeStringAndClear();
1193 uno::Reference< XStatement > statement = m_pConnection->createStatement();
1194 uno::Reference< XResultSet > rs = statement->executeQuery(query.getStr());
1195 uno::Reference< XRow > xRow( rs, UNO_QUERY_THROW );
1197 ODatabaseMetaDataResultSet::ORows aResults;
1198 ODatabaseMetaDataResultSet::ORow aCurrentRow(19);
1200 aCurrentRow[0] = new ORowSetValueDecorator(); // Unused -- numbering starts from 0
1201 aCurrentRow[1] = new ORowSetValueDecorator(); // Catalog - can be null
1202 aCurrentRow[2] = new ORowSetValueDecorator(); // Schema - can be null
1203 aCurrentRow[8] = new ORowSetValueDecorator(); // Unused
1204 aCurrentRow[10] = new ORowSetValueDecorator(sal_Int32(10)); // Radix: fixed in FB
1205 aCurrentRow[14] = new ORowSetValueDecorator(); // Unused
1206 aCurrentRow[15] = new ORowSetValueDecorator(); // Unused
1208 while( rs->next() )
1210 // 3. TABLE_NAME
1211 aCurrentRow[3] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(1)));
1212 // 4. Column Name
1213 aCurrentRow[4] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(2)));
1214 // 5. Datatype
1215 short aType = getFBTypeFromBlrType(xRow->getShort(6));
1216 short aSubType = xRow->getShort(7);
1217 aCurrentRow[5] = new ORowSetValueDecorator(getColumnTypeFromFBType(aType, aSubType));
1218 // 6. Typename (SQL_*)
1219 aCurrentRow[6] = new ORowSetValueDecorator(getColumnTypeNameFromFBType(aType, aSubType));
1221 // 7. Column Sizes
1223 sal_Int32 aColumnSize = 0;
1224 switch (aType)
1226 case SQL_TEXT:
1227 case SQL_VARYING:
1228 aColumnSize = xRow->getShort(8);
1229 break;
1230 case SQL_SHORT:
1231 case SQL_LONG:
1232 case SQL_FLOAT:
1233 case SQL_DOUBLE:
1234 case SQL_D_FLOAT:
1235 case SQL_INT64:
1236 case SQL_QUAD:
1237 aColumnSize = xRow->getShort(9);
1238 break;
1239 case SQL_TIMESTAMP:
1240 case SQL_BLOB:
1241 case SQL_ARRAY:
1242 case SQL_TYPE_TIME:
1243 case SQL_TYPE_DATE:
1244 case SQL_NULL:
1245 // TODO: implement.
1246 break;
1248 aCurrentRow[7] = new ORowSetValueDecorator(aColumnSize);
1251 // 9. Decimal digits (scale)
1252 // fb stores a negative number
1253 aCurrentRow[9] = new ORowSetValueDecorator( (sal_Int16) -(xRow->getShort(10)) );
1255 // 11. Nullable
1256 if (xRow->getShort(11))
1258 aCurrentRow[11] = new ORowSetValueDecorator(ColumnValue::NO_NULLS);
1260 else
1262 aCurrentRow[11] = new ORowSetValueDecorator(ColumnValue::NULLABLE);
1264 // 12. Comments -- may be omitted
1266 OUString aDescription;
1267 uno::Reference< XBlob > xDescriptionBlob = xRow->getBlob(3);
1268 if (xDescriptionBlob.is())
1270 sal_Int32 aBlobLength = (sal_Int32) xDescriptionBlob->length();
1271 aDescription = OUString(reinterpret_cast<char*>(xDescriptionBlob->getBytes(0, aBlobLength).getArray()),
1272 aBlobLength,
1273 RTL_TEXTENCODING_UTF8);
1275 aCurrentRow[12] = new ORowSetValueDecorator(aDescription);
1277 // 13. Default -- may be omitted.
1279 uno::Reference< XBlob > xDefaultValueBlob = xRow->getBlob(4);
1280 if (xDefaultValueBlob.is())
1282 // TODO: Implement
1284 aCurrentRow[13] = new ORowSetValueDecorator();
1287 // 16. Bytes in Column for char
1288 if (aType == SQL_TEXT)
1290 aCurrentRow[16] = new ORowSetValueDecorator(xRow->getShort(8));
1292 else if (aType == SQL_VARYING)
1294 aCurrentRow[16] = new ORowSetValueDecorator(sal_Int32(32767));
1296 else
1298 aCurrentRow[16] = new ORowSetValueDecorator(sal_Int32(0));
1300 // 17. Index of column
1302 short nColumnNumber = xRow->getShort(5);
1303 // Firebird stores column numbers beginning with 0 internally
1304 // SDBC expects column numbering to begin with 1.
1305 aCurrentRow[17] = new ORowSetValueDecorator(sal_Int32(nColumnNumber + 1));
1307 // 18. Is nullable
1308 if (xRow->getShort(9))
1310 aCurrentRow[18] = new ORowSetValueDecorator(OUString("NO"));
1312 else
1314 aCurrentRow[18] = new ORowSetValueDecorator(OUString("YES"));
1317 aResults.push_back(aCurrentRow);
1319 ODatabaseMetaDataResultSet* pResultSet = new
1320 ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eColumns);
1321 uno::Reference< XResultSet > xResultSet = pResultSet;
1322 pResultSet->setRows( aResults );
1324 return xResultSet;
1327 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables(
1328 const Any& /*catalog*/,
1329 const OUString& /*schemaPattern*/,
1330 const OUString& tableNamePattern,
1331 const Sequence< OUString >& types)
1332 throw(SQLException, RuntimeException, std::exception)
1334 SAL_INFO("connectivity.firebird", "getTables() with "
1335 "TableNamePattern: " << tableNamePattern);
1337 ODatabaseMetaDataResultSet* pResultSet = new
1338 ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTables);
1339 uno::Reference< XResultSet > xResultSet = pResultSet;
1340 uno::Reference< XStatement > statement = m_pConnection->createStatement();
1342 static const char wld[] = "%";
1343 OUStringBuffer queryBuf(
1344 "SELECT "
1345 "RDB$RELATION_NAME, "
1346 "RDB$SYSTEM_FLAG, "
1347 "RDB$RELATION_TYPE, "
1348 "RDB$DESCRIPTION, "
1349 "RDB$VIEW_BLR "
1350 "FROM RDB$RELATIONS "
1351 "WHERE ");
1353 // TODO: GLOBAL TEMPORARY, LOCAL TEMPORARY, ALIAS, SYNONYM
1354 if ((types.getLength() == 0) || (types.getLength() == 1 && types[0].match(wld)))
1356 // All table types? I.e. includes system tables.
1357 queryBuf.append("(RDB$RELATION_TYPE = 0 OR RDB$RELATION_TYPE = 1) ");
1359 else
1361 queryBuf.append("( (0 = 1) ");
1362 for (int i = 0; i < types.getLength(); i++)
1364 if (types[i] == "SYSTEM TABLE")
1365 queryBuf.append("OR (RDB$SYSTEM_FLAG = 1 AND RDB$VIEW_BLR IS NULL) ");
1366 else if (types[i] == "TABLE")
1367 queryBuf.append("OR (RDB$SYSTEM_FLAG IS NULL OR RDB$SYSTEM_FLAG = 0 AND RDB$VIEW_BLR IS NULL) ");
1368 else if (types[i] == "VIEW")
1369 queryBuf.append("OR (RDB$SYSTEM_FLAG IS NULL OR RDB$SYSTEM_FLAG = 0 AND RDB$VIEW_BLR IS NOT NULL) ");
1370 else
1371 throw SQLException(); // TODO: implement other types, see above.
1373 queryBuf.append(") ");
1376 if (!tableNamePattern.isEmpty())
1378 OUString sAppend;
1379 if (tableNamePattern.match(wld))
1380 sAppend = "AND RDB$RELATION_NAME LIKE '%' ";
1381 else
1382 sAppend = "AND RDB$RELATION_NAME = '%' ";
1384 queryBuf.append(sAppend.replaceAll(wld, tableNamePattern));
1387 queryBuf.append(" ORDER BY RDB$RELATION_TYPE, RDB$RELATION_NAME");
1389 OUString query = queryBuf.makeStringAndClear();
1391 uno::Reference< XResultSet > rs = statement->executeQuery(query.getStr());
1392 uno::Reference< XRow > xRow( rs, UNO_QUERY_THROW );
1393 ODatabaseMetaDataResultSet::ORows aResults;
1395 ODatabaseMetaDataResultSet::ORow aCurrentRow(6);
1396 aCurrentRow[0] = new ORowSetValueDecorator(); // 0. Unused
1397 aCurrentRow[1] = new ORowSetValueDecorator(); // 1. Table_Cat Unsupported
1398 aCurrentRow[2] = new ORowSetValueDecorator(); // 2. Table_Schem Unsupported
1400 while( rs->next() )
1402 // 3. TABLE_NAME
1403 aCurrentRow[3] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(1)));
1404 // 4. TABLE_TYPE
1406 // TODO: check this as the docs are a bit unclear.
1407 sal_Int16 nSystemFlag = xRow->getShort(2);
1408 sal_Int16 nTableType = xRow->getShort(3);
1409 xRow->getBlob(5); // We have to retrieve a column to verify it is null.
1410 bool aIsView = !xRow->wasNull();
1411 OUString sTableType;
1413 if (nSystemFlag == 1)
1415 sTableType = "SYSTEM TABLE";
1417 else if (aIsView)
1419 sTableType = "VIEW";
1421 else
1423 if (nTableType == 0)
1424 sTableType = "TABLE";
1427 aCurrentRow[4] = new ORowSetValueDecorator(sTableType);
1429 // 5. REMARKS
1431 uno::Reference< XBlob > xBlob = xRow->getBlob(4);
1432 OUString sDescription;
1434 if (xBlob.is())
1436 // TODO: we should actually be using CLOB here instead.
1437 // However we haven't implemented CLOB yet, so use BLOB.
1438 sal_Int32 aBlobLength = (sal_Int32) xBlob->length();
1439 sDescription = OUString(reinterpret_cast<char*>(xBlob->getBytes(0, aBlobLength).getArray()),
1440 aBlobLength,
1441 RTL_TEXTENCODING_UTF8);
1444 aCurrentRow[5] = new ORowSetValueDecorator(sDescription);
1447 aResults.push_back(aCurrentRow);
1450 pResultSet->setRows( aResults );
1452 return xResultSet;
1455 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getProcedureColumns(
1456 const Any& catalog, const OUString& schemaPattern,
1457 const OUString& procedureNamePattern, const OUString& columnNamePattern ) throw(SQLException, RuntimeException, std::exception)
1459 SAL_WARN("connectivity.firebird", "Not yet implemented");
1460 (void) catalog;
1461 (void) schemaPattern;
1462 (void) procedureNamePattern;
1463 (void) columnNamePattern;
1464 OSL_FAIL("Not implemented yet!");
1465 // TODO implement
1466 return new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eProcedureColumns);
1469 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getProcedures(
1470 const Any& catalog, const OUString& schemaPattern,
1471 const OUString& procedureNamePattern ) throw(SQLException, RuntimeException, std::exception)
1473 SAL_WARN("connectivity.firebird", "Not yet implemented");
1474 (void) catalog;
1475 (void) schemaPattern;
1476 (void) procedureNamePattern;
1477 OSL_FAIL("Not implemented yet!");
1478 // TODO implement
1479 return new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eProcedures);
1482 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getVersionColumns(
1483 const Any& catalog, const OUString& schema, const OUString& table ) throw(SQLException, RuntimeException, std::exception)
1485 SAL_WARN("connectivity.firebird", "Not yet implemented");
1486 (void) catalog;
1487 (void) schema;
1488 (void) table;
1489 OSL_FAIL("Not implemented yet!");
1490 // TODO implement
1491 return new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eVersionColumns);
1494 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getExportedKeys(
1495 const Any& catalog, const OUString& schema, const OUString& table ) throw(SQLException, RuntimeException, std::exception)
1497 // List the columns in a table which are foreign keys. This is actually
1498 // never used anywhere in the LO codebase currently. Retrieval from firebird
1499 // requires using a 5-table join.
1500 SAL_WARN("connectivity.firebird", "Not yet implemented");
1501 (void) catalog;
1502 (void) schema;
1503 (void) table;
1504 OSL_FAIL("Not implemented yet!");
1505 // TODO implement
1506 return new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eExportedKeys);
1509 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getImportedKeys(
1510 const Any& catalog, const OUString& schema, const OUString& table ) throw(SQLException, RuntimeException, std::exception)
1512 (void) catalog;
1513 (void) schema;
1515 ODatabaseMetaDataResultSet* pResultSet = new
1516 ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eImportedKeys);
1517 uno::Reference< XResultSet > xResultSet = pResultSet;
1519 uno::Reference< XStatement > statement = m_pConnection->createStatement();
1520 OUString sSQL;
1522 sSQL = "SELECT "
1523 "RDB$REF_CONSTRAINTS.RDB$UPDATE_RULE, " // 1 update rule
1524 "RDB$REF_CONSTRAINTS.RDB$DELETE_RULE, " // 2 delete rule
1525 "RDB$REF_CONSTRAINTS.RDB$CONST_NAME_UQ, " // 3 primary or unique key name
1526 "RDB$REF_CONSTRAINTS.RDB$CONSTRAINT_NAME, " // 4 foreign key name
1527 "PRIM.RDB$DEFERRABLE, " // 5 deferrability
1528 "PRIM.RDB$INITIALLY_DEFERRED, " // 6 deferrability
1529 "PRIM.RDB$RELATION_NAME, " // 7 PK table name
1530 "PRIMARY_INDEX.RDB$FIELD_NAME, " // 8 PK column name
1531 "PRIMARY_INDEX.RDB$FIELD_POSITION, " // 9 PK sequence number
1532 "FOREI.RDB$RELATION_NAME, " // 10 FK table name
1533 "FOREIGN_INDEX.RDB$FIELD_NAME " // 11 FK column name
1534 "FROM RDB$REF_CONSTRAINTS "
1535 "INNER JOIN RDB$RELATION_CONSTRAINTS AS PRIM "
1536 "ON RDB$REF_CONSTRAINTS.RDB$CONST_NAME_UQ = PRIM.RDB$CONSTRAINT_NAME "
1537 "INNER JOIN RDB$RELATION_CONSTRAINTS AS FOREI "
1538 "ON RDB$REF_CONSTRAINTS.RDB$CONSTRAINT_NAME = FOREI.RDB$CONSTRAINT_NAME "
1539 "INNER JOIN RDB$INDEX_SEGMENTS AS PRIMARY_INDEX "
1540 "ON PRIM.RDB$INDEX_NAME = PRIMARY_INDEX.RDB$INDEX_NAME "
1541 "INNER JOIN RDB$INDEX_SEGMENTS AS FOREIGN_INDEX "
1542 "ON FOREI.RDB$INDEX_NAME = FOREIGN_INDEX.RDB$INDEX_NAME "
1543 "WHERE FOREI.RDB$CONSTRAINT_TYPE = 'FOREIGN KEY' "
1544 "AND FOREI.RDB$RELATION_NAME = '"+ table +"'";
1546 uno::Reference< XResultSet > rs = statement->executeQuery(sSQL);
1547 uno::Reference< XRow > xRow( rs, UNO_QUERY_THROW );
1549 ODatabaseMetaDataResultSet::ORows aResults;
1550 ODatabaseMetaDataResultSet::ORow aCurrentRow(15);
1552 // TODO is it necessary to initialize these?
1553 aCurrentRow[0] = new ORowSetValueDecorator(); // Unused
1554 aCurrentRow[1] = new ORowSetValueDecorator(); // PKTABLE_CAT unsupported
1555 aCurrentRow[2] = new ORowSetValueDecorator(); // PKTABLE_SCHEM unsupported
1556 aCurrentRow[5] = new ORowSetValueDecorator(); // FKTABLE_CAT unsupported
1557 aCurrentRow[6] = new ORowSetValueDecorator(); // FKTABLE_SCHEM unsupported
1559 ::std::map< OUString,sal_Int32> aRuleMap;
1560 aRuleMap[ OUString("CASCADE")] = KeyRule::CASCADE;
1561 aRuleMap[ OUString("RESTRICT")] = KeyRule::RESTRICT;
1562 aRuleMap[ OUString("SET NULL")] = KeyRule::SET_NULL;
1563 aRuleMap[ OUString("SET DEFAULT")] = KeyRule::SET_DEFAULT;
1564 aRuleMap[ OUString("NO ACTION")] = KeyRule::NO_ACTION;
1566 while(rs->next())
1568 aCurrentRow[3] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(7))); // PK table
1569 aCurrentRow[4] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(8))); // PK column
1570 aCurrentRow[7] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(10))); // FK table
1571 aCurrentRow[8] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(11))); // FK column
1573 aCurrentRow[9] = new ORowSetValueDecorator(xRow->getShort(9)); // PK sequence number
1574 aCurrentRow[10] = new ORowSetValueDecorator(aRuleMap[sanitizeIdentifier(xRow->getString(1))]); // update role
1575 aCurrentRow[11] = new ORowSetValueDecorator(aRuleMap[sanitizeIdentifier(xRow->getString(2))]); // delete role
1577 aCurrentRow[12] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(4))); // FK name
1578 aCurrentRow[13] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(3))); // PK name
1580 aCurrentRow[14] = new ORowSetValueDecorator(Deferrability::NONE); // deferrability
1582 // deferrability is currently not supported, but may be supported in the future.
1584 aCurrentRow[14] = (xRow->getString(5).compareTo(OUString("NO") == 0 ?
1585 new ORowSetValueDecorator(Deferrability::NONE)
1586 : (xRow->getString(6).compareTo(OUString("NO") == 0 ?
1587 new ORowSetValueDecorator(Deferrability::INITIALLY_IMMEDIATE)
1588 : new ORowSetValueDecorator(Deferrability::INITIALLY_DEFERRED));
1591 aResults.push_back(aCurrentRow);
1594 pResultSet->setRows( aResults );
1595 return xResultSet;
1598 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getPrimaryKeys(
1599 const Any& /*aCatalog*/,
1600 const OUString& /*sSchema*/,
1601 const OUString& sTable)
1602 throw(SQLException, RuntimeException, std::exception)
1604 SAL_INFO("connectivity.firebird", "getPrimaryKeys() with "
1605 "Table: " << sTable);
1607 OUStringBuffer aQueryBuf("SELECT "
1608 "constr.RDB$RELATION_NAME, " // 1. Table Name
1609 "inds.RDB$FIELD_NAME, " // 2. Column Name
1610 "inds.RDB$FIELD_POSITION, " // 3. Sequence Number
1611 "constr.RDB$CONSTRAINT_NAME " // 4 Constraint name
1612 "FROM RDB$RELATION_CONSTRAINTS constr "
1613 "JOIN RDB$INDEX_SEGMENTS inds "
1614 "on (constr.RDB$INDEX_NAME = inds.RDB$INDEX_NAME) ");
1616 OUString sAppend = "WHERE constr.RDB$RELATION_NAME = '%' ";
1617 aQueryBuf.append(sAppend.replaceAll("%", sTable));
1619 aQueryBuf.append("AND constr.RDB$CONSTRAINT_TYPE = 'PRIMARY KEY' "
1620 "ORDER BY inds.RDB$FIELD_NAME");
1622 OUString sQuery = aQueryBuf.makeStringAndClear();
1624 uno::Reference< XStatement > xStatement = m_pConnection->createStatement();
1625 uno::Reference< XResultSet > xRs = xStatement->executeQuery(sQuery);
1626 uno::Reference< XRow > xRow( xRs, UNO_QUERY_THROW );
1628 ODatabaseMetaDataResultSet::ORows aResults;
1629 ODatabaseMetaDataResultSet::ORow aCurrentRow(7);
1631 aCurrentRow[0] = new ORowSetValueDecorator(); // Unused -- numbering starts from 0
1632 aCurrentRow[1] = new ORowSetValueDecorator(); // Catalog - can be null
1633 aCurrentRow[2] = new ORowSetValueDecorator(); // Schema - can be null
1635 while(xRs->next())
1637 // 3. Table Name
1638 if (xRs->getRow() == 1) // Table name doesn't change, so only retrieve once
1640 aCurrentRow[3] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(1)));
1642 // 4. Column Name
1643 aCurrentRow[4] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(2)));
1644 // 5. KEY_SEQ (which key in the sequence)
1645 aCurrentRow[5] = new ORowSetValueDecorator(xRow->getShort(3));
1646 // 6. Primary Key Name
1647 aCurrentRow[6] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(4)));
1649 aResults.push_back(aCurrentRow);
1651 ODatabaseMetaDataResultSet* pResultSet = new
1652 ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::ePrimaryKeys);
1653 uno::Reference< XResultSet > xResultSet = pResultSet;
1654 pResultSet->setRows( aResults );
1656 return xResultSet;
1659 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getIndexInfo(
1660 const Any& /*aCatalog*/,
1661 const OUString& /*sSchema*/,
1662 const OUString& sTable,
1663 sal_Bool bIsUnique,
1664 sal_Bool bIsApproximate)
1665 throw(SQLException, RuntimeException, std::exception)
1667 // Apparently this method can also return a "tableIndexStatistic"
1668 // However this is only mentioned in XDatabaseMetaData.idl (whose comments
1669 // are duplicated in the postgresql driver), and is otherwise undocumented.
1670 SAL_INFO("connectivity.firebird", "getPrimaryKeys() with "
1671 "Table: " << sTable);
1673 OUStringBuffer aQueryBuf("SELECT "
1674 "indices.RDB$RELATION_NAME, " // 1. Table Name
1675 "index_segments.RDB$FIELD_NAME, " // 2. Column Name
1676 "index_segments.RDB$FIELD_POSITION, " // 3. Sequence Number
1677 "indices.RDB$INDEX_NAME, " // 4. Index name
1678 "indices.RDB$UNIQUE_FLAG, " // 5. Unique Flag
1679 "indices.RDB$INDEX_TYPE " // 6. Index Type
1680 "FROM RDB$INDICES indices "
1681 "JOIN RDB$INDEX_SEGMENTS index_segments "
1682 "on (indices.RDB$INDEX_NAME = index_segments.RDB$INDEX_NAME) "
1683 "WHERE indices.RDB$RELATION_NAME = '" + sTable + "' "
1684 "AND (indices.RDB$SYSTEM_FLAG = 0) ");
1685 // Not sure whether we should exclude system indices, but otoh. we never
1686 // actually deal with system tables (system indices only apply to system
1687 // tables) within the GUI.
1689 // Only filter if true (according to the docs), i.e.:
1690 // If false we return all indices, if true we return only unique indices
1691 if (bIsUnique)
1692 aQueryBuf.append("AND (indices.RDB$UNIQUE_FLAG = 1) ");
1694 // TODO: what is bIsApproximate?
1695 (void) bIsApproximate;
1697 OUString sQuery = aQueryBuf.makeStringAndClear();
1699 uno::Reference< XStatement > xStatement = m_pConnection->createStatement();
1700 uno::Reference< XResultSet > xRs = xStatement->executeQuery(sQuery);
1701 uno::Reference< XRow > xRow( xRs, UNO_QUERY_THROW );
1703 ODatabaseMetaDataResultSet::ORows aResults;
1704 ODatabaseMetaDataResultSet::ORow aCurrentRow(14);
1706 aCurrentRow[0] = new ORowSetValueDecorator(); // Unused -- numbering starts from 0
1707 aCurrentRow[1] = new ORowSetValueDecorator(); // Catalog - can be null
1708 aCurrentRow[2] = new ORowSetValueDecorator(); // Schema - can be null
1709 aCurrentRow[5] = new ORowSetValueDecorator(); // Index Catalog -- can be null
1710 // According to wikipedia firebird uses clustered indices.
1711 // The documentation does not specifically seem to specify this.
1712 aCurrentRow[7] = new ORowSetValueDecorator(IndexType::CLUSTERED); // 7. INDEX TYPE
1713 aCurrentRow[13] = new ORowSetValueDecorator(); // Filter Condition -- can be null
1715 while(xRs->next())
1717 // 3. Table Name
1718 if (xRs->getRow() == 1) // Table name doesn't change, so only retrieve once
1720 aCurrentRow[3] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(1)));
1723 // 4. NON_UNIQUE -- i.e. specifically negate here.
1724 aCurrentRow[4] = new ORowSetValueDecorator(!xRow->getBoolean(5));
1725 // 6. INDEX NAME
1726 aCurrentRow[6] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(4)));
1728 // 8. ORDINAL POSITION
1729 aCurrentRow[8] = new ORowSetValueDecorator(xRow->getShort(3));
1730 // 9. COLUMN NAME
1731 aCurrentRow[9] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(2)));
1732 // 10. ASC(ending)/DESC(ending)
1733 if (xRow->getShort(6) == 1)
1734 aCurrentRow[10] = new ORowSetValueDecorator(OUString("D"));
1735 else
1736 aCurrentRow[10] = new ORowSetValueDecorator(OUString("A"));
1737 // TODO: double check this^^^, doesn't seem to be officially documented anywhere.
1738 // 11. CARDINALITY
1739 aCurrentRow[11] = new ORowSetValueDecorator((sal_Int32)0); // TODO: determine how to do this
1740 // 12. PAGES
1741 aCurrentRow[12] = new ORowSetValueDecorator((sal_Int32)0); // TODO: determine how to do this
1743 aResults.push_back(aCurrentRow);
1745 ODatabaseMetaDataResultSet* pResultSet = new
1746 ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::ePrimaryKeys);
1747 uno::Reference< XResultSet > xResultSet = pResultSet;
1748 pResultSet->setRows( aResults );
1750 return xResultSet;
1753 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getBestRowIdentifier(
1754 const Any& catalog, const OUString& schema, const OUString& table, sal_Int32 scope,
1755 sal_Bool nullable ) throw(SQLException, RuntimeException, std::exception)
1757 (void) catalog;
1758 (void) schema;
1759 (void) table;
1760 (void) scope;
1761 (void) nullable;
1762 OSL_FAIL("Not implemented yet!");
1763 // TODO implement
1764 return new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eBestRowIdentifier);
1767 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges(
1768 const Any& /*aCatalog*/,
1769 const OUString& /*sSchemaPattern*/,
1770 const OUString& sTableNamePattern)
1771 throw(SQLException, RuntimeException, std::exception)
1773 SAL_INFO("connectivity.firebird", "getTablePrivileges() with "
1774 "TableNamePattern: " << sTableNamePattern);
1776 ODatabaseMetaDataResultSet* pResultSet = new
1777 ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTablePrivileges);
1778 uno::Reference< XResultSet > xResultSet = pResultSet;
1779 uno::Reference< XStatement > statement = m_pConnection->createStatement();
1781 // TODO: column specific privileges are included, we may need
1782 // to have WHERE RDB$FIELD_NAME = NULL or similar.
1783 static const char wld[] = "%";
1784 OUStringBuffer queryBuf(
1785 "SELECT "
1786 "priv.RDB$RELATION_NAME, " // 1
1787 "priv.RDB$GRANTOR," // 2
1788 "priv.RDB$USER, " // 3 Grantee
1789 "priv.RDB$PRIVILEGE, " // 4
1790 "priv.RDB$GRANT_OPTION " // 5 is Grantable
1791 "FROM RDB$USER_PRIVILEGES priv ");
1793 if (!sTableNamePattern.isEmpty())
1795 OUString sAppend;
1796 if (sTableNamePattern.match(wld))
1797 sAppend = "WHERE priv.RDB$RELATION_NAME LIKE '%' ";
1798 else
1799 sAppend = "WHERE priv.RDB$RELATION_NAME = '%' ";
1801 queryBuf.append(sAppend.replaceAll(wld, sTableNamePattern));
1803 queryBuf.append(" ORDER BY priv.RDB$RELATION_TYPE, "
1804 "priv.RDB$RELATION_NAME, "
1805 "priv.RDB$PRIVILEGE");
1807 OUString query = queryBuf.makeStringAndClear();
1809 uno::Reference< XResultSet > rs = statement->executeQuery(query.getStr());
1810 uno::Reference< XRow > xRow( rs, UNO_QUERY_THROW );
1811 ODatabaseMetaDataResultSet::ORows aResults;
1813 ODatabaseMetaDataResultSet::ORow aRow(8);
1814 aRow[0] = new ORowSetValueDecorator(); // Unused
1815 aRow[1] = new ORowSetValueDecorator(); // TABLE_CAT unsupported
1816 aRow[2] = new ORowSetValueDecorator(); // TABLE_SCHEM unsupported.
1818 while( rs->next() )
1820 // 3. TABLE_NAME
1821 aRow[3] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(1)));
1822 aRow[4] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(2))); // 4. GRANTOR
1823 aRow[5] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(3))); // 5. GRANTEE
1824 aRow[6] = new ORowSetValueDecorator(xRow->getString(4)); // 6. Privilege
1825 aRow[7] = new ORowSetValueDecorator(xRow->getBoolean(5)); // 7. Is Grantable
1827 aResults.push_back(aRow);
1830 pResultSet->setRows( aResults );
1832 return xResultSet;
1835 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getCrossReference(
1836 const Any& primaryCatalog, const OUString& primarySchema,
1837 const OUString& primaryTable, const Any& foreignCatalog,
1838 const OUString& foreignSchema, const OUString& foreignTable ) throw(SQLException, RuntimeException, std::exception)
1840 (void) primaryCatalog;
1841 (void) primarySchema;
1842 (void) primaryTable;
1843 (void) foreignCatalog;
1844 (void) foreignSchema;
1845 (void) foreignTable;
1846 OSL_FAIL("Not implemented yet!");
1847 // TODO implement
1848 return new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eCrossReference);
1851 uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getUDTs( const Any& catalog, const OUString& schemaPattern, const OUString& typeNamePattern, const Sequence< sal_Int32 >& types ) throw(SQLException, RuntimeException, std::exception)
1853 (void) catalog;
1854 (void) schemaPattern;
1855 (void) typeNamePattern;
1856 (void) types;
1857 OSL_FAIL("Not implemented yet!");
1858 // TODO implement
1859 return new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eUDTs);
1863 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */