I'm trying to insert a csv file, containing about 500 words into an existing table of an sqlite database.
The sqlite structure is:
_id(INTEGER), word(TEXT), frequency(INTEGER), locale(TEXT), appid(INTEGER, shortcut(TEXT)
I've filled the data manually to see how the data should look and the _id, as expected is incremented automatically, the word is the entry of interest, which should be used from the csv, frequency seems to be simply 250, locale and shortcut may be null and the appid is 0.
To test if an external modification of the database (in python3), is possible I tried to do the following:
import sqlite
conn = sqlite3.connect('/tmp/user_dict.db')
c = conn.cursor()
c.execute("INSERT INTO words VALUES (3, 'test3', 250, 'Null', 0, 'Null')")
conn.commit()
conn.close()
Now I could use some funky regex to create a list of c.executes from my csv file, but I guess that's not really efficient.
I have two problems with the csv file here, how do I loop trough the csv and enter each word in the INSERT command and how do I correctly handle the _id?
Context: The database was pulled from an Android 6 device, using adb. Android 6 seemingly doesn't allow apps to alter the user dictionary database so I want to pull the database, alter it, then push it back onto the device.
Data: SELECT * FROM TABLE words of the sqlite database (using sqlite3), after manually inserting 2 entries on the phone and 1 entry via the above python script shows:
1|test1|250||0|
2|test2|250||0|
3|test3|250||0|
Aucun commentaire:
Enregistrer un commentaire