diff options
author | drh <> | 2023-06-29 17:26:21 +0000 |
---|---|---|
committer | drh <> | 2023-06-29 17:26:21 +0000 |
commit | a75011a891db06ae496851f8fe8a4a95bec74fe0 (patch) | |
tree | b9a4375b948a0a561b5293b80de52128671ec4d1 /src | |
parent | cd88a74115626bfe6403a08b33cdcb67854bcc07 (diff) | |
download | sqlite-a75011a891db06ae496851f8fe8a4a95bec74fe0.tar.gz sqlite-a75011a891db06ae496851f8fe8a4a95bec74fe0.zip |
Further refine the dtostr() testing function in the CLI so that it takes an
optional second parameter which is the number of significant digits to display.
FossilOrigin-Name: 2f9d4444aa503102a00d6e6769dadc57d4b26a2c07f145f23f2f28e0c161246d
Diffstat (limited to 'src')
-rw-r--r-- | src/shell.c.in | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/shell.c.in b/src/shell.c.in index 5bda7c9cd..fef9d45c3 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -1237,8 +1237,11 @@ static void shellDtostr( sqlite3_value **apVal ){ double r = sqlite3_value_double(apVal[0]); - char z[200]; - sprintf(z, "%#+.26e", r); + int n = nVal>=2 ? sqlite3_value_int(apVal[1]) : 26; + char z[400]; + if( n<1 ) n = 1; + if( n>350 ) n = 350; + sprintf(z, "%#+.*e", n, r); sqlite3_result_text(pCtx, z, -1, SQLITE_TRANSIENT); } @@ -5503,6 +5506,8 @@ static void open_db(ShellState *p, int openFlags){ shellStrtod, 0, 0); sqlite3_create_function(p->db, "dtostr", 1, SQLITE_UTF8, 0, shellDtostr, 0, 0); + sqlite3_create_function(p->db, "dtostr", 2, SQLITE_UTF8, 0, + shellDtostr, 0, 0); sqlite3_create_function(p->db, "shell_add_schema", 3, SQLITE_UTF8, 0, shellAddSchemaName, 0, 0); sqlite3_create_function(p->db, "shell_module_schema", 1, SQLITE_UTF8, 0, |