Switch to unified view

a/src/python/recoll/pyrecoll.cpp b/src/python/recoll/pyrecoll.cpp
...
...
15
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16
 */
16
 */
17
17
18
#include <Python.h>
18
#include <Python.h>
19
#include <structmember.h>
19
#include <structmember.h>
20
#include <bytearrayobject.h>
20
#include <bytesobject.h>
21
21
22
#include <strings.h>
22
#include <strings.h>
23
23
24
#include <string>
24
#include <string>
25
#include <iostream>
25
#include <iostream>
...
...
342
    if (self->doc == 0 || 
342
    if (self->doc == 0 || 
343
    the_docs.find(self->doc) == the_docs.end()) {
343
    the_docs.find(self->doc) == the_docs.end()) {
344
        PyErr_SetString(PyExc_AttributeError, "doc");
344
        PyErr_SetString(PyExc_AttributeError, "doc");
345
    return 0;
345
    return 0;
346
    }
346
    }
347
    return PyByteArray_FromStringAndSize(self->doc->url.c_str(), 
347
    return PyBytes_FromStringAndSize(self->doc->url.c_str(), 
348
                   self->doc->url.size());
348
                     self->doc->url.size());
349
}
349
}
350
350
351
PyDoc_STRVAR(doc_Doc_setbinurl,
351
PyDoc_STRVAR(doc_Doc_setbinurl,
352
"setbinurl(url) -> binary url\n"
352
"setbinurl(url) -> binary url\n"
353
"\n"
353
"\n"
...
...
759
    PyObject_HEAD
759
    PyObject_HEAD
760
    /* Type-specific fields go here. */
760
    /* Type-specific fields go here. */
761
    Rcl::Query *query;
761
    Rcl::Query *query;
762
    int         next; // Index of result to be fetched next or -1 if uninit
762
    int         next; // Index of result to be fetched next or -1 if uninit
763
    int         rowcount; // Number of records returned by last execute
763
    int         rowcount; // Number of records returned by last execute
764
    string      *sortfield;
764
    string      *sortfield; // Need to allocate in here, main program is C.
765
    int         ascending;
765
    int         ascending;
766
    int         arraysize; // Default size for fetchmany
766
    int         arraysize; // Default size for fetchmany
767
    recoll_DbObject* connection;
767
    recoll_DbObject* connection;
768
} recoll_QueryObject;
768
} recoll_QueryObject;
769
769
...
...
897
    if (sstemlang) {
897
    if (sstemlang) {
898
    stemlang.assign(sstemlang);
898
    stemlang.assign(sstemlang);
899
    PyMem_Free(sstemlang);
899
    PyMem_Free(sstemlang);
900
    }
900
    }
901
901
902
    LOGDEB(("Query_execute: [%s] dostem %d stemlang [%s]\n", sutf8, dostem,
902
    LOGDEB(("Query_execute: [%s] dostem %d stemlang [%s]\n", utf8.c_str(), 
903
        stemlang.c_str()));
903
        dostem, stemlang.c_str()));
904
904
905
    if (self->query == 0 || 
905
    if (self->query == 0 || 
906
    the_queries.find(self->query) == the_queries.end()) {
906
    the_queries.find(self->query) == the_queries.end()) {
907
        PyErr_SetString(PyExc_AttributeError, "query");
907
        PyErr_SetString(PyExc_AttributeError, "query");
908
    return 0;
908
    return 0;
...
...
997
    if (!result) {
997
    if (!result) {
998
        PyErr_SetString(PyExc_EnvironmentError, "doc create failed");
998
        PyErr_SetString(PyExc_EnvironmentError, "doc create failed");
999
    return 0;
999
    return 0;
1000
    }
1000
    }
1001
    if (self->next >= self->rowcount) {
1001
    if (self->next >= self->rowcount) {
1002
        PyErr_SetString(PyExc_StopIteration, "End of list reached");
1002
        PyErr_SetNone(PyExc_StopIteration);
1003
    return 0;
1003
    return 0;
1004
    }
1004
    }
1005
    if (!self->query->getDoc(self->next, *result->doc)) {
1005
    if (!self->query->getDoc(self->next, *result->doc)) {
1006
        PyErr_SetString(PyExc_EnvironmentError, "query: cant fetch result");
1006
        PyErr_SetString(PyExc_EnvironmentError, "query: cant fetch result");
1007
    self->next = -1;
1007
    self->next = -1;
...
...
1087
        isrelative = 1;
1087
        isrelative = 1;
1088
    } else if (!strcasecmp(smode, "absolute")) {
1088
    } else if (!strcasecmp(smode, "absolute")) {
1089
        isrelative = 0;
1089
        isrelative = 0;
1090
    } else {
1090
    } else {
1091
        PyErr_SetString(PyExc_ValueError, "bad mode value");
1091
        PyErr_SetString(PyExc_ValueError, "bad mode value");
1092
      return 0;
1092
    }
1093
    }
1093
    } 
1094
    } 
1094
1095
1095
    if (self->query == 0 || 
1096
    if (self->query == 0 || 
1096
    the_queries.find(self->query) == the_queries.end()) {
1097
    the_queries.find(self->query) == the_queries.end()) {
1097
        PyErr_SetString(PyExc_AttributeError, "query");
1098
        PyErr_SetString(PyExc_AttributeError, "null query");
1098
    return 0;
1099
    return 0;
1099
    }
1100
    }
1100
    int newpos = isrelative ? self->next + pos : pos;
1101
    int newpos = isrelative ? self->next + pos : pos;
1101
    if (newpos < 0 || newpos >= self->rowcount) {
1102
    if (newpos < 0 || newpos >= self->rowcount) {
1102
        PyErr_SetString(PyExc_IndexError, "position out of range");
1103
        PyErr_SetString(PyExc_IndexError, "position out of range");
...
...
1289
"Meaningful only after executexx\n"
1290
"Meaningful only after executexx\n"
1290
);
1291
);
1291
static PyObject *
1292
static PyObject *
1292
Query_getxquery(recoll_QueryObject* self, PyObject *, PyObject *)
1293
Query_getxquery(recoll_QueryObject* self, PyObject *, PyObject *)
1293
{
1294
{
1294
    LOGDEB(("Query_getxquery\n"));
1295
    LOGDEB(("Query_getxquery self->query %p\n"));
1295
1296
1296
    if (self->query == 0 || 
1297
    if (self->query == 0 || 
1297
    the_queries.find(self->query) == the_queries.end()) {
1298
    the_queries.find(self->query) == the_queries.end()) {
1298
        PyErr_SetString(PyExc_AttributeError, "query");
1299
        PyErr_SetString(PyExc_AttributeError, "query");
1299
    return 0;
1300
    return 0;
...
...
1585
    result->query = new Rcl::Query(self->db);
1586
    result->query = new Rcl::Query(self->db);
1586
    result->connection = self;
1587
    result->connection = self;
1587
    Py_INCREF(self);
1588
    Py_INCREF(self);
1588
1589
1589
    the_queries.insert(result->query);
1590
    the_queries.insert(result->query);
1591
    Py_INCREF(result);
1590
    return (PyObject *)result;
1592
    return (PyObject *)result;
1591
}
1593
}
1592
1594
1593
static PyObject *
1595
static PyObject *
1594
Db_setAbstractParams(recoll_DbObject *self, PyObject *args, PyObject *kwargs)
1596
Db_setAbstractParams(recoll_DbObject *self, PyObject *args, PyObject *kwargs)