File: createtestdb.py

package info (click to toggle)
sqlitebrowser 3.10.1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 10,616 kB
  • sloc: cpp: 89,765; xml: 45; python: 27; sh: 7; makefile: 5
file content (34 lines) | stat: -rwxr-xr-x 858 bytes parent folder | download | duplicates (3)
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
31
32
33
34
#!/usr/bin/python
import sys
import os
import random
import string
import sqlite3

CREATE = """
CREATE TABLE IF NOT EXISTS hugetable (
   id   INTEGER PRIMARY KEY AUTOINCREMENT,
   weirdtext   TEXT,
   crazynumber REAL
);
"""

def main():
    if len(sys.argv) != 2:
        sys.exit("please specify the db filename")

    with sqlite3.connect(sys.argv[1]) as c:
        c.executescript(CREATE)

        rowcount = 1000000
        for i in range(rowcount):
            text = "".join( [random.choice(string.ascii_letters) for i in range(200)] )
            num = random.random() * random.randint(0, 2930)
            c.execute("INSERT INTO hugetable(weirdtext, crazynumber) VALUES ( :t, :n);", {"t": text, "n": num})
            if i % 1000 == 0:
                print("inserted", i, "of", rowcount)
        c.commit()


if __name__ == "__main__":
    main()