~ubuntu-branches/ubuntu/maverick/mysql-5.1/maverick-proposed

« back to all changes in this revision

Viewing changes to sql/field.cc

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 14:16:05 UTC
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: package-import@ubuntu.com-20120222141605-nxlu9yzc6attylc2
Tags: upstream-5.1.61
ImportĀ upstreamĀ versionĀ 5.1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved.
 
1
/*
 
2
   Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
2
3
 
3
4
   This program is free software; you can redistribute it and/or modify
4
5
   it under the terms of the GNU General Public License as published by
11
12
 
12
13
   You should have received a copy of the GNU General Public License
13
14
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
 
 
 
15
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 
16
*/
16
17
 
17
18
/**
18
19
  @file
1535
1536
  }
1536
1537
  else
1537
1538
    field->org_table_name= field->db_name= "";
1538
 
  if (orig_table)
 
1539
  if (orig_table && orig_table->alias)
1539
1540
  {
1540
1541
    field->table_name= orig_table->alias;
1541
1542
    field->org_col_name= field_name;
2277
2278
  snprintf(buff,sizeof(buff)-1, "%.*f",(int) dec,nr);
2278
2279
  length= strlen(buff);
2279
2280
#else
2280
 
  length= my_sprintf(buff,(buff,"%.*f",dec,nr));
 
2281
  length= sprintf(buff, "%.*f", dec, nr);
2281
2282
#endif
2282
2283
 
2283
2284
  if (length > field_length)
2583
2584
  DBUG_ENTER("Field_new_decimal::store_value");
2584
2585
#ifndef DBUG_OFF
2585
2586
  {
2586
 
    char dbug_buff[DECIMAL_MAX_STR_LENGTH+1];
 
2587
    char dbug_buff[DECIMAL_MAX_STR_LENGTH+2];
2587
2588
    DBUG_PRINT("enter", ("value: %s", dbug_decimal_as_string(dbug_buff, decimal_value)));
2588
2589
  }
2589
2590
#endif
2598
2599
  }
2599
2600
#ifndef DBUG_OFF
2600
2601
  {
2601
 
    char dbug_buff[DECIMAL_MAX_STR_LENGTH+1];
 
2602
    char dbug_buff[DECIMAL_MAX_STR_LENGTH+2];
2602
2603
    DBUG_PRINT("info", ("saving with precision %d  scale: %d  value %s",
2603
2604
                        (int)precision, (int)dec,
2604
2605
                        dbug_decimal_as_string(dbug_buff, decimal_value)));
2673
2674
  }
2674
2675
 
2675
2676
#ifndef DBUG_OFF
2676
 
  char dbug_buff[DECIMAL_MAX_STR_LENGTH+1];
 
2677
  char dbug_buff[DECIMAL_MAX_STR_LENGTH+2];
2677
2678
  DBUG_PRINT("enter", ("value: %s",
2678
2679
                       dbug_decimal_as_string(dbug_buff, &decimal_value)));
2679
2680
#endif
4259
4260
    snprintf(to,to_length-1,"%.*f",dec,nr);
4260
4261
    to=strend(to);
4261
4262
#else
4262
 
    to+= my_sprintf(to,(to,"%.*f",dec,nr));
 
4263
    to+= sprintf(to, "%.*f", dec, nr);
4263
4264
#endif
4264
4265
#endif
4265
4266
  }
4561
4562
#endif
4562
4563
    doubleget(nr,ptr);
4563
4564
 
4564
 
  uint to_length=max(field_length, DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE);
 
4565
  uint to_length= DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE;
4565
4566
  val_buffer->alloc(to_length);
4566
4567
  char *to=(char*) val_buffer->ptr();
4567
4568
 
4617
4618
    snprintf(to,to_length-1,"%.*f",dec,nr);
4618
4619
    to=strend(to);
4619
4620
#else
4620
 
    to+= my_sprintf(to,(to,"%.*f",dec,nr));
 
4621
    to+= sprintf(to, "%.*f", dec, nr);
4621
4622
#endif
4622
4623
#endif
4623
4624
  }
5467
5468
longlong Field_year::val_int(void)
5468
5469
{
5469
5470
  ASSERT_COLUMN_MARKED_FOR_READ;
 
5471
  DBUG_ASSERT(field_length == 2 || field_length == 4);
5470
5472
  int tmp= (int) ptr[0];
5471
5473
  if (field_length != 4)
5472
5474
    tmp%=100;                                   // Return last 2 char
5479
5481
String *Field_year::val_str(String *val_buffer,
5480
5482
                            String *val_ptr __attribute__((unused)))
5481
5483
{
 
5484
  DBUG_ASSERT(field_length < 5);
5482
5485
  val_buffer->alloc(5);
5483
5486
  val_buffer->length(field_length);
5484
5487
  char *to=(char*) val_buffer->ptr();
5541
5544
int Field_date::store(double nr)
5542
5545
{
5543
5546
  longlong tmp;
5544
 
  int error= 0;
5545
5547
  if (nr >= 19000000000000.0 && nr <= 99991231235959.0)
5546
5548
    nr=floor(nr/1000000.0);                     // Timestamp to date
5547
5549
  if (nr < 0.0 || nr > 99991231.0)
5550
5552
    set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
5551
5553
                         ER_WARN_DATA_OUT_OF_RANGE,
5552
5554
                         nr, MYSQL_TIMESTAMP_DATE);
5553
 
    error= 1;
5554
5555
  }
5555
5556
  else
5556
5557
    tmp= (longlong) rint(nr);
6461
6462
  /* Limit precision to DBL_DIG to avoid garbage past significant digits */
