xref: /trunk/main/connectivity/source/inc/ado/Awrapado.hxx (revision 9c15e1abd703a7953928d7a80655ae1a76a41f6d)
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 #ifndef _CONNECTIVITY_ADO_AWRAPADO_HXX_
24 #define _CONNECTIVITY_ADO_AWRAPADO_HXX_
25 
26 #include <com/sun/star/beans/PropertyAttribute.hpp>
27 
28 // Includes fuer ADO
29 #include "ado_pre_sys_include.h"
30 #include <oledb.h>
31 #include <ocidl.h>
32 // A modern Windows SDK ships the ADO interfaces twice: adoint.h, which has
33 // dropped the <Enum>_Param typedefs, and adoint_Backcompat.h, which keeps
34 // them.  This driver uses PositionEnum_Param, so it needs the latter:
35 //
36 //     AResultSet.cxx(277): error C2065: 'PositionEnum_Param': undeclared
37 //
38 // INSTEAD OF and not in addition to.  Both files open with
39 //
40 //     #ifndef _ADOINT_H_
41 //
42 // so whichever is included second is skipped entirely -- adding the
43 // back-compat header after adoint.h looks right and does exactly nothing.
44 // The two declare the same interfaces (ADOConnection, ADORecordset, ...);
45 // only the typedefs differ.
46 //
47 // Gated on the compiler generation rather than __has_include, which is C++17
48 // and this build is /std:c++14.  On this branch a UCRT-era compiler always
49 // pairs with the Windows 10 SDK, and VC9 always with an SDK whose adoint.h
50 // still carries the typedefs itself.
51 #if defined(_MSC_VER) && _MSC_VER >= 1900
52 #include <adoint_Backcompat.h>
53 #else
54 #include <adoint.h>
55 #endif
56 #include "ado_post_sys_include.h"
57 
58 
59 #include "ado/adoimp.hxx"
60 #include "ado/Aolewrap.hxx"
61 #include "ado/Aolevariant.hxx"
62 
63 namespace connectivity
64 {
65     namespace ado
66     {
67         class WpADOConnection;
68         class WpADOCommand;
69         class WpADORecordset;
70         class WpADOField;
71         class WpADOParameter;
72         class WpADOError;
73         class WpADOProperty;
74 
75         typedef WpOLEAppendCollection<  ADOFields,      ADOField,       WpADOField>         WpADOFields;
76         typedef WpOLECollection<        ADOProperties,  ADOProperty,    WpADOProperty>      WpADOProperties;
77 
78         //------------------------------------------------------------------------
79         class WpADOConnection : public WpOLEBase<ADOConnection>
80         {
81             friend class WpADOCommand;
82         public:
83 
84             WpADOConnection(ADOConnection* pInt)    :   WpOLEBase<ADOConnection>(pInt){}
85 
86             WpADOConnection(const WpADOConnection& rhs){operator=(rhs);}
87 
88              WpADOConnection& operator=(const WpADOConnection& rhs)
89                 {WpOLEBase<ADOConnection>::operator=(rhs); return *this;}
90 
91             //////////////////////////////////////////////////////////////////////
92 
93             WpADOProperties get_Properties() const;
94 
95              rtl::OUString GetConnectionString() const;
96 
97              sal_Bool PutConnectionString(const ::rtl::OUString &aCon) const;
98 
99              sal_Int32 GetCommandTimeout() const;
100 
101              void PutCommandTimeout(sal_Int32 nRet);
102 
103              sal_Int32 GetConnectionTimeout() const ;
104 
105              void PutConnectionTimeout(sal_Int32 nRet);
106 
107              sal_Bool Close( ) ;
108 
109              sal_Bool Execute(const ::rtl::OUString& _CommandText,OLEVariant& RecordsAffected,long Options, WpADORecordset** ppiRset);
110 
111              sal_Bool BeginTrans();
112 
113              sal_Bool CommitTrans( ) ;
114 
115              sal_Bool RollbackTrans( );
116 
117              sal_Bool Open(const ::rtl::OUString& ConnectionString, const ::rtl::OUString& UserID,const ::rtl::OUString& Password,long Options);
118 
119              sal_Bool GetErrors(ADOErrors** pErrors);
120 
121              ::rtl::OUString GetDefaultDatabase() const;
122 
123              sal_Bool PutDefaultDatabase(const ::rtl::OUString& _bstr);
124 
125              IsolationLevelEnum get_IsolationLevel() const ;
126 
127              sal_Bool put_IsolationLevel(const IsolationLevelEnum& eNum) ;
128 
129              sal_Int32 get_Attributes() const;
130 
131              sal_Bool put_Attributes(sal_Int32 nRet);
132 
133              CursorLocationEnum get_CursorLocation() const;
134 
135              sal_Bool put_CursorLocation(const CursorLocationEnum &eNum) ;
136 
137              ConnectModeEnum get_Mode() const;
138 
139              sal_Bool put_Mode(const ConnectModeEnum &eNum) ;
140 
141              ::rtl::OUString get_Provider() const;
142 
143              sal_Bool put_Provider(const ::rtl::OUString& _bstr);
144 
145              sal_Int32 get_State() const;
146 
147              sal_Bool OpenSchema(SchemaEnum eNum,OLEVariant& Restrictions,OLEVariant& SchemaID,ADORecordset**pprset);
148 
149              ::rtl::OUString get_Version() const;
150 
151              // special methods
152              ADORecordset* getExportedKeys( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table );
153              ADORecordset* getImportedKeys( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table );
154              ADORecordset* getPrimaryKeys( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table );
155              ADORecordset* getIndexInfo( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, sal_Bool unique, sal_Bool approximate );
156              ADORecordset* getTablePrivileges( const ::com::sun::star::uno::Any& catalog,
157                                                   const ::rtl::OUString& schemaPattern,
158                                                   const ::rtl::OUString& tableNamePattern );
159              ADORecordset* getCrossReference( const ::com::sun::star::uno::Any& primaryCatalog,
160                                                   const ::rtl::OUString& primarySchema,
161                                                   const ::rtl::OUString& primaryTable,
162                                                   const ::com::sun::star::uno::Any& foreignCatalog,
163                                                   const ::rtl::OUString& foreignSchema,
164                                                   const ::rtl::OUString& foreignTable);
165              ADORecordset* getProcedures( const ::com::sun::star::uno::Any& catalog,
166                                                   const ::rtl::OUString& schemaPattern,
167                                                   const ::rtl::OUString& procedureNamePattern );
168              ADORecordset* getProcedureColumns( const ::com::sun::star::uno::Any& catalog,
169                                                   const ::rtl::OUString& schemaPattern,
170                                                   const ::rtl::OUString& procedureNamePattern,
171                                                   const ::rtl::OUString& columnNamePattern );
172              ADORecordset* getTables( const ::com::sun::star::uno::Any& catalog,
173                                                   const ::rtl::OUString& schemaPattern,
174                                                   const ::rtl::OUString& tableNamePattern,
175                                                   const ::com::sun::star::uno::Sequence< ::rtl::OUString >& types );
176              ADORecordset* getColumns( const ::com::sun::star::uno::Any& catalog,
177                                                   const ::rtl::OUString& schemaPattern,
178                                                   const ::rtl::OUString& tableNamePattern,
179                                                   const ::rtl::OUString& columnNamePattern );
180              ADORecordset* getColumnPrivileges( const ::com::sun::star::uno::Any& catalog,
181                                                   const ::rtl::OUString& schemaPattern,
182                                                   const ::rtl::OUString& table,
183                                                   const ::rtl::OUString& columnNamePattern );
184              ADORecordset* getTypeInfo(DataTypeEnum _eType = adEmpty );
185         };
186 
187         //------------------------------------------------------------------------
188         class WpADOCommand : public WpOLEBase<ADOCommand>
189         {
190         public:
191             WpADOCommand(){}
192             // Konstruktoren, operator=
193             // diese rufen nur die Oberklasse
194             WpADOCommand(ADOCommand* pInt)  :   WpOLEBase<ADOCommand>(pInt){}
195 
196             WpADOCommand(const WpADOCommand& rhs){operator=(rhs);}
197 
198              WpADOCommand& operator=(const WpADOCommand& rhs)
199             {
200                 WpOLEBase<ADOCommand>::operator=(rhs); return *this;}
201 
202             //////////////////////////////////////////////////////////////////////
203 
204             sal_Bool putref_ActiveConnection( WpADOConnection *pCon);
205 
206             void put_ActiveConnection(/* [in] */ const OLEVariant& vConn);
207              void Create();
208              sal_Int32 get_State() const;
209              ::rtl::OUString get_CommandText() const;
210              sal_Bool put_CommandText(const ::rtl::OUString &aCon) ;
211              sal_Int32 get_CommandTimeout() const;
212              void put_CommandTimeout(sal_Int32 nRet);
213              sal_Bool get_Prepared() const;
214              sal_Bool put_Prepared(VARIANT_BOOL bPrepared) const;
215              sal_Bool Execute(OLEVariant& RecordsAffected,OLEVariant& Parameters,long Options, ADORecordset** ppiRset);
216              ADOParameter* CreateParameter(const ::rtl::OUString &_bstr,DataTypeEnum Type,ParameterDirectionEnum Direction,long nSize,const OLEVariant &Value);
217 
218              ADOParameters* get_Parameters() const;
219              sal_Bool put_CommandType( /* [in] */ CommandTypeEnum lCmdType);
220              CommandTypeEnum get_CommandType( ) const ;
221             // gibt den Namen des Feldes zur"ueck
222              ::rtl::OUString GetName() const ;
223              sal_Bool put_Name(const ::rtl::OUString& _Name);
224              sal_Bool Cancel();
225         };
226         //------------------------------------------------------------------------
227         class WpADOError : public WpOLEBase<ADOError>
228         {
229         public:
230 
231             // Konstruktoren, operator=
232             // diese rufen nur die Oberklasse
233 
234             WpADOError(ADOError* pInt):WpOLEBase<ADOError>(pInt){}
235 
236             WpADOError(const WpADOError& rhs){operator=(rhs);}
237 
238              WpADOError& operator=(const WpADOError& rhs)
239                 {WpOLEBase<ADOError>::operator=(rhs); return *this;}
240 
241             //////////////////////////////////////////////////////////////////////
242 
243              ::rtl::OUString GetDescription() const;
244 
245              ::rtl::OUString GetSource() const ;
246 
247              sal_Int32 GetNumber() const ;
248              ::rtl::OUString GetSQLState() const ;
249              sal_Int32 GetNativeError() const ;
250         };
251 
252 
253 
254         //------------------------------------------------------------------------
255         class WpADOField : public WpOLEBase<ADOField>
256         {
257             //  friend class WpADOFields;
258         public:
259 
260             // Konstruktoren, operator=
261             // diese rufen nur die Oberklasse
262             WpADOField(ADOField* pInt=NULL):WpOLEBase<ADOField>(pInt){}
263             WpADOField(const WpADOField& rhs){operator=(rhs);}
264 
265              WpADOField& operator=(const WpADOField& rhs)
266                 {WpOLEBase<ADOField>::operator=(rhs); return *this;}
267             //////////////////////////////////////////////////////////////////////
268 
269              WpADOProperties get_Properties();
270              sal_IntPtr GetActualSize() const ;
271              sal_Int32 GetAttributes() const ;
272              sal_Int32 GetStatus() const      ;
273              sal_IntPtr GetDefinedSize() const ;
274             // gibt den Namen des Feldes zur"ueck
275              ::rtl::OUString GetName() const ;
276              DataTypeEnum GetADOType() const  ;
277              void get_Value(OLEVariant& aValVar) const ;
278              OLEVariant get_Value() const;
279              sal_Bool PutValue(const OLEVariant& aVariant);
280              sal_Int32 GetPrecision() const ;
281              sal_Int32 GetNumericScale() const ;
282              sal_Bool AppendChunk(const OLEVariant& _Variant);
283              OLEVariant GetChunk(long Length) const;
284              void GetChunk(long Length,OLEVariant &aValVar) const;
285              OLEVariant GetOriginalValue() const;
286              void GetOriginalValue(OLEVariant &aValVar) const;
287              OLEVariant GetUnderlyingValue() const;
288 
289              void GetUnderlyingValue(OLEVariant &aValVar) const;
290 
291              sal_Bool PutPrecision(sal_Int8 _prec);
292 
293              sal_Bool PutNumericScale(sal_Int8 _prec);
294 
295              void PutADOType(DataTypeEnum eType) ;
296 
297              sal_Bool PutDefinedSize(sal_IntPtr _nDefSize);
298 
299              sal_Bool PutAttributes(sal_Int32 _nDefSize);
300         };
301 
302 
303 
304         //------------------------------------------------------------------------
305         class WpADOProperty: public WpOLEBase<ADOProperty>
306         {
307         public:
308             // Konstruktoren, operator=
309             // diese rufen nur die Oberklasse
310             WpADOProperty(ADOProperty* pInt=NULL):WpOLEBase<ADOProperty>(pInt){}
311             WpADOProperty(const WpADOProperty& rhs){operator=(rhs);}
312              WpADOProperty& operator=(const WpADOProperty& rhs)
313                 {WpOLEBase<ADOProperty>::operator=(rhs); return *this;}
314             //////////////////////////////////////////////////////////////////////
315 
316              OLEVariant GetValue() const;
317              void GetValue(OLEVariant &aValVar) const;
318              sal_Bool PutValue(const OLEVariant &aValVar) ;
319              ::rtl::OUString GetName() const ;
320              DataTypeEnum GetADOType() const ;
321              sal_Int32 GetAttributes() const ;
322              sal_Bool PutAttributes(sal_Int32 _nDefSize);
323         };
324 
325 
326         class WpADORecordset : public WpOLEBase<ADORecordset>
327         {
328 
329         public:
330             // Konstruktoren, operator=
331             // diese rufen nur die Oberklasse
332             WpADORecordset(ADORecordset* pInt=NULL):WpOLEBase<ADORecordset>(pInt){}
333             WpADORecordset(const WpADORecordset& rhs){operator=(rhs);}
334              WpADORecordset& operator=(const WpADORecordset& rhs)
335             {
336                 WpOLEBase<ADORecordset>::operator=(rhs);
337                 return *this;
338             }
339             ~WpADORecordset()
340             {
341                 //  if(pInterface && get_State() == adStateOpen)
342                     //  Close();
343             }
344             //////////////////////////////////////////////////////////////////////
345              void Create();
346              sal_Bool Open(
347                     /* [optional][in] */ VARIANT Source,
348                     /* [optional][in] */ VARIANT ActiveConnection,
349                     /* [defaultvalue][in] */ CursorTypeEnum CursorType,
350                     /* [defaultvalue][in] */ LockTypeEnum LockType,
351                     /* [defaultvalue][in] */ sal_Int32 Options);
352              LockTypeEnum GetLockType();
353              void Close();
354              sal_Bool Cancel() const;
355              sal_Int32 get_State( );
356              sal_Bool Supports( /* [in] */ CursorOptionEnum CursorOptions);
357              sal_IntPtr get_AbsolutePosition();
358              void GetDataSource(IUnknown** pIUnknown) const ;
359              void PutRefDataSource(IUnknown* pIUnknown);
360              void GetBookmark(VARIANT& var);
361              OLEVariant GetBookmark();
362             CompareEnum CompareBookmarks(const OLEVariant& left,const OLEVariant& right);
363              sal_Bool SetBookmark(const OLEVariant &pSafeAr);
364              WpADOFields GetFields() const;
365              sal_Bool Move(sal_Int32 nRows, VARIANT aBmk);
366              sal_Bool MoveNext();
367              sal_Bool MovePrevious();
368              sal_Bool MoveFirst();
369              sal_Bool MoveLast();
370 
371              sal_Bool IsAtBOF() const;
372              sal_Bool IsAtEOF() const;
373              sal_Bool Delete(AffectEnum eNum);
374              sal_Bool AddNew(const OLEVariant &FieldList,const OLEVariant &Values);
375              sal_Bool Update(const OLEVariant &FieldList,const OLEVariant &Values);
376              sal_Bool CancelUpdate();
377              WpADOProperties get_Properties() const;
378              sal_Bool NextRecordset(OLEVariant& RecordsAffected,ADORecordset** ppiRset);
379              sal_Bool get_RecordCount(sal_IntPtr &_nRet) const;
380              sal_Bool get_MaxRecords(sal_IntPtr &_nRet) const;
381              sal_Bool put_MaxRecords(sal_IntPtr _nRet);
382              sal_Bool get_CursorType(CursorTypeEnum &_nRet) const;
383              sal_Bool put_CursorType(CursorTypeEnum _nRet);
384              sal_Bool get_LockType(LockTypeEnum &_nRet) const;
385              sal_Bool put_LockType(LockTypeEnum _nRet);
386              sal_Bool get_CacheSize(sal_Int32 &_nRet) const;
387              sal_Bool put_CacheSize(sal_Int32 _nRet);
388              sal_Bool UpdateBatch(AffectEnum AffectRecords);
389         };
390 
391         //------------------------------------------------------------------------
392         class WpADOParameter:public WpOLEBase<ADOParameter>
393         {
394         public:
395             // Konstruktoren, operator=
396             // diese rufen nur die Oberklasse
397             WpADOParameter(ADOParameter* pInt):WpOLEBase<ADOParameter>(pInt){}
398             WpADOParameter(const WpADOParameter& rhs):WpOLEBase<ADOParameter>(rhs){}
399              WpADOParameter& operator=(const WpADOParameter& rhs)
400                 {WpOLEBase<ADOParameter>::operator=(rhs); return *this;}
401             //////////////////////////////////////////////////////////////////////
402 
403              ::rtl::OUString GetName() const ;
404              DataTypeEnum GetADOType() const ;
405              void put_Type(const DataTypeEnum& _eType);
406              sal_Bool put_Size(const sal_Int32& _nSize);
407              sal_Int32 GetAttributes() const ;
408              sal_Int32 GetPrecision() const ;
409              sal_Int32 GetNumericScale() const ;
410              ParameterDirectionEnum get_Direction() const;
411              void GetValue(OLEVariant& aValVar) const ;
412              OLEVariant GetValue() const;
413              sal_Bool PutValue(const OLEVariant& aVariant);
414              sal_Bool AppendChunk(const OLEVariant& aVariant);
415         };
416 
417         class OTools
418         {
419         public:
420             /** putValue set the property value at the ado column
421                 @param  _rProps     the properties where to set
422                 @param  _aPosition  which property to set
423                 @param  _aValVar    the value to set
424             */
425             static void             putValue(const WpADOProperties& _rProps,const OLEVariant &_aPosition,const OLEVariant &_aValVar);
426 
427             /** getValue returns a specific property value
428                 @param  _rProps     the properties where to set
429                 @param  _aPosition  the property
430 
431                 @return the property value
432             */
433             static OLEVariant       getValue(const WpADOProperties& _rProps,const OLEVariant &_aPosition);
434         };
435     }
436 }
437 #endif //_CONNECTIVITY_ADO_AWRAPADO_HXX_
438