1/* -*- c-basic-offset: 2 -*- */
2/*
3 Copyright(C) 2016 Kouhei Sutou <kou@clear-code.com>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19
20#include <mrn_mysql.h>
21#include <mrn_mysql_compat.h>
22
23#include "mrn_column_name.hpp"
24
25#include <strfunc.h>
26
27#include <string.h>
28
29// for debug
30#define MRN_CLASS_NAME "mrn::ColumnName"
31
32namespace mrn {
33 ColumnName::ColumnName(const char *mysql_name)
34 : mysql_name_(mysql_name) {
35 encode(mysql_name, strlen(mysql_name));
36 }
37
38 ColumnName::ColumnName(const LEX_CSTRING &mysql_name)
39 : mysql_name_(mysql_name.str) {
40 encode(mysql_name.str, mysql_name.length);
41 }
42
43 const char *ColumnName::mysql_name() {
44 return mysql_name_;
45 }
46
47 const char *ColumnName::c_str() {
48 return name_;
49 }
50
51 size_t ColumnName::length() {
52 return length_;
53 }
54
55 void ColumnName::encode(const char *mysql_name,
56 size_t mysql_name_length) {
57 MRN_DBUG_ENTER_METHOD();
58 uint errors;
59 length_ = mrn_strconvert(system_charset_info,
60 mysql_name,
61 mysql_name_length,
62 &my_charset_filename,
63 name_,
64 MRN_MAX_PATH_SIZE,
65 &errors);
66 name_[length_] = '\0';
67 DBUG_VOID_RETURN;
68 }
69}
70