| | @@ -4088,56 +4088,10 @@ |
| 4088 | 4088 | sqlite3_free(sCtx.z); |
| 4089 | 4089 | sqlite3_finalize(pStmt); |
| 4090 | 4090 | if( needCommit ) sqlite3_exec(p->db, "COMMIT", 0, 0, 0); |
| 4091 | 4091 | }else |
| 4092 | 4092 | |
| 4093 | | - if( c=='i' && (strncmp(azArg[0], "indices", n)==0 |
| 4094 | | - || strncmp(azArg[0], "indexes", n)==0) ){ |
| 4095 | | - ShellState data; |
| 4096 | | - char *zErrMsg = 0; |
| 4097 | | - open_db(p, 0); |
| 4098 | | - memcpy(&data, p, sizeof(data)); |
| 4099 | | - data.showHeader = 0; |
| 4100 | | - data.cMode = data.mode = MODE_List; |
| 4101 | | - if( nArg==1 ){ |
| 4102 | | - rc = sqlite3_exec(p->db, |
| 4103 | | - "SELECT name FROM sqlite_master " |
| 4104 | | - "WHERE type='index' AND name NOT LIKE 'sqlite_%' " |
| 4105 | | - "UNION ALL " |
| 4106 | | - "SELECT name FROM sqlite_temp_master " |
| 4107 | | - "WHERE type='index' " |
| 4108 | | - "ORDER BY 1", |
| 4109 | | - callback, &data, &zErrMsg |
| 4110 | | - ); |
| 4111 | | - }else if( nArg==2 ){ |
| 4112 | | - zShellStatic = azArg[1]; |
| 4113 | | - rc = sqlite3_exec(p->db, |
| 4114 | | - "SELECT name FROM sqlite_master " |
| 4115 | | - "WHERE type='index' AND tbl_name LIKE shellstatic() " |
| 4116 | | - "UNION ALL " |
| 4117 | | - "SELECT name FROM sqlite_temp_master " |
| 4118 | | - "WHERE type='index' AND tbl_name LIKE shellstatic() " |
| 4119 | | - "ORDER BY 1", |
| 4120 | | - callback, &data, &zErrMsg |
| 4121 | | - ); |
| 4122 | | - zShellStatic = 0; |
| 4123 | | - }else{ |
| 4124 | | - raw_printf(stderr, "Usage: .indexes ?LIKE-PATTERN?\n"); |
| 4125 | | - rc = 1; |
| 4126 | | - goto meta_command_exit; |
| 4127 | | - } |
| 4128 | | - if( zErrMsg ){ |
| 4129 | | - utf8_printf(stderr,"Error: %s\n", zErrMsg); |
| 4130 | | - sqlite3_free(zErrMsg); |
| 4131 | | - rc = 1; |
| 4132 | | - }else if( rc != SQLITE_OK ){ |
| 4133 | | - raw_printf(stderr, |
| 4134 | | - "Error: querying sqlite_master and sqlite_temp_master\n"); |
| 4135 | | - rc = 1; |
| 4136 | | - } |
| 4137 | | - }else |
| 4138 | | - |
| 4139 | 4093 | #ifndef SQLITE_UNTESTABLE |
| 4140 | 4094 | if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){ |
| 4141 | 4095 | char *zSql; |
| 4142 | 4096 | char *zCollist = 0; |
| 4143 | 4097 | sqlite3_stmt *pStmt; |
| | @@ -4957,11 +4911,14 @@ |
| 4957 | 4911 | raw_printf(stderr, "Usage: .stats ?on|off?\n"); |
| 4958 | 4912 | rc = 1; |
| 4959 | 4913 | } |
| 4960 | 4914 | }else |
| 4961 | 4915 | |
| 4962 | | - if( c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0 ){ |
| 4916 | + if( (c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0) |
| 4917 | + || (c=='i' && (strncmp(azArg[0], "indices", n)==0 |
| 4918 | + || strncmp(azArg[0], "indexes", n)==0) ) |
| 4919 | + ){ |
| 4963 | 4920 | sqlite3_stmt *pStmt; |
| 4964 | 4921 | char **azResult; |
| 4965 | 4922 | int nRow, nAlloc; |
| 4966 | 4923 | char *zSql = 0; |
| 4967 | 4924 | int ii; |
| | @@ -4970,32 +4927,45 @@ |
| 4970 | 4927 | if( rc ) return shellDatabaseError(p->db); |
| 4971 | 4928 | |
| 4972 | 4929 | /* Create an SQL statement to query for the list of tables in the |
| 4973 | 4930 | ** main and all attached databases where the table name matches the |
| 4974 | 4931 | ** LIKE pattern bound to variable "?1". */ |
| 4975 | | - zSql = sqlite3_mprintf( |
| 4976 | | - "SELECT name FROM sqlite_master" |
| 4977 | | - " WHERE type IN ('table','view')" |
| 4978 | | - " AND name NOT LIKE 'sqlite_%%'" |
| 4979 | | - " AND name LIKE ?1"); |
| 4932 | + if( c=='t' ){ |
| 4933 | + zSql = sqlite3_mprintf( |
| 4934 | + "SELECT name FROM sqlite_master" |
| 4935 | + " WHERE type IN ('table','view')" |
| 4936 | + " AND name NOT LIKE 'sqlite_%%'" |
| 4937 | + " AND name LIKE ?1"); |
| 4938 | + }else if( nArg>2 ){ |
| 4939 | + /* It is an historical accident that the .indexes command shows an error |
| 4940 | + ** when called with the wrong number of arguments whereas the .tables |
| 4941 | + ** command does not. */ |
| 4942 | + raw_printf(stderr, "Usage: .indexes ?LIKE-PATTERN?\n"); |
| 4943 | + rc = 1; |
| 4944 | + goto meta_command_exit; |
| 4945 | + }else{ |
| 4946 | + zSql = sqlite3_mprintf( |
| 4947 | + "SELECT name FROM sqlite_master" |
| 4948 | + " WHERE type='index'" |
| 4949 | + " AND tbl_name LIKE ?1"); |
| 4950 | + } |
| 4980 | 4951 | for(ii=0; zSql && sqlite3_step(pStmt)==SQLITE_ROW; ii++){ |
| 4981 | 4952 | const char *zDbName = (const char*)sqlite3_column_text(pStmt, 1); |
| 4982 | 4953 | if( zDbName==0 || ii==0 ) continue; |
| 4983 | | - if( strcmp(zDbName,"temp")==0 ){ |
| 4984 | | - zSql = sqlite3_mprintf( |
| 4985 | | - "%z UNION ALL " |
| 4986 | | - "SELECT 'temp.' || name FROM sqlite_temp_master" |
| 4987 | | - " WHERE type IN ('table','view')" |
| 4988 | | - " AND name NOT LIKE 'sqlite_%%'" |
| 4989 | | - " AND name LIKE ?1", zSql); |
| 4990 | | - }else{ |
| 4954 | + if( c=='t' ){ |
| 4991 | 4955 | zSql = sqlite3_mprintf( |
| 4992 | 4956 | "%z UNION ALL " |
| 4993 | 4957 | "SELECT '%q.' || name FROM \"%w\".sqlite_master" |
| 4994 | 4958 | " WHERE type IN ('table','view')" |
| 4995 | 4959 | " AND name NOT LIKE 'sqlite_%%'" |
| 4996 | 4960 | " AND name LIKE ?1", zSql, zDbName, zDbName); |
| 4961 | + }else{ |
| 4962 | + zSql = sqlite3_mprintf( |
| 4963 | + "%z UNION ALL " |
| 4964 | + "SELECT '%q.' || name FROM \"%w\".sqlite_master" |
| 4965 | + " WHERE type='index'" |
| 4966 | + " AND tbl_name LIKE ?1", zSql, zDbName, zDbName); |
| 4997 | 4967 | } |
| 4998 | 4968 | } |
| 4999 | 4969 | rc = sqlite3_finalize(pStmt); |
| 5000 | 4970 | if( zSql && rc==SQLITE_OK ){ |
| 5001 | 4971 | zSql = sqlite3_mprintf("%z ORDER BY 1", zSql); |
| 5002 | 4972 | |