#include "mysql_priv.h"#include "sql_select.h"#include "sql_cursor.h"#include "sp_head.h"#include "sp.h"#include "sp_cache.h"#include <mysql_com.h>Include dependency graph for sql_prepare.cc:

Go to the source code of this file.
| static bool check_prepared_statement | ( | Prepared_statement * | stmt, | |
| bool | text_protocol | |||
| ) | [static] |
Definition at line 1658 of file sql_prepare.cc.
References DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, ER, ER_UNSUPPORTED_PS, error, FALSE, my_message(), MYF, mysql_test_create_table(), mysql_test_delete(), mysql_test_do_fields(), mysql_test_insert(), mysql_test_insert_select(), mysql_test_multidelete(), mysql_test_multiupdate(), mysql_test_select(), mysql_test_set_fields(), mysql_test_update(), Prepared_statement::param_count, st_table_list::select_lex, send_prep_stmt(), sql_command_flags, SQLCOM_ALTER_TABLE, SQLCOM_ANALYZE, SQLCOM_ASSIGN_TO_KEYCACHE, SQLCOM_CALL, SQLCOM_CHANGE_MASTER, SQLCOM_CHECKSUM, SQLCOM_COMMIT, SQLCOM_CREATE_DB, SQLCOM_CREATE_INDEX, SQLCOM_CREATE_TABLE, SQLCOM_CREATE_USER, SQLCOM_CREATE_VIEW, SQLCOM_DELETE, SQLCOM_DELETE_MULTI, SQLCOM_DO, SQLCOM_DROP_DB, SQLCOM_DROP_INDEX, SQLCOM_DROP_TABLE, SQLCOM_DROP_USER, SQLCOM_DROP_VIEW, SQLCOM_FLUSH, SQLCOM_GRANT, SQLCOM_INSERT, SQLCOM_INSERT_SELECT, SQLCOM_INSTALL_PLUGIN, SQLCOM_KILL, SQLCOM_OPTIMIZE, SQLCOM_PRELOAD_KEYS, SQLCOM_RENAME_DB, SQLCOM_RENAME_TABLE, SQLCOM_RENAME_USER, SQLCOM_REPAIR, SQLCOM_REPLACE, SQLCOM_REPLACE_SELECT, SQLCOM_RESET, SQLCOM_REVOKE, SQLCOM_ROLLBACK, SQLCOM_SELECT, SQLCOM_SET_OPTION, SQLCOM_SHOW_AUTHORS, SQLCOM_SHOW_BINLOG_EVENTS, SQLCOM_SHOW_BINLOGS, SQLCOM_SHOW_COLUMN_TYPES, SQLCOM_SHOW_CONTRIBUTORS, SQLCOM_SHOW_CREATE, SQLCOM_SHOW_CREATE_DB, SQLCOM_SHOW_CREATE_EVENT, SQLCOM_SHOW_CREATE_FUNC, SQLCOM_SHOW_CREATE_PROC, SQLCOM_SHOW_ENGINE_LOGS, SQLCOM_SHOW_ENGINE_MUTEX, SQLCOM_SHOW_ENGINE_STATUS, SQLCOM_SHOW_ERRORS, SQLCOM_SHOW_FUNC_CODE, SQLCOM_SHOW_GRANTS, SQLCOM_SHOW_MASTER_STAT, SQLCOM_SHOW_PRIVILEGES, SQLCOM_SHOW_PROC_CODE, SQLCOM_SHOW_PROCESSLIST, SQLCOM_SHOW_SLAVE_STAT, SQLCOM_SHOW_STORAGE_ENGINES, SQLCOM_SHOW_WARNS, SQLCOM_SLAVE_START, SQLCOM_SLAVE_STOP, SQLCOM_TRUNCATE, SQLCOM_UNINSTALL_PLUGIN, SQLCOM_UPDATE, SQLCOM_UPDATE_MULTI, Prepared_statement::thd, and TRUE.
Referenced by Prepared_statement::prepare().
01660 { 01661 THD *thd= stmt->thd; 01662 LEX *lex= stmt->lex; 01663 SELECT_LEX *select_lex= &lex->select_lex; 01664 TABLE_LIST *tables; 01665 enum enum_sql_command sql_command= lex->sql_command; 01666 int res= 0; 01667 DBUG_ENTER("check_prepared_statement"); 01668 DBUG_PRINT("enter",("command: %d, param_count: %ld", 01669 sql_command, stmt->param_count)); 01670 01671 lex->first_lists_tables_same(); 01672 tables= lex->query_tables; 01673 01674 /* set context for commands which do not use setup_tables */ 01675 lex->select_lex.context.resolve_in_table_list_only(select_lex-> 01676 get_table_list()); 01677 01678 switch (sql_command) { 01679 case SQLCOM_REPLACE: 01680 case SQLCOM_INSERT: 01681 res= mysql_test_insert(stmt, tables, lex->field_list, 01682 lex->many_values, 01683 select_lex->item_list, lex->value_list, 01684 lex->duplicates); 01685 break; 01686 01687 case SQLCOM_UPDATE: 01688 res= mysql_test_update(stmt, tables); 01689 /* mysql_test_update returns 2 if we need to switch to multi-update */ 01690 if (res != 2) 01691 break; 01692 01693 case SQLCOM_UPDATE_MULTI: 01694 res= mysql_test_multiupdate(stmt, tables, res == 2); 01695 break; 01696 01697 case SQLCOM_DELETE: 01698 res= mysql_test_delete(stmt, tables); 01699 break; 01700 01701 case SQLCOM_SELECT: 01702 res= mysql_test_select(stmt, tables, text_protocol); 01703 if (res == 2) 01704 { 01705 /* Statement and field info has already been sent */ 01706 DBUG_RETURN(FALSE); 01707 } 01708 break; 01709 case SQLCOM_CREATE_TABLE: 01710 res= mysql_test_create_table(stmt); 01711 break; 01712 01713 case SQLCOM_DO: 01714 res= mysql_test_do_fields(stmt, tables, lex->insert_list); 01715 break; 01716 01717 case SQLCOM_SET_OPTION: 01718 res= mysql_test_set_fields(stmt, tables, &lex->var_list); 01719 break; 01720 01721 case SQLCOM_DELETE_MULTI: 01722 res= mysql_test_multidelete(stmt, tables); 01723 break; 01724 01725 case SQLCOM_INSERT_SELECT: 01726 case SQLCOM_REPLACE_SELECT: 01727 res= mysql_test_insert_select(stmt, tables); 01728 break; 01729 01730 /* 01731 Note that we don't need to have cases in this list if they are 01732 marked with CF_STATUS_COMMAND in sql_command_flags 01733 */ 01734 case SQLCOM_SHOW_PROCESSLIST: 01735 case SQLCOM_SHOW_STORAGE_ENGINES: 01736 case SQLCOM_SHOW_PRIVILEGES: 01737 case SQLCOM_SHOW_COLUMN_TYPES: 01738 case SQLCOM_SHOW_ENGINE_LOGS: 01739 case SQLCOM_SHOW_ENGINE_STATUS: 01740 case SQLCOM_SHOW_ENGINE_MUTEX: 01741 case SQLCOM_SHOW_CREATE_DB: 01742 case SQLCOM_SHOW_GRANTS: 01743 case SQLCOM_SHOW_BINLOG_EVENTS: 01744 case SQLCOM_SHOW_MASTER_STAT: 01745 case SQLCOM_SHOW_SLAVE_STAT: 01746 case SQLCOM_SHOW_CREATE_PROC: 01747 case SQLCOM_SHOW_CREATE_FUNC: 01748 case SQLCOM_SHOW_CREATE_EVENT: 01749 case SQLCOM_SHOW_CREATE: 01750 case SQLCOM_SHOW_PROC_CODE: 01751 case SQLCOM_SHOW_FUNC_CODE: 01752 case SQLCOM_SHOW_AUTHORS: 01753 case SQLCOM_SHOW_CONTRIBUTORS: 01754 case SQLCOM_SHOW_WARNS: 01755 case SQLCOM_SHOW_ERRORS: 01756 case SQLCOM_SHOW_BINLOGS: 01757 case SQLCOM_DROP_TABLE: 01758 case SQLCOM_RENAME_TABLE: 01759 case SQLCOM_ALTER_TABLE: 01760 case SQLCOM_COMMIT: 01761 case SQLCOM_CREATE_INDEX: 01762 case SQLCOM_DROP_INDEX: 01763 case SQLCOM_ROLLBACK: 01764 case SQLCOM_TRUNCATE: 01765 case SQLCOM_CALL: 01766 case SQLCOM_CREATE_VIEW: 01767 case SQLCOM_DROP_VIEW: 01768 case SQLCOM_REPAIR: 01769 case SQLCOM_ANALYZE: 01770 case SQLCOM_OPTIMIZE: 01771 case SQLCOM_CHANGE_MASTER: 01772 case SQLCOM_RESET: 01773 case SQLCOM_FLUSH: 01774 case SQLCOM_SLAVE_START: 01775 case SQLCOM_SLAVE_STOP: 01776 case SQLCOM_INSTALL_PLUGIN: 01777 case SQLCOM_UNINSTALL_PLUGIN: 01778 case SQLCOM_CREATE_DB: 01779 case SQLCOM_DROP_DB: 01780 case SQLCOM_RENAME_DB: 01781 case SQLCOM_CHECKSUM: 01782 case SQLCOM_CREATE_USER: 01783 case SQLCOM_RENAME_USER: 01784 case SQLCOM_DROP_USER: 01785 case SQLCOM_ASSIGN_TO_KEYCACHE: 01786 case SQLCOM_PRELOAD_KEYS: 01787 case SQLCOM_GRANT: 01788 case SQLCOM_REVOKE: 01789 case SQLCOM_KILL: 01790 break; 01791 01792 default: 01793 /* 01794 Trivial check of all status commands. This is easier than having 01795 things in the above case list, as it's less chance for mistakes. 01796 */ 01797 if (!(sql_command_flags[sql_command] & CF_STATUS_COMMAND)) 01798 { 01799 /* All other statements are not supported yet. */ 01800 my_message(ER_UNSUPPORTED_PS, ER(ER_UNSUPPORTED_PS), MYF(0)); 01801 goto error; 01802 } 01803 break; 01804 } 01805 if (res == 0) 01806 DBUG_RETURN(text_protocol? FALSE : (send_prep_stmt(stmt, 0) || 01807 thd->protocol->flush())); 01808 error: 01809 DBUG_RETURN(TRUE); 01810 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static Prepared_statement* find_prepared_statement | ( | THD * | thd, | |
| ulong | id, | |||
| const char * | where | |||
| ) | [static] |
Definition at line 176 of file sql_prepare.cc.
References ER_UNKNOWN_STMT_HANDLER, llstr(), my_error(), and MYF.
Referenced by mysql_stmt_close(), mysql_stmt_execute(), mysql_stmt_fetch(), mysql_stmt_get_longdata(), and mysql_stmt_reset().
00177 { 00178 /* 00179 To strictly separate namespaces of SQL prepared statements and C API 00180 prepared statements find() will return 0 if there is a named prepared 00181 statement with such id. 00182 */ 00183 Statement *stmt= thd->stmt_map.find(id); 00184 00185 if (stmt == 0 || stmt->type() != Query_arena::PREPARED_STATEMENT) 00186 { 00187 char llbuf[22]; 00188 my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), sizeof(llbuf), llstr(id, llbuf), 00189 where); 00190 return 0; 00191 } 00192 return (Prepared_statement *) stmt; 00193 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static const char* get_dynamic_sql_string | ( | LEX * | lex, | |
| uint * | query_len | |||
| ) | [static] |
Definition at line 1943 of file sql_prepare.cc.
References alloc_root(), String::charset(), copy_and_convert(), DBUG_ASSERT, hash_search(), String::length(), charset_info_st::mbmaxlen, memcpy, my_charset_latin1, String::needs_conversion(), NOT_FIXED_DEC, String::ptr(), String::set(), and STRING_WITH_LEN.
Referenced by mysql_sql_stmt_prepare().
01944 { 01945 THD *thd= lex->thd; 01946 char *query_str= 0; 01947 01948 if (lex->prepared_stmt_code_is_varref) 01949 { 01950 /* This is PREPARE stmt FROM or EXECUTE IMMEDIATE @var. */ 01951 String str; 01952 CHARSET_INFO *to_cs= thd->variables.collation_connection; 01953 bool needs_conversion; 01954 user_var_entry *entry; 01955 String *var_value= &str; 01956 uint32 unused, len; 01957 /* 01958 Convert @var contents to string in connection character set. Although 01959 it is known that int/real/NULL value cannot be a valid query we still 01960 convert it for error messages to be uniform. 01961 */ 01962 if ((entry= 01963 (user_var_entry*)hash_search(&thd->user_vars, 01964 (byte*)lex->prepared_stmt_code.str, 01965 lex->prepared_stmt_code.length)) 01966 && entry->value) 01967 { 01968 my_bool is_var_null; 01969 var_value= entry->val_str(&is_var_null, &str, NOT_FIXED_DEC); 01970 /* 01971 NULL value of variable checked early as entry->value so here 01972 we can't get NULL in normal conditions 01973 */ 01974 DBUG_ASSERT(!is_var_null); 01975 if (!var_value) 01976 goto end; 01977 } 01978 else 01979 { 01980 /* 01981 variable absent or equal to NULL, so we need to set variable to 01982 something reasonable to get a readable error message during parsing 01983 */ 01984 str.set(STRING_WITH_LEN("NULL"), &my_charset_latin1); 01985 } 01986 01987 needs_conversion= String::needs_conversion(var_value->length(), 01988 var_value->charset(), to_cs, 01989 &unused); 01990 01991 len= (needs_conversion ? var_value->length() * to_cs->mbmaxlen : 01992 var_value->length()); 01993 if (!(query_str= alloc_root(thd->mem_root, len+1))) 01994 goto end; 01995 01996 if (needs_conversion) 01997 { 01998 uint dummy_errors; 01999 len= copy_and_convert(query_str, len, to_cs, var_value->ptr(), 02000 var_value->length(), var_value->charset(), 02001 &dummy_errors); 02002 } 02003 else 02004 memcpy(query_str, var_value->ptr(), var_value->length()); 02005 query_str[len]= '\0'; // Safety (mostly for debug) 02006 *query_len= len; 02007 } 02008 else 02009 { 02010 query_str= lex->prepared_stmt_code.str; 02011 *query_len= lex->prepared_stmt_code.length; 02012 } 02013 end: 02014 return query_str; 02015 }
Here is the call graph for this function:

Here is the caller graph for this function:

EMBEDDED_LIBRARY
Definition at line 265 of file sql_prepare.cc.
References pos(), reg1, uint2korr, uint3korr, and uint4korr.
Referenced by set_param_date(), set_param_datetime(), set_param_decimal(), set_param_str(), and set_param_time().
00266 { 00267 reg1 uchar *pos= *packet; 00268 if (len < 1) 00269 return 0; 00270 if (*pos < 251) 00271 { 00272 (*packet)++; 00273 return (ulong) *pos; 00274 } 00275 if (len < 3) 00276 return 0; 00277 if (*pos == 252) 00278 { 00279 (*packet)+=3; 00280 return (ulong) uint2korr(pos+1); 00281 } 00282 if (len < 4) 00283 return 0; 00284 if (*pos == 253) 00285 { 00286 (*packet)+=4; 00287 return (ulong) uint3korr(pos+1); 00288 } 00289 if (len < 5) 00290 return 0; 00291 (*packet)+=9; // Must be 254 when here 00292 /* 00293 In our client-server protocol all numbers bigger than 2^24 00294 stored as 8 bytes with uint8korr. Here we always know that 00295 parameter length is less than 2^4 so don't look at the second 00296 4 bytes. But still we need to obey the protocol hence 9 in the 00297 assignment above. 00298 */ 00299 return (ulong) uint4korr(pos+1); 00300 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static bool init_param_array | ( | Prepared_statement * | stmt | ) | [static] |
Definition at line 1818 of file sql_prepare.cc.
References alloc_root(), ER, ER_PS_MANY_PARAM, FALSE, my_message(), MYF, Prepared_statement::param_array, Prepared_statement::param_count, Prepared_statement::thd, to, TRUE, and UINT_MAX16.
Referenced by Prepared_statement::prepare().
01819 { 01820 LEX *lex= stmt->lex; 01821 if ((stmt->param_count= lex->param_list.elements)) 01822 { 01823 if (stmt->param_count > (uint) UINT_MAX16) 01824 { 01825 /* Error code to be defined in 5.0 */ 01826 my_message(ER_PS_MANY_PARAM, ER(ER_PS_MANY_PARAM), MYF(0)); 01827 return TRUE; 01828 } 01829 Item_param **to; 01830 List_iterator<Item_param> param_iterator(lex->param_list); 01831 /* Use thd->mem_root as it points at statement mem_root */ 01832 stmt->param_array= (Item_param **) 01833 alloc_root(stmt->thd->mem_root, 01834 sizeof(Item_param*) * stmt->param_count); 01835 if (!stmt->param_array) 01836 return TRUE; 01837 for (to= stmt->param_array; 01838 to < stmt->param_array + stmt->param_count; 01839 ++to) 01840 { 01841 *to= param_iterator++; 01842 } 01843 } 01844 return FALSE; 01845 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void init_stmt_after_parse | ( | LEX * | lex | ) | [static] |
Definition at line 2020 of file sql_prepare.cc.
References UNCACHEABLE_PREPARE.
Referenced by Prepared_statement::prepare().
02021 { 02022 SELECT_LEX *sl= lex->all_selects_list; 02023 /* 02024 Switch off a temporary flag that prevents evaluation of 02025 subqueries in statement prepare. 02026 */ 02027 for (; sl; sl= sl->next_select_in_list()) 02028 sl->uncacheable&= ~UNCACHEABLE_PREPARE; 02029 }
Here is the caller graph for this function:

| static bool insert_params | ( | Prepared_statement * | stmt, | |
| uchar * | null_array, | |||
| uchar * | read_pos, | |||
| uchar * | data_end, | |||
| String * | expanded_query | |||
| ) | [static] |
Definition at line 738 of file sql_prepare.cc.
References Item_param::convert_str_value(), DBUG_ENTER, DBUG_RETURN, is_param_null(), Item_param::LONG_DATA_VALUE, Prepared_statement::param_array, Prepared_statement::param_count, Item_param::set_null(), Item_param::set_param_func, Item_param::state, and Prepared_statement::thd.
Referenced by Prepared_statement::setup_set_params().
00741 { 00742 Item_param **begin= stmt->param_array; 00743 Item_param **end= begin + stmt->param_count; 00744 00745 DBUG_ENTER("insert_params"); 00746 00747 for (Item_param **it= begin; it < end; ++it) 00748 { 00749 Item_param *param= *it; 00750 if (param->state != Item_param::LONG_DATA_VALUE) 00751 { 00752 if (is_param_null(null_array, it - begin)) 00753 param->set_null(); 00754 else 00755 { 00756 if (read_pos >= data_end) 00757 DBUG_RETURN(1); 00758 param->set_param_func(param, &read_pos, data_end - read_pos); 00759 } 00760 } 00761 if (param->convert_str_value(stmt->thd)) 00762 DBUG_RETURN(1); /* out of memory */ 00763 } 00764 DBUG_RETURN(0); 00765 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static bool insert_params_from_vars | ( | Prepared_statement * | stmt, | |
| List< LEX_STRING > & | varnames, | |||
| String *query | __attribute__((unused)) | |||
| ) | [static] |
EMBEDDED_LIBRARY
Definition at line 910 of file sql_prepare.cc.
References DBUG_ENTER, DBUG_RETURN, hash_search(), LEX_STRING::length, Prepared_statement::param_array, Prepared_statement::param_count, LEX_STRING::str, and Prepared_statement::thd.
Referenced by Prepared_statement::setup_set_params().
00913 { 00914 Item_param **begin= stmt->param_array; 00915 Item_param **end= begin + stmt->param_count; 00916 user_var_entry *entry; 00917 LEX_STRING *varname; 00918 List_iterator<LEX_STRING> var_it(varnames); 00919 DBUG_ENTER("insert_params_from_vars"); 00920 00921 for (Item_param **it= begin; it < end; ++it) 00922 { 00923 Item_param *param= *it; 00924 varname= var_it++; 00925 entry= (user_var_entry*)hash_search(&stmt->thd->user_vars, 00926 (byte*) varname->str, 00927 varname->length); 00928 if (param->set_from_user_var(stmt->thd, entry) || 00929 param->convert_str_value(stmt->thd)) 00930 DBUG_RETURN(1); 00931 } 00932 DBUG_RETURN(0); 00933 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static bool insert_params_from_vars_with_log | ( | Prepared_statement * | stmt, | |
| List< LEX_STRING > & | varnames, | |||
| String * | query | |||
| ) | [static] |
Definition at line 949 of file sql_prepare.cc.
References buf, DBUG_ENTER, DBUG_RETURN, default_charset_info, escape_string_for_mysql(), get_var_with_binlog(), String::length(), my_charset_utf8_general_ci, my_null_string, charset_info_st::name, Prepared_statement::param_array, Prepared_statement::param_count, query, and Prepared_statement::thd.
Referenced by Prepared_statement::setup_set_params().
00952 { 00953 Item_param **begin= stmt->param_array; 00954 Item_param **end= begin + stmt->param_count; 00955 user_var_entry *entry; 00956 LEX_STRING *varname; 00957 List_iterator<LEX_STRING> var_it(varnames); 00958 String buf; 00959 const String *val; 00960 uint32 length= 0; 00961 00962 DBUG_ENTER("insert_params_from_vars"); 00963 00964 if (query->copy(stmt->query, stmt->query_length, default_charset_info)) 00965 DBUG_RETURN(1); 00966 00967 for (Item_param **it= begin; it < end; ++it) 00968 { 00969 Item_param *param= *it; 00970 varname= var_it++; 00971 if (get_var_with_binlog(stmt->thd, stmt->lex->sql_command, 00972 *varname, &entry)) 00973 DBUG_RETURN(1); 00974 00975 if (param->set_from_user_var(stmt->thd, entry)) 00976 DBUG_RETURN(1); 00977 /* Insert @'escaped-varname' instead of parameter in the query */ 00978 if (entry) 00979 { 00980 char *begin, *ptr; 00981 buf.length(0); 00982 if (buf.reserve(entry->name.length*2+3)) 00983 DBUG_RETURN(1); 00984 00985 begin= ptr= buf.c_ptr_quick(); 00986 *ptr++= '@'; 00987 *ptr++= '\''; 00988 ptr+= escape_string_for_mysql(&my_charset_utf8_general_ci, 00989 ptr, 0, entry->name.str, 00990 entry->name.length); 00991 *ptr++= '\''; 00992 buf.length(ptr - begin); 00993 val= &buf; 00994 } 00995 else 00996 val= &my_null_string; 00997 00998 if (param->convert_str_value(stmt->thd)) 00999 DBUG_RETURN(1); /* out of memory */ 01000 01001 if (query->replace(param->pos_in_query+length, 1, *val)) 01002 DBUG_RETURN(1); 01003 length+= val->length()-1; 01004 } 01005 DBUG_RETURN(0); 01006 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static bool insert_params_withlog | ( | Prepared_statement * | stmt, | |
| uchar * | null_array, | |||
| uchar * | read_pos, | |||
| uchar * | data_end, | |||
| String * | query | |||
| ) | [static] |
Definition at line 696 of file sql_prepare.cc.
References Item_param::convert_str_value(), DBUG_ENTER, DBUG_RETURN, default_charset_info, is_param_null(), String::length(), Item_param::LONG_DATA_VALUE, Prepared_statement::param_array, Prepared_statement::param_count, Item_param::pos_in_query, query, Item_param::query_val_str(), Item_param::set_null(), Item_param::set_param_func, Item_param::state, and Prepared_statement::thd.
Referenced by Prepared_statement::setup_set_params().
00699 { 00700 THD *thd= stmt->thd; 00701 Item_param **begin= stmt->param_array; 00702 Item_param **end= begin + stmt->param_count; 00703 uint32 length= 0; 00704 String str; 00705 const String *res; 00706 DBUG_ENTER("insert_params_withlog"); 00707 00708 if (query->copy(stmt->query, stmt->query_length, default_charset_info)) 00709 DBUG_RETURN(1); 00710 00711 for (Item_param **it= begin; it < end; ++it) 00712 { 00713 Item_param *param= *it; 00714 if (param->state != Item_param::LONG_DATA_VALUE) 00715 { 00716 if (is_param_null(null_array, it - begin)) 00717 param->set_null(); 00718 else 00719 { 00720 if (read_pos >= data_end) 00721 DBUG_RETURN(1); 00722 param->set_param_func(param, &read_pos, data_end - read_pos); 00723 } 00724 } 00725 res= param->query_val_str(&str); 00726 if (param->convert_str_value(thd)) 00727 DBUG_RETURN(1); /* out of memory */ 00728 00729 if (query->replace(param->pos_in_query+length, 1, *res)) 00730 DBUG_RETURN(1); 00731 00732 length+= res->length()-1; 00733 } 00734 DBUG_RETURN(0); 00735 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 153 of file sql_prepare.cc.
Referenced by insert_params(), and insert_params_withlog().
00154 { 00155 return pos[param_no/8] & (1 << (param_no & 7)); 00156 }
Here is the caller graph for this function:

| static bool mysql_insert_select_prepare_tester | ( | THD * | thd | ) | [static] |
Definition at line 1576 of file sql_prepare.cc.
References mysql_insert_select_prepare(), st_table_list::next_local, and TRUE.
Referenced by mysql_test_insert_select().
01577 { 01578 TABLE_LIST *first; 01579 bool res; 01580 SELECT_LEX *first_select= &thd->lex->select_lex; 01581 /* Skip first table, which is the table we are inserting in */ 01582 first_select->table_list.first= (byte*)(first= 01583 ((TABLE_LIST*)first_select-> 01584 table_list.first)->next_local); 01585 res= mysql_insert_select_prepare(thd); 01586 /* 01587 insert/replace from SELECT give its SELECT_LEX for SELECT, 01588 and item_list belong to SELECT 01589 */ 01590 thd->lex->select_lex.context.resolve_in_select_list= TRUE; 01591 thd->lex->select_lex.context.table_list= first; 01592 return res; 01593 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void mysql_sql_stmt_close | ( | THD * | thd | ) |
Definition at line 2510 of file sql_prepare.cc.
References DBUG_PRINT, Prepared_statement::deallocate(), ER_UNKNOWN_STMT_HANDLER, my_error(), MYF, name, and send_ok().
Referenced by mysql_execute_command().
02511 { 02512 Prepared_statement* stmt; 02513 LEX_STRING *name= &thd->lex->prepared_stmt_name; 02514 DBUG_PRINT("info", ("DEALLOCATE PREPARE: %.*s\n", name->length, name->str)); 02515 02516 if (! (stmt= (Prepared_statement*) thd->stmt_map.find_by_name(name))) 02517 { 02518 my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), 02519 name->length, name->str, "DEALLOCATE PREPARE"); 02520 return; 02521 } 02522 02523 if (stmt->deallocate() == 0) 02524 send_ok(thd); 02525 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void mysql_sql_stmt_execute | ( | THD * | thd | ) |
Definition at line 2325 of file sql_prepare.cc.
References DBUG_ENTER, DBUG_PRINT, DBUG_VOID_RETURN, ER_UNKNOWN_STMT_HANDLER, ER_WRONG_ARGUMENTS, Prepared_statement::execute(), FALSE, my_error(), MYF, name, Prepared_statement::param_count, reset_stmt_params(), and Prepared_statement::set_params_from_vars.
Referenced by mysql_execute_command().
02326 { 02327 LEX *lex= thd->lex; 02328 Prepared_statement *stmt; 02329 LEX_STRING *name= &lex->prepared_stmt_name; 02330 /* Query text for binary, general or slow log, if any of them is open */ 02331 String expanded_query; 02332 DBUG_ENTER("mysql_sql_stmt_execute"); 02333 DBUG_PRINT("info", ("EXECUTE: %.*s\n", name->length, name->str)); 02334 02335 if (!(stmt= (Prepared_statement*) thd->stmt_map.find_by_name(name))) 02336 { 02337 my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), 02338 name->length, name->str, "EXECUTE"); 02339 DBUG_VOID_RETURN; 02340 } 02341 02342 if (stmt->param_count != lex->prepared_stmt_params.elements) 02343 { 02344 my_error(ER_WRONG_ARGUMENTS, MYF(0), "EXECUTE"); 02345 DBUG_VOID_RETURN; 02346 } 02347 02348 DBUG_PRINT("info",("stmt: %p", stmt)); 02349 02350 if (stmt->set_params_from_vars(stmt, lex->prepared_stmt_params, 02351 &expanded_query)) 02352 goto set_params_data_err; 02353 02354 (void) stmt->execute(&expanded_query, FALSE); 02355 02356 DBUG_VOID_RETURN; 02357 02358 set_params_data_err: 02359 my_error(ER_WRONG_ARGUMENTS, MYF(0), "EXECUTE"); 02360 reset_stmt_params(stmt); 02361 DBUG_VOID_RETURN; 02362 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void mysql_sql_stmt_prepare | ( | THD * | thd | ) |
Definition at line 2048 of file sql_prepare.cc.
References DBUG_ASSERT, DBUG_ENTER, DBUG_VOID_RETURN, Prepared_statement::deallocate(), get_dynamic_sql_string(), name, Prepared_statement::prepare(), query, send_ok(), and Prepared_statement::set_name().
Referenced by mysql_execute_command().
02049 { 02050 LEX *lex= thd->lex; 02051 LEX_STRING *name= &lex->prepared_stmt_name; 02052 Prepared_statement *stmt; 02053 const char *query; 02054 uint query_len; 02055 DBUG_ENTER("mysql_sql_stmt_prepare"); 02056 DBUG_ASSERT(thd->protocol == &thd->protocol_simple); 02057 02058 if ((stmt= (Prepared_statement*) thd->stmt_map.find_by_name(name))) 02059 { 02060 /* 02061 If there is a statement with the same name, remove it. It is ok to 02062 remove old and fail to insert a new one at the same time. 02063 */ 02064 if (stmt->deallocate()) 02065 DBUG_VOID_RETURN; 02066 } 02067 02068 if (! (query= get_dynamic_sql_string(lex, &query_len)) || 02069 ! (stmt= new Prepared_statement(thd, &thd->protocol_simple))) 02070 { 02071 DBUG_VOID_RETURN; /* out of memory */ 02072 } 02073 02074 /* Set the name first, insert should know that this statement has a name */ 02075 if (stmt->set_name(name)) 02076 { 02077 delete stmt; 02078 DBUG_VOID_RETURN; 02079 } 02080 if (thd->stmt_map.insert(thd, stmt)) 02081 { 02082 /* The statement is deleted and an error is set if insert fails */ 02083 DBUG_VOID_RETURN; 02084 } 02085 02086 if (stmt->prepare(query, query_len+1)) 02087 { 02088 /* Statement map deletes the statement on erase */ 02089 thd->stmt_map.erase(stmt); 02090 } 02091 else 02092 send_ok(thd, 0L, 0L, "Statement prepared"); 02093 02094 DBUG_VOID_RETURN; 02095 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void mysql_stmt_close | ( | THD * | thd, | |
| char * | packet | |||
| ) |
Definition at line 2476 of file sql_prepare.cc.
References DBUG_ASSERT, DBUG_ENTER, DBUG_VOID_RETURN, Prepared_statement::deallocate(), find_prepared_statement(), Prepared_statement::flags, Prepared_statement::IS_IN_USE, and uint4korr.
02477 { 02478 /* There is always space for 4 bytes in packet buffer */ 02479 ulong stmt_id= uint4korr(packet); 02480 Prepared_statement *stmt; 02481 DBUG_ENTER("mysql_stmt_close"); 02482 02483 if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_close"))) 02484 DBUG_VOID_RETURN; 02485 02486 /* 02487 The only way currently a statement can be deallocated when it's 02488 in use is from within Dynamic SQL. 02489 */ 02490 DBUG_ASSERT(! (stmt->flags & (uint) Prepared_statement::IS_IN_USE)); 02491 (void) stmt->deallocate(); 02492 02493 DBUG_VOID_RETURN; 02494 }
Here is the call graph for this function:

| void mysql_stmt_execute | ( | THD * | thd, | |
| char * | packet_arg, | |||
| uint | packet_length | |||
| ) |
Definition at line 2241 of file sql_prepare.cc.
References COM_STMT_EXECUTE, CURSOR_TYPE_READ_ONLY, DBUG_ENTER, DBUG_PRINT, DBUG_VOID_RETURN, ER_WRONG_ARGUMENTS, error, Prepared_statement::execute(), find_prepared_statement(), flags, general_log_print(), my_error(), my_pthread_setprio(), MYF, mysql_reset_thd_for_next_command(), Prepared_statement::param_count, QUERY_PRIOR, reset_stmt_params(), setup_conversion_functions(), sp_cache_flush_obsolete(), SPECIAL_NO_PRIOR, specialflag, test, uint4korr, and WAIT_PRIOR.
02242 { 02243 uchar *packet= (uchar*)packet_arg; // GCC 4.0.1 workaround 02244 ulong stmt_id= uint4korr(packet); 02245 ulong flags= (ulong) ((uchar) packet[4]); 02246 /* Query text for binary, general or slow log, if any of them is open */ 02247 String expanded_query; 02248 #ifndef EMBEDDED_LIBRARY 02249 uchar *packet_end= (uchar *) packet + packet_length - 1; 02250 #endif 02251 Prepared_statement *stmt; 02252 bool error; 02253 DBUG_ENTER("mysql_stmt_execute"); 02254 02255 packet+= 9; /* stmt_id + 5 bytes of flags */ 02256 02257 /* First of all clear possible warnings from the previous command */ 02258 mysql_reset_thd_for_next_command(thd); 02259 02260 if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_execute"))) 02261 DBUG_VOID_RETURN; 02262 02263 DBUG_PRINT("exec_query", ("%s", stmt->query)); 02264 DBUG_PRINT("info",("stmt: %p", stmt)); 02265 02266 sp_cache_flush_obsolete(&thd->sp_proc_cache); 02267 sp_cache_flush_obsolete(&thd->sp_func_cache); 02268 02269 #ifndef EMBEDDED_LIBRARY 02270 if (stmt->param_count) 02271 { 02272 uchar *null_array= (uchar *) packet; 02273 if (setup_conversion_functions(stmt, (uchar **) &packet, packet_end) || 02274 stmt->set_params(stmt, null_array, (uchar *) packet, packet_end, 02275 &expanded_query)) 02276 goto set_params_data_err; 02277 } 02278 #else 02279 /* 02280 In embedded library we re-install conversion routines each time 02281 we set params, and also we don't need to parse packet. 02282 So we do it in one function. 02283 */ 02284 if (stmt->param_count && stmt->set_params_data(stmt, &expanded_query)) 02285 goto set_params_data_err; 02286 #endif 02287 if (!(specialflag & SPECIAL_NO_PRIOR)) 02288 my_pthread_setprio(pthread_self(),QUERY_PRIOR); 02289 error= stmt->execute(&expanded_query, 02290 test(flags & (ulong) CURSOR_TYPE_READ_ONLY)); 02291 if (!(specialflag & SPECIAL_NO_PRIOR)) 02292 my_pthread_setprio(pthread_self(), WAIT_PRIOR); 02293 if (error == 0) 02294 general_log_print(thd, COM_STMT_EXECUTE, "[%lu] %s", stmt->id, thd->query); 02295 02296 DBUG_VOID_RETURN; 02297 02298 set_params_data_err: 02299 my_error(ER_WRONG_ARGUMENTS, MYF(0), "mysql_stmt_execute"); 02300 reset_stmt_params(stmt); 02301 DBUG_VOID_RETURN; 02302 }
Here is the call graph for this function:

| void mysql_stmt_fetch | ( | THD * | thd, | |
| char * | packet, | |||
| uint | packet_length | |||
| ) |
Definition at line 2375 of file sql_prepare.cc.
References Prepared_statement::close_cursor(), DBUG_ENTER, DBUG_VOID_RETURN, ER_STMT_HAS_NO_OPEN_CURSOR, Server_side_cursor::fetch(), find_prepared_statement(), Server_side_cursor::is_open(), LOCK_status, my_error(), my_pthread_setprio(), MYF, mysql_reset_thd_for_next_command(), QUERY_PRIOR, reset_stmt_params(), SPECIAL_NO_PRIOR, specialflag, statistic_increment, uint4korr, and WAIT_PRIOR.
02376 { 02377 /* assume there is always place for 8-16 bytes */ 02378 ulong stmt_id= uint4korr(packet); 02379 ulong num_rows= uint4korr(packet+4); 02380 Prepared_statement *stmt; 02381 Statement stmt_backup; 02382 Server_side_cursor *cursor; 02383 DBUG_ENTER("mysql_stmt_fetch"); 02384 02385 /* First of all clear possible warnings from the previous command */ 02386 mysql_reset_thd_for_next_command(thd); 02387 statistic_increment(thd->status_var.com_stmt_fetch, &LOCK_status); 02388 if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_fetch"))) 02389 DBUG_VOID_RETURN; 02390 02391 cursor= stmt->cursor; 02392 if (!cursor) 02393 { 02394 my_error(ER_STMT_HAS_NO_OPEN_CURSOR, MYF(0), stmt_id); 02395 DBUG_VOID_RETURN; 02396 } 02397 02398 thd->stmt_arena= stmt; 02399 thd->set_n_backup_statement(stmt, &stmt_backup); 02400 02401 if (!(specialflag & SPECIAL_NO_PRIOR)) 02402 my_pthread_setprio(pthread_self(), QUERY_PRIOR); 02403 02404 cursor->fetch(num_rows); 02405 02406 if (!(specialflag & SPECIAL_NO_PRIOR)) 02407 my_pthread_setprio(pthread_self(), WAIT_PRIOR); 02408 02409 if (!cursor->is_open()) 02410 { 02411 stmt->close_cursor(); 02412 thd->cursor= 0; 02413 reset_stmt_params(stmt); 02414 } 02415 02416 thd->restore_backup_statement(stmt, &stmt_backup); 02417 thd->stmt_arena= thd; 02418 02419 DBUG_VOID_RETURN; 02420 }
Here is the call graph for this function:

| void mysql_stmt_get_longdata | ( | THD * | thd, | |
| char * | packet, | |||
| ulong | packet_length | |||
| ) |
Definition at line 2544 of file sql_prepare.cc.
References DBUG_ENTER, DBUG_VOID_RETURN, ER, ER_OUTOFMEMORY, ER_WRONG_ARGUMENTS, find_prepared_statement(), Prepared_statement::last_errno, Prepared_statement::last_error, LOCK_status, my_error(), MYF, MYSQL_LONG_DATA_HEADER, Prepared_statement::param_array, Prepared_statement::param_count, Item_param::set_longdata(), statistic_increment, uint2korr, and uint4korr.
Referenced by dispatch_command().
02545 { 02546 ulong stmt_id; 02547 uint param_number; 02548 Prepared_statement *stmt; 02549 Item_param *param; 02550 char *packet_end= packet + packet_length - 1; 02551 DBUG_ENTER("mysql_stmt_get_longdata"); 02552 02553 statistic_increment(thd->status_var.com_stmt_send_long_data, &LOCK_status); 02554 #ifndef EMBEDDED_LIBRARY 02555 /* Minimal size of long data packet is 6 bytes */ 02556 if (packet_length <= MYSQL_LONG_DATA_HEADER) 02557 { 02558 my_error(ER_WRONG_ARGUMENTS, MYF(0), "mysql_stmt_send_long_data"); 02559 DBUG_VOID_RETURN; 02560 } 02561 #endif 02562 02563 stmt_id= uint4korr(packet); 02564 packet+= 4; 02565 02566 if (!(stmt=find_prepared_statement(thd, stmt_id, 02567 "mysql_stmt_send_long_data"))) 02568 DBUG_VOID_RETURN; 02569 02570 param_number= uint2korr(packet); 02571 packet+= 2; 02572 #ifndef EMBEDDED_LIBRARY 02573 if (param_number >= stmt->param_count) 02574 { 02575 /* Error will be sent in execute call */ 02576 stmt->state= Query_arena::ERROR; 02577 stmt->last_errno= ER_WRONG_ARGUMENTS; 02578 sprintf(stmt->last_error, ER(ER_WRONG_ARGUMENTS), 02579 "mysql_stmt_send_long_data"); 02580 DBUG_VOID_RETURN; 02581 } 02582 #endif 02583 02584 param= stmt->param_array[param_number]; 02585 02586 #ifndef EMBEDDED_LIBRARY 02587 if (param->set_longdata(packet, (ulong) (packet_end - packet))) 02588 #else 02589 if (param->set_longdata(thd->extra_data, thd->extra_length)) 02590 #endif 02591 { 02592 stmt->state= Query_arena::ERROR; 02593 stmt->last_errno= ER_OUTOFMEMORY; 02594 sprintf(stmt->last_error, ER(ER_OUTOFMEMORY), 0); 02595 } 02596 DBUG_VOID_RETURN; 02597 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void mysql_stmt_prepare | ( | THD * | thd, | |
| const char * | packet, | |||
| uint | packet_length | |||
| ) |
Definition at line 1877 of file sql_prepare.cc.
References COM_STMT_PREPARE, DBUG_ENTER, DBUG_PRINT, DBUG_VOID_RETURN, error, general_log_print(), my_pthread_setprio(), mysql_reset_errors(), mysql_reset_thd_for_next_command(), Prepared_statement::prepare(), QUERY_PRIOR, sp_cache_flush_obsolete(), SPECIAL_NO_PRIOR, specialflag, and WAIT_PRIOR.
01878 { 01879 Prepared_statement *stmt; 01880 bool error; 01881 DBUG_ENTER("mysql_stmt_prepare"); 01882 01883 DBUG_PRINT("prep_query", ("%s", packet)); 01884 01885 /* First of all clear possible warnings from the previous command */ 01886 mysql_reset_thd_for_next_command(thd); 01887 01888 if (! (stmt= new Prepared_statement(thd, &thd->protocol_prep))) 01889 DBUG_VOID_RETURN; /* out of memory: error is set in Sql_alloc */ 01890 01891 if (thd->stmt_map.insert(thd, stmt)) 01892 { 01893 /* 01894 The error is set in the insert. The statement itself 01895 will be also deleted there (this is how the hash works). 01896 */ 01897 DBUG_VOID_RETURN; 01898 } 01899 01900 /* Reset warnings from previous command */ 01901 mysql_reset_errors(thd, 0); 01902 sp_cache_flush_obsolete(&thd->sp_proc_cache); 01903 sp_cache_flush_obsolete(&thd->sp_func_cache); 01904 01905 if (!(specialflag & SPECIAL_NO_PRIOR)) 01906 my_pthread_setprio(pthread_self(),QUERY_PRIOR); 01907 01908 error= stmt->prepare(packet, packet_length); 01909 01910 if (!(specialflag & SPECIAL_NO_PRIOR)) 01911 my_pthread_setprio(pthread_self(),WAIT_PRIOR); 01912 01913 if (error) 01914 { 01915 /* Statement map deletes statement on erase */ 01916 thd->stmt_map.erase(stmt); 01917 } 01918 else 01919 general_log_print(thd, COM_STMT_PREPARE, "[%lu] %s", stmt->id, packet); 01920 01921 /* check_prepared_statemnt sends the metadata packet in case of success */ 01922 DBUG_VOID_RETURN; 01923 }
Here is the call graph for this function:

| void mysql_stmt_reset | ( | THD * | thd, | |
| char * | packet | |||
| ) |
Definition at line 2441 of file sql_prepare.cc.
References Prepared_statement::close_cursor(), DBUG_ENTER, DBUG_VOID_RETURN, find_prepared_statement(), LOCK_status, mysql_reset_thd_for_next_command(), reset_stmt_params(), send_ok(), statistic_increment, and uint4korr.
02442 { 02443 /* There is always space for 4 bytes in buffer */ 02444 ulong stmt_id= uint4korr(packet); 02445 Prepared_statement *stmt; 02446 DBUG_ENTER("mysql_stmt_reset"); 02447 02448 /* First of all clear possible warnings from the previous command */ 02449 mysql_reset_thd_for_next_command(thd); 02450 02451 statistic_increment(thd->status_var.com_stmt_reset, &LOCK_status); 02452 if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_reset"))) 02453 DBUG_VOID_RETURN; 02454 02455 stmt->close_cursor(); 02456 02457 /* 02458 Clear parameters from data which could be set by 02459 mysql_stmt_send_long_data() call. 02460 */ 02461 reset_stmt_params(stmt); 02462 02463 stmt->state= Query_arena::PREPARED; 02464 02465 send_ok(thd); 02466 02467 DBUG_VOID_RETURN; 02468 }
Here is the call graph for this function:

| static bool mysql_test_create_table | ( | Prepared_statement * | stmt | ) | [static] |
Definition at line 1469 of file sql_prepare.cc.
References create_table(), create_table_precheck(), DBUG_ENTER, DBUG_RETURN, FALSE, select_like_stmt_test_with_open_n_lock(), Prepared_statement::thd, and TRUE.
Referenced by check_prepared_statement().
01470 { 01471 DBUG_ENTER("mysql_test_create_table"); 01472 THD *thd= stmt->thd; 01473 LEX *lex= stmt->lex; 01474 SELECT_LEX *select_lex= &lex->select_lex; 01475 bool res= FALSE; 01476 /* Skip first table, which is the table we are creating */ 01477 bool link_to_local; 01478 TABLE_LIST *create_table= lex->unlink_first_table(&link_to_local); 01479 TABLE_LIST *tables= lex->query_tables; 01480 01481 if (create_table_precheck(thd, tables, create_table)) 01482 DBUG_RETURN(TRUE); 01483 01484 if (select_lex->item_list.elements) 01485 { 01486 select_lex->context.resolve_in_select_list= TRUE; 01487 res= select_like_stmt_test_with_open_n_lock(stmt, tables, 0, 0); 01488 } 01489 01490 /* put tables back for PS rexecuting */ 01491 lex->link_first_table_back(create_table, link_to_local); 01492 DBUG_RETURN(res); 01493 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static bool mysql_test_delete | ( | Prepared_statement * | stmt, | |
| TABLE_LIST * | table_list | |||
| ) | [static] |
Definition at line 1205 of file sql_prepare.cc.
References DBUG_ENTER, DBUG_RETURN, delete_precheck(), ER_VIEW_DELETE_MERGE_VIEW, error, my_error(), MYF, mysql_prepare_delete(), open_and_lock_tables(), st_table_list::select_lex, LEX_STRING::str, st_table_list::table, Prepared_statement::thd, TRUE, st_table_list::view_db, and st_table_list::view_name.
Referenced by check_prepared_statement().
01207 { 01208 THD *thd= stmt->thd; 01209 LEX *lex= stmt->lex; 01210 DBUG_ENTER("mysql_test_delete"); 01211 01212 if (delete_precheck(thd, table_list) || 01213 open_and_lock_tables(thd, table_list)) 01214 goto error; 01215 01216 if (!table_list->table) 01217 { 01218 my_error(ER_VIEW_DELETE_MERGE_VIEW, MYF(0), 01219 table_list->view_db.str, table_list->view_name.str); 01220 goto error; 01221 } 01222 01223 DBUG_RETURN(mysql_prepare_delete(thd, table_list, &lex->select_lex.where)); 01224 error: 01225 DBUG_RETURN(TRUE); 01226 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static bool mysql_test_do_fields | ( | Prepared_statement * | stmt, | |
| TABLE_LIST * | tables, | |||
| List< Item > * | values | |||
| ) | [static] |
Definition at line 1325 of file sql_prepare.cc.
References check_table_access(), DBUG_ENTER, DBUG_RETURN, MARK_COLUMNS_NONE, open_and_lock_tables(), SELECT_ACL, setup_fields(), Prepared_statement::thd, and TRUE.
Referenced by check_prepared_statement().
01328 { 01329 THD *thd= stmt->thd; 01330 01331 DBUG_ENTER("mysql_test_do_fields"); 01332 if (tables && check_table_access(thd, SELECT_ACL, tables, 0)) 01333 DBUG_RETURN(TRUE); 01334 01335 if (open_and_lock_tables(thd, tables)) 01336 DBUG_RETURN(TRUE); 01337 DBUG_RETURN(setup_fields(thd, 0, *values, MARK_COLUMNS_NONE, 0, 0)); 01338 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static bool mysql_test_insert | ( | Prepared_statement * | stmt, | |
| TABLE_LIST * | table_list, | |||
| List< Item > & | fields, | |||
| List< List_item > & | values_list, | |||
| List< Item > & | update_fields, | |||
| List< Item > & | update_values, | |||
| enum_duplicates | duplic | |||
| ) | [static] |
Definition at line 1021 of file sql_prepare.cc.
References counter, DBUG_ENTER, DBUG_RETURN, ER_ILLEGAL_HA, ER_WRONG_VALUE_COUNT_ON_ROW, error, FALSE, st_table::file, HA_CAN_INSERT_DELAYED, handler::ha_table_flags(), insert_precheck(), st_table::insert_values, st_table_list::lock_type, MARK_COLUMNS_NONE, my_error(), MYF, mysql_prepare_insert(), open_normal_and_derived_tables(), List_iterator_fast< T >::rewind(), setup_fields(), LEX_STRING::str, st_table_list::table, st_table_list::table_name, Prepared_statement::thd, TL_WRITE_DELAYED, TRUE, st_table_list::view, and st_table_list::view_name.
Referenced by check_prepared_statement().
01028 { 01029 THD *thd= stmt->thd; 01030 LEX *lex= stmt->lex; 01031 List_iterator_fast<List_item> its(values_list); 01032 List_item *values; 01033 DBUG_ENTER("mysql_test_insert"); 01034 01035 if (insert_precheck(thd, table_list)) 01036 goto error; 01037 01038 /* 01039 open temporary memory pool for temporary data allocated by derived 01040 tables & preparation procedure 01041 Note that this is done without locks (should not be needed as we will not 01042 access any data here) 01043 If we would use locks, then we have to ensure we are not using 01044 TL_WRITE_DELAYED as having two such locks can cause table corruption. 01045 */ 01046 if (open_normal_and_derived_tables(thd, table_list, 0)) 01047 goto error; 01048 01049 if ((values= its++)) 01050 { 01051 uint value_count; 01052 ulong counter= 0; 01053 Item *unused_conds= 0; 01054 01055 if (table_list->table) 01056 { 01057 // don't allocate insert_values 01058 table_list->table->insert_values=(byte *)1; 01059 } 01060 01061 if (mysql_prepare_insert(thd, table_list, table_list->table, 01062 fields, values, update_fields, update_values, 01063 duplic, &unused_conds, FALSE)) 01064 goto error; 01065 01066 value_count= values->elements; 01067 its.rewind(); 01068 01069 if (table_list->lock_type == TL_WRITE_DELAYED && 01070 !(table_list->table->file->ha_table_flags() & HA_CAN_INSERT_DELAYED)) 01071 { 01072 my_error(ER_ILLEGAL_HA, MYF(0), (table_list->view ? 01073 table_list->view_name.str : 01074 table_list->table_name)); 01075 goto error; 01076 } 01077 while ((values= its++)) 01078 { 01079 counter++; 01080 if (values->elements != value_count) 01081 { 01082 my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), counter); 01083 goto error; 01084 } 01085 if (setup_fields(thd, 0, *values, MARK_COLUMNS_NONE, 0, 0)) 01086 goto error; 01087 } 01088 } 01089 DBUG_RETURN(FALSE); 01090 01091 error: 01092 /* insert_values is cleared in open_table */ 01093 DBUG_RETURN(TRUE); 01094 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static bool mysql_test_insert_select | ( | Prepared_statement * | stmt, | |
| TABLE_LIST * | tables | |||
| ) | [static] |
Definition at line 1609 of file sql_prepare.cc.
References DBUG_ASSERT, insert_precheck(), st_table::insert_values, mysql_insert_select_prepare_tester(), OPTION_SETUP_TABLES_DONE, st_table_list::select_lex, select_like_stmt_test_with_open_n_lock(), st_table_list::table, and Prepared_statement::thd.
Referenced by check_prepared_statement().
01611 { 01612 int res; 01613 LEX *lex= stmt->lex; 01614 TABLE_LIST *first_local_table; 01615 01616 if (tables->table) 01617 { 01618 // don't allocate insert_values 01619 tables->table->insert_values=(byte *)1; 01620 } 01621 01622 if (insert_precheck(stmt->thd, tables)) 01623 return 1; 01624 01625 /* store it, because mysql_insert_select_prepare_tester change it */ 01626 first_local_table= (TABLE_LIST *)lex->select_lex.table_list.first; 01627 DBUG_ASSERT(first_local_table != 0); 01628 01629 res= 01630 select_like_stmt_test_with_open_n_lock(stmt, tables, 01631 &mysql_insert_select_prepare_tester, 01632 OPTION_SETUP_TABLES_DONE); 01633 /* revert changes made by mysql_insert_select_prepare_tester */ 01634 lex->select_lex.table_list.first= (byte*) first_local_table; 01635 return res; 01636 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static bool mysql_test_multidelete | ( | Prepared_statement * | stmt, | |
| TABLE_LIST * | tables | |||
| ) | [static] |
Definition at line 1536 of file sql_prepare.cc.
References ER_OUTOFMEMORY, ER_VIEW_DELETE_MERGE_VIEW, error, FALSE, multi_delete_precheck(), my_error(), MYF, mysql_multi_delete_prepare(), OPTION_SETUP_TABLES_DONE, select_like_stmt_test_with_open_n_lock(), LEX_STRING::str, st_table_list::table, Prepared_statement::thd, TRUE, st_table_list::view_db, and st_table_list::view_name.
Referenced by check_prepared_statement().
01538 { 01539 stmt->thd->lex->current_select= &stmt->thd->lex->select_lex; 01540 if (add_item_to_list(stmt->thd, new Item_null())) 01541 { 01542 my_error(ER_OUTOFMEMORY, MYF(0), 0); 01543 goto error; 01544 } 01545 01546 if (multi_delete_precheck(stmt->thd, tables) || 01547 select_like_stmt_test_with_open_n_lock(stmt, tables, 01548 &mysql_multi_delete_prepare, 01549 OPTION_SETUP_TABLES_DONE)) 01550 goto error; 01551 if (!tables->table) 01552 { 01553 my_error(ER_VIEW_DELETE_MERGE_VIEW, MYF(0), 01554 tables->view_db.str, tables->view_name.str); 01555 goto error; 01556 } 01557 return FALSE; 01558 error: 01559 return TRUE; 01560 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static bool mysql_test_multiupdate | ( | Prepared_statement * | stmt, | |
| TABLE_LIST * | tables, | |||
| bool | converted | |||
| ) | [static] |
Definition at line 1510 of file sql_prepare.cc.
References multi_update_precheck(), mysql_multi_update_prepare(), OPTION_SETUP_TABLES_DONE, select_like_stmt_test(), Prepared_statement::thd, and TRUE.
Referenced by check_prepared_statement().
01513 { 01514 /* if we switched from normal update, rights are checked */ 01515 if (!converted && multi_update_precheck(stmt->thd, tables)) 01516 return TRUE; 01517 01518 return select_like_stmt_test(stmt, &mysql_multi_update_prepare, 01519 OPTION_SETUP_TABLES_DONE); 01520 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static int mysql_test_select | ( | Prepared_statement * | stmt, | |
| TABLE_LIST * | tables, | |||
| bool | text_protocol | |||
| ) | [static] |
Definition at line 1247 of file sql_prepare.cc.
References any_db, check_access(), check_table_access(), DBUG_ENTER, DBUG_RETURN, ER_OUTOFMEMORY, error, FILE_ACL, my_error(), MYF, new(), open_and_lock_tables(), Prepared_statement::result, SELECT_ACL, Protocol::SEND_EOF, send_prep_stmt(), Prepared_statement::thd, and TRUE.
Referenced by check_prepared_statement().
01249 { 01250 THD *thd= stmt->thd; 01251 LEX *lex= stmt->lex; 01252 SELECT_LEX_UNIT *unit= &lex->unit; 01253 DBUG_ENTER("mysql_test_select"); 01254 01255 lex->select_lex.context.resolve_in_select_list= TRUE; 01256 01257 #ifndef NO_EMBEDDED_ACCESS_CHECKS 01258 ulong privilege= lex->exchange ? SELECT_ACL | FILE_ACL : SELECT_ACL; 01259 if (tables) 01260 { 01261 if (check_table_access(thd, privilege, tables,0)) 01262 goto error; 01263 } 01264 else if (check_access(thd, privilege, any_db,0,0,0,0)) 01265 goto error; 01266 #endif 01267 01268 if (!lex->result && !(lex->result= new (stmt->mem_root) select_send)) 01269 { 01270 my_error(ER_OUTOFMEMORY, MYF(0), sizeof(select_send)); 01271 goto error; 01272 } 01273 01274 if (open_and_lock_tables(thd, tables)) 01275 goto error; 01276 01277 thd->used_tables= 0; // Updated by setup_fields 01278 01279 /* 01280 JOIN::prepare calls 01281 It is not SELECT COMMAND for sure, so setup_tables will be called as 01282 usual, and we pass 0 as setup_tables_done_option 01283 */ 01284 if (unit->prepare(thd, 0, 0)) 01285 goto error; 01286 if (!lex->describe && !text_protocol) 01287 { 01288 /* Make copy of item list, as change_columns may change it */ 01289 List<Item> fields(lex->select_lex.item_list); 01290 01291 /* Change columns if a procedure like analyse() */ 01292 if (unit->last_procedure && unit->last_procedure->change_columns(fields)) 01293 goto error; 01294 01295 /* 01296 We can use lex->result as it should've been prepared in 01297 unit->prepare call above. 01298 */ 01299 if (send_prep_stmt(stmt, lex->result->field_count(fields)) || 01300 lex->result->send_fields(fields, Protocol::SEND_EOF) || 01301 thd->protocol->flush()) 01302 goto error; 01303 DBUG_RETURN(2); 01304 } 01305 DBUG_RETURN(0); 01306 error: 01307 DBUG_RETURN(1); 01308 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static bool mysql_test_set_fields | ( | Prepared_statement * | stmt, | |
| TABLE_LIST * | tables, | |||
| List< set_var_base > * | var_list | |||
| ) | [static] |
Definition at line 1355 of file sql_prepare.cc.
References check_table_access(), DBUG_ENTER, DBUG_RETURN, error, FALSE, set_var_base::light_check(), open_and_lock_tables(), SELECT_ACL, Prepared_statement::thd, and TRUE.
Referenced by check_prepared_statement().
01358 { 01359 DBUG_ENTER("mysql_test_set_fields"); 01360 List_iterator_fast<set_var_base> it(*var_list); 01361 THD *thd= stmt->thd; 01362 set_var_base *var; 01363 01364 if (tables && check_table_access(thd, SELECT_ACL, tables, 0) || 01365 open_and_lock_tables(thd, tables)) 01366 goto error; 01367 01368 while ((var= it++)) 01369 { 01370 if (var->light_check(thd)) 01371 goto error; 01372 } 01373 DBUG_RETURN(FALSE); 01374 error: 01375 DBUG_RETURN(TRUE); 01376 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static int mysql_test_update | ( | Prepared_statement * | stmt, | |
| TABLE_LIST * | table_list | |||
| ) | [static] |
Definition at line 1111 of file sql_prepare.cc.
References close_tables_for_reopen(), DBUG_ASSERT, DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, error, lock_tables, st_table_list::multitable_view, open_tables(), Prepared_statement::thd, update_precheck(), and st_table_list::view.
Referenced by check_prepared_statement().
01113 { 01114 int res; 01115 THD *thd= stmt->thd; 01116 uint table_count= 0; 01117 SELECT_LEX *select= &stmt->lex->select_lex; 01118 #ifndef NO_EMBEDDED_ACCESS_CHECKS 01119 uint want_privilege; 01120 #endif 01121 bool need_reopen; 01122 DBUG_ENTER("mysql_test_update"); 01123 01124 if (update_precheck(thd, table_list)) 01125 goto error; 01126 01127 for ( ; ; ) 01128 { 01129 if (open_tables(thd, &table_list, &table_count, 0)) 01130 goto error; 01131 01132 if (table_list->multitable_view) 01133 { 01134 DBUG_ASSERT(table_list->view != 0); 01135 DBUG_PRINT("info", ("Switch to multi-update")); 01136 /* pass counter value */ 01137 thd->lex->table_count= table_count; 01138 /* convert to multiupdate */ 01139 DBUG_RETURN(2); 01140 } 01141 01142 if (!lock_tables(thd, table_list, table_count, &need_reopen)) 01143 break; 01144 if (!need_reopen) 01145 goto error; 01146 close_tables_for_reopen(thd, &table_list); 01147 } 01148 01149 /* 01150 thd->fill_derived_tables() is false here for sure (because it is 01151 preparation of PS, so we even do not check it). 01152 */ 01153 if (mysql_handle_derived(thd->lex, &mysql_derived_prepare)) 01154 goto error; 01155 01156 #ifndef NO_EMBEDDED_ACCESS_CHECKS 01157 /* TABLE_LIST contain right privilages request */ 01158 want_privilege= table_list->grant.want_privilege; 01159 #endif 01160 01161 if (mysql_prepare_update(thd, table_list, &select->where, 01162 select->order_list.elements, 01163 (ORDER *) select->order_list.first)) 01164 goto error; 01165 01166 #ifndef NO_EMBEDDED_ACCESS_CHECKS 01167 table_list->grant.want_privilege= want_privilege; 01168 table_list->table->grant.want_privilege= want_privilege; 01169 table_list->register_want_access(want_privilege); 01170 #endif 01171 thd->lex->select_lex.no_wrap_view_item= TRUE; 01172 res= setup_fields(thd, 0, select->item_list, MARK_COLUMNS_READ, 0, 0); 01173 thd->lex->select_lex.no_wrap_view_item= FALSE; 01174 if (res) 01175 goto error; 01176 #ifndef NO_EMBEDDED_ACCESS_CHECKS 01177 /* Check values */ 01178 table_list->grant.want_privilege= 01179 table_list->table->grant.want_privilege= 01180 (SELECT_ACL & ~table_list->table->grant.privilege); 01181 table_list->register_want_access(SELECT_ACL); 01182 #endif 01183 if (setup_fields(thd, 0, stmt->lex->value_list, MARK_COLUMNS_NONE, 0, 0)) 01184 goto error; 01185 /* TODO: here we should send types of placeholders to the client. */ 01186 DBUG_RETURN(0); 01187 error: 01188 DBUG_RETURN(1); 01189 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void reinit_stmt_before_use | ( | THD * | thd, | |
| LEX * | lex | |||
| ) |
Definition at line 2099 of file sql_prepare.cc.
References DBUG_ASSERT, DBUG_ENTER, DBUG_VOID_RETURN, FALSE, st_table_list::next_global, NULL, order, st_table_list::reinit_before_use(), and SELECT_DESCRIBE.
Referenced by Prepared_statement::execute(), and sp_lex_keeper::reset_lex_and_exec_core().
02100 { 02101 SELECT_LEX *sl= lex->all_selects_list; 02102 DBUG_ENTER("reinit_stmt_before_use"); 02103 02104 /* 02105 We have to update "thd" pointer in LEX, all its units and in LEX::result, 02106 since statements which belong to trigger body are associated with TABLE 02107 object and because of this can be used in different threads. 02108 */ 02109 lex->thd= thd; 02110 02111 if (lex->empty_field_list_on_rset) 02112 { 02113 lex->empty_field_list_on_rset= 0; 02114 lex->field_list.empty(); 02115 } 02116 for (; sl; sl= sl->next_select_in_list()) 02117 { 02118 if (!sl->first_execution) 02119 { 02120 /* remove option which was put by mysql_explain_union() */ 02121 sl->options&= ~SELECT_DESCRIBE; 02122 02123 /* see unique_table() */ 02124 sl->exclude_from_table_unique_test= FALSE; 02125 02126 /* 02127 Copy WHERE, HAVING clause pointers to avoid damaging them 02128 by optimisation 02129 */ 02130 if (sl->prep_where) 02131 { 02132 sl->where= sl->prep_where->copy_andor_structure(thd); 02133 sl->where->cleanup(); 02134 } 02135 if (sl->prep_having) 02136 { 02137 sl->having= sl->prep_having->copy_andor_structure(thd); 02138 sl->having->cleanup(); 02139 } 02140 DBUG_ASSERT(sl->join == 0); 02141 ORDER *order; 02142 /* Fix GROUP list */ 02143 for (order= (ORDER *)sl->group_list.first; order; order= order->next) 02144 order->item= &order->item_ptr; 02145 /* Fix ORDER list */ 02146 for (order= (ORDER *)sl->order_list.first; order; order= order->next) 02147 order->item= &order->item_ptr; 02148 } 02149 { 02150 SELECT_LEX_UNIT *unit= sl->master_unit(); 02151 unit->unclean(); 02152 unit->types.empty(); 02153 /* for derived tables & PS (which can't be reset by Item_subquery) */ 02154 unit->reinit_exec_mechanism(); 02155 unit->set_thd(thd); 02156 } 02157 } 02158 02159 /* 02160 TODO: When the new table structure is ready, then have a status bit 02161 to indicate the table is altered, and re-do the setup_* 02162 and open the tables back. 02163 */ 02164 /* 02165 NOTE: We should reset whole table list here including all tables added 02166 by prelocking algorithm (it is not a problem for substatements since 02167 they have their own table list). 02168 */ 02169 for (TABLE_LIST *tables= lex->query_tables; 02170 tables; 02171 tables= tables->next_global) 02172 { 02173 tables->reinit_before_use(thd); 02174 } 02175 /* 02176 Cleanup of the special case of DELETE t1, t2 FROM t1, t2, t3 ... 02177 (multi-delete). We do a full clean up, although at the moment all we 02178 need to clean in the tables of MULTI-DELETE list is 'table' member. 02179 */ 02180 for (TABLE_LIST *tables= (TABLE_LIST*) lex->auxiliary_table_list.first; 02181 tables; 02182 tables= tables->next_global) 02183 { 02184 tables->reinit_before_use(thd); 02185 } 02186 lex->current_select= &lex->select_lex; 02187 02188 /* restore original list used in INSERT ... SELECT */ 02189 if (lex->leaf_tables_insert) 02190 lex->select_lex.leaf_tables= lex->leaf_tables_insert; 02191 02192 if (lex->result) 02193 { 02194 lex->result->cleanup(); 02195 lex->result->set_thd(thd); 02196 } 02197 lex->allow_sum_func= 0; 02198 lex->in_sum_func= NULL; 02199 DBUG_VOID_RETURN; 02200 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void reset_stmt_params | ( | Prepared_statement * | stmt | ) | [static] |
Definition at line 2212 of file sql_prepare.cc.
References Prepared_statement::param_array, and Prepared_statement::param_count.
Referenced by Prepared_statement::execute(), mysql_sql_stmt_execute(), mysql_stmt_execute(), mysql_stmt_fetch(), and mysql_stmt_reset().
02213 { 02214 Item_param **item= stmt->param_array; 02215 Item_param **end= item + stmt->param_count; 02216 for (;item < end ; ++item) 02217 (**item).reset(); 02218 }
Here is the caller graph for this function:

| static bool select_like_stmt_test | ( | Prepared_statement * | stmt, | |
| bool(*)(THD *thd) | specific_prepare, | |||
| ulong | setup_tables_done_option | |||
| ) | [static] |
Definition at line 1399 of file sql_prepare.cc.
References DBUG_ENTER, DBUG_RETURN, Prepared_statement::thd, and TRUE.
Referenced by mysql_test_multiupdate(), and select_like_stmt_test_with_open_n_lock().
01402 { 01403 DBUG_ENTER("select_like_stmt_test"); 01404 THD *thd= stmt->thd; 01405 LEX *lex= stmt->lex; 01406 01407 lex->select_lex.context.resolve_in_select_list= TRUE; 01408 01409 if (specific_prepare && (*specific_prepare)(thd)) 01410 DBUG_RETURN(TRUE); 01411 01412 thd->used_tables= 0; // Updated by setup_fields 01413 01414 /* Calls JOIN::prepare */ 01415 DBUG_RETURN(lex->unit.prepare(thd, 0, setup_tables_done_option)); 01416 }
Here is the caller graph for this function:

| static bool select_like_stmt_test_with_open_n_lock | ( | Prepared_statement * | stmt, | |
| TABLE_LIST * | tables, | |||
| bool(*)(THD *thd) | specific_prepare, | |||
| ulong | setup_tables_done_option | |||
| ) | [static] |
Definition at line 1436 of file sql_prepare.cc.
References DBUG_ENTER, DBUG_RETURN, open_and_lock_tables(), select_like_stmt_test(), Prepared_statement::thd, and TRUE.
Referenced by mysql_test_create_table(), mysql_test_insert_select(), and mysql_test_multidelete().
01440 { 01441 DBUG_ENTER("select_like_stmt_test_with_open_n_lock"); 01442 01443 /* 01444 We should not call LEX::unit.cleanup() after this open_and_lock_tables() 01445 call because we don't allow prepared EXPLAIN yet so derived tables will 01446 clean up after themself. 01447 */ 01448 if (open_and_lock_tables(stmt->thd, tables)) 01449 DBUG_RETURN(TRUE); 01450 01451 DBUG_RETURN(select_like_stmt_test(stmt, specific_prepare, 01452 setup_tables_done_option)); 01453 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static bool send_prep_stmt | ( | Prepared_statement * | stmt, | |
| uint | columns | |||
| ) | [static] |
Definition at line 207 of file sql_prepare.cc.
References DBUG_ENTER, DBUG_RETURN, int2store, int4store, min, my_net_write(), Prepared_statement::param_count, Protocol::SEND_EOF, and Prepared_statement::thd.
Referenced by check_prepared_statement(), and mysql_test_select().
00208 { 00209 NET *net= &stmt->thd->net; 00210 char buff[12]; 00211 uint tmp; 00212 DBUG_ENTER("send_prep_stmt"); 00213 00214 buff[0]= 0; /* OK packet indicator */ 00215 int4store(buff+1, stmt->id); 00216 int2store(buff+5, columns); 00217 int2store(buff+7, stmt->param_count); 00218 buff[9]= 0; // Guard against a 4.1 client 00219 tmp= min(stmt->thd->total_warn_count, 65535); 00220 int2store(buff+10, tmp); 00221 00222 /* 00223 Send types and names of placeholders to the client 00224 XXX: fix this nasty upcast from List<Item_param> to List<Item> 00225 */ 00226 DBUG_RETURN(my_net_write(net, buff, sizeof(buff)) || 00227 (stmt->param_count && 00228 stmt->thd->protocol_simple.send_fields((List<Item> *) 00229 &stmt->lex->param_list, 00230 Protocol::SEND_EOF))); 00231 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void set_param_date | ( | Item_param * | param, | |
| uchar ** | pos, | |||
| ulong | len | |||
| ) | [static] |
Definition at line 489 of file sql_prepare.cc.
References st_mysql_time::day, get_param_length(), st_mysql_time::hour, MAX_DATE_WIDTH, st_mysql_time::minute, st_mysql_time::month, MY_CHARSET_BIN_MB_MAXLEN, MYSQL_TIMESTAMP_DATE, st_mysql_time::neg, st_mysql_time::second, st_mysql_time::second_part, Item_param::set_time(), set_zero_time(), sint2korr, to, and st_mysql_time::year.
Referenced by setup_one_conversion_function().
00490 { 00491 MYSQL_TIME tm; 00492 ulong length= get_param_length(pos, len); 00493 00494 if (length >= 4) 00495 { 00496 uchar *to= *pos; 00497 00498 tm.year= (uint) sint2korr(to); 00499 tm.month= (uint) to[2]; 00500 tm.day= (uint) to[3]; 00501 00502 tm.hour= tm.minute= tm.second= 0; 00503 tm.second_part= 0; 00504 tm.neg= 0; 00505 } 00506 else 00507 set_zero_time(&tm, MYSQL_TIMESTAMP_DATE); 00508 param->set_time(&tm, MYSQL_TIMESTAMP_DATE, 00509 MAX_DATE_WIDTH * MY_CHARSET_BIN_MB_MAXLEN); 00510 *pos+= length; 00511 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void set_param_datetime | ( | Item_param * | param, | |
| uchar ** | pos, | |||
| ulong | len | |||
| ) | [static] |
Definition at line 457 of file sql_prepare.cc.
References st_mysql_time::day, get_param_length(), st_mysql_time::hour, MAX_DATETIME_WIDTH, st_mysql_time::minute, st_mysql_time::month, MY_CHARSET_BIN_MB_MAXLEN, MYSQL_TIMESTAMP_DATETIME, st_mysql_time::neg, st_mysql_time::second, st_mysql_time::second_part, Item_param::set_time(), set_zero_time(), sint2korr, sint4korr, to, and st_mysql_time::year.
Referenced by setup_one_conversion_function().
00458 { 00459 MYSQL_TIME tm; 00460 ulong length= get_param_length(pos, len); 00461 00462 if (length >= 4) 00463 { 00464 uchar *to= *pos; 00465 00466 tm.neg= 0; 00467 tm.year= (uint) sint2korr(to); 00468 tm.month= (uint) to[2]; 00469 tm.day= (uint) to[3]; 00470 if (length > 4) 00471 { 00472 tm.hour= (uint) to[4]; 00473 tm.minute= (uint) to[5]; 00474 tm.second= (uint) to[6]; 00475 } 00476 else 00477 tm.hour= tm.minute= tm.second= 0; 00478 00479 tm.second_part= (length > 7) ? (ulong) sint4korr(to+7) : 0; 00480 } 00481 else 00482 set_zero_time(&tm, MYSQL_TIMESTAMP_DATETIME); 00483 param->set_time(&tm, MYSQL_TIMESTAMP_DATETIME, 00484 MAX_DATETIME_WIDTH * MY_CHARSET_BIN_MB_MAXLEN); 00485 *pos+= length; 00486 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void set_param_decimal | ( | Item_param * | param, | |
| uchar ** | pos, | |||
| ulong | len | |||
| ) | [static] |
Definition at line 410 of file sql_prepare.cc.
References get_param_length(), and Item_param::set_decimal().
Referenced by setup_one_conversion_function().
00411 { 00412 ulong length= get_param_length(pos, len); 00413 param->set_decimal((char*)*pos, length); 00414 *pos+= length; 00415 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void set_param_double | ( | Item_param * | param, | |
| uchar ** | pos, | |||
| ulong | len | |||
| ) | [static] |
Definition at line 396 of file sql_prepare.cc.
References data, doubleget, float8get, and Item_param::set_double().
Referenced by setup_one_conversion_function().
00397 { 00398 double data; 00399 #ifndef EMBEDDED_LIBRARY 00400 if (len < 8) 00401 return; 00402 float8get(data,*pos); 00403 #else 00404 doubleget(data, *pos); 00405 #endif 00406 param->set_double((double) data); 00407 *pos+= 8; 00408 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void set_param_float | ( | Item_param * | param, | |
| uchar ** | pos, | |||
| ulong | len | |||
| ) | [static] |
Definition at line 382 of file sql_prepare.cc.
References data, float4get, floatget, and Item_param::set_double().
Referenced by setup_one_conversion_function().
00383 { 00384 float data; 00385 #ifndef EMBEDDED_LIBRARY 00386 if (len < 4) 00387 return; 00388 float4get(data,*pos); 00389 #else 00390 floatget(data, *pos); 00391 #endif 00392 param->set_double((double) data); 00393 *pos+= 4; 00394 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void set_param_int32 | ( | Item_param * | param, | |
| uchar ** | pos, | |||
| ulong | len | |||
| ) | [static] |
Definition at line 353 of file sql_prepare.cc.
References longget, Item_param::set_int(), sint4korr, Item::unsigned_flag, and value.
Referenced by setup_one_conversion_function().
00354 { 00355 int32 value; 00356 #ifndef EMBEDDED_LIBRARY 00357 if (len < 4) 00358 return; 00359 value= sint4korr(*pos); 00360 #else 00361 longget(value, *pos); 00362 #endif 00363 param->set_int(param->unsigned_flag ? (longlong) ((uint32) value) : 00364 (longlong) value, 11); 00365 *pos+= 4; 00366 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void set_param_int64 | ( | Item_param * | param, | |
| uchar ** | pos, | |||
| ulong | len | |||
| ) | [static] |
Definition at line 368 of file sql_prepare.cc.
References longlongget, Item_param::set_int(), sint8korr, and value.
Referenced by setup_one_conversion_function().
00369 { 00370 longlong value; 00371 #ifndef EMBEDDED_LIBRARY 00372 if (len < 8) 00373 return; 00374 value= (longlong) sint8korr(*pos); 00375 #else 00376 longlongget(value, *pos); 00377 #endif 00378 param->set_int(value, 21); 00379 *pos+= 8; 00380 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void set_param_short | ( | Item_param * | param, | |
| uchar ** | pos, | |||
| ulong | len | |||
| ) | [static] |
Definition at line 338 of file sql_prepare.cc.
References Item_param::set_int(), shortget, sint2korr, Item::unsigned_flag, and value.
Referenced by setup_one_conversion_function().
00339 { 00340 int16 value; 00341 #ifndef EMBEDDED_LIBRARY 00342 if (len < 2) 00343 return; 00344 value= sint2korr(*pos); 00345 #else 00346 shortget(value, *pos); 00347 #endif 00348 param->set_int(param->unsigned_flag ? (longlong) ((uint16) value) : 00349 (longlong) value, 6); 00350 *pos+= 2; 00351 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void set_param_str | ( | Item_param * | param, | |
| uchar ** | pos, | |||
| ulong | len | |||
| ) | [static] |
EMBEDDED_LIBRARY
Definition at line 550 of file sql_prepare.cc.
References get_param_length(), and Item_param::set_str().
Referenced by setup_one_conversion_function().
00551 { 00552 ulong length= get_param_length(pos, len); 00553 param->set_str((const char *)*pos, length); 00554 *pos+= length; 00555 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void set_param_time | ( | Item_param * | param, | |
| uchar ** | pos, | |||
| ulong | len | |||
| ) | [static] |
Definition at line 425 of file sql_prepare.cc.
References bool, st_mysql_time::day, get_param_length(), st_mysql_time::hour, MAX_TIME_WIDTH, st_mysql_time::minute, st_mysql_time::month, MY_CHARSET_BIN_MB_MAXLEN, MYSQL_TIMESTAMP_TIME, st_mysql_time::neg, st_mysql_time::second, st_mysql_time::second_part, Item_param::set_time(), set_zero_time(), sint4korr, to, and st_mysql_time::year.
Referenced by setup_one_conversion_function().
00426 { 00427 MYSQL_TIME tm; 00428 ulong length= get_param_length(pos, len); 00429 00430 if (length >= 8) 00431 { 00432 uchar *to= *pos; 00433 uint day; 00434 00435 tm.neg= (bool) to[0]; 00436 day= (uint) sint4korr(to+1); 00437 tm.hour= (uint) to[5] + day * 24; 00438 tm.minute= (uint) to[6]; 00439 tm.second= (uint) to[7]; 00440 tm.second_part= (length > 8) ? (ulong) sint4korr(to+8) : 0; 00441 if (tm.hour > 838) 00442 { 00443 /* TODO: add warning 'Data truncated' here */ 00444 tm.hour= 838; 00445 tm.minute= 59; 00446 tm.second= 59; 00447 } 00448 tm.day= tm.year= tm.month= 0; 00449 } 00450 else 00451 set_zero_time(&tm, MYSQL_TIMESTAMP_TIME); 00452 param->set_time(&tm, MYSQL_TIMESTAMP_TIME, 00453 MAX_TIME_WIDTH * MY_CHARSET_BIN_MB_MAXLEN); 00454 *pos+= length; 00455 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void set_param_tiny | ( | Item_param * | param, | |
| uchar ** | pos, | |||
| ulong | len | |||
| ) | [static] |
EMBEDDED_LIBRARY
Definition at line 326 of file sql_prepare.cc.
References Item_param::set_int(), Item::unsigned_flag, and value.
Referenced by setup_one_conversion_function().
00327 { 00328 #ifndef EMBEDDED_LIBRARY 00329 if (len < 1) 00330 return; 00331 #endif 00332 int8 value= (int8) **pos; 00333 param->set_int(param->unsigned_flag ? (longlong) ((uint8) value) : 00334 (longlong) value, 4); 00335 *pos+= 1; 00336 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static bool setup_conversion_functions | ( | Prepared_statement * | stmt, | |
| uchar ** | data, | |||
| uchar * | data_end | |||
| ) | [static] |
Definition at line 768 of file sql_prepare.cc.
References DBUG_ENTER, DBUG_RETURN, Prepared_statement::param_array, Prepared_statement::param_count, setup_one_conversion_function(), sint2korr, test, and Prepared_statement::thd.
Referenced by mysql_stmt_execute().
00770 { 00771 /* skip null bits */ 00772 uchar *read_pos= *data + (stmt->param_count+7) / 8; 00773 00774 DBUG_ENTER("setup_conversion_functions"); 00775 00776 if (*read_pos++) //types supplied / first execute 00777 { 00778 /* 00779 First execute or types altered by the client, setup the 00780 conversion routines for all parameters (one time) 00781 */ 00782 Item_param **it= stmt->param_array; 00783 Item_param **end= it + stmt->param_count; 00784 THD *thd= stmt->thd; 00785 for (; it < end; ++it) 00786 { 00787 ushort typecode; 00788 const uint signed_bit= 1 << 15; 00789 00790 if (read_pos >= data_end) 00791 DBUG_RETURN(1); 00792 00793 typecode= sint2korr(read_pos); 00794 read_pos+= 2; 00795 (**it).unsigned_flag= test(typecode & signed_bit); 00796 setup_one_conversion_function(thd, *it, (uchar) (typecode & ~signed_bit)); 00797 } 00798 } 00799 *data= read_pos; 00800 DBUG_RETURN(0); 00801 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void setup_one_conversion_function | ( | THD * | thd, | |
| Item_param * | param, | |||
| uchar | param_type | |||
| ) | [static] |
Definition at line 560 of file sql_prepare.cc.
References Item_param::cs_info, DBUG_ASSERT, Item::DECIMAL_ITEM, DECIMAL_RESULT, Item::INT_ITEM, INT_RESULT, Item_param::item_result_type, Item_param::item_type, my_charset_bin, MYSQL_TYPE_BLOB, MYSQL_TYPE_DATE, MYSQL_TYPE_DATETIME, MYSQL_TYPE_DECIMAL, MYSQL_TYPE_DOUBLE, MYSQL_TYPE_FLOAT, MYSQL_TYPE_LONG, MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONGLONG, MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_SHORT, MYSQL_TYPE_TIME, MYSQL_TYPE_TIMESTAMP, MYSQL_TYPE_TINY, MYSQL_TYPE_TINY_BLOB, String::needs_conversion(), Item_param::param_type, Item::REAL_ITEM, REAL_RESULT, set_param_date(), set_param_datetime(), set_param_decimal(), set_param_double(), set_param_float(), Item_param::set_param_func, set_param_int32(), set_param_int64(), set_param_short(), set_param_str(), set_param_time(), set_param_tiny(), Item::STRING_ITEM, STRING_RESULT, and Item_param::value.
Referenced by setup_conversion_functions().
00562 { 00563 switch (param_type) { 00564 case MYSQL_TYPE_TINY: 00565 param->set_param_func= set_param_tiny; 00566 param->item_type= Item::INT_ITEM; 00567 param->item_result_type= INT_RESULT; 00568 break; 00569 case MYSQL_TYPE_SHORT: 00570 param->set_param_func= set_param_short; 00571 param->item_type= Item::INT_ITEM; 00572 param->item_result_type= INT_RESULT; 00573 break; 00574 case MYSQL_TYPE_LONG: 00575 param->set_param_func= set_param_int32; 00576 param->item_type= Item::INT_ITEM; 00577 param->item_result_type= INT_RESULT; 00578 break; 00579 case MYSQL_TYPE_LONGLONG: 00580 param->set_param_func= set_param_int64; 00581 param->item_type= Item::INT_ITEM; 00582 param->item_result_type= INT_RESULT; 00583 break; 00584 case MYSQL_TYPE_FLOAT: 00585 param->set_param_func= set_param_float; 00586 param->item_type= Item::REAL_ITEM; 00587 param->item_result_type= REAL_RESULT; 00588 break; 00589 case MYSQL_TYPE_DOUBLE: 00590 param->set_param_func= set_param_double; 00591 param->item_type= Item::REAL_ITEM; 00592 param->item_result_type= REAL_RESULT; 00593 break; 00594 case MYSQL_TYPE_DECIMAL: 00595 case MYSQL_TYPE_NEWDECIMAL: 00596 param->set_param_func= set_param_decimal; 00597 param->item_type= Item::DECIMAL_ITEM; 00598 param->item_result_type= DECIMAL_RESULT; 00599 break; 00600 case MYSQL_TYPE_TIME: 00601 param->set_param_func= set_param_time; 00602 param->item_type= Item::STRING_ITEM; 00603 param->item_result_type= STRING_RESULT; 00604 break; 00605 case MYSQL_TYPE_DATE: 00606 param->set_param_func= set_param_date; 00607 param->item_type= Item::STRING_ITEM; 00608 param->item_result_type= STRING_RESULT; 00609 break; 00610 case MYSQL_TYPE_DATETIME: 00611 case MYSQL_TYPE_TIMESTAMP: 00612 param->set_param_func= set_param_datetime; 00613 param->item_type= Item::STRING_ITEM; 00614 param->item_result_type= STRING_RESULT; 00615 break; 00616 case MYSQL_TYPE_TINY_BLOB: 00617 case MYSQL_TYPE_MEDIUM_BLOB: 00618 case MYSQL_TYPE_LONG_BLOB: 00619 case MYSQL_TYPE_BLOB: 00620 param->set_param_func= set_param_str; 00621 param->value.cs_info.character_set_of_placeholder= &my_charset_bin; 00622 param->value.cs_info.character_set_client= 00623 thd->variables.character_set_client; 00624 DBUG_ASSERT(thd->variables.character_set_client); 00625 param->value.cs_info.final_character_set_of_str_value= &my_charset_bin; 00626 param->item_type= Item::STRING_ITEM; 00627 param->item_result_type= STRING_RESULT; 00628 break; 00629 default: 00630 /* 00631 The client library ensures that we won't get any other typecodes 00632 except typecodes above and typecodes for string types. Marking 00633 label as 'default' lets us to handle malformed packets as well. 00634 */ 00635 { 00636 CHARSET_INFO *fromcs= thd->variables.character_set_client; 00637 CHARSET_INFO *tocs= thd->variables.collation_connection; 00638 uint32 dummy_offset; 00639 00640 param->value.cs_info.character_set_of_placeholder= fromcs; 00641 param->value.cs_info.character_set_client= fromcs; 00642 00643 /* 00644 Setup source and destination character sets so that they 00645 are different only if conversion is necessary: this will 00646 make later checks easier. 00647 */ 00648 param->value.cs_info.final_character_set_of_str_value= 00649 String::needs_conversion(0, fromcs, tocs, &dummy_offset) ? 00650 tocs : fromcs; 00651 param->set_param_func= set_param_str; 00652 /* 00653 Exact value of max_length is not known unless data is converted to 00654 charset of connection, so we have to set it later. 00655 */ 00656 param->item_type= Item::STRING_ITEM; 00657 param->item_result_type= STRING_RESULT; 00658 } 00659 } 00660 param->param_type= (enum enum_field_types) param_type; 00661 }
Here is the call graph for this function:

Here is the caller graph for this function:

1.4.7

