1
- /* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.27 2003/11/08 19:46:27 meskes Exp $ */
1
+ /* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.28 2003/11/10 20:28:30 meskes Exp $ */
2
2
3
3
/*
4
4
* The aim is to get a simpler inteface to the database routines.
@@ -230,12 +230,25 @@ next_insert(char *text)
230
230
return (* ptr == '\0' ) ?NULL :ptr ;
231
231
}
232
232
233
+ static void
234
+ ECPGtypeinfocache_push (struct ECPGtype_information_cache * * cache ,int oid ,bool isarray ,int lineno )
235
+ {
236
+ struct ECPGtype_information_cache * new_entry
237
+ = (struct ECPGtype_information_cache * )ECPGalloc (sizeof (struct ECPGtype_information_cache ),lineno );
238
+
239
+ new_entry -> oid = oid ;
240
+ new_entry -> isarray = isarray ;
241
+ new_entry -> next = * cache ;
242
+ * cache = new_entry ;
243
+ }
244
+
233
245
static enum ARRAY_TYPE
234
246
ECPGis_type_an_array (int type ,const struct statement * stmt ,const struct variable * var )
235
247
{
236
248
char * array_query ;
237
249
enum ARRAY_TYPE isarray = ECPG_ARRAY_NOT_SET ;
238
250
PGresult * query ;
251
+ struct ECPGtype_information_cache * cache_entry ;
239
252
240
253
if ((stmt -> connection -> cache_head )== NULL )
241
254
{
@@ -245,117 +258,76 @@ ECPGis_type_an_array(int type, const struct statement * stmt, const struct varia
245
258
* these values.
246
259
*/
247
260
#define not_an_array_in_ecpg ECPG_ARRAY_NONE
248
-
249
- switch (type )
250
- {
251
- case BOOLOID :isarray = ECPG_ARRAY_NONE ;
252
- break ;
253
- case BYTEAOID :isarray = ECPG_ARRAY_NONE ;
254
- break ;
255
- case CHAROID :isarray = ECPG_ARRAY_NONE ;
256
- break ;
257
- case NAMEOID :isarray = not_an_array_in_ecpg ;
258
- break ;
259
- case INT8OID :isarray = ECPG_ARRAY_NONE ;
260
- break ;
261
- case INT2OID :isarray = ECPG_ARRAY_NONE ;
262
- break ;
263
- case INT2VECTOROID :isarray = ECPG_ARRAY_VECTOR ;
264
- break ;
265
- case INT4OID :isarray = ECPG_ARRAY_NONE ;
266
- break ;
267
- case REGPROCOID :isarray = ECPG_ARRAY_NONE ;
268
- break ;
269
- case TEXTOID :isarray = ECPG_ARRAY_NONE ;
270
- break ;
271
- case OIDOID :isarray = ECPG_ARRAY_NONE ;
272
- break ;
273
- case TIDOID :isarray = ECPG_ARRAY_NONE ;
274
- break ;
275
- case XIDOID :isarray = ECPG_ARRAY_NONE ;
276
- break ;
277
- case CIDOID :isarray = ECPG_ARRAY_NONE ;
278
- break ;
279
- case OIDVECTOROID :isarray = ECPG_ARRAY_VECTOR ;
280
- break ;
281
- case POINTOID :isarray = ECPG_ARRAY_VECTOR ;
282
- break ;
283
- case LSEGOID :isarray = ECPG_ARRAY_VECTOR ;
284
- break ;
285
- case PATHOID :isarray = ECPG_ARRAY_NONE ;
286
- break ;
287
- case BOXOID :isarray = ECPG_ARRAY_VECTOR ;
288
- break ;
289
- case POLYGONOID :isarray = ECPG_ARRAY_NONE ;
290
- break ;
291
- case LINEOID :isarray = ECPG_ARRAY_VECTOR ;
292
- break ;
293
- case FLOAT4OID :isarray = ECPG_ARRAY_NONE ;
294
- break ;
295
- case FLOAT8OID :isarray = ECPG_ARRAY_NONE ;
296
- break ;
297
- case ABSTIMEOID :isarray = ECPG_ARRAY_NONE ;
298
- break ;
299
- case RELTIMEOID :isarray = ECPG_ARRAY_NONE ;
300
- break ;
301
- case TINTERVALOID :isarray = ECPG_ARRAY_NONE ;
302
- break ;
303
- case UNKNOWNOID :isarray = ECPG_ARRAY_NONE ;
304
- break ;
305
- case CIRCLEOID :isarray = ECPG_ARRAY_NONE ;
306
- break ;
307
- case CASHOID :isarray = ECPG_ARRAY_NONE ;
308
- break ;
309
- case INETOID :isarray = ECPG_ARRAY_NONE ;
310
- break ;
311
- case CIDROID :isarray = ECPG_ARRAY_NONE ;
312
- break ;
313
- case BPCHAROID :isarray = ECPG_ARRAY_NONE ;
314
- break ;
315
- case VARCHAROID :isarray = ECPG_ARRAY_NONE ;
316
- break ;
317
- case DATEOID :isarray = ECPG_ARRAY_NONE ;
318
- break ;
319
- case TIMEOID :isarray = ECPG_ARRAY_NONE ;
320
- break ;
321
- case TIMESTAMPOID :isarray = ECPG_ARRAY_NONE ;
322
- break ;
323
- case TIMESTAMPTZOID :isarray = ECPG_ARRAY_NONE ;
324
- break ;
325
- case INTERVALOID :isarray = ECPG_ARRAY_NONE ;
326
- break ;
327
- case TIMETZOID :isarray = ECPG_ARRAY_NONE ;
328
- break ;
329
- case ZPBITOID :isarray = ECPG_ARRAY_NONE ;
330
- break ;
331
- case VARBITOID :isarray = ECPG_ARRAY_NONE ;
332
- break ;
333
- case NUMERICOID :isarray = ECPG_ARRAY_NONE ;
334
- break ;
335
- default :break ;
336
- }
261
+
262
+ /* populate cache with well known types to speed things up */
263
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),BOOLOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
264
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),BYTEAOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
265
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),CHAROID ,ECPG_ARRAY_NONE ,stmt -> lineno );
266
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),NAMEOID ,not_an_array_in_ecpg ,stmt -> lineno );
267
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),INT8OID ,ECPG_ARRAY_NONE ,stmt -> lineno );
268
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),INT2OID ,ECPG_ARRAY_NONE ,stmt -> lineno );
269
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),INT2VECTOROID ,ECPG_ARRAY_VECTOR ,stmt -> lineno );
270
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),INT4OID ,ECPG_ARRAY_NONE ,stmt -> lineno );
271
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),REGPROCOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
272
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),TEXTOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
273
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),OIDOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
274
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),TIDOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
275
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),XIDOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
276
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),CIDOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
277
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),OIDVECTOROID ,ECPG_ARRAY_VECTOR ,stmt -> lineno );
278
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),POINTOID ,ECPG_ARRAY_VECTOR ,stmt -> lineno );
279
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),LSEGOID ,ECPG_ARRAY_VECTOR ,stmt -> lineno );
280
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),PATHOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
281
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),BOXOID ,ECPG_ARRAY_VECTOR ,stmt -> lineno );
282
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),POLYGONOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
283
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),LINEOID ,ECPG_ARRAY_VECTOR ,stmt -> lineno );
284
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),FLOAT4OID ,ECPG_ARRAY_NONE ,stmt -> lineno );
285
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),FLOAT8OID ,ECPG_ARRAY_NONE ,stmt -> lineno );
286
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),ABSTIMEOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
287
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),RELTIMEOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
288
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),TINTERVALOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
289
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),UNKNOWNOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
290
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),CIRCLEOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
291
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),CASHOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
292
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),INETOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
293
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),CIDROID ,ECPG_ARRAY_NONE ,stmt -> lineno );
294
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),BPCHAROID ,ECPG_ARRAY_NONE ,stmt -> lineno );
295
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),VARCHAROID ,ECPG_ARRAY_NONE ,stmt -> lineno );
296
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),DATEOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
297
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),TIMEOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
298
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),TIMESTAMPOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
299
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),TIMESTAMPTZOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
300
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),INTERVALOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
301
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),TIMETZOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
302
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),ZPBITOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
303
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),VARBITOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
304
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),NUMERICOID ,ECPG_ARRAY_NONE ,stmt -> lineno );
337
305
}
338
306
339
- if (isarray == ECPG_ARRAY_NOT_SET )
307
+ for (cache_entry = (stmt -> connection -> cache_head );cache_entry != NULL ;cache_entry = cache_entry -> next )
308
+ {
309
+ if (cache_entry -> oid == type )
310
+ return cache_entry -> isarray ;
311
+ }
312
+
313
+ array_query = (char * )ECPGalloc (strlen ("select typlen from pg_type where oid= and typelem<>0" )+ 11 ,stmt -> lineno );
314
+ sprintf (array_query ,"select typlen from pg_type where oid=%d and typelem<>0" ,type );
315
+ query = PQexec (stmt -> connection -> connection ,array_query );
316
+ ECPGfree (array_query );
317
+ if (PQresultStatus (query )== PGRES_TUPLES_OK )
340
318
{
341
- array_query = (char * )ECPGalloc (strlen ("select typlen from pg_type where oid= and typelem<>0" )+ 11 ,stmt -> lineno );
342
- sprintf (array_query ,"select typlen from pg_type where oid=%d and typelem<>0" ,type );
343
- query = PQexec (stmt -> connection -> connection ,array_query );
344
- ECPGfree (array_query );
345
- if (PQresultStatus (query )== PGRES_TUPLES_OK )
319
+ isarray = (atol ((char * )PQgetvalue (query ,0 ,0 ))== -1 ) ?ECPG_ARRAY_ARRAY :ECPG_ARRAY_VECTOR ;
320
+ if (ECPGDynamicType (type )== SQL3_CHARACTER ||
321
+ ECPGDynamicType (type )== SQL3_CHARACTER_VARYING )
346
322
{
347
- isarray = (atol ((char * )PQgetvalue (query ,0 ,0 ))== -1 ) ?ECPG_ARRAY_ARRAY :ECPG_ARRAY_VECTOR ;
348
- if (ECPGDynamicType (type )== SQL3_CHARACTER ||
349
- ECPGDynamicType (type )== SQL3_CHARACTER_VARYING )
350
- {
351
- /*
352
- * arrays of character strings are not yet implemented
353
- */
354
- isarray = ECPG_ARRAY_NONE ;
355
- }
323
+ /*
324
+ * arrays of character strings are not yet implemented
325
+ */
326
+ isarray = ECPG_ARRAY_NONE ;
356
327
}
357
- PQclear (query );
358
328
}
329
+ PQclear (query );
330
+ ECPGtypeinfocache_push (& (stmt -> connection -> cache_head ),type ,isarray ,stmt -> lineno );
359
331
ECPGlog ("ECPGexecute line %d: TYPE database: %d C: %d array: %d\n" ,stmt -> lineno ,type ,var -> type ,isarray );
360
332
return isarray ;
361
333
}