wasCSharpSQLite – Blame information for rev 4

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 using System.Diagnostics;
2 using System.Text;
3  
4 namespace Community.CsharpSqlite
5 {
6 #if TCLSH
7 using tcl.lang;
8 using sqlite3_stmt = Community.CsharpSqlite.Sqlite3.Vdbe;
9 using Tcl_Interp = tcl.lang.Interp;
10 using Tcl_Obj = tcl.lang.TclObject;
11  
12 public partial class Sqlite3
13 {
14 /*
15 ** 2007 March 29
16 **
17 ** The author disclaims copyright to this source code. In place of
18 ** a legal notice, here is a blessing:
19 **
20 ** May you do good and not evil.
21 ** May you find forgiveness for yourself and forgive others.
22 ** May you share freely, never taking more than you give.
23 **
24 *************************************************************************
25 **
26 ** This file contains obscure tests of the C-interface required
27 ** for completeness. Test code is written in C for these cases
28 ** as there is not much point in binding to Tcl.
29 *************************************************************************
30 ** Included in SQLite3 port to C#-SQLite; 2008 Noah B Hart
31 ** C#-SQLite is an independent reimplementation of the SQLite software library
32 **
33 ** SQLITE_SOURCE_ID: 2010-08-23 18:52:01 42537b60566f288167f1b5864a5435986838e3a3
34 **
35 *************************************************************************
36 */
37 //#include "sqliteInt.h"
38 //#include "tcl.h"
39 //#include <stdlib.h>
40 //#include <string.h>
41  
42 /*
43 ** c_collation_test
44 */
45 static int c_collation_test(
46 object clientdata, /* Pointer to sqlite3_enable_XXX function */
47 Tcl_Interp interp, /* The TCL interpreter that invoked this command */
48 int objc, /* Number of arguments */
49 Tcl_Obj[] objv /* Command arguments */
50 )
51 {
52 string zErrFunction = "N/A";
53 sqlite3 db = null;
54  
55 int rc;
56 if ( objc != 1 )
57 {
58 TCL.Tcl_WrongNumArgs( interp, 1, objv, "" );
59 return TCL.TCL_ERROR;
60 }
61  
62 /* Open a database. */
63 rc = sqlite3_open( ":memory:", out db );
64 if ( rc != SQLITE_OK )
65 {
66 zErrFunction = "sqlite3_open";
67 goto error_out;
68 }
69  
70 rc = sqlite3_create_collation( db, "collate", 456, null, null );
71 if ( rc != SQLITE_MISUSE )
72 {
73 sqlite3_close( db );
74 zErrFunction = "sqlite3_create_collation";
75 goto error_out;
76 }
77  
78 sqlite3_close( db );
79 return TCL.TCL_OK;
80  
81 error_out:
82 TCL.Tcl_ResetResult( interp );
83 TCL.Tcl_AppendResult( interp, "Error testing function: ", zErrFunction, null );
84 return TCL.TCL_ERROR;
85 }
86  
87 /*
88 ** c_realloc_test
89 */
90 static int c_realloc_test(
91 object clientdata, /* Pointer to sqlite3_enable_XXX function */
92 Tcl_Interp interp, /* The TCL interpreter that invoked this command */
93 int objc, /* Number of arguments */
94 Tcl_Obj[] objv /* Command arguments */
95 )
96 {
97 object p;
98 string zErrFunction = "N/A";
99  
100 if ( objc != 1 )
101 {
102 TCL.Tcl_WrongNumArgs( interp, 1, objv, "" );
103 return TCL.TCL_ERROR;
104 }
105  
106 p = sqlite3Malloc( 5 );
107 if ( p == null )
108 {
109 zErrFunction = "sqlite3Malloc";
110 goto error_out;
111 }
112  
113 /* Test that realloc()ing a block of memory to a negative size is
114 ** the same as free()ing that memory.
115 */
116 //TODO -- ignore realloc
117 //p = sqlite3_realloc(p, -1);
118 //if( p!=null ){
119 // zErrFunction = "sqlite3_realloc";
120 // goto error_out;
121 //}
122  
123 return TCL.TCL_OK;
124  
125 error_out:
126 TCL.Tcl_ResetResult( interp );
127 TCL.Tcl_AppendResult( interp, "Error testing function: ", zErrFunction );
128 return TCL.TCL_ERROR;
129 }
130  
131  
132 /*
133 ** c_misuse_test
134 */
135 static int c_misuse_test(
136 object clientdata, /* Pointer to sqlite3_enable_XXX function */
137 Tcl_Interp interp, /* The TCL interpreter that invoked this command */
138 int objc, /* Number of arguments */
139 Tcl_Obj[] objv /* Command arguments */
140 )
141 {
142 string zErrFunction = "N/A";
143 sqlite3 db = null;
144 sqlite3_stmt pStmt;
145 int rc;
146  
147 if ( objc != 1 )
148 {
149 TCL.Tcl_WrongNumArgs( interp, 1, objv, "" );
150 return TCL.TCL_ERROR;
151 }
152  
153 /* Open a database. Then close it again. We need to do this so that
154 ** we have a "closed database handle" to pass to various API functions.
155 */
156 rc = sqlite3_open( ":memory:", out db );
157 if ( rc != SQLITE_OK )
158 {
159 zErrFunction = "sqlite3_open";
160 goto error_out;
161 }
162 sqlite3_close( db );
163  
164  
165 rc = sqlite3_errcode( db );
166 if ( rc != SQLITE_MISUSE )
167 {
168 zErrFunction = "sqlite3_errcode";
169 goto error_out;
170 }
171  
172 pStmt = new sqlite3_stmt();
173 pStmt.pc = 1234;
174 rc = sqlite3_prepare( db, (StringBuilder)null, 0, ref pStmt, 0 );
175 if ( rc != SQLITE_MISUSE )
176 {
177 zErrFunction = "sqlite3_prepare";
178 goto error_out;
179 }
180 Debug.Assert( pStmt == null ); /* Verify that pStmt is zeroed even on a MISUSE error */
181  
182  
183 pStmt = new sqlite3_stmt();
184 pStmt.pc = 1234;
185 rc = sqlite3_prepare_v2( db, null, 0, ref pStmt, 0 );
186 if ( rc != SQLITE_MISUSE )
187 {
188 zErrFunction = "sqlite3_prepare_v2";
189 goto error_out;
190 }
191 Debug.Assert( pStmt == null );
192  
193 #if !SQLITE_OMIT_UTF16
194 pStmt = (sqlite3_stmt)1234;
195 rc = sqlite3_prepare16( db, null, 0, ref pStmt, 0 );
196 if( rc!=SQLITE_MISUSE ){
197 zErrFunction = "sqlite3_prepare16";
198 goto error_out;
199 }
200 Debug.Assert( pStmt==0 );
201 pStmt = (sqlite3_stmt)1234;
202 rc = sqlite3_prepare16_v2( db, null, 0, ref pStmt, 0 );
203 if( rc!=SQLITE_MISUSE ){
204 zErrFunction = "sqlite3_prepare16_v2";
205 goto error_out;
206 }
207 Debug.Assert( pStmt==0 );
208 #endif
209  
210 return TCL.TCL_OK;
211  
212 error_out:
213 TCL.Tcl_ResetResult( interp );
214 TCL.Tcl_AppendResult( interp, "Error testing function: ", zErrFunction );
215 return TCL.TCL_ERROR;
216 }
217  
218 /*
219 ** Register commands with the TCL interpreter.
220 */
221 static public int Sqlitetest9_Init( Tcl_Interp interp )
222 {
223 //static struct {
224 // string zName;
225 // Tcl_ObjCmdProc *xProc;
226 // void *object;
227 //}
228 _aObjCmd[] aObjCmd = new _aObjCmd[] {
229 new _aObjCmd( "c_misuse_test", c_misuse_test, 0 ),
230 new _aObjCmd( "c_realloc_test", c_realloc_test, 0 ),
231 new _aObjCmd( "c_collation_test", c_collation_test, 0 ),
232 };
233 int i;
234 for ( i = 0; i < aObjCmd.Length; i++ )
235 {//sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
236 TCL.Tcl_CreateObjCommand( interp, aObjCmd[i].zName,
237 aObjCmd[i].xProc, aObjCmd[i].clientData, null );
238 }
239 return TCL.TCL_OK;
240 }
241 }
242 #endif
243 }