77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.1.1.1 1996/07/09 06:22:17 scrappy Exp $
10+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.2 1996/07/12 04:53:59 scrappy Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -358,12 +358,20 @@ PQexec(PGconn* conn, char* query)
358358char cmdStatus [MAX_MESSAGE_LEN ];
359359char pname [MAX_MESSAGE_LEN ];/* portal name */
360360PGnotify * newNotify ;
361- FILE * Pfin = conn -> Pfin ;
362- FILE * Pfout = conn -> Pfout ;
363- FILE * Pfdebug = conn -> Pfdebug ;
361+ FILE * Pfin ,* Pfout ,* Pfdebug ;
364362
365363pname [0 ]= '\0' ;
366364
365+ if (!conn )return NULL ;
366+ if (!query ) {
367+ sprintf (conn -> errorMessage ,"PQexec() -- query pointer is null." );
368+ return NULL ;
369+ }
370+
371+ Pfin = conn -> Pfin ;
372+ Pfout = conn -> Pfout ;
373+ Pfdebug = conn -> Pfdebug ;
374+
367375/*clear the error string */
368376conn -> errorMessage [0 ]= '\0' ;
369377
@@ -500,6 +508,9 @@ PGnotify*
500508PQnotifies (PGconn * conn )
501509{
502510Dlelem * e ;
511+
512+ if (!conn )return NULL ;
513+
503514if (conn -> status != CONNECTION_OK )
504515return NULL ;
505516/* RemHead returns NULL if list is empy */
531542PQgetline (PGconn * conn ,char * s ,int maxlen )
532543{
533544int c = '\0' ;
545+
546+ if (!conn )return EOF ;
534547
535548if (!conn -> Pfin || !s || maxlen <=1 )
536549return (EOF );
@@ -561,7 +574,7 @@ PQgetline(PGconn *conn, char *s, int maxlen)
561574void
562575PQputline (PGconn * conn ,char * s )
563576{
564- if (conn -> Pfout ) {
577+ if (conn && ( conn -> Pfout ) ) {
565578(void )fputs (s ,conn -> Pfout );
566579fflush (conn -> Pfout );
567580 }
580593PQendcopy (PGconn * conn )
581594{
582595char id ;
583- FILE * Pfin = conn -> Pfin ;
584- FILE * Pfdebug = conn -> Pfdebug ;
596+ FILE * Pfin ,* Pfdebug ;
597+
598+ if (!conn )return (int )NULL ;
599+
600+ Pfin = conn -> Pfin ;
601+ Pfdebug = conn -> Pfdebug ;
585602
586603if ( (id = pqGetc (Pfin ,Pfdebug ))> 0 )
587604return (0 );
@@ -836,12 +853,16 @@ PQfn(PGconn *conn,
836853PQArgBlock * args ,
837854int nargs )
838855{
839- FILE * Pfin = conn -> Pfin ;
840- FILE * Pfout = conn -> Pfout ;
841- FILE * Pfdebug = conn -> Pfdebug ;
856+ FILE * Pfin ,* Pfout ,* Pfdebug ;
842857int id ;
843858int i ;
844859
860+ if (!conn )return NULL ;
861+
862+ Pfin = conn -> Pfin ;
863+ Pfout = conn -> Pfout ;
864+ Pfdebug = conn -> Pfdebug ;
865+
845866/* clear the error string */
846867conn -> errorMessage [0 ]= '\0' ;
847868
@@ -916,18 +937,33 @@ PQfn(PGconn *conn,
916937ExecStatusType
917938PQresultStatus (PGresult * res )
918939{
940+ if (!res ) {
941+ fprintf (stderr ,"PQresultStatus() -- pointer to PQresult is null" );
942+ return PGRES_NONFATAL_ERROR ;
943+ }
944+
919945return res -> resultStatus ;
920946}
921947
922948int
923949PQntuples (PGresult * res )
924950{
951+ if (!res ) {
952+ fprintf (stderr ,"PQntuples() -- pointer to PQresult is null" );
953+ return (int )NULL ;
954+ }
955+
925956return res -> ntups ;
926957}
927958
928959int
929960PQnfields (PGresult * res )
930961{
962+ if (!res ) {
963+ fprintf (stderr ,"PQnfields() -- pointer to PQresult is null" );
964+ return (int )NULL ;
965+ }
966+
931967return res -> numAttributes ;
932968}
933969
@@ -937,6 +973,12 @@ PQnfields(PGresult *res)
937973char *
938974PQfname (PGresult * res ,int field_num )
939975{
976+
977+ if (!res ) {
978+ fprintf (stderr ,"PQfname() -- pointer to PQresult is null" );
979+ return NULL ;
980+ }
981+
940982if (field_num > (res -> numAttributes - 1 )) {
941983fprintf (stderr ,
942984"PQfname: ERROR! name of field %d(of %d) is not available" ,
@@ -957,6 +999,11 @@ PQfnumber(PGresult *res, char* field_name)
957999{
9581000int i ;
9591001
1002+ if (!res ) {
1003+ fprintf (stderr ,"PQfnumber() -- pointer to PQresult is null" );
1004+ return -1 ;
1005+ }
1006+
9601007if (field_name == NULL ||
9611008field_name [0 ]== '\0' ||
9621009res -> attDescs == NULL )
@@ -973,6 +1020,11 @@ PQfnumber(PGresult *res, char* field_name)
9731020Oid
9741021PQftype (PGresult * res ,int field_num )
9751022{
1023+ if (!res ) {
1024+ fprintf (stderr ,"PQftype() -- pointer to PQresult is null" );
1025+ return InvalidOid ;
1026+ }
1027+
9761028if (field_num > (res -> numAttributes - 1 )) {
9771029fprintf (stderr ,
9781030"PQftype: ERROR! type of field %d(of %d) is not available" ,
@@ -987,6 +1039,11 @@ PQftype(PGresult *res, int field_num)
9871039int2
9881040PQfsize (PGresult * res ,int field_num )
9891041{
1042+ if (!res ) {
1043+ fprintf (stderr ,"PQfsize() -- pointer to PQresult is null" );
1044+ return (int2 )NULL ;
1045+ }
1046+
9901047if (field_num > (res -> numAttributes - 1 )) {
9911048fprintf (stderr ,
9921049"PQfsize: ERROR! size of field %d(of %d) is not available" ,
@@ -999,6 +1056,11 @@ PQfsize(PGresult *res, int field_num)
9991056}
10001057
10011058char * PQcmdStatus (PGresult * res ) {
1059+ if (!res ) {
1060+ fprintf (stderr ,"PQcmdStatus() -- pointer to PQresult is null" );
1061+ return NULL ;
1062+ }
1063+
10021064return res -> cmdStatus ;
10031065}
10041066
@@ -1008,6 +1070,11 @@ char* PQcmdStatus(PGresult *res) {
10081070 if not, return ""
10091071*/
10101072char * PQoidStatus (PGresult * res ) {
1073+ if (!res ) {
1074+ fprintf (stderr ,"PQoidStatus() -- pointer to PQresult is null" );
1075+ return NULL ;
1076+ }
1077+
10111078if (!res -> cmdStatus )
10121079return "" ;
10131080
@@ -1031,6 +1098,11 @@ char* PQoidStatus(PGresult *res) {
10311098char *
10321099PQgetvalue (PGresult * res ,int tup_num ,int field_num )
10331100{
1101+ if (!res ) {
1102+ fprintf (stderr ,"PQgetvalue() -- pointer to PQresult is null" );
1103+ return NULL ;
1104+ }
1105+
10341106if (tup_num > (res -> ntups - 1 )||
10351107field_num > (res -> numAttributes - 1 )) {
10361108fprintf (stderr ,
@@ -1050,6 +1122,11 @@ PQgetvalue(PGresult *res, int tup_num, int field_num)
10501122int
10511123PQgetlength (PGresult * res ,int tup_num ,int field_num )
10521124{
1125+ if (!res ) {
1126+ fprintf (stderr ,"PQgetlength() -- pointer to PQresult is null" );
1127+ return (int )NULL ;
1128+ }
1129+
10531130if (tup_num > (res -> ntups - 1 )||
10541131field_num > (res -> numAttributes - 1 )) {
10551132fprintf (stderr ,