Bump for 3.6-28
[LibreOffice.git] / connectivity / source / drivers / ado / adoimp.cxx
blob3c05419a85eab488bc83050b3919efc05fe7a0cc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <com/sun/star/sdbcx/Privilege.hpp>
30 #include <com/sun/star/sdbcx/PrivilegeObject.hpp>
31 #include "connectivity/dbexception.hxx"
32 #include "ado/Awrapado.hxx"
33 #include "ado/adoimp.hxx"
34 #include <osl/diagnose.h>
35 #include <com/sun/star/sdbc/DataType.hpp>
38 using namespace connectivity::ado;
39 using namespace com::sun::star::uno;
40 using namespace com::sun::star::sdbc;
41 using namespace com::sun::star::sdbcx;
44 #define MYADOID(l) {l, 0,0x10,{0x80,0,0,0xAA,0,0x6D,0x2E,0xA4}};
46 const CLSID ADOS::CLSID_ADOCONNECTION_21 = MYADOID(0x00000514);
47 const IID ADOS::IID_ADOCONNECTION_21 = MYADOID(0x00000550);
49 const CLSID ADOS::CLSID_ADOCOMMAND_21 = MYADOID(0x00000507);
50 const IID ADOS::IID_ADOCOMMAND_21 = MYADOID(0x0000054E);
52 const CLSID ADOS::CLSID_ADORECORDSET_21 = MYADOID(0x00000535);
53 const IID ADOS::IID_ADORECORDSET_21 = MYADOID(0x0000054F);
55 const CLSID ADOS::CLSID_ADOCATALOG_25 = MYADOID(0x00000602);
56 const IID ADOS::IID_ADOCATALOG_25 = MYADOID(0x00000603);
58 const CLSID ADOS::CLSID_ADOINDEX_25 = MYADOID(0x0000061E);
59 const IID ADOS::IID_ADOINDEX_25 = MYADOID(0x0000061F);
61 const CLSID ADOS::CLSID_ADOTABLE_25 = MYADOID(0x00000609);
62 const IID ADOS::IID_ADOTABLE_25 = MYADOID(0x00000610);
64 const CLSID ADOS::CLSID_ADOKEY_25 = MYADOID(0x00000621);
65 const IID ADOS::IID_ADOKEY_25 = MYADOID(0x00000622);
67 const CLSID ADOS::CLSID_ADOCOLUMN_25 = MYADOID(0x0000061B);
68 const IID ADOS::IID_ADOCOLUMN_25 = MYADOID(0x0000061C);
70 const CLSID ADOS::CLSID_ADOGROUP_25 = MYADOID(0x00000615);
71 const IID ADOS::IID_ADOGROUP_25 = MYADOID(0x00000616);
73 const CLSID ADOS::CLSID_ADOUSER_25 = MYADOID(0x00000618);
74 const IID ADOS::IID_ADOUSER_25 = MYADOID(0x00000619);
76 const CLSID ADOS::CLSID_ADOVIEW_25 = MYADOID(0x00000612);
77 const IID ADOS::IID_ADOVIEW_25 = MYADOID(0x00000613);
79 OLEString& ADOS::GetKeyStr()
81 static OLEString sKeyStr(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("gxwaezucfyqpwjgqbcmtsncuhwsnyhiohwxz")));
82 return sKeyStr;
85 // -------------------------------------------------------------------------
86 sal_Int32 ADOS::MapADOType2Jdbc(DataTypeEnum eType)
88 sal_Int32 nType = DataType::VARCHAR;
89 switch (eType)
91 case adUnsignedSmallInt:
92 case adSmallInt: nType = DataType::SMALLINT; break;
93 case adUnsignedInt:
94 case adInteger: nType = DataType::INTEGER; break;
95 case adUnsignedBigInt:
96 case adBigInt: nType = DataType::BIGINT; break;
97 case adSingle: nType = DataType::FLOAT; break;
98 case adDouble: nType = DataType::DOUBLE; break;
99 case adCurrency: nType = DataType::DOUBLE; break;
100 case adVarNumeric:
101 case adNumeric: nType = DataType::NUMERIC; break;
102 case adDecimal: nType = DataType::DECIMAL; break;
103 case adDBDate: nType = DataType::DATE; break;
104 case adDBTime: nType = DataType::TIME; break;
105 case adDate:
106 case adDBTimeStamp: nType = DataType::TIMESTAMP; break;
107 case adBoolean: nType = DataType::BOOLEAN; break;
108 // case adArray: nType = DataType::ARRAY; break;
109 case adBinary: nType = DataType::BINARY; break;
110 case adGUID: nType = DataType::OBJECT; break;
111 case adBSTR:
112 case adVarWChar:
113 case adWChar:
114 case adVarChar: nType = DataType::VARCHAR; break;
115 case adLongVarWChar:
116 case adLongVarChar: nType = DataType::LONGVARCHAR; break;
117 case adVarBinary: nType = DataType::VARBINARY; break;
118 case adLongVarBinary: nType = DataType::LONGVARBINARY;break;
119 case adChar: nType = DataType::CHAR; break;
120 case adUnsignedTinyInt:
121 case adTinyInt: nType = DataType::TINYINT; break;
122 case adEmpty: nType = DataType::SQLNULL; break;
123 case adUserDefined:
124 case adPropVariant:
125 case adFileTime:
126 case adChapter:
127 case adIDispatch:
128 case adIUnknown:
129 case adError:
130 case adVariant:
131 nType = DataType::OTHER; break;
132 default:
133 OSL_FAIL("MapADOType2Jdbc: Unknown Type!");
136 return nType;
138 // -------------------------------------------------------------------------
139 DataTypeEnum ADOS::MapJdbc2ADOType(sal_Int32 _nType,sal_Int32 _nJetEngine)
141 switch (_nType)
143 case DataType::SMALLINT: return adSmallInt; break;
144 case DataType::INTEGER: return adInteger; break;
145 case DataType::BIGINT: return adBigInt; break;
146 case DataType::FLOAT: return adSingle; break;
147 case DataType::DOUBLE: return adDouble; break;
148 case DataType::NUMERIC: return adNumeric; break;
149 case DataType::DECIMAL: return adDecimal; break;
150 case DataType::DATE: return isJetEngine(_nJetEngine) ? adDate : adDBDate; break;
151 case DataType::TIME: return adDBTime; break;
152 case DataType::TIMESTAMP: return isJetEngine(_nJetEngine) ? adDate : adDBTimeStamp; break;
153 case DataType::BOOLEAN:
154 case DataType::BIT: return adBoolean; break;
155 case DataType::BINARY: return adBinary; break;
156 case DataType::VARCHAR: return adVarWChar; break;
157 case DataType::CLOB:
158 case DataType::LONGVARCHAR: return adLongVarWChar; break;
159 case DataType::VARBINARY: return adVarBinary; break;
160 case DataType::BLOB:
161 case DataType::LONGVARBINARY: return adLongVarBinary; break;
162 case DataType::CHAR: return adWChar; break;
163 case DataType::TINYINT: return isJetEngine(_nJetEngine) ? adUnsignedTinyInt : adTinyInt;break;
164 case DataType::OBJECT: return adGUID; break;
165 default:
166 OSL_FAIL("MapJdbc2ADOType: Unknown Type!");
169 return adEmpty;
171 // -----------------------------------------------------------------------------
172 const int JET_ENGINETYPE_UNKNOWN = 0;
173 const int JET_ENGINETYPE_JET10 = 1;
174 const int JET_ENGINETYPE_JET11 = 2;
175 const int JET_ENGINETYPE_JET20 = 3;
176 const int JET_ENGINETYPE_JET3X = 4;
177 const int JET_ENGINETYPE_JET4X = 5;
178 const int JET_ENGINETYPE_DBASE3 = 10;
179 const int JET_ENGINETYPE_DBASE4 = 11;
180 const int JET_ENGINETYPE_DBASE5 = 12;
181 const int JET_ENGINETYPE_EXCEL30 = 20;
182 const int JET_ENGINETYPE_EXCEL40 = 21;
183 const int JET_ENGINETYPE_EXCEL50 = 22;
184 const int JET_ENGINETYPE_EXCEL80 = 23;
185 const int JET_ENGINETYPE_EXCEL90 = 24;
186 const int JET_ENGINETYPE_EXCHANGE4 = 30;
187 const int JET_ENGINETYPE_LOTUSWK1 = 40;
188 const int JET_ENGINETYPE_LOTUSWK3 = 41;
189 const int JET_ENGINETYPE_LOTUSWK4 = 42;
190 const int JET_ENGINETYPE_PARADOX3X = 50;
191 const int JET_ENGINETYPE_PARADOX4X = 51;
192 const int JET_ENGINETYPE_PARADOX5X = 52;
193 const int JET_ENGINETYPE_PARADOX7X = 53;
194 const int JET_ENGINETYPE_TEXT1X = 60;
195 const int JET_ENGINETYPE_HTML1X = 70;
197 sal_Bool ADOS::isJetEngine(sal_Int32 _nEngineType)
199 sal_Bool bRet = sal_False;
200 switch(_nEngineType)
202 case JET_ENGINETYPE_UNKNOWN:
203 case JET_ENGINETYPE_JET10:
204 case JET_ENGINETYPE_JET11:
205 case JET_ENGINETYPE_JET20:
206 case JET_ENGINETYPE_JET3X:
207 case JET_ENGINETYPE_JET4X:
208 case JET_ENGINETYPE_DBASE3:
209 case JET_ENGINETYPE_DBASE4:
210 case JET_ENGINETYPE_DBASE5:
211 case JET_ENGINETYPE_EXCEL30:
212 case JET_ENGINETYPE_EXCEL40:
213 case JET_ENGINETYPE_EXCEL50:
214 case JET_ENGINETYPE_EXCEL80:
215 case JET_ENGINETYPE_EXCEL90:
216 case JET_ENGINETYPE_EXCHANGE4:
217 case JET_ENGINETYPE_LOTUSWK1:
218 case JET_ENGINETYPE_LOTUSWK3:
219 case JET_ENGINETYPE_LOTUSWK4:
220 case JET_ENGINETYPE_PARADOX3X:
221 case JET_ENGINETYPE_PARADOX4X:
222 case JET_ENGINETYPE_PARADOX5X:
223 case JET_ENGINETYPE_PARADOX7X:
224 case JET_ENGINETYPE_TEXT1X:
225 case JET_ENGINETYPE_HTML1X:
226 bRet = sal_True;
227 break;
229 return bRet;
231 // -----------------------------------------------------------------------------
232 ObjectTypeEnum ADOS::mapObjectType2Ado(sal_Int32 objType)
234 ObjectTypeEnum eType = adPermObjTable;
235 switch(objType)
237 case PrivilegeObject::TABLE:
238 eType = adPermObjTable;
239 break;
240 case PrivilegeObject::VIEW:
241 eType = adPermObjView;
242 break;
243 case PrivilegeObject::COLUMN:
244 eType = adPermObjColumn;
245 break;
247 return eType;
249 // -----------------------------------------------------------------------------
250 sal_Int32 ADOS::mapAdoType2Object(ObjectTypeEnum objType)
252 sal_Int32 nType = PrivilegeObject::TABLE;
253 switch(objType)
255 case adPermObjTable:
256 nType = PrivilegeObject::TABLE;
257 break;
258 case adPermObjView:
259 nType = PrivilegeObject::VIEW;
260 break;
261 case adPermObjColumn:
262 nType = PrivilegeObject::COLUMN;
263 break;
264 default:
265 OSL_FAIL( "ADOS::mapAdoType2Object: privilege type cannot be translated!" );
266 break;
268 return nType;
270 #ifdef DELETE
271 #undef DELETE
272 #endif
273 // -----------------------------------------------------------------------------
274 sal_Int32 ADOS::mapAdoRights2Sdbc(RightsEnum eRights)
276 sal_Int32 nRights = 0;
277 if((eRights & adRightInsert) == adRightInsert)
278 nRights |= Privilege::INSERT;
279 if((eRights & adRightDelete) == adRightDelete)
280 nRights |= ::com::sun::star::sdbcx::Privilege::DELETE;
281 if((eRights & adRightUpdate) == adRightUpdate)
282 nRights |= Privilege::UPDATE;
283 if((eRights & adRightWriteDesign) == adRightWriteDesign)
284 nRights |= Privilege::ALTER;
285 if((eRights & adRightRead) == adRightRead)
286 nRights |= Privilege::SELECT;
287 if((eRights & adRightReference) == adRightReference)
288 nRights |= Privilege::REFERENCE;
289 if((eRights & adRightDrop) == adRightDrop)
290 nRights |= Privilege::DROP;
292 return nRights;
294 // -----------------------------------------------------------------------------
295 sal_Int32 ADOS::mapRights2Ado(sal_Int32 nRights)
297 sal_Int32 eRights = adRightNone;
299 if((nRights & Privilege::INSERT) == Privilege::INSERT)
300 eRights |= adRightInsert;
301 if((nRights & Privilege::DELETE) == Privilege::DELETE)
302 eRights |= adRightDelete;
303 if((nRights & Privilege::UPDATE) == Privilege::UPDATE)
304 eRights |= adRightUpdate;
305 if((nRights & Privilege::ALTER) == Privilege::ALTER)
306 eRights |= adRightWriteDesign;
307 if((nRights & Privilege::SELECT) == Privilege::SELECT)
308 eRights |= adRightRead;
309 if((nRights & Privilege::REFERENCE) == Privilege::REFERENCE)
310 eRights |= adRightReference;
311 if((nRights & Privilege::DROP) == Privilege::DROP)
312 eRights |= adRightDrop;
314 return eRights;
316 // -----------------------------------------------------------------------------
317 WpADOField ADOS::getField(ADORecordset* _pRecordSet,sal_Int32 _nColumnIndex) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
319 if ( !_pRecordSet )
320 return WpADOField();
322 ADOFields* pFields = NULL;
323 _pRecordSet->get_Fields(&pFields);
324 WpOLEAppendCollection<ADOFields, ADOField, WpADOField> aFields(pFields);
325 if(_nColumnIndex <= 0 || _nColumnIndex > aFields.GetItemCount())
326 ::dbtools::throwInvalidIndexException(NULL);
327 WpADOField aField(aFields.GetItem(_nColumnIndex-1));
328 if(!aField.IsValid())
329 ::dbtools::throwInvalidIndexException(NULL);
330 return aField;
332 // -----------------------------------------------------------------------------
337 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */