src/PythonHandler.h
branchv_0
changeset 13 df354b680b89
parent 12 ee69be2212fa
child 14 9ed7c3b6ad7a
equal deleted inserted replaced
12:ee69be2212fa 13:df354b680b89
   105 			if (currentAttributeIndex > 0 && currentAttributeIndex % currentRecord.size() == 0) {
   105 			if (currentAttributeIndex > 0 && currentAttributeIndex % currentRecord.size() == 0) {
   106 
   106 
   107 				PyObject* pyModule;
   107 				PyObject* pyModule;
   108 				PyObject* pyDict;
   108 				PyObject* pyDict;
   109 				PyObject* pyWhere;
   109 				PyObject* pyWhere;
       
   110 				PyObject* pyRecord = PyTuple_New(currentRecord.size());
       
   111 
       
   112 				//PyUnicode_FromWideChar()
       
   113 
       
   114 				for (int i = 0; i < currentRecord.size(); i++) {
       
   115 					PyTuple_SetItem(pyRecord, i, PyUnicode_FromString(convertor.to_bytes(currentRecord[i]).c_str()));
       
   116 				}
       
   117 
       
   118 				pyModule = PyImport_AddModule((char*) "__main__"); // FIXME: variable and Py_DecodeLocale ?
       
   119 				pyDict = PyModule_GetDict(pyModule);
       
   120 				PyDict_SetItemString(pyDict, "record", pyRecord);
   110 
   121 
   111 				PyRun_SimpleString(convertor.to_bytes(pythonCode).c_str());
   122 				PyRun_SimpleString(convertor.to_bytes(pythonCode).c_str());
   112 				
   123 
   113 				// FIXME: check Python error and throw exception
   124 				// FIXME: check Python error and throw exception
   114 				// if (PyErr_Occurred()) throw cli::RelpipeCLIException(L"Python code failed.", cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); // TODO: review exit code
   125 				// if (PyErr_Occurred()) throw cli::RelpipeCLIException(L"Python code failed.", cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); // TODO: review exit code
   115 				// if (PyErr_Occurred()) { PyErr_Print(); PyErr_Clear(); }
   126 				// if (PyErr_Occurred()) { PyErr_Print(); PyErr_Clear(); }
   116 
   127 
   117 				pyModule = PyImport_AddModule((char*) "__main__"); // FIXME: variable and Py_DecodeLocale ?
   128 
   118 				pyDict = PyModule_GetDict(pyModule);
       
   119 				pyWhere = PyDict_GetItemString(pyDict, "WHERE");
   129 				pyWhere = PyDict_GetItemString(pyDict, "WHERE");
   120 
   130 
   121 				if (pyWhere) includeCurrentRecord = PyLong_AsLong(pyWhere);
   131 				if (pyWhere) includeCurrentRecord = PyLong_AsLong(pyWhere);
   122 
   132 
   123 
   133