Consider this case when the last line of the CSV is a duplicate
myFile1.csv
column1,column2,column3
r1v1,r1v2,r1v3
r2v1,r2v2,r2v3
r1v1,r1v2,r1v3
sqliteCommandsFile.sql
CREATE TABLE foo(column1 PRIMARY KEY UNIQUE,column2,column3);
.mode csv
.import myFile1.csv foo
> sqlite3 /tmp/output.db < sqliteCommandsFile.sql
INSERT failed: UNIQUE constraint failed: foo.column1
> echo $?
1
Now consider this case
myFile2.csv
column1,column2,column3
r1v1,r1v2,r1v3
r2v1,r2v2,r2v3
r1v1,r1v2,r1v3
r3v1,r3v2,r3v3
sqliteCommandsFile2.sql
CREATE TABLE foo(column1 PRIMARY KEY UNIQUE,column2,column3);
.mode csv
.import myFile2.csv foo
> sqlite3 /tmp/output.db < sqliteCommandsFile2.sql
INSERT failed: UNIQUE constraint failed: foo.column1
> echo $?
0
I wouldn't care so much about the status code, but since sqlite3 will rollback when it has an error on the last line the database will be empty when the duplicate is on the last line.
I have a hack in place to add a random line to the end of the file but it doesn't seem reasonable to do that.