* PQgetline - gets a newline-terminated string from the backend. * * See fe-exec.c for documentation. */
| 1950 | * See fe-exec.c for documentation. |
| 1951 | */ |
| 1952 | int |
| 1953 | pqGetline3(PGconn *conn, char *s, int maxlen) |
| 1954 | { |
| 1955 | int status; |
| 1956 | |
| 1957 | if (conn->sock == PGINVALID_SOCKET || |
| 1958 | (conn->asyncStatus != PGASYNC_COPY_OUT && |
| 1959 | conn->asyncStatus != PGASYNC_COPY_BOTH) || |
| 1960 | conn->copy_is_binary) |
| 1961 | { |
| 1962 | appendPQExpBufferStr(&conn->errorMessage, |
| 1963 | libpq_gettext("PQgetline: not doing text COPY OUT\n")); |
| 1964 | *s = '\0'; |
| 1965 | return EOF; |
| 1966 | } |
| 1967 | |
| 1968 | while ((status = PQgetlineAsync(conn, s, maxlen - 1)) == 0) |
| 1969 | { |
| 1970 | /* need to load more data */ |
| 1971 | if (pqWait(true, false, conn) || |
| 1972 | pqReadData(conn) < 0) |
| 1973 | { |
| 1974 | *s = '\0'; |
| 1975 | return EOF; |
| 1976 | } |
| 1977 | } |
| 1978 | |
| 1979 | if (status < 0) |
| 1980 | { |
| 1981 | /* End of copy detected; gin up old-style terminator */ |
| 1982 | strcpy(s, "\\."); |
| 1983 | return 0; |
| 1984 | } |
| 1985 | |
| 1986 | /* Add null terminator, and strip trailing \n if present */ |
| 1987 | if (s[status - 1] == '\n') |
| 1988 | { |
| 1989 | s[status - 1] = '\0'; |
| 1990 | return 0; |
| 1991 | } |
| 1992 | else |
| 1993 | { |
| 1994 | s[status] = '\0'; |
| 1995 | return 1; |
| 1996 | } |
| 1997 | } |
| 1998 | |
| 1999 | /* |
| 2000 | * PQgetlineAsync - gets a COPY data row without blocking. |
no test coverage detected