~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/field.cc

  • Committer: lbieber at stabletransit
  • Date: 2010-10-19 14:03:27 UTC
  • mfrom: (1861.1.2 build)
  • Revision ID: lbieber@drizzle-build-n02.wc1.dfw1.stabletransit.com-20101019140327-2jvt5j2wi4pzhm1z
Merge Brian - Small collection of cleanups/refactor'ing around locks
Merge Monty - fix a few things in the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
111
111
{
112
112
  Table *table= (Table *) arg;
113
113
  if (field->getTable() == table || !table)
114
 
    field->getTable()->setReadSet(field->position());
 
114
    field->getTable()->setReadSet(field->field_index);
115
115
 
116
116
  return 0;
117
117
}
165
165
   have_privileges(0),
166
166
   any_privileges(0)
167
167
{
168
 
  Select_Lex *select= getSession().getLex()->current_select;
 
168
  Select_Lex *select= current_session->lex->current_select;
169
169
  collation.set(DERIVATION_IMPLICIT);
170
170
 
171
171
  if (select && select->parsing_place != IN_HAVING)
246
246
}
247
247
 
248
248
 
249
 
type::Decimal *Item_field::val_decimal(type::Decimal *decimal_value)
 
249
my_decimal *Item_field::val_decimal(my_decimal *decimal_value)
250
250
{
251
251
  if ((null_value= field->is_null()))
252
252
    return 0;
262
262
  return result_field->val_str(str,&str_value);
263
263
}
264
264
 
265
 
bool Item_field::get_date(type::Time &ltime,uint32_t fuzzydate)
 
265
bool Item_field::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
266
266
{
267
267
  if ((null_value=field->is_null()) || field->get_date(ltime,fuzzydate))
268
268
  {
269
 
    ltime.reset();
 
269
    memset(ltime, 0, sizeof(*ltime));
270
270
    return 1;
271
271
  }
272
272
  return 0;
273
273
}
274
274
 
275
 
bool Item_field::get_date_result(type::Time &ltime,uint32_t fuzzydate)
 
275
bool Item_field::get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
276
276
{
277
277
  if ((null_value=result_field->is_null()) ||
278
278
      result_field->get_date(ltime,fuzzydate))
279
279
  {
280
 
    ltime.reset();
 
280
    memset(ltime, 0, sizeof(*ltime));
281
281
    return 1;
282
282
  }
283
283
  return 0;
284
284
}
285
285
 
286
 
bool Item_field::get_time(type::Time &ltime)
 
286
bool Item_field::get_time(DRIZZLE_TIME *ltime)
287
287
{
288
288
  if ((null_value=field->is_null()) || field->get_time(ltime))
289
289
  {
290
 
    ltime.reset();
 
290
    memset(ltime, 0, sizeof(*ltime));
291
291
    return 1;
292
292
  }
293
293
  return 0;
308
308
}
309
309
 
310
310
 
311
 
type::Decimal *Item_field::val_decimal_result(type::Decimal *decimal_value)
 
311
my_decimal *Item_field::val_decimal_result(my_decimal *decimal_value)
312
312
{
313
313
  if ((null_value= result_field->is_null()))
314
314
    return 0;
319
319
bool Item_field::val_bool_result()
320
320
{
321
321
  if ((null_value= result_field->is_null()))
322
 
  {
323
322
    return false;
324
 
  }
325
 
 
326
323
  switch (result_field->result_type()) {
327
324
  case INT_RESULT:
328
325
    return result_field->val_int() != 0;
329
 
 
330
326
  case DECIMAL_RESULT:
331
 
    {
332
 
      type::Decimal decimal_value;
333
 
      type::Decimal *val= result_field->val_decimal(&decimal_value);
334
 
      if (val)
335
 
        return not val->isZero();
336
 
      return 0;
337
 
    }
338
 
 
 
327
  {
 
328
    my_decimal decimal_value;
 
329
    my_decimal *val= result_field->val_decimal(&decimal_value);
 
330
    if (val)
 
331
      return !my_decimal_is_zero(val);
 
332
    return 0;
 
333
  }
339
334
  case REAL_RESULT:
340
335
  case STRING_RESULT:
341
336
    return result_field->val_real() != 0.0;
342
 
 
343
337
  case ROW_RESULT:
 
338
  default:
344
339
    assert(0);
345
340
    return 0;                                   // Shut up compiler
346
341
  }
347
 
 
348
 
  assert(0);
349
 
  return 0;                                   // Shut up compiler
350
342
}
351
343
 
352
344
 
369
361
    (In cases where we would choose wrong we would have to generate a
370
362
    ER_NON_UNIQ_ERROR).
371
363
  */
372
 
  return (not my_strcasecmp(system_charset_info, item_field->name, field_name) &&
373
 
          (not item_field->table_name || not table_name ||
374
 
           (not my_strcasecmp(table_alias_charset, item_field->table_name, table_name) &&
375
 
            (not item_field->db_name || not db_name ||
376
 
             (item_field->db_name && not my_strcasecmp(system_charset_info, item_field->db_name, db_name))))));
 
364
  return (!my_strcasecmp(system_charset_info, item_field->name,
 
365
                         field_name) &&
 
366
          (!item_field->table_name || !table_name ||
 
367
           (!my_strcasecmp(table_alias_charset, item_field->table_name,
 
368
                           table_name) &&
 
369
            (!item_field->db_name || !db_name ||
 
370
             (item_field->db_name && !strcasecmp(item_field->db_name,
 
371
                                             db_name))))));
377
372
}
378
373
 
