# HG changeset patch # User František Kučera # Date 1544742898 -3600 # Node ID ee69be2212faf66fcd8c3411b524329aae82d988 # Parent 5e0b317f4100638bdbf7d70f8c5feae427ad77d1 relational restriction possible through Python: WHERE = False diff -r 5e0b317f4100 -r ee69be2212fa src/PythonHandler.h --- a/src/PythonHandler.h Thu Dec 13 19:40:29 2018 +0100 +++ b/src/PythonHandler.h Fri Dec 14 00:14:58 2018 +0100 @@ -69,7 +69,7 @@ pythonProgramName = Py_DecodeLocale("relpipe-tr-python", NULL); Py_SetProgramName(pythonProgramName); Py_Initialize(); - + if (arguments.size() == 2) { relationNameRegEx = wregex(arguments[0]); pythonCode = arguments[1]; @@ -103,7 +103,24 @@ currentAttributeIndex++; if (currentAttributeIndex > 0 && currentAttributeIndex % currentRecord.size() == 0) { + + PyObject* pyModule; + PyObject* pyDict; + PyObject* pyWhere; + 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); + + if (includeCurrentRecord) for (string_t v : currentRecord) relationalWriter->writeAttribute(v); includeCurrentRecord = true; }