void Cask::CdapOdbc::DataReader::fetchValue(const web::json::value& value, const ColumnBinding& binding) {
  std::wstring strValue;
  SQLDOUBLE dblValue = NAN;
  switch (binding.getTargetType()) {
    case SQL_CHAR:
      strValue = to_wstring(value);
      this->fetchVarchar(strValue.c_str(), binding);
      break;
    case SQL_WCHAR:
      strValue = to_wstring(value);
      this->fetchWVarchar(strValue.c_str(), binding);
      break;
    case SQL_DOUBLE:
      if (value.is_string()) {
        dblValue = std::wcstod(value.as_string().c_str(), nullptr);
      } else if (value.is_integer()) {
        dblValue = value.as_integer();
      } else if (value.is_double()) {
        dblValue = value.as_double();
      } else if (value.is_number()) {
        dblValue = value.as_number().to_double();
      } else if (value.is_boolean()) {
        dblValue = value.as_bool() ? 1.0 : 0.0;
      }

      this->fetchDouble(dblValue, binding);
      break;
  }
}
Beispiel #2
0
	bool Indiv::setField(const FieldValue t, const web::json::value & value) {
		switch (t) {
		case FieldValue::hasimage:
			this->m_hasimage =
				((!value.is_null()) && value.is_boolean()) ?
				value.as_bool() : false;
			return true;
		case FieldValue::imagedata: {
										this->m_size = 0;
										this->m_data.reset();
										if (value.is_array()) {
											const size_t n = value.size();
											if (n > 0) {
												this->m_data.reset(new byte[n]);
												byte *pDest = this->m_data.get();
												if (pDest != nullptr) {
													for (size_t i = 0; i < n; ++i) {
														byte b = (byte) 0;
														auto v = value.get(i);
														if ((!v.is_null()) && v.is_number()) {
															b = (byte) v.as_integer();
														}
														pDest[i] = b;
													} // i
													this->m_size = n;
												} // pDest
											} // n
										} // array
		}
			return true;
		default:
			break;
		} // t
		return (DatasetChild::setField(t, value));
	} // setField
Beispiel #3
0
void JsonPrettify::formatValue (web::json::value &val, utility::ostream_t &stream) {
	if ( val.is_array () )
		formatArray (val.as_array (), stream) ;
	else if ( val.is_object () )
		formatObject (val.as_object (), stream) ;
	else if ( val.is_string () )
		format_string (val.as_string (), stream) ;
	else if ( val.is_boolean () )
		format_boolean (val.as_bool (), stream) ;
	else if ( val.is_integer () )
		format_integer (val.as_integer (), stream) ;
	else if ( val.is_double () )
		format_double (val.as_double (), stream) ;
	else if ( val.is_null () )
		format_null (stream) ;
}