6
6
*
7
7
*
8
8
* IDENTIFICATION
9
- * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.40 1998/01/31 04:38:18 momjian Exp $
9
+ * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.41 1998/02/10 16:02:51 momjian Exp $
10
10
*
11
11
*-------------------------------------------------------------------------
12
12
*/
@@ -65,7 +65,7 @@ static void CopyAttributeOut(FILE *fp, char *string, char *delim);
65
65
static int CountTuples (Relation relation );
66
66
67
67
extern FILE * Pfout ,
68
- * Pfin ;
68
+ * Pfin ;
69
69
70
70
static int lineno ;
71
71
@@ -205,6 +205,7 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
205
205
FmgrInfo * out_functions ;
206
206
Oid out_func_oid ;
207
207
Oid * elements ;
208
+ int16 * typmod ;
208
209
Datum value ;
209
210
bool isnull ; /* The attribute we are copying is null */
210
211
char * nulls ;
@@ -230,18 +231,21 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
230
231
{
231
232
out_functions = (FmgrInfo * ) palloc (attr_count * sizeof (FmgrInfo ));
232
233
elements = (Oid * ) palloc (attr_count * sizeof (Oid ));
234
+ typmod = (int16 * ) palloc (attr_count * sizeof (int16 ));
233
235
for (i = 0 ; i < attr_count ; i ++ )
234
236
{
235
237
out_func_oid = (Oid ) GetOutputFunction (attr [i ]-> atttypid );
236
238
fmgr_info (out_func_oid , & out_functions [i ]);
237
239
elements [i ] = GetTypeElement (attr [i ]-> atttypid );
240
+ typmod [i ] = attr [i ]-> atttypmod ;
238
241
}
239
242
nulls = NULL ; /* meaningless, but compiler doesn't know
240
243
* that */
241
244
}
242
245
else
243
246
{
244
247
elements = NULL ;
248
+ typmod = NULL ;
245
249
out_functions = NULL ;
246
250
nulls = (char * ) palloc (attr_count );
247
251
for (i = 0 ; i < attr_count ; i ++ )
@@ -271,7 +275,8 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
271
275
{
272
276
if (!isnull )
273
277
{
274
- string = (char * ) (* fmgr_faddr (& out_functions [i ])) (value , elements [i ]);
278
+ string = (char * ) (* fmgr_faddr (& out_functions [i ]))
279
+ (value , elements [i ], typmod [i ]);
275
280
CopyAttributeOut (fp , string , delim );
276
281
pfree (string );
277
282
}
@@ -345,6 +350,7 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
345
350
{
346
351
pfree (out_functions );
347
352
pfree (elements );
353
+ pfree (typmod );
348
354
}
349
355
350
356
heap_close (rel );
@@ -376,6 +382,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
376
382
tuples_read = 0 ;
377
383
bool reading_to_eof = true;
378
384
Oid * elements ;
385
+ int16 * typmod ;
379
386
FuncIndexInfo * finfo ,
380
387
* * finfoP = NULL ;
381
388
TupleDesc * itupdescArr ;
@@ -498,17 +505,20 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
498
505
{
499
506
in_functions = (FmgrInfo * ) palloc (attr_count * sizeof (FmgrInfo ));
500
507
elements = (Oid * ) palloc (attr_count * sizeof (Oid ));
508
+ typmod = (int16 * ) palloc (attr_count * sizeof (int16 ));
501
509
for (i = 0 ; i < attr_count ; i ++ )
502
510
{
503
511
in_func_oid = (Oid ) GetInputFunction (attr [i ]-> atttypid );
504
512
fmgr_info (in_func_oid , & in_functions [i ]);
505
513
elements [i ] = GetTypeElement (attr [i ]-> atttypid );
514
+ typmod [i ] = attr [i ]-> atttypmod ;
506
515
}
507
516
}
508
517
else
509
518
{
510
519
in_functions = NULL ;
511
520
elements = NULL ;
521
+ typmod = NULL ;
512
522
fread (& ntuples , sizeof (int32 ), 1 , fp );
513
523
if (ntuples != 0 )
514
524
reading_to_eof = false;
@@ -574,7 +584,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
574
584
values [i ] =
575
585
(Datum ) (* fmgr_faddr (& in_functions [i ])) (string ,
576
586
elements [i ],
577
- attr [i ]-> atttypmod );
587
+ typmod [i ]);
578
588
579
589
/*
580
590
* Sanity check - by reference attributes cannot
@@ -801,9 +811,13 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
801
811
done = true;
802
812
}
803
813
pfree (values );
814
+ pfree (nulls );
804
815
if (!binary )
816
+ {
805
817
pfree (in_functions );
806
- pfree (nulls );
818
+ pfree (elements );
819
+ pfree (typmod );
820
+ }
807
821
pfree (byval );
808
822
heap_close (rel );
809
823
}
0 commit comments