New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MDEV-12192 - Shell-style alias/unalias commands for MariaDB client #321
Conversation
I think you are after http://mycli.net/favorites :-) |
Hi Nirbhay, Thanks for your contribution. JIRA task has been created to track this pull request: https://jira.mariadb.org/browse/MDEV-12192 This task was added to 10.2 backlog, which is planned to be handled between 2017-03-09 and 2017-03-16. Thanks, |
@@ -1289,6 +1302,10 @@ int main(int argc,char *argv[]) | |||
"Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\n"); | |||
put_info(buff,INFO_INFO); | |||
status.exit_status= read_and_execute(!status.batch); | |||
|
|||
/* Free alias hash. */ | |||
deinit_alias(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go into mysql_end()
.
@@ -1196,6 +1205,10 @@ int main(int argc,char *argv[]) | |||
my_end(0); | |||
exit(1); | |||
} | |||
|
|||
/* Init alias hash. */ | |||
init_alias(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't simply exit()
in init_alias()
. We should free_defaults(defaults_argv)
and my_end(0)
as well.
String aliased_buffer; | ||
if (alias_element) | ||
{ | ||
aliased_buffer.copy(alias_element->value, strlen(alias_element->value), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it makes sense to store value
length in ALIAS
?
@@ -3262,6 +3311,7 @@ com_go(String *buffer,char *line __attribute__((unused))) | |||
#endif | |||
|
|||
buffer->length(0); | |||
aliased_buffer.length(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why is this needed?
charset_info); | ||
} | ||
|
||
aliased_buffer.append(alias_end, buffer->length() - alias_len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... how does it work if alias is not found? FWICS we end up with a string which has characters up to a space trimmed, which is not expected right?
I'd generally suggest to use String::set(const char* ...)
for the case when alias is not found. In this case we don't have to memcopy/alloc.
|
||
/* Remove leading whitespaces. */ | ||
while (*ptr && my_isspace(charset_info, *ptr)) | ||
ptr ++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ptr++
, ptr+=
here and everywhere else please.
Since '\0'
is not a space, you don't need to explicitly check for it.
free(line); | ||
|
||
if (file) | ||
my_fclose(file, MYF(0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to close file
unconditionally here, because according to code it can never be NULL
.
@@ -272,6 +279,7 @@ typedef struct { | |||
|
|||
static COMMANDS commands[] = { | |||
{ "?", '?', com_help, 1, "Synonym for `help'." }, | |||
{ "alias", 'a', com_alias, 1, "Print or add aliases." }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate syntax here or anywhere in a comment.
} | ||
*error= false; | ||
} | ||
return pos; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In current implementation, I guess you need to free(name)
. It'd be nice if parse_alias_name
wouldn't do string copy.
{ | ||
my_hash_delete(&aliases, record); | ||
} | ||
alias= (ALIAS *) my_malloc(sizeof(ALIAS), MYF(MY_WME)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please either allocate ALIAS
+ name
+ value
at once or use MEM_ROOT
for all allocations.
No feedback was provided for this pull request for over a month, so it is being closed. Feel free to reopen if you are able to implement requested changes. |
I submit this patch under the BSD-new license.
Best,
Nirbhay