##// END OF EJS Templates
try to atomically create DB
Matthias Bussonnier -
Show More
@@ -242,18 +242,24 b' class HistoryAccessor(HistoryAccessorBase):'
242 kwargs = dict(detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)
242 kwargs = dict(detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)
243 kwargs.update(self.connection_options)
243 kwargs.update(self.connection_options)
244 self.db = sqlite3.connect(str(self.hist_file), **kwargs)
244 self.db = sqlite3.connect(str(self.hist_file), **kwargs)
245 self.db.execute("""CREATE TABLE IF NOT EXISTS sessions (session integer
245 with self.db:
246 self.db.execute(
247 """CREATE TABLE IF NOT EXISTS sessions (session integer
246 primary key autoincrement, start timestamp,
248 primary key autoincrement, start timestamp,
247 end timestamp, num_cmds integer, remark text)""")
249 end timestamp, num_cmds integer, remark text)"""
248 self.db.execute("""CREATE TABLE IF NOT EXISTS history
250 )
251 self.db.execute(
252 """CREATE TABLE IF NOT EXISTS history
249 (session integer, line integer, source text, source_raw text,
253 (session integer, line integer, source text, source_raw text,
250 PRIMARY KEY (session, line))""")
254 PRIMARY KEY (session, line))"""
255 )
251 # Output history is optional, but ensure the table's there so it can be
256 # Output history is optional, but ensure the table's there so it can be
252 # enabled later.
257 # enabled later.
253 self.db.execute("""CREATE TABLE IF NOT EXISTS output_history
258 self.db.execute(
259 """CREATE TABLE IF NOT EXISTS output_history
254 (session integer, line integer, output text,
260 (session integer, line integer, output text,
255 PRIMARY KEY (session, line))""")
261 PRIMARY KEY (session, line))"""
256 self.db.commit()
262 )
257 # success! reset corrupt db count
263 # success! reset corrupt db count
258 self._corrupt_db_counter = 0
264 self._corrupt_db_counter = 0
259
265
General Comments 0
You need to be logged in to leave comments. Login now