File: item_uuidfunc.h

package info (click to toggle)
mariadb 1%3A11.8.3-0%2Bdeb13u1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 772,508 kB
  • sloc: ansic: 2,414,714; cpp: 1,791,394; asm: 381,336; perl: 62,905; sh: 49,647; pascal: 40,897; java: 39,363; python: 20,791; yacc: 20,432; sql: 17,907; xml: 12,344; ruby: 8,544; cs: 6,542; makefile: 6,145; ada: 1,879; lex: 1,193; javascript: 996; objc: 80; tcl: 73; awk: 46; php: 22
file content (118 lines) | stat: -rw-r--r-- 3,521 bytes parent folder | download | duplicates (4)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#ifndef ITEM_UUIDFUNC_INCLUDED
#define ITEM_UUIDFUNC_INCLUDED

/* Copyright (c) 2019,2024, 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 "item.h"
#include "sql_type_uuid_v1.h"
#include "sql_type_uuid_v4.h"
#include "sql_type_uuid_v7.h"

class Item_func_sys_guid: public Item_str_func
{
protected:
  static size_t uuid_len()
  { return MY_UUID_BARE_STRING_LENGTH; }
public:
  Item_func_sys_guid(THD *thd): Item_str_func(thd) {}
  bool fix_length_and_dec(THD *thd) override
  {
    collation.set(DTCollation_numeric());
    fix_char_length(uuid_len());
    return FALSE;
  }
  bool const_item() const override { return false; }
  table_map used_tables() const override { return RAND_TABLE_BIT; }
  LEX_CSTRING func_name_cstring() const override
  {
    static LEX_CSTRING name= {STRING_WITH_LEN("sys_guid") };
    return name;
  }
  String *val_str(String *) override;
  bool check_vcol_func_processor(void *arg) override
  {
    return mark_unsupported_function(func_name(), "()", arg, VCOL_NON_DETERMINISTIC);
  }
  Item *do_get_copy(THD *thd) const override
  { return get_item_copy<Item_func_sys_guid>(thd, this); }
};


template<class UUIDvX>
class Item_func_uuid_vx: public Type_handler_uuid_new::Item_fbt_func
{
public:
  using Item_fbt_func::Item_fbt_func;
  bool const_item() const override { return false; }
  table_map used_tables() const override { return RAND_TABLE_BIT; }
  bool check_vcol_func_processor(void *arg) override
  {
    return mark_unsupported_function(func_name(), "()", arg, VCOL_NON_DETERMINISTIC);
  }
  String *val_str(String *str) override
  {
    DBUG_ASSERT(fixed());
    return UUIDvX().to_string(str) ? NULL : str;
  }
  bool val_native(THD *thd, Native *to) override
  {
    DBUG_ASSERT(fixed());
    return UUIDvX::construct_native(to);
  }
};


class Item_func_uuid: public Item_func_uuid_vx<UUIDv1>
{
public:
  using Item_func_uuid_vx::Item_func_uuid_vx;
  LEX_CSTRING func_name_cstring() const override
  {
    static LEX_CSTRING name= {STRING_WITH_LEN("uuid") };
    return name;
  }
  Item *do_get_copy(THD *thd) const override
  { return get_item_copy<Item_func_uuid>(thd, this); }
};


class Item_func_uuid_v4: public Item_func_uuid_vx<UUIDv4>
{
public:
  using Item_func_uuid_vx::Item_func_uuid_vx;
  LEX_CSTRING func_name_cstring() const override
  {
    static LEX_CSTRING name= {STRING_WITH_LEN("uuid_v4") };
    return name;
  }
  Item *do_get_copy(THD *thd) const override
  { return get_item_copy<Item_func_uuid_v4>(thd, this); }
};

class Item_func_uuid_v7: public Item_func_uuid_vx<UUIDv7>
{
public:
  using Item_func_uuid_vx::Item_func_uuid_vx;
  LEX_CSTRING func_name_cstring() const override
  {
    static LEX_CSTRING name= {STRING_WITH_LEN("uuid_v7") };
    return name;
  }
  Item *do_get_copy(THD *thd) const override
  { return get_item_copy<Item_func_uuid_v7>(thd, this); }
};
#endif // ITEM_UUIDFUNC_INCLUDED