aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2024-10-11 14:30:58 +0000
committerdrh <>2024-10-11 14:30:58 +0000
commitb23cce9a16a6b90fed2bd3e189fe4e9f2ff63b68 (patch)
tree18bf8f1a7f947cdbedd365af96c5de6911abb32f /src
parent0b453b3b3379f34527c957c6e1f7631a887c7340 (diff)
downloadsqlite-b23cce9a16a6b90fed2bd3e189fe4e9f2ff63b68.tar.gz
sqlite-b23cce9a16a6b90fed2bd3e189fe4e9f2ff63b68.zip
Fix the CSV output mode in the CLI such that the line ending is NL by default
but goes to CRLF if ".crnl on" is set. Make the .crnl command available on non-Windows builds. Update the .crnl command such that if it has no arguments it shows the current setting. FossilOrigin-Name: da750e39df7bf42330d8c8b266300da07247c9619895861b4cff4be7c94db7cf
Diffstat (limited to 'src')
-rw-r--r--src/shell.c.in40
1 files changed, 19 insertions, 21 deletions
diff --git a/src/shell.c.in b/src/shell.c.in
index 5a90fec7e..ec32acca7 100644
--- a/src/shell.c.in
+++ b/src/shell.c.in
@@ -1629,13 +1629,7 @@ static const char *modeDescr[] = {
#define SEP_Tab "\t"
#define SEP_Space " "
#define SEP_Comma ","
-#ifdef SQLITE_U8TEXT_ONLY
- /* With the SQLITE_U8TEXT_ONLY option, the output will always be in
- ** text mode. The \r will be inserted automatically. */
-# define SEP_CrLf "\n"
-#else
-# define SEP_CrLf "\r\n"
-#endif
+#define SEP_CrLf "\n" /* Use ".crnl on" to get \r\n line endings */
#define SEP_Unit "\x1F"
#define SEP_Record "\x1E"
@@ -2801,13 +2795,21 @@ static int shell_callback(
for(i=0; i<nArg; i++){
output_csv(p, azCol[i] ? azCol[i] : "", i<nArg-1);
}
- sqlite3_fputs(p->rowSeparator, p->out);
+ if( p->crnlMode && cli_strcmp(p->rowSeparator,SEP_CrLf)==0 ){
+ sqlite3_fputs("\r\n", p->out);
+ }else{
+ sqlite3_fputs(p->rowSeparator, p->out);
+ }
}
if( nArg>0 ){
for(i=0; i<nArg; i++){
output_csv(p, azArg[i], i<nArg-1);
}
- sqlite3_fputs(p->rowSeparator, p->out);
+ if( p->crnlMode && cli_strcmp(p->rowSeparator,SEP_CrLf)==0 ){
+ sqlite3_fputs("\r\n", p->out);
+ }else{
+ sqlite3_fputs(p->rowSeparator, p->out);
+ }
}
setCrnlMode(p);
break;
@@ -4952,9 +4954,7 @@ static const char *(azHelp[]) = {
".clone NEWDB Clone data into NEWDB from the existing database",
#endif
".connection [close] [#] Open or close an auxiliary database connection",
-#if defined(_WIN32)
- ".crnl on|off Translate \\n to \\r\\n. Default ON",
-#endif
+ ".crnl on|off Translate \\n to \\r\\n sometimes. Default OFF",
".databases List names and files of attached databases",
".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
#if SQLITE_SHELL_HAVE_RECOVER
@@ -8573,17 +8573,13 @@ static int do_meta_command(char *zLine, ShellState *p){
}else
if( c=='c' && n==4 && cli_strncmp(azArg[0], "crnl", n)==0 ){
-#if !defined(_WIN32)
- sqlite3_fputs("The \".crnl\" command is disable in this build.\n", p->out);
-#else
if( nArg==2 ){
p->crnlMode = booleanValue(azArg[1]);
setCrnlMode(p);
}else{
- eputz("Usage: .crnl on|off\n");
- rc = 1;
+ sqlite3_fprintf(stderr, "crnl is currently %s\n",
+ p->crnlMode ? "ON" : "OFF");
}
-#endif
}else
if( c=='d' && n>1 && cli_strncmp(azArg[0], "databases", n)==0 ){
@@ -12620,9 +12616,11 @@ static void main_init(ShellState *data) {
/* By default, come up in O_BINARY mode. That way, the default output is
** the same for Windows and non-Windows systems. Use the ".crnl on"
** command to change into O_TEXT mode to do automatic NL-to-CRLF
- ** conversions on output for Windows. Windows console output is not
- ** subject to the crnlMode setting and is unaffected either way. This
- ** setting only affects output going into a file or pipe. */
+ ** conversions on output for Windows.
+ **
+ ** End-of-line marks on CVS output is CRLF when in .crnl is on and
+ ** NL when .crnl is off.
+ */
data->crnlMode = 0;
}