Exemplo n.º 1
0
Variant ArrayUtil::NumericUnique(const Array& input) {
  std::set<double> seenValues;
  Array ret = Array::Create();
  for (ArrayIter iter(input); iter; ++iter) {
    auto const value = tvCastToDouble(iter.secondVal());
    std::pair<std::set<double>::iterator, bool> res =
      seenValues.insert(value);
    if (res.second) { // it was inserted
      ret.set(iter.first(), iter.secondVal());
    }
  }
  return ret;
}
Exemplo n.º 2
0
bool MySQLStmtVariables::bind_params(MYSQL_STMT *stmt) {
  m_value_arr.clear();
  for (int i = 0; i < m_arr.size(); i++) {
    MYSQL_BIND *b = &m_vars[i];
    auto const var = m_arr.lvalAt(i).unboxed();
    Variant v;
    if (isNullType(var.type())) {
      *b->is_null = 1;
    } else {
      switch (b->buffer_type) {
        case MYSQL_TYPE_LONGLONG:
          {
            m_value_arr.push_back(cellToInt(var.tv()));
            b->buffer = m_value_arr.back().getInt64Data();
          }
          break;
        case MYSQL_TYPE_DOUBLE:
          {
            m_value_arr.push_back(tvCastToDouble(var.tv()));
            b->buffer = m_value_arr.back().getDoubleData();
          }
          break;
        case MYSQL_TYPE_STRING:
          {
            m_value_arr.push_back(tvCastToString(var.tv()));
            StringData *sd = m_value_arr.back().getStringData();
            b->buffer = (void *)sd->data();
            // FIXME: setting buffer_length will cause the destructor to free
            // memory owned by the string
            *b->length = sd->size();
          }
          break;
        case MYSQL_TYPE_LONG_BLOB:
          // The value are set using send_long_data so we don't have to do
          // anything here
          break;
        default:
          assertx(false);
      }
    }
  }

  return !mysql_stmt_bind_param(stmt, m_vars);
}
Exemplo n.º 3
0
int64_t convCellToDblHelper(TypedValue tv) {
  return reinterpretDblAsInt(tvCastToDouble(&tv));
}