Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 122 lines (110 sloc) 3.673 kb
60cdc8c @jasny Firt commit
jasny authored
1 /*
08837a1 changed to MIT License
raw authored
2 * Copyright (C) 2007-2013 Rich Waters <raw@goodhumans.net>
60cdc8c @jasny Firt commit
jasny authored
3 *
4 * This file is part of lib_mysqludf_preg.
5 *
08837a1 changed to MIT License
raw authored
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
60cdc8c @jasny Firt commit
jasny authored
23 */
24
25
26 /** @file ghmysql.c
27 *
28 * @brief Provides some functions that are shared by the various
29 * gh udf functions.
30 *
31 */
32 #include "ghmysql.h"
460af3b 1.1 update
raw authored
33 #include "ghfcns.h"
8fedab7 merged in changes from Travers Carter as attached to ticket at http://my...
raw authored
34 #include <time.h>
35 #include <stdarg.h>
60cdc8c @jasny Firt commit
jasny authored
36
37
38 /**
39 * @fn char *ghargdup( UDF_ARGS *args,int i )
40 *
41 * @brief extract argument as a newly allocated null-terminated memory area
42 *
43 * @param args - args from the UDF function call
44 * @param i - offset of argument to extract.
45 *
46 * @return pointer - to newly allocate memory if successful
47 * @return NULL - if arg is NULL or not enough memory
48 *
49 */
50 char *ghargdup( UDF_ARGS *args,int i )
51 {
52 int l ;
53 char *s ;
54 char *colval = NULL ;
55
56 if( (l=args->lengths[i] ) && (s=args->args[i]) )
57 {
58 colval = ghstrndup( s , l ) ;
59 }
60
61 return colval ;
62 }
63
64 /**
65 * @fn char *ghargdups( UDF_ARGS *args,int i , unsigned long *l)
66 *
67 * @brief extract argument as a newly allocated null-terminated memory area,
68 * and set the length to the size of that area
69 *
70 * @param args - args from the UDF function call
71 * @param i - offset of argument to extract.
72 * @param l - store the length of the argument here
73 *
74 * @return pointer - to newly allocate memory if successful
75 *
76 * @details This is useful for guaranteeing not to have NULL as an argument
77 */
78 char *ghargdups( UDF_ARGS *args , int i , unsigned long *l)
79 {
80 if( !(*l=args->lengths[ i ]))
81 {
82 return strdup( "" ) ;
83 }
84 else if( !args->args[i]) {
85 *l = 0 ;
86 return strdup( "" ) ;
87 }
88 else {
89 return ghargdup( args , i ) ;
90 }
91 }
92
93
94 /**
95 * @fn char *ghargIsNull( UDF_ARGS *args,int argNum)
96 *
97 * @brief is the given argument NULL
98 *
99 * @param args - args from the UDF function call
100 * @param i - the argument to test
101 *
102 * @return int - 1 if the argument is NULL, 0 otherwise
103 *
104 * @details - this only returns true if the arg is specified as NULL
105 * when in the mysql statement. This does not return true if the
106 * NULL results from evaluating a column. The purpose of this function
107 * in so that init functions can differentiate NULL constants from
108 * NULL meaning that there are no constant arguments. This is important
109 * because there is better error handling in the API for init functions
110 * than mains.
111 */
112 int ghargIsNullConstant(UDF_ARGS *args, int argNum)
113 {
114 if( args->arg_count > argNum && !args->args[argNum] &&
115 !strncmp( args->attributes[argNum], "NULL" , 4 ) ) {
116 return 1 ;
117 }
118
119 return 0 ;
120 }
8fedab7 merged in changes from Travers Carter as attached to ticket at http://my...
raw authored
121
Something went wrong with that request. Please try again.