Fix regression when checking db integrity with custom cols introduced in 0.7.17

This commit is contained in:
Kovid Goyal 2010-09-06 09:41:26 -06:00
commit 5952c349d5
2 changed files with 2 additions and 14 deletions

View File

@ -144,6 +144,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
self.initialize_dynamic() self.initialize_dynamic()
def initialize_dynamic(self): def initialize_dynamic(self):
self.field_metadata = FieldMetadata() #Ensure we start with a clean copy
self.prefs = DBPrefs(self) self.prefs = DBPrefs(self)
defs = self.prefs.defaults defs = self.prefs.defaults
defs['gui_restriction'] = defs['cs_restriction'] = '' defs['gui_restriction'] = defs['cs_restriction'] = ''
@ -1125,7 +1126,6 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
if not authors: if not authors:
authors = [_('Unknown')] authors = [_('Unknown')]
self.conn.execute('DELETE FROM books_authors_link WHERE book=?',(id,)) self.conn.execute('DELETE FROM books_authors_link WHERE book=?',(id,))
self.conn.execute('DELETE FROM authors WHERE (SELECT COUNT(id) FROM books_authors_link WHERE author=authors.id) < 1')
for a in authors: for a in authors:
if not a: if not a:
continue continue
@ -2151,8 +2151,6 @@ books_series_link feeds
os.remove(self.dbpath) os.remove(self.dbpath)
shutil.copyfile(dest, self.dbpath) shutil.copyfile(dest, self.dbpath)
self.connect() self.connect()
self.field_metadata.remove_dynamic_categories()
self.field_metadata.remove_custom_fields()
self.initialize_dynamic() self.initialize_dynamic()
self.refresh() self.refresh()
if os.path.exists(dest): if os.path.exists(dest):

View File

@ -306,7 +306,7 @@ class FieldMetadata(dict):
self._tb_cats[k]['label'] = k self._tb_cats[k]['label'] = k
self._tb_cats[k]['display'] = {} self._tb_cats[k]['display'] = {}
self._tb_cats[k]['is_editable'] = True self._tb_cats[k]['is_editable'] = True
self._add_search_terms_to_map(k, self._tb_cats[k]['search_terms']) self._add_search_terms_to_map(k, v['search_terms'])
self.custom_field_prefix = '#' self.custom_field_prefix = '#'
self.get = self._tb_cats.get self.get = self._tb_cats.get
@ -408,16 +408,6 @@ class FieldMetadata(dict):
self._add_search_terms_to_map(key, [key]) self._add_search_terms_to_map(key, [key])
self.custom_label_to_key_map[label+'_index'] = key self.custom_label_to_key_map[label+'_index'] = key
def remove_custom_fields(self):
for key in self.get_custom_fields():
del self._tb_cats[key]
def remove_dynamic_categories(self):
for key in list(self._tb_cats.keys()):
val = self._tb_cats[key]
if val['is_category'] and val['kind'] in ('user', 'search'):
del self._tb_cats[key]
def cc_series_index_column_for(self, key): def cc_series_index_column_for(self, key):
return self._tb_cats[key]['rec_index'] + 1 return self._tb_cats[key]['rec_index'] + 1