1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*9b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*9b5730f6SAndrew Rist * distributed with this work for additional information
6*9b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*9b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at
10*9b5730f6SAndrew Rist *
11*9b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist *
13*9b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist * KIND, either express or implied. See the License for the
17*9b5730f6SAndrew Rist * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist * under the License.
19*9b5730f6SAndrew Rist *
20*9b5730f6SAndrew Rist *************************************************************/
21*9b5730f6SAndrew Rist
22*9b5730f6SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include "flat/EDatabaseMetaData.hxx"
29cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
30cdf0e10cSrcweir #include <com/sun/star/sdbc/ResultSetType.hpp>
31cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnValue.hpp>
32cdf0e10cSrcweir #include <com/sun/star/beans/XFastPropertySet.hpp>
33cdf0e10cSrcweir #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
34cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
35cdf0e10cSrcweir #include <com/sun/star/sdbcx/XIndexesSupplier.hpp>
36cdf0e10cSrcweir #include <tools/urlobj.hxx>
37cdf0e10cSrcweir #include "FDatabaseMetaDataResultSet.hxx"
38cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp>
39cdf0e10cSrcweir #include <comphelper/extract.hxx>
40cdf0e10cSrcweir #include <comphelper/types.hxx>
41cdf0e10cSrcweir #include <rtl/logfile.hxx>
42cdf0e10cSrcweir
43cdf0e10cSrcweir using namespace ::comphelper;
44cdf0e10cSrcweir
45cdf0e10cSrcweir using namespace connectivity;
46cdf0e10cSrcweir using namespace connectivity::flat;
47cdf0e10cSrcweir // using namespace connectivity::file;
48cdf0e10cSrcweir using namespace ::com::sun::star::uno;
49cdf0e10cSrcweir using namespace ::com::sun::star::beans;
50cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
51cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
52cdf0e10cSrcweir using namespace ::com::sun::star::container;
53cdf0e10cSrcweir
54cdf0e10cSrcweir
55cdf0e10cSrcweir
OFlatDatabaseMetaData(::connectivity::file::OConnection * _pCon)56cdf0e10cSrcweir OFlatDatabaseMetaData::OFlatDatabaseMetaData(::connectivity::file::OConnection* _pCon) :ODatabaseMetaData(_pCon)
57cdf0e10cSrcweir {
58cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "flat", "Ocke.Janssen@sun.com", "OFlatDatabaseMetaData::OFlatDatabaseMetaData" );
59cdf0e10cSrcweir }
60cdf0e10cSrcweir // -------------------------------------------------------------------------
~OFlatDatabaseMetaData()61cdf0e10cSrcweir OFlatDatabaseMetaData::~OFlatDatabaseMetaData()
62cdf0e10cSrcweir {
63cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "flat", "Ocke.Janssen@sun.com", "OFlatDatabaseMetaData::~OFlatDatabaseMetaData" );
64cdf0e10cSrcweir }
65cdf0e10cSrcweir // -------------------------------------------------------------------------
impl_getTypeInfo_throw()66cdf0e10cSrcweir Reference< XResultSet > OFlatDatabaseMetaData::impl_getTypeInfo_throw( )
67cdf0e10cSrcweir {
68cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "flat", "Ocke.Janssen@sun.com", "OFlatDatabaseMetaData::impl_getTypeInfo_throw" );
69cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
70cdf0e10cSrcweir
71cdf0e10cSrcweir ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo);
72cdf0e10cSrcweir Reference< XResultSet > xRef = pResult;
73cdf0e10cSrcweir
74cdf0e10cSrcweir static ODatabaseMetaDataResultSet::ORows aRows;
75cdf0e10cSrcweir if(aRows.empty())
76cdf0e10cSrcweir {
77cdf0e10cSrcweir ODatabaseMetaDataResultSet::ORow aRow;
78cdf0e10cSrcweir
79cdf0e10cSrcweir aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
80cdf0e10cSrcweir aRow.push_back(new ORowSetValueDecorator(::rtl::OUString::createFromAscii("CHAR")));
81cdf0e10cSrcweir aRow.push_back(new ORowSetValueDecorator(DataType::CHAR));
82cdf0e10cSrcweir aRow.push_back(new ORowSetValueDecorator((sal_Int32)254));
83cdf0e10cSrcweir aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue());
84cdf0e10cSrcweir aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue());
85cdf0e10cSrcweir aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
86cdf0e10cSrcweir aRow.push_back(new ORowSetValueDecorator((sal_Int32)ColumnValue::NULLABLE));
87cdf0e10cSrcweir aRow.push_back(ODatabaseMetaDataResultSet::get1Value());
88cdf0e10cSrcweir aRow.push_back(new ORowSetValueDecorator((sal_Int32)ColumnSearch::CHAR));
89cdf0e10cSrcweir aRow.push_back(ODatabaseMetaDataResultSet::get1Value());
90cdf0e10cSrcweir aRow.push_back(ODatabaseMetaDataResultSet::get0Value());
91cdf0e10cSrcweir aRow.push_back(ODatabaseMetaDataResultSet::get0Value());
92cdf0e10cSrcweir aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
93cdf0e10cSrcweir aRow.push_back(ODatabaseMetaDataResultSet::get0Value());
94cdf0e10cSrcweir aRow.push_back(ODatabaseMetaDataResultSet::get0Value());
95cdf0e10cSrcweir aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
96cdf0e10cSrcweir aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
97cdf0e10cSrcweir aRow.push_back(new ORowSetValueDecorator((sal_Int32)10));
98cdf0e10cSrcweir
99cdf0e10cSrcweir aRows.push_back(aRow);
100cdf0e10cSrcweir
101cdf0e10cSrcweir aRow[1] = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("VARCHAR"));
102cdf0e10cSrcweir aRow[2] = new ORowSetValueDecorator(DataType::VARCHAR);
103cdf0e10cSrcweir aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue();
104cdf0e10cSrcweir aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue();
105cdf0e10cSrcweir aRows.push_back(aRow);
106cdf0e10cSrcweir
107cdf0e10cSrcweir
108cdf0e10cSrcweir aRow[1] = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("LONGVARCHAR"));
109cdf0e10cSrcweir aRow[2] = new ORowSetValueDecorator(DataType::LONGVARCHAR);
110cdf0e10cSrcweir aRow[3] = new ORowSetValueDecorator((sal_Int32)65535);
111cdf0e10cSrcweir aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue();
112cdf0e10cSrcweir aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue();
113cdf0e10cSrcweir aRows.push_back(aRow);
114cdf0e10cSrcweir
115cdf0e10cSrcweir aRow[1] = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("DATE"));
116cdf0e10cSrcweir aRow[2] = new ORowSetValueDecorator(DataType::DATE);
117cdf0e10cSrcweir aRow[3] = new ORowSetValueDecorator((sal_Int32)10);
118cdf0e10cSrcweir aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue();
119cdf0e10cSrcweir aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue();
120cdf0e10cSrcweir aRows.push_back(aRow);
121cdf0e10cSrcweir
122cdf0e10cSrcweir aRow[1] = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("TIME"));
123cdf0e10cSrcweir aRow[2] = new ORowSetValueDecorator(DataType::TIME);
124cdf0e10cSrcweir aRow[3] = new ORowSetValueDecorator((sal_Int32)8);
125cdf0e10cSrcweir aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue();
126cdf0e10cSrcweir aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue();
127cdf0e10cSrcweir aRows.push_back(aRow);
128cdf0e10cSrcweir
129cdf0e10cSrcweir aRow[1] = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("TIMESTAMP"));
130cdf0e10cSrcweir aRow[2] = new ORowSetValueDecorator(DataType::TIMESTAMP);
131cdf0e10cSrcweir aRow[3] = new ORowSetValueDecorator((sal_Int32)19);
132cdf0e10cSrcweir aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue();
133cdf0e10cSrcweir aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue();
134cdf0e10cSrcweir aRows.push_back(aRow);
135cdf0e10cSrcweir
136cdf0e10cSrcweir aRow[1] = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("BOOL"));
137cdf0e10cSrcweir aRow[2] = new ORowSetValueDecorator(DataType::BIT);
138cdf0e10cSrcweir aRow[3] = ODatabaseMetaDataResultSet::get1Value();
139cdf0e10cSrcweir aRow[9] = ODatabaseMetaDataResultSet::getBasicValue();
140cdf0e10cSrcweir aRows.push_back(aRow);
141cdf0e10cSrcweir
142cdf0e10cSrcweir aRow[1] = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("DECIMAL"));
143cdf0e10cSrcweir aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL);
144cdf0e10cSrcweir aRow[3] = new ORowSetValueDecorator((sal_Int32)20);
145cdf0e10cSrcweir aRow[15] = new ORowSetValueDecorator((sal_Int32)15);
146cdf0e10cSrcweir aRows.push_back(aRow);
147cdf0e10cSrcweir
148cdf0e10cSrcweir aRow[1] = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("DOUBLE"));
149cdf0e10cSrcweir aRow[2] = new ORowSetValueDecorator(DataType::DOUBLE);
150cdf0e10cSrcweir aRow[3] = new ORowSetValueDecorator((sal_Int32)20);
151cdf0e10cSrcweir aRow[15] = ODatabaseMetaDataResultSet::get0Value();
152cdf0e10cSrcweir aRows.push_back(aRow);
153cdf0e10cSrcweir
154cdf0e10cSrcweir aRow[1] = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("NUMERIC"));
155cdf0e10cSrcweir aRow[2] = new ORowSetValueDecorator(DataType::NUMERIC);
156cdf0e10cSrcweir aRow[3] = new ORowSetValueDecorator((sal_Int32)20);
157cdf0e10cSrcweir aRow[15] = new ORowSetValueDecorator((sal_Int32)20);
158cdf0e10cSrcweir aRows.push_back(aRow);
159cdf0e10cSrcweir }
160cdf0e10cSrcweir
161cdf0e10cSrcweir pResult->setRows(aRows);
162cdf0e10cSrcweir return xRef;
163cdf0e10cSrcweir }
164cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumns(const Any &,const::rtl::OUString &,const::rtl::OUString & tableNamePattern,const::rtl::OUString & columnNamePattern)165cdf0e10cSrcweir Reference< XResultSet > SAL_CALL OFlatDatabaseMetaData::getColumns(
166cdf0e10cSrcweir const Any& /*catalog*/, const ::rtl::OUString& /*schemaPattern*/, const ::rtl::OUString& tableNamePattern,
167cdf0e10cSrcweir const ::rtl::OUString& columnNamePattern ) throw(SQLException, RuntimeException)
168cdf0e10cSrcweir {
169cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "flat", "Ocke.Janssen@sun.com", "OFlatDatabaseMetaData::getColumns" );
170cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
171cdf0e10cSrcweir
172cdf0e10cSrcweir Reference< XTablesSupplier > xTables = m_pConnection->createCatalog();
173cdf0e10cSrcweir if(!xTables.is())
174cdf0e10cSrcweir throw SQLException();
175cdf0e10cSrcweir
176cdf0e10cSrcweir Reference< XNameAccess> xNames = xTables->getTables();
177cdf0e10cSrcweir if(!xNames.is())
178cdf0e10cSrcweir throw SQLException();
179cdf0e10cSrcweir
180cdf0e10cSrcweir ODatabaseMetaDataResultSet::ORows aRows;
181cdf0e10cSrcweir ODatabaseMetaDataResultSet::ORow aRow(19);
182cdf0e10cSrcweir aRow[10] = new ORowSetValueDecorator((sal_Int32)10);
183cdf0e10cSrcweir Sequence< ::rtl::OUString> aTabNames(xNames->getElementNames());
184cdf0e10cSrcweir const ::rtl::OUString* pTabBegin = aTabNames.getConstArray();
185cdf0e10cSrcweir const ::rtl::OUString* pTabEnd = pTabBegin + aTabNames.getLength();
186cdf0e10cSrcweir for(;pTabBegin != pTabEnd;++pTabBegin)
187cdf0e10cSrcweir {
188cdf0e10cSrcweir if(match(tableNamePattern,*pTabBegin,'\0'))
189cdf0e10cSrcweir {
190cdf0e10cSrcweir Reference< XColumnsSupplier> xTable;
191cdf0e10cSrcweir ::cppu::extractInterface(xTable,xNames->getByName(*pTabBegin));
192cdf0e10cSrcweir aRow[3] = new ORowSetValueDecorator(*pTabBegin);
193cdf0e10cSrcweir
194cdf0e10cSrcweir Reference< XNameAccess> xColumns = xTable->getColumns();
195cdf0e10cSrcweir if(!xColumns.is())
196cdf0e10cSrcweir throw SQLException();
197cdf0e10cSrcweir
198cdf0e10cSrcweir Sequence< ::rtl::OUString> aColNames(xColumns->getElementNames());
199cdf0e10cSrcweir
200cdf0e10cSrcweir const ::rtl::OUString* pBegin = aColNames.getConstArray();
201cdf0e10cSrcweir const ::rtl::OUString* pEnd = pBegin + aColNames.getLength();
202cdf0e10cSrcweir Reference< XPropertySet> xColumn;
203cdf0e10cSrcweir for(sal_Int32 i=1;pBegin != pEnd;++pBegin,++i)
204cdf0e10cSrcweir {
205cdf0e10cSrcweir if(match(columnNamePattern,*pBegin,'\0'))
206cdf0e10cSrcweir {
207cdf0e10cSrcweir aRow[4] = new ORowSetValueDecorator(*pBegin);
208cdf0e10cSrcweir
209cdf0e10cSrcweir ::cppu::extractInterface(xColumn,xColumns->getByName(*pBegin));
210cdf0e10cSrcweir OSL_ENSURE(xColumn.is(),"Columns contains a column who isn't a fastpropertyset!");
211cdf0e10cSrcweir aRow[5] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))));
212cdf0e10cSrcweir aRow[6] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))));
213cdf0e10cSrcweir aRow[7] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))));
214cdf0e10cSrcweir aRow[9] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))));
215cdf0e10cSrcweir aRow[11] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))));
216cdf0e10cSrcweir aRow[13] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE))));
217cdf0e10cSrcweir
218cdf0e10cSrcweir switch((sal_Int32)aRow[5]->getValue())
219cdf0e10cSrcweir {
220cdf0e10cSrcweir case DataType::CHAR:
221cdf0e10cSrcweir case DataType::VARCHAR:
222cdf0e10cSrcweir aRow[16] = new ORowSetValueDecorator((sal_Int32)254);
223cdf0e10cSrcweir break;
224cdf0e10cSrcweir case DataType::LONGVARCHAR:
225cdf0e10cSrcweir aRow[16] = new ORowSetValueDecorator((sal_Int32)65535);
226cdf0e10cSrcweir break;
227cdf0e10cSrcweir default:
228cdf0e10cSrcweir aRow[16] = new ORowSetValueDecorator((sal_Int32)0);
229cdf0e10cSrcweir }
230cdf0e10cSrcweir aRow[17] = new ORowSetValueDecorator(i);
231cdf0e10cSrcweir switch(sal_Int32(aRow[11]->getValue()))
232cdf0e10cSrcweir {
233cdf0e10cSrcweir case ColumnValue::NO_NULLS:
234cdf0e10cSrcweir aRow[18] = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("NO"));
235cdf0e10cSrcweir break;
236cdf0e10cSrcweir case ColumnValue::NULLABLE:
237cdf0e10cSrcweir aRow[18] = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("YES"));
238cdf0e10cSrcweir break;
239cdf0e10cSrcweir default:
240cdf0e10cSrcweir aRow[18] = new ORowSetValueDecorator(::rtl::OUString());
241cdf0e10cSrcweir }
242cdf0e10cSrcweir aRows.push_back(aRow);
243cdf0e10cSrcweir }
244cdf0e10cSrcweir }
245cdf0e10cSrcweir }
246cdf0e10cSrcweir }
247cdf0e10cSrcweir
248cdf0e10cSrcweir ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns);
249cdf0e10cSrcweir Reference< XResultSet > xRef = pResult;
250cdf0e10cSrcweir pResult->setRows(aRows);
251cdf0e10cSrcweir
252cdf0e10cSrcweir return xRef;
253cdf0e10cSrcweir }
254cdf0e10cSrcweir // -------------------------------------------------------------------------
getURL()255cdf0e10cSrcweir ::rtl::OUString SAL_CALL OFlatDatabaseMetaData::getURL( ) throw(SQLException, RuntimeException)
256cdf0e10cSrcweir {
257cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "flat", "Ocke.Janssen@sun.com", "OFlatDatabaseMetaData::getURL" );
258cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
259cdf0e10cSrcweir return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:flat:")) + m_pConnection->getURL();
260cdf0e10cSrcweir }
261cdf0e10cSrcweir // -----------------------------------------------------------------------------
262cdf0e10cSrcweir
263cdf0e10cSrcweir
264