Skip to content

Instantly share code, notes, and snippets.

@gregroberts
Last active August 29, 2015 14:07

Revisions

  1. gregroberts revised this gist Oct 2, 2014. 1 changed file with 18 additions and 16 deletions.
    34 changes: 18 additions & 16 deletions SQLite Litest example
    Original 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')
    import sqlite3

    ... #a cursor object is used to execute queries against the db
    ... cursor = connection.cursor()
    #this one line is all you need to set up a database
    connection = sqlite3.connect('example')

    ... #create a table
    ... cursor.execute('CREATE TABLE example (id real, value text)')
    #a cursor object is used to execute queries against the db
    cursor = connection.cursor()

    ... #insert 100 values into the table
    >>> for i in range(100):
    ... cursor.execute('INSERT INTO example VALUES (%d, \'%s\')' % (i, 'value %s' % str(i)))
    #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()

    ... #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()
    #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')]

    >>>

  2. gregroberts revised this gist Oct 2, 2014. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions SQLite Litest example
    Original 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')]

    >>>
  3. gregroberts created this gist Oct 2, 2014.
    25 changes: 25 additions & 0 deletions SQLite Litest example
    Original 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')]
    >>>