From: larrybr Date: Tue, 3 May 2022 19:51:22 +0000 (+0000) Subject: Fix multi-byte column name rendition on .import and display of NULL in columnar modes. X-Git-Tag: version-3.38.4~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5854a3611c8ee6367e150ee9a801c16648adef58;p=thirdparty%2Fsqlite.git Fix multi-byte column name rendition on .import and display of NULL in columnar modes. FossilOrigin-Name: f863aabe9da11b9d424362543536c929f34a0f632ba973c278d4cd56e21960fa --- diff --git a/manifest b/manifest index 3ab47885dc..419c65855a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Increase\sthe\sversion\snumber\sto\s3.38.4. -D 2022-05-03T14:26:58.550 +C Fix\smulti-byte\scolumn\sname\srendition\son\s.import\sand\sdisplay\sof\sNULL\sin\scolumnar\smodes. +D 2022-05-03T19:51:22.532 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -553,7 +553,7 @@ F src/random.c 097dc8b31b8fba5a9aca1697aeb9fd82078ec91be734c16bffda620ced7ab83c F src/resolve.c ea935b87d6fb36c78b70cdc7b28561dc8f33f2ef37048389549c7b5ef9b0ba5e F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92 F src/select.c ba0cd3d264fa788c8d65f063d5ec3e1d65b0dac206c822a564a59ba550210cfc -F src/shell.c.in ec4b952f7d9c02919e8e8394be16bcbff55c105fd080895602d10fc8fa5328b8 +F src/shell.c.in e2bc31eca23a1d1d2aaea02dcfde6dfe0ee96bdfa6cbcc36c79f02e457bef18c F src/sqlite.h.in b93deee892f1bc4030e5c8712df9e21d786a1bf8e921ab8dc987eaf1e44c676f F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h a95cb9ed106e3d39e2118e4dcc15a14faec3fa50d0093425083d340d9dfd96e6 @@ -1388,11 +1388,11 @@ F test/sharedA.test 49d87ec54ab640fbbc3786ee3c01de94aaa482a3a9f834ad3fe92770eb69 F test/sharedB.test 16cc7178e20965d75278f410943109b77b2e645e F test/shared_err.test 32634e404a3317eeb94abc7a099c556a346fdb8fb3858dbe222a4cbb8926a939 F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304 -F test/shell1.test b224e0793c5f48aa3749e65d8c64b93a30731bd206f2e41e6c5f1bee1bdb16c6 +F test/shell1.test f7a2ef8260aa01f20be3185118213b1ae70518fdcd2105f3e25b021b5ca800ac F test/shell2.test 7a3a23a9f57b99453f1679b1fe8072cb30e382a622874c0c4d97695fadb0a787 F test/shell3.test a50628ab1d78d90889d9d3f32fb2c084ee15674771e96afe954aaa0accd1de3c F test/shell4.test 8f6c0fce4abed19a8a7f7262517149812a04caa905d01bdc8f5e92573504b759 -F test/shell5.test 0a9920d81fae28c45cd5dbd1deb809487a23c5f4b422a49f9d31c85f926d4a9c +F test/shell5.test 78a7a8516b1e7de560748881424f621321549023d3e5f7ed2e1c56497f64c06c F test/shell6.test 1ceb51b2678c472ba6cf1e5da96679ce8347889fe2c3bf93a0e0fa73f00b00d3 F test/shell7.test 115132f66d0463417f408562cc2cf534f6bbc6d83a6d50f0072a9eb171bae97f F test/shell8.test 388471d16e4de767333107e30653983f186232c0e863f4490bb230419e830aae @@ -1944,8 +1944,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 3dc9fc2f2de8696b67d0fc6f414398625d6fe7de108e95b443fb11e8f460b84c -R a275a6749c13af260d7d1d0222df3e57 -U drh -Z 3341a8b5e552909fb3760d546107699b +P def971a0e90212a2387967d4a4b266a7c39129ad66fb7df7bf11f6979d1e524a +Q +21e96600d90c1cda84777abe22a11058eba46c9faefeb05f8c31bc0e7fa84b19 +Q +77aed89192bdbad819ac17bf5d08728278a9b8cbbbef1d805df230caff79b417 +Q +dfd2100bc4f316825fd199b347849d1a2b941837f9eedcf36f3c3d280692b991 +R bc7c810360b7b2c9fe8a3f83de0daf96 +U larrybr +Z 8e27acbdaff1028d4e6e2d1634565657 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index eea884b9e0..c764644f2c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -def971a0e90212a2387967d4a4b266a7c39129ad66fb7df7bf11f6979d1e524a \ No newline at end of file +f863aabe9da11b9d424362543536c929f34a0f632ba973c278d4cd56e21960fa \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index c0b5898e6e..9626c46627 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -3346,6 +3346,8 @@ static void exec_prepared_stmt_columnar( int bNextLine = 0; int bMultiLineRowExists = 0; int bw = p->cmOpts.bWordWrap; + const char *zEmpty = ""; + const char *zShowNull = p->nullValue; rc = sqlite3_step(pStmt); if( rc!=SQLITE_ROW ) return; @@ -3407,12 +3409,14 @@ static void exec_prepared_stmt_columnar( if( wx<0 ) wx = -wx; if( useNextLine ){ uz = azNextLine[i]; + if( uz==0 ) uz = (u8*)zEmpty; }else if( p->cmOpts.bQuote ){ sqlite3_free(azQuoted[i]); azQuoted[i] = quoted_column(pStmt,i); uz = (const unsigned char*)azQuoted[i]; }else{ uz = (const unsigned char*)sqlite3_column_text(pStmt,i); + if( uz==0 ) uz = (u8*)zShowNull; } azData[nRow*nColumn + i] = translateForDisplayAndDup(uz, &azNextLine[i], wx, bw); @@ -3426,7 +3430,7 @@ static void exec_prepared_stmt_columnar( nTotal = nColumn*(nRow+1); for(i=0; inullValue; + if( z==0 ) z = (char*)zEmpty; n = strlenChar(z); j = i%nColumn; if( n>p->actualWidth[j] ) p->actualWidth[j] = n; @@ -3530,7 +3534,10 @@ columnar_end: utf8_printf(p->out, "Interrupt\n"); } nData = (nRow+1)*nColumn; - for(i=0; i0, ' ', x'0a'||' '))\ ||')' AS ColsSpec \ FROM (\ - SELECT cpos, printf('\"%w\"',printf('%.*s%s', nlen-chop,name,suff)) AS cname \ + SELECT cpos, printf('\"%w\"',printf('%!.*s%s', nlen-chop,name,suff)) AS cname \ FROM ColNames ORDER BY cpos\ )"; static const char * const zRenamesDone = "SELECT group_concat(" - " printf('\"%w\" to \"%w\"',name,printf('%.*s%s', nlen-chop, name, suff))," + " printf('\"%w\" to \"%w\"',name,printf('%!.*s%s', nlen-chop, name, suff))," " ','||x'0a')" "FROM ColNames WHERE suff<>'' OR chop!=0" ; diff --git a/test/shell1.test b/test/shell1.test index cbbadc58c9..3c7061c55d 100644 --- a/test/shell1.test +++ b/test/shell1.test @@ -1221,6 +1221,23 @@ do_test shell1-8.4 { +------------------+-----+ | 6683623321994527 | -47 | +------------------+-----+}} +do_test shell1-8.5 { + catchcmd ":memory: --box" { +create table t(a text, b int); +insert into t values ('too long for one line', 1), ('shorter', NULL); +.header on +.width 10 10 +.nullvalue NADA +select * from t;} +} {0 {┌────────────┬────────────┐ +│ a │ b │ +├────────────┼────────────┤ +│ too long f │ 1 │ +│ or one lin │ │ +│ e │ │ +├────────────┼────────────┤ +│ shorter │ NADA │ +└────────────┴────────────┘}} #---------------------------------------------------------------------------- # Test cases shell1-9.*: Basic test that "dot" commands and SQL intermix ok. diff --git a/test/shell5.test b/test/shell5.test index d63a0a20d3..00d89f8d78 100644 --- a/test/shell5.test +++ b/test/shell5.test @@ -540,4 +540,34 @@ Columns renamed during .import shell5.csv due to duplicates: "CoW" to "CoW_3", "cOw" to "cOw_4"}} +#---------------------------------------------------------------------------- +# Tests for preserving utf-8 that is not also ASCII. +# + +do_test shell5-6.1 { + set out [open shell5.csv w] + fconfigure $out -translation lf + puts $out {あい,うえお} + puts $out {1,2} + close $out + forcedelete test.db + catchcmd test.db {.import -csv shell5.csv t1 +.mode line +SELECT * FROM t1;} +} {0 { あい = 1 +うえお = 2}} + +do_test shell5-6.2 { + set out [open shell5.csv w] + fconfigure $out -translation lf + puts $out {1,2} + puts $out {あい,うえお} + close $out + forcedelete test.db + catchcmd test.db {.import -csv shell5.csv t1 +.mode line +SELECT * FROM t1;} +} {0 { 1 = あい + 2 = うえお}} + finish_test