Пример #1
0
  Lng32 fetchStrings(char **strings, Lng32 bufLen)
  {
    if (!initialized_)
      return -9999;

    Lng32 result = 0;
    for (Lng32 i = 0; i < numOutColumns_ && !result; i++)
    {
      if (!result)
        result = SQL_EXEC_SetDescItem(&outDesc_, i + 1, SQLDESC_TYPE,
                                      SQLTYPECODE_VARCHAR, 0);
      if (!result)
        result = SQL_EXEC_SetDescItem(&outDesc_, i + 1, SQLDESC_LENGTH,
                                      bufLen, 0);
      if (!result)
        result = SQL_EXEC_SetDescItem(&outDesc_, i + 1, SQLDESC_VAR_PTR,
                                      (Long) (strings[i]), 0);
    }

    if (!result)
      result = SQL_EXEC_Fetch(&stmtId_, &outDesc_, 0);

    SQL_ERROR_HANDLER(result);
    return result;
  }
Пример #2
0
  Lng32 executeUsingString(const char *s, Lng32 len)
  {
    if (!initialized_)
    {
      return -9999;
    }

    Lng32 result = 0;

    if (!result)
      result = SQL_EXEC_ClearDiagnostics(NULL);
    if (!result)
      result = SQL_EXEC_SetDescItem(&inDesc_, 1, SQLDESC_TYPE,
                                    (Lng32) SQLTYPECODE_CHAR, 0);
    if (!result)
      result = SQL_EXEC_SetDescItem(&inDesc_, 1, SQLDESC_LENGTH,
                                    (Lng32) len, 0);
    if (!result)
      result = SQL_EXEC_SetDescItem(&inDesc_, 1, SQLDESC_VAR_PTR,
                                    (Long) s, 0);
    if (!result)
      result = SQL_EXEC_ExecClose(&stmtId_, &inDesc_, 0);

    SQL_ERROR_HANDLER(result);
    return result;
  }
Пример #3
0
  Lng32 executeUsingLong(Lng32 i)
  {
    if (!initialized_)
    {
      return -9999;
    }

    Lng32 result = 0;

    if (!result)
      result = SQL_EXEC_ClearDiagnostics(NULL);
    if (!result)
      result = SQL_EXEC_SetDescItem(&inDesc_, 1, SQLDESC_TYPE,
                                    SQLTYPECODE_INTEGER, 0);
    if (!result)
      result = SQL_EXEC_SetDescItem(&inDesc_, 1, SQLDESC_LENGTH,
                                    sizeof(i), 0);
    if (!result)
      result = SQL_EXEC_SetDescItem(&inDesc_, 1, SQLDESC_VAR_PTR,
                                    (Long) &i, 0);
    if (!result)
      result = SQL_EXEC_ExecClose(&stmtId_, &inDesc_, 0);

    SQL_ERROR_HANDLER(result);
    return result;
  }
Пример #4
0
// LCOV_EXCL_START
  Lng32 prepare(const char *stmtText)
  {
    if (!initialized_)
    {
      return -9999;
    }

    delete [] stmtText_;
    stmtText_ = new char[strlen(stmtText) + 1];
    strcpy(stmtText_, stmtText);
    
    Lng32 result = 0;

    if (!result)
      result = SQL_EXEC_ClearDiagnostics(NULL);
    if (!result)
      result = SQL_EXEC_SetDescItem(&stmtTextDesc_, 1, SQLDESC_TYPE,
                                    SQLTYPECODE_CHAR, 0);
    if (!result)
      result = SQL_EXEC_SetDescItem(&stmtTextDesc_, 1, SQLDESC_LENGTH,
                                    strlen(stmtText_), 0);
    if (!result)
      result = SQL_EXEC_SetDescItem(&stmtTextDesc_, 1, SQLDESC_VAR_PTR,
                                    (Long) stmtText_, 0);
    if (!result)
      result = SQL_EXEC_Prepare(&stmtId_, &stmtTextDesc_);

    if (!result)
      result = SQL_EXEC_DescribeStmt(&stmtId_, &inDesc_, &outDesc_);

    if (!result)
      result = SQL_EXEC_GetDescEntryCountBasic(&outDesc_, &numOutColumns_);

    if (!result)
      result = SQL_EXEC_GetDescEntryCountBasic(&inDesc_, &numInColumns_);

    SQL_ERROR_HANDLER(result);
    return result;
  }
