| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | import sqlite3 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-15 22:17:21 +02:00
										 |  |  | con = sqlite3.connect(":memory:") | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | cur = con.cursor() | 
					
						
							| 
									
										
										
										
											2021-04-14 14:28:55 +02:00
										 |  |  | cur.execute("create table lang (lang_name, lang_age)") | 
					
						
							| 
									
										
										
										
											2007-08-15 14:28:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-15 22:17:21 +02:00
										 |  |  | # This is the qmark style: | 
					
						
							| 
									
										
										
										
											2021-04-14 14:28:55 +02:00
										 |  |  | cur.execute("insert into lang values (?, ?)", ("C", 49)) | 
					
						
							| 
									
										
										
										
											2012-02-15 22:17:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-14 14:28:55 +02:00
										 |  |  | # The qmark style used with executemany(): | 
					
						
							|  |  |  | lang_list = [ | 
					
						
							|  |  |  |     ("Fortran", 64), | 
					
						
							|  |  |  |     ("Python", 30), | 
					
						
							|  |  |  |     ("Go", 11), | 
					
						
							|  |  |  | ] | 
					
						
							|  |  |  | cur.executemany("insert into lang values (?, ?)", lang_list) | 
					
						
							| 
									
										
										
										
											2012-02-15 22:17:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-14 14:28:55 +02:00
										 |  |  | # And this is the named style: | 
					
						
							|  |  |  | cur.execute("select * from lang where lang_name=:name and lang_age=:age", | 
					
						
							|  |  |  |             {"name": "C", "age": 49}) | 
					
						
							|  |  |  | print(cur.fetchall()) | 
					
						
							| 
									
										
										
										
											2019-05-20 03:22:20 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | con.close() |