static PyObject *
KyotoDB_iter(KyotoDB *self)
{
    KyotoCursor *cursor = PyObject_New(KyotoCursor, &yakc_CursorType);
    APR tuple(PyTuple_Pack(1, self));
    int re = Cursor_init(cursor, tuple.get(), NULL);
    if (re == 0)
        return (PyObject *)cursor;
    PyErr_SetString(PyExc_RuntimeError, "Cannot create cursor");
    return NULL;
}
static PyObject *
KyotoDB_iteritems(KyotoDB *self)
{
    KyotoCursor *cursor = PyObject_New(KyotoCursor, &yakc_CursorType);
    APR type(PyInt_FromLong((long)KYOTO_ITEMS));
    APR tuple(PyTuple_Pack(2, self, type.get()));
    int re = Cursor_init(cursor, tuple.get(), NULL);
    if (re == 0)
        return (PyObject *)cursor;
    PyErr_SetString(PyExc_RuntimeError, "Cannot create cursor");
    return NULL;
}
Ejemplo n.º 3
0
static bool import_types()
{
    // In Python 2.5 final, PyDateTime_IMPORT no longer works unless the datetime module was previously
    // imported (among other problems).

    PyObject* pdt = PyImport_ImportModule("datetime");
    
    if (!pdt)
        return false;

    PyDateTime_IMPORT;
     
    if (!PyDateTimeAPI)
    {
        PyErr_SetString(PyExc_RuntimeError, "Unable to import the datetime module.");
        return false;
    }
    
    OurDateTimeType = PyDateTimeAPI->DateTimeType;
    OurDateType     = PyDateTimeAPI->DateType;
    OurTimeType     = PyDateTimeAPI->TimeType;

    Cursor_init();
    CnxnInfo_init();
    GetData_init();

    PyObject* decimalmod = PyImport_ImportModule("decimal");
    if (!decimalmod)
    {
        PyErr_SetString(PyExc_RuntimeError, "Unable to import decimal");
        return false;
    }
    
    decimal_type = PyObject_GetAttrString(decimalmod, "Decimal");
    Py_DECREF(decimalmod);

    if (decimal_type == 0)
        PyErr_SetString(PyExc_RuntimeError, "Unable to import decimal.Decimal.");
    
    return decimal_type != 0;
}
Ejemplo n.º 4
0
static bool import_types()
{
    // In Python 2.5 final, PyDateTime_IMPORT no longer works unless the datetime module was previously
    // imported (among other problems).

    PyObject* pdt = PyImport_ImportModule("datetime");

    if (!pdt)
        return false;

    PyDateTime_IMPORT;

    Cursor_init();
    CnxnInfo_init();
    GetData_init();
    if (!Params_init())
        return false;

    PyObject* decimalmod = PyImport_ImportModule("cdecimal");
    if (!decimalmod)
    {
        // Clear the error from the failed import of cdecimal.
        PyErr_Clear();
        decimalmod = PyImport_ImportModule("decimal");
        if (!decimalmod) {
            PyErr_SetString(PyExc_RuntimeError, "Unable to import cdecimal or decimal");
            return false;
        }
    }

    decimal_type = PyObject_GetAttrString(decimalmod, "Decimal");
    Py_DECREF(decimalmod);

    if (decimal_type == 0)
        PyErr_SetString(PyExc_RuntimeError, "Unable to import decimal.Decimal.");

    return decimal_type != 0;
}
Ejemplo n.º 5
0
static bool import_types()
{
    // Note: We can only import types from C extensions since they are shared among all
    // interpreters.  Other classes are imported per-thread via GetClassForThread.

    // In Python 2.5 final, PyDateTime_IMPORT no longer works unless the datetime module was previously
    // imported (among other problems).

    PyObject* pdt = PyImport_ImportModule("datetime");

    if (!pdt)
        return false;

    PyDateTime_IMPORT;

    Cursor_init();
    if (!CnxnInfo_init())
        return false;
    GetData_init();
    if (!Params_init())
        return false;

    return true;
}