pass record data from C++ to Python and filtering: WHERE = record[0] == "a" v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Fri, 14 Dec 2018 01:26:33 +0100
branchv_0
changeset 13 df354b680b89
parent 12 ee69be2212fa
child 14 9ed7c3b6ad7a
pass record data from C++ to Python and filtering: WHERE = record[0] == "a"
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);