Esempio n. 1
0
static awk_value_t *
do_pg_getcopydata(int nargs, awk_value_t *result)
{
  PGconn *conn;
  char *buffer;
  int rc;

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

  if (!(conn = find_handle(conns, 0))) {
    set_ERRNO(_("pg_getcopydata called with unknown connection handle"));
    RET_NULSTR;
  }

  buffer = NULL;
  switch (rc = PQgetCopyData(conn, &buffer, FALSE)) {
  /* case 0 can only happen if async is TRUE */
  case -1: /* copy done */
    make_null_string(result);
    unset_ERRNO();
    break;
  case -2: /* error */
    make_null_string(result);
    {
      const char *emsg = PQerrorMessage(conn);
      if (emsg)
        set_ERRNO(PQerrorMessage(conn));
      else
        set_ERRNO(_("PQgetCopyData failed, but no error message is available"));
    }
    break;
  default: /* rc should be positive and equal # of bytes in row */
    if (rc > 0) {
      make_string_malloc(buffer, rc, result);
      unset_ERRNO();
    }
    else {
      /* this should not happen */
      char buf[512];
      make_null_string(result);
      snprintf(buf, sizeof(buf),
	       _("PQgetCopyData returned invalid value %d: %s"),
	       rc, PQerrorMessage(conn));
      set_ERRNO(buf);
    }
  }

  if (buffer)
    PQfreemem(buffer);
  return result;
}
Esempio n. 2
0
static void
api_unset_ERRNO(awk_ext_id_t id)
{
	(void) id;

	unset_ERRNO();
}