Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Z

  • Loading branch information...
commit 6e85d3756474b3db354d2856897334657d74f90d 1 parent 5903bdf
Mike Zamansky zamansky authored
Showing with 61 additions and 0 deletions.
  1. +15 −0 sql/create.py
  2. +10 −0 sql/names
  3. +26 −0 sql/populate.py
  4. +10 −0 sql/quotes
15 sql/create.py
View
@@ -0,0 +1,15 @@
+import sqlite3
+
+conn = sqlite3.connect('test.db')
+
+c=conn.cursor()
+
+c.execute('''
+CREATE TABLE people (name text, id integer)
+''')
+
+c.execute('''
+CREATE TABLE quotes (id integer,quote text)
+''')
+
+conn.commit()
10 sql/names
View
@@ -0,0 +1,10 @@
+mike,1
+steve,2
+fred,3
+sarah,4
+teo,5
+ismael,6
+shanna,7
+dana,8
+melissa,9
+james,10
26 sql/populate.py
View
@@ -0,0 +1,26 @@
+import sqlite3
+
+conn = sqlite3.connect('test.db')
+
+
+c=conn.cursor()
+basestring="INSERT INTO PEOPLE VALUES( '%s' , %s)"
+for line in open("names").readlines():
+ line=line.strip()
+ (name,idnum)=line.split(",")
+ q=basestring%(name,idnum)
+ c.execute(q)
+ print q
+
+basestring="insert into quotes %s"
+
+
+# this is a little messy, but it lets us add lots of
+# records in one shot (using the union select stuff
+l=[ x.strip().split(",") for x in open("quotes").readlines()]
+l=[ " select %s, '%s' "%(x[0],x[1]) for x in l]
+thevalues="\nunion\n".join(l)
+q=basestring%(thevalues)
+print q
+c.execute(q)
+conn.commit()
10 sql/quotes
View
@@ -0,0 +1,10 @@
+1,Where does how go
+2,when you see a fork in the road - take it
+3,90 percent of the game is half mental
+1,who is john galt
+3,life is short - no - its the longest thing you do
+4,a person who never made a mistake never tried something new
+2,I may be drunk miss - but in the morning Ill be sober and you will stil be ugly
+1,He was going to live forever - or die in the attempt
+1,Anything worth dying for is worth living for
+2,just because youre paranoid doesnt mean theyre not after you
Please sign in to comment.
Something went wrong with that request. Please try again.