bump product version to 7.2.5.1
[LibreOffice.git] / connectivity / source / drivers / component / CDatabaseMetaData.cxx
blobcb5d1dcab4eb8b15e5398c01207a8b7784c9ef7b
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 <component/CDatabaseMetaData.hxx>
21 #include <file/FConnection.hxx>
22 #include <com/sun/star/sdbc/ColumnSearch.hpp>
23 #include <com/sun/star/sdbc/DataType.hpp>
24 #include <com/sun/star/sdbc/ColumnValue.hpp>
25 #include <com/sun/star/sdbc/SQLException.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
28 #include <FDatabaseMetaDataResultSet.hxx>
29 #include <comphelper/types.hxx>
31 using namespace connectivity::component;
32 using namespace connectivity::file;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::beans;
35 using namespace ::com::sun::star::sdbcx;
36 using namespace ::com::sun::star::sdbc;
37 using namespace ::com::sun::star::container;
39 OComponentDatabaseMetaData::OComponentDatabaseMetaData(OConnection* _pCon) :ODatabaseMetaData(_pCon)
43 OComponentDatabaseMetaData::~OComponentDatabaseMetaData()
47 Reference< XResultSet > OComponentDatabaseMetaData::impl_getTypeInfo_throw( )
49 ::osl::MutexGuard aGuard( m_aMutex );
51 rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo);
53 static ODatabaseMetaDataResultSet::ORows aRows;
54 if(aRows.empty())
56 aRows.reserve(6);
57 ODatabaseMetaDataResultSet::ORow aRow
59 ODatabaseMetaDataResultSet::getEmptyValue(),
60 new ORowSetValueDecorator(OUString("VARCHAR")),
61 new ORowSetValueDecorator(DataType::VARCHAR),
62 new ORowSetValueDecorator(sal_Int32(65535)),
63 ODatabaseMetaDataResultSet::getQuoteValue(),
64 ODatabaseMetaDataResultSet::getQuoteValue(),
65 ODatabaseMetaDataResultSet::getEmptyValue(),
66 ODatabaseMetaDataResultSet::get1Value(), // ORowSetValue((sal_Int32)ColumnValue::NULLABLE
67 ODatabaseMetaDataResultSet::get1Value(),
68 new ORowSetValueDecorator(sal_Int32(ColumnSearch::CHAR)),
69 ODatabaseMetaDataResultSet::get1Value(),
70 ODatabaseMetaDataResultSet::get0Value(),
71 ODatabaseMetaDataResultSet::get0Value(),
72 ODatabaseMetaDataResultSet::getEmptyValue(),
73 ODatabaseMetaDataResultSet::get0Value(),
74 ODatabaseMetaDataResultSet::get0Value(),
75 ODatabaseMetaDataResultSet::getEmptyValue(),
76 ODatabaseMetaDataResultSet::getEmptyValue(),
77 new ORowSetValueDecorator(sal_Int32(10))
80 aRows.push_back(aRow);
82 aRow[1] = new ORowSetValueDecorator(OUString("DECIMAL"));
83 aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL);
84 aRow[3] = ODatabaseMetaDataResultSet::get0Value();
85 aRow[9] = ODatabaseMetaDataResultSet::getBasicValue();
86 aRow[15] = ODatabaseMetaDataResultSet::get0Value();
87 aRows.push_back(aRow);
89 aRow[1] = new ORowSetValueDecorator(OUString("BOOL"));
90 aRow[2] = new ORowSetValueDecorator(DataType::BIT);
91 aRow[3] = new ORowSetValueDecorator(sal_Int32(20));
92 aRow[9] = ODatabaseMetaDataResultSet::getBasicValue();
93 aRow[15] = new ORowSetValueDecorator(sal_Int32(15));
94 aRows.push_back(aRow);
96 aRow[1] = new ORowSetValueDecorator(OUString("DATE"));
97 aRow[2] = new ORowSetValueDecorator(DataType::DATE);
98 aRow[3] = ODatabaseMetaDataResultSet::get0Value();
99 aRow[9] = ODatabaseMetaDataResultSet::getBasicValue();
100 aRow[15] = ODatabaseMetaDataResultSet::get0Value();
101 aRows.push_back(aRow);
103 aRow[1] = new ORowSetValueDecorator(OUString("TIME"));
104 aRow[2] = new ORowSetValueDecorator(DataType::TIME);
105 aRow[3] = ODatabaseMetaDataResultSet::get0Value();
106 aRow[9] = ODatabaseMetaDataResultSet::getBasicValue();
107 aRow[15] = ODatabaseMetaDataResultSet::get0Value();
108 aRows.push_back(aRow);
110 aRow[1] = new ORowSetValueDecorator(OUString("TIMESTAMP"));
111 aRow[2] = new ORowSetValueDecorator(DataType::TIMESTAMP);
112 aRow[3] = ODatabaseMetaDataResultSet::get0Value();
113 aRow[9] = ODatabaseMetaDataResultSet::getBasicValue();
114 aRow[15] = ODatabaseMetaDataResultSet::get0Value();
115 aRows.push_back(aRow);
118 pResult->setRows(aRows);
119 return pResult;
122 Reference< XResultSet > SAL_CALL OComponentDatabaseMetaData::getColumns(
123 const Any& /*catalog*/, const OUString& /*schemaPattern*/, const OUString& tableNamePattern,
124 const OUString& columnNamePattern )
126 ::osl::MutexGuard aGuard( m_aMutex );
129 Reference< XTablesSupplier > xTables = m_pConnection->createCatalog();
130 if(!xTables.is())
131 throw SQLException();
133 Reference< XNameAccess> xNames = xTables->getTables();
134 if(!xNames.is())
135 throw SQLException();
137 ODatabaseMetaDataResultSet::ORows aRows;
138 ODatabaseMetaDataResultSet::ORow aRow(19);
140 aRow[10] = new ORowSetValueDecorator(sal_Int32(10));
142 Sequence< OUString> aTabNames(xNames->getElementNames());
143 const OUString* pTabIter = aTabNames.getConstArray();
144 const OUString* pTabEnd = pTabIter + aTabNames.getLength();
145 for(;pTabIter != pTabEnd;++pTabIter)
147 if(match(tableNamePattern,*pTabIter,'\0'))
149 const Reference< XColumnsSupplier> xTable(xNames->getByName(*pTabIter),UNO_QUERY_THROW);
150 aRow[3] = new ORowSetValueDecorator(*pTabIter);
152 const Reference< XNameAccess> xColumns = xTable->getColumns();
153 if(!xColumns.is())
154 throw SQLException();
156 const Sequence< OUString> aColNames(xColumns->getElementNames());
158 const OUString* pColumnIter = aColNames.getConstArray();
159 const OUString* pEnd = pColumnIter + aColNames.getLength();
160 Reference< XPropertySet> xColumn;
161 for(sal_Int32 i=1;pColumnIter != pEnd;++pColumnIter,++i)
163 if(match(columnNamePattern,*pColumnIter,'\0'))
165 aRow[4] = new ORowSetValueDecorator( *pColumnIter);
167 xColumns->getByName(*pColumnIter) >>= xColumn;
168 OSL_ENSURE(xColumn.is(),"Columns contains a column who isn't a fastpropertyset!");
169 aRow[5] = new ORowSetValueDecorator(::comphelper::getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))));
170 aRow[6] = new ORowSetValueDecorator(::comphelper::getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))));
171 aRow[7] = new ORowSetValueDecorator(::comphelper::getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))));
172 // aRow[8] = xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME));
173 aRow[9] = new ORowSetValueDecorator(::comphelper::getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))));
174 aRow[11] = new ORowSetValueDecorator(::comphelper::getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))));
175 // aRow[12] = xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME));
176 aRow[13] = new ORowSetValueDecorator(::comphelper::getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE))));
177 // aRow[14] = xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME));
178 // aRow[15] = xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME));
179 switch(sal_Int32(aRow[5]->getValue()))
181 case DataType::CHAR:
182 case DataType::VARCHAR:
183 aRow[16] = new ORowSetValueDecorator(sal_Int32(254));
184 break;
185 case DataType::LONGVARCHAR:
186 aRow[16] = new ORowSetValueDecorator(sal_Int32(65535));
187 break;
188 default:
189 aRow[16] = new ORowSetValueDecorator(sal_Int32(0));
191 aRow[17] = new ORowSetValueDecorator(i);
192 switch(sal_Int32(aRow[11]->getValue()))
194 case ColumnValue::NO_NULLS:
195 aRow[18] = new ORowSetValueDecorator(OUString("NO"));
196 break;
197 case ColumnValue::NULLABLE:
198 aRow[18] = new ORowSetValueDecorator(OUString("YES"));
199 break;
200 default:
201 aRow[18] = new ORowSetValueDecorator(OUString());
203 aRows.push_back(aRow);
209 rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns);
210 pResult->setRows(aRows);
212 return pResult;
215 sal_Int32 SAL_CALL OComponentDatabaseMetaData::getMaxBinaryLiteralLength( )
217 return SAL_MAX_INT32;
220 sal_Int32 SAL_CALL OComponentDatabaseMetaData::getMaxCharLiteralLength( )
222 return SAL_MAX_INT32;
225 sal_Int32 SAL_CALL OComponentDatabaseMetaData::getMaxColumnNameLength( )
227 return SAL_MAX_INT32;
230 sal_Int32 SAL_CALL OComponentDatabaseMetaData::getMaxColumnsInIndex( )
232 return 1;
235 sal_Int32 SAL_CALL OComponentDatabaseMetaData::getMaxColumnsInTable( )
237 return 256;
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */