def Read(self, name, *args, **kwargs): self._read_call_args[name].append((args, kwargs)) if self._test_db is not None: return self._test_db.Read(name, *args, **kwargs) try: if (name, args) in self._param_read_responses: return self._param_read_responses[(name, args)] except: pass result = self._name_read_responses[name] if isinstance(result, Exception): raise HydrusExceptions.DBException(result, str(result), 'test trace') return result
def _InitDB(self): create_db = False db_path = os.path.join(self._db_dir, self._db_filenames['main']) if not os.path.exists(db_path): create_db = True external_db_paths = [ os.path.join(self._db_dir, self._db_filenames[db_name]) for db_name in self._db_filenames if db_name != 'main' ] existing_external_db_paths = [ external_db_path for external_db_path in external_db_paths if os.path.exists(external_db_path) ] if len(existing_external_db_paths) > 0: message = 'Although the external files, "{}" do exist, the main database file, "{}", does not! This makes for an invalid database, and the program will now quit. Please contact hydrus_dev if you do not know how this happened or need help recovering from hard drive failure.' message = message.format(', '.join(existing_external_db_paths), db_path) raise HydrusExceptions.DBException(message) self._InitDBCursor() result = self._c.execute( 'SELECT 1 FROM sqlite_master WHERE type = ? AND name = ?;', ('table', 'version')).fetchone() if result is None: create_db = True if create_db: self._is_first_start = True self._CreateDB() self._Commit() self._BeginImmediate()