Feature #1077 ยป sqlite3test.py
1 |
import sqlite3, time |
---|---|
2 |
conn = sqlite3.connect(':memory:') |
3 |
cursor = conn.cursor() |
4 |
|
5 |
colnum = 999 |
6 |
rownum = 500 |
7 |
|
8 |
# create table query
|
9 |
columnnames = ["col"+str(i) for i in range(colnum)] |
10 |
createquery = "CREATE TABLE customer(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " |
11 |
for i, name in enumerate(columnnames): |
12 |
createquery = createquery + name + " REAL" |
13 |
if i != colnum-1: |
14 |
createquery = createquery + ", " |
15 |
createquery = createquery + ")" |
16 |
|
17 |
# create table query execution
|
18 |
#print createquery
|
19 |
cursor.execute(createquery) |
20 |
|
21 |
# generating rows data
|
22 |
rows = [] |
23 |
for row in range(rownum): |
24 |
newcol = () |
25 |
for col in range(colnum): |
26 |
newcol = newcol + (row*0.1, ) |
27 |
rows.append(newcol) |
28 |
|
29 |
#print rows
|
30 |
|
31 |
# insert query
|
32 |
insertquery = "INSERT INTO customer(" |
33 |
for i, name in enumerate(columnnames): |
34 |
insertquery = insertquery + name |
35 |
if i != colnum-1: |
36 |
insertquery = insertquery + ", " |
37 |
insertquery = insertquery + ") VALUES(" |
38 |
for i in range(colnum): |
39 |
insertquery = insertquery + "?" |
40 |
if i != colnum-1: |
41 |
insertquery = insertquery + ", " |
42 |
insertquery = insertquery + ")" |
43 |
#print insertquery
|
44 |
|
45 |
|
46 |
# starting timer
|
47 |
t = time.time() |
48 |
|
49 |
# insert query execution
|
50 |
conn.executemany(insertquery, rows) |
51 |
conn.commit() |
52 |
|
53 |
print "\n Time Taken: %.3f sec" % (time.time()-t) |