Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions | Variables

plpy_resultobject.c File Reference

#include "postgres.h"
#include "plpython.h"
#include "plpy_resultobject.h"
#include "plpy_elog.h"
Include dependency graph for plpy_resultobject.c:

Go to the source code of this file.

Functions

static void PLy_result_dealloc (PyObject *arg)
static PyObject * PLy_result_colnames (PyObject *self, PyObject *unused)
static PyObject * PLy_result_coltypes (PyObject *self, PyObject *unused)
static PyObject * PLy_result_coltypmods (PyObject *self, PyObject *unused)
static PyObject * PLy_result_nrows (PyObject *self, PyObject *args)
static PyObject * PLy_result_status (PyObject *self, PyObject *args)
static Py_ssize_t PLy_result_length (PyObject *arg)
static PyObject * PLy_result_item (PyObject *arg, Py_ssize_t idx)
static PyObject * PLy_result_slice (PyObject *arg, Py_ssize_t lidx, Py_ssize_t hidx)
static int PLy_result_ass_slice (PyObject *arg, Py_ssize_t lidx, Py_ssize_t hidx, PyObject *slice)
static PyObject * PLy_result_str (PyObject *arg)
static PyObject * PLy_result_subscript (PyObject *arg, PyObject *item)
static int PLy_result_ass_subscript (PyObject *self, PyObject *item, PyObject *value)
void PLy_result_init_type (void)
PyObject * PLy_result_new (void)

Variables

static char PLy_result_doc []
static PySequenceMethods PLy_result_as_sequence
static PyMappingMethods PLy_result_as_mapping
static PyMethodDef PLy_result_methods []
static PyTypeObject PLy_ResultType

Function Documentation

static int PLy_result_ass_slice ( PyObject *  arg,
Py_ssize_t  lidx,
Py_ssize_t  hidx,
PyObject *  slice 
) [static]

Definition at line 243 of file plpy_resultobject.c.

References PLyResultObject::rows.

{
    int         rv;
    PLyResultObject *ob = (PLyResultObject *) arg;

    rv = PyList_SetSlice(ob->rows, lidx, hidx, slice);
    return rv;
}

static int PLy_result_ass_subscript ( PyObject *  self,
PyObject *  item,
PyObject *  value 
) [static]

Definition at line 281 of file plpy_resultobject.c.

References PLyResultObject::rows.

{
    PLyResultObject *ob = (PLyResultObject *) arg;

    return PyObject_SetItem(ob->rows, item, value);
}

static PyObject * PLy_result_colnames ( PyObject *  self,
PyObject *  unused 
) [static]

Definition at line 137 of file plpy_resultobject.c.

References tupleDesc::attrs, i, sort-test::list, NameStr, tupleDesc::natts, PLy_exc_error, PLy_exception_set(), and PLyResultObject::tupdesc.

{
    PLyResultObject *ob = (PLyResultObject *) self;
    PyObject   *list;
    int         i;

    if (!ob->tupdesc)
    {
        PLy_exception_set(PLy_exc_error, "command did not produce a result set");
        return NULL;
    }

    list = PyList_New(ob->tupdesc->natts);
    for (i = 0; i < ob->tupdesc->natts; i++)
        PyList_SET_ITEM(list, i, PyString_FromString(NameStr(ob->tupdesc->attrs[i]->attname)));

    return list;
}

static PyObject * PLy_result_coltypes ( PyObject *  self,
PyObject *  unused 
) [static]

Definition at line 157 of file plpy_resultobject.c.

References tupleDesc::attrs, i, sort-test::list, tupleDesc::natts, PLy_exc_error, PLy_exception_set(), and PLyResultObject::tupdesc.

{
    PLyResultObject *ob = (PLyResultObject *) self;
    PyObject   *list;
    int         i;

    if (!ob->tupdesc)
    {
        PLy_exception_set(PLy_exc_error, "command did not produce a result set");
        return NULL;
    }

    list = PyList_New(ob->tupdesc->natts);
    for (i = 0; i < ob->tupdesc->natts; i++)
        PyList_SET_ITEM(list, i, PyInt_FromLong(ob->tupdesc->attrs[i]->atttypid));

    return list;
}

static PyObject * PLy_result_coltypmods ( PyObject *  self,
PyObject *  unused 
) [static]

Definition at line 177 of file plpy_resultobject.c.

References tupleDesc::attrs, i, sort-test::list, tupleDesc::natts, PLy_exc_error, PLy_exception_set(), and PLyResultObject::tupdesc.

{
    PLyResultObject *ob = (PLyResultObject *) self;
    PyObject   *list;
    int         i;

    if (!ob->tupdesc)
    {
        PLy_exception_set(PLy_exc_error, "command did not produce a result set");
        return NULL;
    }

    list = PyList_New(ob->tupdesc->natts);
    for (i = 0; i < ob->tupdesc->natts; i++)
        PyList_SET_ITEM(list, i, PyInt_FromLong(ob->tupdesc->attrs[i]->atttypmod));

    return list;
}

static void PLy_result_dealloc ( PyObject *  arg  )  [static]

Definition at line 120 of file plpy_resultobject.c.

References FreeTupleDesc(), PLyResultObject::nrows, PLyResultObject::rows, PLyResultObject::status, and PLyResultObject::tupdesc.

{
    PLyResultObject *ob = (PLyResultObject *) arg;

    Py_XDECREF(ob->nrows);
    Py_XDECREF(ob->rows);
    Py_XDECREF(ob->status);
    if (ob->tupdesc)
    {
        FreeTupleDesc(ob->tupdesc);
        ob->tupdesc = NULL;
    }

    arg->ob_type->tp_free(arg);
}

