wasCSharpSQLite – Blame information for rev 4
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | namespace Community.CsharpSqlite |
2 | { |
||
3 | #if TCLSH |
||
4 | using tcl.lang; |
||
5 | using sqlite3_value = Sqlite3.Mem; |
||
6 | using Tcl_Interp = tcl.lang.Interp; |
||
7 | using Tcl_Obj = tcl.lang.TclObject; |
||
8 | |||
9 | public partial class Sqlite3 |
||
10 | { |
||
11 | /* |
||
12 | ** 2006 August 23 |
||
13 | ** |
||
14 | ** The author disclaims copyright to this source code. In place of |
||
15 | ** a legal notice, here is a blessing: |
||
16 | ** |
||
17 | ** May you do good and not evil. |
||
18 | ** May you find forgiveness for yourself and forgive others. |
||
19 | ** May you share freely, never taking more than you give. |
||
20 | ** |
||
21 | ************************************************************************* |
||
22 | ** Test extension for testing the sqlite3_auto_extension() function. |
||
23 | ************************************************************************* |
||
24 | ** Included in SQLite3 port to C#-SQLite; 2008 Noah B Hart |
||
25 | ** C#-SQLite is an independent reimplementation of the SQLite software library |
||
26 | ** |
||
27 | ** SQLITE_SOURCE_ID: 2010-08-23 18:52:01 42537b60566f288167f1b5864a5435986838e3a3 |
||
28 | ** |
||
29 | ************************************************************************* |
||
30 | */ |
||
31 | //#include "tcl.h" |
||
32 | //#include "sqlite3ext.h" |
||
33 | |||
34 | #if !SQLITE_OMIT_LOAD_EXTENSION |
||
35 | //static int SQLITE_EXTENSION_INIT1 = null; |
||
36 | static sqlite3_api_routines sqlite3_api = null; |
||
37 | |||
38 | /* |
||
39 | ** The sqr() SQL function returns the square of its input value. |
||
40 | */ |
||
41 | static void sqrFunc( |
||
42 | sqlite3_context context, |
||
43 | int argc, |
||
44 | sqlite3_value[] argv |
||
45 | ) |
||
46 | { |
||
47 | double r = sqlite3_value_double( argv[0] ); |
||
48 | sqlite3_result_double( context, r * r ); |
||
49 | } |
||
50 | |||
51 | /* |
||
52 | ** This is the entry point to register the extension for the sqr() function. |
||
53 | */ |
||
54 | static int sqr_init( |
||
55 | sqlite3 db, |
||
56 | ref string pzErrMsg, |
||
57 | sqlite3_api_routines pApi |
||
58 | ) |
||
59 | { |
||
60 | sqlite3_api = pApi; // SQLITE_EXTENSION_INIT2( pApi ); |
||
61 | sqlite3_create_function( db, "sqr", 1, SQLITE_ANY, 0, sqrFunc, null, null ); |
||
62 | return 0; |
||
63 | } |
||
64 | |||
65 | /* |
||
66 | ** The cube() SQL function returns the cube of its input value. |
||
67 | */ |
||
68 | static void cubeFunc( |
||
69 | sqlite3_context context, |
||
70 | int argc, |
||
71 | sqlite3_value[] argv |
||
72 | ) |
||
73 | { |
||
74 | double r = sqlite3_value_double( argv[0] ); |
||
75 | sqlite3_result_double( context, r * r * r ); |
||
76 | } |
||
77 | |||
78 | /* |
||
79 | ** This is the entry point to register the extension for the cube() function. |
||
80 | */ |
||
81 | static int cube_init( |
||
82 | sqlite3 db, |
||
83 | ref string pzErrMsg, |
||
84 | sqlite3_api_routines pApi |
||
85 | ) |
||
86 | { |
||
87 | sqlite3_api = pApi; //SQLITE_EXTENSION_INIT2( pApi ); |
||
88 | sqlite3_create_function( db, "cube", 1, SQLITE_ANY, 0, cubeFunc, null, null ); |
||
89 | return 0; |
||
90 | } |
||
91 | |||
92 | /* |
||
93 | ** This is a broken extension entry point |
||
94 | */ |
||
95 | static int broken_init( |
||
96 | sqlite3 db, |
||
97 | ref string pzErrMsg, |
||
98 | sqlite3_api_routines pApi |
||
99 | ) |
||
100 | { |
||
101 | string zErr; |
||
102 | sqlite3_api = pApi; //SQLITE_EXTENSION_INIT2( pApi ); |
||
103 | zErr = sqlite3_mprintf( "broken autoext!" ); |
||
104 | pzErrMsg = zErr; |
||
105 | return 1; |
||
106 | } |
||
107 | |||
108 | /* |
||
109 | ** tclcmd: sqlite3_auto_extension_sqr |
||
110 | ** |
||
111 | ** Register the "sqr" extension to be loaded automatically. |
||
112 | */ |
||
113 | static int autoExtSqrObjCmd( |
||
114 | object clientdata, |
||
115 | Tcl_Interp interp, |
||
116 | int objc, |
||
117 | Tcl_Obj[] objv |
||
118 | ) |
||
119 | { |
||
120 | int rc = sqlite3_auto_extension( sqr_init ); |
||
121 | TCL.Tcl_SetObjResult( interp, TCL.Tcl_NewIntObj( rc ) ); |
||
122 | return SQLITE_OK; |
||
123 | } |
||
124 | |||
125 | /* |
||
126 | ** tclcmd: sqlite3_auto_extension_cube |
||
127 | ** |
||
128 | ** Register the "cube" extension to be loaded automatically. |
||
129 | */ |
||
130 | static int autoExtCubeObjCmd( |
||
131 | object clientdata, |
||
132 | Tcl_Interp interp, |
||
133 | int objc, |
||
134 | Tcl_Obj[] objv |
||
135 | ) |
||
136 | { |
||
137 | int rc = sqlite3_auto_extension( cube_init ); |
||
138 | TCL.Tcl_SetObjResult( interp, TCL.Tcl_NewIntObj( rc ) ); |
||
139 | return SQLITE_OK; |
||
140 | } |
||
141 | |||
142 | /* |
||
143 | ** tclcmd: sqlite3_auto_extension_broken |
||
144 | ** |
||
145 | ** Register the broken extension to be loaded automatically. |
||
146 | */ |
||
147 | static int autoExtBrokenObjCmd( |
||
148 | object clientdata, |
||
149 | Tcl_Interp interp, |
||
150 | int objc, |
||
151 | Tcl_Obj[] objv |
||
152 | ) |
||
153 | { |
||
154 | int rc = sqlite3_auto_extension( (dxInit)broken_init ); |
||
155 | TCL.Tcl_SetObjResult( interp, TCL.Tcl_NewIntObj( rc ) ); |
||
156 | return SQLITE_OK; |
||
157 | } |
||
158 | |||
159 | #else |
||
160 | // static void sqlite3_reset_auto_extension() { } |
||
161 | #endif //* SQLITE_OMIT_LOAD_EXTENSION */ |
||
162 | |||
163 | |||
164 | /* |
||
165 | ** tclcmd: sqlite3_reset_auto_extension |
||
166 | ** |
||
167 | ** Reset all auto-extensions |
||
168 | */ |
||
169 | static int resetAutoExtObjCmd( |
||
170 | object clientdata, |
||
171 | Tcl_Interp interp, |
||
172 | int objc, |
||
173 | Tcl_Obj[] objv |
||
174 | ) |
||
175 | { |
||
176 | sqlite3_reset_auto_extension(); |
||
177 | return SQLITE_OK; |
||
178 | } |
||
179 | |||
180 | |||
181 | /* |
||
182 | ** This procedure registers the TCL procs defined in this file. |
||
183 | */ |
||
184 | public static int Sqlitetest_autoext_Init( Tcl_Interp interp ) |
||
185 | { |
||
186 | #if !SQLITE_OMIT_LOAD_EXTENSION |
||
187 | TCL.Tcl_CreateObjCommand( interp, "sqlite3_auto_extension_sqr", |
||
188 | autoExtSqrObjCmd, null, null ); |
||
189 | TCL.Tcl_CreateObjCommand( interp, "sqlite3_auto_extension_cube", |
||
190 | autoExtCubeObjCmd, null, null ); |
||
191 | TCL.Tcl_CreateObjCommand( interp, "sqlite3_auto_extension_broken", |
||
192 | autoExtBrokenObjCmd, null, null ); |
||
193 | #endif |
||
194 | TCL.Tcl_CreateObjCommand( interp, "sqlite3_reset_auto_extension", |
||
195 | resetAutoExtObjCmd, null, null ); |
||
196 | return TCL.TCL_OK; |
||
197 | } |
||
198 | } |
||
199 | #endif |
||
200 | } |