]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Test cases for .import, as well as minor enhancements to .import and to .check. master
authordrh <>
Sun, 28 Dec 2025 21:37:58 +0000 (21:37 +0000)
committerdrh <>
Sun, 28 Dec 2025 21:37:58 +0000 (21:37 +0000)
FossilOrigin-Name: 0252ac1c946cd2101f0084f11951b1aeea330dea23b707934c8852d9abe136b9

manifest
manifest.uuid
src/shell.c.in
test/import01.sql [new file with mode: 0644]
test/modeA.sql
test/shellB.test

index dc2d3989062c84c4051d4abb26d831c252c6c300..c2b59ec9b2894cad450040596fb136f34e44109e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C If\sthe\sfilename\sargument\sto\sthe\s.import\scommand\sis\sof\sthe\sform\n"&lt;&lt;endmark"\sthen\sthe\scontent\sis\sread\sfrom\sthe\sscript\s(or\sstdin)\suntil\nthe\sfirst\sline\sthat\sbegins\swith\s"endmark".
-D 2025-12-28T14:32:28.710
+C Test\scases\sfor\s.import,\sas\swell\sas\sminor\senhancements\sto\s.import\sand\sto\s.check.
+D 2025-12-28T21:37:58.718
 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 35396d39cf51e4bfcfee81c4d65b02f91b95d8ee8cec5e98bf1d9213cca40949
+F src/shell.c.in 8806b477d53b3937a995aa1f214f8aa444c16043688525cb95fd81b30c2849e2
 F src/sqlite.h.in b6599377f02ef9d545a8da48959213928b63291ad83ff65e5f3a72bf4fec595d
 F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479
 F src/sqlite3ext.h 5d5330f5f8461f5ce74960436ddcfa53ecd09c2b8b23901e22ae38aec3243998
@@ -1265,6 +1265,7 @@ F test/hook.test 2d89bf9480646feb8093be3a58ea502d6521906779ed960de31dd9c4502c054
 F test/hook2.test b9ff3b8c6519fb67f33192f1afe86e7782ee4ac8
 F test/icu.test 8da7d52cd9722c82f33b0466ed915460cb03c23a38f18a9a2d3ff97da9a4a8c0
 F test/ieee754.test 0d3ab84ab2069c9994c833a7cd820ee6037f0cf888e206a4a7fc05f735d5790a
+F test/import01.sql 1e73de7fe4d23e83678cb0d0d58484fc34c5f583803a19b7477ee0308a207cd0
 F test/imposter1.sql fc5ad0945bb19622688c7a1cd7dfd1cefa4b013bac9e2628c22b03c7309f021f
 F test/imposter1.test 5a20b2cdeb53e65fc57cdb10a33750bd4ef6259909eaf1972253b9e79f7a3fb2
 F test/in.test edf979bff3244b9e47849e2b43886631354c8213791f42da92216f08012141af
@@ -1443,7 +1444,7 @@ F test/mmap4.test 2e2b4e32555b58da15176e6fe750f17c9dcf7f93
 F test/mmapcorrupt.test 470fb44fe92e99c1d23701d156f8c17865f5b027063c9119dcfdb842791f4465
 F test/mmapfault.test d4c9eff9cd8c2dc14bc43e71e042f175b0a26fe3
 F test/mmapwarm.test 2272005969cd17a910077bd5082f70bc1fefad9a875afec7fc9af483898ecaf3
-F test/modeA.sql 7ca3b6a04bdf0e6dcaee1f43fde35c7ba19b3f3adc94e5789168d76521464935
+F test/modeA.sql d10f214f8c36f0cf3cae0e55145e5d139d875a85ef1fb828937817f6e37f4cd8
 F test/multiplex.test d74c034e52805f6de8cc5432cef8c9eb774bb64ec29b83a22effc8ca4dac1f08
 F test/multiplex2.test 580ca5817c7edbe4cc68fa150609c9473393003a
 F test/multiplex3.test fac575e0b1b852025575a6a8357701d80933e98b5d2fe6d35ddaa68f92f6a1f7
@@ -1623,7 +1624,7 @@ F test/shell7.test 43fd8e511c533bab5232e95c7b4be93b243451709e89582600d4b6e67693d
 F test/shell8.test 641cf21a99c59404c24e3062923734951c4099a6b6b6520de00cf7a1249ee871
 F test/shell9.test 8742a5b390cdcef6369f5aa223e415aa4255a4129ef249b177887dc635a87209
 F test/shellA.test 05cdaafa1f79913654487ce3aefa038d4106245d58f52e02faf506140a76d480
-F test/shellB.test 8bdf078c0a539d45f0fed74519f6d859ae1f3101b0e287035f994089d4ccb602
+F test/shellB.test af842c24a455feaeca0a03d8d69d477170bb3130757b90c266180d447acba12f
 F test/shmlock.test 9f1f729a7fe2c46c88b156af819ac9b72c0714ac6f7246638a73c5752b5fd13c
 F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3
 F test/show_speedtest1_rtree.tcl 32e6c5f073d7426148a6936a0408f4b5b169aba5
