@@ -179,71 +179,89 @@ static void parseParameters(Function self, Oid* dfltIds, const char* paramDecl)
179179 char c ;
180180 int idx = 0 ;
181181 int top = self -> func .nonudt .numParams ;
182- bool lastIsOut = !self -> func .nonudt .isMultiCall && Type_isOutParameter (self -> func .nonudt .returnType );
182+ bool lastIsOut = !self -> func .nonudt .isMultiCall
183+ && Type_isOutParameter (self -> func .nonudt .returnType );
183184 StringInfoData sign ;
184- initStringInfo (& sign );
185- for (;;)
185+ Type deflt ;
186+ const char * jtName ;
187+ bool gotone = false;
188+ for ( ; ; ++ paramDecl )
186189 {
187- if (idx >= top )
188- {
189- if (!(lastIsOut && idx == top ))
190- ereport (ERROR , (
191- errcode (ERRCODE_SYNTAX_ERROR ),
192- errmsg ("To many parameters - expected %d " , top )));
193- }
190+ c = * paramDecl ;
191+ /* all whitespace has already been stripped by getAS() */
194192
195- c = * paramDecl ++ ;
196- if (c == 0 || c == ',' )
193+ if ( '\0' != c && ',' != c )
197194 {
198- Type deflt = (idx == top ) ? self -> func .nonudt .returnType : self -> func .nonudt .paramTypes [idx ];
199- const char * jtName = Type_getJavaTypeName (deflt );
200- if (strcmp (jtName , sign .data ) != 0 )
195+ if ( ! gotone ) /* first character of a param type has been seen. */
201196 {
202- Oid did ;
203- Type repl ;
204- if (idx == top )
205- /*
206- * Last parameter is the OUT parameter. It has no corresponding
207- * entry in the dfltIds array.
208- */
209- did = InvalidOid ;
210- else
211- did = dfltIds [idx ];
212-
213- repl = Type_fromJavaType (did , sign .data );
214- if (!Type_canReplaceType (repl , deflt ))
215- repl = Type_getCoerceIn (repl , deflt );
216-
217- if (idx == top )
218- self -> func .nonudt .returnType = repl ;
219- else
220- self -> func .nonudt .paramTypes [idx ] = repl ;
197+ if (idx >= top )
198+ {
199+ if (!(lastIsOut && idx == top ))
200+ ereport (ERROR , (
201+ errcode (ERRCODE_SYNTAX_ERROR ),
202+ errmsg ("AS (Java): expected %d parameter types, "
203+ "found more" , top )));
204+ }
205+ gotone = true;
206+ initStringInfo (& sign );
221207 }
222- pfree (sign .data );
208+ appendStringInfoChar (& sign , c );
209+ continue ;
210+ }
223211
224- ++ idx ;
225- if (c == 0 )
226- {
212+ if ( ! gotone )
213+ {
214+ if ( '\0' == c )
215+ break ;
216+ ereport (ERROR , (
217+ errcode (ERRCODE_SYNTAX_ERROR ),
218+ errmsg ("AS (Java): expected parameter type, found comma" )));
219+ }
220+
221+ /* so, got one. */
222+ deflt = (idx == top )
223+ ? self -> func .nonudt .returnType : self -> func .nonudt .paramTypes [idx ];
224+ jtName = Type_getJavaTypeName (deflt );
225+ if ( strcmp (jtName , sign .data ) != 0 )
226+ {
227+ Oid did ;
228+ Type repl ;
229+ if (idx == top )
227230 /*
228- * We are done.
231+ * Last parameter is the OUT parameter. It has no corresponding
232+ * entry in the dfltIds array.
229233 */
230- if (lastIsOut )
231- ++ top ;
232- if (idx != top )
233- ereport (ERROR , (
234- errcode (ERRCODE_SYNTAX_ERROR ),
235- errmsg ("To few parameters - expected %d " , top )));
236- break ;
237- }
234+ did = InvalidOid ;
235+ else
236+ did = dfltIds [idx ];
238237
239- /*
240- * Initialize next parameter.
241- */
242- initStringInfo (& sign );
238+ repl = Type_fromJavaType (did , sign .data );
239+ if (!Type_canReplaceType (repl , deflt ))
240+ repl = Type_getCoerceIn (repl , deflt );
241+
242+ if (idx == top )
243+ self -> func .nonudt .returnType = repl ;
244+ else
245+ self -> func .nonudt .paramTypes [idx ] = repl ;
243246 }
244- else
245- appendStringInfoChar (& sign , c );
247+ pfree (sign .data );
248+
249+ ++ idx ;
250+ if ( '\0' == c )
251+ break ;
252+ gotone = false;
246253 }
254+
255+ /*
256+ * We are done.
257+ */
258+ if (lastIsOut )
259+ ++ top ;
260+ if (idx != top )
261+ ereport (ERROR , (
262+ errcode (ERRCODE_SYNTAX_ERROR ),
263+ errmsg ("AS (Java): expected %d parameter types, found fewer" ,
264+ top )));
247265}
248266
249267static char * getAS (HeapTuple procTup , char * * epHolder )
0 commit comments