~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sys_var.cc

  • Committer: Mark Atwood
  • Date: 2011-06-14 06:10:57 UTC
  • mfrom: (2318.2.19 rf)
  • Revision ID: me@mark.atwood.name-20110614061057-u08az4cidd4l7blm
mergeĀ lp:~olafvdspek/drizzle/refactor4

Show diffs side-by-side

added added

removed removed

Lines of Context:
114
114
static void fix_max_join_size(Session *session, sql_var_t type);
115
115
static void fix_session_mem_root(Session *session, sql_var_t type);
116
116
static void fix_server_id(Session *session, sql_var_t type);
117
 
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
118
 
                          const std::string &name, int64_t val);
 
117
void throw_bounds_warning(Session *session, bool fixed, bool unsignd, const std::string &name, int64_t val);
119
118
static unsigned char *get_error_count(Session *session);
120
119
static unsigned char *get_warning_count(Session *session);
121
120
static unsigned char *get_tmpdir(Session *session);
437
436
}
438
437
 
439
438
 
440
 
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
441
 
                          const std::string &name, int64_t val)
 
439
void throw_bounds_warning(Session *session, bool fixed, bool unsignd, const std::string &name, int64_t val)
442
440
{
443
 
  if (fixed)
444
 
  {
445
 
    char buf[DECIMAL_LONGLONG_DIGITS];
446
 
 
447
 
    if (unsignd)
448
 
      internal::ullstr((uint64_t) val, buf);
449
 
    else
450
 
      internal::llstr(val, buf);
451
 
 
452
 
    push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
453
 
                        ER_TRUNCATED_WRONG_VALUE,
454
 
                        ER(ER_TRUNCATED_WRONG_VALUE), name.c_str(), buf);
455
 
  }
456
 
  return false;
 
441
  if (not fixed)
 
442
    return;
 
443
  char buf[DECIMAL_LONGLONG_DIGITS];
 
444
 
 
445
  if (unsignd)
 
446
    internal::ullstr((uint64_t) val, buf);
 
447
  else
 
448
    internal::llstr(val, buf);
 
449
 
 
450
  push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
451
    ER_TRUNCATED_WRONG_VALUE, ER(ER_TRUNCATED_WRONG_VALUE), name.c_str(), buf);
457
452
}
458
453
 
459
 
uint64_t fix_unsigned(Session *session, uint64_t num,
460
 
                              const struct option *option_limits)
 
454
uint64_t fix_unsigned(Session *session, uint64_t num, const option& option_limits)
461
455
{
462
456
  bool fixed= false;
463
457
  uint64_t out= getopt_ull_limit_value(num, option_limits, &fixed);
464
458
 
465
 
  throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
 
459
  throw_bounds_warning(session, fixed, true, option_limits.name, (int64_t) num);
466
460
  return out;
467
461
}
468
462
 
469
463
 
470
 
static size_t fix_size_t(Session *session, size_t num,
471
 
                           const struct option *option_limits)
 
464
static size_t fix_size_t(Session *session, size_t num, const option& option_limits)
472
465
{
473
466
  bool fixed= false;
474
467
  size_t out= (size_t)getopt_ull_limit_value(num, option_limits, &fixed);
475
468
 
476
 
  throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
 
469
  throw_bounds_warning(session, fixed, true, option_limits.name, (int64_t) num);
477
470
  return out;
478
471
}
479
472
 
490
483
 
491
484
  if (option_limits)
492
485
  {
493
 
    uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, option_limits);
494
 
    if(static_cast<uint64_t>(newvalue) == tmp)
 
486
    uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, *option_limits);
 
487
    if (static_cast<uint64_t>(newvalue) == tmp)
495
488
      *value= newvalue;
496
489
  }
497
490
  else
507
500
{
508
501
  bool not_used;
509
502
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
510
 
  *value= (uint32_t)getopt_ull_limit_value((uint32_t) option_limits->def_value,
511
 
                                           option_limits, &not_used);
 
503
  *value= (uint32_t)getopt_ull_limit_value((uint32_t) option_limits->def_value, *option_limits, &not_used);
512
504
}
513
505
 
514
506
 
519
511
 
520
512
  if (option_limits)
521
513
  {
522
 
    uint64_t newvalue= fix_unsigned(session, tmp, option_limits);
523
 
    if(newvalue==tmp)
 
514
    uint64_t newvalue= fix_unsigned(session, tmp, *option_limits);
 
515
    if (newvalue==tmp)
524
516
      *value= newvalue;
525
517
  }
526
518
  else
542
534
  {
543
535
    bool not_used;
544
536
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
545
 
    *value= getopt_ull_limit_value((uint64_t) option_limits->def_value,
546
 
                                   option_limits, &not_used);
 
537
    *value= getopt_ull_limit_value((uint64_t) option_limits->def_value, *option_limits, &not_used);
547
538
  }
548
539
}
549
540
 
555
546
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
556
547
 
557
548
  if (option_limits)
