Skip to content

Instantly share code, notes, and snippets.

@binki
Last active June 21, 2016 02:08
Show Gist options
  • Save binki/717a6d53d426b5161744c1e08a51efa5 to your computer and use it in GitHub Desktop.
Save binki/717a6d53d426b5161744c1e08a51efa5 to your computer and use it in GitHub Desktop.
ohnobinki@gibby ~ $ python3
Python 3.3.5 (default, May 19 2015, 14:05:03)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> logger_connection = sqlite3.connect('/home/ohnobinki/log.sql')
>>> logger_connection.exec('CREATE TABLE IF NOT EXISTS submission_log (text TEXT)');
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'sqlite3.Connection' object has no attribute 'exec'
>>> logger_connection.execute('CREATE TABLE IF NOT EXISTS submission_log (text TEXT)')
<sqlite3.Cursor object at 0x7f4fc93582d0>
>>> logger_connection.commit()
>>> logger_connection.execute('INSERT submission_log VALUES ({text})', text='Blah!')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: execute() takes no keyword arguments
>>> logger_connection.execute('INSERT submission_log VALUES (?)', ('Blah!',))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
sqlite3.OperationalError: near "submission_log": syntax error
>>> logger_connection.execute('INSERT submission_log (text) VALUES (?)', ('Blah!',))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
sqlite3.OperationalError: near "submission_log": syntax error
>>> logger_connection.execute('INSERT INTO submission_log (text) VALUES (?)', ('Blah!',))
<sqlite3.Cursor object at 0x7f4fc9358260>
>>> logger_connection.commit()
>>> quit
Use quit() or Ctrl-D (i.e. EOF) to exit
>>> quit()
ohnobinki@gibby ~ $ sqlite3 log.sql
SQLite version 3.8.10.2 2015-05-20 18:17:19
Enter ".help" for usage hints.
sqlite> SELECT * FROM submission_log
...> ;
Blah!
sqlite>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment