~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/longstr.cc

  • Committer: Monty Taylor
  • Date: 2008-11-16 20:15:33 UTC
  • mto: (584.1.9 devel)
  • mto: This revision was merged to the branch mainline in revision 589.
  • Revision ID: monty@inaugust.com-20081116201533-d0f19s1bk1h95iyw
Removed a big bank of includes from item.h.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 MySQL
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 */
 
20
 
 
21
 
 
22
#include <drizzled/server_includes.h>
 
23
#include <drizzled/field/longstr.h>
 
24
#include <drizzled/error.h>
 
25
 
 
26
/*
 
27
  Check if we lost any important data and send a truncation error/warning
 
28
 
 
29
  SYNOPSIS
 
30
    Field_longstr::report_if_important_data()
 
31
    ptr                      - Truncated rest of string
 
32
    end                      - End of truncated string
 
33
 
 
34
  RETURN VALUES
 
35
    0   - None was truncated (or we don't count cut fields)
 
36
    2   - Some bytes was truncated
 
37
 
 
38
  NOTE
 
39
    Check if we lost any important data (anything in a binary string,
 
40
    or any non-space in others). If only trailing spaces was lost,
 
41
    send a truncation note, otherwise send a truncation error.
 
42
*/
 
43
 
 
44
int
 
45
Field_longstr::report_if_important_data(const char *ptr, const char *end)
 
46
{
 
47
  if ((ptr < end) && table->in_use->count_cuted_fields)
 
48
  {
 
49
    if (test_if_important_data(field_charset, ptr, end))
 
50
    {
 
51
      if (table->in_use->abort_on_warning)
 
52
        set_warning(DRIZZLE_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
 
53
      else
 
54
        set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
 
55
    }
 
56
    else /* If we lost only spaces then produce a NOTE, not a WARNING */
 
57
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_NOTE, ER_WARN_DATA_TRUNCATED, 1);
 
58
    return 2;
 
59
  }
 
60
  return 0;
 
61
}
 
62
 
 
63
int Field_longstr::store_decimal(const my_decimal *d)
 
64
{
 
65
  char buff[DECIMAL_MAX_STR_LENGTH+1];
 
66
  String str(buff, sizeof(buff), &my_charset_bin);
 
67
  my_decimal2string(E_DEC_FATAL_ERROR, d, 0, 0, 0, &str);
 
68
  return store(str.ptr(), str.length(), str.charset());
 
69
}
 
70
 
 
71
uint32_t Field_longstr::max_data_length() const
 
72
{
 
73
  return field_length + (field_length > 255 ? 2 : 1);
 
74
}
 
75