bump product version to 6.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / ado / adoimp.cxx
blob1e368d8ddec946662bfcb896544f54d16d530939
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <com/sun/star/sdbcx/Privilege.hpp>
21 #include <com/sun/star/sdbcx/PrivilegeObject.hpp>
22 #include <connectivity/dbexception.hxx>
23 #include <ado/Awrapado.hxx>
24 #include <ado/adoimp.hxx>
25 #include <osl/diagnose.h>
26 #include <com/sun/star/sdbc/DataType.hpp>
29 using namespace connectivity::ado;
30 using namespace com::sun::star::uno;
31 using namespace com::sun::star::sdbc;
32 using namespace com::sun::star::sdbcx;
35 #define MYADOID(l) {l, 0,0x10,{0x80,0,0,0xAA,0,0x6D,0x2E,0xA4}};
37 const CLSID ADOS::CLSID_ADOCONNECTION_21 = MYADOID(0x00000514);
38 const IID ADOS::IID_ADOCONNECTION_21 = MYADOID(0x00000550);
40 const CLSID ADOS::CLSID_ADOCOMMAND_21 = MYADOID(0x00000507);
41 const IID ADOS::IID_ADOCOMMAND_21 = MYADOID(0x0000054E);
43 const CLSID ADOS::CLSID_ADORECORDSET_21 = MYADOID(0x00000535);
44 const IID ADOS::IID_ADORECORDSET_21 = MYADOID(0x0000054F);
46 const CLSID ADOS::CLSID_ADOCATALOG_25 = MYADOID(0x00000602);
47 const IID ADOS::IID_ADOCATALOG_25 = MYADOID(0x00000603);
49 const CLSID ADOS::CLSID_ADOINDEX_25 = MYADOID(0x0000061E);
50 const IID ADOS::IID_ADOINDEX_25 = MYADOID(0x0000061F);
52 const CLSID ADOS::CLSID_ADOTABLE_25 = MYADOID(0x00000609);
53 const IID ADOS::IID_ADOTABLE_25 = MYADOID(0x00000610);
55 const CLSID ADOS::CLSID_ADOKEY_25 = MYADOID(0x00000621);
56 const IID ADOS::IID_ADOKEY_25 = MYADOID(0x00000622);
58 const CLSID ADOS::CLSID_ADOCOLUMN_25 = MYADOID(0x0000061B);
59 const IID ADOS::IID_ADOCOLUMN_25 = MYADOID(0x0000061C);
61 const CLSID ADOS::CLSID_ADOGROUP_25 = MYADOID(0x00000615);
62 const IID ADOS::IID_ADOGROUP_25 = MYADOID(0x00000616);
64 const CLSID ADOS::CLSID_ADOUSER_25 = MYADOID(0x00000618);
65 const IID ADOS::IID_ADOUSER_25 = MYADOID(0x00000619);
67 const CLSID ADOS::CLSID_ADOVIEW_25 = MYADOID(0x00000612);
68 const IID ADOS::IID_ADOVIEW_25 = MYADOID(0x00000613);
70 OLEString& ADOS::GetKeyStr()
72 static OLEString sKeyStr(OUString("gxwaezucfyqpwjgqbcmtsncuhwsnyhiohwxz"));
73 return sKeyStr;
77 sal_Int32 ADOS::MapADOType2Jdbc(DataTypeEnum eType)
79 sal_Int32 nType = DataType::VARCHAR;
80 switch (eType)
82 case adUnsignedSmallInt:
83 case adSmallInt: nType = DataType::SMALLINT; break;
84 case adUnsignedInt:
85 case adInteger: nType = DataType::INTEGER; break;
86 case adUnsignedBigInt:
87 case adBigInt: nType = DataType::BIGINT; break;
88 case adSingle: nType = DataType::FLOAT; break;
89 case adDouble: nType = DataType::DOUBLE; break;
90 case adCurrency: nType = DataType::DOUBLE; break;
91 case adVarNumeric:
92 case adNumeric: nType = DataType::NUMERIC; break;
93 case adDecimal: nType = DataType::DECIMAL; break;
94 case adDBDate: nType = DataType::DATE; break;
95 case adDBTime: nType = DataType::TIME; break;
96 case adDate:
97 case adDBTimeStamp: nType = DataType::TIMESTAMP; break;
98 case adBoolean: nType = DataType::BOOLEAN; break;
99 // case adArray: nType = DataType::ARRAY; break;
100 case adBinary: nType = DataType::BINARY; break;
101 case adGUID: nType = DataType::OBJECT; break;
102 case adBSTR:
103 case adVarWChar:
104 case adWChar:
105 case adVarChar: nType = DataType::VARCHAR; break;
106 case adLongVarWChar:
107 case adLongVarChar: nType = DataType::LONGVARCHAR; break;
108 case adVarBinary: nType = DataType::VARBINARY; break;
109 case adLongVarBinary: nType = DataType::LONGVARBINARY;break;
110 case adChar: nType = DataType::CHAR; break;
111 case adUnsignedTinyInt:
112 case adTinyInt: nType = DataType::TINYINT; break;
113 case adEmpty: nType = DataType::SQLNULL; break;
114 case adUserDefined:
115 case adPropVariant:
116 case adFileTime:
117 case adChapter:
118 case adIDispatch:
119 case adIUnknown:
120 case adError:
121 case adVariant:
122 nType = DataType::OTHER; break;
123 default:
124 OSL_FAIL("MapADOType2Jdbc: Unknown Type!");
127 return nType;
130 DataTypeEnum ADOS::MapJdbc2ADOType(sal_Int32 _nType,sal_Int32 _nJetEngine)
132 switch (_nType)
134 case DataType::SMALLINT: return adSmallInt; break;
135 case DataType::INTEGER: return adInteger; break;
136 case DataType::BIGINT: return adBigInt; break;
137 case DataType::FLOAT: return adSingle; break;
138 case DataType::DOUBLE: return adDouble; break;
139 case DataType::NUMERIC: return adNumeric; break;
140 case DataType::DECIMAL: return adDecimal; break;
141 case DataType::DATE: return isJetEngine(_nJetEngine) ? adDate : adDBDate; break;
142 case DataType::TIME: return adDBTime; break;
143 case DataType::TIMESTAMP: return isJetEngine(_nJetEngine) ? adDate : adDBTimeStamp; break;
144 case DataType::BOOLEAN:
145 case DataType::BIT: return adBoolean; break;
146 case DataType::BINARY: return adBinary; break;
147 case DataType::VARCHAR: return adVarWChar; break;
148 case DataType::CLOB:
149 case DataType::LONGVARCHAR: return adLongVarWChar; break;
150 case DataType::VARBINARY: return adVarBinary; break;
151 case DataType::BLOB:
152 case DataType::LONGVARBINARY: return adLongVarBinary; break;
153 case DataType::CHAR: return adWChar; break;
154 case DataType::TINYINT: return isJetEngine(_nJetEngine) ? adUnsignedTinyInt : adTinyInt;break;
155 case DataType::OBJECT: return adGUID; break;
156 default:
157 OSL_FAIL("MapJdbc2ADOType: Unknown Type!");
160 return adEmpty;
163 const int JET_ENGINETYPE_UNKNOWN = 0;
164 const int JET_ENGINETYPE_JET10 = 1;
165 const int JET_ENGINETYPE_JET11 = 2;
166 const int JET_ENGINETYPE_JET20 = 3;
167 const int JET_ENGINETYPE_JET3X = 4;
168 const int JET_ENGINETYPE_JET4X = 5;
169 const int JET_ENGINETYPE_DBASE3 = 10;
170 const int JET_ENGINETYPE_DBASE4 = 11;
171 const int JET_ENGINETYPE_DBASE5 = 12;
172 const int JET_ENGINETYPE_EXCEL30 = 20;
173 const int JET_ENGINETYPE_EXCEL40 = 21;
174 const int JET_ENGINETYPE_EXCEL50 = 22;
175 const int JET_ENGINETYPE_EXCEL80 = 23;
176 const int JET_ENGINETYPE_EXCEL90 = 24;
177 const int JET_ENGINETYPE_EXCHANGE4 = 30;
178 const int JET_ENGINETYPE_LOTUSWK1 = 40;
179 const int JET_ENGINETYPE_LOTUSWK3 = 41;
180 const int JET_ENGINETYPE_LOTUSWK4 = 42;
181 const int JET_ENGINETYPE_PARADOX3X = 50;
182 const int JET_ENGINETYPE_PARADOX4X = 51;
183 const int JET_ENGINETYPE_PARADOX5X = 52;
184 const int JET_ENGINETYPE_PARADOX7X = 53;
185 const int JET_ENGINETYPE_TEXT1X = 60;
186 const int JET_ENGINETYPE_HTML1X = 70;
188 bool ADOS::isJetEngine(sal_Int32 _nEngineType)
190 bool bRet = false;
191 switch(_nEngineType)
193 case JET_ENGINETYPE_UNKNOWN:
194 case JET_ENGINETYPE_JET10:
195 case JET_ENGINETYPE_JET11:
196 case JET_ENGINETYPE_JET20:
197 case JET_ENGINETYPE_JET3X:
198 case JET_ENGINETYPE_JET4X:
199 case JET_ENGINETYPE_DBASE3:
200 case JET_ENGINETYPE_DBASE4:
201 case JET_ENGINETYPE_DBASE5:
202 case JET_ENGINETYPE_EXCEL30:
203 case JET_ENGINETYPE_EXCEL40:
204 case JET_ENGINETYPE_EXCEL50:
205 case JET_ENGINETYPE_EXCEL80:
206 case JET_ENGINETYPE_EXCEL90:
207 case JET_ENGINETYPE_EXCHANGE4:
208 case JET_ENGINETYPE_LOTUSWK1:
209 case JET_ENGINETYPE_LOTUSWK3:
210 case JET_ENGINETYPE_LOTUSWK4:
211 case JET_ENGINETYPE_PARADOX3X:
212 case JET_ENGINETYPE_PARADOX4X:
213 case JET_ENGINETYPE_PARADOX5X:
214 case JET_ENGINETYPE_PARADOX7X:
215 case JET_ENGINETYPE_TEXT1X:
216 case JET_ENGINETYPE_HTML1X:
217 bRet = true;
218 break;
220 return bRet;
223 ObjectTypeEnum ADOS::mapObjectType2Ado(sal_Int32 objType)
225 ObjectTypeEnum eType = adPermObjTable;
226 switch(objType)
228 case PrivilegeObject::TABLE:
229 eType = adPermObjTable;
230 break;
231 case PrivilegeObject::VIEW:
232 eType = adPermObjView;
233 break;
234 case PrivilegeObject::COLUMN:
235 eType = adPermObjColumn;
236 break;
238 return eType;
241 sal_Int32 ADOS::mapAdoType2Object(ObjectTypeEnum objType)
243 sal_Int32 nType = PrivilegeObject::TABLE;
244 switch(objType)
246 case adPermObjTable:
247 nType = PrivilegeObject::TABLE;
248 break;
249 case adPermObjView:
250 nType = PrivilegeObject::VIEW;
251 break;
252 case adPermObjColumn:
253 nType = PrivilegeObject::COLUMN;
254 break;
255 default:
256 OSL_FAIL( "ADOS::mapAdoType2Object: privilege type cannot be translated!" );
257 break;
259 return nType;
261 #ifdef DELETE
262 #undef DELETE
263 #endif
265 sal_Int32 ADOS::mapAdoRights2Sdbc(RightsEnum eRights)
267 sal_Int32 nRights = 0;
268 if((eRights & adRightInsert) == adRightInsert)
269 nRights |= Privilege::INSERT;
270 if((eRights & adRightDelete) == adRightDelete)
271 nRights |= css::sdbcx::Privilege::DELETE;
272 if((eRights & adRightUpdate) == adRightUpdate)
273 nRights |= Privilege::UPDATE;
274 if((eRights & adRightWriteDesign) == adRightWriteDesign)
275 nRights |= Privilege::ALTER;
276 if((eRights & adRightRead) == adRightRead)
277 nRights |= Privilege::SELECT;
278 if((eRights & adRightReference) == adRightReference)
279 nRights |= Privilege::REFERENCE;
280 if((eRights & adRightDrop) == adRightDrop)
281 nRights |= Privilege::DROP;
283 return nRights;
286 sal_Int32 ADOS::mapRights2Ado(sal_Int32 nRights)
288 sal_Int32 eRights = adRightNone;
290 if((nRights & Privilege::INSERT) == Privilege::INSERT)
291 eRights |= adRightInsert;
292 if((nRights & Privilege::DELETE) == Privilege::DELETE)
293 eRights |= adRightDelete;
294 if((nRights & Privilege::UPDATE) == Privilege::UPDATE)
295 eRights |= adRightUpdate;
296 if((nRights & Privilege::ALTER) == Privilege::ALTER)
297 eRights |= adRightWriteDesign;
298 if((nRights & Privilege::SELECT) == Privilege::SELECT)
299 eRights |= adRightRead;
300 if((nRights & Privilege::REFERENCE) == Privilege::REFERENCE)
301 eRights |= adRightReference;
302 if((nRights & Privilege::DROP) == Privilege::DROP)
303 eRights |= adRightDrop;
305 return eRights;
308 WpADOField ADOS::getField(ADORecordset* _pRecordSet,sal_Int32 _nColumnIndex)
310 if ( !_pRecordSet )
311 return WpADOField();
313 ADOFields* pFields = nullptr;
314 _pRecordSet->get_Fields(&pFields);
315 WpOLEAppendCollection<ADOFields, ADOField, WpADOField> aFields(pFields);
316 if(_nColumnIndex <= 0 || _nColumnIndex > aFields.GetItemCount())
317 ::dbtools::throwInvalidIndexException(nullptr);
318 WpADOField aField(aFields.GetItem(_nColumnIndex-1));
319 if(!aField.IsValid())
320 ::dbtools::throwInvalidIndexException(nullptr);
321 return aField;
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */