~ubuntu-branches/ubuntu/lucid/python-apsw/lucid

« back to all changes in this revision

Viewing changes to testextension.c

  • Committer: Bazaar Package Importer
  • Author(s): Joel Rosdahl
  • Date: 2010-01-11 20:44:37 UTC
  • mfrom: (1.1.6 upstream) (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100111204437-iao0rcj1p2m29juy
Tags: 3.6.22-r1-1
* New upstream version.
* Added ${misc:Depends} for binary packages' requirements.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This code is to test extension loading and is taken from 
2
 
   http://www.sqlite.org/cvstrac/wiki/wiki?p=LoadableExtensions */
3
 
 
4
 
 
5
 
    #include <sqlite3ext.h>
6
 
    SQLITE_EXTENSION_INIT1
7
 
 
8
 
    /*
9
 
    ** The half() SQL function returns half of its input value.
10
 
    */
11
 
    static void halfFunc(
12
 
      sqlite3_context *context,
13
 
      int argc,
14
 
      sqlite3_value **argv
15
 
    ){
16
 
      sqlite3_result_double(context, 0.5*sqlite3_value_double(argv[0]));
17
 
    }
18
 
 
19
 
    /* SQLite invokes this routine once when it loads the extension.
20
 
    ** Create new functions, collating sequences, and virtual table
21
 
    ** modules here.  This is usually the only exported symbol in
22
 
    ** the shared library.
23
 
    */
24
 
    int sqlite3_extension_init(
25
 
      sqlite3 *db,
26
 
      char **pzErrMsg,
27
 
      const sqlite3_api_routines *pApi
28
 
    ){
29
 
      SQLITE_EXTENSION_INIT2(pApi)
30
 
      sqlite3_create_function(db, "half", 1, SQLITE_ANY, 0, halfFunc, 0, 0);
31
 
      return 0;
32
 
    }
33
 
 
34
 
 
35
 
/* this is code added by me and checks that alternate entry points work by
36
 
   providing an double function */
37
 
 
38
 
    static void doubleFunc(
39
 
      sqlite3_context *context,
40
 
      int argc,
41
 
      sqlite3_value **argv
42
 
    ){
43
 
      sqlite3_result_double(context, 2.0*sqlite3_value_double(argv[0]));
44
 
    }
45
 
 
46
 
    int alternate_sqlite3_extension_init(
47
 
      sqlite3 *db,
48
 
      char **pzErrMsg,
49
 
      const sqlite3_api_routines *pApi
50
 
    ){
51
 
      SQLITE_EXTENSION_INIT2(pApi)
52
 
      sqlite3_create_function(db, "doubleup", 1, SQLITE_ANY, 0, doubleFunc, 0, 0);
53
 
      return 0;
54
 
    }