Ejemplo n.º 1
0
void Packet_Generator::handle_start(const bool run)
{
  if (run && !keep_running) {
    keep_running = run;
    handle_next(NULL);
  }
  keep_running = run;
}
Ejemplo n.º 2
0
void
dispatch_db_cmd(ETERM *msg)
{
  ETERM *tag;
  char *tag_name;

  tag = erl_element(1, msg);
  tag_name = (char *)ERL_ATOM_PTR(tag);
  if (strncmp(tag_name, CONNECT_MSG, strlen(CONNECT_MSG)) == 0)
    handle_connect(msg);
  else if (strncmp(tag_name, QUERY_MSG, strlen(QUERY_MSG)) == 0)
    handle_query(msg);
  else if (strncmp(tag_name, PARAM_QUERY_MSG, strlen(PARAM_QUERY_MSG)) == 0)
    handle_param_query(msg);
  else if (strncmp(tag_name, SELECT_COUNT_MSG, strlen(SELECT_COUNT_MSG)) == 0)
    handle_select_count(msg);
  else if (strncmp(tag_name, SELECT_MSG, strlen(SELECT_MSG)) == 0)
    handle_select(msg);
  else if (strncmp(tag_name, FIRST_MSG, strlen(FIRST_MSG)) == 0)
    handle_first(msg);
  else if (strncmp(tag_name, LAST_MSG, strlen(LAST_MSG)) == 0)
    handle_last(msg);
  else if (strncmp(tag_name, NEXT_MSG, strlen(NEXT_MSG)) == 0)
    handle_next(msg);
  else if (strncmp(tag_name, PREV_MSG, strlen(PREV_MSG)) == 0)
    handle_prev(msg);
  else {
    ETERM *resp;

    resp = erl_format("{error, {uknown_message, ~s}}", tag);
    write_msg(resp);
    erl_free_term(resp);
  }

  erl_free_term(tag);
}
Ejemplo n.º 3
0
void
handle_select(ETERM *msg)
{
  ETERM *epos, *ecount, *ecols, *erows, *resp;
  my_ulonglong pos, count;

  epos   = erl_element(2, msg);
  ecount = erl_element(3, msg);
  pos    = ERL_INT_UVALUE(epos);
  count  = ERL_INT_UVALUE(ecount);
  erl_free_term(epos);
  erl_free_term(ecount);

  if (results == NULL) {
    resp = erl_format("{error, result_set_does_not_exist}");
    write_msg(resp);
    erl_free_term(resp);

    return;
  }

  if (ERL_IS_TUPLE(epos)) {
    char *pos_type;
    unsigned int pos_count;

    pos_type = ERL_ATOM_PTR(erl_element(1, epos));
    pos_count = ERL_INT_UVALUE(erl_element(2, epos));
    if (strncmp(pos_type, SELECT_ABSOLUTE, strlen(SELECT_ABSOLUTE)) == 0) {
      resultoffset = pos_count - 1;
    } else if (strncmp(pos_type, SELECT_RELATIVE, strlen(SELECT_RELATIVE)) == 0) {
      resultoffset += pos_count - 1;
    } else {
      resp = erl_format("{error, unknown_position, ~w}", epos);
      write_msg(resp);
      erl_free_term(resp);

      return;
    }
  } else {
    if (strncmp((char *)ERL_ATOM_PTR(epos), SELECT_NEXT, strlen(SELECT_NEXT)) == 0) {
      handle_next(NULL);
      return;
    } else {
      resp = erl_format("{error, unknown_position, ~w}", epos);
      write_msg(resp);
      erl_free_term(resp);

      return;
    }
  }

  mysql_stmt_data_seek(sth, resultoffset);

  ecols = make_cols();
  erows = make_rows(count);
  resultoffset += count;
  resp = erl_format("{selected, ~w, ~w}", ecols, erows);
  erl_free_term(erows);

  erl_free_term(ecols);
  write_msg(resp);
  erl_free_term(resp);
}