File: samplext.c

package info (click to toggle)
sqliteodbc 0.91-3
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 6,412 kB
  • sloc: ansic: 34,510; sh: 11,960; makefile: 582; sql: 313
file content (39 lines) | stat: -rw-r--r-- 936 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
/*
 * SQLite3 example extension from wiki
 * http://www.sqlite.org/cvstrac/wiki?p=LoadableExtensions
 *
 * Compile with
 *   tcc -rdynamic -shared -o samplext.dll samplext.c
 */

#include <sqlite3ext.h>

SQLITE_EXTENSION_INIT1

/*
 * The half() SQL function returns half of its input value.
 */
static void halfFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  sqlite3_result_double(context, 0.5 * sqlite3_value_double(argv[0]));
}

/*
 * SQLite invokes this routine once when it loads the extension.
 * Create new functions, collating sequences, and virtual table
 * modules here.  This is usually the only exported symbol in
 * the shared library.
 */
int sqlite3_extension_init(
  sqlite3 *db,
  char **pzErrMsg,
  const sqlite3_api_routines *pApi
){
  SQLITE_EXTENSION_INIT2(pApi)
  sqlite3_create_function(db, "half", 1, SQLITE_ANY, 0, halfFunc, 0, 0);
  return 0;
}