mirror of
				https://github.com/psycopg/psycopg2.git
				synced 2025-10-30 07:17:28 +03:00 
			
		
		
		
	conn_commit/conn_rollback error handling (closes: #187).
This commit is contained in:
		
							parent
							
								
									a07987cd90
								
							
						
					
					
						commit
						46668d214b
					
				|  | @ -1,5 +1,8 @@ | ||||||
| 2007-05-29  Federico Di Gregorio  <fog@initd.org> | 2007-05-29  Federico Di Gregorio  <fog@initd.org> | ||||||
| 
 | 
 | ||||||
|  | 	* Applied patch from mkz (ticket #187) to add error handling when calling | ||||||
|  | 	conn_commit() and conn_rollback(). Fixes #187. | ||||||
|  | 
 | ||||||
| 	* cursor.copy_expert() implementation by David Rushby (copy_expert set 5/5.) | 	* cursor.copy_expert() implementation by David Rushby (copy_expert set 5/5.) | ||||||
| 
 | 
 | ||||||
| 	* SQL validation refactor patch from David Rushby (copy_expert set 4/5.) | 	* SQL validation refactor patch from David Rushby (copy_expert set 4/5.) | ||||||
|  |  | ||||||
|  | @ -117,8 +117,11 @@ psyco_conn_commit(connectionObject *self, PyObject *args) | ||||||
| 
 | 
 | ||||||
|     if (!PyArg_ParseTuple(args, "")) return NULL; |     if (!PyArg_ParseTuple(args, "")) return NULL; | ||||||
| 
 | 
 | ||||||
|     /* FIXME: check return status? */ |     if (conn_commit(self) < 0) { | ||||||
|     conn_commit(self); |         PyErr_SetString(OperationalError, | ||||||
|  |                         PQerrorMessage(self->pgconn)); | ||||||
|  |         return NULL; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     Py_INCREF(Py_None); |     Py_INCREF(Py_None); | ||||||
|     return Py_None; |     return Py_None; | ||||||
|  | @ -137,8 +140,11 @@ psyco_conn_rollback(connectionObject *self, PyObject *args) | ||||||
| 
 | 
 | ||||||
|     if (!PyArg_ParseTuple(args, "")) return NULL; |     if (!PyArg_ParseTuple(args, "")) return NULL; | ||||||
| 
 | 
 | ||||||
|     /* FIXME: check return status? */ |     if (conn_rollback(self) < 0) { | ||||||
|     conn_rollback(self); |         PyErr_SetString(OperationalError, | ||||||
|  |                         PQerrorMessage(self->pgconn)); | ||||||
|  |         return NULL; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     Py_INCREF(Py_None); |     Py_INCREF(Py_None); | ||||||
|     return Py_None; |     return Py_None; | ||||||
|  | @ -167,8 +173,12 @@ psyco_conn_set_isolation_level(connectionObject *self, PyObject *args) | ||||||
|         return NULL; |         return NULL; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /* FIXME: check return status? */ |     if (conn_switch_isolation_level(self, level) < 0) { | ||||||
|     conn_switch_isolation_level(self, level); |         PyErr_SetString(OperationalError, | ||||||
|  |                         PQerrorMessage(self->pgconn)); | ||||||
|  |         return NULL; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
|     Py_INCREF(Py_None); |     Py_INCREF(Py_None); | ||||||
|     return Py_None; |     return Py_None; | ||||||
|  |  | ||||||
|  | @ -397,13 +397,29 @@ pq_execute(cursorObject *curs, const char *query, int async) | ||||||
|     Py_BEGIN_ALLOW_THREADS; |     Py_BEGIN_ALLOW_THREADS; | ||||||
|     pthread_mutex_lock(&(curs->conn->lock)); |     pthread_mutex_lock(&(curs->conn->lock)); | ||||||
| 
 | 
 | ||||||
|     pq_begin(curs->conn); |     if (pq_begin(curs->conn) < 0) { | ||||||
|  |         pthread_mutex_unlock(&(curs->conn->lock)); | ||||||
|  |         Py_BLOCK_THREADS; | ||||||
|  |         PyErr_SetString(OperationalError, | ||||||
|  |                         PQerrorMessage(curs->conn->pgconn)); | ||||||
|  |         return -1; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     if (async == 0) { |     if (async == 0) { | ||||||
|         IFCLEARPGRES(curs->pgres); |         IFCLEARPGRES(curs->pgres); | ||||||
|         Dprintf("pq_execute: executing SYNC query:"); |         Dprintf("pq_execute: executing SYNC query:"); | ||||||
|         Dprintf("    %-.200s", query); |         Dprintf("    %-.200s", query); | ||||||
|         curs->pgres = PQexec(curs->conn->pgconn, query); |         curs->pgres = PQexec(curs->conn->pgconn, query); | ||||||
|  | 
 | ||||||
|  |         /* dont let pgres = NULL go to pq_fetch() */ | ||||||
|  |         /* if (curs->pgres == NULL) {
 | ||||||
|  |             pthread_mutex_unlock(&(curs->conn->lock)); | ||||||
|  |             Py_BLOCK_THREADS; | ||||||
|  |             PyErr_SetString(OperationalError, | ||||||
|  |                             PQerrorMessage(curs->conn->pgconn)); | ||||||
|  |             return -1; | ||||||
|  |         } | ||||||
|  |         */ | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     else if (async == 1) { |     else if (async == 1) { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user