Here is my code (currently):
conn = sqlite3.connect(db)
conn.text_factory = str #bugger 8-bit bytestrings
cur = conn.cursor()
reader = csv.reader(open(csvfile, "rU"), delimiter = '\t')
for Number, Name, Message, Datetime, Type in reader:
# populate subscriber table
if str(Number)[:1] == '1':
tmpNumber = str(Number)[1:]
Number = int(tmpNumber)
cur.execute('INSERT OR IGNORE INTO subscriber (name, phone_number) VALUES (?,?)', (Name, Number))
cur.close()
conn.close()
Here is some sample data from the csv file (tab-delimited in the file):
Number Name Message Date/Time Type
16665551212 Jane Doe message one 11/23/2011 6:34:44 AM Incoming
16665551212 Jane Doe message two 11/23/2011 4:53:21 PM Incoming
The code executes without any errors, only nothing is written to the database. Why is this?
You need to commit your changes: conn.commit()
If you do not want to use transactions at all, ie work in "autocommit" mode, use isolation_level=None
in the connect()
call. However, this is usually a bad idea.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.