| 126 | */ |
| 127 | |
| 128 | static bool check_view_single_update(List<Item> &fields, List<Item> *values, |
| 129 | TABLE_LIST *view, table_map *map, |
| 130 | bool insert) |
| 131 | { |
| 132 | /* it is join view => we need to find the table for update */ |
| 133 | List_iterator_fast<Item> it(fields); |
| 134 | Item *item; |
| 135 | TABLE_LIST *tbl= 0; // reset for call to check_single_table() |
| 136 | table_map tables= 0; |
| 137 | |
| 138 | while ((item= it++)) |
| 139 | tables|= item->used_tables(); |
| 140 | |
| 141 | /* |
| 142 | Check that table is only one |
| 143 | (we can not rely on check_single_table because it skips some |
| 144 | types of tables) |
| 145 | */ |
| 146 | if (my_count_bits(tables) > 1) |
| 147 | goto error; |
| 148 | |
| 149 | if (values) |
| 150 | { |
| 151 | it.init(*values); |
| 152 | while ((item= it++)) |
| 153 | tables|= item->view_used_tables(view); |
| 154 | } |
| 155 | |
| 156 | /* Convert to real table bits */ |
| 157 | tables&= ~PSEUDO_TABLE_BITS; |
| 158 | |
| 159 | /* Check found map against provided map */ |
| 160 | if (*map) |
| 161 | { |
| 162 | if (tables != *map) |
| 163 | goto error; |
| 164 | return FALSE; |
| 165 | } |
| 166 | |
| 167 | if (view->check_single_table(&tbl, tables, view) || tbl == 0) |
| 168 | goto error; |
| 169 | |
| 170 | /* view->table should have been set in mysql_derived_merge_for_insert */ |
| 171 | DBUG_ASSERT(view->table); |
| 172 | |
| 173 | /* |
| 174 | Use buffer for the insert values that was allocated for the merged view. |
| 175 | */ |
| 176 | tbl->table->insert_values= view->table->insert_values; |
| 177 | view->table= tbl->table; |
| 178 | if (!tbl->single_table_updatable()) |
| 179 | { |
| 180 | if (insert) |
| 181 | my_error(ER_NON_INSERTABLE_TABLE, MYF(0), view->alias.str, "INSERT"); |
| 182 | else |
| 183 | my_error(ER_NON_UPDATABLE_TABLE, MYF(0), view->alias.str, "UPDATE"); |
| 184 | return TRUE; |
| 185 | } |
no test coverage detected