Lakhtin_V Active Member Licensed User Longtime User Apr 17, 2023 #1 I am successfully using SQLite in my application. Requests are processed and tables are updated. I wanted to make a "filter" that would save me from duplicating records. 1. I created a checksum field - CRC. 2. Made this field CRC as primary key. I specified a condition in the request if we are trying to add a line with duplicate information, then the record will not be added, but it does not work for me, what is my mistake. I tried different spellings of the CPC field with and without quotes with the table name but it does not help. android.database.sqlite.SQLiteException: near "ON": syntax error (code 1): , while compiling: INSERT INTO `Target` (`DTime`, `STime`, `CRC`) VALUES (1681747764109, 1681747759803, 'F0F44') ON CONFLICT(`CRC`) IGNORE
I am successfully using SQLite in my application. Requests are processed and tables are updated. I wanted to make a "filter" that would save me from duplicating records. 1. I created a checksum field - CRC. 2. Made this field CRC as primary key. I specified a condition in the request if we are trying to add a line with duplicate information, then the record will not be added, but it does not work for me, what is my mistake. I tried different spellings of the CPC field with and without quotes with the table name but it does not help. android.database.sqlite.SQLiteException: near "ON": syntax error (code 1): , while compiling: INSERT INTO `Target` (`DTime`, `STime`, `CRC`) VALUES (1681747764109, 1681747759803, 'F0F44') ON CONFLICT(`CRC`) IGNORE
C coldtech Member Licensed User Longtime User Apr 17, 2023 #2 I believe you need to define the column as UNIQUE not just as a Primary Key. Upvote 0
Lakhtin_V Active Member Licensed User Longtime User Apr 17, 2023 #3 coldtech said: I believe you need to define the column as UNIQUE not just as a Primary Key. Click to expand... I've tried giving the field different combinations of a UNIQUE and Primary key, all of which doesn't help. Upvote 0
coldtech said: I believe you need to define the column as UNIQUE not just as a Primary Key. Click to expand... I've tried giving the field different combinations of a UNIQUE and Primary key, all of which doesn't help.
LucaMs Expert Licensed User Longtime User Apr 17, 2023 #4 I think that you don't have to specify the field, CRC, just because it is the primary key of the table. Lakhtin_V said: ON CONFLICT(`CRC`) IGNORE Click to expand... just: ON CONFLICT IGNORE Also, using SQL's ExecuteNonQuery2 you don't have to worry about quotes, double quotes, ... Upvote 0
I think that you don't have to specify the field, CRC, just because it is the primary key of the table. Lakhtin_V said: ON CONFLICT(`CRC`) IGNORE Click to expand... just: ON CONFLICT IGNORE Also, using SQL's ExecuteNonQuery2 you don't have to worry about quotes, double quotes, ...
Lakhtin_V Active Member Licensed User Longtime User Apr 17, 2023 #5 LucaMs said: I think that you don't have to specify the field, CRC, just because it is the primary key of the table. just: ON CONFLICT IGNORE Also, using SQL's ExecuteNonQuery2 you don't have to worry about quotes, double quotes, ... Click to expand... There is no problem in quotes, I checked it in the absence of a primary key, but with a primary key, any combinations with ON CONFLICT IGNORE or ON CONFLICT DO NOTHING do not work Upvote 0
LucaMs said: I think that you don't have to specify the field, CRC, just because it is the primary key of the table. just: ON CONFLICT IGNORE Also, using SQL's ExecuteNonQuery2 you don't have to worry about quotes, double quotes, ... Click to expand... There is no problem in quotes, I checked it in the absence of a primary key, but with a primary key, any combinations with ON CONFLICT IGNORE or ON CONFLICT DO NOTHING do not work
M Mahares Expert Licensed User Longtime User Apr 17, 2023 #6 Lakhtin_V said: but with a primary key, any combinations with ON CONFLICT IGNORE or ON CONFLICT DO NOTHING do not work Click to expand... If your table has CRC as PRIMARY KEY and you want to avoid duplicate records if CRC is duplicated, you can do: INSERT OR IGNORE INTO Target..... Upvote 0
Lakhtin_V said: but with a primary key, any combinations with ON CONFLICT IGNORE or ON CONFLICT DO NOTHING do not work Click to expand... If your table has CRC as PRIMARY KEY and you want to avoid duplicate records if CRC is duplicated, you can do: INSERT OR IGNORE INTO Target.....
LucaMs Expert Licensed User Longtime User Apr 17, 2023 #7 I'm lazy. ? https://www.perplexity.ai/search/f778e0d7-b8a5-423d-a3ea-7ed528c3ddab?s=u Upvote 0
LucaMs Expert Licensed User Longtime User Apr 17, 2023 #8 LucaMs said: I'm lazy. ? https://www.perplexity.ai/search/f778e0d7-b8a5-423d-a3ea-7ed528c3ddab?s=u Click to expand... After trying pretty hard I have to say that Perplexity is wrong Upvote 0
LucaMs said: I'm lazy. ? https://www.perplexity.ai/search/f778e0d7-b8a5-423d-a3ea-7ed528c3ddab?s=u Click to expand... After trying pretty hard I have to say that Perplexity is wrong
Lakhtin_V Active Member Licensed User Longtime User Apr 17, 2023 #9 Mahares said: If your table has CRC as PRIMARY KEY and you want to avoid duplicate records if CRC is duplicated, you can do: INSERT OR IGNORE INTO Target..... Click to expand... INSERT OR IGNORE INTO Target..... ON CONFLICT DO NOTHING ? Upvote 0
Mahares said: If your table has CRC as PRIMARY KEY and you want to avoid duplicate records if CRC is duplicated, you can do: INSERT OR IGNORE INTO Target..... Click to expand... INSERT OR IGNORE INTO Target..... ON CONFLICT DO NOTHING ?
LucaMs Expert Licensed User Longtime User Apr 17, 2023 #10 Lakhtin_V said: INSERT OR IGNORE INTO Target..... ON CONFLICT DO NOTHING ? Click to expand... Yes. Upvote 0
LucaMs Expert Licensed User Longtime User Apr 17, 2023 #11 LucaMs said: After trying pretty hard I have to say that Perplexity is wrong Click to expand... So I asket it: "Are you sure? In SQLite..." and... but I see no difference ? Upvote 0
LucaMs said: After trying pretty hard I have to say that Perplexity is wrong Click to expand... So I asket it: "Are you sure? In SQLite..." and... but I see no difference ?
LucaMs Expert Licensed User Longtime User Apr 17, 2023 #12 LucaMs said: So I asket it: "Are you sure? In SQLite..." and... View attachment 141285 but I see no difference ? Click to expand... B4X: Copy Query = $"INSERT INTO Category (Id, CategoryName, Description) VALUES (1, "NewCat", "John") ON CONFLICT (Id) DO UPDATE SET CategoryName = "Other";"$ (SQLException) java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (near "ON": syntax error) Nothing to do, it doesn't work. That's enough, because @Mahares fixed it the best way. Upvote 0
LucaMs said: So I asket it: "Are you sure? In SQLite..." and... View attachment 141285 but I see no difference ? Click to expand... B4X: Copy Query = $"INSERT INTO Category (Id, CategoryName, Description) VALUES (1, "NewCat", "John") ON CONFLICT (Id) DO UPDATE SET CategoryName = "Other";"$ (SQLException) java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (near "ON": syntax error) Nothing to do, it doesn't work. That's enough, because @Mahares fixed it the best way.
Lakhtin_V Active Member Licensed User Longtime User Apr 17, 2023 #13 Mahares said: If your table has CRC as PRIMARY KEY and you want to avoid duplicate records if CRC is duplicated, you can do: INSERT OR IGNORE INTO Target..... Click to expand... Good advice Mahares, you solved my problem, I did not find such a syntax option in the documentation. Where did you get your magical knowledge from? Thank you very much! INSERT OR IGNORE INTO Target.... only ;-) Upvote 0
Mahares said: If your table has CRC as PRIMARY KEY and you want to avoid duplicate records if CRC is duplicated, you can do: INSERT OR IGNORE INTO Target..... Click to expand... Good advice Mahares, you solved my problem, I did not find such a syntax option in the documentation. Where did you get your magical knowledge from? Thank you very much! INSERT OR IGNORE INTO Target.... only ;-)
LucaMs Expert Licensed User Longtime User Apr 17, 2023 #14 https://www.sqlite.org/lang_insert.html Upvote 0
LucaMs Expert Licensed User Longtime User Apr 17, 2023 #15 https://www.sqlitetutorial.net/sqlite-insert/ Upvote 0