| 773 | */ |
| 774 | |
| 775 | bool alloc_query(THD *thd, const char *packet, uint packet_length) |
| 776 | { |
| 777 | char *query; |
| 778 | /* Remove garbage at start and end of query */ |
| 779 | while (packet_length > 0 && my_isspace(thd->charset(), packet[0])) |
| 780 | { |
| 781 | packet++; |
| 782 | packet_length--; |
| 783 | } |
| 784 | const char *pos= packet + packet_length; // Point at end null |
| 785 | while (packet_length > 0 && |
| 786 | (pos[-1] == ';' || my_isspace(thd->charset() ,pos[-1]))) |
| 787 | { |
| 788 | pos--; |
| 789 | packet_length--; |
| 790 | } |
| 791 | /* We must allocate some extra memory for query cache |
| 792 | |
| 793 | The query buffer layout is: |
| 794 | buffer :== |
| 795 | <statement> The input statement(s) |
| 796 | '\0' Terminating null char (1 byte) |
| 797 | <length> Length of following current database name (size_t) |
| 798 | <db_name> Name of current database |
| 799 | <flags> Flags struct |
| 800 | */ |
| 801 | if (! (query= (char*) thd->memdup_w_gap(packet, |
| 802 | packet_length, |
| 803 | 1 + sizeof(size_t) + thd->db_length))) |
| 804 | return TRUE; |
| 805 | query[packet_length]= '\0'; |
| 806 | /* |
| 807 | Space to hold the name of the current database is allocated. We |
| 808 | also store this length, in case current database is changed during |
| 809 | execution. We might need to reallocate the 'query' buffer |
| 810 | */ |
| 811 | char *len_pos = (query + packet_length + 1); |
| 812 | memcpy(len_pos, (char *) &thd->db_length, sizeof(size_t)); |
| 813 | |
| 814 | thd->set_query(query, packet_length); |
| 815 | thd->rewritten_query.free(); // free here lest PS break |
| 816 | |
| 817 | /* Reclaim some memory */ |
| 818 | thd->convert_buffer.shrink(thd->variables.net_buffer_length); |
| 819 | |
| 820 | return FALSE; |
| 821 | } |
| 822 | |
| 823 | /**************************************************************************** |
| 824 | Check stack size; Send error if there isn't enough stack to continue |
no test coverage detected