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 characters
import sqlite3 | |
import json | |
conn = sqlite3.connect('test.db') | |
c = conn.cursor() | |
# Insert values | |
c.execute('''insert into data values(?)''', (json.dumps({'test':'test2'}),)) | |
conn.commit() |
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 characters
import sqlite3 | |
import json | |
conn = sqlite3.connect('test.db') | |
c = conn.cursor() | |
# Insert {'test':'test2'} dummy values into database | |
c.execute('''insert into data values(?)''',(json.dumps({'test':'test2'}),)) | |
conn.commit() |
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 characters
# Select those values, get them to be json | |
c.execute('select * from data') | |
data = c.fetchall() | |
print data | |
# Data will print: [(u'{"test": "test2"}',)] | |
# To load the JSON for python use | |
for item in data: | |
print json.loads(item[0]) | |
# Data will print: {u'test': u'test2'} |
OlderNewer