mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-95273: Move sqlite3 executemany examples from reference to tutorial (#95351)
This commit is contained in:
parent
e9c8de669d
commit
f0bf7956e6
3 changed files with 26 additions and 54 deletions
|
@ -1,26 +0,0 @@
|
|||
import sqlite3
|
||||
|
||||
class IterChars:
|
||||
def __init__(self):
|
||||
self.count = ord('a')
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def __next__(self):
|
||||
if self.count > ord('z'):
|
||||
raise StopIteration
|
||||
self.count += 1
|
||||
return (chr(self.count - 1),) # this is a 1-tuple
|
||||
|
||||
con = sqlite3.connect(":memory:")
|
||||
cur = con.cursor()
|
||||
cur.execute("create table characters(c)")
|
||||
|
||||
theIter = IterChars()
|
||||
cur.executemany("insert into characters(c) values (?)", theIter)
|
||||
|
||||
cur.execute("select c from characters")
|
||||
print(cur.fetchall())
|
||||
|
||||
con.close()
|
|
@ -1,17 +0,0 @@
|
|||
import sqlite3
|
||||
import string
|
||||
|
||||
def char_generator():
|
||||
for c in string.ascii_lowercase:
|
||||
yield (c,)
|
||||
|
||||
con = sqlite3.connect(":memory:")
|
||||
cur = con.cursor()
|
||||
cur.execute("create table characters(c)")
|
||||
|
||||
cur.executemany("insert into characters(c) values (?)", char_generator())
|
||||
|
||||
cur.execute("select c from characters")
|
||||
print(cur.fetchall())
|
||||
|
||||
con.close()
|
Loading…
Add table
Add a link
Reference in a new issue