--- 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;
}