Exemple #1
0
static awk_value_t *
do_pg_sendprepare(int nargs, awk_value_t *result)
{
  PGconn *conn;
  awk_value_t command;
  char *stmtName;
  int res;

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

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

  if (!get_argument(1, AWK_STRING, &command)) {
    set_ERRNO(_("pg_sendprepare 2nd argument should be a string"));
    RET_NULSTR;
  }

  res = PQsendPrepare(conn, (stmtName = prep_name()),
		      command.str_value.str, 0, NULL);

  if (!res) {
    /* connection is probably bad */
    set_ERRNO(PQerrorMessage(conn));
    RET_NULSTR;
  }
  return make_string_malloc(stmtName, strlen(stmtName), result);
}
CAMLprim value PQsendPrepare_stub(value v_conn, value v_stm_name, value v_query)
{
  PGconn *conn = get_conn(v_conn);
  const char *stm_name = String_val(v_stm_name);
  const char *query = String_val(v_query);
  int res;
  res = PQsendPrepare(conn, stm_name, query, 0, NULL);
  return Val_int(res);
}