1
/* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 MySQL
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.
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.
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
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>
29
Check if we lost any important data and send a truncation error/warning
32
Field_longstr::report_if_important_data()
33
ptr - Truncated rest of string
34
end - End of truncated string
37
0 - None was truncated (or we don't count cut fields)
38
2 - Some bytes was truncated
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.
47
Field_longstr::report_if_important_data(const char *field_ptr, const char *end)
49
if ((field_ptr < end) && table->in_use->count_cuted_fields)
51
if (test_if_important_data(field_charset, field_ptr, end))
53
if (table->in_use->abort_on_warning)
54
set_warning(DRIZZLE_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
56
set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED, 1);
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);
65
int Field_longstr::store_decimal(const my_decimal *d)
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());
73
uint32_t Field_longstr::max_data_length() const
75
return field_length + (field_length > 255 ? 2 : 1);