mirror of
				https://github.com/psycopg/psycopg2.git
				synced 2025-10-31 15:57:31 +03:00 
			
		
		
		
	Correctly handle exceptions with non-ascii chars in the message
Previous implementation would have barfed in canse of non-utf-8 data in the message.
This commit is contained in:
		
							parent
							
								
									d263ecfee7
								
							
						
					
					
						commit
						8a08114314
					
				|  | @ -593,14 +593,27 @@ psyco_set_error(PyObject *exc, PyObject *curs, const char *msg, | |||
|                 const char *pgerror, const char *pgcode) | ||||
| { | ||||
|     PyObject *t; | ||||
|     PyObject *pymsg; | ||||
|     PyObject *err = NULL; | ||||
|     connectionObject *conn = NULL; | ||||
| 
 | ||||
|     PyObject *err = PyObject_CallFunction(exc, "s", msg); | ||||
|     if (curs) { | ||||
|         conn = ((cursorObject *)curs)->conn; | ||||
|     } | ||||
| 
 | ||||
|     if ((pymsg = conn_text_from_chars(conn, msg))) { | ||||
|         err = PyObject_CallFunctionObjArgs(exc, pymsg, NULL); | ||||
|         Py_DECREF(pymsg); | ||||
|     } | ||||
|     else { | ||||
|         /* what's better than an error in an error handler in the morning?
 | ||||
|          * Anyway, some error was set, refcount is ok... get outta here. */ | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     if (err) { | ||||
|         connectionObject *conn = NULL; | ||||
|         if (curs) { | ||||
|             PyObject_SetAttrString(err, "cursor", curs); | ||||
|             conn = ((cursorObject *)curs)->conn; | ||||
|         } | ||||
| 
 | ||||
|         if (pgerror) { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user