mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 18:28:49 +00:00 
			
		
		
		
	 287b84de93
			
		
	
	
		287b84de93
		
	
	
	
	
		
			
			The sqlit3.Connection object doesn't call its close() method when it's used as a context manager.
		
			
				
	
	
		
			18 lines
		
	
	
	
		
			399 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			18 lines
		
	
	
	
		
			399 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| import sqlite3
 | |
| 
 | |
| con = sqlite3.connect(":memory:")
 | |
| cur = con.cursor()
 | |
| cur.execute("create table people (name_last, age)")
 | |
| 
 | |
| who = "Yeltsin"
 | |
| age = 72
 | |
| 
 | |
| # This is the qmark style:
 | |
| cur.execute("insert into people values (?, ?)", (who, age))
 | |
| 
 | |
| # And this is the named style:
 | |
| cur.execute("select * from people where name_last=:who and age=:age", {"who": who, "age": age})
 | |
| 
 | |
| print(cur.fetchone())
 | |
| 
 | |
| con.close()
 |