fix(shell): add help command and fix crete table filed complete include binary

This commit is contained in:
Alex Duan 2022-11-24 11:12:08 +08:00
parent f58396ea8b
commit cd46ca0f5a
3 changed files with 38 additions and 14 deletions

View File

@ -39,4 +39,7 @@ void callbackAutoTab(char* sqlstr, TAOS* pSql, bool usedb);
// introduction
void printfIntroduction();
// show all commands help
void showHelp();
#endif

View File

@ -108,6 +108,7 @@ SWords shellCommands[] = {
{"drop topic <topic_name> ;", 0, 0, NULL},
{"drop stream <stream_name> ;", 0, 0, NULL},
{"explain select", 0, 0, NULL}, // 44 append sub sql
{"help;", 0, 0, NULL},
{"grant all on <anyword> to <user_name> ;", 0, 0, NULL},
{"grant read on <anyword> to <user_name> ;", 0, 0, NULL},
{"grant write on <anyword> to <user_name> ;", 0, 0, NULL},
@ -386,6 +387,8 @@ void showHelp() {
drop stream <stream_name> ;\n\
----- E ----- \n\
explain select clause ...\n\
----- H ----- \n\
help;\n\
----- I ----- \n\
insert into <tb_name> values(...) ;\n\
insert into <tb_name> using <stb_name> tags(...) values(...) ;\n\
@ -1478,24 +1481,36 @@ bool matchSelectQuery(TAOS* con, SShellCmd* cmd) {
// if is input create fields or tags area, return true
bool isCreateFieldsArea(char* p) {
char* left = strrchr(p, '(');
if (left == NULL) {
// like 'create table st'
return false;
}
// put to while, support like create table st(ts timestamp, bin1 binary(16), bin2 + blank + TAB
char* p1 = strdup(p);
bool ret = false;
while (1) {
char* left = strrchr(p1, '(');
if (left == NULL) {
// like 'create table st'
ret = false;
break;
}
char* right = strrchr(p, ')');
if (right == NULL) {
// like 'create table st( '
return true;
}
char* right = strrchr(p1, ')');
if (right == NULL) {
// like 'create table st( '
ret = true;
break;
}
if (left > right) {
// like 'create table st( ts timestamp, age int) tags(area '
return true;
if (left > right) {
// like 'create table st( ts timestamp, age int) tags(area '
ret = true;
break;
}
// set string end by small for next strrchr search
*left = 0;
}
taosMemoryFree(p1);
return false;
return ret;
}
bool matchCreateTable(TAOS* con, SShellCmd* cmd) {

View File

@ -134,6 +134,12 @@ int32_t shellRunCommand(char *command, bool recordHistory) {
return 0;
}
// add help or help;
if(strcmp(command, "help") == 0 || strcmp(command, "help;") == 0) {
showHelp();
return 0;
}
if (recordHistory) shellRecordCommandToHistory(command);
char quote = 0, *cmd = command;