558
 
    *value= fix_size_t(session, tmp, option_limits);
 
549
    *value= fix_size_t(session, tmp, *option_limits);
559
550
  else
560
551
    *value= tmp;
561
552
 
567
558
{
568
559
  bool not_used;
569
560
  boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
570
 
  *value= (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
571
 
                                         option_limits, &not_used);
 
561
  *value= (size_t)getopt_ull_limit_value((size_t) option_limits->def_value, *option_limits, &not_used);
572
562
}
573
563
 
574
564
bool sys_var_bool_ptr::check(Session *session, set_var *var)
610
600
  }
611
601
 
612
602
  if (option_limits)
613
 
    tmp= (uint32_t) fix_unsigned(session, tmp, option_limits);
 
603
    tmp= (uint32_t) fix_unsigned(session, tmp, *option_limits);
614
604
  else if (tmp > UINT32_MAX)
615
605
  {
616
606
    tmp= UINT32_MAX;
633
623
     bool not_used;
634
624
     /* We will not come here if option_limits is not set */
635
625
     global_system_variables.*offset=
636
 
       (uint32_t) getopt_ull_limit_value((uint32_t) option_limits->def_value,
637
 
                                      option_limits, &not_used);
 
626
       (uint32_t) getopt_ull_limit_value((uint32_t) option_limits->def_value, *option_limits, &not_used);
638
627
   }
639
628
   else
640
629
     session->variables.*offset= global_system_variables.*offset;
660
649
    tmp= max_system_variables.*offset;
661
650
 
662
651
  if (option_limits)
663
 
    tmp= (ha_rows) fix_unsigned(session, tmp, option_limits);
 
652
    tmp= (ha_rows) fix_unsigned(session, tmp, *option_limits);
664
653
  if (var->type == OPT_GLOBAL)
665
654
  {
666
655
    /* Lock is needed to make things safe on 32 bit systems */
684
673
    /* We will not come here if option_limits is not set */
685
674
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
686
675
    global_system_variables.*offset=
687
 
      (ha_rows) getopt_ull_limit_value((ha_rows) option_limits->def_value,
688
 
                                       option_limits, &not_used);
 
676
      (ha_rows) getopt_ull_limit_value((ha_rows) option_limits->def_value, *option_limits, &not_used);
689
677
  }
690
678
  else
691
679
  {
720
708
  }
721
709
 
722
710
  if (option_limits)
723
 
    tmp= fix_unsigned(session, tmp, option_limits);
 
711
    tmp= fix_unsigned(session, tmp, *option_limits);
724
712
  if (var->type == OPT_GLOBAL)
725
713
  {
726
714
    /* Lock is needed to make things safe on 32 bit systems */
743
731
    bool not_used;
744
732
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
745
733
    global_system_variables.*offset=
746
 
      getopt_ull_limit_value((uint64_t) option_limits->def_value,
747
 
                             option_limits, &not_used);
 
734
      getopt_ull_limit_value((uint64_t) option_limits->def_value, *option_limits, &not_used);
748
735
  }
749
736
  else
750
737
  {
776
763
    tmp= max_system_variables.*offset;
777
764
 
778
765
  if (option_limits)
779
 
    tmp= fix_size_t(session, tmp, option_limits);
 
766
    tmp= fix_size_t(session, tmp, *option_limits);
780
767
  if (var->type == OPT_GLOBAL)
781
768
  {
782
769
    /* Lock is needed to make things safe on 32 bit systems */
799
786
    bool not_used;
800
787
    boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
801
788
    global_system_variables.*offset=
802
 
      (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
803
 
                                     option_limits, &not_used);
 
789
      (size_t)getopt_ull_limit_value((size_t) option_limits->def_value, *option_limits, &not_used);
804
790
  }
805
791
  else
806
792
  {
1387
1373
    ptr         pointer to option structure
1388
1374
*/
1389
1375
 
1390
 
static struct option *find_option(struct option *opt, const char *name)
 
1376
static option* find_option(struct option *opt, const char *name)
1391
1377
{
1392
 
  uint32_t length=strlen(name);
 
1378
  uint32_t length= strlen(name);
1393
1379
  for (; opt->name; opt++)
1394
1380
  {
1395
 
    if (!getopt_compare_strings(opt->name, name, length) &&
1396
 
        !opt->name[length])
 
1381
    if (!getopt_compare_strings(opt->name, name, length) && !opt->name[length])
1397
1382
    {
1398
1383
      /*
1399
 
        Only accept the option if one can set values through it.
1400
 
        If not, there is no default value or limits in the option.
 
1384
      Only accept the option if one can set values through it.
 
1385
      If not, there is no default value or limits in the option.
1401
1386
      */
1402
 
      return (opt->value) ? opt : 0;
 
1387
      return opt->value ? opt : NULL;
1403
1388
    }
1404
1389
  }
1405
 
  return 0;
 
1390
  return NULL;
1406
1391
}
1407
1392
 
1408
1393