aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlarrybr <larrybr@noemail.net>2022-04-16 17:53:25 +0000
committerlarrybr <larrybr@noemail.net>2022-04-16 17:53:25 +0000
commit2d27d36cba01b9ceff2c36ad0cef9468db370024 (patch)
tree9d13fb6099235343b2a05aa8e7db7647edb93f1a /src
parentb192970809949903b955e37b71853585cef864c4 (diff)
downloadsqlite-2d27d36cba01b9ceff2c36ad0cef9468db370024.tar.gz
sqlite-2d27d36cba01b9ceff2c36ad0cef9468db370024.zip
Make shell auto-column work with lots of columns when log() is missing.
FossilOrigin-Name: 82366436ef74838dae1f379f3e5b8ad187225a30ec58fb49f047ab7c08a263cf
Diffstat (limited to 'src')
-rw-r--r--src/shell.c.in13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/shell.c.in b/src/shell.c.in
index 996a7f942..5a2ff6ea2 100644
--- a/src/shell.c.in
+++ b/src/shell.c.in
@@ -7833,7 +7833,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){
#endif /* !(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB) */
-/*
+/*
* zAutoColumn(zCol, &db, ?) => Maybe init db, add column zCol to it.
* zAutoColumn(0, &db, ?) => (db!=0) Form columns spec for CREATE TABLE,
* close db and set it to 0, and return the columns spec, to later
@@ -7916,6 +7916,13 @@ UPDATE ColNames AS t SET reps=\
static const char * const zColDigits = "\
SELECT CAST(ceil(log(count(*)+0.5)) AS INT) FROM ColNames \
";
+#else
+ /* Counting on SQLITE_MAX_COLUMN < 100,000 here. (32767 is the hard limit.) */
+ static const char * const zColDigits = "\
+SELECT CASE WHEN (nc < 10) THEN 1 WHEN (nc < 100) THEN 2 \
+ WHEN (nc < 1000) THEN 3 WHEN (nc < 10000) THEN 4 \
+ ELSE 5 FROM (SELECT count(*) AS nc FROM ColNames) \
+";
#endif
static const char * const zRenameRank =
#ifdef SHELL_COLUMN_RENAME_CLEAN
@@ -8001,11 +8008,7 @@ FROM (\
/* Formulate the columns spec, close the DB, zero *pDb. */
char *zColsSpec = 0;
int hasDupes = db_int(*pDb, zHasDupes);
-#ifdef SQLITE_ENABLE_MATH_FUNCTIONS
int nDigits = (hasDupes)? db_int(*pDb, zColDigits) : 0;
-#else
-# define nDigits 2
-#endif
if( hasDupes ){
#ifdef SHELL_COLUMN_RENAME_CLEAN
rc = sqlite3_exec(*pDb, zDedoctor, 0, 0, 0);