mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 02:15:10 +00:00 
			
		
		
		
	 287b84de93
			
		
	
	
		287b84de93
		
	
	
	
	
		
			
			The sqlit3.Connection object doesn't call its close() method when it's used as a context manager.
		
			
				
	
	
		
			17 lines
		
	
	
	
		
			323 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			17 lines
		
	
	
	
		
			323 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| import sqlite3
 | |
| import datetime
 | |
| import time
 | |
| 
 | |
| def adapt_datetime(ts):
 | |
|     return time.mktime(ts.timetuple())
 | |
| 
 | |
| sqlite3.register_adapter(datetime.datetime, adapt_datetime)
 | |
| 
 | |
| con = sqlite3.connect(":memory:")
 | |
| cur = con.cursor()
 | |
| 
 | |
| now = datetime.datetime.now()
 | |
| cur.execute("select ?", (now,))
 | |
| print(cur.fetchone()[0])
 | |
| 
 | |
| con.close()
 |