# Cppcheck report - LibreOffice: connectivity/source/drivers/ado/adoimp.cxx

      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328

    /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */<--- Skipping configuration 'DELETE' since the value of 'DELETE' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    /*
     * This file is part of the LibreOffice project.
     *
     * This Source Code Form is subject to the terms of the Mozilla Public
     * License, v. 2.0. If a copy of the MPL was not distributed with this
     * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     *
     * This file incorporates work covered by the following license notice:
     *
     *   Licensed to the Apache Software Foundation (ASF) under one or more
     *   contributor license agreements. See the NOTICE file distributed
     *   with this work for additional information regarding copyright
     *   ownership. The ASF licenses this file to you under the Apache
     *   License, Version 2.0 (the "License"); you may not use this file
     *   except in compliance with the License. You may obtain a copy of
     *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
     */

    #include <com/sun/star/sdbcx/Privilege.hpp>
    #include <com/sun/star/sdbcx/PrivilegeObject.hpp>
    #include <connectivity/dbexception.hxx>
    #include "ado/Awrapado.hxx"
    #include "ado/adoimp.hxx"
    #include <osl/diagnose.h>
    #include <com/sun/star/sdbc/DataType.hpp>

    using namespace connectivity::ado;
    using namespace com::sun::star::uno;
    using namespace com::sun::star::sdbc;
    using namespace com::sun::star::sdbcx;

    #define MYADOID(l) {l, 0,0x10,{0x80,0,0,0xAA,0,0x6D,0x2E,0xA4}};

    const CLSID ADOS::CLSID_ADOCONNECTION_21    =   MYADOID(0x00000514);
    const IID   ADOS::IID_ADOCONNECTION_21      =   MYADOID(0x00000550);

    const CLSID ADOS::CLSID_ADOCOMMAND_21       =   MYADOID(0x00000507);
    const IID   ADOS::IID_ADOCOMMAND_21         =   MYADOID(0x0000054E);

    const CLSID ADOS::CLSID_ADORECORDSET_21     =   MYADOID(0x00000535);
    const IID   ADOS::IID_ADORECORDSET_21       =   MYADOID(0x0000054F);

    const CLSID ADOS::CLSID_ADOCATALOG_25       =   MYADOID(0x00000602);
    const IID ADOS::IID_ADOCATALOG_25           =   MYADOID(0x00000603);

    const CLSID ADOS::CLSID_ADOINDEX_25         =   MYADOID(0x0000061E);
    const IID ADOS::IID_ADOINDEX_25             =   MYADOID(0x0000061F);

    const CLSID ADOS::CLSID_ADOTABLE_25         =   MYADOID(0x00000609);
    const IID ADOS::IID_ADOTABLE_25             =   MYADOID(0x00000610);

    const CLSID ADOS::CLSID_ADOKEY_25           =   MYADOID(0x00000621);
    const IID ADOS::IID_ADOKEY_25               =   MYADOID(0x00000622);

    const CLSID ADOS::CLSID_ADOCOLUMN_25        =   MYADOID(0x0000061B);
    const IID ADOS::IID_ADOCOLUMN_25            =   MYADOID(0x0000061C);

    const CLSID ADOS::CLSID_ADOGROUP_25         =   MYADOID(0x00000615);
    const IID ADOS::IID_ADOGROUP_25             =   MYADOID(0x00000616);

    const CLSID ADOS::CLSID_ADOUSER_25          =   MYADOID(0x00000618);
    const IID ADOS::IID_ADOUSER_25              =   MYADOID(0x00000619);

    const CLSID ADOS::CLSID_ADOVIEW_25          =   MYADOID(0x00000612);
    const IID ADOS::IID_ADOVIEW_25              =   MYADOID(0x00000613);

    OLEString& ADOS::GetKeyStr()
    {
        static OLEString sKeyStr(OUString("gxwaezucfyqpwjgqbcmtsncuhwsnyhiohwxz"));
        return sKeyStr;
    }

    sal_Int32 ADOS::MapADOType2Jdbc(DataTypeEnum eType)
    {
        sal_Int32 nType = DataType::VARCHAR;
        switch (eType)
        {
            case adUnsignedSmallInt:
            case adSmallInt:            nType = DataType::SMALLINT;     break;
            case adUnsignedInt:
            case adInteger:             nType = DataType::INTEGER;      break;
            case adUnsignedBigInt:
            case adBigInt:              nType = DataType::BIGINT;       break;
            case adSingle:              nType = DataType::FLOAT;        break;
            case adDouble:              nType = DataType::DOUBLE;       break;
            case adCurrency:            nType = DataType::DOUBLE;       break;
            case adVarNumeric:
            case adNumeric:             nType = DataType::NUMERIC;      break;
            case adDecimal:             nType = DataType::DECIMAL;      break;
            case adDBDate:              nType = DataType::DATE;         break;
            case adDBTime:              nType = DataType::TIME;         break;
            case adDate:
            case adDBTimeStamp:         nType = DataType::TIMESTAMP;    break;
            case adBoolean:             nType = DataType::BOOLEAN;      break;
    //      case adArray:               nType = DataType::ARRAY;        break;
            case adBinary:              nType = DataType::BINARY;       break;
            case adGUID:                nType = DataType::OBJECT;       break;
            case adBSTR:
            case adVarWChar:
            case adWChar:
            case adVarChar:             nType = DataType::VARCHAR;      break;
            case adLongVarWChar:
            case adLongVarChar:         nType = DataType::LONGVARCHAR;  break;
            case adVarBinary:           nType = DataType::VARBINARY;    break;
            case adLongVarBinary:       nType = DataType::LONGVARBINARY;break;
            case adChar:                nType = DataType::CHAR;         break;
            case adUnsignedTinyInt:
            case adTinyInt:             nType = DataType::TINYINT;      break;
            case adEmpty:               nType = DataType::SQLNULL;      break;
            case adUserDefined:
            case adPropVariant:
            case adFileTime:
            case adChapter:
            case adIDispatch:
            case adIUnknown:
            case adError:
            case adVariant:
                                        nType = DataType::OTHER;        break;
            default:
                OSL_FAIL("MapADOType2Jdbc: Unknown Type!");
                ;
        }
        return nType;
    }

    DataTypeEnum ADOS::MapJdbc2ADOType(sal_Int32 _nType,sal_Int32 _nJetEngine)
    {
        switch (_nType)
        {
            case DataType::SMALLINT:        return adSmallInt;          break;
            case DataType::INTEGER:         return adInteger;           break;
            case DataType::BIGINT:          return adBigInt;            break;
            case DataType::FLOAT:           return adSingle;            break;
            case DataType::DOUBLE:          return adDouble;            break;
            case DataType::NUMERIC:         return adNumeric;           break;
            case DataType::DECIMAL:         return adDecimal;           break;
            case DataType::DATE:            return isJetEngine(_nJetEngine) ? adDate : adDBDate;            break;
            case DataType::TIME:            return adDBTime;            break;
            case DataType::TIMESTAMP:       return isJetEngine(_nJetEngine) ? adDate : adDBTimeStamp;       break;
            case DataType::BOOLEAN:
            case DataType::BIT:             return adBoolean;           break;
            case DataType::BINARY:          return adBinary;            break;
            case DataType::VARCHAR:         return adVarWChar;          break;
            case DataType::CLOB:
            case DataType::LONGVARCHAR:     return adLongVarWChar;      break;
            case DataType::VARBINARY:       return adVarBinary;         break;
            case DataType::BLOB:
            case DataType::LONGVARBINARY:   return adLongVarBinary;     break;
            case DataType::CHAR:            return adWChar;             break;
            case DataType::TINYINT:         return isJetEngine(_nJetEngine) ? adUnsignedTinyInt : adTinyInt;break;
            case DataType::OBJECT:          return adGUID;      break;
        default:
            OSL_FAIL("MapJdbc2ADOType: Unknown Type!");
                ;
        }
        return adEmpty;
    }

    const int JET_ENGINETYPE_UNKNOWN    = 0;
    const int JET_ENGINETYPE_JET10      = 1;
    const int JET_ENGINETYPE_JET11      = 2;
    const int JET_ENGINETYPE_JET20      = 3;
    const int JET_ENGINETYPE_JET3X      = 4;
    const int JET_ENGINETYPE_JET4X      = 5;
    const int JET_ENGINETYPE_DBASE3     = 10;
    const int JET_ENGINETYPE_DBASE4     = 11;
    const int JET_ENGINETYPE_DBASE5     = 12;
    const int JET_ENGINETYPE_EXCEL30    = 20;
    const int JET_ENGINETYPE_EXCEL40    = 21;
    const int JET_ENGINETYPE_EXCEL50    = 22;
    const int JET_ENGINETYPE_EXCEL80    = 23;
    const int JET_ENGINETYPE_EXCEL90    = 24;
    const int JET_ENGINETYPE_EXCHANGE4  = 30;
    const int JET_ENGINETYPE_LOTUSWK1   = 40;
    const int JET_ENGINETYPE_LOTUSWK3   = 41;
    const int JET_ENGINETYPE_LOTUSWK4   = 42;
    const int JET_ENGINETYPE_PARADOX3X  = 50;
    const int JET_ENGINETYPE_PARADOX4X  = 51;
    const int JET_ENGINETYPE_PARADOX5X  = 52;
    const int JET_ENGINETYPE_PARADOX7X  = 53;
    const int JET_ENGINETYPE_TEXT1X     = 60;
    const int JET_ENGINETYPE_HTML1X     = 70;

    sal_Bool ADOS::isJetEngine(sal_Int32 _nEngineType)
    {
        sal_Bool bRet = sal_False;
        switch(_nEngineType)
        {
            case JET_ENGINETYPE_UNKNOWN:
            case JET_ENGINETYPE_JET10:
            case JET_ENGINETYPE_JET11:
            case JET_ENGINETYPE_JET20:
            case JET_ENGINETYPE_JET3X:
            case JET_ENGINETYPE_JET4X:
            case JET_ENGINETYPE_DBASE3:
            case JET_ENGINETYPE_DBASE4:
            case JET_ENGINETYPE_DBASE5:
            case JET_ENGINETYPE_EXCEL30:
            case JET_ENGINETYPE_EXCEL40:
            case JET_ENGINETYPE_EXCEL50:
            case JET_ENGINETYPE_EXCEL80:
            case JET_ENGINETYPE_EXCEL90:
            case JET_ENGINETYPE_EXCHANGE4:
            case JET_ENGINETYPE_LOTUSWK1:
            case JET_ENGINETYPE_LOTUSWK3:
            case JET_ENGINETYPE_LOTUSWK4:
            case JET_ENGINETYPE_PARADOX3X:
            case JET_ENGINETYPE_PARADOX4X:
            case JET_ENGINETYPE_PARADOX5X:
            case JET_ENGINETYPE_PARADOX7X:
            case JET_ENGINETYPE_TEXT1X:
            case JET_ENGINETYPE_HTML1X:
                bRet = sal_True;
                break;
        }
        return bRet;
    }

    ObjectTypeEnum ADOS::mapObjectType2Ado(sal_Int32 objType)
    {
        ObjectTypeEnum eType = adPermObjTable;
        switch(objType)
        {
            case PrivilegeObject::TABLE:
                eType = adPermObjTable;
                break;
            case PrivilegeObject::VIEW:
                eType = adPermObjView;
                break;
            case PrivilegeObject::COLUMN:
                eType = adPermObjColumn;
                break;
        }
        return eType;
    }

    sal_Int32 ADOS::mapAdoType2Object(ObjectTypeEnum objType)
    {
        sal_Int32 nType = PrivilegeObject::TABLE;
        switch(objType)
        {
            case adPermObjTable:
                nType = PrivilegeObject::TABLE;
                break;
            case adPermObjView:
                nType = PrivilegeObject::VIEW;
                break;
            case adPermObjColumn:
                nType = PrivilegeObject::COLUMN;
                break;
            default:
                OSL_FAIL( "ADOS::mapAdoType2Object: privilege type cannot be translated!" );
                break;
        }
        return nType;
    }
    #ifdef DELETE
    #undef DELETE
    #endif

    sal_Int32 ADOS::mapAdoRights2Sdbc(RightsEnum eRights)
    {
        sal_Int32 nRights = 0;
        if((eRights & adRightInsert) == adRightInsert)
            nRights |= Privilege::INSERT;
        if((eRights & adRightDelete) == adRightDelete)
            nRights |= ::com::sun::star::sdbcx::Privilege::DELETE;
        if((eRights & adRightUpdate) == adRightUpdate)
            nRights |= Privilege::UPDATE;
        if((eRights & adRightWriteDesign) == adRightWriteDesign)
            nRights |= Privilege::ALTER;
        if((eRights & adRightRead) == adRightRead)
            nRights |= Privilege::SELECT;
        if((eRights & adRightReference) == adRightReference)
            nRights |= Privilege::REFERENCE;
        if((eRights & adRightDrop) == adRightDrop)
            nRights |= Privilege::DROP;

        return nRights;
    }

    sal_Int32 ADOS::mapRights2Ado(sal_Int32 nRights)
    {
        sal_Int32 eRights = adRightNone;

        if((nRights & Privilege::INSERT) == Privilege::INSERT)
            eRights |= adRightInsert;
        if((nRights & Privilege::DELETE) == Privilege::DELETE)
            eRights |= adRightDelete;
        if((nRights & Privilege::UPDATE) == Privilege::UPDATE)
            eRights |= adRightUpdate;
        if((nRights & Privilege::ALTER) == Privilege::ALTER)
            eRights |= adRightWriteDesign;
        if((nRights & Privilege::SELECT) == Privilege::SELECT)
            eRights |= adRightRead;
        if((nRights & Privilege::REFERENCE) == Privilege::REFERENCE)
            eRights |= adRightReference;
        if((nRights & Privilege::DROP) == Privilege::DROP)
            eRights |= adRightDrop;

        return eRights;
    }

    WpADOField ADOS::getField(ADORecordset* _pRecordSet,sal_Int32 _nColumnIndex) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
    {
        if ( !_pRecordSet )
            return WpADOField();

        ADOFields* pFields  = NULL;
        _pRecordSet->get_Fields(&pFields);
        WpOLEAppendCollection<ADOFields, ADOField, WpADOField>  aFields(pFields);
        if(_nColumnIndex <= 0 || _nColumnIndex > aFields.GetItemCount())
            ::dbtools::throwInvalidIndexException(NULL);
        WpADOField aField(aFields.GetItem(_nColumnIndex-1));
        if(!aField.IsValid())
            ::dbtools::throwInvalidIndexException(NULL);
        return aField;
    }

    /* vim:set shiftwidth=4 softtabstop=4 expandtab: */