Must use thd_alloc() instead of thd->alloc() refs #1964
Must use thd_sql_command() instead of thd->lex->sql_command. refs #1964