# HG changeset patch # User František Kučera # Date 1544747193 -3600 # Node ID df354b680b890031481229fa38508b9518e9024d # Parent ee69be2212faf66fcd8c3411b524329aae82d988 pass record data from C++ to Python and filtering: WHERE = record[0] == "a" diff -r ee69be2212fa -r df354b680b89 src/PythonHandler.h --- a/src/PythonHandler.h Fri Dec 14 00:14:58 2018 +0100 +++ b/src/PythonHandler.h Fri Dec 14 01:26:33 2018 +0100 @@ -107,15 +107,25 @@ PyObject* pyModule; PyObject* pyDict; PyObject* pyWhere; + PyObject* pyRecord = PyTuple_New(currentRecord.size()); + + //PyUnicode_FromWideChar() + + for (int i = 0; i < currentRecord.size(); i++) { + PyTuple_SetItem(pyRecord, i, PyUnicode_FromString(convertor.to_bytes(currentRecord[i]).c_str())); + } + + pyModule = PyImport_AddModule((char*) "__main__"); // FIXME: variable and Py_DecodeLocale ? + pyDict = PyModule_GetDict(pyModule); + PyDict_SetItemString(pyDict, "record", pyRecord); PyRun_SimpleString(convertor.to_bytes(pythonCode).c_str()); - + // FIXME: check Python error and throw exception // if (PyErr_Occurred()) throw cli::RelpipeCLIException(L"Python code failed.", cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); // TODO: review exit code // if (PyErr_Occurred()) { PyErr_Print(); PyErr_Clear(); } - pyModule = PyImport_AddModule((char*) "__main__"); // FIXME: variable and Py_DecodeLocale ? - pyDict = PyModule_GetDict(pyModule); + pyWhere = PyDict_GetItemString(pyDict, "WHERE"); if (pyWhere) includeCurrentRecord = PyLong_AsLong(pyWhere);