~ubuntu-branches/ubuntu/utopic/postgresql-9.1/utopic

« back to all changes in this revision

Viewing changes to src/backend/utils/adt/rowtypes.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2012-12-03 22:32:35 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20121203223235-828kgo6j9luo7c0r
* New upstream bug fix release. See HISTORY/changelog.gz for details.
* Add 03-python-includedirs.patch: Detect both python3.3 include locations.
  Thanks Dmitrijs Ledkovs!

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
        Oid                     column_type;
32
32
        Oid                     typiofunc;
33
33
        Oid                     typioparam;
 
34
        bool            typisvarlena;
34
35
        FmgrInfo        proc;
35
36
} ColumnIOData;
36
37
 
363
364
        {
364
365
                ColumnIOData *column_info = &my_extra->columns[i];
365
366
                Oid                     column_type = tupdesc->attrs[i]->atttypid;
 
367
                Datum           attr;
366
368
                char       *value;
367
369
                char       *tmp;
368
370
                bool            nq;
386
388
                 */
387
389
                if (column_info->column_type != column_type)
388
390
                {
389
 
                        bool            typIsVarlena;
390
 
 
391
391
                        getTypeOutputInfo(column_type,
392
392
                                                          &column_info->typiofunc,
393
 
                                                          &typIsVarlena);
 
393
                                                          &column_info->typisvarlena);
394
394
                        fmgr_info_cxt(column_info->typiofunc, &column_info->proc,
395
395
                                                  fcinfo->flinfo->fn_mcxt);
396
396
                        column_info->column_type = column_type;
397
397
                }
398
398
 
399
 
                value = OutputFunctionCall(&column_info->proc, values[i]);
 
399
                /*
 
400
                 * If we have a toasted datum, forcibly detoast it here to avoid
 
401
                 * memory leakage inside the type's output routine.
 
402
                 */
 
403
                if (column_info->typisvarlena)
 
404
                        attr = PointerGetDatum(PG_DETOAST_DATUM(values[i]));
 
405
                else
 
406
                        attr = values[i];
 
407
 
 
408
                value = OutputFunctionCall(&column_info->proc, attr);
400
409
 
401
410
                /* Detect whether we need double quotes for this value */
402
411
                nq = (value[0] == '\0');        /* force quotes for empty string */
415
424
 
416
425
                /* And emit the string */
417
426
                if (nq)
418
 
                        appendStringInfoChar(&buf, '"');
 
427
                        appendStringInfoCharMacro(&buf, '"');
419
428
                for (tmp = value; *tmp; tmp++)
420
429
                {
421
430
                        char            ch = *tmp;
422
431
 
423
432
                        if (ch == '"' || ch == '\\')
424
 
                                appendStringInfoChar(&buf, ch);
425
 
                        appendStringInfoChar(&buf, ch);
 
433
                                appendStringInfoCharMacro(&buf, ch);
 
434
                        appendStringInfoCharMacro(&buf, ch);
426
435
                }
427
436
                if (nq)
428
 
                        appendStringInfoChar(&buf, '"');
 
437
                        appendStringInfoCharMacro(&buf, '"');
 
438
 
 
439
                pfree(value);
 
440
 
 
441
                /* Clean up detoasted copy, if any */
 
442
                if (DatumGetPointer(attr) != DatumGetPointer(values[i]))
 
443
                        pfree(DatumGetPointer(attr));
429
444
        }
430
445
 
431
446
        appendStringInfoChar(&buf, ')');
713
728
        {
714
729
                ColumnIOData *column_info = &my_extra->columns[i];
715
730
                Oid                     column_type = tupdesc->attrs[i]->atttypid;
 
731
                Datum           attr;
716
732
                bytea      *outputbytes;
717
733
 
718
734
                /* Ignore dropped columns in datatype */
733
749
                 */
734
750
                if (column_info->column_type != column_type)
735
751
                {
736
 
                        bool            typIsVarlena;
737
 
 
738
752
                        getTypeBinaryOutputInfo(column_type,
739
753
                                                                        &column_info->typiofunc,
740
 
                                                                        &typIsVarlena);
 
754
                                                                        &column_info->typisvarlena);
741
755
                        fmgr_info_cxt(column_info->typiofunc, &column_info->proc,
742
756
                                                  fcinfo->flinfo->fn_mcxt);
743
757
                        column_info->column_type = column_type;
744
758
                }
745
759
 
746
 
                outputbytes = SendFunctionCall(&column_info->proc, values[i]);
 
760
                /*
 
761
                 * If we have a toasted datum, forcibly detoast it here to avoid
 
762
                 * memory leakage inside the type's output routine.
 
763
                 */
 
764
                if (column_info->typisvarlena)
 
765
                        attr = PointerGetDatum(PG_DETOAST_DATUM(values[i]));
 
766
                else
 
767
                        attr = values[i];
 
768
 
 
769
                outputbytes = SendFunctionCall(&column_info->proc, attr);
747
770
 
748
771
                /* We assume the result will not have been toasted */
749
772
                pq_sendint(&buf, VARSIZE(outputbytes) - VARHDRSZ, 4);
750
773
                pq_sendbytes(&buf, VARDATA(outputbytes),
751
774
                                         VARSIZE(outputbytes) - VARHDRSZ);
 
775
 
752
776
                pfree(outputbytes);
 
777
 
 
778
                /* Clean up detoasted copy, if any */
 
779
                if (DatumGetPointer(attr) != DatumGetPointer(values[i]))
 
780
                        pfree(DatumGetPointer(attr));
753
781
        }
754
782
 
755
783
        pfree(values);