1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

errors without code removed

net_printf/send_error calls replaced by my_error family functions
-1/1 (sent/unsent) error reporting removed
(WL#2133)
This commit is contained in:
bell@sanja.is.com.ua
2004-10-20 04:04:37 +03:00
parent 09e9651acc
commit 4714a6e744
86 changed files with 1886 additions and 1566 deletions

View File

@ -122,16 +122,13 @@ inline bool is_param_null(const uchar *pos, ulong param_no)
enum { STMT_QUERY_LOG_LENGTH= 8192 };
enum enum_send_error { DONT_SEND_ERROR= 0, SEND_ERROR };
/*
Seek prepared statement in statement map by id: returns zero if statement
was not found, pointer otherwise.
*/
static Prepared_statement *
find_prepared_statement(THD *thd, ulong id, const char *where,
enum enum_send_error se)
find_prepared_statement(THD *thd, ulong id, const char *where)
{
Statement *stmt= thd->stmt_map.find(id);
@ -139,8 +136,6 @@ find_prepared_statement(THD *thd, ulong id, const char *where,
{
char llbuf[22];
my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), 22, llstr(id, llbuf), where);
if (se == SEND_ERROR)
send_error(thd);
return 0;
}
return (Prepared_statement *) stmt;
@ -180,7 +175,7 @@ static bool send_prep_stmt(Prepared_statement *stmt,
thd->client_stmt_id= stmt->id;
thd->client_param_count= stmt->param_count;
thd->net.last_errno= 0;
thd->clear_error();
return 0;
}
@ -881,24 +876,23 @@ static bool insert_params_from_vars_with_log(Prepared_statement *stmt,
tables global/local table list
RETURN VALUE
0 ok
1 error, sent to the client
-1 error, not sent to client
FALSE OK
TRUE error
*/
static int 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 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)
{
THD *thd= stmt->thd;
LEX *lex= stmt->lex;
List_iterator_fast<List_item> its(values_list);
List_item *values;
int res;
bool res;
my_bool update= (lex->value_list.elements ? UPDATE_ACL : 0);
DBUG_ENTER("mysql_test_insert");
@ -909,9 +903,9 @@ static int mysql_test_insert(Prepared_statement *stmt,
open temporary memory pool for temporary data allocated by derived
tables & preparation procedure
*/
if ((res= open_and_lock_tables(thd, table_list)))
if (open_and_lock_tables(thd, table_list))
{
DBUG_RETURN(res);
DBUG_RETURN(TRUE);
}
if ((values= its++))
@ -958,14 +952,13 @@ error:
tables list of tables queries
RETURN VALUE
0 success
1 error, sent to client
-1 error, not sent to client
FALSE success
TRUE error
*/
static int mysql_test_update(Prepared_statement *stmt,
TABLE_LIST *table_list)
static bool mysql_test_update(Prepared_statement *stmt,
TABLE_LIST *table_list)
{
int res;
bool res;
THD *thd= stmt->thd;
SELECT_LEX *select= &stmt->lex->select_lex;
DBUG_ENTER("mysql_test_update");
@ -1010,28 +1003,27 @@ static int mysql_test_update(Prepared_statement *stmt,
tables list of tables queries
RETURN VALUE
0 success
1 error, sent to client
-1 error, not sent to client
FALSE success
TRUE error
*/
static int mysql_test_delete(Prepared_statement *stmt,
TABLE_LIST *table_list)
{
int res;
THD *thd= stmt->thd;
LEX *lex= stmt->lex;
DBUG_ENTER("mysql_test_delete");
if ((res= delete_precheck(thd, table_list)))
DBUG_RETURN(res);
if (delete_precheck(thd, table_list))
DBUG_RETURN(TRUE);
if (!(res=open_and_lock_tables(thd, table_list)))
if (!open_and_lock_tables(thd, table_list))
{
res= mysql_prepare_delete(thd, table_list, &lex->select_lex.where);
mysql_prepare_delete(thd, table_list, &lex->select_lex.where);
lex->unit.cleanup();
DBUG_RETURN(FALSE)
}
/* TODO: here we should send types of placeholders to the client. */
DBUG_RETURN(res);
DBUG_RETURN(TRUE);
}
@ -1046,9 +1038,8 @@ static int mysql_test_delete(Prepared_statement *stmt,
tables list of tables queries
RETURN VALUE
0 success
1 error, sent to client
-1 error, not sent to client
FALSE success
TRUE error, sent to client
*/
static int mysql_test_select(Prepared_statement *stmt,
@ -1057,7 +1048,7 @@ static int mysql_test_select(Prepared_statement *stmt,
THD *thd= stmt->thd;
LEX *lex= stmt->lex;
SELECT_LEX_UNIT *unit= &lex->unit;
int result;
bool result;
DBUG_ENTER("mysql_test_select");
#ifndef NO_EMBEDDED_ACCESS_CHECKS
@ -1065,26 +1056,21 @@ static int mysql_test_select(Prepared_statement *stmt,
if (tables)
{
if (check_table_access(thd, privilege, tables,0))
DBUG_RETURN(1);
DBUG_RETURN(TRUE);
}
else if (check_access(thd, privilege, any_db,0,0,0))
DBUG_RETURN(1);
DBUG_RETURN(TRUE);
#endif
if ((result= open_and_lock_tables(thd, tables)))
{
result= 1; // Error sent
send_error(thd);
goto err;
}
result= 1;
result= TRUE;
thd->used_tables= 0; // Updated by setup_fields
// JOIN::prepare calls
if (unit->prepare(thd, 0, 0))
{
send_error(thd);
goto err_prep;
}
if (!text_protocol)
@ -1106,7 +1092,7 @@ static int mysql_test_select(Prepared_statement *stmt,
goto err_prep;
}
}
result= 0; // ok
result= FALSE; // ok
err_prep:
unit->cleanup();
@ -1125,30 +1111,27 @@ err:
values list of expressions
RETURN VALUE
0 success
1 error, sent to client
-1 error, not sent to client
FALSE success
TRUE error, sent to client
*/
static int mysql_test_do_fields(Prepared_statement *stmt,
static bool mysql_test_do_fields(Prepared_statement *stmt,
TABLE_LIST *tables,
List<Item> *values)
{
DBUG_ENTER("mysql_test_do_fields");
THD *thd= stmt->thd;
int res= 0;
if (tables && (res= check_table_access(thd, SELECT_ACL, tables, 0)))
DBUG_RETURN(res);
bool res;
if (tables && check_table_access(thd, SELECT_ACL, tables, 0))
DBUG_RETURN(TRUE);
if (tables && (res= open_and_lock_tables(thd, tables)))
if (tables && open_and_lock_tables(thd, tables))
{
DBUG_RETURN(res);
DBUG_RETURN(TRUE);
}
res= setup_fields(thd, 0, 0, *values, 0, 0, 0);
stmt->lex->unit.cleanup();
if (res)
DBUG_RETURN(-1);
DBUG_RETURN(0);
DBUG_RETURN(res);
}
@ -1162,22 +1145,21 @@ static int mysql_test_do_fields(Prepared_statement *stmt,
values list of expressions
RETURN VALUE
0 success
1 error, sent to client
-1 error, not sent to client
FALSE success
TRUE error
*/
static int mysql_test_set_fields(Prepared_statement *stmt,
TABLE_LIST *tables,
List<set_var_base> *var_list)
static bool mysql_test_set_fields(Prepared_statement *stmt,
TABLE_LIST *tables,
List<set_var_base> *var_list)
{
DBUG_ENTER("mysql_test_set_fields");
List_iterator_fast<set_var_base> it(*var_list);
THD *thd= stmt->thd;
set_var_base *var;
int res= 0;
bool res= 0;
if (tables && (res= check_table_access(thd, SELECT_ACL, tables, 0)))
DBUG_RETURN(res);
if (tables && check_table_access(thd, SELECT_ACL, tables, 0))
DBUG_RETURN(TRUE);
if (tables && (res= open_and_lock_tables(thd, tables)))
goto error;
@ -1186,7 +1168,7 @@ static int mysql_test_set_fields(Prepared_statement *stmt,
if (var->light_check(thd))
{
stmt->lex->unit.cleanup();
res= -1;
res= TRUE;
goto error;
}
}
@ -1206,18 +1188,17 @@ error:
specific_prepare - function of command specific prepare
RETURN VALUE
0 success
1 error, sent to client
-1 error, not sent to client
FALSE success
TRUE error
*/
static int select_like_statement_test(Prepared_statement *stmt,
TABLE_LIST *tables,
int (*specific_prepare)(THD *thd))
static bool select_like_statement_test(Prepared_statement *stmt,
TABLE_LIST *tables,
bool (*specific_prepare)(THD *thd))
{
DBUG_ENTER("select_like_statement_test");
THD *thd= stmt->thd;
LEX *lex= stmt->lex;
int res= 0;
bool res= 0;
if (tables && (res= open_and_lock_tables(thd, tables)))
goto end;
@ -1230,7 +1211,7 @@ static int select_like_statement_test(Prepared_statement *stmt,
// JOIN::prepare calls
if (lex->unit.prepare(thd, 0, 0))
{
res= thd->net.report_error ? -1 : 1;
res= TRUE;
}
end:
lex->unit.cleanup();
@ -1287,16 +1268,15 @@ static int mysql_test_create_table(Prepared_statement *stmt)
tables list of tables queries
RETURN VALUE
0 success
1 error, sent to client
-1 error, not sent to client
FALSE success
TRUE error
*/
static int mysql_test_multiupdate(Prepared_statement *stmt,
static bool mysql_test_multiupdate(Prepared_statement *stmt,
TABLE_LIST *tables)
{
int res;
if ((res= multi_update_precheck(stmt->thd, tables)))
return res;
if (multi_update_precheck(stmt->thd, tables))
return TRUE;
return select_like_statement_test(stmt, tables, &mysql_multi_update_prepare);
}
@ -1477,8 +1457,6 @@ static int send_prepare_results(Prepared_statement *stmt, bool text_protocol)
if (res == 0)
DBUG_RETURN(text_protocol? 0 : send_prep_stmt(stmt, 0));
error:
if (res < 0)
send_error(thd,thd->killed_errno());
DBUG_RETURN(1);
}
@ -1500,10 +1478,7 @@ static bool init_param_array(Prepared_statement *stmt)
alloc_root(&stmt->thd->mem_root,
sizeof(Item_param*) * stmt->param_count);
if (!stmt->param_array)
{
send_error(stmt->thd, ER_OUT_OF_RESOURCES);
return 1;
}
for (to= stmt->param_array;
to < stmt->param_array + stmt->param_count;
++to)
@ -1527,10 +1502,10 @@ static bool init_param_array(Prepared_statement *stmt)
name NULL or statement name. For unnamed statements binary PS
protocol is used, for named statements text protocol is
used.
RETURN
0 OK, statement prepared successfully
other Error
RETURN
FALSE OK, statement prepared successfully
TRUE Error
NOTES
This function parses the query and sends the total number of parameters
and resultset metadata information back to client (if any), without
@ -1544,21 +1519,18 @@ static bool init_param_array(Prepared_statement *stmt)
*/
int mysql_stmt_prepare(THD *thd, char *packet, uint packet_length,
LEX_STRING *name)
bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length,
LEX_STRING *name)
{
LEX *lex;
Prepared_statement *stmt= new Prepared_statement(thd);
int error;
bool error;
DBUG_ENTER("mysql_stmt_prepare");
DBUG_PRINT("prep_query", ("%s", packet));
if (stmt == 0)
{
send_error(thd, ER_OUT_OF_RESOURCES);
DBUG_RETURN(1);
}
DBUG_RETURN(TRUE);
if (name)
{
@ -1567,16 +1539,14 @@ int mysql_stmt_prepare(THD *thd, char *packet, uint packet_length,
name->length)))
{
delete stmt;
send_error(thd, ER_OUT_OF_RESOURCES);
DBUG_RETURN(1);
DBUG_RETURN(TRUE);
}
}
if (thd->stmt_map.insert(stmt))
{
delete stmt;
send_error(thd, ER_OUT_OF_RESOURCES);
DBUG_RETURN(1);
DBUG_RETURN(TRUE);
}
thd->set_n_backup_statement(stmt, &thd->stmt_backup);
@ -1588,8 +1558,7 @@ int mysql_stmt_prepare(THD *thd, char *packet, uint packet_length,
thd->restore_backup_item_arena(stmt, &thd->stmt_backup);
/* Statement map deletes statement on erase */
thd->stmt_map.erase(stmt);
send_error(thd, ER_OUT_OF_RESOURCES);
DBUG_RETURN(1);
DBUG_RETURN(TRUE);
}
mysql_log.write(thd, COM_PREPARE, "%s", packet);
@ -1768,8 +1737,7 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length)
packet+= 9; /* stmt_id + 5 bytes of flags */
if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_execute",
SEND_ERROR)))
if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_execute")))
DBUG_VOID_RETURN;
DBUG_PRINT("exec_query:", ("%s", stmt->query));
@ -1777,7 +1745,7 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length)
/* Check if we got an error when sending long data */
if (stmt->state == Item_arena::ERROR)
{
send_error(thd, stmt->last_errno, stmt->last_error);
my_message(stmt->last_errno, stmt->last_error, MYF(0));
DBUG_VOID_RETURN;
}
@ -1795,10 +1763,7 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length)
{
if (!stmt->cursor &&
!(stmt->cursor= new (&stmt->mem_root) Cursor()))
{
send_error(thd, ER_OUT_OF_RESOURCES);
DBUG_VOID_RETURN;
}
/* If lex->result is set, mysql_execute_command will use it */
stmt->lex->result= &stmt->cursor->result;
}
@ -1866,7 +1831,6 @@ set_params_data_err:
reset_stmt_params(stmt);
my_error(ER_WRONG_ARGUMENTS, MYF(0), "mysql_stmt_execute");
err:
send_error(thd);
DBUG_VOID_RETURN;
}
@ -1892,14 +1856,12 @@ void mysql_sql_stmt_execute(THD *thd, LEX_STRING *stmt_name)
{
my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), stmt_name->length,
stmt_name->str, "EXECUTE");
send_error(thd);
DBUG_VOID_RETURN;
}
if (stmt->param_count != thd->lex->prepared_stmt_params.elements)
{
my_error(ER_WRONG_ARGUMENTS, MYF(0), "EXECUTE");
send_error(thd);
DBUG_VOID_RETURN;
}
@ -1910,7 +1872,6 @@ void mysql_sql_stmt_execute(THD *thd, LEX_STRING *stmt_name)
&expanded_query))
{
my_error(ER_WRONG_ARGUMENTS, MYF(0), "EXECUTE");
send_error(thd);
}
execute_stmt(thd, stmt, &expanded_query);
DBUG_VOID_RETURN;
@ -1994,7 +1955,6 @@ void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length)
!stmt->cursor->is_open())
{
my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), stmt_id, "fetch");
send_error(thd);
DBUG_VOID_RETURN;
}
@ -2018,9 +1978,6 @@ void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length)
thd->set_statement(&thd->stmt_backup);
thd->set_item_arena(&thd->stmt_backup);
if (error && error != -4)
send_error(thd, ER_OUT_OF_RESOURCES);
DBUG_VOID_RETURN;
}
@ -2050,8 +2007,7 @@ void mysql_stmt_reset(THD *thd, char *packet)
DBUG_ENTER("mysql_stmt_reset");
if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_reset",
SEND_ERROR)))
if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_reset")))
DBUG_VOID_RETURN;
stmt->state= Item_arena::PREPARED;
@ -2081,8 +2037,7 @@ void mysql_stmt_free(THD *thd, char *packet)
DBUG_ENTER("mysql_stmt_free");
if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_close",
DONT_SEND_ERROR)))
if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_close")))
DBUG_VOID_RETURN;
/* Statement map deletes statement on erase */
@ -2132,8 +2087,8 @@ void mysql_stmt_get_longdata(THD *thd, char *packet, ulong packet_length)
stmt_id= uint4korr(packet);
packet+= 4;
if (!(stmt=find_prepared_statement(thd, stmt_id, "mysql_stmt_send_long_data",
DONT_SEND_ERROR)))
if (!(stmt=find_prepared_statement(thd, stmt_id,
"mysql_stmt_send_long_data")))
DBUG_VOID_RETURN;
param_number= uint2korr(packet);