|
7 | 7 | * |
8 | 8 | * |
9 | 9 | * IDENTIFICATION |
10 | | - * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.14 1999/02/13 23:19:26 momjian Exp $ |
| 10 | + * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.15 1999/03/15 03:24:32 tgl Exp $ |
11 | 11 | * |
12 | 12 | *------------------------------------------------------------------------- |
13 | 13 | */ |
@@ -36,59 +36,66 @@ static intmy_varattno(Relation rd, char *a); |
36 | 36 | * ---------------------------------------------------------------- |
37 | 37 | */ |
38 | 38 | bool |
39 | | -int4notin(int16not_in_arg,char*relation_and_attr) |
| 39 | +int4notin(int32not_in_arg,char*relation_and_attr) |
40 | 40 | { |
41 | 41 | Relationrelation_to_scan; |
42 | | -intleft_side_argument, |
43 | | -integer_value; |
| 42 | +int32integer_value; |
44 | 43 | HeapTuplecurrent_tuple; |
45 | 44 | HeapScanDescscan_descriptor; |
46 | 45 | booldummy, |
47 | 46 | retval; |
48 | 47 | intattrid; |
49 | 48 | char*relation, |
50 | 49 | *attribute; |
51 | | -charmy_copy[32]; |
| 50 | +charmy_copy[NAMEDATALEN*2+2]; |
52 | 51 | Datumvalue; |
53 | | -NameDatarelNameData; |
54 | | -ScanKeyDataskeyData; |
55 | 52 |
|
56 | | -strcpy(my_copy,relation_and_attr); |
| 53 | +strncpy(my_copy,relation_and_attr,sizeof(my_copy)); |
| 54 | +my_copy[sizeof(my_copy)-1]='\0'; |
57 | 55 |
|
58 | 56 | relation= (char*)strtok(my_copy,"."); |
59 | 57 | attribute= (char*)strtok(NULL,"."); |
| 58 | +if (attribute==NULL) |
| 59 | +{ |
| 60 | +elog(ERROR,"int4notin: must provide relationname.attributename"); |
| 61 | +} |
60 | 62 |
|
| 63 | +/* Open the relation and get a relation descriptor */ |
61 | 64 |
|
62 | | -/* fetch tuple OID */ |
63 | | - |
64 | | -left_side_argument=not_in_arg; |
| 65 | +relation_to_scan=heap_openr(relation); |
| 66 | +if (!RelationIsValid(relation_to_scan)) |
| 67 | +{ |
| 68 | +elog(ERROR,"int4notin: unknown relation %s", |
| 69 | +relation); |
| 70 | +} |
65 | 71 |
|
66 | | -/*Open therelation and get a relation descriptor */ |
| 72 | +/*Find thecolumn to search */ |
67 | 73 |
|
68 | | -namestrcpy(&relNameData,relation); |
69 | | -relation_to_scan=heap_openr(relNameData.data); |
70 | 74 | attrid=my_varattno(relation_to_scan,attribute); |
| 75 | +if (attrid<0) |
| 76 | +{ |
| 77 | +elog(ERROR,"int4notin: unknown attribute %s for relation %s", |
| 78 | +attribute,relation); |
| 79 | +} |
71 | 80 |
|
72 | | -/* the last argument should be a ScanKey, not an integer! - jolly */ |
73 | | -/* it looks like the arguments are out of order, too */ |
74 | | -/* but skeyData is never initialized! does this work?? - ay 2/95 */ |
75 | 81 | scan_descriptor=heap_beginscan(relation_to_scan, false,SnapshotNow, |
76 | | -0,&skeyData); |
| 82 | +0,(ScanKey)NULL); |
77 | 83 |
|
78 | 84 | retval= true; |
79 | 85 |
|
80 | 86 | /* do a scan of the relation, and do the check */ |
81 | | -while (HeapTupleIsValid(current_tuple=heap_getnext(scan_descriptor,0))&& |
82 | | -retval) |
| 87 | +while (HeapTupleIsValid(current_tuple=heap_getnext(scan_descriptor,0))) |
83 | 88 | { |
84 | 89 | value=heap_getattr(current_tuple, |
85 | 90 | (AttrNumber)attrid, |
86 | 91 | RelationGetDescr(relation_to_scan), |
87 | 92 | &dummy); |
88 | | - |
89 | | -integer_value=DatumGetInt16(value); |
90 | | -if (left_side_argument==integer_value) |
| 93 | +integer_value=DatumGetInt32(value); |
| 94 | +if (not_in_arg==integer_value) |
| 95 | +{ |
91 | 96 | retval= false; |
| 97 | +break;/* can stop scanning now */ |
| 98 | +} |
92 | 99 | } |
93 | 100 |
|
94 | 101 | /* close the relation */ |
|