Fixes for:
Here are a few minor fixes to Postgres95. Mostly I have added const to some of the char pointers. There was also a missing header file and a place where it looks like "==" was used when "=" was meant. I also changed some variables from Pfin and Pfout tp pfin and pfout because the latter shadow global variables and that just seems like an unsafe practice which I like to avoid. Submitted by: "D'Arcy J.M. Cain" <darcy@druid.druid.com>
This commit is contained in:
parent
fd3b829959
commit
c4e53a1411
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.3 1996/07/27 02:27:55 scrappy Exp $
|
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.4 1996/08/06 16:16:42 scrappy Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -162,16 +162,16 @@ pg_krb4_authname(char* PQerrormsg)
|
|||||||
* (canonicalized to omit all domain suffixes).
|
* (canonicalized to omit all domain suffixes).
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
pg_krb4_sendauth(char* PQerrormsg, int sock,
|
pg_krb4_sendauth(const char* PQerrormsg, int sock,
|
||||||
struct sockaddr_in *laddr,
|
struct sockaddr_in *laddr,
|
||||||
struct sockaddr_in *raddr,
|
struct sockaddr_in *raddr,
|
||||||
char *hostname)
|
const char *hostname)
|
||||||
{
|
{
|
||||||
long krbopts = 0; /* one-way authentication */
|
long krbopts = 0; /* one-way authentication */
|
||||||
KTEXT_ST clttkt;
|
KTEXT_ST clttkt;
|
||||||
int status;
|
int status;
|
||||||
char hostbuf[MAXHOSTNAMELEN];
|
char hostbuf[MAXHOSTNAMELEN];
|
||||||
char *realm = getenv("PGREALM"); /* NULL == current realm */
|
const char *realm = getenv("PGREALM"); /* NULL == current realm */
|
||||||
|
|
||||||
if (!hostname || !(*hostname)) {
|
if (!hostname || !(*hostname)) {
|
||||||
if (gethostname(hostbuf, MAXHOSTNAMELEN) < 0)
|
if (gethostname(hostbuf, MAXHOSTNAMELEN) < 0)
|
||||||
@ -227,7 +227,7 @@ pg_krb4_sendauth(char* PQerrormsg, int sock,
|
|||||||
* and we can't afford to punt.
|
* and we can't afford to punt.
|
||||||
*/
|
*/
|
||||||
static char *
|
static char *
|
||||||
pg_an_to_ln(char *aname)
|
pg_an_to_ln(const char *aname)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
@ -246,7 +246,7 @@ pg_an_to_ln(char *aname)
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
krb5_ccache pg_krb5_init()
|
krb5_ccache pg_krb5_init(void)
|
||||||
{
|
{
|
||||||
krb5_error_code code;
|
krb5_error_code code;
|
||||||
char *realm, *defname;
|
char *realm, *defname;
|
||||||
@ -287,8 +287,8 @@ krb5_ccache pg_krb5_init()
|
|||||||
*
|
*
|
||||||
* We obtain this information by digging around in the ticket file.
|
* We obtain this information by digging around in the ticket file.
|
||||||
*/
|
*/
|
||||||
static char *
|
static const char *
|
||||||
pg_krb5_authname(char* PQerrormsg)
|
pg_krb5_authname(const char* PQerrormsg)
|
||||||
{
|
{
|
||||||
krb5_ccache ccache;
|
krb5_ccache ccache;
|
||||||
krb5_principal principal;
|
krb5_principal principal;
|
||||||
@ -335,15 +335,15 @@ pg_krb5_authname(char* PQerrormsg)
|
|||||||
* in the PGREALM (or local) database. This is probably a bad assumption.
|
* in the PGREALM (or local) database. This is probably a bad assumption.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
pg_krb5_sendauth(char* PQerrormsg,int sock,
|
pg_krb5_sendauth(const char* PQerrormsg,int sock,
|
||||||
struct sockaddr_in *laddr,
|
struct sockaddr_in *laddr,
|
||||||
struct sockaddr_in *raddr,
|
struct sockaddr_in *raddr,
|
||||||
char *hostname)
|
const char *hostname)
|
||||||
{
|
{
|
||||||
char servbuf[MAXHOSTNAMELEN + 1 +
|
char servbuf[MAXHOSTNAMELEN + 1 +
|
||||||
sizeof(PG_KRB_SRVNAM)];
|
sizeof(PG_KRB_SRVNAM)];
|
||||||
char *hostp;
|
const char *hostp;
|
||||||
char *realm;
|
const char *realm;
|
||||||
krb5_error_code code;
|
krb5_error_code code;
|
||||||
krb5_principal client, server;
|
krb5_principal client, server;
|
||||||
krb5_ccache ccache;
|
krb5_ccache ccache;
|
||||||
@ -430,7 +430,7 @@ pg_krb5_sendauth(char* PQerrormsg,int sock,
|
|||||||
* fe_sendauth -- client demux routine for outgoing authentication information
|
* fe_sendauth -- client demux routine for outgoing authentication information
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
fe_sendauth(MsgType msgtype, Port *port, char *hostname, char* PQerrormsg)
|
fe_sendauth(MsgType msgtype, Port *port, const char *hostname, const char* PQerrormsg)
|
||||||
{
|
{
|
||||||
switch (msgtype) {
|
switch (msgtype) {
|
||||||
#ifdef KRB4
|
#ifdef KRB4
|
||||||
@ -474,7 +474,7 @@ fe_sendauth(MsgType msgtype, Port *port, char *hostname, char* PQerrormsg)
|
|||||||
static pg_authsvc = -1;
|
static pg_authsvc = -1;
|
||||||
|
|
||||||
void
|
void
|
||||||
fe_setauthsvc(char *name, char* PQerrormsg)
|
fe_setauthsvc(const char *name, char* PQerrormsg)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 1994, Regents of the University of California
|
* Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: fe-auth.h,v 1.1.1.1 1996/07/09 06:22:17 scrappy Exp $
|
* $Id: fe-auth.h,v 1.2 1996/08/06 16:16:44 scrappy Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -28,8 +28,8 @@
|
|||||||
#define DEFAULT_CLIENT_AUTHSVC "kerberos"
|
#define DEFAULT_CLIENT_AUTHSVC "kerberos"
|
||||||
#endif /* KRB4 || KRB5 */
|
#endif /* KRB4 || KRB5 */
|
||||||
|
|
||||||
extern int fe_sendauth(MsgType msgtype, Port *port, char *hostname, char* PQerromsg);
|
extern int fe_sendauth(MsgType msgtype, Port *port, const char *hostname, const char* PQerromsg);
|
||||||
extern void fe_setauthsvc(char *name, char* PQerrormsg);
|
extern void fe_setauthsvc(const char *name, char* PQerrormsg);
|
||||||
|
|
||||||
#define PG_KRB4_VERSION "PGVER4.1" /* at most KRB_SENDAUTH_VLEN chars */
|
#define PG_KRB4_VERSION "PGVER4.1" /* at most KRB_SENDAUTH_VLEN chars */
|
||||||
#define PG_KRB5_VERSION "PGVER5.1"
|
#define PG_KRB5_VERSION "PGVER5.1"
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.4 1996/07/23 03:35:12 scrappy Exp $
|
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.5 1996/08/06 16:16:45 scrappy Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -31,7 +31,7 @@
|
|||||||
standard function? (My, my. Touchy today, are we?) */
|
standard function? (My, my. Touchy today, are we?) */
|
||||||
static
|
static
|
||||||
char *
|
char *
|
||||||
strdup(char *string)
|
strdup(const char *string)
|
||||||
{
|
{
|
||||||
char *nstr;
|
char *nstr;
|
||||||
|
|
||||||
@ -64,10 +64,10 @@ static void closePGconn(PGconn *conn);
|
|||||||
* ----------------
|
* ----------------
|
||||||
*/
|
*/
|
||||||
PGconn*
|
PGconn*
|
||||||
PQsetdb(char *pghost, char* pgport, char* pgoptions, char* pgtty, char* dbName)
|
PQsetdb(const char *pghost, const char* pgport, const char* pgoptions, const char* pgtty, const char* dbName)
|
||||||
{
|
{
|
||||||
PGconn *conn;
|
PGconn *conn;
|
||||||
char *tmp;
|
const char *tmp;
|
||||||
|
|
||||||
conn = (PGconn*)malloc(sizeof(PGconn));
|
conn = (PGconn*)malloc(sizeof(PGconn));
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.12 1996/07/31 18:40:09 scrappy Exp $
|
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.13 1996/08/06 16:16:46 scrappy Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -37,7 +37,7 @@ struct winsize {
|
|||||||
#define TUPARR_GROW_BY 100
|
#define TUPARR_GROW_BY 100
|
||||||
|
|
||||||
/* keep this in same order as ExecStatusType in pgtclCmds.h */
|
/* keep this in same order as ExecStatusType in pgtclCmds.h */
|
||||||
char* pgresStatus[] = {
|
const char* pgresStatus[] = {
|
||||||
"PGRES_EMPTY_QUERY",
|
"PGRES_EMPTY_QUERY",
|
||||||
"PGRES_COMMAND_OK",
|
"PGRES_COMMAND_OK",
|
||||||
"PGRES_TUPLES_OK",
|
"PGRES_TUPLES_OK",
|
||||||
@ -130,7 +130,7 @@ getTuple(PGconn *conn, PGresult* result, int binary)
|
|||||||
char bmap; /* One byte of the bitmap */
|
char bmap; /* One byte of the bitmap */
|
||||||
int bitcnt = 0; /* number of bits examined in current byte */
|
int bitcnt = 0; /* number of bits examined in current byte */
|
||||||
int vlen; /* length of the current field value */
|
int vlen; /* length of the current field value */
|
||||||
FILE *Pfin = conn->Pfin;
|
FILE *pfin = conn->Pfin;
|
||||||
FILE *Pfdebug = conn->Pfdebug;
|
FILE *Pfdebug = conn->Pfdebug;
|
||||||
|
|
||||||
PGresAttValue* tup;
|
PGresAttValue* tup;
|
||||||
@ -145,7 +145,7 @@ getTuple(PGconn *conn, PGresult* result, int binary)
|
|||||||
if ( (nfields % BYTELEN) > 0)
|
if ( (nfields % BYTELEN) > 0)
|
||||||
nbytes++;
|
nbytes++;
|
||||||
|
|
||||||
if (pqGetnchar(bitmap, nbytes, Pfin, Pfdebug) == 1){
|
if (pqGetnchar(bitmap, nbytes, pfin, Pfdebug) == 1){
|
||||||
sprintf(conn->errorMessage,
|
sprintf(conn->errorMessage,
|
||||||
"Error reading null-values bitmap from tuple data stream\n");
|
"Error reading null-values bitmap from tuple data stream\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -164,7 +164,7 @@ getTuple(PGconn *conn, PGresult* result, int binary)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* get the value length (the first four bytes are for length) */
|
/* get the value length (the first four bytes are for length) */
|
||||||
pqGetInt(&vlen, VARHDRSZ, Pfin, Pfdebug);
|
pqGetInt(&vlen, VARHDRSZ, pfin, Pfdebug);
|
||||||
if (binary == 0) {
|
if (binary == 0) {
|
||||||
vlen = vlen - VARHDRSZ;
|
vlen = vlen - VARHDRSZ;
|
||||||
}
|
}
|
||||||
@ -174,7 +174,7 @@ getTuple(PGconn *conn, PGresult* result, int binary)
|
|||||||
tup[i].value = (char*) malloc(vlen + 1);
|
tup[i].value = (char*) malloc(vlen + 1);
|
||||||
/* read in the value; */
|
/* read in the value; */
|
||||||
if (vlen > 0)
|
if (vlen > 0)
|
||||||
pqGetnchar((char*)(tup[i].value), vlen, Pfin, Pfdebug);
|
pqGetnchar((char*)(tup[i].value), vlen, pfin, Pfdebug);
|
||||||
tup[i].value[vlen] = '\0';
|
tup[i].value[vlen] = '\0';
|
||||||
}
|
}
|
||||||
/* get the appropriate bitmap */
|
/* get the appropriate bitmap */
|
||||||
@ -240,7 +240,7 @@ makePGresult(PGconn* conn, char* pname)
|
|||||||
|
|
||||||
PGresAttValue* newTup;
|
PGresAttValue* newTup;
|
||||||
|
|
||||||
FILE* Pfin = conn->Pfin;
|
FILE* pfin = conn->Pfin;
|
||||||
FILE* Pfdebug = conn->Pfdebug;
|
FILE* Pfdebug = conn->Pfdebug;
|
||||||
|
|
||||||
result = makeEmptyPGresult(conn, PGRES_TUPLES_OK);
|
result = makeEmptyPGresult(conn, PGRES_TUPLES_OK);
|
||||||
@ -249,7 +249,7 @@ makePGresult(PGconn* conn, char* pname)
|
|||||||
/* id of the stream is 'T' to start with */
|
/* id of the stream is 'T' to start with */
|
||||||
|
|
||||||
/* the next two bytes are the number of fields */
|
/* the next two bytes are the number of fields */
|
||||||
if (pqGetInt(&nfields, 2, Pfin, Pfdebug) == 1) {
|
if (pqGetInt(&nfields, 2, pfin, Pfdebug) == 1) {
|
||||||
sprintf(conn->errorMessage,
|
sprintf(conn->errorMessage,
|
||||||
"could not get the number of fields from the 'T' message\n");
|
"could not get the number of fields from the 'T' message\n");
|
||||||
goto makePGresult_badResponse_return;
|
goto makePGresult_badResponse_return;
|
||||||
@ -268,9 +268,9 @@ makePGresult(PGconn* conn, char* pname)
|
|||||||
int adtid;
|
int adtid;
|
||||||
int adtsize;
|
int adtsize;
|
||||||
|
|
||||||
if ( pqGets(typName, MAX_MESSAGE_LEN, Pfin, Pfdebug) ||
|
if ( pqGets(typName, MAX_MESSAGE_LEN, pfin, Pfdebug) ||
|
||||||
pqGetInt(&adtid, 4, Pfin, Pfdebug) ||
|
pqGetInt(&adtid, 4, pfin, Pfdebug) ||
|
||||||
pqGetInt(&adtsize, 2, Pfin, Pfdebug)) {
|
pqGetInt(&adtsize, 2, pfin, Pfdebug)) {
|
||||||
sprintf(conn->errorMessage,
|
sprintf(conn->errorMessage,
|
||||||
"error reading type information from the 'T' message\n");
|
"error reading type information from the 'T' message\n");
|
||||||
goto makePGresult_badResponse_return;
|
goto makePGresult_badResponse_return;
|
||||||
@ -281,7 +281,7 @@ makePGresult(PGconn* conn, char* pname)
|
|||||||
result->attDescs[i].adtsize = adtsize; /* casting from int to int2 here */
|
result->attDescs[i].adtsize = adtsize; /* casting from int to int2 here */
|
||||||
}
|
}
|
||||||
|
|
||||||
id = pqGetc(Pfin,Pfdebug);
|
id = pqGetc(pfin,Pfdebug);
|
||||||
|
|
||||||
/* process the data stream until we're finished */
|
/* process the data stream until we're finished */
|
||||||
while(!done) {
|
while(!done) {
|
||||||
@ -306,12 +306,12 @@ makePGresult(PGconn* conn, char* pname)
|
|||||||
case 'C': /* end of portal tuple stream */
|
case 'C': /* end of portal tuple stream */
|
||||||
{
|
{
|
||||||
char command[MAX_MESSAGE_LEN];
|
char command[MAX_MESSAGE_LEN];
|
||||||
pqGets(command,MAX_MESSAGE_LEN, Pfin, Pfdebug); /* read the command tag */
|
pqGets(command,MAX_MESSAGE_LEN, pfin, Pfdebug); /* read the command tag */
|
||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'E': /* errors */
|
case 'E': /* errors */
|
||||||
if (pqGets(conn->errorMessage, ERROR_MSG_LENGTH, Pfin, Pfdebug) == 1) {
|
if (pqGets(conn->errorMessage, ERROR_MSG_LENGTH, pfin, Pfdebug) == 1) {
|
||||||
sprintf(conn->errorMessage,
|
sprintf(conn->errorMessage,
|
||||||
"Error return detected from backend, but error message cannot be read");
|
"Error return detected from backend, but error message cannot be read");
|
||||||
}
|
}
|
||||||
@ -319,7 +319,7 @@ makePGresult(PGconn* conn, char* pname)
|
|||||||
return result;
|
return result;
|
||||||
break;
|
break;
|
||||||
case 'N': /* notices from the backend */
|
case 'N': /* notices from the backend */
|
||||||
if (pqGets(conn->errorMessage, ERROR_MSG_LENGTH, Pfin, Pfdebug) == 1) {
|
if (pqGets(conn->errorMessage, ERROR_MSG_LENGTH, pfin, Pfdebug) == 1) {
|
||||||
sprintf(conn->errorMessage,
|
sprintf(conn->errorMessage,
|
||||||
"Notice return detected from backend, but error message cannot be read");
|
"Notice return detected from backend, but error message cannot be read");
|
||||||
} else
|
} else
|
||||||
@ -336,7 +336,7 @@ makePGresult(PGconn* conn, char* pname)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!done)
|
if (!done)
|
||||||
id = getc(Pfin);
|
id = getc(pfin);
|
||||||
} /* while (1) */
|
} /* while (1) */
|
||||||
|
|
||||||
result->resultStatus = PGRES_TUPLES_OK;
|
result->resultStatus = PGRES_TUPLES_OK;
|
||||||
@ -362,7 +362,7 @@ makePGresult_badResponse_return:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
PGresult*
|
PGresult*
|
||||||
PQexec(PGconn* conn, char* query)
|
PQexec(PGconn* conn, const char* query)
|
||||||
{
|
{
|
||||||
PGresult *result;
|
PGresult *result;
|
||||||
int id, clear;
|
int id, clear;
|
||||||
@ -370,7 +370,7 @@ PQexec(PGconn* conn, char* query)
|
|||||||
char cmdStatus[MAX_MESSAGE_LEN];
|
char cmdStatus[MAX_MESSAGE_LEN];
|
||||||
char pname[MAX_MESSAGE_LEN]; /* portal name */
|
char pname[MAX_MESSAGE_LEN]; /* portal name */
|
||||||
PGnotify *newNotify;
|
PGnotify *newNotify;
|
||||||
FILE *Pfin, *Pfout, *Pfdebug;
|
FILE *pfin, *pfout, *Pfdebug;
|
||||||
|
|
||||||
pname[0]='\0';
|
pname[0]='\0';
|
||||||
|
|
||||||
@ -397,7 +397,7 @@ PQexec(PGconn* conn, char* query)
|
|||||||
sprintf(buffer,"Q%s",query);
|
sprintf(buffer,"Q%s",query);
|
||||||
|
|
||||||
/* send the query to the backend; */
|
/* send the query to the backend; */
|
||||||
if (pqPuts(buffer,Pfout, Pfdebug) == 1) {
|
if (pqPuts(buffer,pfout, Pfdebug) == 1) {
|
||||||
(void) sprintf(conn->errorMessage,
|
(void) sprintf(conn->errorMessage,
|
||||||
"PQexec() -- while sending query: %s\n-- fprintf to Pfout failed: errno=%d\n%s\n",
|
"PQexec() -- while sending query: %s\n-- fprintf to Pfout failed: errno=%d\n%s\n",
|
||||||
query, errno,strerror(errno));
|
query, errno,strerror(errno));
|
||||||
@ -412,7 +412,7 @@ PQexec(PGconn* conn, char* query)
|
|||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
/* read the result id */
|
/* read the result id */
|
||||||
id = pqGetc(Pfin,Pfdebug);
|
id = pqGetc(pfin,Pfdebug);
|
||||||
if (id == EOF) {
|
if (id == EOF) {
|
||||||
/* hmm, no response from the backend-end, that's bad */
|
/* hmm, no response from the backend-end, that's bad */
|
||||||
(void) sprintf(conn->errorMessage,
|
(void) sprintf(conn->errorMessage,
|
||||||
@ -423,14 +423,14 @@ PQexec(PGconn* conn, char* query)
|
|||||||
switch (id) {
|
switch (id) {
|
||||||
case 'A':
|
case 'A':
|
||||||
newNotify = (PGnotify*)malloc(sizeof(PGnotify));
|
newNotify = (PGnotify*)malloc(sizeof(PGnotify));
|
||||||
pqGetInt(&(newNotify->be_pid), 4, Pfin, Pfdebug);
|
pqGetInt(&(newNotify->be_pid), 4, pfin, Pfdebug);
|
||||||
pqGets(newNotify->relname, NAMEDATALEN, Pfin, Pfdebug);
|
pqGets(newNotify->relname, NAMEDATALEN, pfin, Pfdebug);
|
||||||
DLAddTail(conn->notifyList, DLNewElem(newNotify));
|
DLAddTail(conn->notifyList, DLNewElem(newNotify));
|
||||||
/* async messages are piggy'ed back on other messages,
|
/* async messages are piggy'ed back on other messages,
|
||||||
so we stay in the while loop for other messages */
|
so we stay in the while loop for other messages */
|
||||||
break;
|
break;
|
||||||
case 'C': /* portal query command, no tuples returned */
|
case 'C': /* portal query command, no tuples returned */
|
||||||
if (pqGets(cmdStatus, MAX_MESSAGE_LEN, Pfin, Pfdebug) == 1) {
|
if (pqGets(cmdStatus, MAX_MESSAGE_LEN, pfin, Pfdebug) == 1) {
|
||||||
sprintf(conn->errorMessage,
|
sprintf(conn->errorMessage,
|
||||||
"PQexec() -- query command completed, but return message from backend cannot be read");
|
"PQexec() -- query command completed, but return message from backend cannot be read");
|
||||||
return (PGresult*)NULL;
|
return (PGresult*)NULL;
|
||||||
@ -444,10 +444,10 @@ PQexec(PGconn* conn, char* query)
|
|||||||
*/
|
*/
|
||||||
clear = 0;
|
clear = 0;
|
||||||
|
|
||||||
pqPuts("Q ",Pfout,Pfdebug); /* send an empty query */
|
pqPuts("Q ",pfout,Pfdebug); /* send an empty query */
|
||||||
while (!clear)
|
while (!clear)
|
||||||
{
|
{
|
||||||
if (pqGets(buffer,ERROR_MSG_LENGTH,Pfin,Pfdebug) == 1)
|
if (pqGets(buffer,ERROR_MSG_LENGTH,pfin,Pfdebug) == 1)
|
||||||
clear = 1;
|
clear = 1;
|
||||||
clear = (buffer[0] == 'I');
|
clear = (buffer[0] == 'I');
|
||||||
}
|
}
|
||||||
@ -457,7 +457,7 @@ PQexec(PGconn* conn, char* query)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'E': /* error return */
|
case 'E': /* error return */
|
||||||
if (pqGets(conn->errorMessage, ERROR_MSG_LENGTH, Pfin, Pfdebug) == 1) {
|
if (pqGets(conn->errorMessage, ERROR_MSG_LENGTH, pfin, Pfdebug) == 1) {
|
||||||
(void) sprintf(conn->errorMessage,
|
(void) sprintf(conn->errorMessage,
|
||||||
"PQexec() -- error return detected from backend, but error message cannot be read");
|
"PQexec() -- error return detected from backend, but error message cannot be read");
|
||||||
}
|
}
|
||||||
@ -467,7 +467,7 @@ PQexec(PGconn* conn, char* query)
|
|||||||
/* read the throw away the closing '\0' */
|
/* read the throw away the closing '\0' */
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
if ((c = pqGetc(Pfin,Pfdebug)) != '\0') {
|
if ((c = pqGetc(pfin,Pfdebug)) != '\0') {
|
||||||
fprintf(stderr,"error!, unexpected character %c following 'I'\n", c);
|
fprintf(stderr,"error!, unexpected character %c following 'I'\n", c);
|
||||||
}
|
}
|
||||||
result = makeEmptyPGresult(conn, PGRES_EMPTY_QUERY);
|
result = makeEmptyPGresult(conn, PGRES_EMPTY_QUERY);
|
||||||
@ -475,7 +475,7 @@ PQexec(PGconn* conn, char* query)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'N': /* notices from the backend */
|
case 'N': /* notices from the backend */
|
||||||
if (pqGets(conn->errorMessage, ERROR_MSG_LENGTH, Pfin, Pfdebug) == 1) {
|
if (pqGets(conn->errorMessage, ERROR_MSG_LENGTH, pfin, Pfdebug) == 1) {
|
||||||
sprintf(conn->errorMessage,
|
sprintf(conn->errorMessage,
|
||||||
"PQexec() -- error return detected from backend, but error message cannot be read");
|
"PQexec() -- error return detected from backend, but error message cannot be read");
|
||||||
return (PGresult*)NULL;
|
return (PGresult*)NULL;
|
||||||
@ -484,7 +484,7 @@ PQexec(PGconn* conn, char* query)
|
|||||||
fprintf(stderr,"%s", conn->errorMessage);
|
fprintf(stderr,"%s", conn->errorMessage);
|
||||||
break;
|
break;
|
||||||
case 'P': /* synchronous (normal) portal */
|
case 'P': /* synchronous (normal) portal */
|
||||||
pqGets(pname,MAX_MESSAGE_LEN,Pfin, Pfdebug); /* read in the portal name*/
|
pqGets(pname,MAX_MESSAGE_LEN,pfin, Pfdebug); /* read in the portal name*/
|
||||||
break;
|
break;
|
||||||
case 'T': /* actual tuple results: */
|
case 'T': /* actual tuple results: */
|
||||||
return makePGresult(conn, pname);
|
return makePGresult(conn, pname);
|
||||||
@ -584,7 +584,7 @@ PQgetline(PGconn *conn, char *s, int maxlen)
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
PQputline(PGconn *conn, char *s)
|
PQputline(PGconn *conn, const char *s)
|
||||||
{
|
{
|
||||||
if (conn && (conn->Pfout)) {
|
if (conn && (conn->Pfout)) {
|
||||||
(void) fputs(s, conn->Pfout);
|
(void) fputs(s, conn->Pfout);
|
||||||
@ -605,21 +605,21 @@ int
|
|||||||
PQendcopy(PGconn *conn)
|
PQendcopy(PGconn *conn)
|
||||||
{
|
{
|
||||||
char id;
|
char id;
|
||||||
FILE *Pfin, *Pfdebug;
|
FILE *pfin, *Pfdebug;
|
||||||
|
|
||||||
if (!conn) return (int)NULL;
|
if (!conn) return (int)NULL;
|
||||||
|
|
||||||
Pfin = conn->Pfin;
|
Pfin = conn->Pfin;
|
||||||
Pfdebug = conn->Pfdebug;
|
Pfdebug = conn->Pfdebug;
|
||||||
|
|
||||||
if ( (id = pqGetc(Pfin,Pfdebug)) > 0)
|
if ( (id = pqGetc(pfin,Pfdebug)) > 0)
|
||||||
return(0);
|
return(0);
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case 'Z': /* backend finished the copy */
|
case 'Z': /* backend finished the copy */
|
||||||
return(1);
|
return(1);
|
||||||
case 'E':
|
case 'E':
|
||||||
case 'N':
|
case 'N':
|
||||||
if (pqGets(conn->errorMessage, ERROR_MSG_LENGTH, Pfin, Pfdebug) == 1) {
|
if (pqGets(conn->errorMessage, ERROR_MSG_LENGTH, pfin, Pfdebug) == 1) {
|
||||||
sprintf(conn->errorMessage,
|
sprintf(conn->errorMessage,
|
||||||
"Error return detected from backend, but error message cannot be read");
|
"Error return detected from backend, but error message cannot be read");
|
||||||
}
|
}
|
||||||
@ -661,7 +661,7 @@ void
|
|||||||
PQdisplayTuples(PGresult *res,
|
PQdisplayTuples(PGresult *res,
|
||||||
FILE *fp, /* where to send the output */
|
FILE *fp, /* where to send the output */
|
||||||
int fillAlign, /* pad the fields with spaces */
|
int fillAlign, /* pad the fields with spaces */
|
||||||
char *fieldSep, /* field separator */
|
const char *fieldSep, /* field separator */
|
||||||
int printHeader, /* display headers? */
|
int printHeader, /* display headers? */
|
||||||
int quiet
|
int quiet
|
||||||
)
|
)
|
||||||
@ -674,7 +674,7 @@ PQdisplayTuples(PGresult *res,
|
|||||||
int fLength[MAX_FIELDS];
|
int fLength[MAX_FIELDS];
|
||||||
|
|
||||||
if (fieldSep == NULL)
|
if (fieldSep == NULL)
|
||||||
fieldSep == DEFAULT_FIELD_SEP;
|
fieldSep = DEFAULT_FIELD_SEP;
|
||||||
|
|
||||||
/* Get some useful info about the results */
|
/* Get some useful info about the results */
|
||||||
nFields = PQnfields(res);
|
nFields = PQnfields(res);
|
||||||
@ -1197,7 +1197,7 @@ PQfn(PGconn *conn,
|
|||||||
PQArgBlock *args,
|
PQArgBlock *args,
|
||||||
int nargs)
|
int nargs)
|
||||||
{
|
{
|
||||||
FILE *Pfin, *Pfout, *Pfdebug;
|
FILE *pfin, *pfout, *Pfdebug;
|
||||||
int id;
|
int id;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -1210,24 +1210,24 @@ PQfn(PGconn *conn,
|
|||||||
/* clear the error string */
|
/* clear the error string */
|
||||||
conn->errorMessage[0] = '\0';
|
conn->errorMessage[0] = '\0';
|
||||||
|
|
||||||
pqPuts("F ",Pfout,Pfdebug); /* function */
|
pqPuts("F ",pfout,Pfdebug); /* function */
|
||||||
pqPutInt(fnid, 4, Pfout, Pfdebug); /* function id */
|
pqPutInt(fnid, 4, pfout, Pfdebug); /* function id */
|
||||||
pqPutInt(nargs, 4, Pfout, Pfdebug); /* # of args */
|
pqPutInt(nargs, 4, pfout, Pfdebug); /* # of args */
|
||||||
|
|
||||||
for (i = 0; i < nargs; ++i) { /* len.int4 + contents */
|
for (i = 0; i < nargs; ++i) { /* len.int4 + contents */
|
||||||
pqPutInt(args[i].len, 4, Pfout, Pfdebug);
|
pqPutInt(args[i].len, 4, pfout, Pfdebug);
|
||||||
if (args[i].isint) {
|
if (args[i].isint) {
|
||||||
pqPutInt(args[i].u.integer, 4, Pfout, Pfdebug);
|
pqPutInt(args[i].u.integer, 4, pfout, Pfdebug);
|
||||||
} else {
|
} else {
|
||||||
pqPutnchar((char *)args[i].u.ptr, args[i].len, Pfout, Pfdebug);
|
pqPutnchar((char *)args[i].u.ptr, args[i].len, pfout, Pfdebug);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pqFlush(Pfout, Pfdebug);
|
pqFlush(pfout, Pfdebug);
|
||||||
|
|
||||||
id = pqGetc(Pfin, Pfdebug);
|
id = pqGetc(pfin, Pfdebug);
|
||||||
if (id != 'V') {
|
if (id != 'V') {
|
||||||
if (id == 'E') {
|
if (id == 'E') {
|
||||||
pqGets(conn->errorMessage,ERROR_MSG_LENGTH,Pfin,Pfdebug);
|
pqGets(conn->errorMessage,ERROR_MSG_LENGTH,pfin,Pfdebug);
|
||||||
} else
|
} else
|
||||||
sprintf(conn->errorMessage,
|
sprintf(conn->errorMessage,
|
||||||
"PQfn: expected a 'V' from the backend. Got '%c' instead",
|
"PQfn: expected a 'V' from the backend. Got '%c' instead",
|
||||||
@ -1235,19 +1235,19 @@ PQfn(PGconn *conn,
|
|||||||
return makeEmptyPGresult(conn,PGRES_FATAL_ERROR);
|
return makeEmptyPGresult(conn,PGRES_FATAL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
id = pqGetc(Pfin, Pfdebug);
|
id = pqGetc(pfin, Pfdebug);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int c;
|
int c;
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case 'G': /* function returned properly */
|
case 'G': /* function returned properly */
|
||||||
pqGetInt(actual_result_len,4,Pfin,Pfdebug);
|
pqGetInt(actual_result_len,4,pfin,Pfdebug);
|
||||||
if (result_is_int) {
|
if (result_is_int) {
|
||||||
pqGetInt(result_buf,4,Pfin,Pfdebug);
|
pqGetInt(result_buf,4,pfin,Pfdebug);
|
||||||
} else {
|
} else {
|
||||||
pqGetnchar((char *) result_buf, *actual_result_len,
|
pqGetnchar((char *) result_buf, *actual_result_len,
|
||||||
Pfin, Pfdebug);
|
pfin, Pfdebug);
|
||||||
}
|
}
|
||||||
c = pqGetc(Pfin, Pfdebug); /* get the last '0'*/
|
c = pqGetc(pfin, Pfdebug); /* get the last '0'*/
|
||||||
return makeEmptyPGresult(conn,PGRES_COMMAND_OK);
|
return makeEmptyPGresult(conn,PGRES_COMMAND_OK);
|
||||||
case 'E':
|
case 'E':
|
||||||
sprintf(conn->errorMessage,
|
sprintf(conn->errorMessage,
|
||||||
@ -1255,7 +1255,7 @@ PQfn(PGconn *conn,
|
|||||||
return makeEmptyPGresult(conn,PGRES_FATAL_ERROR);
|
return makeEmptyPGresult(conn,PGRES_FATAL_ERROR);
|
||||||
case 'N':
|
case 'N':
|
||||||
/* print notice and go back to processing return values */
|
/* print notice and go back to processing return values */
|
||||||
if (pqGets(conn->errorMessage, ERROR_MSG_LENGTH, Pfin, Pfdebug) == 1) {
|
if (pqGets(conn->errorMessage, ERROR_MSG_LENGTH, pfin, Pfdebug) == 1) {
|
||||||
sprintf(conn->errorMessage,
|
sprintf(conn->errorMessage,
|
||||||
"Notice return detected from backend, but error message cannot be read");
|
"Notice return detected from backend, but error message cannot be read");
|
||||||
} else
|
} else
|
||||||
@ -1333,7 +1333,7 @@ PQfname(PGresult *res, int field_num)
|
|||||||
returns -1 on a bad field name
|
returns -1 on a bad field name
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
PQfnumber(PGresult *res, char* field_name)
|
PQfnumber(PGresult *res, const char* field_name)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -1406,7 +1406,7 @@ char* PQcmdStatus(PGresult *res) {
|
|||||||
if the last command was an INSERT, return the oid string
|
if the last command was an INSERT, return the oid string
|
||||||
if not, return ""
|
if not, return ""
|
||||||
*/
|
*/
|
||||||
char* PQoidStatus(PGresult *res) {
|
const char* PQoidStatus(PGresult *res) {
|
||||||
if (!res) {
|
if (!res) {
|
||||||
fprintf(stderr, "PQoidStatus() -- pointer to PQresult is null");
|
fprintf(stderr, "PQoidStatus() -- pointer to PQresult is null");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -11,13 +11,14 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.1.1.1 1996/07/09 06:22:17 scrappy Exp $
|
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.2 1996/08/06 16:16:48 scrappy Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "libpq-fe.h"
|
||||||
|
|
||||||
/* pqGetc:
|
/* pqGetc:
|
||||||
get a character from stream f
|
get a character from stream f
|
||||||
@ -41,7 +42,7 @@ pqGetc(FILE* fin, FILE* debug)
|
|||||||
returns 1 if there was an error, 0 otherwise.
|
returns 1 if there was an error, 0 otherwise.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
pqPutnchar(char* s, int len, FILE *f, FILE *debug)
|
pqPutnchar(const char* s, int len, FILE *f, FILE *debug)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
@ -165,7 +166,7 @@ pqGetInt(int* result, int bytes, FILE* f, FILE *debug)
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
pqPuts(char* s, FILE *f, FILE *debug)
|
pqPuts(const char* s, FILE *f, FILE *debug)
|
||||||
{
|
{
|
||||||
if (f == NULL)
|
if (f == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 1994, Regents of the University of California
|
* Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: libpq-fe.h,v 1.5 1996/07/31 18:40:12 scrappy Exp $
|
* $Id: libpq-fe.h,v 1.6 1996/08/06 16:16:50 scrappy Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -45,7 +45,7 @@ typedef enum {
|
|||||||
} ExecStatusType;
|
} ExecStatusType;
|
||||||
|
|
||||||
/* string descriptions of the ExecStatusTypes */
|
/* string descriptions of the ExecStatusTypes */
|
||||||
extern char* pgresStatus[];
|
extern const char* pgresStatus[];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* POSTGRES backend dependent Constants.
|
* POSTGRES backend dependent Constants.
|
||||||
@ -144,8 +144,8 @@ typedef struct _PQprintOpt PQprintOpt;
|
|||||||
|
|
||||||
/* === in fe-connect.c === */
|
/* === in fe-connect.c === */
|
||||||
/* make a new client connection to the backend */
|
/* make a new client connection to the backend */
|
||||||
extern PGconn* PQsetdb(char* pghost, char* pgport, char* pgoptions,
|
extern PGconn* PQsetdb(const char* pghost, const char* pgport, const char* pgoptions,
|
||||||
char* pgtty, char* dbName);
|
const char* pgtty, const char* dbName);
|
||||||
/* close the current connection and free the PGconn data structure */
|
/* close the current connection and free the PGconn data structure */
|
||||||
extern void PQfinish(PGconn* conn);
|
extern void PQfinish(PGconn* conn);
|
||||||
/* close the current connection and restablish a new one with the same
|
/* close the current connection and restablish a new one with the same
|
||||||
@ -163,19 +163,19 @@ extern void PQtrace(PGconn *conn, FILE* debug_port);
|
|||||||
extern void PQuntrace(PGconn *conn);
|
extern void PQuntrace(PGconn *conn);
|
||||||
|
|
||||||
/* === in fe-exec.c === */
|
/* === in fe-exec.c === */
|
||||||
extern PGresult* PQexec(PGconn* conn, char* query);
|
extern PGresult* PQexec(PGconn* conn, const char* query);
|
||||||
extern int PQgetline(PGconn *conn, char* string, int length);
|
extern int PQgetline(PGconn *conn, char* string, int length);
|
||||||
extern int PQendcopy(PGconn *conn);
|
extern int PQendcopy(PGconn *conn);
|
||||||
extern void PQputline(PGconn *conn, char* string);
|
extern void PQputline(PGconn *conn, const char* string);
|
||||||
extern ExecStatusType PQresultStatus(PGresult* res);
|
extern ExecStatusType PQresultStatus(PGresult* res);
|
||||||
extern int PQntuples(PGresult *res);
|
extern int PQntuples(PGresult *res);
|
||||||
extern int PQnfields(PGresult *res);
|
extern int PQnfields(PGresult *res);
|
||||||
extern char* PQfname(PGresult *res, int field_num);
|
extern char* PQfname(PGresult *res, int field_num);
|
||||||
extern int PQfnumber(PGresult *res, char* field_name);
|
extern int PQfnumber(PGresult *res, const char* field_name);
|
||||||
extern Oid PQftype(PGresult *res, int field_num);
|
extern Oid PQftype(PGresult *res, int field_num);
|
||||||
extern int2 PQfsize(PGresult *res, int field_num);
|
extern int2 PQfsize(PGresult *res, int field_num);
|
||||||
extern char* PQcmdStatus(PGresult *res);
|
extern char* PQcmdStatus(PGresult *res);
|
||||||
extern char* PQoidStatus(PGresult *res);
|
extern const char* PQoidStatus(PGresult *res);
|
||||||
extern char* PQgetvalue(PGresult *res, int tup_num, int field_num);
|
extern char* PQgetvalue(PGresult *res, int tup_num, int field_num);
|
||||||
extern int PQgetlength(PGresult *res, int tup_num, int field_num);
|
extern int PQgetlength(PGresult *res, int tup_num, int field_num);
|
||||||
extern void PQclear(PGresult* res);
|
extern void PQclear(PGresult* res);
|
||||||
@ -183,7 +183,7 @@ extern void PQclear(PGresult* res);
|
|||||||
extern void PQdisplayTuples(PGresult *res,
|
extern void PQdisplayTuples(PGresult *res,
|
||||||
FILE *fp, /* where to send the output */
|
FILE *fp, /* where to send the output */
|
||||||
int fillAlign, /* pad the fields with spaces */
|
int fillAlign, /* pad the fields with spaces */
|
||||||
char *fieldSep, /* field separator */
|
const char *fieldSep, /* field separator */
|
||||||
int printHeader, /* display headers? */
|
int printHeader, /* display headers? */
|
||||||
int quiet);
|
int quiet);
|
||||||
extern void PQprintTuples(PGresult* res,
|
extern void PQprintTuples(PGresult* res,
|
||||||
@ -207,7 +207,7 @@ extern PGresult* PQfn(PGconn* conn,
|
|||||||
int nargs);
|
int nargs);
|
||||||
/* === in fe-auth.c === */
|
/* === in fe-auth.c === */
|
||||||
extern MsgType fe_getauthsvc(char* PQerrormsg);
|
extern MsgType fe_getauthsvc(char* PQerrormsg);
|
||||||
extern void fe_setauthsvc(char *name, char* PQerrormsg);
|
extern void fe_setauthsvc(const char *name, char* PQerrormsg);
|
||||||
extern char *fe_getauthname(char* PQerrormsg);
|
extern char *fe_getauthname(char* PQerrormsg);
|
||||||
|
|
||||||
/* === in fe-misc.c === */
|
/* === in fe-misc.c === */
|
||||||
@ -217,8 +217,8 @@ extern char *fe_getauthname(char* PQerrormsg);
|
|||||||
*/
|
*/
|
||||||
extern int pqGets(char* s, int maxlen, FILE* stream, FILE* debug);
|
extern int pqGets(char* s, int maxlen, FILE* stream, FILE* debug);
|
||||||
extern int pqGetnchar(char* s, int maxlen, FILE* stream, FILE* debug);
|
extern int pqGetnchar(char* s, int maxlen, FILE* stream, FILE* debug);
|
||||||
extern int pqPutnchar(char* s, int maxlen, FILE* stream, FILE* debug);
|
extern int pqPutnchar(const char* s, int maxlen, FILE* stream, FILE* debug);
|
||||||
extern int pqPuts(char* s, FILE* stream, FILE* debug );
|
extern int pqPuts(const char* s, FILE* stream, FILE* debug );
|
||||||
extern int pqGetc(FILE* stream, FILE *debug);
|
extern int pqGetc(FILE* stream, FILE *debug);
|
||||||
/* get a n-byte integer from the stream into result */
|
/* get a n-byte integer from the stream into result */
|
||||||
/* returns 0 if successful */
|
/* returns 0 if successful */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user