# HG changeset patch # User František Kučera # Date 1544749404 -3600 # Node ID 9ed7c3b6ad7a9c12f3fd59be4600b41fdffbf7dd # Parent df354b680b890031481229fa38508b9518e9024d modify records from Python: r[1] = "hello from Python" diff -r df354b680b89 -r 9ed7c3b6ad7a 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; }