1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: adoimp.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include <com/sun/star/sdbcx/Privilege.hpp>
34 #include <com/sun/star/sdbcx/PrivilegeObject.hpp>
35 #include "connectivity/dbexception.hxx"
36 #include "ado/Awrapado.hxx"
37 #include "ado/adoimp.hxx"
38 #include <osl/diagnose.h>
39 #include <com/sun/star/sdbc/DataType.hpp>
42 using namespace connectivity::ado
;
43 using namespace com::sun::star::uno
;
44 using namespace com::sun::star::sdbc
;
45 using namespace com::sun::star::sdbcx
;
48 #define MYADOID(l) {l, 0,0x10,0x80,0,0,0xAA,0,0x6D,0x2E,0xA4};
50 const CLSID
ADOS::CLSID_ADOCONNECTION_21
= MYADOID(0x00000514);
51 const IID
ADOS::IID_ADOCONNECTION_21
= MYADOID(0x00000550);
53 const CLSID
ADOS::CLSID_ADOCOMMAND_21
= MYADOID(0x00000507);
54 const IID
ADOS::IID_ADOCOMMAND_21
= MYADOID(0x0000054E);
56 const CLSID
ADOS::CLSID_ADORECORDSET_21
= MYADOID(0x00000535);
57 const IID
ADOS::IID_ADORECORDSET_21
= MYADOID(0x0000054F);
59 const CLSID
ADOS::CLSID_ADOCATALOG_25
= MYADOID(0x00000602);
60 const IID
ADOS::IID_ADOCATALOG_25
= MYADOID(0x00000603);
62 const CLSID
ADOS::CLSID_ADOINDEX_25
= MYADOID(0x0000061E);
63 const IID
ADOS::IID_ADOINDEX_25
= MYADOID(0x0000061F);
65 const CLSID
ADOS::CLSID_ADOTABLE_25
= MYADOID(0x00000609);
66 const IID
ADOS::IID_ADOTABLE_25
= MYADOID(0x00000610);
68 const CLSID
ADOS::CLSID_ADOKEY_25
= MYADOID(0x00000621);
69 const IID
ADOS::IID_ADOKEY_25
= MYADOID(0x00000622);
71 const CLSID
ADOS::CLSID_ADOCOLUMN_25
= MYADOID(0x0000061B);
72 const IID
ADOS::IID_ADOCOLUMN_25
= MYADOID(0x0000061C);
74 const CLSID
ADOS::CLSID_ADOGROUP_25
= MYADOID(0x00000615);
75 const IID
ADOS::IID_ADOGROUP_25
= MYADOID(0x00000616);
77 const CLSID
ADOS::CLSID_ADOUSER_25
= MYADOID(0x00000618);
78 const IID
ADOS::IID_ADOUSER_25
= MYADOID(0x00000619);
80 const CLSID
ADOS::CLSID_ADOVIEW_25
= MYADOID(0x00000612);
81 const IID
ADOS::IID_ADOVIEW_25
= MYADOID(0x00000613);
83 OLEString
& ADOS::GetKeyStr()
85 static OLEString
sKeyStr(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("gxwaezucfyqpwjgqbcmtsncuhwsnyhiohwxz")));
89 // -------------------------------------------------------------------------
90 sal_Int32
ADOS::MapADOType2Jdbc(DataTypeEnum eType
)
92 sal_Int32 nType
= DataType::VARCHAR
;;
95 case adUnsignedSmallInt
:
96 case adSmallInt
: nType
= DataType::SMALLINT
; break;
98 case adInteger
: nType
= DataType::INTEGER
; break;
99 case adUnsignedBigInt
:
100 case adBigInt
: nType
= DataType::BIGINT
; break;
101 case adSingle
: nType
= DataType::FLOAT
; break;
102 case adDouble
: nType
= DataType::DOUBLE
; break;
103 case adCurrency
: nType
= DataType::DOUBLE
; break;
105 case adNumeric
: nType
= DataType::NUMERIC
; break;
106 case adDecimal
: nType
= DataType::DECIMAL
; break;
107 case adDBDate
: nType
= DataType::DATE
; break;
108 case adDBTime
: nType
= DataType::TIME
; break;
110 case adDBTimeStamp
: nType
= DataType::TIMESTAMP
; break;
111 case adBoolean
: nType
= DataType::BIT
; break;
112 // case adArray: nType = DataType::ARRAY; break;
113 case adBinary
: nType
= DataType::BINARY
; break;
114 case adGUID
: nType
= DataType::OBJECT
; break;
118 case adVarChar
: nType
= DataType::VARCHAR
; break;
120 case adLongVarChar
: nType
= DataType::LONGVARCHAR
; break;
121 case adVarBinary
: nType
= DataType::VARBINARY
; break;
122 case adLongVarBinary
: nType
= DataType::LONGVARBINARY
;break;
123 case adChar
: nType
= DataType::CHAR
; break;
124 case adUnsignedTinyInt
:
125 case adTinyInt
: nType
= DataType::TINYINT
; break;
126 case adEmpty
: nType
= DataType::SQLNULL
; break;
135 nType
= DataType::OTHER
; break;
137 OSL_ENSURE(0,"MapADOType2Jdbc: Unknown Type!");
142 // -------------------------------------------------------------------------
143 DataTypeEnum
ADOS::MapJdbc2ADOType(sal_Int32 _nType
,sal_Int32 _nJetEngine
)
147 case DataType::SMALLINT
: return adSmallInt
; break;
148 case DataType::INTEGER
: return adInteger
; break;
149 case DataType::BIGINT
: return adBigInt
; break;
150 case DataType::FLOAT
: return adSingle
; break;
151 case DataType::DOUBLE
: return adDouble
; break;
152 case DataType::NUMERIC
: return adNumeric
; break;
153 case DataType::DECIMAL
: return adDecimal
; break;
154 case DataType::DATE
: return isJetEngine(_nJetEngine
) ? adDate
: adDBDate
; break;
155 case DataType::TIME
: return adDBTime
; break;
156 case DataType::TIMESTAMP
: return isJetEngine(_nJetEngine
) ? adDate
: adDBTimeStamp
; break;
157 case DataType::BIT
: return adBoolean
; break;
158 case DataType::BINARY
: return adBinary
; break;
159 case DataType::VARCHAR
: return adVarWChar
; break;
160 case DataType::LONGVARCHAR
: return adLongVarWChar
; break;
161 case DataType::VARBINARY
: return adVarBinary
; break;
162 case DataType::LONGVARBINARY
: return adLongVarBinary
; break;
163 case DataType::CHAR
: return adWChar
; break;
164 case DataType::TINYINT
: return isJetEngine(_nJetEngine
) ? adUnsignedTinyInt
: adTinyInt
;break;
165 case DataType::OBJECT
: return adGUID
; break;
167 OSL_ENSURE(0,"MapJdbc2ADOType: Unknown Type!");
172 // -----------------------------------------------------------------------------
173 const int JET_ENGINETYPE_UNKNOWN
= 0;
174 const int JET_ENGINETYPE_JET10
= 1;
175 const int JET_ENGINETYPE_JET11
= 2;
176 const int JET_ENGINETYPE_JET20
= 3;
177 const int JET_ENGINETYPE_JET3X
= 4;
178 const int JET_ENGINETYPE_JET4X
= 5;
179 const int JET_ENGINETYPE_DBASE3
= 10;
180 const int JET_ENGINETYPE_DBASE4
= 11;
181 const int JET_ENGINETYPE_DBASE5
= 12;
182 const int JET_ENGINETYPE_EXCEL30
= 20;
183 const int JET_ENGINETYPE_EXCEL40
= 21;
184 const int JET_ENGINETYPE_EXCEL50
= 22;
185 const int JET_ENGINETYPE_EXCEL80
= 23;
186 const int JET_ENGINETYPE_EXCEL90
= 24;
187 const int JET_ENGINETYPE_EXCHANGE4
= 30;
188 const int JET_ENGINETYPE_LOTUSWK1
= 40;
189 const int JET_ENGINETYPE_LOTUSWK3
= 41;
190 const int JET_ENGINETYPE_LOTUSWK4
= 42;
191 const int JET_ENGINETYPE_PARADOX3X
= 50;
192 const int JET_ENGINETYPE_PARADOX4X
= 51;
193 const int JET_ENGINETYPE_PARADOX5X
= 52;
194 const int JET_ENGINETYPE_PARADOX7X
= 53;
195 const int JET_ENGINETYPE_TEXT1X
= 60;
196 const int JET_ENGINETYPE_HTML1X
= 70;
198 sal_Bool
ADOS::isJetEngine(sal_Int32 _nEngineType
)
200 sal_Bool bRet
= sal_False
;
203 case JET_ENGINETYPE_UNKNOWN
:
204 case JET_ENGINETYPE_JET10
:
205 case JET_ENGINETYPE_JET11
:
206 case JET_ENGINETYPE_JET20
:
207 case JET_ENGINETYPE_JET3X
:
208 case JET_ENGINETYPE_JET4X
:
209 case JET_ENGINETYPE_DBASE3
:
210 case JET_ENGINETYPE_DBASE4
:
211 case JET_ENGINETYPE_DBASE5
:
212 case JET_ENGINETYPE_EXCEL30
:
213 case JET_ENGINETYPE_EXCEL40
:
214 case JET_ENGINETYPE_EXCEL50
:
215 case JET_ENGINETYPE_EXCEL80
:
216 case JET_ENGINETYPE_EXCEL90
:
217 case JET_ENGINETYPE_EXCHANGE4
:
218 case JET_ENGINETYPE_LOTUSWK1
:
219 case JET_ENGINETYPE_LOTUSWK3
:
220 case JET_ENGINETYPE_LOTUSWK4
:
221 case JET_ENGINETYPE_PARADOX3X
:
222 case JET_ENGINETYPE_PARADOX4X
:
223 case JET_ENGINETYPE_PARADOX5X
:
224 case JET_ENGINETYPE_PARADOX7X
:
225 case JET_ENGINETYPE_TEXT1X
:
226 case JET_ENGINETYPE_HTML1X
:
232 // -----------------------------------------------------------------------------
233 ObjectTypeEnum
ADOS::mapObjectType2Ado(sal_Int32 objType
)
235 ObjectTypeEnum eType
= adPermObjTable
;
238 case PrivilegeObject::TABLE
:
239 eType
= adPermObjTable
;
241 case PrivilegeObject::VIEW
:
242 eType
= adPermObjView
;
244 case PrivilegeObject::COLUMN
:
245 eType
= adPermObjColumn
;
250 // -----------------------------------------------------------------------------
251 sal_Int32
ADOS::mapAdoType2Object(ObjectTypeEnum objType
)
253 sal_Int32 nType
= PrivilegeObject::TABLE
;
257 nType
= PrivilegeObject::TABLE
;
260 nType
= PrivilegeObject::VIEW
;
262 case adPermObjColumn
:
263 nType
= PrivilegeObject::COLUMN
;
266 OSL_ENSURE( false, "ADOS::mapAdoType2Object: privilege type cannot be translated!" );
274 // -----------------------------------------------------------------------------
275 sal_Int32
ADOS::mapAdoRights2Sdbc(RightsEnum eRights
)
277 sal_Int32 nRights
= 0;
278 if((eRights
& adRightInsert
) == adRightInsert
)
279 nRights
|= Privilege::INSERT
;
280 if((eRights
& adRightDelete
) == adRightDelete
)
281 nRights
|= ::com::sun::star::sdbcx::Privilege::DELETE
;
282 if((eRights
& adRightUpdate
) == adRightUpdate
)
283 nRights
|= Privilege::UPDATE
;
284 if((eRights
& adRightWriteDesign
) == adRightWriteDesign
)
285 nRights
|= Privilege::ALTER
;
286 if((eRights
& adRightRead
) == adRightRead
)
287 nRights
|= Privilege::SELECT
;
288 if((eRights
& adRightReference
) == adRightReference
)
289 nRights
|= Privilege::REFERENCE
;
290 if((eRights
& adRightDrop
) == adRightDrop
)
291 nRights
|= Privilege::DROP
;
295 // -----------------------------------------------------------------------------
296 sal_Int32
ADOS::mapRights2Ado(sal_Int32 nRights
)
298 sal_Int32 eRights
= adRightNone
;
300 if((nRights
& Privilege::INSERT
) == Privilege::INSERT
)
301 eRights
|= adRightInsert
;
302 if((nRights
& Privilege::DELETE
) == Privilege::DELETE
)
303 eRights
|= adRightDelete
;
304 if((nRights
& Privilege::UPDATE
) == Privilege::UPDATE
)
305 eRights
|= adRightUpdate
;
306 if((nRights
& Privilege::ALTER
) == Privilege::ALTER
)
307 eRights
|= adRightWriteDesign
;
308 if((nRights
& Privilege::SELECT
) == Privilege::SELECT
)
309 eRights
|= adRightRead
;
310 if((nRights
& Privilege::REFERENCE
) == Privilege::REFERENCE
)
311 eRights
|= adRightReference
;
312 if((nRights
& Privilege::DROP
) == Privilege::DROP
)
313 eRights
|= adRightDrop
;
317 // -----------------------------------------------------------------------------
318 WpADOField
ADOS::getField(ADORecordset
* _pRecordSet
,sal_Int32 _nColumnIndex
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
323 ADOFields
* pFields
= NULL
;
324 _pRecordSet
->get_Fields(&pFields
);
325 WpOLEAppendCollection
<ADOFields
, ADOField
, WpADOField
> aFields(pFields
);
326 if(_nColumnIndex
<= 0 || _nColumnIndex
> aFields
.GetItemCount())
327 ::dbtools::throwInvalidIndexException(NULL
);
328 WpADOField
aField(aFields
.GetItem(_nColumnIndex
-1));
329 if(!aField
.IsValid())
330 ::dbtools::throwInvalidIndexException(NULL
);
333 // -----------------------------------------------------------------------------