Пример #5
0
  Lng32 fetchString(char *buf, Lng32 bufLen)
  {
    if (!initialized_)
    {
      return -9999;
    }

    Lng32 result = 0;

    if (!result)
      result = SQL_EXEC_SetDescItem(&outDesc_, 1, SQLDESC_TYPE,
                                    SQLTYPECODE_VARCHAR, 0);
    if (!result)
      result = SQL_EXEC_SetDescItem(&outDesc_, 1, SQLDESC_LENGTH,
                                    bufLen, 0);
    if (!result)
      result = SQL_EXEC_SetDescItem(&outDesc_, 1, SQLDESC_VAR_PTR,
                                    (Long) buf, 0);
    if (!result)
      result = SQL_EXEC_Fetch(&stmtId_, &outDesc_, 0);

    SQL_ERROR_HANDLER(result);
    return result;
  }
Пример #6
0
  Lng32 fetchLong(Lng32 &i)
  {
    if (!initialized_)
    {
      return -9999;
    }

    Lng32 result = 0;

    if (!result)
      result = SQL_EXEC_SetDescItem(&outDesc_, 1, SQLDESC_TYPE,
                                    SQLTYPECODE_INTEGER, 0);
    if (!result)
      result = SQL_EXEC_SetDescItem(&outDesc_, 1, SQLDESC_LENGTH,
                                    sizeof(i), 0);
    if (!result)
      result = SQL_EXEC_SetDescItem(&outDesc_, 1, SQLDESC_VAR_PTR,
                                    (Long) &i, 0);
    if (!result)
      result = SQL_EXEC_Fetch(&stmtId_, &outDesc_, 0);

    SQL_ERROR_HANDLER(result);
    return result;
  }
