Back to index

python3.2  3.2.2
Functions | Variables
row.c File Reference
#include "row.h"
#include "cursor.h"
#include "sqlitecompat.h"

Go to the source code of this file.

Functions

void pysqlite_row_dealloc (pysqlite_Row *self)
int pysqlite_row_init (pysqlite_Row *self, PyObject *args, PyObject *kwargs)
PyObjectpysqlite_row_subscript (pysqlite_Row *self, PyObject *idx)
Py_ssize_t pysqlite_row_length (pysqlite_Row *self, PyObject *args, PyObject *kwargs)
PyObjectpysqlite_row_keys (pysqlite_Row *self, PyObject *args, PyObject *kwargs)
static int pysqlite_row_print (pysqlite_Row *self, FILE *fp, int flags)
static PyObjectpysqlite_iter (pysqlite_Row *self)
static Py_hash_t pysqlite_row_hash (pysqlite_Row *self)
static PyObjectpysqlite_row_richcompare (pysqlite_Row *self, PyObject *_other, int opid)
int pysqlite_row_setup_types (void)

Variables

PyMappingMethods pysqlite_row_as_mapping
static PyMethodDef pysqlite_row_methods []
PyTypeObject pysqlite_RowType

Function Documentation

static PyObject* pysqlite_iter ( pysqlite_Row self) [static]

Definition at line 164 of file row.c.

{
    return PyObject_GetIter(self->data);
}

Here is the call graph for this function:

Definition at line 28 of file row.c.

{
    Py_XDECREF(self->data);
    Py_XDECREF(self->description);

    Py_TYPE(self)->tp_free((PyObject*)self);
}
static Py_hash_t pysqlite_row_hash ( pysqlite_Row self) [static]

Definition at line 169 of file row.c.

{
    return PyObject_Hash(self->description) ^ PyObject_Hash(self->data);
}

Here is the call graph for this function:

int pysqlite_row_init ( pysqlite_Row self,
PyObject args,
PyObject kwargs 
)

Definition at line 36 of file row.c.

{
    PyObject* data;
    pysqlite_Cursor* cursor;

    self->data = 0;
    self->description = 0;

    if (!PyArg_ParseTuple(args, "OO", &cursor, &data)) {
        return -1;
    }

    if (!PyObject_IsInstance((PyObject*)cursor, (PyObject*)&pysqlite_CursorType)) {
        PyErr_SetString(PyExc_TypeError, "instance of cursor required for first argument");
        return -1;
    }

    if (!PyTuple_Check(data)) {
        PyErr_SetString(PyExc_TypeError, "tuple required for second argument");
        return -1;
    }

    Py_INCREF(data);
    self->data = data;

    Py_INCREF(cursor->description);
    self->description = cursor->description;

    return 0;
}

Here is the call graph for this function:

PyObject* pysqlite_row_keys ( pysqlite_Row self,
PyObject args,
PyObject kwargs 
)

Definition at line 138 of file row.c.

{
    PyObject* list;
    int nitems, i;

    list = PyList_New(0);
    if (!list) {
        return NULL;
    }
    nitems = PyTuple_Size(self->description);

    for (i = 0; i < nitems; i++) {
        if (PyList_Append(list, PyTuple_GET_ITEM(PyTuple_GET_ITEM(self->description, i), 0)) != 0) {
            Py_DECREF(list);
            return NULL;
        }
    }

    return list;
}

Here is the call graph for this function:

Py_ssize_t pysqlite_row_length ( pysqlite_Row self,
PyObject args,
PyObject kwargs 
)

Definition at line 133 of file row.c.

{
    return PyTuple_GET_SIZE(self->data);
}
static int pysqlite_row_print ( pysqlite_Row self,
FILE *  fp,
int  flags 
) [static]

Definition at line 159 of file row.c.

{
    return (&PyTuple_Type)->tp_print(self->data, fp, flags);
}
static PyObject* pysqlite_row_richcompare ( pysqlite_Row self,
PyObject _other,
int  opid 
) [static]

Definition at line 174 of file row.c.

{
    if (opid != Py_EQ && opid != Py_NE) {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }
    if (PyType_IsSubtype(Py_TYPE(_other), &pysqlite_RowType)) {
        pysqlite_Row *other = (pysqlite_Row *)_other;
        PyObject *res = PyObject_RichCompare(self->description, other->description, opid);
        if ((opid == Py_EQ && res == Py_True)
            || (opid == Py_NE && res == Py_False)) {
            Py_DECREF(res);
            return PyObject_RichCompare(self->data, other->data, opid);
        }
    }
    Py_INCREF(Py_NotImplemented);
    return Py_NotImplemented;
}

Here is the call graph for this function:

Definition at line 248 of file row.c.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 67 of file row.c.

{
    long _idx;
    char* key;
    int nitems, i;
    char* compare_key;

    char* p1;
    char* p2;

    PyObject* item;

    if (PyLong_Check(idx)) {
        _idx = PyLong_AsLong(idx);
        item = PyTuple_GetItem(self->data, _idx);
        Py_XINCREF(item);
        return item;
    } else if (PyUnicode_Check(idx)) {
        key = _PyUnicode_AsString(idx);
        if (key == NULL)
            return NULL;

        nitems = PyTuple_Size(self->description);

        for (i = 0; i < nitems; i++) {
            compare_key = _PyUnicode_AsString(PyTuple_GET_ITEM(PyTuple_GET_ITEM(self->description, i), 0));
            if (!compare_key) {
                return NULL;
            }

            p1 = key;
            p2 = compare_key;

            while (1) {
                if ((*p1 == (char)0) || (*p2 == (char)0)) {
                    break;
                }

                if ((*p1 | 0x20) != (*p2 | 0x20)) {
                    break;
                }

                p1++;
                p2++;
            }

            if ((*p1 == (char)0) && (*p2 == (char)0)) {
                /* found item */
                item = PyTuple_GetItem(self->data, i);
                Py_INCREF(item);
                return item;
            }

        }

        PyErr_SetString(PyExc_IndexError, "No item with that key");
        return NULL;
    } else if (PySlice_Check(idx)) {
        PyErr_SetString(PyExc_ValueError, "slices not implemented, yet");
        return NULL;
    } else {
        PyErr_SetString(PyExc_IndexError, "Index must be int or string");
        return NULL;
    }
}

Here is the call graph for this function:


Variable Documentation

Initial value:

Definition at line 193 of file row.c.

Initial value:
 {
    {"keys", (PyCFunction)pysqlite_row_keys, METH_NOARGS,
        PyDoc_STR("Returns the keys of the row.")},
    {NULL, NULL}
}

Definition at line 199 of file row.c.

Definition at line 206 of file row.c.