~drizzle-pbxt/drizzle/pbxt

« back to all changes in this revision

Viewing changes to drizzled/field/longstr.cc

  • Committer: Paul McCullagh
  • Date: 2009-05-27 10:53:19 UTC
  • mfrom: (1014.3.25 staging)
  • Revision ID: paul.mccullagh@primebase.org-20090527105319-yybeemx3chfwgpy8
Merged with Drizzle trunk

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
 
#include <drizzled/table.h>
26
 
#include <drizzled/session.h>
27
 
 
28
 
/*
29
 
  Check if we lost any important data and send a truncation error/warning
30
 
 
31
 
  SYNOPSIS
32
 
    Field_longstr::report_if_important_data()
33
 
    ptr                      - Truncated rest of string
34
 
    end                      - End of truncated string
35
 
 
36
 
  RETURN VALUES
37
 
    0   - None was truncated (or we don't count cut fields)
38
 
    2   - Some bytes was truncated
39
 
 
40
 
  NOTE
41
 
    Check if we lost any important data (anything in a binary string,
42
 
    or any non-space in others). If only trailing spaces was lost,
43
 
    send a truncation note, otherwise send a truncation error.
44
 
*/
45
 
 
46
 
int
47
 
Field_longstr::report_if_important_data(const char *field_ptr, const char *end)
48
 
{
49
 
  if ((field_ptr < end) && table->in_use->count_cuted_fields)
50
 
  {
51
 
    if (test_if_important_data(field_charset, field_ptr, end))
52
 
    {
53
 
      if (table->in_use->abort_on_warning)
54
 
        set_warning(DRIZZLE_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
55
 
      else
56
 
        set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
57
 
    }
58
 
    else /* If we lost only spaces then produce a NOTE, not a WARNING */
59
 
      set_warning(DRIZZLE_ERROR::WARN_LEVEL_NOTE, ER_WARN_DATA_TRUNCATED, 1);
60
 
    return 2;
61
 
  }
62
 
  return 0;
63
 
}
64
 
 
65
 
int Field_longstr::store_decimal(const my_decimal *d)
66
 
{
67
 
  char buff[DECIMAL_MAX_STR_LENGTH+1];
68
 
  String str(buff, sizeof(buff), &my_charset_bin);
69
 
  my_decimal2string(E_DEC_FATAL_ERROR, d, 0, 0, 0, &str);
70
 
  return store(str.ptr(), str.length(), str.charset());
71
 
}
72
 
 
73
 
uint32_t Field_longstr::max_data_length() const
74
 
{
75
 
  return field_length + (field_length > 255 ? 2 : 1);
76
 
}
77