@@ -2188,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 436ed7937bcd3b5781539d883ff2957b81d74abccb75f65a2ffb7446a5944522
-R c6951f2ba3a0d1f38f6ef6bfc8ae18c1
+P 6e8ab51fbe0ee918bce6ab960c9fb078764aa9721ef41d39818127eb98045d46
+R 8eadc3683ae1edb25c521107f8b2e915
 U drh
-Z 8253cdf56e85c54f922d095ac05cd420
+Z 6d2e0ca98a0f666557e439a5406ebfa3
 # Remove this line to create a well-formed Fossil manifest.
index cc58ec3a276f426bb560951e801ec1a7d8a9983d..f9665dc4af24ea97aabdbe0e281f1f6b187eed14 100644 (file)
@@ -1 +1 @@
-6e8ab51fbe0ee918bce6ab960c9fb078764aa9721ef41d39818127eb98045d46
+0252ac1c946cd2101f0084f11951b1aeea330dea23b707934c8852d9abe136b9
index ea4329bfdf06d0b6c5d1d73705e84fc8ca91373b..c309d2a0ff4817f99f75e2d094d8a171d9439f79 100644 (file)
@@ -7690,6 +7690,10 @@ static int dotCmdImport(ShellState *p){
       }
       sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
       if( i<nCol-1 && sCtx.cTerm!=sCtx.cColSep ){
+        if( i==0 && (strcmp(z,"\n")==0 || strcmp(z,"\r\n")==0) ){
+          /* Ignore trailing \n or \r\n when some other row separator */
+          break;
+        }
         cli_printf(stderr,"%s:%d: expected %d columns but found %d"
               " - filling the rest with NULL\n",
               sCtx.zFile, startLine, nCol, i+1);
@@ -8653,7 +8657,7 @@ static int dotCmdCheck(ShellState *p){
     dotCmdError(p, 0, "no PATTERN specified", 0);
     return 1;
   }
-  if( cli_output_capture ){
+  if( cli_output_capture && sqlite3_str_length(cli_output_capture) ){
     zTest = sqlite3_str_value(cli_output_capture);
     shell_check_oom(zTest);
   }else{
diff --git a/test/import01.sql b/test/import01.sql
new file mode 100644 (file)
index 0000000..9b5f420
--- /dev/null
@@ -0,0 +1,70 @@
+#!sqlite3
+#
+# 2025-12-28
+#
+# The author disclaims copyright to this source code.  In place of
+# a legal notice, here is a blessing:
+#
+#    May you do good and not evil.
+#    May you find forgiveness for yourself and forgive others.
+#    May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+# Test cases for the ".import" command of the CLI.
+# To run these tests:
+#
+#   ./sqlite3 test/import01.sql
+#
+
+.testcase setup
+.open :memory:
+.mode tty
+.check ''
+
+.testcase 100
+CREATE TABLE t1(a,b,c);
+.import -csv <<END t1
+111,222,333
+abc,def,ghi
+END
+SELECT * FROM t1;
+.check <<END
+╭───────┬───────┬───────╮
+│   a   │   b   │   c   │
+╞═══════╪═══════╪═══════╡
+│ '111' │ '222' │ '333' │
+│ abc   │ def   │ ghi   │
+╰───────┴───────┴───────╯
+END
+
+.testcase 110
+DELETE FROM t1;
+.import -colsep ";" <<END t1
+this;is a;test
+one;two;three
+END
+SELECT * FROM t1;
+.check <<END
+╭──────┬──────┬───────╮
+│  a   │  b   │   c   │
+╞══════╪══════╪═══════╡
+│ this │ is a │ test  │
+│ one  │ two  │ three │
+╰──────┴──────┴───────╯
+END
+
+.testcase 120
+DELETE FROM t1;
+.import -colsep "," -rowsep ';' <<END t1
+this,is a,test;one,two,three;
+END
+SELECT * FROM t1;
+.check <<END
+╭──────┬──────┬───────╮
+│  a   │  b   │   c   │
+╞══════╪══════╪═══════╡
+│ this │ is a │ test  │
+│ one  │ two  │ three │
+╰──────┴──────┴───────╯
+END
index 6e899852d9c1f6cea020da23d192a3c5c75b9886..781d01610333dbea6b0c8dc16a955958b5848a13 100644 (file)
@@ -14,7 +14,7 @@
 # Test cases for the ".mode" command of the CLI.
 # To run these tests:
 #
-#   ./sqlite3 <test/modeA.clitest
+#   ./sqlite3 test/modeA.sql
 #
 #
 .open :memory:
index 2819536821408a7b96bee2ccccdcb428d2b3c2e0..9ce2dd8c910d2112b773def4dfdee2d7cec47613 100644 (file)
@@ -44,5 +44,6 @@ do_clitest dblwidth-a.sql
 do_clitest vt100-a.sql
 do_clitest regexp1.sql
 do_clitest imposter1.sql
+do_clitest import01.sql
 
 finish_test