** If an input line begins with "." then invoke this routine to ** process that line. ** ** Return 1 on error, 2 to exit, and 0 otherwise. */
| 22971 | ** Return 1 on error, 2 to exit, and 0 otherwise. |
| 22972 | */ |
| 22973 | static int do_meta_command(char *zLine, ShellState *p){ |
| 22974 | int h = 1; |
| 22975 | int nArg = 0; |
| 22976 | int n, c; |
| 22977 | int rc = 0; |
| 22978 | char *azArg[52]; |
| 22979 | |
| 22980 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 22981 | if( p->expert.pExpert ){ |
| 22982 | expertFinish(p, 1, 0); |
| 22983 | } |
| 22984 | #endif |
| 22985 | |
| 22986 | /* Parse the input line into tokens. |
| 22987 | */ |
| 22988 | while( zLine[h] && nArg<ArraySize(azArg)-1 ){ |
| 22989 | while( IsSpace(zLine[h]) ){ h++; } |
| 22990 | if( zLine[h]==0 ) break; |
| 22991 | if( zLine[h]=='\'' || zLine[h]=='"' ){ |
| 22992 | int delim = zLine[h++]; |
| 22993 | azArg[nArg++] = &zLine[h]; |
| 22994 | while( zLine[h] && zLine[h]!=delim ){ |
| 22995 | if( zLine[h]=='\\' && delim=='"' && zLine[h+1]!=0 ) h++; |
| 22996 | h++; |
| 22997 | } |
| 22998 | if( zLine[h]==delim ){ |
| 22999 | zLine[h++] = 0; |
| 23000 | } |
| 23001 | if( delim=='"' ) resolve_backslashes(azArg[nArg-1]); |
| 23002 | }else{ |
| 23003 | azArg[nArg++] = &zLine[h]; |
| 23004 | while( zLine[h] && !IsSpace(zLine[h]) ){ h++; } |
| 23005 | if( zLine[h] ) zLine[h++] = 0; |
| 23006 | resolve_backslashes(azArg[nArg-1]); |
| 23007 | } |
| 23008 | } |
| 23009 | azArg[nArg] = 0; |
| 23010 | |
| 23011 | /* Process the input line. |
| 23012 | */ |
| 23013 | if( nArg==0 ) return 0; /* no tokens, no error */ |
| 23014 | n = strlen30(azArg[0]); |
| 23015 | c = azArg[0][0]; |
| 23016 | clearTempFile(p); |
| 23017 | |
| 23018 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 23019 | if( c=='a' && cli_strncmp(azArg[0], "auth", n)==0 ){ |
| 23020 | if( nArg!=2 ){ |
| 23021 | raw_printf(stderr, "Usage: .auth ON|OFF\n"); |
| 23022 | rc = 1; |
| 23023 | goto meta_command_exit; |
| 23024 | } |
| 23025 | open_db(p, 0); |
| 23026 | if( booleanValue(azArg[1]) ){ |
| 23027 | sqlite3_set_authorizer(p->db, shellAuth, p); |
| 23028 | }else if( p->bSafeModePersist ){ |
| 23029 | sqlite3_set_authorizer(p->db, safeModeAuth, p); |
| 23030 | }else{ |
no test coverage detected