]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix the new .import logic in the CLI so that it honors ".bail on".
authordrh <>
Mon, 29 Dec 2025 23:56:05 +0000 (23:56 +0000)
committerdrh <>
Mon, 29 Dec 2025 23:56:05 +0000 (23:56 +0000)
[forum:/forumpost/6c1c0e213d|Forum post 6c1c0e213d].

FossilOrigin-Name: d58846e74b6971a5fd80e5f030985273b7dfa0087c2f3c9d0c088c248e183f8a

manifest
manifest.uuid
src/shell.c.in
test/shell5.test

index 33e74a80b78d4ab5dd6d962de5862a29d535fac5..1ef1a0f9f09a3481a34e6f3a646fd55489501d6b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\serror\smessages\sassociated\swith\s.import,\salong\swith\scorresponding\ntest\scases.
-D 2025-12-29T21:39:48.227
+C Fix\sthe\snew\s.import\slogic\sin\sthe\sCLI\sso\sthat\sit\shonors\s".bail\son".\n[forum:/forumpost/6c1c0e213d|Forum\spost\s6c1c0e213d].
+D 2025-12-29T23:56:05.180
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -737,7 +737,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
 F src/resolve.c 47aa7fdc9ec4c19b103ac5e79d7887d30119b5675309facf5eed1118391c868b
 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
 F src/select.c 85852256d860f3ba5be4a9edc1238e68dbea082a0167f31b7345c821ae45775d
-F src/shell.c.in d0a6f0877a63ccb08f613fb42ecfee701f95235495af69cc84e8f9dfdffd328a
+F src/shell.c.in a1bbd7dd24c10c18190c66b4f6258dcd04a77fba5c60c4d92fe04b4f20a316b9
 F src/sqlite.h.in b6599377f02ef9d545a8da48959213928b63291ad83ff65e5f3a72bf4fec595d
 F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479
 F src/sqlite3ext.h 5d5330f5f8461f5ce74960436ddcfa53ecd09c2b8b23901e22ae38aec3243998
@@ -1618,7 +1618,7 @@ F test/shell1.test 56f200ba4b36cbe8229d84d848e6a8d69eb91a75b2deaf28c454027433c6e
 F test/shell2.test dc541d2681503e55466a24d35a4cbf8ca5b90b8fcdef37fc4db07373a67d31d3
 F test/shell3.test 603b448e917537cf77be0f265c05c6f63bc677c63a533c8e96aae923b56f4a0e
 F test/shell4.test e25580a792b7b54560c3a76b6968bd8189261f38979fe28e6bc6312c5db280db
-F test/shell5.test 42eb3f73a662db5d4d6e113392163dce6181edb4910f775949436a873fbbe3b1
+F test/shell5.test c6d7784404eb28edd9f63d2ff0190b4389f38c35895e06cfa4eaccdf03a127f9
 F test/shell6.test e3b883b61d4916b6906678a35f9d19054861123ad91b856461e0a456273bdbb8
 F test/shell7.test 43fd8e511c533bab5232e95c7b4be93b243451709e89582600d4b6e67693d5c3
 F test/shell8.test 641cf21a99c59404c24e3062923734951c4099a6b6b6520de00cf7a1249ee871
@@ -2189,8 +2189,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee
 F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
 F tool/winmain.c f40bccf0236f8bcc34b299781b7d34cb269ace23afe5c1b8a9d966e2fa1ce9e5
-P 5a1e931b19c346bdc8d1a51fa6ef8ee04b7371cdf5df2ee32e1333226c42d327
-R 6e224daaa7e358d3ad5886f31fcd83f2
+P 2084e805d0d9da8f419b8506fccd652a7d20262bd95729250a2d2eabfdd079ad
+R 14d23b01fe372b0e2bcd9984dfd257be
 U drh
-Z b737c51c2dffe2b9663221f89baa58f1
+Z 33a7b23e86645674a047edd8d2564d54
 # Remove this line to create a well-formed Fossil manifest.