379
374
 
380
375
table_map Item_field::used_tables() const
381
376
{
382
377
  if (field->getTable()->const_table)
383
 
  {
384
378
    return 0;                                   // const item
385
 
  }
386
 
 
387
379
  return (depended_from ? OUTER_REF_TABLE_BIT : field->getTable()->map);
388
380
}
389
381
 
541
533
        if (*from_field != view_ref_found)
542
534
        {
543
535
          prev_subselect_item->used_tables_cache|= (*from_field)->getTable()->map;
544
 
          prev_subselect_item->const_item_cache= false;
 
536
          prev_subselect_item->const_item_cache= 0;
545
537
          set_field(*from_field);
546
538
          if (!last_checked_context->select_lex->having_fix_field &&
547
539
              select->group_list.elements &&
629
621
      case it does not matter which used tables bits we set)
630
622
    */
631
623
    prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
632
 
    prev_subselect_item->const_item_cache= false;
 
624
    prev_subselect_item->const_item_cache= 0;
633
625
  }
634
626
 
635
627
  assert(ref != 0);
640
632
    if (upward_lookup)
641
633
    {
642
634
      // We can't say exactly what absent table or field
643
 
      my_error(ER_BAD_FIELD_ERROR, MYF(0), full_name(), session->where());
 
635
      my_error(ER_BAD_FIELD_ERROR, MYF(0), full_name(), session->where);
644
636
    }
645
637
    else
646
638
    {
707
699
    {
708
700
      Item_ref *rf;
709
701
      rf= new Item_ref(context,
710
 
                       (cached_table->getSchemaName()[0] ? cached_table->getSchemaName() : 0),
 
702
                       (cached_table->db[0] ? cached_table->db : 0),
711
703
                       (char*) cached_table->alias, (char*) field_name);
712
704
      if (!rf)
713
705
        return -1;
824
816
            {
825
817
              /* The column to which we link isn't valid. */
826
818
              my_error(ER_BAD_FIELD_ERROR, MYF(0), (*res)->name,
827
 
                       session->where());
 
819
                       current_session->where);
828
820
              return(1);
829
821
            }
830
822
 
910
902
      current_bitmap= table->write_set;
911
903
      other_bitmap=   table->read_set;
912
904
    }
913
 
    //if (! current_bitmap->testAndSet(field->position()))
914
 
    if (! current_bitmap->test(field->position()))
 
905
    //if (! current_bitmap->testAndSet(field->field_index))
 
906
    if (! current_bitmap->test(field->field_index))
915
907
    {
916
 
      if (! other_bitmap->test(field->position()))
 
908
      if (! other_bitmap->test(field->field_index))
917
909
      {
918
910
        /* First usage of column */
919
911
        table->used_fields++;                     // Used to optimize loops
1271
1263
  {
1272
1264
    char buff[MAX_FIELD_WIDTH];
1273
1265
    String tmp(buff,sizeof(buff),str->charset());
1274
 
    field->val_str_internal(&tmp);
 
1266
    field->val_str(&tmp);
1275
1267
    if (field->is_null())  {
1276
1268
      str->append("NULL");
1277
1269
    }