View Single Post
Old 03-14-2014, 05:27 AM   #2
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,449
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
I don't see this behavior.

My experiment:
  1. Look at the db with SQLiteSpy. Find a float custom column. Image is below.
    Click image for larger version

Name:	Clipboard01.png
Views:	284
Size:	56.0 KB
ID:	120204
  2. Change a value in calibre, in this case 9.01 becomes 9.02
  3. Look at the db again. The value has changed and there is no duplicated row.
    Click image for larger version

Name:	Clipboard02.png
Views:	301
Size:	55.3 KB
ID:	120205
What are you doing that is different?

I also note that the table has a UNIQUE constraint on the book_id, so the db itself should toss exceptions in the case you describe.
Code:
CREATE TABLE custom_column_16(
                    id    INTEGER PRIMARY KEY AUTOINCREMENT,
                    book  INTEGER,
                    value REAL NOT NULL ,
                    UNIQUE(book));

CREATE INDEX custom_column_16_idx ON custom_column_16 (book);

CREATE TRIGGER fkc_insert_custom_column_16
                        BEFORE INSERT ON custom_column_16
                        BEGIN
                            SELECT CASE
                                WHEN (SELECT id from books WHERE id=NEW.book) IS NULL
                                THEN RAISE(ABORT, 'Foreign key violation: book not in books')
                            END;
                        END;

CREATE TRIGGER fkc_update_custom_column_16
                        BEFORE UPDATE OF book ON custom_column_16
                        BEGIN
                            SELECT CASE
                                WHEN (SELECT id from books WHERE id=NEW.book) IS NULL
                                THEN RAISE(ABORT, 'Foreign key violation: book not in books')
                            END;
                        END;
chaley is offline   Reply With Quote