my table is :
CREATE TABLE IF NOT EXISTS BrowseHistory (
id INTEGER NOT NULL,
tid INTEGER NOT NULL PRIMARY KEY,
data BLOB NOT NULL)
what I want to do is give tid and data, I want to find if there's not a record's tid == given tid, then insert it( the id is the max(id) + 1). If there is, check if the id is equal to max(id) ,if not set the id to max(id) +1. I used the following sql, it can work ,but it will always set the id equals to max(id) + 1
INSERT OR REPLACE INTO BrowseHistory (id, tid, data) values ((SELECT IFNULL(MAX(id),0) FROM BrowseHistory) + 1, ?, ?)
Aucun commentaire:
Enregistrer un commentaire