Пример #7
0
// returns -1, if a transaction is active; 0, otherwise.
// Optionally returns the transaction identifier, if transid is passed in.
short SqlciEnv::statusTransaction(Int64 * transid)
{
  // if a transaction is active, get the transid by calling the CLI procedure. 
  SQLDESC_ID transid_desc; // added for multi charset module names
  SQLMODULE_ID module;

  init_SQLCLI_OBJ_ID(&transid_desc);
  init_SQLMODULE_ID(&module);

  module.module_name = 0;
  transid_desc.module = &module;
  transid_desc.name_mode = desc_handle;

  HandleCLIErrorInit();
  
  Lng32 rc = SQL_EXEC_AllocDesc(&transid_desc, 1);

  HandleCLIError(rc, this);
  
  Int64 transid_;
  rc = SQL_EXEC_SetDescItem(&transid_desc, 1, SQLDESC_VAR_PTR,
			    (Long)&transid_, 0);
  if (rc)
    SQL_EXEC_DeallocDesc(&transid_desc);
  HandleCLIError(rc, this);
  
  rc = SQL_EXEC_Xact(SQLTRANS_STATUS, &transid_desc);
  if (rc == 0)
    {
      if (transid) *transid = transid_;	// return transID if arg was passed in.
      rc = -1;				// transaction is active.
    }
  else
    rc = 0;
  SQL_EXEC_DeallocDesc(&transid_desc);
	
  return (short)rc;
	
}
Пример #8
0
Lng32 HSSqTableDef::DescribeColumnNames()
  {
    Lng32 entry, len;
    NAString query;
    char colName[ComMAX_1_PART_INTERNAL_UTF8_NAME_LEN_IN_BYTES + 2];
    HSLogMan *LM = HSLogMan::Instance();

    SQLMODULE_ID module;
    init_SQLMODULE_ID(&module);

    SQLSTMT_ID *stmt = new(STMTHEAP) SQLSTMT_ID;
    init_SQLCLI_OBJ_ID(stmt);
    stmt->module = &module;
    stmt->name_mode = stmt_handle;

    SQLDESC_ID *srcDesc = new(STMTHEAP) SQLDESC_ID;
    init_SQLCLI_OBJ_ID(srcDesc);
    srcDesc->module = &module;
    srcDesc->name_mode = desc_handle;

    SQLDESC_ID *outputDesc = new(STMTHEAP) SQLDESC_ID;
    init_SQLCLI_OBJ_ID(outputDesc);
    outputDesc->module = &module;
    outputDesc->name_mode = desc_handle;

    // Use the header information from a 'select *' to get the column names. 
    // Note that this works for SJIS and UTF8 since the names returned through
    // CLI are encoded correctly.
    retcode_ = setHasSyskeyFlag();
    HSHandleError(retcode_);
    if (hasSyskey_)
      query  = "SELECT SYSKEY, * FROM ";
    else
      query  = "SELECT * FROM ";
    if(objActualFormat_ == SQLMP)
      query += getTableName(tableName_->data(), nameSpace_);
    else
      query += getTableName(ansiName_->data(), nameSpace_);

    retcode_ = SQL_EXEC_ClearDiagnostics(stmt);
    // to prevent false alarms for statement heap memory allocation "smt"
    // coverity[leaked_storage]
    HSHandleError(retcode_);

    retcode_ = SQL_EXEC_AllocStmt(stmt, 0);
    HSHandleError(retcode_);
    retcode_ = SQL_EXEC_AllocDesc(srcDesc, 1);
    HSHandleError(retcode_);
    retcode_ = SQL_EXEC_AllocDesc(outputDesc, 4096);
    HSHandleError(retcode_);

    retcode_ = SQL_EXEC_SetDescItem(srcDesc, 1, SQLDESC_TYPE_FS,
                                    REC_BYTE_V_ANSI, 0);
    HSHandleError(retcode_);
    retcode_ = SQL_EXEC_SetDescItem(srcDesc, 1, SQLDESC_VAR_PTR,
                                    (Long)query.data(), 0);
    HSHandleError(retcode_);
    retcode_ = SQL_EXEC_SetDescItem(srcDesc, 1, SQLDESC_LENGTH,
#pragma nowarn(1506)   // warning elimination
                                    query.length() + 1, 0);
#pragma warn(1506)  // warning elimination
    HSHandleError(retcode_);
    // SQLDESC_CHAR_SET must be the last descriptor item set, otherwise
    // it may get reset by other calls to SQL_EXEC_SetDescItem().
    NAString charSet = ActiveSchemaDB()->getDefaults().getValue(ISO_MAPPING);
    NAString defCS   = ActiveSchemaDB()->getDefaults().getValue(DEFAULT_CHARSET);
    retcode_ = SQL_EXEC_SetDescItem(srcDesc, 1, SQLDESC_CHAR_SET,
                                    SQLCHARSETCODE_UTF8
                                    , 0);
    HSHandleError(retcode_);

    // ---------------------------------------------------------------------
    // Prepare the statement
    // ---------------------------------------------------------------------
    SQL_QUERY_COST_INFO query_cost_info;
    SQL_QUERY_COMPILER_STATS_INFO comp_stats_info;
   
    retcode_ = SQL_EXEC_Prepare2(stmt, srcDesc,NULL,0,NULL,&query_cost_info, &comp_stats_info,NULL,0,0);
    HSHandleError( retcode_);

    // ---------------------------------------------------------------------
    // describe the column information into the output descriptor
    // ---------------------------------------------------------------------
    retcode_ = SQL_EXEC_DescribeStmt(stmt, 0, outputDesc);
    HSHandleError(retcode_);

    retcode_ = SQL_EXEC_GetDescEntryCount(outputDesc, &numCols_);
    HSHandleError(retcode_);

    colInfo_ = new(STMTHEAP) HSColumnStruct[numCols_];
    for (Int32 i = 0; i < numCols_; i++)
      {
                                                  /*==   GET COLUMN NAME   ==*/
        entry = i + 1;
        retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry,
                                        SQLDESC_NAME,
                                        0, colName, sizeof(colName), &len, 0);
        if ((retcode_ == 0) &&
            (len >= sizeof(colName) ))
          retcode_ = -1;
        HSHandleError(retcode_);
        colName[len] = '\0';
        *colInfo_[i].colname = &*colName;
                                                  /*== GET COLUMN DATATYPE ==*/
        retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry,
                                        SQLDESC_TYPE_FS,
                                        &colInfo_[i].datatype,
                                        0, 0, 0, 0);
        HSHandleError(retcode_);

        retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry,
                                        SQLDESC_NULLABLE,
                                        &colInfo_[i].nullflag,
                                        0, 0, 0, 0);
        HSHandleError(retcode_);
                                                  /*==  GET COLUMN LENGTH  ==*/
        retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry,
                                        SQLDESC_OCTET_LENGTH,
                                        &colInfo_[i].length,
                                        0, 0, 0, 0);
        HSHandleError(retcode_);

        // If applicable, get the character set, precision and scale
        if (DFS2REC::isAnyCharacter(colInfo_[i].datatype))
          {
            retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry,
                                            SQLDESC_CHAR_SET,
                                            (Lng32*)&colInfo_[i].charset, 0, 0, 0, 0);
            HSHandleError(retcode_);
            // UCS2 cols not supported in MODE_SPECIAL_1 or 2 and do not support case insensitivity.
            retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry,
                                            SQLDESC_CASEINSENSITIVE,
                                            (Lng32*)&colInfo_[i].caseInsensitive, 0, 0, 0, 0);
            HSHandleError(retcode_);
            retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry,
                                            SQLDESC_COLLATION,
                                            (Lng32*)&colInfo_[i].colCollation, 0, 0, 0, 0);
            HSHandleError(retcode_);
          }
        else if ((colInfo_[i].datatype >= REC_MIN_BINARY &&  // May be type NUMERIC
                  colInfo_[i].datatype <= REC_MAX_BINARY)    //    instead of INT
                     ||
                 (colInfo_[i].datatype >= REC_MIN_DECIMAL &&
                 colInfo_[i].datatype <= REC_MAX_DECIMAL))
          {
            retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry,                
                                           SQLDESC_PRECISION,                  
                                           &colInfo_[i].precision, 0, 0, 0, 0);
            HSHandleError(retcode_);
            retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry,                
                                           SQLDESC_SCALE,                  
                                           &colInfo_[i].scale, 0, 0, 0, 0);
            HSHandleError(retcode_);
          }
        else if (DFS2REC::isDateTime(colInfo_[i].datatype))
          {
            retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry,
                                           SQLDESC_DATETIME_CODE,
                                           &colInfo_[i].precision, 0, 0, 0, 0);
            HSHandleError(retcode_);
            retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry,
                                           SQLDESC_PRECISION,
                                           &colInfo_[i].scale, 0, 0, 0, 0);
            HSHandleError(retcode_);
          }
        else if (DFS2REC::isInterval(colInfo_[i].datatype))
          {
            retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry,                
                                            SQLDESC_INT_LEAD_PREC,              
                                            &colInfo_[i].precision, 0, 0, 0, 0);
            HSHandleError(retcode_);                                           
            retcode_ = SQL_EXEC_GetDescItem(outputDesc, entry,                
                                            SQLDESC_PRECISION,                  
                                            &colInfo_[i].scale, 0, 0, 0, 0);
            HSHandleError(retcode_);
          }
        else
          {
            /* No additional information about column attributes needed */
          }

        if (LM->LogNeeded())
          {
            sprintf(LM->msg, "COLUMN [%s]: (%d, %d, %d, %d, %d, %d)"
                                , colInfo_[i].colname->data()
                                , colInfo_[i].datatype
                                , colInfo_[i].nullflag
                                , colInfo_[i].charset
                                , colInfo_[i].length
                                , colInfo_[i].precision
                                , colInfo_[i].scale
                   );
            LM->Log(LM->msg);
          }
      }
    retcode_ = SQL_EXEC_DeallocStmt(stmt);
    HSHandleError(retcode_);

    return 0;
  }