-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathudf.c
More file actions
65 lines (52 loc) · 1.63 KB
/
Copy pathudf.c
File metadata and controls
65 lines (52 loc) · 1.63 KB
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
/*
Copyright 2017 Guy Riddle
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1
/*
* One sample SQLite stored function that is automatically loaded into each database opened.
*
* You might use a different cheese, of course.
*
* Demonstrate via: "SELECT gouda(1.2, 2.3, 5.0, 3.4);"
*
*/
static void
gouda_function(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
double a = sqlite3_value_double(argv[0]);
double b = sqlite3_value_double(argv[1]);
double c = sqlite3_value_double(argv[2]);
double d = sqlite3_value_double(argv[3]);
double answer;
answer = a*b - c*d;
sqlite3_result_double(context, answer);
}
int
load_udf_definitions(
sqlite3 *db,
const char **pzErrMsg,
const struct sqlite3_api_routines *pApi
){
int rc = SQLITE_OK;
SQLITE_EXTENSION_INIT2(pApi);
rc = sqlite3_create_function(db, "gouda", 4, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, gouda_function, 0, 0);
return(rc);
};
#undef sqlite3_auto_extension
void
udf_initialize(){
sqlite3_auto_extension((void *) &load_udf_definitions);
}