7
7
*
8
8
*
9
9
* 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 $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -358,12 +358,20 @@ PQexec(PGconn* conn, char* query)
358
358
char cmdStatus [MAX_MESSAGE_LEN ];
359
359
char pname [MAX_MESSAGE_LEN ]; /* portal name */
360
360
PGnotify * newNotify ;
361
- FILE * Pfin = conn -> Pfin ;
362
- FILE * Pfout = conn -> Pfout ;
363
- FILE * Pfdebug = conn -> Pfdebug ;
361
+ FILE * Pfin , * Pfout , * Pfdebug ;
364
362
365
363
pname [0 ]= '\0' ;
366
364
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
+
367
375
/*clear the error string */
368
376
conn -> errorMessage [0 ] = '\0' ;
369
377
@@ -500,6 +508,9 @@ PGnotify*
500
508
PQnotifies (PGconn * conn )
501
509
{
502
510
Dlelem * e ;
511
+
512
+ if (!conn ) return NULL ;
513
+
503
514
if (conn -> status != CONNECTION_OK )
504
515
return NULL ;
505
516
/* RemHead returns NULL if list is empy */
531
542
PQgetline (PGconn * conn , char * s , int maxlen )
532
543
{
533
544
int c = '\0' ;
545
+
546
+ if (!conn ) return EOF ;
534
547
535
548
if (!conn -> Pfin || !s || maxlen <= 1 )
536
549
return (EOF );
@@ -561,7 +574,7 @@ PQgetline(PGconn *conn, char *s, int maxlen)
561
574
void
562
575
PQputline (PGconn * conn , char * s )
563
576
{
564
- if (conn -> Pfout ) {
577
+ if (conn && ( conn -> Pfout ) ) {
565
578
(void ) fputs (s , conn -> Pfout );
566
579
fflush (conn -> Pfout );
567
580
}
580
593
PQendcopy (PGconn * conn )
581
594
{
582
595
char 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 ;
585
602
586
603
if ( (id = pqGetc (Pfin ,Pfdebug )) > 0 )
587
604
return (0 );
@@ -836,12 +853,16 @@ PQfn(PGconn *conn,
836
853
PQArgBlock * args ,
837
854
int nargs )
838
855
{
839
- FILE * Pfin = conn -> Pfin ;
840
- FILE * Pfout = conn -> Pfout ;
841
- FILE * Pfdebug = conn -> Pfdebug ;
856
+ FILE * Pfin , * Pfout , * Pfdebug ;
842
857
int id ;
843
858
int i ;
844
859
860
+ if (!conn ) return NULL ;
861
+
862
+ Pfin = conn -> Pfin ;
863
+ Pfout = conn -> Pfout ;
864
+ Pfdebug = conn -> Pfdebug ;
865
+
845
866
/* clear the error string */
846
867
conn -> errorMessage [0 ] = '\0' ;
847
868
@@ -916,18 +937,33 @@ PQfn(PGconn *conn,
916
937
ExecStatusType
917
938
PQresultStatus (PGresult * res )
918
939
{
940
+ if (!res ) {
941
+ fprintf (stderr , "PQresultStatus() -- pointer to PQresult is null" );
942
+ return PGRES_NONFATAL_ERROR ;
943
+ }
944
+
919
945
return res -> resultStatus ;
920
946
}
921
947
922
948
int
923
949
PQntuples (PGresult * res )
924
950
{
951
+ if (!res ) {
952
+ fprintf (stderr , "PQntuples() -- pointer to PQresult is null" );
953
+ return (int )NULL ;
954
+ }
955
+
925
956
return res -> ntups ;
926
957
}
927
958
928
959
int
929
960
PQnfields (PGresult * res )
930
961
{
962
+ if (!res ) {
963
+ fprintf (stderr , "PQnfields() -- pointer to PQresult is null" );
964
+ return (int )NULL ;
965
+ }
966
+
931
967
return res -> numAttributes ;
932
968
}
933
969
@@ -937,6 +973,12 @@ PQnfields(PGresult *res)
937
973
char *
938
974
PQfname (PGresult * res , int field_num )
939
975
{
976
+
977
+ if (!res ) {
978
+ fprintf (stderr , "PQfname() -- pointer to PQresult is null" );
979
+ return NULL ;
980
+ }
981
+
940
982
if (field_num > (res -> numAttributes - 1 )) {
941
983
fprintf (stderr ,
942
984
"PQfname: ERROR! name of field %d(of %d) is not available" ,
@@ -957,6 +999,11 @@ PQfnumber(PGresult *res, char* field_name)
957
999
{
958
1000
int i ;
959
1001
1002
+ if (!res ) {
1003
+ fprintf (stderr , "PQfnumber() -- pointer to PQresult is null" );
1004
+ return -1 ;
1005
+ }
1006
+
960
1007
if (field_name == NULL ||
961
1008
field_name [0 ] == '\0' ||
962
1009
res -> attDescs == NULL )
@@ -973,6 +1020,11 @@ PQfnumber(PGresult *res, char* field_name)
973
1020
Oid
974
1021
PQftype (PGresult * res , int field_num )
975
1022
{
1023
+ if (!res ) {
1024
+ fprintf (stderr , "PQftype() -- pointer to PQresult is null" );
1025
+ return InvalidOid ;
1026
+ }
1027
+
976
1028
if (field_num > (res -> numAttributes - 1 )) {
977
1029
fprintf (stderr ,
978
1030
"PQftype: ERROR! type of field %d(of %d) is not available" ,
@@ -987,6 +1039,11 @@ PQftype(PGresult *res, int field_num)
987
1039
int2
988
1040
PQfsize (PGresult * res , int field_num )
989
1041
{
1042
+ if (!res ) {
1043
+ fprintf (stderr , "PQfsize() -- pointer to PQresult is null" );
1044
+ return (int2 )NULL ;
1045
+ }
1046
+
990
1047
if (field_num > (res -> numAttributes - 1 )) {
991
1048
fprintf (stderr ,
992
1049
"PQfsize: ERROR! size of field %d(of %d) is not available" ,
@@ -999,6 +1056,11 @@ PQfsize(PGresult *res, int field_num)
999
1056
}
1000
1057
1001
1058
char * PQcmdStatus (PGresult * res ) {
1059
+ if (!res ) {
1060
+ fprintf (stderr , "PQcmdStatus() -- pointer to PQresult is null" );
1061
+ return NULL ;
1062
+ }
1063
+
1002
1064
return res -> cmdStatus ;
1003
1065
}
1004
1066
@@ -1008,6 +1070,11 @@ char* PQcmdStatus(PGresult *res) {
1008
1070
if not, return ""
1009
1071
*/
1010
1072
char * PQoidStatus (PGresult * res ) {
1073
+ if (!res ) {
1074
+ fprintf (stderr , "PQoidStatus() -- pointer to PQresult is null" );
1075
+ return NULL ;
1076
+ }
1077
+
1011
1078
if (!res -> cmdStatus )
1012
1079
return "" ;
1013
1080
@@ -1031,6 +1098,11 @@ char* PQoidStatus(PGresult *res) {
1031
1098
char *
1032
1099
PQgetvalue (PGresult * res , int tup_num , int field_num )
1033
1100
{
1101
+ if (!res ) {
1102
+ fprintf (stderr , "PQgetvalue() -- pointer to PQresult is null" );
1103
+ return NULL ;
1104
+ }
1105
+
1034
1106
if (tup_num > (res -> ntups - 1 ) ||
1035
1107
field_num > (res -> numAttributes - 1 )) {
1036
1108
fprintf (stderr ,
@@ -1050,6 +1122,11 @@ PQgetvalue(PGresult *res, int tup_num, int field_num)
1050
1122
int
1051
1123
PQgetlength (PGresult * res , int tup_num , int field_num )
1052
1124
{
1125
+ if (!res ) {
1126
+ fprintf (stderr , "PQgetlength() -- pointer to PQresult is null" );
1127
+ return (int )NULL ;
1128
+ }
1129
+
1053
1130
if (tup_num > (res -> ntups - 1 )||
1054
1131
field_num > (res -> numAttributes - 1 )) {
1055
1132
fprintf (stderr ,
0 commit comments