7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.57 1999/07/17 20:16:57 momjian Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.58 1999/07/19 00:26:15 tgl Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -86,31 +86,44 @@ ExecEvalArrayRef(ArrayRef *arrayRef,
86
86
bool * isNull ,
87
87
bool * isDone )
88
88
{
89
- bool dummy ;
90
- int i = 0 ,
91
- j = 0 ;
92
89
ArrayType * array_scanner ;
93
- List * upperIndexpr ,
94
- * lowerIndexpr ;
95
- Node * assgnexpr ;
96
90
List * elt ;
91
+ int i = 0 ,
92
+ j = 0 ;
97
93
IntArray upper ,
98
94
lower ;
99
95
int * lIndex ;
100
- char * dataPtr ;
96
+ bool dummy ;
101
97
102
98
* isNull = false;
103
- array_scanner = (ArrayType * ) ExecEvalExpr (arrayRef -> refexpr ,
104
- econtext ,
105
- isNull ,
106
- isDone );
107
- if (* isNull )
108
- return (Datum ) NULL ;
109
99
110
- upperIndexpr = arrayRef -> refupperindexpr ;
100
+ if (arrayRef -> refexpr != NULL )
101
+ {
102
+ array_scanner = (ArrayType * ) ExecEvalExpr (arrayRef -> refexpr ,
103
+ econtext ,
104
+ isNull ,
105
+ isDone );
106
+ if (* isNull )
107
+ return (Datum ) NULL ;
108
+ }
109
+ else
110
+ {
111
+ /* Null refexpr indicates we are doing an INSERT into an array column.
112
+ * For now, we just take the refassgnexpr (which the parser will have
113
+ * ensured is an array value) and return it as-is, ignoring any
114
+ * subscripts that may have been supplied in the INSERT column list.
115
+ * This is a kluge, but it's not real clear what the semantics ought
116
+ * to be...
117
+ */
118
+ array_scanner = NULL ;
119
+ }
111
120
112
- foreach (elt , upperIndexpr )
121
+ foreach (elt , arrayRef -> refupperindexpr )
113
122
{
123
+ if (i >= MAXDIM )
124
+ elog (ERROR , "ExecEvalArrayRef: can only handle %d dimensions" ,
125
+ MAXDIM );
126
+
114
127
upper .indx [i ++ ] = (int32 ) ExecEvalExpr ((Node * ) lfirst (elt ),
115
128
econtext ,
116
129
isNull ,
@@ -119,12 +132,14 @@ ExecEvalArrayRef(ArrayRef *arrayRef,
119
132
return (Datum ) NULL ;
120
133
}
121
134
122
- lowerIndexpr = arrayRef -> reflowerindexpr ;
123
- lIndex = NULL ;
124
- if (lowerIndexpr != NIL )
135
+ if (arrayRef -> reflowerindexpr != NIL )
125
136
{
126
- foreach (elt , lowerIndexpr )
137
+ foreach (elt , arrayRef -> reflowerindexpr )
127
138
{
139
+ if (j >= MAXDIM )
140
+ elog (ERROR , "ExecEvalArrayRef: can only handle %d dimensions" ,
141
+ MAXDIM );
142
+
128
143
lower .indx [j ++ ] = (int32 ) ExecEvalExpr ((Node * ) lfirst (elt ),
129
144
econtext ,
130
145
isNull ,
@@ -137,30 +152,42 @@ ExecEvalArrayRef(ArrayRef *arrayRef,
137
152
"ExecEvalArrayRef: upper and lower indices mismatch" );
138
153
lIndex = lower .indx ;
139
154
}
155
+ else
156
+ {
157
+ lIndex = NULL ;
158
+ }
140
159
141
- assgnexpr = arrayRef -> refassgnexpr ;
142
- if (assgnexpr != NULL )
160
+ if (arrayRef -> refassgnexpr != NULL )
143
161
{
144
- dataPtr = (char * ) ExecEvalExpr ((Node * )
145
- assgnexpr , econtext ,
146
- isNull , & dummy );
162
+ Datum sourceData = ExecEvalExpr (arrayRef -> refassgnexpr ,
163
+ econtext ,
164
+ isNull ,
165
+ & dummy );
147
166
if (* isNull )
148
167
return (Datum ) NULL ;
168
+
149
169
execConstByVal = arrayRef -> refelembyval ;
150
170
execConstLen = arrayRef -> refelemlength ;
171
+
172
+ if (array_scanner == NULL )
173
+ return sourceData ; /* XXX do something else? */
174
+
151
175
if (lIndex == NULL )
152
- return (Datum ) array_set (array_scanner , i , upper .indx , dataPtr ,
176
+ return (Datum ) array_set (array_scanner , i , upper .indx ,
177
+ (char * ) sourceData ,
153
178
arrayRef -> refelembyval ,
154
179
arrayRef -> refelemlength ,
155
180
arrayRef -> refattrlength , isNull );
156
181
return (Datum ) array_assgn (array_scanner , i , upper .indx ,
157
182
lower .indx ,
158
- (ArrayType * ) dataPtr ,
183
+ (ArrayType * ) sourceData ,
159
184
arrayRef -> refelembyval ,
160
185
arrayRef -> refelemlength , isNull );
161
186
}
187
+
162
188
execConstByVal = arrayRef -> refelembyval ;
163
189
execConstLen = arrayRef -> refelemlength ;
190
+
164
191
if (lIndex == NULL )
165
192
return (Datum ) array_ref (array_scanner , i , upper .indx ,
166
193
arrayRef -> refelembyval ,
0 commit comments