Last active
August 29, 2015 14:07
Revisions
-
gregroberts revised this gist
Oct 2, 2014 . 1 changed file with 18 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,23 +1,26 @@ import sqlite3 #this one line is all you need to set up a database connection = sqlite3.connect('example') #a cursor object is used to execute queries against the db cursor = connection.cursor() #create a table cursor.execute('CREATE TABLE example (id real, value text)') #insert 100 values into the table for i in range(100): cursor.execute('INSERT INTO example VALUES (%d, \'%s\')' % (i, 'value %s' % str(i))) #commit the records to memory connection.commit() 0: <sqlite3.Cursor object at 0x02601C20> #select a slice of the data cursor.execute('SELECT * from example where id > 90').fetchall() 2: [(91.0, u'value 91'), (92.0, u'value 92'), (93.0, u'value 93'), @@ -27,5 +30,4 @@ (97.0, u'value 97'), (98.0, u'value 98'), (99.0, u'value 99')]
-
gregroberts revised this gist
Oct 2, 2014 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,21 @@ >>> import sqlite3 >>> #this one line is all you need to set up a database ... connection = sqlite3.connect('example') ... #a cursor object is used to execute queries against the db ... cursor = connection.cursor() ... #create a table ... cursor.execute('CREATE TABLE example (id real, value text)') ... #insert 100 values into the table >>> for i in range(100): ... cursor.execute('INSERT INTO example VALUES (%d, \'%s\')' % (i, 'value %s' % str(i))) ... #commit the records to memory ... connection.commit() 0: <sqlite3.Cursor object at 0x02601C20> ... #select a slice of the data >>> cursor.execute('SELECT * from example where id > 90').fetchall() 2: [(91.0, u'value 91'), @@ -22,4 +27,5 @@ (97.0, u'value 97'), (98.0, u'value 98'), (99.0, u'value 99')] >>> -
gregroberts created this gist
Oct 2, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ >>> import sqlite3 >>> #this one line is all you need to set up a database ... connection = sqlite3.connect('example') ... #a cursor object is used to execute queries against the db ... cursor = connection.cursor() ... #create a table ... cursor.execute('CREATE TABLE example (id real, value text)') ... #insert 100 values into the table >>> for i in range(100): ... cursor.execute('INSERT INTO example VALUES (%d, \'%s\')' % (i, 'value %s' % str(i))) ... #commit the records to memory ... connection.commit() 0: <sqlite3.Cursor object at 0x02601C20> ... #select a slice of the data >>> cursor.execute('SELECT * from example where id > 90').fetchall() 2: [(91.0, u'value 91'), (92.0, u'value 92'), (93.0, u'value 93'), (94.0, u'value 94'), (95.0, u'value 95'), (96.0, u'value 96'), (97.0, u'value 97'), (98.0, u'value 98'), (99.0, u'value 99')] >>>