22 *
33 * Copyright (c) 2000, Christof Petig <christof.petig@wtal.de>
44 *
5- * $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/dynamic.c,v 1.3 2000/02/18 14:34:05 meskes Exp $
5+ * $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/dynamic.c,v 1.4 2000/02/18 16:02:49 meskes Exp $
66 */
77
88/* I borrowed the include files from ecpglib.c, maybe we don't need all of them */
99
1010#include <sql3types.h>
1111
1212static struct descriptor
13- { char * name ;
13+ {
14+ char * name ;
1415 PGresult * result ;
1516 struct descriptor * next ;
1617} * all_descriptors = NULL ;
1718
1819PGconn * ECPG_internal_get_connection (char * name );
1920
2021unsigned int ECPGDynamicType (Oid type )
21- { switch (type )
22+ {
23+ switch (type )
2224 { case 16 : return SQL3_BOOLEAN ; /* bool */
2325 case 21 : return SQL3_SMALLINT ; /* int2 */
2426 case 23 : return SQL3_INTEGER ; /* int4 */
@@ -204,7 +206,7 @@ bool ECPGdo_descriptor(int line,const char *connection,
204206 return (status );
205207 }
206208 }
207- ECPGraise (line ,ECPG_UNKNOWN_DESCRIPTOR );
209+ ECPGraise (line , ECPG_UNKNOWN_DESCRIPTOR , NULL );
208210 return false;
209211}
210212
@@ -217,7 +219,7 @@ PGresult *ECPGresultByDescriptor(int line,const char *name)
217219 if (!strcmp (name , i -> name )) return i -> result ;
218220 }
219221
220- ECPGraise (line ,ECPG_UNKNOWN_DESCRIPTOR );
222+ ECPGraise (line , ECPG_UNKNOWN_DESCRIPTOR , NULL );
221223
222224 return NULL ;
223225}
@@ -236,7 +238,7 @@ bool ECPGdeallocate_desc(int line,const char *name)
236238 return true;
237239 }
238240 }
239- ECPGraise (line ,ECPG_UNKNOWN_DESCRIPTOR );
241+ ECPGraise (line , ECPG_UNKNOWN_DESCRIPTOR , NULL );
240242 return false;
241243}
242244
@@ -252,30 +254,69 @@ bool ECPGallocate_desc(int line,const char *name)
252254 return true;
253255}
254256
255- void ECPGraise (int line , int code )
257+ void
258+ ECPGraise (int line , int code , const char * str )
256259{
260+ struct auto_mem * am ;
261+
257262 sqlca .sqlcode = code ;
258263 switch (code )
259264 {
260265 case ECPG_NOT_FOUND :
261266 snprintf (sqlca .sqlerrm .sqlerrmc ,sizeof (sqlca .sqlerrm .sqlerrmc ),
262- "No data found line %d." ,line );
267+ "No data found line %d." , line );
268+ break ;
269+
270+ case ECPG_OUT_OF_MEMORY :
271+ snprintf (sqlca .sqlerrm .sqlerrmc ,sizeof (sqlca .sqlerrm .sqlerrmc ),
272+ "Out of memory in line %d." , line );
263273 break ;
274+
275+ case ECPG_UNSUPPORTED :
276+ snprintf (sqlca .sqlerrm .sqlerrmc ,sizeof (sqlca .sqlerrm .sqlerrmc ),
277+ "Unsupported type %s in line %d." , str , line );
278+ break ;
279+
280+ case ECPG_TOO_MANY_ARGUMENTS :
281+ snprintf (sqlca .sqlerrm .sqlerrmc ,sizeof (sqlca .sqlerrm .sqlerrmc ),
282+ "Too many arguments in line %d." , line );
283+ break ;
284+
285+ case ECPG_TOO_FEW_ARGUMENTS :
286+ snprintf (sqlca .sqlerrm .sqlerrmc ,sizeof (sqlca .sqlerrm .sqlerrmc ),
287+ "Too few arguments in line %d." , line );
288+ break ;
289+
264290 case ECPG_MISSING_INDICATOR :
265291 snprintf (sqlca .sqlerrm .sqlerrmc ,sizeof (sqlca .sqlerrm .sqlerrmc ),
266- "NULL value without indicator, line %d." ,line );
292+ "NULL value without indicator, line %d." , line );
267293 break ;
294+
268295 case ECPG_UNKNOWN_DESCRIPTOR :
269296 snprintf (sqlca .sqlerrm .sqlerrmc ,sizeof (sqlca .sqlerrm .sqlerrmc ),
270- "descriptor not found, line %d." ,line );
297+ "descriptor not found, line %d." , line );
271298 break ;
299+
272300 case ECPG_INVALID_DESCRIPTOR_INDEX :
273301 snprintf (sqlca .sqlerrm .sqlerrmc ,sizeof (sqlca .sqlerrm .sqlerrmc ),
274- "descriptor index out of range, line %d." ,line );
302+ "descriptor index out of range, line %d." , line );
275303 break ;
304+
276305 default :
277306 snprintf (sqlca .sqlerrm .sqlerrmc ,sizeof (sqlca .sqlerrm .sqlerrmc ),
278- "SQL error #%d, line %d." ,code ,line );
307+ "SQL error #%d, line %d." ,code , line );
279308 break ;
280309 }
310+
311+ /* free all memory we have allocated for the user */
312+ for (am = auto_allocs ; am ;)
313+ {
314+ struct auto_mem * act = am ;
315+
316+ am = am -> next ;
317+ free (act -> pointer );
318+ free (act );
319+ }
320+
321+ auto_allocs = NULL ;
281322}
0 commit comments