summaryrefslogtreecommitdiffstats
path: root/client/client_metadata.h
blob: 49921f018850bec7905d17d6e31305a23e36e2d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef SQL_CLIENT_METADATA_INCLUDED
#define SQL_CLIENT_METADATA_INCLUDED
/*
   Copyright (c) 2020, MariaDB Corporation.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335  USA */

#include "sql_string.h"


/*
  Print MYSQL_FIELD metadata in human readable format
*/
class Client_field_metadata
{
  const MYSQL_FIELD *m_field;
public:
  Client_field_metadata(MYSQL_FIELD *field)
   :m_field(field)
  { }
  void print_attr(Binary_string *to,
                  const LEX_CSTRING &name,
                  mariadb_field_attr_t attr,
                  uint orig_to_length) const
  {
    MARIADB_CONST_STRING tmp;
    if (!mariadb_field_attr(&tmp, m_field, attr) && tmp.length)
    {
      if (to->length() != orig_to_length)
        to->append(" ", 1);
      to->append(name);
      to->append(tmp.str, tmp.length);
    }
  }
  void print_data_type_related_attributes(Binary_string *to) const
  {
    static const LEX_CSTRING type= {C_STRING_WITH_LEN("type=")};
    static const LEX_CSTRING format= {C_STRING_WITH_LEN("format=")};
    uint to_length_orig= to->length();
    print_attr(to, type, MARIADB_FIELD_ATTR_DATA_TYPE_NAME, to_length_orig);
    print_attr(to, format, MARIADB_FIELD_ATTR_FORMAT_NAME, to_length_orig);
  }
};


#endif // SQL_CLIENT_METADATA_INCLUDED