From: drh Date: Sat, 24 Dec 2016 21:32:40 +0000 (+0000) Subject: Combine the implementations of the ".tables" and ".indexes" commands in the X-Git-Tag: version-3.16.0~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6a5a4208fce89a15870af87d4254e0caa99323a8;p=thirdparty%2Fsqlite.git Combine the implementations of the ".tables" and ".indexes" commands in the command-line shell. The ".indexes" command now puts the indexes in multiple columns, just like ".tables" and shows all indexes in all attached databases. FossilOrigin-Name: def29333655691c7d54451193be13445a2857d29 --- diff --git a/manifest b/manifest index 7ac383dc3b..f144229d72 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C The\sschema\sname\s"main"\sis\salways\san\sacceptable\salias\sfor\sthe\sprimary\sdatabase\neven\sif\sthe\sprimary\sdatabase\sis\srenamed\susing\sSQLITE_DBCONFIG_MAINDBNAME. -D 2016-12-24T19:37:16.675 +C Combine\sthe\simplementations\sof\sthe\s".tables"\sand\s".indexes"\scommands\sin\sthe\ncommand-line\sshell.\s\sThe\s".indexes"\scommand\snow\sputs\sthe\sindexes\sin\smultiple\ncolumns,\sjust\slike\s".tables"\sand\sshows\sall\sindexes\sin\sall\sattached\sdatabases. +D 2016-12-24T21:32:40.591 F Makefile.in 41bd4cad981487345c4a84081074bcdb876e4b2e F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc b8ca53350ae545e3562403d5da2a69cec79308da @@ -389,7 +389,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c bb070cf5f23611c44ab7e4788803684e385fc3fb F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c dfb6cadc3dcfba1b1bdbfba62ebba2b4b673413e -F src/shell.c 1594340a8c7b75751b73950f0006643d116d3ef5 +F src/shell.c 48ab675e5526903d2b7bea8c9736cafa345544e1 F src/sqlite.h.in e8e2d108d82647f0a812fdb74accf91c1ec08ddc F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae @@ -1539,7 +1539,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8558512e9ca343300a767ef23810f2d7b50fd925 -R b30977e76e92562c072b2b96c5549420 +P 2f481b854f04bec546eb172d1b6dbc88067d3fda +R c83fd4223f5b56b5947d45d91cd58312 U drh -Z d1e40bfcd22533ee4ef2e0ad49608c3a +Z f50c0755f44c554bddf33086d9d8e98a diff --git a/manifest.uuid b/manifest.uuid index 8afde31bf9..021315cf1a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2f481b854f04bec546eb172d1b6dbc88067d3fda \ No newline at end of file +def29333655691c7d54451193be13445a2857d29 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 2ad6c8c195..ae833d767a 100644 --- a/src/shell.c +++ b/src/shell.c @@ -4090,52 +4090,6 @@ static int do_meta_command(char *zLine, ShellState *p){ if( needCommit ) sqlite3_exec(p->db, "COMMIT", 0, 0, 0); }else - if( c=='i' && (strncmp(azArg[0], "indices", n)==0 - || strncmp(azArg[0], "indexes", n)==0) ){ - ShellState data; - char *zErrMsg = 0; - open_db(p, 0); - memcpy(&data, p, sizeof(data)); - data.showHeader = 0; - data.cMode = data.mode = MODE_List; - if( nArg==1 ){ - rc = sqlite3_exec(p->db, - "SELECT name FROM sqlite_master " - "WHERE type='index' AND name NOT LIKE 'sqlite_%' " - "UNION ALL " - "SELECT name FROM sqlite_temp_master " - "WHERE type='index' " - "ORDER BY 1", - callback, &data, &zErrMsg - ); - }else if( nArg==2 ){ - zShellStatic = azArg[1]; - rc = sqlite3_exec(p->db, - "SELECT name FROM sqlite_master " - "WHERE type='index' AND tbl_name LIKE shellstatic() " - "UNION ALL " - "SELECT name FROM sqlite_temp_master " - "WHERE type='index' AND tbl_name LIKE shellstatic() " - "ORDER BY 1", - callback, &data, &zErrMsg - ); - zShellStatic = 0; - }else{ - raw_printf(stderr, "Usage: .indexes ?LIKE-PATTERN?\n"); - rc = 1; - goto meta_command_exit; - } - if( zErrMsg ){ - utf8_printf(stderr,"Error: %s\n", zErrMsg); - sqlite3_free(zErrMsg); - rc = 1; - }else if( rc != SQLITE_OK ){ - raw_printf(stderr, - "Error: querying sqlite_master and sqlite_temp_master\n"); - rc = 1; - } - }else - #ifndef SQLITE_UNTESTABLE if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){ char *zSql; @@ -4959,7 +4913,10 @@ static int do_meta_command(char *zLine, ShellState *p){ } }else - if( c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0 ){ + if( (c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0) + || (c=='i' && (strncmp(azArg[0], "indices", n)==0 + || strncmp(azArg[0], "indexes", n)==0) ) + ){ sqlite3_stmt *pStmt; char **azResult; int nRow, nAlloc; @@ -4972,28 +4929,41 @@ static int do_meta_command(char *zLine, ShellState *p){ /* Create an SQL statement to query for the list of tables in the ** main and all attached databases where the table name matches the ** LIKE pattern bound to variable "?1". */ - zSql = sqlite3_mprintf( - "SELECT name FROM sqlite_master" - " WHERE type IN ('table','view')" - " AND name NOT LIKE 'sqlite_%%'" - " AND name LIKE ?1"); + if( c=='t' ){ + zSql = sqlite3_mprintf( + "SELECT name FROM sqlite_master" + " WHERE type IN ('table','view')" + " AND name NOT LIKE 'sqlite_%%'" + " AND name LIKE ?1"); + }else if( nArg>2 ){ + /* It is an historical accident that the .indexes command shows an error + ** when called with the wrong number of arguments whereas the .tables + ** command does not. */ + raw_printf(stderr, "Usage: .indexes ?LIKE-PATTERN?\n"); + rc = 1; + goto meta_command_exit; + }else{ + zSql = sqlite3_mprintf( + "SELECT name FROM sqlite_master" + " WHERE type='index'" + " AND tbl_name LIKE ?1"); + } for(ii=0; zSql && sqlite3_step(pStmt)==SQLITE_ROW; ii++){ const char *zDbName = (const char*)sqlite3_column_text(pStmt, 1); if( zDbName==0 || ii==0 ) continue; - if( strcmp(zDbName,"temp")==0 ){ + if( c=='t' ){ zSql = sqlite3_mprintf( "%z UNION ALL " - "SELECT 'temp.' || name FROM sqlite_temp_master" + "SELECT '%q.' || name FROM \"%w\".sqlite_master" " WHERE type IN ('table','view')" " AND name NOT LIKE 'sqlite_%%'" - " AND name LIKE ?1", zSql); + " AND name LIKE ?1", zSql, zDbName, zDbName); }else{ zSql = sqlite3_mprintf( "%z UNION ALL " "SELECT '%q.' || name FROM \"%w\".sqlite_master" - " WHERE type IN ('table','view')" - " AND name NOT LIKE 'sqlite_%%'" - " AND name LIKE ?1", zSql, zDbName, zDbName); + " WHERE type='index'" + " AND tbl_name LIKE ?1", zSql, zDbName, zDbName); } } rc = sqlite3_finalize(pStmt);