Ejemplo n.º 1
0
void Cask::CdapOdbc::ColumnsDataReader::getColumnValue(const ColumnBinding& binding) {
  auto& record = this->queryResult.getRows().at(this->currentRowIndex);
  std::wstring name;
  std::wstring typeName;
  SQLSMALLINT radix = 0;

  switch (binding.getColumnNumber()) {
    case 1: // TABLE_CAT 
    case 2: // TABLE_SCHEM 
    case 9: // DECIMAL_DIGITS 
    case 12: // REMARKS 
    case 13: // COLUMN_DEF 
    case 15: // SQL_DATETIME_SUB 
    case 16: // CHAR_OCTET_LENGTH 
      this->fetchNull(binding);
      break;
    case 3: // TABLE_NAME 
      this->fetchVarchar(this->tableName.c_str(), binding);
      break;
    case 4: // COLUMN_NAME 
      name = record.at(L"name").as_string();
      this->fetchVarchar(name.c_str(), binding);
      break;
    case 5: // DATA_TYPE
    case 14: // SQL_DATA_TYPE 
      this->fetchSmallint(getDataType(record.at(L"type")), binding);
      break;
    case 6: // TYPE_NAME 
      typeName = getTypeName(record.at(L"type"));
      this->fetchVarchar(typeName.c_str(), binding);
      break;
    case 7: // COLUMN_SIZE 
      this->fetchInt(getColumnSize(record.at(L"type")), binding);
      break;
    case 8: // BUFFER_LENGTH 
      this->fetchInt(getBufferLength(record.at(L"type")), binding);
      break;
    case 10: // NUM_PREC_RADIX 
      radix = getRadix(record.at(L"type"));
      if (radix > 0) {
        this->fetchSmallint(radix, binding);
      } else {
        this->fetchNull(binding);
      }

      break;
    case 11: // NULLABLE
      this->fetchSmallint(getIsNull(record.at(L"type")), binding);
      break;
    case 17: // ORDINAL_POSITION 
      this->fetchInt(this->currentRowIndex + 1, binding);
      break;
    case 18: // IS_NULLABLE 
      this->fetchVarchar((getIsNull(record.at(L"type")) == SQL_NO_NULLS) ? L"NO" : L"YES", binding);
      break;
  }
}
void Cask::CdapOdbc::QueryDataReader::getColumnValue(const ColumnBinding& binding) {
  auto& row = this->queryResult.getRows().at(this->currentRowIndex);
  auto& value = row.at(L"columns").as_array().at(binding.getColumnNumber() - 1);
  
  if (value.is_null()) {
    this->fetchNull(binding);
  } else {
    this->fetchValue(value, binding);
  }
}
void Cask::CdapOdbc::TypesDataReader::getColumnValue(const ColumnBinding& binding) {
    switch (binding.getColumnNumber()) {
    case 1: // TYPE_NAME
        this->fetchVarchar(L"string", binding);
        break;
    case 2: // DATA_TYPE
    case 16: // SQL_DATA_TYPE
        this->fetchSmallint(SQL_VARCHAR, binding);
        break;
    case 3: // COLUMN_SIZE
        this->fetchSmallint(2000, binding);
        break;
    case 4: // LITERAL_PREFIX
    case 5: // LITERAL_SUFFIX
    case 10: // UNSIGNED_ATTRIBUTE
    case 12: // AUTO_UNIQUE_VALUE
    case 13: // LOCAL_TYPE_NAME
    case 14: // MINIMUM_SCALE
    case 15: // MAXIMUM_SCALE
    case 17: // SQL_DATETIME_SUB
    case 18: // NUM_PREC_RADIX
    case 19: // INTERVAL_PRECISION
        this->fetchNull(binding);
        break;
    case 6: // CREATE_PARAMS
        this->fetchVarchar(L"length", binding);
        break;
    case 7: // NULLABLE
        this->fetchSmallint(SQL_NULLABLE, binding);
        break;
    case 8: // CASE_SENSITIVE
        this->fetchSmallint(SQL_TRUE, binding);
        break;
    case 9: // SEARCHABLE
        this->fetchSmallint(SQL_SEARCHABLE, binding);
        break;
    case 11: // FIXED_PREC_SCALE
        this->fetchSmallint(SQL_FALSE, binding);
        break;
    }
}