1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <flat/EDatabaseMetaData.hxx>
21 #include <com/sun/star/sdbc/ColumnSearch.hpp>
22 #include <com/sun/star/sdbc/DataType.hpp>
23 #include <com/sun/star/sdbc/ColumnValue.hpp>
24 #include <com/sun/star/sdbc/SQLException.hpp>
25 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
26 #include <FDatabaseMetaDataResultSet.hxx>
27 #include <comphelper/types.hxx>
29 using namespace ::comphelper
;
31 using namespace connectivity
;
32 using namespace connectivity::flat
;
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
;
40 OFlatDatabaseMetaData::OFlatDatabaseMetaData(::connectivity::file::OConnection
* _pCon
) :ODatabaseMetaData(_pCon
)
44 OFlatDatabaseMetaData::~OFlatDatabaseMetaData()
48 Reference
< XResultSet
> OFlatDatabaseMetaData::impl_getTypeInfo_throw( )
50 ::osl::MutexGuard
aGuard( m_aMutex
);
52 rtl::Reference
<::connectivity::ODatabaseMetaDataResultSet
> pResult
= new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo
);
54 static ODatabaseMetaDataResultSet::ORows aRows
= [&]()
56 ODatabaseMetaDataResultSet::ORows
tmp(10);
57 ODatabaseMetaDataResultSet::ORow aRow
59 ODatabaseMetaDataResultSet::getEmptyValue() ,
60 new ORowSetValueDecorator(OUString("CHAR")) ,
61 new ORowSetValueDecorator(DataType::CHAR
) ,
62 new ORowSetValueDecorator(sal_Int32(254)) ,
63 ODatabaseMetaDataResultSet::getQuoteValue() ,
64 ODatabaseMetaDataResultSet::getQuoteValue() ,
65 ODatabaseMetaDataResultSet::getEmptyValue() ,
66 new ORowSetValueDecorator(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))
82 aRow
[1] = new ORowSetValueDecorator(OUString("VARCHAR"));
83 aRow
[2] = new ORowSetValueDecorator(DataType::VARCHAR
);
84 aRow
[4] = ODatabaseMetaDataResultSet::getQuoteValue();
85 aRow
[5] = ODatabaseMetaDataResultSet::getQuoteValue();
89 aRow
[1] = new ORowSetValueDecorator(OUString("LONGVARCHAR"));
90 aRow
[2] = new ORowSetValueDecorator(DataType::LONGVARCHAR
);
91 aRow
[3] = new ORowSetValueDecorator(sal_Int32(65535));
92 aRow
[4] = ODatabaseMetaDataResultSet::getQuoteValue();
93 aRow
[5] = ODatabaseMetaDataResultSet::getQuoteValue();
96 aRow
[1] = new ORowSetValueDecorator(OUString("DATE"));
97 aRow
[2] = new ORowSetValueDecorator(DataType::DATE
);
98 aRow
[3] = new ORowSetValueDecorator(sal_Int32(10));
99 aRow
[4] = ODatabaseMetaDataResultSet::getQuoteValue();
100 aRow
[5] = ODatabaseMetaDataResultSet::getQuoteValue();
103 aRow
[1] = new ORowSetValueDecorator(OUString("TIME"));
104 aRow
[2] = new ORowSetValueDecorator(DataType::TIME
);
105 aRow
[3] = new ORowSetValueDecorator(sal_Int32(8));
106 aRow
[4] = ODatabaseMetaDataResultSet::getQuoteValue();
107 aRow
[5] = ODatabaseMetaDataResultSet::getQuoteValue();
110 aRow
[1] = new ORowSetValueDecorator(OUString("TIMESTAMP"));
111 aRow
[2] = new ORowSetValueDecorator(DataType::TIMESTAMP
);
112 aRow
[3] = new ORowSetValueDecorator(sal_Int32(19));
113 aRow
[4] = ODatabaseMetaDataResultSet::getQuoteValue();
114 aRow
[5] = ODatabaseMetaDataResultSet::getQuoteValue();
117 aRow
[1] = new ORowSetValueDecorator(OUString("BOOL"));
118 aRow
[2] = new ORowSetValueDecorator(DataType::BIT
);
119 aRow
[3] = ODatabaseMetaDataResultSet::get1Value();
120 aRow
[9] = ODatabaseMetaDataResultSet::getBasicValue();
123 aRow
[1] = new ORowSetValueDecorator(OUString("DECIMAL"));
124 aRow
[2] = new ORowSetValueDecorator(DataType::DECIMAL
);
125 aRow
[3] = new ORowSetValueDecorator(sal_Int32(20));
126 aRow
[15] = new ORowSetValueDecorator(sal_Int32(15));
129 aRow
[1] = new ORowSetValueDecorator(OUString("DOUBLE"));
130 aRow
[2] = new ORowSetValueDecorator(DataType::DOUBLE
);
131 aRow
[3] = new ORowSetValueDecorator(sal_Int32(20));
132 aRow
[15] = ODatabaseMetaDataResultSet::get0Value();
135 aRow
[1] = new ORowSetValueDecorator(OUString("NUMERIC"));
136 aRow
[2] = new ORowSetValueDecorator(DataType::NUMERIC
);
137 aRow
[3] = new ORowSetValueDecorator(sal_Int32(20));
138 aRow
[15] = new ORowSetValueDecorator(sal_Int32(20));
144 pResult
->setRows(aRows
);
148 Reference
< XResultSet
> SAL_CALL
OFlatDatabaseMetaData::getColumns(
149 const Any
& /*catalog*/, const OUString
& /*schemaPattern*/, const OUString
& tableNamePattern
,
150 const OUString
& columnNamePattern
)
152 ::osl::MutexGuard
aGuard( m_aMutex
);
154 Reference
< XTablesSupplier
> xTables
= m_pConnection
->createCatalog();
156 throw SQLException();
158 Reference
< XNameAccess
> xNames
= xTables
->getTables();
160 throw SQLException();
162 ODatabaseMetaDataResultSet::ORows aRows
;
163 ODatabaseMetaDataResultSet::ORow
aRow(19);
164 aRow
[10] = new ORowSetValueDecorator(sal_Int32(10));
165 Sequence
< OUString
> aTabNames(xNames
->getElementNames());
166 const OUString
* pTabBegin
= aTabNames
.getConstArray();
167 const OUString
* pTabEnd
= pTabBegin
+ aTabNames
.getLength();
168 for(;pTabBegin
!= pTabEnd
;++pTabBegin
)
170 if(match(tableNamePattern
,*pTabBegin
,'\0'))
172 Reference
< XColumnsSupplier
> xTable(
173 xNames
->getByName(*pTabBegin
), css::uno::UNO_QUERY
);
174 aRow
[3] = new ORowSetValueDecorator(*pTabBegin
);
176 Reference
< XNameAccess
> xColumns
= xTable
->getColumns();
178 throw SQLException();
180 Sequence
< OUString
> aColNames(xColumns
->getElementNames());
182 const OUString
* pBegin
= aColNames
.getConstArray();
183 const OUString
* pEnd
= pBegin
+ aColNames
.getLength();
184 Reference
< XPropertySet
> xColumn
;
185 for(sal_Int32 i
=1;pBegin
!= pEnd
;++pBegin
,++i
)
187 if(match(columnNamePattern
,*pBegin
,'\0'))
189 aRow
[4] = new ORowSetValueDecorator(*pBegin
);
192 xColumns
->getByName(*pBegin
), css::uno::UNO_QUERY
);
193 OSL_ENSURE(xColumn
.is(),"Columns contains a column who isn't a fastpropertyset!");
194 aRow
[5] = new ORowSetValueDecorator(getINT32(xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE
))));
195 aRow
[6] = new ORowSetValueDecorator(getString(xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME
))));
196 aRow
[7] = new ORowSetValueDecorator(getINT32(xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION
))));
197 aRow
[9] = new ORowSetValueDecorator(getINT32(xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE
))));
198 aRow
[11] = new ORowSetValueDecorator(getINT32(xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE
))));
199 aRow
[13] = new ORowSetValueDecorator(getString(xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE
))));
201 switch(static_cast<sal_Int32
>(aRow
[5]->getValue()))
204 case DataType::VARCHAR
:
205 aRow
[16] = new ORowSetValueDecorator(sal_Int32(254));
207 case DataType::LONGVARCHAR
:
208 aRow
[16] = new ORowSetValueDecorator(sal_Int32(65535));
211 aRow
[16] = new ORowSetValueDecorator(sal_Int32(0));
213 aRow
[17] = new ORowSetValueDecorator(i
);
214 switch(sal_Int32(aRow
[11]->getValue()))
216 case ColumnValue::NO_NULLS
:
217 aRow
[18] = new ORowSetValueDecorator(OUString("NO"));
219 case ColumnValue::NULLABLE
:
220 aRow
[18] = new ORowSetValueDecorator(OUString("YES"));
223 aRow
[18] = new ORowSetValueDecorator(OUString());
225 aRows
.push_back(aRow
);
231 rtl::Reference
<::connectivity::ODatabaseMetaDataResultSet
> pResult
= new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns
);
232 pResult
->setRows(aRows
);
237 OUString SAL_CALL
OFlatDatabaseMetaData::getURL( )
239 ::osl::MutexGuard
aGuard( m_aMutex
);
240 return "sdbc:flat:" + m_pConnection
->getURL();
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */