1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_connectivity.hxx"
30 
31 #include "MacabResultSetMetaData.hxx"
32 #include "MacabHeader.hxx"
33 #include "MacabRecords.hxx"
34 #include "MacabAddressBook.hxx"
35 #include "macabutilities.hxx"
36 #include "resource/macab_res.hrc"
37 
38 using namespace connectivity::macab;
39 using namespace com::sun::star::uno;
40 using namespace com::sun::star::lang;
41 using namespace com::sun::star::sdbc;
42 
43 MacabResultSetMetaData::MacabResultSetMetaData(MacabConnection* _pConnection, ::rtl::OUString _sTableName)
44 	: m_pConnection(_pConnection),
45 		m_sTableName(_sTableName),
46 	  m_aMacabFields()
47 {
48 }
49 // -------------------------------------------------------------------------
50 MacabResultSetMetaData::~MacabResultSetMetaData()
51 {
52 }
53 // -------------------------------------------------------------------------
54 void MacabResultSetMetaData::setMacabFields(const ::vos::ORef<connectivity::OSQLColumns> &xColumns) throw(SQLException)
55 {
56 	OSQLColumns::Vector::const_iterator aIter;
57 	static const ::rtl::OUString aName(::rtl::OUString::createFromAscii("Name"));
58 	MacabRecords *aRecords;
59 	MacabHeader *aHeader;
60 
61 	aRecords = m_pConnection->getAddressBook()->getMacabRecords(m_sTableName);
62 
63 	// In case, somehow, we don't have anything with the name m_sTableName
64 	if(aRecords == NULL)
65 	{
66         impl_throwError(STR_NO_TABLE);
67 	}
68 
69 	aHeader = aRecords->getHeader();
70 
71 	for (aIter = xColumns->get().begin(); aIter != xColumns->get().end(); ++aIter)
72 	{
73 		::rtl::OUString aFieldName;
74 		sal_uInt32 nFieldNumber;
75 
76 		(*aIter)->getPropertyValue(aName) >>= aFieldName;
77 		nFieldNumber = aHeader->getColumnNumber(aFieldName);
78 		m_aMacabFields.push_back(nFieldNumber);
79 	}
80 
81 }
82 // -------------------------------------------------------------------------
83 sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnDisplaySize(sal_Int32 column) throw(SQLException, RuntimeException)
84 {
85 	// For now, all columns are the same size.
86 	return 50;
87 }
88 // -------------------------------------------------------------------------
89 sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnType(sal_Int32 column) throw(SQLException, RuntimeException)
90 {
91 	MacabRecords *aRecords;
92 	MacabHeader *aHeader;
93 	macabfield *aField;
94 
95 	aRecords = m_pConnection->getAddressBook()->getMacabRecords(m_sTableName);
96 
97 	// In case, somehow, we don't have anything with the name m_sTableName
98 	if(aRecords == NULL)
99 	{
100         impl_throwError(STR_NO_TABLE);
101 	}
102 
103 	aHeader = aRecords->getHeader();
104 	aField = aHeader->get(column-1);
105 
106 	if(aField == NULL)
107 	{
108         ::dbtools::throwInvalidIndexException(*this,Any());
109 		return -1;
110 	}
111 
112 	return ABTypeToDataType(aField->type);
113 }
114 // -------------------------------------------------------------------------
115 sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnCount() throw(SQLException, RuntimeException)
116 {
117 	return m_aMacabFields.size();
118 }
119 // -------------------------------------------------------------------------
120 sal_Bool SAL_CALL MacabResultSetMetaData::isCaseSensitive(sal_Int32) throw(SQLException, RuntimeException)
121 {
122 	return sal_True;
123 }
124 // -------------------------------------------------------------------------
125 ::rtl::OUString SAL_CALL MacabResultSetMetaData::getSchemaName(sal_Int32) throw(SQLException, RuntimeException)
126 {
127 	return ::rtl::OUString();
128 }
129 // -------------------------------------------------------------------------
130 ::rtl::OUString SAL_CALL MacabResultSetMetaData::getColumnName(sal_Int32 column) throw(SQLException, RuntimeException)
131 {
132 	sal_uInt32 nFieldNumber = m_aMacabFields[column - 1];
133 	MacabRecords *aRecords;
134 	MacabHeader *aHeader;
135 
136 	aRecords = m_pConnection->getAddressBook()->getMacabRecords(m_sTableName);
137 
138 	// In case, somehow, we don't have anything with the name m_sTableName
139 	if(aRecords == NULL)
140 	{
141 		impl_throwError(STR_NO_TABLE);
142 	}
143 
144 	aHeader = aRecords->getHeader();
145 	::rtl::OUString aName = aHeader->getString(nFieldNumber);
146 
147 	return aName;
148 }
149 // -------------------------------------------------------------------------
150 ::rtl::OUString SAL_CALL MacabResultSetMetaData::getTableName(sal_Int32) throw(SQLException, RuntimeException)
151 {
152 	return m_sTableName;
153 }
154 // -------------------------------------------------------------------------
155 ::rtl::OUString SAL_CALL MacabResultSetMetaData::getCatalogName(sal_Int32) throw(SQLException, RuntimeException)
156 {
157 	return ::rtl::OUString();
158 }
159 // -------------------------------------------------------------------------
160 ::rtl::OUString SAL_CALL MacabResultSetMetaData::getColumnTypeName(sal_Int32) throw(SQLException, RuntimeException)
161 {
162 	return ::rtl::OUString();
163 }
164 // -------------------------------------------------------------------------
165 ::rtl::OUString SAL_CALL MacabResultSetMetaData::getColumnLabel(sal_Int32) throw(SQLException, RuntimeException)
166 {
167 	return ::rtl::OUString();
168 }
169 // -------------------------------------------------------------------------
170 ::rtl::OUString SAL_CALL MacabResultSetMetaData::getColumnServiceName(sal_Int32) throw(SQLException, RuntimeException)
171 {
172 	return ::rtl::OUString();
173 }
174 // -------------------------------------------------------------------------
175 sal_Bool SAL_CALL MacabResultSetMetaData::isCurrency(sal_Int32) throw(SQLException, RuntimeException)
176 {
177 	return sal_False;
178 }
179 // -------------------------------------------------------------------------
180 sal_Bool SAL_CALL MacabResultSetMetaData::isAutoIncrement(sal_Int32) throw(SQLException, RuntimeException)
181 {
182 	return sal_False;
183 }
184 // -------------------------------------------------------------------------
185 sal_Bool SAL_CALL MacabResultSetMetaData::isSigned(sal_Int32) throw(SQLException, RuntimeException)
186 {
187 	return sal_False;
188 }
189 // -------------------------------------------------------------------------
190 sal_Int32 SAL_CALL MacabResultSetMetaData::getPrecision(sal_Int32) throw(SQLException, RuntimeException)
191 {
192 	return 0;
193 }
194 // -----------------------------------------------------------------------------
195 sal_Int32 SAL_CALL MacabResultSetMetaData::getScale(sal_Int32) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
196 {
197 	return 0;
198 }
199 // -------------------------------------------------------------------------
200 sal_Int32 SAL_CALL MacabResultSetMetaData::isNullable(sal_Int32) throw(SQLException, RuntimeException)
201 {
202 	return (sal_Int32) sal_True;
203 }
204 // -------------------------------------------------------------------------
205 sal_Bool SAL_CALL MacabResultSetMetaData::isSearchable(sal_Int32) throw(SQLException, RuntimeException)
206 {
207 	return sal_True;
208 }
209 // -------------------------------------------------------------------------
210 sal_Bool SAL_CALL MacabResultSetMetaData::isReadOnly(sal_Int32) throw(SQLException, RuntimeException)
211 {
212 	return sal_True;
213 }
214 // -------------------------------------------------------------------------
215 sal_Bool SAL_CALL MacabResultSetMetaData::isDefinitelyWritable(sal_Int32) throw(SQLException, RuntimeException)
216 {
217 	return sal_False;
218 }
219 // -------------------------------------------------------------------------
220 sal_Bool SAL_CALL MacabResultSetMetaData::isWritable(sal_Int32) throw(SQLException, RuntimeException)
221 {
222 	return sal_False;
223 }
224 // -------------------------------------------------------------------------
225