CAMLprim value PQgetlineAsync_stub( value v_conn, value v_buf, value v_pos, value v_len) { return Val_int(PQgetlineAsync(get_conn(v_conn), String_val(v_buf) + Long_val(v_pos), Long_val(v_len))); }
/* * PQgetline - gets a newline-terminated string from the backend. * * See fe-exec.c for documentation. */ int pqGetline3(PGconn *conn, char *s, int maxlen) { int status; if (conn->sock < 0 || conn->asyncStatus != PGASYNC_COPY_OUT || conn->copy_is_binary) { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("PQgetline: not doing text COPY OUT\n")); *s = '\0'; return EOF; } while ((status = PQgetlineAsync(conn, s, maxlen - 1)) == 0) { /* need to load more data */ if (pqWait(TRUE, FALSE, conn) || pqReadData(conn) < 0) { *s = '\0'; return EOF; } } if (status < 0) { /* End of copy detected; gin up old-style terminator */ strcpy(s, "\\."); return 0; } /* Add null terminator, and strip trailing \n if present */ if (s[status - 1] == '\n') { s[status - 1] = '\0'; return 0; } else { s[status] = '\0'; return 1; } }
/* * Called when reading data (via gets) for a copy <rel> to stdout. */ int PgInputProc(DRIVER_INPUT_PROTO) { Pg_ConnectionId *connid; PGconn *conn; int avail; connid = (Pg_ConnectionId *) cData; conn = connid->conn; if (connid->res_copy < 0 || PQresultStatus(connid->results[connid->res_copy]) != PGRES_COPY_OUT) { *errorCodePtr = EBUSY; return -1; } /* * Read any newly arrived data into libpq's buffer, thereby clearing * the socket's read-ready condition. */ if (!PQconsumeInput(conn)) { *errorCodePtr = EIO; return -1; } /* Move data from libpq's buffer to Tcl's. */ avail = PQgetlineAsync(conn, buf, bufSize); if (avail < 0) { /* Endmarker detected, change state and return 0 */ return PgEndCopy(connid, errorCodePtr); } return avail; }