modify records from Python: r[1] = "hello from Python" v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Fri, 14 Dec 2018 02:03:24 +0100
branchv_0
changeset 14 9ed7c3b6ad7a
parent 13 df354b680b89
child 15 60a17d8fc223
modify records from Python: r[1] = "hello from Python"
src/PythonHandler.h
--- a/src/PythonHandler.h	Fri Dec 14 01:26:33 2018 +0100
+++ b/src/PythonHandler.h	Fri Dec 14 02:03:24 2018 +0100
@@ -107,17 +107,17 @@
 				PyObject* pyModule;
 				PyObject* pyDict;
 				PyObject* pyWhere;
-				PyObject* pyRecord = PyTuple_New(currentRecord.size());
+				PyObject* pyRecord = PyList_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()));
+					PyList_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);
+				PyDict_SetItemString(pyDict, "r", pyRecord);
 
 				PyRun_SimpleString(convertor.to_bytes(pythonCode).c_str());
 
@@ -131,6 +131,14 @@
 				if (pyWhere) includeCurrentRecord = PyLong_AsLong(pyWhere);
 
 
+				if (includeCurrentRecord) {
+					for (int i = 0; i < currentRecord.size(); i++) {
+						Py_ssize_t l;
+						currentRecord[i] = wstring(PyUnicode_AsWideCharString(PyList_GetItem(pyRecord, i), &l));
+					}
+				}
+
+
 				if (includeCurrentRecord) for (string_t v : currentRecord) relationalWriter->writeAttribute(v);
 				includeCurrentRecord = true;
 			}