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

« back to all changes in this revision

Viewing changes to sql/item_create.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
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 
16
*/
15
17
 
16
18
/**
17
19
  @file
5051
5053
                 CHARSET_INFO *cs)
5052
5054
{
5053
5055
  Item *UNINIT_VAR(res);
5054
 
  ulong len;
5055
 
  uint dec;
5056
5056
 
5057
5057
  switch (cast_type) {
5058
5058
  case ITEM_CAST_BINARY:
5075
5075
    break;
5076
5076
  case ITEM_CAST_DECIMAL:
5077
5077
  {
5078
 
    if (c_len == NULL)
5079
 
    {
5080
 
      len= 0;
5081
 
    }
5082
 
    else
 
5078
    ulong len= 0;
 
5079
    uint dec= 0;
 
5080
 
 
5081
    if (c_len)
5083
5082
    {
5084
5083
      ulong decoded_size;
5085
5084
      errno= 0;
5086
5085
      decoded_size= strtoul(c_len, NULL, 10);
5087
5086
      if (errno != 0)
5088
5087
      {
5089
 
        my_error(ER_TOO_BIG_PRECISION, MYF(0), c_len, a->name,
5090
 
                 DECIMAL_MAX_PRECISION);
 
5088
        my_error(ER_TOO_BIG_PRECISION, MYF(0), INT_MAX, a->name,
 
5089
                 static_cast<ulong>(DECIMAL_MAX_PRECISION));
5091
5090
        return NULL;
5092
5091
      }
5093
5092
      len= decoded_size;
5094
5093
    }
5095
5094
 
5096
 
    if (c_dec == NULL)
5097
 
    {
5098
 
      dec= 0;
5099
 
    }
5100
 
    else
 
5095
    if (c_dec)
5101
5096
    {
5102
5097
      ulong decoded_size;
5103
5098
      errno= 0;
5104
5099
      decoded_size= strtoul(c_dec, NULL, 10);
5105
5100
      if ((errno != 0) || (decoded_size > UINT_MAX))
5106
5101
      {
5107
 
        my_error(ER_TOO_BIG_SCALE, MYF(0), c_dec, a->name,
5108
 
                 DECIMAL_MAX_SCALE);
 
5102
        my_error(ER_TOO_BIG_SCALE, MYF(0), INT_MAX, a->name,
 
5103
                 static_cast<ulong>(DECIMAL_MAX_SCALE));
5109
5104
        return NULL;
5110
5105
      }
5111
5106
      dec= decoded_size;
5118
5113
    }
5119
5114
    if (len > DECIMAL_MAX_PRECISION)
5120
5115
    {
5121
 
      my_error(ER_TOO_BIG_PRECISION, MYF(0), len, a->name,
5122
 
               DECIMAL_MAX_PRECISION);
 
5116
      my_error(ER_TOO_BIG_PRECISION, MYF(0), static_cast<int>(len), a->name,
 
5117
               static_cast<ulong>(DECIMAL_MAX_PRECISION));
5123
5118
      return 0;
5124
5119
    }
5125
5120
    if (dec > DECIMAL_MAX_SCALE)
5126
5121
    {
5127
5122
      my_error(ER_TOO_BIG_SCALE, MYF(0), dec, a->name,
5128
 
               DECIMAL_MAX_SCALE);
 
5123
               static_cast<ulong>(DECIMAL_MAX_SCALE));
5129
5124
      return 0;
5130
5125
    }
5131
5126
    res= new (thd->mem_root) Item_decimal_typecast(a, len, dec);
5133
5128
  }
5134
5129
  case ITEM_CAST_CHAR:
5135
5130
  {
 
5131
    int len= -1;
5136
5132
    CHARSET_INFO *real_cs= (cs ? cs : thd->variables.collation_connection);
5137
 
    if (c_len == NULL)
5138
 
    {
5139
 
      len= LL(-1);
5140
 
    }
5141
 
    else
 
5133
    if (c_len)
5142
5134
    {
5143
5135
      ulong decoded_size;
5144
5136
      errno= 0;
5148
5140
        my_error(ER_TOO_BIG_DISPLAYWIDTH, MYF(0), "cast as char", MAX_FIELD_BLOBLENGTH);
5149
5141
        return NULL;
5150
5142
      }
5151
 
      len= decoded_size;
 
5143
      len= (int) decoded_size;
5152
5144
    }
5153
5145
    res= new (thd->mem_root) Item_char_typecast(a, len, real_cs);
5154
5146
    break;