1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26
27 #include "MacabResultSetMetaData.hxx"
28 #include "MacabHeader.hxx"
29 #include "MacabRecords.hxx"
30 #include "MacabAddressBook.hxx"
31 #include "macabutilities.hxx"
32 #include "resource/macab_res.hrc"
33
34 using namespace connectivity::macab;
35 using namespace com::sun::star::uno;
36 using namespace com::sun::star::lang;
37 using namespace com::sun::star::sdbc;
38
MacabResultSetMetaData(MacabConnection * _pConnection,::rtl::OUString _sTableName)39 MacabResultSetMetaData::MacabResultSetMetaData(MacabConnection* _pConnection, ::rtl::OUString _sTableName)
40 : m_pConnection(_pConnection),
41 m_sTableName(_sTableName),
42 m_aMacabFields()
43 {
44 }
45 // -------------------------------------------------------------------------
~MacabResultSetMetaData()46 MacabResultSetMetaData::~MacabResultSetMetaData()
47 {
48 }
49 // -------------------------------------------------------------------------
setMacabFields(const::vos::ORef<connectivity::OSQLColumns> & xColumns)50 void MacabResultSetMetaData::setMacabFields(const ::vos::ORef<connectivity::OSQLColumns> &xColumns) throw(SQLException)
51 {
52 OSQLColumns::Vector::const_iterator aIter;
53 static const ::rtl::OUString aName(::rtl::OUString::createFromAscii("Name"));
54 MacabRecords *aRecords;
55 MacabHeader *aHeader;
56
57 aRecords = m_pConnection->getAddressBook()->getMacabRecords(m_sTableName);
58
59 // In case, somehow, we don't have anything with the name m_sTableName
60 if(aRecords == NULL)
61 {
62 impl_throwError(STR_NO_TABLE);
63 }
64
65 aHeader = aRecords->getHeader();
66
67 for (aIter = xColumns->get().begin(); aIter != xColumns->get().end(); ++aIter)
68 {
69 ::rtl::OUString aFieldName;
70 sal_uInt32 nFieldNumber;
71
72 (*aIter)->getPropertyValue(aName) >>= aFieldName;
73 nFieldNumber = aHeader->getColumnNumber(aFieldName);
74 m_aMacabFields.push_back(nFieldNumber);
75 }
76
77 }
78 // -------------------------------------------------------------------------
getColumnDisplaySize(sal_Int32 column)79 sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnDisplaySize(sal_Int32 column) throw(SQLException, RuntimeException)
80 {
81 // For now, all columns are the same size.
82 return 50;
83 }
84 // -------------------------------------------------------------------------
getColumnType(sal_Int32 column)85 sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnType(sal_Int32 column) throw(SQLException, RuntimeException)
86 {
87 MacabRecords *aRecords;
88 MacabHeader *aHeader;
89 macabfield *aField;
90
91 aRecords = m_pConnection->getAddressBook()->getMacabRecords(m_sTableName);
92
93 // In case, somehow, we don't have anything with the name m_sTableName
94 if(aRecords == NULL)
95 {
96 impl_throwError(STR_NO_TABLE);
97 }
98
99 aHeader = aRecords->getHeader();
100 aField = aHeader->get(column-1);
101
102 if(aField == NULL)
103 {
104 ::dbtools::throwInvalidIndexException(*this,Any());
105 return -1;
106 }
107
108 return ABTypeToDataType(aField->type);
109 }
110 // -------------------------------------------------------------------------
getColumnCount()111 sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnCount() throw(SQLException, RuntimeException)
112 {
113 return m_aMacabFields.size();
114 }
115 // -------------------------------------------------------------------------
isCaseSensitive(sal_Int32)116 sal_Bool SAL_CALL MacabResultSetMetaData::isCaseSensitive(sal_Int32) throw(SQLException, RuntimeException)
117 {
118 return sal_True;
119 }
120 // -------------------------------------------------------------------------
getSchemaName(sal_Int32)121 ::rtl::OUString SAL_CALL MacabResultSetMetaData::getSchemaName(sal_Int32) throw(SQLException, RuntimeException)
122 {
123 return ::rtl::OUString();
124 }
125 // -------------------------------------------------------------------------
getColumnName(sal_Int32 column)126 ::rtl::OUString SAL_CALL MacabResultSetMetaData::getColumnName(sal_Int32 column) throw(SQLException, RuntimeException)
127 {
128 sal_uInt32 nFieldNumber = m_aMacabFields[column - 1];
129 MacabRecords *aRecords;
130 MacabHeader *aHeader;
131
132 aRecords = m_pConnection->getAddressBook()->getMacabRecords(m_sTableName);
133
134 // In case, somehow, we don't have anything with the name m_sTableName
135 if(aRecords == NULL)
136 {
137 impl_throwError(STR_NO_TABLE);
138 }
139
140 aHeader = aRecords->getHeader();
141 ::rtl::OUString aName = aHeader->getString(nFieldNumber);
142
143 return aName;
144 }
145 // -------------------------------------------------------------------------
getTableName(sal_Int32)146 ::rtl::OUString SAL_CALL MacabResultSetMetaData::getTableName(sal_Int32) throw(SQLException, RuntimeException)
147 {
148 return m_sTableName;
149 }
150 // -------------------------------------------------------------------------
getCatalogName(sal_Int32)151 ::rtl::OUString SAL_CALL MacabResultSetMetaData::getCatalogName(sal_Int32) throw(SQLException, RuntimeException)
152 {
153 return ::rtl::OUString();
154 }
155 // -------------------------------------------------------------------------
getColumnTypeName(sal_Int32)156 ::rtl::OUString SAL_CALL MacabResultSetMetaData::getColumnTypeName(sal_Int32) throw(SQLException, RuntimeException)
157 {
158 return ::rtl::OUString();
159 }
160 // -------------------------------------------------------------------------
getColumnLabel(sal_Int32)161 ::rtl::OUString SAL_CALL MacabResultSetMetaData::getColumnLabel(sal_Int32) throw(SQLException, RuntimeException)
162 {
163 return ::rtl::OUString();
164 }
165 // -------------------------------------------------------------------------
getColumnServiceName(sal_Int32)166 ::rtl::OUString SAL_CALL MacabResultSetMetaData::getColumnServiceName(sal_Int32) throw(SQLException, RuntimeException)
167 {
168 return ::rtl::OUString();
169 }
170 // -------------------------------------------------------------------------
isCurrency(sal_Int32)171 sal_Bool SAL_CALL MacabResultSetMetaData::isCurrency(sal_Int32) throw(SQLException, RuntimeException)
172 {
173 return sal_False;
174 }
175 // -------------------------------------------------------------------------
isAutoIncrement(sal_Int32)176 sal_Bool SAL_CALL MacabResultSetMetaData::isAutoIncrement(sal_Int32) throw(SQLException, RuntimeException)
177 {
178 return sal_False;
179 }
180 // -------------------------------------------------------------------------
isSigned(sal_Int32)181 sal_Bool SAL_CALL MacabResultSetMetaData::isSigned(sal_Int32) throw(SQLException, RuntimeException)
182 {
183 return sal_False;
184 }
185 // -------------------------------------------------------------------------
getPrecision(sal_Int32)186 sal_Int32 SAL_CALL MacabResultSetMetaData::getPrecision(sal_Int32) throw(SQLException, RuntimeException)
187 {
188 return 0;
189 }
190 // -----------------------------------------------------------------------------
getScale(sal_Int32)191 sal_Int32 SAL_CALL MacabResultSetMetaData::getScale(sal_Int32) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
192 {
193 return 0;
194 }
195 // -------------------------------------------------------------------------
isNullable(sal_Int32)196 sal_Int32 SAL_CALL MacabResultSetMetaData::isNullable(sal_Int32) throw(SQLException, RuntimeException)
197 {
198 return (sal_Int32) sal_True;
199 }
200 // -------------------------------------------------------------------------
isSearchable(sal_Int32)201 sal_Bool SAL_CALL MacabResultSetMetaData::isSearchable(sal_Int32) throw(SQLException, RuntimeException)
202 {
203 return sal_True;
204 }
205 // -------------------------------------------------------------------------
isReadOnly(sal_Int32)206 sal_Bool SAL_CALL MacabResultSetMetaData::isReadOnly(sal_Int32) throw(SQLException, RuntimeException)
207 {
208 return sal_True;
209 }
210 // -------------------------------------------------------------------------
isDefinitelyWritable(sal_Int32)211 sal_Bool SAL_CALL MacabResultSetMetaData::isDefinitelyWritable(sal_Int32) throw(SQLException, RuntimeException)
212 {
213 return sal_False;
214 }
215 // -------------------------------------------------------------------------
isWritable(sal_Int32)216 sal_Bool SAL_CALL MacabResultSetMetaData::isWritable(sal_Int32) throw(SQLException, RuntimeException)
217 {
218 return sal_False;
219 }
220 // -------------------------------------------------------------------------
221