mirror of
				https://github.com/LonamiWebs/Telethon.git
				synced 2025-11-01 00:17:47 +03:00 
			
		
		
		
	Close sqlite's cursor after usage
This commit is contained in:
		
							parent
							
								
									4da50ba3a0
								
							
						
					
					
						commit
						313bead615
					
				|  | @ -280,14 +280,18 @@ class SQLiteSession(MemorySession): | ||||||
|         if not rows: |         if not rows: | ||||||
|             return |             return | ||||||
| 
 | 
 | ||||||
|         self._cursor().executemany( |         c = self._cursor() | ||||||
|  |         c.executemany( | ||||||
|             'insert or replace into entities values (?,?,?,?,?)', rows |             'insert or replace into entities values (?,?,?,?,?)', rows | ||||||
|         ) |         ) | ||||||
|  |         c.close() | ||||||
| 
 | 
 | ||||||
|     def _fetchone_entity(self, query, args): |     def _fetchone_entity(self, query, args): | ||||||
|         c = self._cursor() |         c = self._cursor() | ||||||
|         c.execute(query, args) |         c.execute(query, args) | ||||||
|         return c.fetchone() |         t = c.fetchone() | ||||||
|  |         c.close() | ||||||
|  |         return t | ||||||
| 
 | 
 | ||||||
|     def get_entity_rows_by_phone(self, phone): |     def get_entity_rows_by_phone(self, phone): | ||||||
|         return self._fetchone_entity( |         return self._fetchone_entity( | ||||||
|  | @ -318,11 +322,13 @@ class SQLiteSession(MemorySession): | ||||||
|     # File processing |     # File processing | ||||||
| 
 | 
 | ||||||
|     def get_file(self, md5_digest, file_size, cls): |     def get_file(self, md5_digest, file_size, cls): | ||||||
|         tuple_ = self._cursor().execute( |         c = self._cursor() | ||||||
|  |         tuple_ = c.execute( | ||||||
|             'select id, hash from sent_files ' |             'select id, hash from sent_files ' | ||||||
|             'where md5_digest = ? and file_size = ? and type = ?', |             'where md5_digest = ? and file_size = ? and type = ?', | ||||||
|             (md5_digest, file_size, _SentFileType.from_type(cls).value) |             (md5_digest, file_size, _SentFileType.from_type(cls).value) | ||||||
|         ).fetchone() |         ).fetchone() | ||||||
|  |         c.close() | ||||||
|         if tuple_: |         if tuple_: | ||||||
|             # Both allowed classes have (id, access_hash) as parameters |             # Both allowed classes have (id, access_hash) as parameters | ||||||
|             return cls(tuple_[0], tuple_[1]) |             return cls(tuple_[0], tuple_[1]) | ||||||
|  | @ -331,9 +337,11 @@ class SQLiteSession(MemorySession): | ||||||
|         if not isinstance(instance, (InputDocument, InputPhoto)): |         if not isinstance(instance, (InputDocument, InputPhoto)): | ||||||
|             raise TypeError('Cannot cache %s instance' % type(instance)) |             raise TypeError('Cannot cache %s instance' % type(instance)) | ||||||
| 
 | 
 | ||||||
|         self._cursor().execute( |         c = self._cursor() | ||||||
|  |         c.execute( | ||||||
|             'insert or replace into sent_files values (?,?,?,?,?)', ( |             'insert or replace into sent_files values (?,?,?,?,?)', ( | ||||||
|                 md5_digest, file_size, |                 md5_digest, file_size, | ||||||
|                 _SentFileType.from_type(type(instance)).value, |                 _SentFileType.from_type(type(instance)).value, | ||||||
|                 instance.id, instance.access_hash |                 instance.id, instance.access_hash | ||||||
|         )) |         )) | ||||||
|  |         c.close() | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user