Perform pre and post processing with sqlite3
How can I perform post processing on my SQL3 database via python? The
following code doesn't work, but what I am trying to do is first create a
new database if not exists already, then insert some data, and finally
execute the query and close the connection. But I what to do so
separately, so as to add additional functionality later on, such as delete
/ updater / etc... Any ideas?
class TitlesDB:
# initiate global variables
conn = None
c = None
# perform pre - processing
def __init__(self, name):
import os
os.chdir('/../../')
import sqlite3
conn = sqlite3.connect(name)
c = conn.cursor()
c.execute('CREATE TABLE IF NOT EXISTS titles (title VARCHAR(100)
UNIQUE)')
# insert a bunch of new titles
def InsertTitles(self, list):
c.executemany('INSERT OR IGNORE INTO titles VALUES (?)', list)
# perform post - processing
def __fina__(self):
conn.commit()
conn.close()
No comments:
Post a Comment