mirror of
				https://github.com/psycopg/psycopg2.git
				synced 2025-10-31 07:47:30 +03:00 
			
		
		
		
	Collect rowcount in executemany even when discarding results
Closes #633.
This commit is contained in:
		
							parent
							
								
									727b952a32
								
							
						
					
					
						commit
						65ed5478d1
					
				
							
								
								
									
										4
									
								
								NEWS
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								NEWS
									
									
									
									
									
								
							|  | @ -13,10 +13,12 @@ What's new in psycopg 2.7.4 | ||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||||||
| 
 | 
 | ||||||
| - Fixed Solaris 10 support (:ticket:`#532`). | - Fixed Solaris 10 support (:ticket:`#532`). | ||||||
| - Fixed `!MinTimeLoggingCursor` on Python 3 (:ticket:`#609`). | - Fixed `~psycopg2.extras.MinTimeLoggingCursor` on Python 3 (:ticket:`#609`). | ||||||
| - Fixed parsing of array of points as floats (:ticket:`#613`). | - Fixed parsing of array of points as floats (:ticket:`#613`). | ||||||
| - Fixed `~psycopg2.__libpq_version__` building with libpq >= 10.1 | - Fixed `~psycopg2.__libpq_version__` building with libpq >= 10.1 | ||||||
|   (:ticket:`632`). |   (:ticket:`632`). | ||||||
|  | - Fixed `~cursor.rowcount` after `~cursor.executemany()` with :sql:`RETURNING` statements | ||||||
|  |   (:ticket:`633`). | ||||||
| - Wheel packages compiled against PostgreSQL 10.1 libpq and OpenSSL 1.0.2m. | - Wheel packages compiled against PostgreSQL 10.1 libpq and OpenSSL 1.0.2m. | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1952,8 +1952,9 @@ pq_fetch(cursorObject *curs, int no_result) | ||||||
|         } |         } | ||||||
|         else { |         else { | ||||||
|             Dprintf("pq_fetch: got tuples, discarding them"); |             Dprintf("pq_fetch: got tuples, discarding them"); | ||||||
|  |             /* TODO: is there any case in which PQntuples == PQcmdTuples? */ | ||||||
|  |             _read_rowcount(curs); | ||||||
|             CLEARPGRES(curs->pgres); |             CLEARPGRES(curs->pgres); | ||||||
|             curs->rowcount = -1; |  | ||||||
|             ex = 0; |             ex = 0; | ||||||
|         } |         } | ||||||
|         break; |         break; | ||||||
|  |  | ||||||
|  | @ -583,6 +583,20 @@ class CursorTests(ConnectingTestCase): | ||||||
| 
 | 
 | ||||||
|             self.assertEqual(victim_conn.closed, 2) |             self.assertEqual(victim_conn.closed, 2) | ||||||
| 
 | 
 | ||||||
|  |     @skip_before_postgres(8, 2) | ||||||
|  |     def test_rowcount_on_executemany_returning(self): | ||||||
|  |         cur = self.conn.cursor() | ||||||
|  |         cur.execute("create table execmany(id serial primary key, data int)") | ||||||
|  |         cur.executemany( | ||||||
|  |             "insert into execmany (data) values (%s)", | ||||||
|  |             [(i,) for i in range(4)]) | ||||||
|  |         self.assertEqual(cur.rowcount, 4) | ||||||
|  | 
 | ||||||
|  |         cur.executemany( | ||||||
|  |             "insert into execmany (data) values (%s) returning data", | ||||||
|  |             [(i,) for i in range(5)]) | ||||||
|  |         self.assertEqual(cur.rowcount, 5) | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| def test_suite(): | def test_suite(): | ||||||
|     return unittest.TestLoader().loadTestsFromName(__name__) |     return unittest.TestLoader().loadTestsFromName(__name__) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user