LCOV - code coverage report
Current view: top level - connectivity/source/drivers/firebird - Util.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 121 0.0 %
Date: 2014-04-14 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  */
       9             : 
      10             : #include "Util.hxx"
      11             : 
      12             : #include <rtl/ustrbuf.hxx>
      13             : 
      14             : using namespace ::connectivity;
      15             : 
      16             : using namespace ::rtl;
      17             : 
      18             : using namespace ::com::sun::star;
      19             : using namespace ::com::sun::star::sdbc;
      20             : using namespace ::com::sun::star::uno;
      21             : 
      22           0 : OUString firebird::sanitizeIdentifier(const OUString& rIdentifier)
      23             : {
      24           0 :     OUString sRet = rIdentifier.trim();
      25             :     assert(sRet.getLength() <= 31); // Firebird identifiers cannot be longer than this.
      26             : 
      27           0 :     return sRet;
      28             : }
      29             : 
      30           0 : void firebird::evaluateStatusVector(ISC_STATUS_ARRAY& aStatusVector,
      31             :                                     const OUString& aCause,
      32             :                                     const uno::Reference< XInterface >& _rxContext)
      33             :     throw(SQLException)
      34             : {
      35           0 :     if (aStatusVector[0]==1 && aStatusVector[1]) // indicates error
      36             :     {
      37           0 :         OUStringBuffer buf;
      38             :         char msg[512]; // Size is based on suggestion in docs.
      39           0 :         const ISC_STATUS* pStatus = (const ISC_STATUS*) &aStatusVector;
      40             : 
      41           0 :         buf.appendAscii("firebird_sdbc error:");
      42           0 :         while(fb_interpret(msg, sizeof(msg), &pStatus))
      43             :         {
      44             :             // TODO: verify encoding
      45           0 :             buf.appendAscii("\n*");
      46           0 :             buf.append(OUString(msg, strlen(msg), RTL_TEXTENCODING_UTF8));
      47             :         }
      48           0 :         buf.appendAscii("\ncaused by\n'").append(aCause).appendAscii("'\n");
      49             : 
      50           0 :         OUString error = buf.makeStringAndClear();
      51             :         SAL_WARN("connectivity.firebird", error);
      52             : 
      53           0 :         throw SQLException( error, _rxContext, OUString(), 1, Any() );
      54             :     }
      55           0 : }
      56             : 
      57           0 : sal_Int32 firebird::getColumnTypeFromFBType(short aType)
      58             : {
      59           0 :     aType &= ~1; // Remove last bit -- it is used to denote whether column
      60             :                  // can store Null, not needed for type determination
      61           0 :     switch (aType)
      62             :     {
      63             :     case SQL_TEXT:
      64           0 :         return DataType::CHAR;
      65             :     case SQL_VARYING:
      66           0 :         return DataType::VARCHAR;
      67             :     case SQL_SHORT:
      68           0 :         return DataType::SMALLINT;
      69             :     case SQL_LONG:
      70           0 :         return DataType::INTEGER;
      71             :     case SQL_FLOAT:
      72           0 :         return DataType::FLOAT;
      73             :     case SQL_DOUBLE:
      74           0 :         return DataType::DOUBLE;
      75             :     case SQL_D_FLOAT:
      76           0 :         return DataType::DOUBLE;
      77             :     case SQL_TIMESTAMP:
      78           0 :         return DataType::TIMESTAMP;
      79             :     case SQL_BLOB:
      80           0 :         return DataType::BLOB;
      81             :     case SQL_ARRAY:
      82           0 :         return DataType::ARRAY;
      83             :     case SQL_TYPE_TIME:
      84           0 :         return DataType::TIME;
      85             :     case SQL_TYPE_DATE:
      86           0 :         return DataType::DATE;
      87             :     case SQL_INT64:
      88           0 :         return DataType::BIGINT;
      89             :     case SQL_NULL:
      90           0 :         return DataType::SQLNULL;
      91             :     case SQL_QUAD:      // Is a "Blob ID" according to the docs
      92           0 :         return 0;       // TODO: verify
      93             :     default:
      94             :         assert(false); // Should never happen
      95           0 :         return 0;
      96             :     }
      97             : }
      98             : 
      99           0 : OUString firebird::getColumnTypeNameFromFBType(short aType)
     100             : {
     101           0 :     aType &= ~1; // Remove last bit -- it is used to denote whether column
     102             :                 // can store Null, not needed for type determination
     103           0 :     switch (aType)
     104             :     {
     105             :     case SQL_TEXT:
     106           0 :         return OUString("SQL_TEXT");
     107             :     case SQL_VARYING:
     108           0 :         return OUString("SQL_VARYING");
     109             :     case SQL_SHORT:
     110           0 :         return OUString("SQL_SHORT");
     111             :     case SQL_LONG:
     112           0 :         return OUString("SQL_LONG");
     113             :     case SQL_FLOAT:
     114           0 :         return OUString("SQL_FLOAT");
     115             :     case SQL_DOUBLE:
     116           0 :         return OUString("SQL_DOUBLE");
     117             :     case SQL_D_FLOAT:
     118           0 :         return OUString("SQL_D_FLOAT");
     119             :     case SQL_TIMESTAMP:
     120           0 :         return OUString("SQL_TIMESTAMP");
     121             :     case SQL_BLOB:
     122           0 :         return OUString("SQL_BLOB");
     123             :     case SQL_ARRAY:
     124           0 :         return OUString("SQL_ARRAY");
     125             :     case SQL_TYPE_TIME:
     126           0 :         return OUString("SQL_TYPE_TIME");
     127             :     case SQL_TYPE_DATE:
     128           0 :         return OUString("SQL_TYPE_DATE");
     129             :     case SQL_INT64:
     130           0 :         return OUString("SQL_INT64");
     131             :     case SQL_NULL:
     132           0 :         return OUString("SQL_NULL");
     133             :     case SQL_QUAD:
     134           0 :         return OUString("SQL_QUAD");
     135             :     default:
     136             :         assert(false); // Should never happen
     137           0 :         return OUString();
     138             :     }
     139             : }
     140             : 
     141           0 : short firebird::getFBTypeFromBlrType(short blrType)
     142             : {
     143           0 :     switch (blrType)
     144             :     {
     145             :     case blr_text:
     146           0 :         return SQL_TEXT;
     147             :     case blr_text2:
     148             :         assert(false);
     149           0 :         return 0; // No idea if this should be supported
     150             :     case blr_varying:
     151           0 :         return SQL_VARYING;
     152             :     case blr_varying2:
     153             :         assert(false);
     154           0 :         return 0; // No idea if this should be supported
     155             :     case blr_short:
     156           0 :         return SQL_SHORT;
     157             :     case blr_long:
     158           0 :         return SQL_LONG;
     159             :     case blr_float:
     160           0 :         return SQL_FLOAT;
     161             :     case blr_double:
     162           0 :         return SQL_DOUBLE;
     163             :     case blr_d_float:
     164           0 :         return SQL_D_FLOAT;
     165             :     case blr_timestamp:
     166           0 :         return SQL_TIMESTAMP;
     167             :     case blr_blob:
     168           0 :         return SQL_BLOB;
     169             : //     case blr_SQL_ARRAY:
     170             : //         return OUString("SQL_ARRAY");
     171             :     case blr_sql_time:
     172           0 :         return SQL_TYPE_TIME;
     173             :     case blr_sql_date:
     174           0 :         return SQL_TYPE_DATE;
     175             :     case blr_int64:
     176           0 :         return SQL_INT64;
     177             : //     case SQL_NULL:
     178             : //         return OUString("SQL_NULL");
     179             :     case blr_quad:
     180           0 :         return SQL_QUAD;
     181             :     default:
     182             :         // If this happens we have hit one of the extra types in ibase.h
     183             :         // look up blr_* for a list, e.g. blr_domain_name, blr_not_nullable etc.
     184             :         assert(false);
     185           0 :         return 0;
     186             :     }
     187             : }
     188             : 
     189           0 : void firebird::mallocSQLVAR(XSQLDA* pSqlda)
     190             : {
     191             :     // TODO: confirm the sizings below.
     192           0 :     XSQLVAR* pVar = pSqlda->sqlvar;
     193           0 :     for (int i=0; i < pSqlda->sqld; i++, pVar++)
     194             :     {
     195           0 :         int dtype = (pVar->sqltype & ~1); /* drop flag bit for now */
     196           0 :         switch(dtype) {
     197             :         case SQL_TEXT:
     198           0 :             pVar->sqldata = (char *)malloc(sizeof(char)*pVar->sqllen);
     199           0 :             break;
     200             :         case SQL_VARYING:
     201           0 :             pVar->sqldata = (char *)malloc(sizeof(char)*pVar->sqllen + 2);
     202           0 :             break;
     203             :         case SQL_SHORT:
     204           0 :             pVar->sqldata = (char*) malloc(sizeof(sal_Int16));
     205           0 :             break;
     206             :         case SQL_LONG:
     207           0 :             pVar->sqldata = (char*) malloc(sizeof(sal_Int32));
     208           0 :             break;
     209             :         case SQL_FLOAT:
     210           0 :             pVar->sqldata = (char *)malloc(sizeof(float));
     211           0 :             break;
     212             :         case SQL_DOUBLE:
     213           0 :             pVar->sqldata = (char *)malloc(sizeof(double));
     214           0 :             break;
     215             :         case SQL_D_FLOAT:
     216           0 :             pVar->sqldata = (char *)malloc(sizeof(double));
     217           0 :             break;
     218             :         case SQL_TIMESTAMP:
     219           0 :             pVar->sqldata = (char*) malloc(sizeof(ISC_TIMESTAMP));
     220           0 :             break;
     221             :         case SQL_BLOB:
     222           0 :             pVar->sqldata = (char*) malloc(sizeof(ISC_QUAD));
     223           0 :             break;
     224             :         case SQL_ARRAY:
     225             :             assert(false); // TODO: implement
     226           0 :             break;
     227             :         case SQL_TYPE_TIME:
     228           0 :             pVar->sqldata = (char*) malloc(sizeof(ISC_TIME));
     229           0 :             break;
     230             :         case SQL_TYPE_DATE:
     231           0 :             pVar->sqldata = (char*) malloc(sizeof(ISC_DATE));
     232           0 :             break;
     233             :         case SQL_INT64:
     234           0 :             pVar->sqldata = (char *)malloc(sizeof(sal_Int64));
     235           0 :             break;
     236             :         case SQL_NULL:
     237             :             assert(false); // TODO: implement
     238           0 :             break;
     239             :         case SQL_QUAD:
     240             :             assert(false); // TODO: implement
     241           0 :             break;
     242             :         default:
     243             :             SAL_WARN("connectivity.firebird", "Unknown type: " << dtype);
     244             :             assert(false);
     245           0 :             break;
     246             :         }
     247           0 :         if (pVar->sqltype & 1)
     248             :         {
     249             :             /* allocate variable to hold NULL status */
     250           0 :             pVar->sqlind = (short *)malloc(sizeof(short));
     251             :         }
     252             :     }
     253           0 : }
     254             : 
     255           0 : void firebird::freeSQLVAR(XSQLDA* pSqlda)
     256             : {
     257           0 :     XSQLVAR* pVar = pSqlda->sqlvar;
     258           0 :     for (int i=0; i < pSqlda->sqld; i++, pVar++)
     259             :     {
     260           0 :         int dtype = (pVar->sqltype & ~1); /* drop flag bit for now */
     261           0 :         switch(dtype) {
     262             :         case SQL_TEXT:
     263             :         case SQL_VARYING:
     264             :         case SQL_SHORT:
     265             :         case SQL_LONG:
     266             :         case SQL_FLOAT:
     267             :         case SQL_DOUBLE:
     268             :         case SQL_D_FLOAT:
     269             :         case SQL_TIMESTAMP:
     270             :         case SQL_BLOB:
     271             :         case SQL_INT64:
     272             :         case SQL_TYPE_TIME:
     273             :         case SQL_TYPE_DATE:
     274           0 :             free(pVar->sqldata);
     275           0 :             break;
     276             :         case SQL_ARRAY:
     277             :             assert(false); // TODO: implement
     278           0 :             break;
     279             :         case SQL_NULL:
     280             :             assert(false); // TODO: implement
     281           0 :             break;
     282             :         case SQL_QUAD:
     283             :             assert(false); // TODO: implement
     284           0 :             break;
     285             :         default:
     286             :             SAL_WARN("connectivity.firebird", "Unknown type: " << dtype);
     287             :             assert(false);
     288           0 :             break;
     289             :         }
     290             : 
     291           0 :         if (pVar->sqltype & 1)
     292             :         {
     293           0 :             free(pVar->sqlind);
     294             :         }
     295             :     }
     296           0 : }
     297             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10