@ -7,7 +7,7 @@
*
*
* 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
/* keep this in same order as ExecStatusType in pgtclCmds.h */
char * pgresStatus [ ] = {
const char * pgresStatus [ ] = {
" PGRES_EMPTY_QUERY " ,
" PGRES_COMMAND_OK " ,
" PGRES_TUPLES_OK " ,
@ -130,7 +130,7 @@ getTuple(PGconn *conn, PGresult* result, int binary)
char bmap ; /* One byte of the bitmap */
int bitcnt = 0 ; /* number of bits examined in current byte */
int vlen ; /* length of the current field value */
FILE * P fin = conn - > Pfin ;
FILE * p fin = conn - > Pfin ;
FILE * Pfdebug = conn - > Pfdebug ;
PGresAttValue * tup ;
@ -145,7 +145,7 @@ getTuple(PGconn *conn, PGresult* result, int binary)
if ( ( nfields % BYTELEN ) > 0 )
nbytes + + ;
if ( pqGetnchar ( bitmap , nbytes , P fin, Pfdebug ) = = 1 ) {
if ( pqGetnchar ( bitmap , nbytes , p fin, Pfdebug ) = = 1 ) {
sprintf ( conn - > errorMessage ,
" Error reading null-values bitmap from tuple data stream \n " ) ;
return NULL ;
@ -164,7 +164,7 @@ getTuple(PGconn *conn, PGresult* result, int binary)
}
else {
/* get the value length (the first four bytes are for length) */
pqGetInt ( & vlen , VARHDRSZ , P fin, Pfdebug ) ;
pqGetInt ( & vlen , VARHDRSZ , p fin, Pfdebug ) ;
if ( binary = = 0 ) {
vlen = vlen - VARHDRSZ ;
}
@ -174,7 +174,7 @@ getTuple(PGconn *conn, PGresult* result, int binary)
tup [ i ] . value = ( char * ) malloc ( vlen + 1 ) ;
/* read in the value; */
if ( vlen > 0 )
pqGetnchar ( ( char * ) ( tup [ i ] . value ) , vlen , P fin, Pfdebug ) ;
pqGetnchar ( ( char * ) ( tup [ i ] . value ) , vlen , p fin, Pfdebug ) ;
tup [ i ] . value [ vlen ] = ' \0 ' ;
}
/* get the appropriate bitmap */
@ -240,7 +240,7 @@ makePGresult(PGconn* conn, char* pname)
PGresAttValue * newTup ;
FILE * P fin = conn - > Pfin ;
FILE * p fin = conn - > Pfin ;
FILE * Pfdebug = conn - > Pfdebug ;
result = makeEmptyPGresult ( conn , PGRES_TUPLES_OK ) ;
@ -249,7 +249,7 @@ makePGresult(PGconn* conn, char* pname)
/* id of the stream is 'T' to start with */
/* the next two bytes are the number of fields */
if ( pqGetInt ( & nfields , 2 , P fin, Pfdebug ) = = 1 ) {
if ( pqGetInt ( & nfields , 2 , p fin, Pfdebug ) = = 1 ) {
sprintf ( conn - > errorMessage ,
" could not get the number of fields from the 'T' message \n " ) ;
goto makePGresult_badResponse_return ;
@ -268,9 +268,9 @@ makePGresult(PGconn* conn, char* pname)
int adtid ;
int adtsize ;
if ( pqGets ( typName , MAX_MESSAGE_LEN , P fin, Pfdebug ) | |
pqGetInt ( & adtid , 4 , P fin, Pfdebug ) | |
pqGetInt ( & adtsize , 2 , P fin, Pfdebug ) ) {
if ( pqGets ( typName , MAX_MESSAGE_LEN , p fin, Pfdebug ) | |
pqGetInt ( & adtid , 4 , p fin, Pfdebug ) | |
pqGetInt ( & adtsize , 2 , p fin, Pfdebug ) ) {
sprintf ( conn - > errorMessage ,
" error reading type information from the 'T' message \n " ) ;
goto makePGresult_badResponse_return ;
@ -281,7 +281,7 @@ makePGresult(PGconn* conn, char* pname)
result - > attDescs [ i ] . adtsize = adtsize ; /* casting from int to int2 here */
}
id = pqGetc ( P fin, Pfdebug ) ;
id = pqGetc ( p fin, Pfdebug ) ;
/* process the data stream until we're finished */
while ( ! done ) {
@ -306,12 +306,12 @@ makePGresult(PGconn* conn, char* pname)
case ' C ' : /* end of portal tuple stream */
{
char command [ MAX_MESSAGE_LEN ] ;
pqGets ( command , MAX_MESSAGE_LEN , P fin, Pfdebug ) ; /* read the command tag */
pqGets ( command , MAX_MESSAGE_LEN , p fin, Pfdebug ) ; /* read the command tag */
done = 1 ;
}
break ;
case ' E ' : /* errors */
if ( pqGets ( conn - > errorMessage , ERROR_MSG_LENGTH , P fin, Pfdebug ) = = 1 ) {
if ( pqGets ( conn - > errorMessage , ERROR_MSG_LENGTH , p fin, Pfdebug ) = = 1 ) {
sprintf ( conn - > errorMessage ,
" Error return detected from backend, but error message cannot be read " ) ;
}
@ -319,7 +319,7 @@ makePGresult(PGconn* conn, char* pname)
return result ;
break ;
case ' N ' : /* notices from the backend */
if ( pqGets ( conn - > errorMessage , ERROR_MSG_LENGTH , P fin, Pfdebug ) = = 1 ) {
if ( pqGets ( conn - > errorMessage , ERROR_MSG_LENGTH , p fin, Pfdebug ) = = 1 ) {
sprintf ( conn - > errorMessage ,
" Notice return detected from backend, but error message cannot be read " ) ;
} else
@ -336,7 +336,7 @@ makePGresult(PGconn* conn, char* pname)
break ;
}
if ( ! done )
id = getc ( P fin) ;
id = getc ( p fin) ;
} /* while (1) */
result - > resultStatus = PGRES_TUPLES_OK ;
@ -362,7 +362,7 @@ makePGresult_badResponse_return:
*/
PGresult *
PQexec ( PGconn * conn , char * query )
PQexec ( PGconn * conn , const char * query )
{
PGresult * result ;
int id , clear ;
@ -370,7 +370,7 @@ PQexec(PGconn* conn, char* query)
char cmdStatus [ MAX_MESSAGE_LEN ] ;
char pname [ MAX_MESSAGE_LEN ] ; /* portal name */
PGnotify * newNotify ;
FILE * Pfin , * P fout, * Pfdebug ;
FILE * pfin , * p fout, * Pfdebug ;
pname [ 0 ] = ' \0 ' ;
@ -397,7 +397,7 @@ PQexec(PGconn* conn, char* query)
sprintf ( buffer , " Q%s " , query ) ;
/* send the query to the backend; */
if ( pqPuts ( buffer , P fout, Pfdebug ) = = 1 ) {
if ( pqPuts ( buffer , p fout, Pfdebug ) = = 1 ) {
( void ) sprintf ( conn - > errorMessage ,
" PQexec() -- while sending query: %s \n -- fprintf to Pfout failed: errno=%d \n %s \n " ,
query , errno , strerror ( errno ) ) ;
@ -412,7 +412,7 @@ PQexec(PGconn* conn, char* query)
while ( 1 ) {
/* read the result id */
id = pqGetc ( P fin, Pfdebug ) ;
id = pqGetc ( p fin, Pfdebug ) ;
if ( id = = EOF ) {
/* hmm, no response from the backend-end, that's bad */
( void ) sprintf ( conn - > errorMessage ,
@ -423,14 +423,14 @@ PQexec(PGconn* conn, char* query)
switch ( id ) {
case ' A ' :
newNotify = ( PGnotify * ) malloc ( sizeof ( PGnotify ) ) ;
pqGetInt ( & ( newNotify - > be_pid ) , 4 , P fin, Pfdebug ) ;
pqGets ( newNotify - > relname , NAMEDATALEN , P fin, Pfdebug ) ;
pqGetInt ( & ( newNotify - > be_pid ) , 4 , p fin, Pfdebug ) ;
pqGets ( newNotify - > relname , NAMEDATALEN , p fin, Pfdebug ) ;
DLAddTail ( conn - > notifyList , DLNewElem ( newNotify ) ) ;
/* async messages are piggy'ed back on other messages,
so we stay in the while loop for other messages */
break ;
case ' C ' : /* portal query command, no tuples returned */
if ( pqGets ( cmdStatus , MAX_MESSAGE_LEN , P fin, Pfdebug ) = = 1 ) {
if ( pqGets ( cmdStatus , MAX_MESSAGE_LEN , p fin, Pfdebug ) = = 1 ) {
sprintf ( conn - > errorMessage ,
" PQexec() -- query command completed, but return message from backend cannot be read " ) ;
return ( PGresult * ) NULL ;
@ -444,10 +444,10 @@ PQexec(PGconn* conn, char* query)
*/
clear = 0 ;
pqPuts ( " Q " , P fout, Pfdebug ) ; /* send an empty query */
pqPuts ( " Q " , p fout, Pfdebug ) ; /* send an empty query */
while ( ! clear )
{
if ( pqGets ( buffer , ERROR_MSG_LENGTH , P fin, Pfdebug ) = = 1 )
if ( pqGets ( buffer , ERROR_MSG_LENGTH , p fin, Pfdebug ) = = 1 )
clear = 1 ;
clear = ( buffer [ 0 ] = = ' I ' ) ;
}
@ -457,7 +457,7 @@ PQexec(PGconn* conn, char* query)
}
break ;
case ' E ' : /* error return */
if ( pqGets ( conn - > errorMessage , ERROR_MSG_LENGTH , P fin, Pfdebug ) = = 1 ) {
if ( pqGets ( conn - > errorMessage , ERROR_MSG_LENGTH , p fin, Pfdebug ) = = 1 ) {
( void ) sprintf ( conn - > errorMessage ,
" 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' */
{
int c ;
if ( ( c = pqGetc ( P fin, Pfdebug ) ) ! = ' \0 ' ) {
if ( ( c = pqGetc ( p fin, Pfdebug ) ) ! = ' \0 ' ) {
fprintf ( stderr , " error!, unexpected character %c following 'I' \n " , c ) ;
}
result = makeEmptyPGresult ( conn , PGRES_EMPTY_QUERY ) ;
@ -475,7 +475,7 @@ PQexec(PGconn* conn, char* query)
}
break ;
case ' N ' : /* notices from the backend */
if ( pqGets ( conn - > errorMessage , ERROR_MSG_LENGTH , P fin, Pfdebug ) = = 1 ) {
if ( pqGets ( conn - > errorMessage , ERROR_MSG_LENGTH , p fin, Pfdebug ) = = 1 ) {
sprintf ( conn - > errorMessage ,
" PQexec() -- error return detected from backend, but error message cannot be read " ) ;
return ( PGresult * ) NULL ;
@ -484,7 +484,7 @@ PQexec(PGconn* conn, char* query)
fprintf ( stderr , " %s " , conn - > errorMessage ) ;
break ;
case ' P ' : /* synchronous (normal) portal */
pqGets ( pname , MAX_MESSAGE_LEN , P fin, Pfdebug ) ; /* read in the portal name*/
pqGets ( pname , MAX_MESSAGE_LEN , p fin, Pfdebug ) ; /* read in the portal name*/
break ;
case ' T ' : /* actual tuple results: */
return makePGresult ( conn , pname ) ;
@ -584,7 +584,7 @@ PQgetline(PGconn *conn, char *s, int maxlen)
*
*/
void
PQputline ( PGconn * conn , char * s )
PQputline ( PGconn * conn , const char * s )
{
if ( conn & & ( conn - > Pfout ) ) {
( void ) fputs ( s , conn - > Pfout ) ;
@ -605,21 +605,21 @@ int
PQendcopy ( PGconn * conn )
{
char id ;
FILE * P fin, * Pfdebug ;
FILE * p fin, * Pfdebug ;
if ( ! conn ) return ( int ) NULL ;
Pfin = conn - > Pfin ;
Pfdebug = conn - > Pfdebug ;
if ( ( id = pqGetc ( P fin, Pfdebug ) ) > 0 )
if ( ( id = pqGetc ( p fin, Pfdebug ) ) > 0 )
return ( 0 ) ;
switch ( id ) {
case ' Z ' : /* backend finished the copy */
return ( 1 ) ;
case ' E ' :
case ' N ' :
if ( pqGets ( conn - > errorMessage , ERROR_MSG_LENGTH , P fin, Pfdebug ) = = 1 ) {
if ( pqGets ( conn - > errorMessage , ERROR_MSG_LENGTH , p fin, Pfdebug ) = = 1 ) {
sprintf ( conn - > errorMessage ,
" Error return detected from backend, but error message cannot be read " ) ;
}
@ -661,7 +661,7 @@ void
PQdisplayTuples ( PGresult * res ,
FILE * fp , /* where to send the output */
int fillAlign , /* pad the fields with spaces */
char * fieldSep , /* field separator */
const char * fieldSep , /* field separator */
int printHeader , /* display headers? */
int quiet
)
@ -674,7 +674,7 @@ PQdisplayTuples(PGresult *res,
int fLength [ MAX_FIELDS ] ;
if ( fieldSep = = NULL )
fieldSep = = DEFAULT_FIELD_SEP ;
fieldSep = DEFAULT_FIELD_SEP ;
/* Get some useful info about the results */
nFields = PQnfields ( res ) ;
@ -1197,7 +1197,7 @@ PQfn(PGconn *conn,
PQArgBlock * args ,
int nargs )
{
FILE * Pfin , * P fout, * Pfdebug ;
FILE * pfin , * p fout, * Pfdebug ;
int id ;
int i ;
@ -1210,24 +1210,24 @@ PQfn(PGconn *conn,
/* clear the error string */
conn - > errorMessage [ 0 ] = ' \0 ' ;
pqPuts ( " F " , P fout, Pfdebug ) ; /* function */
pqPutInt ( fnid , 4 , P fout, Pfdebug ) ; /* function id */
pqPutInt ( nargs , 4 , P fout, Pfdebug ) ; /* # of args */
pqPuts ( " F " , p fout, Pfdebug ) ; /* function */
pqPutInt ( fnid , 4 , p fout, Pfdebug ) ; /* function id */
pqPutInt ( nargs , 4 , p fout, Pfdebug ) ; /* # of args */
for ( i = 0 ; i < nargs ; + + i ) { /* len.int4 + contents */
pqPutInt ( args [ i ] . len , 4 , P fout, Pfdebug ) ;
pqPutInt ( args [ i ] . len , 4 , p fout, Pfdebug ) ;
if ( args [ i ] . isint ) {
pqPutInt ( args [ i ] . u . integer , 4 , P fout, Pfdebug ) ;
pqPutInt ( args [ i ] . u . integer , 4 , p fout, Pfdebug ) ;
} else {
pqPutnchar ( ( char * ) args [ i ] . u . ptr , args [ i ] . len , P fout, Pfdebug ) ;
pqPutnchar ( ( char * ) args [ i ] . u . ptr , args [ i ] . len , p fout, Pfdebug ) ;
}
}
pqFlush ( P fout, Pfdebug ) ;
pqFlush ( p fout, Pfdebug ) ;
id = pqGetc ( P fin, Pfdebug ) ;
id = pqGetc ( p fin, Pfdebug ) ;
if ( id ! = ' V ' ) {
if ( id = = ' E ' ) {
pqGets ( conn - > errorMessage , ERROR_MSG_LENGTH , P fin, Pfdebug ) ;
pqGets ( conn - > errorMessage , ERROR_MSG_LENGTH , p fin, Pfdebug ) ;
} else
sprintf ( conn - > errorMessage ,
" PQfn: expected a 'V' from the backend. Got '%c' instead " ,
@ -1235,19 +1235,19 @@ PQfn(PGconn *conn,
return makeEmptyPGresult ( conn , PGRES_FATAL_ERROR ) ;
}
id = pqGetc ( P fin, Pfdebug ) ;
id = pqGetc ( p fin, Pfdebug ) ;
for ( ; ; ) {
int c ;
switch ( id ) {
case ' G ' : /* function returned properly */
pqGetInt ( actual_result_len , 4 , P fin, Pfdebug ) ;
pqGetInt ( actual_result_len , 4 , p fin, Pfdebug ) ;
if ( result_is_int ) {
pqGetInt ( result_buf , 4 , P fin, Pfdebug ) ;
pqGetInt ( result_buf , 4 , p fin, Pfdebug ) ;
} else {
pqGetnchar ( ( char * ) result_buf , * actual_result_len ,
P fin, Pfdebug ) ;
p fin, Pfdebug ) ;
}
c = pqGetc ( P fin, Pfdebug ) ; /* get the last '0'*/
c = pqGetc ( p fin, Pfdebug ) ; /* get the last '0'*/
return makeEmptyPGresult ( conn , PGRES_COMMAND_OK ) ;
case ' E ' :
sprintf ( conn - > errorMessage ,
@ -1255,7 +1255,7 @@ PQfn(PGconn *conn,
return makeEmptyPGresult ( conn , PGRES_FATAL_ERROR ) ;
case ' N ' :
/* print notice and go back to processing return values */
if ( pqGets ( conn - > errorMessage , ERROR_MSG_LENGTH , P fin, Pfdebug ) = = 1 ) {
if ( pqGets ( conn - > errorMessage , ERROR_MSG_LENGTH , p fin, Pfdebug ) = = 1 ) {
sprintf ( conn - > errorMessage ,
" Notice return detected from backend, but error message cannot be read " ) ;
} else
@ -1333,7 +1333,7 @@ PQfname(PGresult *res, int field_num)
returns - 1 on a bad field name
*/
int
PQfnumber ( PGresult * res , char * field_name )
PQfnumber ( PGresult * res , const char * field_name )
{
int i ;
@ -1406,7 +1406,7 @@ char* PQcmdStatus(PGresult *res) {
if the last command was an INSERT , return the oid string
if not , return " "
*/
char * PQoidStatus ( PGresult * res ) {
const char * PQoidStatus ( PGresult * res ) {
if ( ! res ) {
fprintf ( stderr , " PQoidStatus() -- pointer to PQresult is null " ) ;
return NULL ;