File: mysql_casts.c

package info (click to toggle)
pg-comparator 2.3.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 564 kB
  • sloc: perl: 5,349; ansic: 709; sql: 158; makefile: 62
file content (82 lines) | stat: -rw-r--r-- 2,147 bytes parent folder | download | duplicates (6)
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
/* $Id: mysql_casts.c 1127 2012-08-08 07:49:29Z fabien $ */

// minimal headers
#include <stdint.h>
#include <my_global.h>
#include <mysql.h>

/* foo_init, foo, foo_deinit */
my_bool biginttoint8_init(UDF_INIT *, UDF_ARGS *, char *);
longlong biginttoint8(UDF_INIT *, UDF_ARGS *, char *, char *);
my_bool biginttoint4_init(UDF_INIT *, UDF_ARGS *, char *);
longlong biginttoint4(UDF_INIT *, UDF_ARGS *, char *, char *);
my_bool biginttoint2_init(UDF_INIT *, UDF_ARGS *, char *);
longlong biginttoint2(UDF_INIT *, UDF_ARGS *, char *, char *);

longlong biginttoint8(
  UDF_INIT *initid __attribute__((unused)),
  UDF_ARGS *args,
  char *is_null,
  char *error __attribute__((unused)))
{
  // if in doubt, return NULL
  if (args->arg_count!=1 || args->arg_type[0]!=INT_RESULT || !args->args[0]) {
    *is_null = 1;
    return 0;
  }
  return *((longlong*) args->args[0]);
}

my_bool biginttoint8_init(
  UDF_INIT *initid __attribute__((unused)),
  UDF_ARGS *args __attribute__((unused)),
  char *message __attribute__((unused)))
{
  return 0;
}

longlong biginttoint4(
  UDF_INIT *initid __attribute__((unused)),
  UDF_ARGS *args,
  char *is_null,
  char *error __attribute__((unused)))
{
  // if in doubt, return NULL
  if (args->arg_count!=1 || args->arg_type[0]!=INT_RESULT || !args->args[0]) {
    *is_null = 1;
    return 0;
  }
  return (longlong)
    ((int32_t) (*((longlong*) args->args[0]) & 0x00000000ffffffffLL));
}

my_bool biginttoint4_init(
  UDF_INIT *initid __attribute__((unused)),
  UDF_ARGS *args __attribute__((unused)),
  char *message __attribute__((unused)))
{
  return 0;
}

longlong biginttoint2(
  UDF_INIT *initid __attribute__((unused)),
  UDF_ARGS *args,
  char *is_null,
  char *error __attribute__((unused)))
{
  // if in doubt, return NULL
  if (args->arg_count!=1 || args->arg_type[0]!=INT_RESULT || !args->args[0]) {
    *is_null = 1;
    return 0;
  }
  return (longlong)
    ((int16_t)(*((longlong*) args->args[0]) & 0x000000000000ffffLL));
}

my_bool biginttoint2_init(
  UDF_INIT *initid __attribute__((unused)),
  UDF_ARGS *args __attribute__((unused)),
  char *message __attribute__((unused)))
{
  return 0;
}