import sqlite3 import random import string conn sqlite3 connect test d

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import sqlite3
import random
import string
conn = sqlite3.connect('test.db')
c = conn.cursor()
def generate_random_strings(number=6000, min_length=6, max_length=16):
for index in range(number):
yield ''.join(
[random.choice(string.ascii_letters) for _ in range(random.randint(min_length, max_length))]
)
# drop
c.execute('''DROP TABLE users;''')
# Create table
c.execute('''CREATE TABLE users
(name text, user_id integer)''')
# Insert a row of data
for index, name in enumerate(generate_random_strings()):
c.execute("INSERT INTO users VALUES ('{}','{}')".format(name, index))
conn.commit()
for row in c.execute('''SELECT name FROM users WHERE (user_id > 1234 AND user_id < 1334) ORDER BY name'''):
print row
conn.close()