~psycopg/psycopg/2.0.x

« back to all changes in this revision

Viewing changes to psycopg/cursor_type.c

  • Committer: Federico Di Gregorio
  • Date: 2004-11-19 15:30:07 UTC
  • Revision ID: fog-558ef2fb16e99a43fb7d2615482cc7d09f608dee
Fixes to row_factory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
508
508
}
509
509
 
510
510
static PyObject *
511
 
_psyco_curs_buildrow_fill(cursorObject *self, PyObject *res, int row, int n)
 
511
_psyco_curs_buildrow_fill(cursorObject *self, PyObject *res,
 
512
                          int row, int n, int istuple)
512
513
{
513
514
    int i;
514
515
    PyObject *str, *val;
537
538
        
538
539
        if (val) {
539
540
            Dprintf("_psyco_curs_buildrow: val->refcnt = %d", val->ob_refcnt);
540
 
            PySequence_SetItem(res, i, val);
541
 
            Py_DECREF(val);
 
541
            if (istuple) {
 
542
                PyTuple_SET_ITEM(res, i, val);
 
543
            }
 
544
            else {
 
545
                PySequence_SetItem(res, i, val);
 
546
                Py_DECREF(val);
 
547
            }
542
548
        }
543
549
        else {
544
550
            /* an error occurred in the type system, we return NULL to raise
559
565
    int n;
560
566
    
561
567
    n = PQnfields(self->pgres);
562
 
    return _psyco_curs_buildrow_fill(self, PyTuple_New(n), row, n);
 
568
    return _psyco_curs_buildrow_fill(self, PyTuple_New(n), row, n, 1);
563
569
}
564
570
 
565
571
static PyObject *
572
578
    if ((res = PyObject_CallFunction(self->tuple_factory, "O", self))== NULL)
573
579
        return NULL;
574
580
 
575
 
    return _psyco_curs_buildrow_fill(self, res, row, n);
 
581
    return _psyco_curs_buildrow_fill(self, res, row, n, 0);
576
582
}
577
583
 
578
584
                     
1030
1036
#ifdef PSYCOPG_EXTENSIONS    
1031
1037
    {"statusmessage", T_OBJECT, OFFSETOF(pgstatus), RO},
1032
1038
    {"query", T_STRING, OFFSETOF(query), RO},
1033
 
    {"tuple_factory", T_OBJECT, OFFSETOF(tuple_factory), 0},
 
1039
    {"row_factory", T_OBJECT, OFFSETOF(tuple_factory), 0},
1034
1040
    {"tzinfo_factory", T_OBJECT, OFFSETOF(tzinfo_factory), 0},
1035
1041
#endif
1036
1042
    {NULL}