index f86c6b0b0a148b0ab8d8ed0326bf3ba2e4522ec5..0ffd96cb628554f7e6afc981fe675b92dc42f89b 100644 (file)
@@ -1 +1 @@
-2084e805d0d9da8f419b8506fccd652a7d20262bd95729250a2d2eabfdd079ad
+d58846e74b6971a5fd80e5f030985273b7dfa0087c2f3c9d0c088c248e183f8a
index c0d1a2c3f152c600dae05ad5114a9bfadb6cd12d..381459a1fc56b538c3654f634a6be202e8e8d444 100644 (file)
@@ -7406,6 +7406,7 @@ static int dotCmdImport(ShellState *p){
   char *(SQLITE_CDECL *xRead)(ImportCtx*); /* Func to read one value */
   int eVerbose = 0;           /* Larger for more console output */
   i64 nSkip = 0;              /* Initial lines to skip */
+  i64 iLineOffset = 0;        /* Offset to the first line of input */
   char *zCreate = 0;          /* CREATE TABLE statement text */
   int rc;                     /* Result code */
 
@@ -7507,13 +7508,17 @@ static int dotCmdImport(ShellState *p){
   }else if( sCtx.zFile[0]=='<' && sCtx.zFile[1]=='<' && sCtx.zFile[2]!=0 ){
     /* Input text comes from subsequent lines of script until the zFile
     ** delimiter */
-    int nEndMark = strlen30(sCtx.zFile);
+    int nEndMark = strlen30(zFile)-2;
+    char *zEndMark = &zFile[2];
     sqlite3_str *pContent = sqlite3_str_new(p->db);
     int ckEnd = 1;
     i64 iStart = p->lineno;
     char zLine[2000];
+    sCtx.zFile = p->zInFile;
+    sCtx.nLine = p->lineno+1;
+    iLineOffset = p->lineno;
     while( sqlite3_fgets(zLine,sizeof(zLine),p->in) ){
-      if( ckEnd && cli_strncmp(&sCtx.zFile[2],zLine,nEndMark-2)==0 ){
+      if( ckEnd && cli_strncmp(zLine,zEndMark,nEndMark)==0 ){
         ckEnd = 2;
         if( strchr(zLine,'\n') ) p->lineno++;
         break;
@@ -7533,8 +7538,7 @@ static int dotCmdImport(ShellState *p){
     if( ckEnd<2 ){
       i64 savedLn = p->lineno;
       p->lineno = iStart;
-      dotCmdError(p, 0, 0,"Content terminator \"%s\" not found.",
-                  &sCtx.zFile[2]);
+      dotCmdError(p, 0, 0,"Content terminator \"%s\" not found.",zEndMark);
       p->lineno = savedLn;
       import_cleanup(&sCtx);
       return 1;
@@ -7732,6 +7736,7 @@ static int dotCmdImport(ShellState *p){
         cli_printf(stderr,"%s:%d: INSERT failed: %s\n",
               sCtx.zFile, startLine, sqlite3_errmsg(p->db));
         sCtx.nErr++;
+        if( bail_on_error ) break;
       }else{
         sCtx.nRow++;
       }
@@ -7744,9 +7749,9 @@ static int dotCmdImport(ShellState *p){
   if( eVerbose>0 ){
     cli_printf(p->out,
           "Added %d rows with %d errors using %d lines of input\n",
-          sCtx.nRow, sCtx.nErr, sCtx.nLine-1);
+          sCtx.nRow, sCtx.nErr, sCtx.nLine-1-iLineOffset);
   }
-  return 0;
+  return sCtx.nErr ? 1 : 0;
 }
 
 
index c1535f05eaa6585945be0229ca7dffdb3b0f0724..8e1466054531f6a94fa292386a7814e4f64f477d 100644 (file)
@@ -615,4 +615,36 @@ do_test shell5-8.1 {
   catchcmd :memory: {.import --csv shell5.csv '""""""""""""""""""""""""""""""""""""""""""""""'}
 } {0 {}}
 
+
+# 2025-12-29 https://sqlite.org/forum/forumpost/6c1c0e213d
+# .import honor .bail
+#
+do_test shell5-9.1 {
+  catchcmd ":memory:" {
+    CREATE TABLE t1(a,b,c INT CHECK(c<>5));
+.bail on
+.import -csv <<END t1
+1,2,3
+"a","b","c"
+3,4,5
+"q","r","s"
+END
+SELECT * FROM t1;}
+} {1 {<stdin>:7: INSERT failed: CHECK constraint failed: c<>5}}
+do_test shell5-9.2 {
+  catchcmd ":memory:" {
+    CREATE TABLE t1(a,b,c INT CHECK(c<>5));
+.bail off
+.import -csv <<END t1
+1,2,3
+"a","b","c"
+3,4,5
+"q","r","s"
+END
+SELECT * FROM t1;}
+} {1 {1|2|3
+a|b|c
+q|r|s
+<stdin>:7: INSERT failed: CHECK constraint failed: c<>5}}
+
 finish_test