diff options
author | drh <> | 2025-03-05 16:35:51 +0000 |
---|---|---|
committer | drh <> | 2025-03-05 16:35:51 +0000 |
commit | 9f19ea83e75893875572f7cb3a1e89ecf4c1841f (patch) | |
tree | dc875467cfdc5786990d827cfaadc88501ffbbfc /src | |
parent | bf09cbe2cac53b5f38e6ebad85b2594806a9437c (diff) | |
download | sqlite-9f19ea83e75893875572f7cb3a1e89ecf4c1841f.tar.gz sqlite-9f19ea83e75893875572f7cb3a1e89ecf4c1841f.zip |
Improvement output for ".schema --indent" in the CLI when the schema contains
partial indexes with long and complicated WHERE clauses.
FossilOrigin-Name: defd7187ff8c4388f8b5467ed168462ec48215a1f4263bc4128b8e4d89a0bb2a
Diffstat (limited to 'src')
-rw-r--r-- | src/shell.c.in | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/shell.c.in b/src/shell.c.in index 586782f01..1717f76d4 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -2741,6 +2741,8 @@ static int shell_callback( char cEnd = 0; char c; int nLine = 0; + int isIndex; + int isWhere = 0; assert( nArg==1 ); if( azArg[0]==0 ) break; if( sqlite3_strlike("CREATE VIEW%", azArg[0], 0)==0 @@ -2749,6 +2751,8 @@ static int shell_callback( sqlite3_fprintf(p->out, "%s;\n", azArg[0]); break; } + isIndex = sqlite3_strlike("CREATE INDEX%", azArg[0], 0)==0 + || sqlite3_strlike("CREATE UNIQUE INDEX%", azArg[0], 0)==0; z = sqlite3_mprintf("%s", azArg[0]); shell_check_oom(z); j = 0; @@ -2778,14 +2782,26 @@ static int shell_callback( nParen++; }else if( c==')' ){ nParen--; - if( nLine>0 && nParen==0 && j>0 ){ + if( nLine>0 && nParen==0 && j>0 && !isWhere ){ printSchemaLineN(p->out, z, j, "\n"); j = 0; } + }else if( (c=='w' || c=='W') + && nParen==0 && isIndex + && sqlite3_strnicmp("WHERE",&z[i],5)==0 + && !isalnum(z[i+5]) && z[i+5]!='_' ){ + isWhere = 1; + }else if( isWhere && (c=='A' || c=='a') + && nParen==0 + && sqlite3_strnicmp("AND",&z[i],3)==0 + && !isalnum(z[i+3]) && z[i+3]!='_' ){ + printSchemaLineN(p->out, z, j, "\n "); + j = 0; } z[j++] = c; if( nParen==1 && cEnd==0 && (c=='(' || c=='\n' || (c==',' && !wsToEol(z+i+1))) + && !isWhere ){ if( c=='\n' ) j--; printSchemaLineN(p->out, z, j, "\n "); |