void PLy_result_init_type ( void   ) 

Definition at line 94 of file plpy_resultobject.c.

References elog, ERROR, and PLy_ResultType.

Referenced by PLy_init_plpy().

{
    if (PyType_Ready(&PLy_ResultType) < 0)
        elog(ERROR, "could not initialize PLy_ResultType");
}

static PyObject * PLy_result_item ( PyObject *  arg,
Py_ssize_t  idx 
) [static]

Definition at line 223 of file plpy_resultobject.c.

References NULL, and PLyResultObject::rows.

{
    PyObject   *rv;
    PLyResultObject *ob = (PLyResultObject *) arg;

    rv = PyList_GetItem(ob->rows, idx);
    if (rv != NULL)
        Py_INCREF(rv);
    return rv;
}

static Py_ssize_t PLy_result_length ( PyObject *  arg  )  [static]

Definition at line 215 of file plpy_resultobject.c.

References PLyResultObject::rows.

{
    PLyResultObject *ob = (PLyResultObject *) arg;

    return PyList_Size(ob->rows);
}

PyObject* PLy_result_new ( void   ) 

Definition at line 101 of file plpy_resultobject.c.

References PLyResultObject::nrows, NULL, PLy_ResultType, PLyResultObject::rows, PLyResultObject::status, and PLyResultObject::tupdesc.

Referenced by PLy_cursor_fetch(), and PLy_spi_execute_fetch_result().

{
    PLyResultObject *ob;

    if ((ob = PyObject_New(PLyResultObject, &PLy_ResultType)) == NULL)
        return NULL;

    /* ob->tuples = NULL; */

    Py_INCREF(Py_None);
    ob->status = Py_None;
    ob->nrows = PyInt_FromLong(-1);
    ob->rows = PyList_New(0);
    ob->tupdesc = NULL;

    return (PyObject *) ob;
}

static PyObject * PLy_result_nrows ( PyObject *  self,
PyObject *  args 
) [static]

Definition at line 197 of file plpy_resultobject.c.

References PLyResultObject::nrows.

{
    PLyResultObject *ob = (PLyResultObject *) self;

    Py_INCREF(ob->nrows);
    return ob->nrows;
}

static PyObject * PLy_result_slice ( PyObject *  arg,
Py_ssize_t  lidx,
Py_ssize_t  hidx 
) [static]

Definition at line 235 of file plpy_resultobject.c.

References PLyResultObject::rows.

{
    PLyResultObject *ob = (PLyResultObject *) arg;

    return PyList_GetSlice(ob->rows, lidx, hidx);
}

static PyObject * PLy_result_status ( PyObject *  self,
PyObject *  args 
) [static]

Definition at line 206 of file plpy_resultobject.c.

References PLyResultObject::status.

{
    PLyResultObject *ob = (PLyResultObject *) self;

    Py_INCREF(ob->status);
    return ob->status;
}

static PyObject * PLy_result_str ( PyObject *  arg  )  [static]

Definition at line 253 of file plpy_resultobject.c.

References PLyResultObject::nrows, PLyResultObject::rows, and PLyResultObject::status.

{
    PLyResultObject *ob = (PLyResultObject *) arg;

#if PY_MAJOR_VERSION >= 3
    return PyUnicode_FromFormat("<%s status=%S nrows=%S rows=%S>",
                                Py_TYPE(ob)->tp_name,
                                ob->status,
                                ob->nrows,
                                ob->rows);
#else
    return PyString_FromFormat("<%s status=%ld nrows=%ld rows=%s>",
                               ob->ob_type->tp_name,
                               PyInt_AsLong(ob->status),
                               PyInt_AsLong(ob->nrows),
                               PyString_AsString(PyObject_Str(ob->rows)));
#endif
}

static PyObject * PLy_result_subscript ( PyObject *  arg,
PyObject *  item 
) [static]

Definition at line 273 of file plpy_resultobject.c.

References PLyResultObject::rows.

{
    PLyResultObject *ob = (PLyResultObject *) arg;

    return PyObject_GetItem(ob->rows, item);
}


Variable Documentation

PyMappingMethods PLy_result_as_mapping [static]
Initial value:
 {
    PLy_result_length,          
    PLy_result_subscript,       
    PLy_result_ass_subscript,   
}

Definition at line 43 of file plpy_resultobject.c.

PySequenceMethods PLy_result_as_sequence [static]
Initial value:
 {
    PLy_result_length,          
    NULL,                       
    NULL,                       
    PLy_result_item,            
    PLy_result_slice,           
    NULL,                       
    PLy_result_ass_slice,       
}

Definition at line 33 of file plpy_resultobject.c.

char PLy_result_doc[] [static]
Initial value:
 {
    "Results of a PostgreSQL query"
}

Definition at line 29 of file plpy_resultobject.c.

PyMethodDef PLy_result_methods[] [static]
Initial value:
 {
    {"colnames", PLy_result_colnames, METH_NOARGS, NULL},
    {"coltypes", PLy_result_coltypes, METH_NOARGS, NULL},
    {"coltypmods", PLy_result_coltypmods, METH_NOARGS, NULL},
    {"nrows", PLy_result_nrows, METH_VARARGS, NULL},
    {"status", PLy_result_status, METH_VARARGS, NULL},
    {NULL, NULL, 0, NULL}
}

Definition at line 49 of file plpy_resultobject.c.

PyTypeObject PLy_ResultType [static]

Definition at line 58 of file plpy_resultobject.c.

Referenced by PLy_result_init_type(), and PLy_result_new().