/* * Called when writing data (via puts) for a copy <rel> from stdin */ int PgOutputProc(DRIVER_OUTPUT_PROTO) { Pg_ConnectionId *connid; PGconn *conn; connid = (Pg_ConnectionId *) cData; conn = connid->conn; if (connid->res_copy < 0 || PQresultStatus(connid->results[connid->res_copy]) != PGRES_COPY_IN) { *errorCodePtr = EBUSY; return -1; } if (PQputnbytes(conn, buf, bufSize)) { *errorCodePtr = EIO; return -1; } /* * This assumes Tcl script will write the terminator line in a single * operation; maybe not such a good assumption? */ if (bufSize >= 3 && strncmp(&buf[bufSize - 3], "\\.\n", 3) == 0) { if (PgEndCopy(connid, errorCodePtr) == -1) return -1; } return bufSize; }
CAMLprim value PQputnbytes_stub( value v_conn, value v_buf, value v_pos, value v_len) { CAMLparam1(v_conn); PGconn *conn = get_conn(v_conn); value v_res; size_t len = Long_val(v_len); char *buf = caml_stat_alloc(len); memcpy(buf, String_val(v_buf) + Long_val(v_pos), len); caml_enter_blocking_section(); v_res = Val_int(PQputnbytes(conn, buf, len)); free(buf); caml_leave_blocking_section(); CAMLreturn(v_res); }