Skip to content

Instantly share code, notes, and snippets.

@pbojinov
Created June 10, 2014 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbojinov/ee67ab04d5d3cea86fd6 to your computer and use it in GitHub Desktop.
Save pbojinov/ee67ab04d5d3cea86fd6 to your computer and use it in GitHub Desktop.
Create and populate a sqlite database using python sqlite3 adapter
# first create a databse, from the command line run
# > touch hello_world.db
from datetime import datetime, timedelta
import sqlite3
conn = sqlite3.connect('hello_world.db')
c = conn.cursor()
# Create table
c.execute('''
CREATE TABLE tlds
(tld text, tag text, vertical text, brand text, cc text, url text)''')
# sample dummy data
tld = 'abcdefghijkk'
tag = 'abcdefghijk'
vertical = 'abcdefghijk'
brand = 'abcdefghijk'
cc = 'us'
url = 'abcdefghijklmnobqrstuvwxyz1234567890'
query = "INSERT INTO tlds VALUES ('%s','%s','%s','%s','%s','%s')" % (tld, tag, vertical, brand, cc, url)
print query # to make sure we have the right thing
# do 2 million entries
for i in range(0,2000000):
# Insert a row of data
c.execute(query)
print 'insert # %d' % i
# Save (commit) the changes
conn.commit()
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
conn.close()
print 'done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment