I'm pulling data from a website using their api. I'm then wanting to save the data into a database. For some of the fields I need to save a section of the json data that was pulled into one field.
The table layout is created using this:
cur.execute('create table if not exists KillData(KillID INT, Victim TEXT, KillTime TEXT, System INT,'
' Attackers TEXT, Items TEXT, Price REAL)')
This is what I have right now to insert the data:
for kill_mail in response:
kill = KillMail(kill_mail)
cur.execute("insert into KillData values(?, ?, ?, ?, ?, ?, ?)",
(int(kill.get_kill_id()), kill.get_victim(), kill.get_kill_time(), kill.get_system(),
kill.get_attackers, kill.get_items(), kill.get_price()))
where KillMail is just a class which is used to get certain values within the json data. For example:
class KillMail:
def __init__(self, json_kill_mail):
self.json_kill_mail = json_kill_mail
def get_attackers(self):
return json.dumps(self.json_kill_mail['attackers'])
def get_items(self):
return json.dumps(self.json_kill_mail['items'])
kill.get_attackers and kill.get_items() contain items within them because there may be only one attacker/item or up to 100 or more. This is why I'm thinking that saving the data in json format as a string will be best so that when pulling it I can just json.load() to reconstruct the json object to pull info from it.
The error I'm getting when running the code is:
in main kill.get_attackers, kill.get_items(), kill.get_price())) sqlite3.InterfaceError: Error binding parameter 4 - probably unsupported type.
The only thing I could find online about doing this is this.
I tried the suggested things in that post but nothing seemed to work. I also tried to change the two fields to BLOB's but that gave the same error.
So my question is: How can I save a json formatted string into one field?
I can post more info if needed.