MCPcopy Create free account
hub / github.com/ipython/ipython / init_db

Method init_db

IPython/core/history.py:245–268  ·  view source on GitHub ↗

Connect to the database, and create tables if necessary.

(self)

Source from the content-addressed store, hash-verified

243
244 @catch_corrupt_db
245 def init_db(self):
246 """Connect to the database, and create tables if necessary."""
247 if not self.enabled:
248 self.db = DummyDB()
249 return
250
251 # use detect_types so that timestamps return datetime objects
252 kwargs = dict(detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)
253 kwargs.update(self.connection_options)
254 self.db = sqlite3.connect(self.hist_file, **kwargs)
255 self.db.execute("""CREATE TABLE IF NOT EXISTS sessions (session integer
256 primary key autoincrement, start timestamp,
257 end timestamp, num_cmds integer, remark text)""")
258 self.db.execute("""CREATE TABLE IF NOT EXISTS history
259 (session integer, line integer, source text, source_raw text,
260 PRIMARY KEY (session, line))""")
261 # Output history is optional, but ensure the table's there so it can be
262 # enabled later.
263 self.db.execute("""CREATE TABLE IF NOT EXISTS output_history
264 (session integer, line integer, output text,
265 PRIMARY KEY (session, line))""")
266 self.db.commit()
267 # success! reset corrupt db count
268 self._corrupt_db_counter = 0
269
270 def writeout_cache(self):
271 """Overridden by HistoryManager to dump the cache before certain

Callers 2

__init__Method · 0.95
catch_corrupt_dbFunction · 0.80

Calls 4

DummyDBClass · 0.85
executeMethod · 0.80
commitMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected