1
0
mirror of https://github.com/MariaDB/server.git synced 2025-12-24 11:21:21 +03:00

Patch two (the final one) for Bug#7306 "the server side preparedStatement

error for LIMIT placeholder".
The patch adds grammar support for LIMIT ?, ? and changes the
type of ST_SELECT_LEX::select_limit,offset_limit from ha_rows to Item*,
so that it can point to Item_param.


mysql-test/include/ps_modify.inc:
  Fix existing tests: now LIMIT can contain placeholders.
mysql-test/include/ps_query.inc:
  Fix existing tests: now LIMIT can contain placeholders.
mysql-test/r/ps.result:
  Add basic test coverage for LIMIT ?, ? and fix test results.
mysql-test/r/ps_2myisam.result:
  Fix test results: now LIMIT can contain placeholders.
mysql-test/r/ps_3innodb.result:
  Fix test results: now LIMIT can contain placeholders.
mysql-test/r/ps_4heap.result:
  Fix test results: now LIMIT can contain placeholders.
mysql-test/r/ps_5merge.result:
  Fix test results: now LIMIT can contain placeholders.
mysql-test/r/ps_6bdb.result:
  Fix test results: now LIMIT can contain placeholders.
mysql-test/r/ps_7ndb.result:
  Fix test results: now LIMIT can contain placeholders.
mysql-test/t/ps.test:
  Add basic test coverage for LIMIT ?, ?.
sql/item.h:
  Add a short-cut for (ulonglong) val_int() to Item.
  Add a constructor to Item_int() that accepts ulonglong.
  Simplify Item_uint constructor by using the c-tor above.
sql/item_subselect.cc:
  Now select_limit has type Item *.
  We can safely create an Item in Item_exists_subselect::fix_length_and_dec():
  it will be allocated in runtime memory root and freed in the end of
  execution.
sql/sp_head.cc:
  Add a special initalization state for stored procedures to 
  be able to easily distinguish the first execution of a stored procedure
  from prepared statement prepare.
sql/sql_class.h:
  Introduce new state 'INITIALIZED_FOR_SP' to be able to easily distinguish
  the first execution of a stored procedure from prepared statement prepare.
sql/sql_derived.cc:
  - use unit->set_limit() to set unit->select_limit_cnt, offset_limit_cnt
    evreryplace. Add a warning about use of set_limit in 
  mysql_derived_filling.
sql/sql_error.cc:
  - use unit->set_limit() to set unit->select_limit_cnt, offset_limit_cnt
    evreryplace.
  - this change is also aware of bug#11095 "show warnings limit 0 returns 
  all rows instead of zero rows", so the one who merges the bugfix from
  4.1 can use local version of sql_error.cc.
sql/sql_handler.cc:
  - use unit->set_limit() to initalize 
  unit->select_limit_cnt,offset_limit_cnt everyplace.
sql/sql_lex.cc:
  Now ST_SELECT_LEX::select_limit, offset_limit have type Item *
sql/sql_lex.h:
  Now ST_SELECT_LEX::select_limit, offset_limit have type Item *
sql/sql_parse.cc:
  - use unit->set_limit() to initalize 
  unit->select_limit_cnt,offset_limit_cnt everyplace. 
  - we can create an Item_int to set global limit of a statement:
  it will be created in the runtime mem root and freed in the end of
  execution.
sql/sql_repl.cc:
  Use unit->set_limit to initialize limits.
sql/sql_select.cc:
  - select_limit is now Item* so the proper way to check for default value
  is to compare it with NULL.
sql/sql_union.cc:
  Evaluate offset_limit_cnt using the new type of ST_SELECT_LEX::offset_limit
sql/sql_view.cc:
  Now ST_SELECT_LEX::select_limit, offset_limit have type Item *
sql/sql_yacc.yy:
  Add grammar support for LIMIT ?, ? clause.
This commit is contained in:
unknown
2005-06-07 14:11:36 +04:00
parent a9ccff554a
commit 5188f031ae
25 changed files with 203 additions and 132 deletions

View File

@@ -2351,7 +2351,8 @@ mysql_execute_command(THD *thd)
{
SELECT_LEX *param= lex->unit.global_parameters;
if (!param->explicit_limit)
param->select_limit= thd->variables.select_limit;
param->select_limit=
new Item_int((ulonglong)thd->variables.select_limit);
}
select_result *result=lex->result;
@@ -3146,13 +3147,15 @@ unsent_create_error:
DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (update_precheck(thd, all_tables))
break;
DBUG_ASSERT(select_lex->offset_limit == 0);
unit->set_limit(select_lex);
res= (result= mysql_update(thd, all_tables,
select_lex->item_list,
lex->value_list,
select_lex->where,
select_lex->order_list.elements,
(ORDER *) select_lex->order_list.first,
select_lex->select_limit,
unit->select_limit_cnt,
lex->duplicates, lex->ignore));
/* mysql_update return 2 if we need to switch to multi-update */
if (result != 2)
@@ -3258,9 +3261,11 @@ unsent_create_error:
DBUG_ASSERT(first_table == all_tables && first_table != 0);
if ((res= delete_precheck(thd, all_tables)))
break;
DBUG_ASSERT(select_lex->offset_limit == 0);
unit->set_limit(select_lex);
res = mysql_delete(thd, all_tables, select_lex->where,
&select_lex->order_list,
select_lex->select_limit, select_lex->options);
unit->select_limit_cnt, select_lex->options);
break;
}
case SQLCOM_DELETE_MULTI:
@@ -3847,9 +3852,10 @@ unsent_create_error:
*/
if (check_db_used(thd, all_tables))
goto error;
unit->set_limit(select_lex);
res= mysql_ha_read(thd, first_table, lex->ha_read_mode, lex->ident.str,
lex->insert_list, lex->ha_rkey_mode, select_lex->where,
select_lex->select_limit, select_lex->offset_limit);
unit->select_limit_cnt, unit->offset_limit_cnt);
break;
case SQLCOM_BEGIN:
@@ -5130,7 +5136,6 @@ mysql_init_select(LEX *lex)
{
SELECT_LEX *select_lex= lex->current_select;
select_lex->init_select();
select_lex->select_limit= HA_POS_ERROR;
lex->orig_sql_command= SQLCOM_END;
lex->wild= 0;
if (select_lex == &lex->select_lex)
@@ -5145,6 +5150,7 @@ bool
mysql_new_select(LEX *lex, bool move_down)
{
SELECT_LEX *select_lex;
THD *thd;
DBUG_ENTER("mysql_new_select");
if (!(select_lex= new(lex->thd->mem_root) SELECT_LEX()))
@@ -5194,7 +5200,7 @@ mysql_new_select(LEX *lex, bool move_down)
fake->select_number= INT_MAX;
fake->make_empty_select();
fake->linkage= GLOBAL_OPTIONS_TYPE;
fake->select_limit= HA_POS_ERROR;
fake->select_limit= 0;
}
}
@@ -5242,8 +5248,8 @@ void mysql_init_multi_delete(LEX *lex)
{
lex->sql_command= SQLCOM_DELETE_MULTI;
mysql_init_select(lex);
lex->select_lex.select_limit= lex->unit.select_limit_cnt=
HA_POS_ERROR;
lex->select_lex.select_limit= 0;
lex->unit.select_limit_cnt= HA_POS_ERROR;
lex->select_lex.table_list.save_and_clear(&lex->auxilliary_table_list);
lex->lock_option= using_update_log ? TL_READ_NO_INSERT : TL_READ;
lex->query_tables= 0;
@@ -6757,8 +6763,7 @@ bool multi_update_precheck(THD *thd, TABLE_LIST *tables)
if (select_lex->order_list.elements)
msg= "ORDER BY";
else if (select_lex->select_limit && select_lex->select_limit !=
HA_POS_ERROR)
else if (select_lex->select_limit)
msg= "LIMIT";
if (msg)
{