~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

Merged vcol stuff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4141
4141
 
4142
4142
  if (field_ptr && *field_ptr)
4143
4143
  {
 
4144
    if ((*field_ptr)->vcol_info)
 
4145
    {
 
4146
      if (thd->mark_used_columns != MARK_COLUMNS_NONE)
 
4147
      {
 
4148
        Item *vcol_item= (*field_ptr)->vcol_info->expr_item;
 
4149
        assert(vcol_item);
 
4150
        vcol_item->walk(&Item::register_field_in_read_map, 1, (unsigned char *) 0);
 
4151
        /* 
 
4152
          Set the virtual field for write here if 
 
4153
          1) this procedure is called for a read-only operation (SELECT), and
 
4154
          2) the virtual column is not phycically stored in the table
 
4155
        */
 
4156
        if ((thd->mark_used_columns != MARK_COLUMNS_WRITE) && 
 
4157
            (not (*field_ptr)->is_stored))
 
4158
          bitmap_set_bit((*field_ptr)->table->write_set, (*field_ptr)->field_index);
 
4159
      }
 
4160
    }
4144
4161
    *cached_field_index_ptr= field_ptr - table->field;
4145
4162
    field= *field_ptr;
4146
4163
  }
5898
5915
      {
5899
5916
        /* Mark fields as used to allow storage engine to optimze access */
5900
5917
        bitmap_set_bit(field->table->read_set, field->field_index);
 
5918
        /*
 
5919
          Mark virtual fields for write and others that the virtual fields
 
5920
          depend on for read.
 
5921
        */
 
5922
        if (field->vcol_info)
 
5923
        {
 
5924
          Item *vcol_item= field->vcol_info->expr_item;
 
5925
          assert(vcol_item);
 
5926
          vcol_item->walk(&Item::register_field_in_read_map, 1, (unsigned char *) 0);
 
5927
          bitmap_set_bit(field->table->write_set, field->field_index);
 
5928
        }
5901
5929
        if (table)
5902
5930
        {
5903
5931
          table->covering_keys.intersect(field->part_of_key);
6076
6104
  Item *value, *fld;
6077
6105
  Item_field *field;
6078
6106
  Table *table= 0;
 
6107
  List<Table> tbl_list;
 
6108
  bool abort_on_warning_saved= thd->abort_on_warning;
 
6109
  tbl_list.empty();
6079
6110
 
6080
6111
  /*
6081
6112
    Reset the table->auto_increment_field_not_null as it is valid for
6109
6140
    table= rfield->table;
6110
6141
    if (rfield == table->next_number_field)
6111
6142
      table->auto_increment_field_not_null= true;
 
6143
    if (rfield->vcol_info && 
 
6144
        value->type() != Item::DEFAULT_VALUE_ITEM && 
 
6145
        value->type() != Item::NULL_ITEM &&
 
6146
        table->s->table_category != TABLE_CATEGORY_TEMPORARY)
 
6147
    {
 
6148
      thd->abort_on_warning= false;
 
6149
      push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
6150
                          ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN,
 
6151
                          ER(ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN),
 
6152
                          rfield->field_name, table->s->table_name.str);
 
6153
      thd->abort_on_warning= abort_on_warning_saved;
 
6154
    }
6112
6155
    if ((value->save_in_field(rfield, 0) < 0) && !ignore_errors)
6113
6156
    {
6114
6157
      my_message(ER_UNKNOWN_ERROR, ER(ER_UNKNOWN_ERROR), MYF(0));
6115
6158
      goto err;
6116
6159
    }
6117
 
  }
 
6160
    tbl_list.push_back(table);
 
6161
  }
 
6162
  /* Update virtual fields*/
 
6163
  thd->abort_on_warning= false;
 
6164
  if (tbl_list.head())
 
6165
  {
 
6166
    List_iterator_fast<Table> t(tbl_list);
 
6167
    Table *prev_table= 0;
 
6168
    while ((table= t++))
 
6169
    {
 
6170
      /*
 
6171
        Do simple optimization to prevent unnecessary re-generating 
 
6172
        values for virtual fields
 
6173
      */
 
6174
      if (table != prev_table)
 
6175
      {
 
6176
        prev_table= table;
 
6177
        if (table->vfield)
 
6178
        {
 
6179
          if (update_virtual_fields_marked_for_write(table, false))
 
6180
            goto err;
 
6181
        }
 
6182
      }
 
6183
    }
 
6184
  }
 
6185
  thd->abort_on_warning= abort_on_warning_saved;
6118
6186
  return(thd->is_error());
6119
6187
err:
 
6188
  thd->abort_on_warning= abort_on_warning_saved;
6120
6189
  if (table)
6121
6190
    table->auto_increment_field_not_null= false;
6122
6191
  return(true);
6150
6219
  List_iterator_fast<Item> v(values);
6151
6220
  Item *value;
6152
6221
  Table *table= 0;
6153
 
 
6154
6222
  Field *field;
 
6223
  List<Table> tbl_list;
 
6224
  bool abort_on_warning_saved= thd->abort_on_warning;
 
6225
  
 
6226
  tbl_list.empty();
6155
6227
  /*
6156
6228
    Reset the table->auto_increment_field_not_null as it is valid for
6157
6229
    only one row.
6171
6243
    table= field->table;
6172
6244
    if (field == table->next_number_field)
6173
6245
      table->auto_increment_field_not_null= true;
 
6246
    if (field->vcol_info && 
 
6247
        value->type() != Item::DEFAULT_VALUE_ITEM && 
 
6248
        value->type() != Item::NULL_ITEM &&
 
6249
        table->s->table_category != TABLE_CATEGORY_TEMPORARY)
 
6250
    {
 
6251
      thd->abort_on_warning= false;
 
6252
      push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
6253
                          ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN,
 
6254
                          ER(ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN),
 
6255
                          field->field_name, table->s->table_name.str);
 
6256
      thd->abort_on_warning= abort_on_warning_saved;
 
6257
    }
6174
6258
    if (value->save_in_field(field, 0) < 0)
6175
6259
      goto err;
6176
 
  }
 
6260
    tbl_list.push_back(table);
 
6261
  }
 
6262
  /* Update virtual fields*/
 
6263
  thd->abort_on_warning= false;
 
6264
  if (tbl_list.head())
 
6265
  {
 
6266
    List_iterator_fast<Table> t(tbl_list);
 
6267
    Table *prev_table= 0;
 
6268
    while ((table= t++))
 
6269
    {
 
6270
      /*
 
6271
        Do simple optimization to prevent unnecessary re-generating 
 
6272
        values for virtual fields
 
6273
      */
 
6274
      if (table != prev_table)
 
6275
      {
 
6276
        prev_table= table;
 
6277
        if (table->vfield)
 
6278
        {
 
6279
          if (update_virtual_fields_marked_for_write(table, false))
 
6280
          {
 
6281
            goto err;
 
6282
          }
 
6283
        }
 
6284
      }
 
6285
    }
 
6286
  }
 
6287
  thd->abort_on_warning= abort_on_warning_saved;
6177
6288
  return(thd->is_error());
6178
6289
 
6179
6290
err:
 
6291
  thd->abort_on_warning= abort_on_warning_saved;
6180
6292
  if (table)
6181
6293
    table->auto_increment_field_not_null= false;
6182
6294
  return(true);