mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
e15eec8d93
commit
c15856b07c
@ -204,6 +204,10 @@ class WritingTest(BaseTest):
|
|||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
def test_many_many_basic(self): # {{{
|
||||||
|
'Test the different code paths for writing to a many-one field'
|
||||||
|
# Fields: identifiers, authors, tags, languages, #authors, #tags
|
||||||
|
# }}}
|
||||||
|
|
||||||
def tests():
|
def tests():
|
||||||
return unittest.TestLoader().loadTestsFromTestCase(WritingTest)
|
return unittest.TestLoader().loadTestsFromTestCase(WritingTest)
|
||||||
|
@ -137,7 +137,7 @@ def get_adapter(name, metadata):
|
|||||||
def one_one_in_books(book_id_val_map, db, field, *args):
|
def one_one_in_books(book_id_val_map, db, field, *args):
|
||||||
'Set a one-one field in the books table'
|
'Set a one-one field in the books table'
|
||||||
if book_id_val_map:
|
if book_id_val_map:
|
||||||
sequence = tuple((sqlite_datetime(v), k) for k, v in book_id_val_map.iteritems())
|
sequence = ((sqlite_datetime(v), k) for k, v in book_id_val_map.iteritems())
|
||||||
db.conn.executemany(
|
db.conn.executemany(
|
||||||
'UPDATE books SET %s=? WHERE id=?'%field.metadata['column'], sequence)
|
'UPDATE books SET %s=? WHERE id=?'%field.metadata['column'], sequence)
|
||||||
field.table.book_col_map.update(book_id_val_map)
|
field.table.book_col_map.update(book_id_val_map)
|
||||||
@ -155,7 +155,7 @@ def one_one_in_other(book_id_val_map, db, field, *args):
|
|||||||
if updated:
|
if updated:
|
||||||
db.conn.executemany('INSERT OR REPLACE INTO %s(book,%s) VALUES (?,?)'%(
|
db.conn.executemany('INSERT OR REPLACE INTO %s(book,%s) VALUES (?,?)'%(
|
||||||
field.metadata['table'], field.metadata['column']),
|
field.metadata['table'], field.metadata['column']),
|
||||||
tuple((k, sqlite_datetime(v)) for k, v in updated.iteritems()))
|
((k, sqlite_datetime(v)) for k, v in updated.iteritems()))
|
||||||
field.table.book_col_map.update(updated)
|
field.table.book_col_map.update(updated)
|
||||||
return set(book_id_val_map)
|
return set(book_id_val_map)
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ def get_db_id(val, db, m, table, kmap, rid_map, allow_case_changes,
|
|||||||
def change_case(case_changes, dirtied, db, table, m, sql_val_map=lambda x:x):
|
def change_case(case_changes, dirtied, db, table, m, sql_val_map=lambda x:x):
|
||||||
db.conn.executemany(
|
db.conn.executemany(
|
||||||
'UPDATE %s SET %s=? WHERE id=?'%(m['table'], m['column']),
|
'UPDATE %s SET %s=? WHERE id=?'%(m['table'], m['column']),
|
||||||
tuple((sql_val_map(val), item_id) for item_id, val in case_changes.iteritems()))
|
((sql_val_map(val), item_id) for item_id, val in case_changes.iteritems()))
|
||||||
for item_id, val in case_changes.iteritems():
|
for item_id, val in case_changes.iteritems():
|
||||||
table.id_map[item_id] = val
|
table.id_map[item_id] = val
|
||||||
dirtied.update(table.col_book_map[item_id])
|
dirtied.update(table.col_book_map[item_id])
|
||||||
@ -252,7 +252,7 @@ def many_one(book_id_val_map, db, field, allow_case_change, *args):
|
|||||||
# Update the db link table
|
# Update the db link table
|
||||||
if deleted:
|
if deleted:
|
||||||
db.conn.executemany('DELETE FROM %s WHERE book=?'%table.link_table,
|
db.conn.executemany('DELETE FROM %s WHERE book=?'%table.link_table,
|
||||||
tuple((k,) for k in deleted))
|
((k,) for k in deleted))
|
||||||
if updated:
|
if updated:
|
||||||
sql = (
|
sql = (
|
||||||
'DELETE FROM {0} WHERE book=?; INSERT INTO {0}(book,{1},extra) VALUES(?, ?, 1.0)'
|
'DELETE FROM {0} WHERE book=?; INSERT INTO {0}(book,{1},extra) VALUES(?, ?, 1.0)'
|
||||||
@ -260,7 +260,7 @@ def many_one(book_id_val_map, db, field, allow_case_change, *args):
|
|||||||
'DELETE FROM {0} WHERE book=?; INSERT INTO {0}(book,{1}) VALUES(?, ?)'
|
'DELETE FROM {0} WHERE book=?; INSERT INTO {0}(book,{1}) VALUES(?, ?)'
|
||||||
)
|
)
|
||||||
db.conn.executemany(sql.format(table.link_table, m['link_column']),
|
db.conn.executemany(sql.format(table.link_table, m['link_column']),
|
||||||
tuple((book_id, book_id, item_id) for book_id, item_id in
|
((book_id, book_id, item_id) for book_id, item_id in
|
||||||
updated.iteritems()))
|
updated.iteritems()))
|
||||||
|
|
||||||
# Remove no longer used items
|
# Remove no longer used items
|
||||||
@ -268,7 +268,7 @@ def many_one(book_id_val_map, db, field, allow_case_change, *args):
|
|||||||
table.col_book_map.get(item_id, False)}
|
table.col_book_map.get(item_id, False)}
|
||||||
if remove:
|
if remove:
|
||||||
db.conn.executemany('DELETE FROM %s WHERE id=?'%m['table'],
|
db.conn.executemany('DELETE FROM %s WHERE id=?'%m['table'],
|
||||||
tuple((item_id,) for item_id in remove))
|
((item_id,) for item_id in remove))
|
||||||
for item_id in remove:
|
for item_id in remove:
|
||||||
del table.id_map[item_id]
|
del table.id_map[item_id]
|
||||||
table.col_book_map.pop(item_id, None)
|
table.col_book_map.pop(item_id, None)
|
||||||
@ -327,9 +327,9 @@ def many_many(book_id_val_map, db, field, allow_case_change, *args):
|
|||||||
# Update the db link table
|
# Update the db link table
|
||||||
if deleted:
|
if deleted:
|
||||||
db.conn.executemany('DELETE FROM %s WHERE book=?'%table.link_table,
|
db.conn.executemany('DELETE FROM %s WHERE book=?'%table.link_table,
|
||||||
tuple((k,) for k in deleted))
|
((k,) for k in deleted))
|
||||||
if updated:
|
if updated:
|
||||||
vals = tuple(
|
vals = (
|
||||||
(book_id, book_id, val) for book_id, vals in updated.iteritems()
|
(book_id, book_id, val) for book_id, vals in updated.iteritems()
|
||||||
for val in vals
|
for val in vals
|
||||||
)
|
)
|
||||||
@ -343,7 +343,7 @@ def many_many(book_id_val_map, db, field, allow_case_change, *args):
|
|||||||
table.col_book_map.get(item_id, False)}
|
table.col_book_map.get(item_id, False)}
|
||||||
if remove:
|
if remove:
|
||||||
db.conn.executemany('DELETE FROM %s WHERE id=?'%m['table'],
|
db.conn.executemany('DELETE FROM %s WHERE id=?'%m['table'],
|
||||||
tuple((item_id,) for item_id in remove))
|
((item_id,) for item_id in remove))
|
||||||
for item_id in remove:
|
for item_id in remove:
|
||||||
del table.id_map[item_id]
|
del table.id_map[item_id]
|
||||||
table.col_book_map.pop(item_id, None)
|
table.col_book_map.pop(item_id, None)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user