Пример #1
0
static void
issdl_temporal(orchids_t *ctx, state_instance_t *state)
{
  ovm_var_t *str;
  void *temp_ctx;
  char *key;

  /* XXX: if str is temp, clone ! */
  str = stack_pop(ctx->ovm_stack);
  if (TYPE(str) != T_STR) {
    DebugLog(DF_ENG, DS_ERROR, "parameter type error\n");
    ISSDL_RETURN_PARAM_ERROR(ctx, state);
    return ;
  }

  DebugLog(DF_ENG, DS_INFO, "Updating temporal information for container %s\n", STR(str));

  key = ovm_strdup(str);

  temp_ctx = strhash_get(ctx->temporal, key);

  if (temp_ctx == NULL) {
    DebugLog(DF_ENG, DS_INFO, "New container %s\n", key);
    /* create container ctx */
    /* add to hash */
    strhash_add(ctx->temporal, (void *)1, key);
  }
  else {
    Xfree(key);
  }

  /* update temporal info */
  ISSDL_RETURN_TRUE(ctx, state);
}
Пример #2
0
static awk_value_t *
process_result(PGconn *conn, PGresult *res, awk_value_t *resp)
{
  ExecStatusType rc;

  switch (rc = PQresultStatus(res)) {
  case PGRES_TUPLES_OK:
    {
      static unsigned long hnum = 0;
      char handle[64];
      size_t sl;

      snprintf(handle, sizeof(handle), "TUPLES %d pgres%lu",
	       PQntuples(res), hnum++);
      sl = strlen(handle);
      strhash_get(results, handle, sl, 1)->data = res;
      make_string_malloc(handle, sl, resp);
    }
    break;
  case PGRES_COMMAND_OK:
  case PGRES_EMPTY_QUERY:
    {
      char result[32];
      int cnt;

      if (sscanf(PQcmdTuples(res), "%d", &cnt) != 1)
        cnt = 0;
      snprintf(result, sizeof(result), "OK %d", cnt);
      PQclear(res);
      make_string_malloc(result, strlen(result), resp);
    }
    break;
  case PGRES_COPY_IN:
    {
      char buf[100];
      snprintf(buf, sizeof(buf), "COPY_IN %d %s",
	       PQnfields(res), (PQbinaryTuples(res) ? "BINARY" : "TEXT"));
      make_string_malloc(buf, strlen(buf), resp);
      PQclear(res);
    }
    break;
  case PGRES_COPY_OUT:
    {
      char buf[100];
      snprintf(buf, sizeof(buf), "COPY_OUT %d %s",
	       PQnfields(res), (PQbinaryTuples(res) ? "BINARY" : "TEXT"));
      make_string_malloc(buf, strlen(buf), resp);
      PQclear(res);
    }
    break;
  default: /* error */
    set_error(conn, rc, resp);
    set_ERRNO(PQresultErrorMessage(res));
    PQclear(res);
  }
  return resp;
}
Пример #3
0
static void *
find_handle(strhash *ht, unsigned int argnum)
{
  awk_value_t handle;
  strhash_entry *ent;

  if (!get_argument(argnum, AWK_STRING, &handle))
    return NULL;
  ent = strhash_get(ht, handle.str_value.str, handle.str_value.len, 0);
  return ent ? ent->data : NULL;
}
Пример #4
0
static int
make_clocktime_float(clockctx_t *ctx,
                     clocktime_t *clocktime,
                     timefloat_t time,
                     sequence_t seq,
                     char *clock_name)
{
  myclock_t *clock;

  clock = strhash_get(ctx->clocks, clock_name);
  if (clock == NULL)
    return (-1);
  clocktime->clock = clock;
  clocktime->seq = seq;
  clocktime->time = time;

  return (0);
}
Пример #5
0
static int
make_clocktime(clockctx_t *ctx,
               clocktime_t *clocktime,
               timeval_t *time,
               sequence_t seq,
               char *clock_name)
{
  myclock_t *clock;

  clock = strhash_get(ctx->clocks, clock_name);
  if (clock == NULL)
    return (-1);
  clocktime->clock = clock;
  clocktime->seq = seq;
  clocktime->time = TIMER_TO_FLOAT(time);

  return (0);
}
Пример #6
0
static awk_value_t *
do_pg_connect(int nargs, awk_value_t *result)
{
  PGconn *conn;

  if (do_lint && (nargs > 1))
    lintwarn(ext_id, _("pg_connect: called with too many arguments"));

  /* grab optional connection options argument */
  if (nargs > 0) {
    awk_value_t conninfo;
    if (!get_argument(0, AWK_STRING, &conninfo)) {
      set_ERRNO(_("pg_connect: argument is present but not a string"));
      RET_NULSTR;
    }
    conn = PQconnectdb(conninfo.str_value.str);
  }
  else
    conn = PQconnectdb("");

  if (PQstatus(conn) != CONNECTION_OK) {
    /* error */
    set_ERRNO(PQerrorMessage(conn));
    if (conn)
      PQfinish(conn);
    RET_NULSTR;
  }

  {
    /* good connection: return a handle */
    static unsigned long hnum = 0;
    char handle[32];
    size_t sl;

    snprintf(handle, sizeof(handle), "pgconn%lu", hnum++);
    sl = strlen(handle);
    strhash_get(conns, handle, sl, 1)->data = conn;
    return make_string_malloc(handle, sl, result);
  }
}