mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Post review fixes for "SQL Syntax for Prepared Statements".
mysql-test/r/ps.result: Better error message mysys/my_error.c: Comments added sql/item.cc: Moved a chunk of code from sql_prepare.cc to Item_param::set_from_user_var sql/item.h: Moved a chunk of code from sql_prepare.cc to Item_param::set_from_user_var sql/item_func.cc: Code cleanup sql/mysql_priv.h: Code cleanup sql/sql_class.cc: Code cleanup sql/sql_parse.cc: use user_var_entry::val_str in PREPARE stmt FROM @var. sql/sql_prepare.cc: Post-review fixes and code cleanup. sql/sql_yacc.yy: Coding style fixes
This commit is contained in:
@ -1976,86 +1976,59 @@ mysql_execute_command(THD *thd)
|
||||
break;
|
||||
}
|
||||
case SQLCOM_PREPARE:
|
||||
{
|
||||
{
|
||||
char *query_str;
|
||||
uint query_len;
|
||||
if (lex->prepared_stmt_code_is_varref)
|
||||
{
|
||||
/* This is PREPARE stmt FROM @var. */
|
||||
String str;
|
||||
String *pstr;
|
||||
CHARSET_INFO *to_cs= thd->variables.collation_connection;
|
||||
CHARSET_INFO *from_cs;
|
||||
const char *buf;
|
||||
uint buf_len;
|
||||
bool need_conversion;
|
||||
LINT_INIT(from_cs); /* protected by need_conversion */
|
||||
user_var_entry *entry;
|
||||
uint32 unused;
|
||||
/*
|
||||
Convert @var contents to string in connection character set. Although
|
||||
it is known that int/real/NULL value cannot be a valid query we still
|
||||
convert it for error messages to uniform.
|
||||
Convert @var contents to string in connection character set. Although
|
||||
it is known that int/real/NULL value cannot be a valid query we still
|
||||
convert it for error messages to uniform.
|
||||
*/
|
||||
if ((entry=
|
||||
(user_var_entry*)hash_search(&thd->user_vars,
|
||||
if ((entry=
|
||||
(user_var_entry*)hash_search(&thd->user_vars,
|
||||
(byte*)lex->prepared_stmt_code.str,
|
||||
lex->prepared_stmt_code.length))
|
||||
&& entry->value)
|
||||
{
|
||||
switch (entry->type)
|
||||
{
|
||||
case REAL_RESULT:
|
||||
str.set(*(double*)entry->value, NOT_FIXED_DEC, to_cs);
|
||||
buf_len= str.length();
|
||||
buf= str.ptr();
|
||||
need_conversion= false;
|
||||
break;
|
||||
case INT_RESULT:
|
||||
str.set(*(longlong*)entry->value, to_cs);
|
||||
buf_len= str.length();
|
||||
buf= str.ptr();
|
||||
need_conversion= false;
|
||||
break;
|
||||
case STRING_RESULT:
|
||||
buf_len= entry->length;
|
||||
buf= entry->value;
|
||||
from_cs = entry->collation.collation;
|
||||
need_conversion= String::needs_conversion(entry->length, from_cs,
|
||||
to_cs, &unused);
|
||||
break;
|
||||
default:
|
||||
buf= "";
|
||||
need_conversion= false;
|
||||
buf_len= 0;
|
||||
DBUG_ASSERT(0);
|
||||
}
|
||||
String *pstr;
|
||||
my_bool is_var_null;
|
||||
pstr= entry->val_str(&is_var_null, &str, NOT_FIXED_DEC);
|
||||
DBUG_ASSERT(!is_var_null);
|
||||
if (!pstr)
|
||||
send_error(thd, ER_OUT_OF_RESOURCES);
|
||||
DBUG_ASSERT(pstr == &str);
|
||||
}
|
||||
else
|
||||
{
|
||||
from_cs= &my_charset_bin;
|
||||
str.set("NULL", 4, from_cs);
|
||||
buf= str.ptr();
|
||||
buf_len= str.length();
|
||||
need_conversion= String::needs_conversion(str.length(), from_cs,
|
||||
to_cs, &unused);
|
||||
}
|
||||
|
||||
query_len = need_conversion? (buf_len * to_cs->mbmaxlen) : buf_len;
|
||||
str.set("NULL", 4, &my_charset_latin1);
|
||||
need_conversion=
|
||||
String::needs_conversion(str.length(), str.charset(), to_cs, &unused);
|
||||
|
||||
query_len= need_conversion? (str.length() * to_cs->mbmaxlen) :
|
||||
str.length();
|
||||
if (!(query_str= alloc_root(&thd->mem_root, query_len+1)))
|
||||
send_error(thd, ER_OUT_OF_RESOURCES);
|
||||
|
||||
|
||||
if (need_conversion)
|
||||
query_len= copy_and_convert(query_str, query_len, to_cs, buf, buf_len,
|
||||
from_cs);
|
||||
query_len= copy_and_convert(query_str, query_len, to_cs, str.ptr(),
|
||||
str.length(), str.charset());
|
||||
else
|
||||
memcpy(query_str, buf, query_len);
|
||||
memcpy(query_str, str.ptr(), str.length());
|
||||
query_str[query_len]= 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
query_str= lex->prepared_stmt_code.str;
|
||||
query_len= lex->prepared_stmt_code.length;
|
||||
DBUG_PRINT("info", ("PREPARE: %.*s FROM '%.*s' \n",
|
||||
DBUG_PRINT("info", ("PREPARE: %.*s FROM '%.*s' \n",
|
||||
lex->prepared_stmt_name.length,
|
||||
lex->prepared_stmt_name.str,
|
||||
query_len, query_str));
|
||||
@ -2068,7 +2041,7 @@ mysql_execute_command(THD *thd)
|
||||
}
|
||||
case SQLCOM_EXECUTE:
|
||||
{
|
||||
DBUG_PRINT("info", ("EXECUTE: %.*s\n",
|
||||
DBUG_PRINT("info", ("EXECUTE: %.*s\n",
|
||||
lex->prepared_stmt_name.length,
|
||||
lex->prepared_stmt_name.str));
|
||||
mysql_sql_stmt_execute(thd, &lex->prepared_stmt_name);
|
||||
@ -3559,7 +3532,6 @@ error:
|
||||
*/
|
||||
|
||||
int check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables)
|
||||
|
||||
{
|
||||
if (check_access(thd, privilege, tables->db, &tables->grant.privilege,0,0))
|
||||
return 1;
|
||||
|
Reference in New Issue
Block a user