http://stackoverflow.com/questions/531035/how-to-do-if-not-exists-in-sqlite
How about this?
INSERT OR IGNORE INTO EVENTTYPE (EventTypeName) VALUES 'ANI Received'
(Untested as I don't have SQLite... however this link is quite descriptive.)
Additionally, this should also work:
INSERT INTO EVENTTYPE (EventTypeName)
SELECT 'ANI Received'
WHERE NOT EXISTS (SELECT 1 FROM EVENTTYPE WHERE EventTypeName = 'ANI Received');
需要注意的是,这里的Insert Into后面是没有Values;
Values是通过后面的Select来实现的
参考这个
internal static string InsertIdxFile = @"Insert Into SensorData(ID,ProjectID,SensorIdx,IdxFile,StartTimestamp,EndTimestamp) SELECT '{0}','{1}','{2}','{3}','{4}','{5}' WHERE NOT EXISTS (SELECT 1 FROM SensorData WHERE ID = '{0}')";