Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: third_party/sqlite/src/src/test_intarray.c

Issue 901033002: Import SQLite 3.8.7.4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Chromium changes to support SQLite 3.8.7.4. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 ** 2009 November 10 2 ** 2009 November 10
3 ** 3 **
4 ** The author disclaims copyright to this source code. In place of 4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing: 5 ** a legal notice, here is a blessing:
6 ** 6 **
7 ** May you do good and not evil. 7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others. 8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give. 9 ** May you share freely, never taking more than you give.
10 ** 10 **
(...skipping 19 matching lines...) Expand all
30 struct sqlite3_intarray { 30 struct sqlite3_intarray {
31 int n; /* Number of elements in the array */ 31 int n; /* Number of elements in the array */
32 sqlite3_int64 *a; /* Contents of the array */ 32 sqlite3_int64 *a; /* Contents of the array */
33 void (*xFree)(void*); /* Function used to free a[] */ 33 void (*xFree)(void*); /* Function used to free a[] */
34 }; 34 };
35 35
36 /* Objects used internally by the virtual table implementation */ 36 /* Objects used internally by the virtual table implementation */
37 typedef struct intarray_vtab intarray_vtab; 37 typedef struct intarray_vtab intarray_vtab;
38 typedef struct intarray_cursor intarray_cursor; 38 typedef struct intarray_cursor intarray_cursor;
39 39
40 /* A intarray table object */ 40 /* An intarray table object */
41 struct intarray_vtab { 41 struct intarray_vtab {
42 sqlite3_vtab base; /* Base class */ 42 sqlite3_vtab base; /* Base class */
43 sqlite3_intarray *pContent; /* Content of the integer array */ 43 sqlite3_intarray *pContent; /* Content of the integer array */
44 }; 44 };
45 45
46 /* A intarray cursor object */ 46 /* An intarray cursor object */
47 struct intarray_cursor { 47 struct intarray_cursor {
48 sqlite3_vtab_cursor base; /* Base class */ 48 sqlite3_vtab_cursor base; /* Base class */
49 int i; /* Current cursor position */ 49 int i; /* Current cursor position */
50 }; 50 };
51 51
52 /* 52 /*
53 ** None of this works unless we have virtual tables. 53 ** None of this works unless we have virtual tables.
54 */ 54 */
55 #ifndef SQLITE_OMIT_VIRTUALTABLE 55 #ifndef SQLITE_OMIT_VIRTUALTABLE
56 56
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 ** Invoke this routine to create a specific instance of an intarray object. 209 ** Invoke this routine to create a specific instance of an intarray object.
210 ** The new intarray object is returned by the 3rd parameter. 210 ** The new intarray object is returned by the 3rd parameter.
211 ** 211 **
212 ** Each intarray object corresponds to a virtual table in the TEMP table 212 ** Each intarray object corresponds to a virtual table in the TEMP table
213 ** with a name of zName. 213 ** with a name of zName.
214 ** 214 **
215 ** Destroy the intarray object by dropping the virtual table. If not done 215 ** Destroy the intarray object by dropping the virtual table. If not done
216 ** explicitly by the application, the virtual table will be dropped implicitly 216 ** explicitly by the application, the virtual table will be dropped implicitly
217 ** by the system when the database connection is closed. 217 ** by the system when the database connection is closed.
218 */ 218 */
219 int sqlite3_intarray_create( 219 SQLITE_API int sqlite3_intarray_create(
220 sqlite3 *db, 220 sqlite3 *db,
221 const char *zName, 221 const char *zName,
222 sqlite3_intarray **ppReturn 222 sqlite3_intarray **ppReturn
223 ){ 223 ){
224 int rc = SQLITE_OK; 224 int rc = SQLITE_OK;
225 #ifndef SQLITE_OMIT_VIRTUALTABLE 225 #ifndef SQLITE_OMIT_VIRTUALTABLE
226 sqlite3_intarray *p; 226 sqlite3_intarray *p;
227 227
228 *ppReturn = p = sqlite3_malloc( sizeof(*p) ); 228 *ppReturn = p = sqlite3_malloc( sizeof(*p) );
229 if( p==0 ){ 229 if( p==0 ){
(...skipping 13 matching lines...) Expand all
243 return rc; 243 return rc;
244 } 244 }
245 245
246 /* 246 /*
247 ** Bind a new array array of integers to a specific intarray object. 247 ** Bind a new array array of integers to a specific intarray object.
248 ** 248 **
249 ** The array of integers bound must be unchanged for the duration of 249 ** The array of integers bound must be unchanged for the duration of
250 ** any query against the corresponding virtual table. If the integer 250 ** any query against the corresponding virtual table. If the integer
251 ** array does change or is deallocated undefined behavior will result. 251 ** array does change or is deallocated undefined behavior will result.
252 */ 252 */
253 int sqlite3_intarray_bind( 253 SQLITE_API int sqlite3_intarray_bind(
254 sqlite3_intarray *pIntArray, /* The intarray object to bind to */ 254 sqlite3_intarray *pIntArray, /* The intarray object to bind to */
255 int nElements, /* Number of elements in the intarray */ 255 int nElements, /* Number of elements in the intarray */
256 sqlite3_int64 *aElements, /* Content of the intarray */ 256 sqlite3_int64 *aElements, /* Content of the intarray */
257 void (*xFree)(void*) /* How to dispose of the intarray when done */ 257 void (*xFree)(void*) /* How to dispose of the intarray when done */
258 ){ 258 ){
259 if( pIntArray->xFree ){ 259 if( pIntArray->xFree ){
260 pIntArray->xFree(pIntArray->a); 260 pIntArray->xFree(pIntArray->a);
261 } 261 }
262 pIntArray->n = nElements; 262 pIntArray->n = nElements;
263 pIntArray->a = aElements; 263 pIntArray->a = aElements;
264 pIntArray->xFree = xFree; 264 pIntArray->xFree = xFree;
265 return SQLITE_OK; 265 return SQLITE_OK;
266 } 266 }
267 267
268 268
269 /***************************************************************************** 269 /*****************************************************************************
270 ** Everything below is interface for testing this module. 270 ** Everything below is interface for testing this module.
271 */ 271 */
272 #ifdef SQLITE_TEST 272 #ifdef SQLITE_TEST
273 #include <tcl.h> 273 #include <tcl.h>
274 274
275 /* 275 /*
276 ** Routines to encode and decode pointers 276 ** Routines to encode and decode pointers
277 */ 277 */
278 extern int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb); 278 extern int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb);
279 extern void *sqlite3TestTextToPtr(const char*); 279 extern void *sqlite3TestTextToPtr(const char*);
280 extern int sqlite3TestMakePointerStr(Tcl_Interp*, char *zPtr, void*); 280 extern int sqlite3TestMakePointerStr(Tcl_Interp*, char *zPtr, void*);
281 extern const char *sqlite3TestErrorName(int); 281 extern const char *sqlite3ErrName(int);
282 282
283 /* 283 /*
284 ** sqlite3_intarray_create DB NAME 284 ** sqlite3_intarray_create DB NAME
285 ** 285 **
286 ** Invoke the sqlite3_intarray_create interface. A string that becomes 286 ** Invoke the sqlite3_intarray_create interface. A string that becomes
287 ** the first parameter to sqlite3_intarray_bind. 287 ** the first parameter to sqlite3_intarray_bind.
288 */ 288 */
289 static int test_intarray_create( 289 static int test_intarray_create(
290 ClientData clientData, /* Not used */ 290 ClientData clientData, /* Not used */
291 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ 291 Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
(...skipping 10 matching lines...) Expand all
302 Tcl_WrongNumArgs(interp, 1, objv, "DB"); 302 Tcl_WrongNumArgs(interp, 1, objv, "DB");
303 return TCL_ERROR; 303 return TCL_ERROR;
304 } 304 }
305 if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; 305 if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
306 zName = Tcl_GetString(objv[2]); 306 zName = Tcl_GetString(objv[2]);
307 #ifndef SQLITE_OMIT_VIRTUALTABLE 307 #ifndef SQLITE_OMIT_VIRTUALTABLE
308 rc = sqlite3_intarray_create(db, zName, &pArray); 308 rc = sqlite3_intarray_create(db, zName, &pArray);
309 #endif 309 #endif
310 if( rc!=SQLITE_OK ){ 310 if( rc!=SQLITE_OK ){
311 assert( pArray==0 ); 311 assert( pArray==0 );
312 Tcl_AppendResult(interp, sqlite3TestErrorName(rc), (char*)0); 312 Tcl_AppendResult(interp, sqlite3ErrName(rc), (char*)0);
313 return TCL_ERROR; 313 return TCL_ERROR;
314 } 314 }
315 sqlite3TestMakePointerStr(interp, zPtr, pArray); 315 sqlite3TestMakePointerStr(interp, zPtr, pArray);
316 Tcl_AppendResult(interp, zPtr, (char*)0); 316 Tcl_AppendResult(interp, zPtr, (char*)0);
317 return TCL_OK; 317 return TCL_OK;
318 } 318 }
319 319
320 /* 320 /*
321 ** sqlite3_intarray_bind INTARRAY ?VALUE ...? 321 ** sqlite3_intarray_bind INTARRAY ?VALUE ...?
322 ** 322 **
(...skipping 16 matching lines...) Expand all
339 } 339 }
340 pArray = (sqlite3_intarray*)sqlite3TestTextToPtr(Tcl_GetString(objv[1])); 340 pArray = (sqlite3_intarray*)sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
341 n = objc - 2; 341 n = objc - 2;
342 #ifndef SQLITE_OMIT_VIRTUALTABLE 342 #ifndef SQLITE_OMIT_VIRTUALTABLE
343 a = sqlite3_malloc( sizeof(a[0])*n ); 343 a = sqlite3_malloc( sizeof(a[0])*n );
344 if( a==0 ){ 344 if( a==0 ){
345 Tcl_AppendResult(interp, "SQLITE_NOMEM", (char*)0); 345 Tcl_AppendResult(interp, "SQLITE_NOMEM", (char*)0);
346 return TCL_ERROR; 346 return TCL_ERROR;
347 } 347 }
348 for(i=0; i<n; i++){ 348 for(i=0; i<n; i++){
349 a[i] = 0; 349 Tcl_WideInt x = 0;
350 Tcl_GetWideIntFromObj(0, objv[i+2], &a[i]); 350 Tcl_GetWideIntFromObj(0, objv[i+2], &x);
351 a[i] = x;
351 } 352 }
352 rc = sqlite3_intarray_bind(pArray, n, a, sqlite3_free); 353 rc = sqlite3_intarray_bind(pArray, n, a, sqlite3_free);
353 if( rc!=SQLITE_OK ){ 354 if( rc!=SQLITE_OK ){
354 Tcl_AppendResult(interp, sqlite3TestErrorName(rc), (char*)0); 355 Tcl_AppendResult(interp, sqlite3ErrName(rc), (char*)0);
355 return TCL_ERROR; 356 return TCL_ERROR;
356 } 357 }
357 #endif 358 #endif
358 return TCL_OK; 359 return TCL_OK;
359 } 360 }
360 361
361 /* 362 /*
362 ** Register commands with the TCL interpreter. 363 ** Register commands with the TCL interpreter.
363 */ 364 */
364 int Sqlitetestintarray_Init(Tcl_Interp *interp){ 365 int Sqlitetestintarray_Init(Tcl_Interp *interp){
365 static struct { 366 static struct {
366 char *zName; 367 char *zName;
367 Tcl_ObjCmdProc *xProc; 368 Tcl_ObjCmdProc *xProc;
368 void *clientData; 369 void *clientData;
369 } aObjCmd[] = { 370 } aObjCmd[] = {
370 { "sqlite3_intarray_create", test_intarray_create, 0 }, 371 { "sqlite3_intarray_create", test_intarray_create, 0 },
371 { "sqlite3_intarray_bind", test_intarray_bind, 0 }, 372 { "sqlite3_intarray_bind", test_intarray_bind, 0 },
372 }; 373 };
373 int i; 374 int i;
374 for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){ 375 for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
375 Tcl_CreateObjCommand(interp, aObjCmd[i].zName, 376 Tcl_CreateObjCommand(interp, aObjCmd[i].zName,
376 aObjCmd[i].xProc, aObjCmd[i].clientData, 0); 377 aObjCmd[i].xProc, aObjCmd[i].clientData, 0);
377 } 378 }
378 return TCL_OK; 379 return TCL_OK;
379 } 380 }
380 381
381 #endif /* SQLITE_TEST */ 382 #endif /* SQLITE_TEST */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698