6462
6463
  set_if_smaller(digits, DBL_DIG);
6463
6464
  
6464
 
  length= (uint) my_sprintf(buff, (buff, "%-.*g", digits, nr));
 
6465
  length= (uint) sprintf(buff, "%-.*g", digits, nr);
6465
6466
 
6466
6467
#ifdef __WIN__
6467
6468
  /*
8691
8692
{
8692
8693
  ASSERT_COLUMN_MARKED_FOR_WRITE;
8693
8694
  int error= 0;
8694
 
  ulonglong max_nr= set_bits(ulonglong, typelib->count);
 
8695
  ulonglong max_nr;
 
8696
 
 
8697
  if (sizeof(ulonglong)*8 <= typelib->count)
 
8698
    max_nr= ULONGLONG_MAX;
 
8699
  else
 
8700
    max_nr= (ULL(1) << typelib->count) - 1;
 
8701
 
8695
8702
  if ((ulonglong) nr > max_nr)
8696
8703
  {
8697
8704
    nr&= max_nr;
9472
9479
  case MYSQL_TYPE_MEDIUM_BLOB:
9473
9480
  case MYSQL_TYPE_LONG_BLOB:
9474
9481
  case MYSQL_TYPE_BLOB:
 
9482
  case MYSQL_TYPE_GEOMETRY:
9475
9483
  case MYSQL_TYPE_VAR_STRING:
9476
9484
  case MYSQL_TYPE_STRING:
9477
9485
  case MYSQL_TYPE_VARCHAR:
9578
9586
  if (decimals >= NOT_FIXED_DEC)
9579
9587
  {
9580
9588
    my_error(ER_TOO_BIG_SCALE, MYF(0), decimals, fld_name,
9581
 
             NOT_FIXED_DEC-1);
 
9589
             static_cast<ulong>(NOT_FIXED_DEC - 1));
9582
9590
    DBUG_RETURN(TRUE);
9583
9591
  }
9584
9592
 
9648
9656
    my_decimal_trim(&length, &decimals);
9649
9657
    if (length > DECIMAL_MAX_PRECISION)
9650
9658
    {
9651
 
      my_error(ER_TOO_BIG_PRECISION, MYF(0), length, fld_name,
9652
 
               DECIMAL_MAX_PRECISION);
 
9659
      my_error(ER_TOO_BIG_PRECISION, MYF(0), static_cast<int>(length),
 
9660
               fld_name, static_cast<ulong>(DECIMAL_MAX_PRECISION));
9653
9661
      DBUG_RETURN(TRUE);
9654
9662
    }
9655
9663
    if (length < decimals)
9874
9882
      if (length > MAX_BIT_FIELD_LENGTH)
9875
9883
      {
9876
9884
        my_error(ER_TOO_BIG_DISPLAYWIDTH, MYF(0), fld_name,
9877
 
                 MAX_BIT_FIELD_LENGTH);
 
9885
                 static_cast<ulong>(MAX_BIT_FIELD_LENGTH));
9878
9886
        DBUG_RETURN(TRUE);
9879
9887
      }
9880
9888
      pack_length= (length + 7) / 8;
10413
10421
  {
10414
10422
    /* DBL_DIG is enough to print '-[digits].E+###' */
10415
10423
    char str_nr[DBL_DIG + 8];
10416
 
    uint str_len= my_sprintf(str_nr, (str_nr, "%g", nr));
 
10424
    uint str_len= sprintf(str_nr, "%g", nr);
10417
10425
    make_truncated_value_warning(thd, level, str_nr, str_len, ts_type,
10418
10426
                                 field_name);
10419
10427
  }