test1.c revision 2
2N/A#
pragma ident "%Z%%M% %I% %E% SMI" 2N/A** The author disclaims copyright to this source code. In place of 2N/A** a legal notice, here is a blessing: 2N/A** May you do good and not evil. 2N/A** May you find forgiveness for yourself and forgive others. 2N/A** May you share freely, never taking more than you give. 2N/A************************************************************************* 2N/A** Code for testing the printf() interface to SQLite. This code 2N/A** is not included in the SQLite library. It is used for automated 2N/A** testing of the SQLite library. 2N/A** $Id: test1.c,v 1.36.2.1 2004/05/07 00:57:06 drh Exp $ 2N/A** Decode a pointer to an sqlite object. 2N/A** Decode a pointer to an sqlite_vm object. 2N/A** Generate a text representation of a pointer that can be understood 2N/A** by the getDbPointer and getVmPointer routines above. 2N/A** The problem is, on some machines (Solaris) if you do a printf with 2N/A** "%p" you cannot turn around and do a scanf with the same "%p" and 2N/A** get your pointer back. You have to prepend a "0x" before it will 2N/A** work. Or at least that is what is reported to me (drh). But this 2N/A** behavior varies from machine to machine. The solution used her is 2N/A** to test the string right after it is generated to see if it can be 2N/A** understood by scanf, and if not, try prepending an "0x" to see if 2N/A** that helps. If nothing works, a fatal error is generated. 2N/A "in the file " __FILE__ " in function makePointerStr(). Please " 2N/A "report this problem to the SQLite mailing list or as a new but " 2N/A "report. Please provide detailed information about how you compiled " 2N/A "SQLite and what computer you are running on.", 0);
2N/A** Usage: sqlite_open filename 2N/A** Returns: The name of an open database. 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A** The callback routine for sqlite_exec_printf(). 2N/A** Usage: sqlite_exec_printf DB FORMAT STRING 2N/A** Invoke the sqlite_exec_printf() interface using the open database 2N/A** DB. The SQL is the string FORMAT. The format string should contain 2N/A** one %s or %q. STRING is the value inserted into %s or %q. 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A " DB FORMAT STRING", 0);
2N/A** Usage: sqlite_mprintf_z_test SEPARATOR ARG0 ARG1 ... 2N/A** Test the %z format of mprintf(). Use multiple mprintf() calls to 2N/A** concatenate arg0 through argn using separator as the separator. 2N/A** Return the result. 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A** Usage: sqlite_get_table_printf DB FORMAT STRING 2N/A** Invoke the sqlite_get_table_printf() interface using the open database 2N/A** DB. The SQL is the string FORMAT. The format string should contain 2N/A** one %s or %q. STRING is the value inserted into %s or %q. 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A " DB FORMAT STRING", 0);
2N/A** Usage: sqlite_last_insert_rowid DB 2N/A** Returns the integer ROWID of the most recent insert. 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A** Usage: sqlite_close DB 2N/A** Closes the database opened by sqlite_open. 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A** Implementation of the x_coalesce() function. 2N/A** Return the first argument non-NULL argument. 2N/A** A structure into which to accumulate text. 2N/A char *z;
/* The space */ 2N/A** Append text to a dstr 2N/A** Invoked for each callback from sqliteExecFunc 2N/A** Implementation of the x_sqlite_exec() function. This function takes 2N/A** a single argument and attempts to execute that argument as SQL code. 2N/A** This is illegal and should set the SQLITE_MISUSE flag on the database. 2N/A** 2004-Jan-07: We have changed this to make it legal to call sqlite_exec() 2N/A** from within a function call. 2N/A** This routine simulates the effect of having two threads attempt to 2N/A** use the same database at the same time. 2N/A** Usage: sqlite_test_create_function DB 2N/A** Call the sqlite_create_function API on the given database in order 2N/A** to create a function named "x_coalesce". This function does the same thing 2N/A** as the "coalesce" function. This function also registers an SQL function 2N/A** named "x_sqlite_exec" that invokes sqlite_exec(). Invoking sqlite_exec() 2N/A** in this way is illegal recursion and should raise an SQLITE_MISUSE error. 2N/A** The effect is similar to trying to use the same database connection from 2N/A** two threads at the same time. 2N/A** The original motivation for this routine was to be able to call the 2N/A** sqlite_create_function function while a query is in progress in order 2N/A** to test the SQLITE_MISUSE detection logic. 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A** Routines to implement the x_count() aggregate function. 2N/A** Usage: sqlite_test_create_aggregate DB 2N/A** Call the sqlite_create_function API on the given database in order 2N/A** to create a function named "x_count". This function does the same thing 2N/A** as the "md5sum" function. 2N/A** The original motivation for this routine was to be able to call the 2N/A** sqlite_create_aggregate function while a query is in progress in order 2N/A** to test the SQLITE_MISUSE detection logic. 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A** Usage: sqlite_mprintf_int FORMAT INTEGER INTEGER INTEGER 2N/A** Call mprintf with three integer arguments 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A " FORMAT INT INT INT\"", 0);
2N/A** Usage: sqlite_mprintf_str FORMAT INTEGER INTEGER STRING 2N/A** Call mprintf with two integer arguments and one string argument 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A " FORMAT INT INT ?STRING?\"", 0);
2N/A** Usage: sqlite_mprintf_str FORMAT INTEGER INTEGER DOUBLE 2N/A** Call mprintf with two integer arguments and one double argument 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A " FORMAT INT INT STRING\"", 0);
2N/A** Usage: sqlite_mprintf_str FORMAT DOUBLE DOUBLE 2N/A** Call mprintf with a single double argument which is the product of the 2N/A** two arguments given above. This is used to generate overflow and underflow 2N/A** doubles to test that they are converted properly. 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A " FORMAT DOUBLE DOUBLE\"", 0);
2N/A** Usage: sqlite_malloc_fail N 2N/A** Rig sqliteMalloc() to fail on the N-th call. Turn off this mechanism 2N/A** and reset the sqlite_malloc_failed variable is N==0. 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A** Usage: sqlite_malloc_stat 2N/A** Return the number of prior calls to sqliteMalloc() and sqliteFree(). 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A** Usage: sqlite_abort 2N/A** Shutdown the process immediately. This is not a clean shutdown. 2N/A** This command is used to test the recoverability of a database in 2N/A** the event of a program crash. 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A** The following routine is a user-defined SQL function whose purpose 2N/A** is to test the sqlite_set_result() API. 2N/A "may not be NULL", -
1);
2N/A "first argument is not \"string\"", -
1);
2N/A "string int double", -
1);
2N/A** Usage: sqlite_register_test_function DB NAME 2N/A** Register the test SQL function on the database DB under the name NAME. 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A " DB FUNCTION-NAME", 0);
2N/A** This SQLite callback records the datatype of all columns. 2N/A** The pArg argument is really a pointer to a TCL interpreter. The 2N/A** column names are inserted as the result of this interpreter. 2N/A** This routine returns non-zero which causes the query to abort. 2N/A** Invoke an SQL statement but ignore all the data in the result. Instead, 2N/A** return a list that consists of the datatypes of the various columns. 2N/A** This only works if "PRAGMA show_datatypes=on" has been executed against 2N/A** the database connection. 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A** Usage: sqlite_compile DB SQL ?TAILVAR? 2N/A** Attempt to compile an SQL statement. Return a pointer to the virtual 2N/A** machine used to execute that statement. Unprocessed SQL is written 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A " DB SQL TAILVAR", 0);
2N/A** Usage: sqlite_step VM ?NVAR? ?VALUEVAR? ?COLNAMEVAR? 2N/A** Step a virtual machine. Return a the result code as a string. 2N/A** Column results are written into three variables. 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A " VM NVAR VALUEVAR COLNAMEVAR", 0);
2N/A for(i=0; i<N*
2; i++){
2N/A default:
zRc =
"unknown";
break;
2N/A** Usage: sqlite_finalize VM 2N/A** Shutdown a virtual machine. 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A** Usage: sqlite_reset VM 2N/A** Reset a virtual machine and prepare it to be run again. 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A** This is the "static_bind_value" that variables are bound to when 2N/A** the FLAG option of sqlite_bind is "static" 2N/A** Usage: sqlite_bind VM IDX VALUE FLAGS 2N/A** Sets the value of the IDX-th occurance of "?" in the original SQL 2N/A** string. VALUE is the new value. If FLAGS=="null" then VALUE is 2N/A** ignored and the value is set to NULL. If FLAGS=="static" then 2N/A** the value is set to the value of a static variable named 2N/A** "sqlite_static_bind_value". If FLAGS=="normal" then a copy 2N/A** of the VALUE is made. 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A " VM IDX VALUE (null|static|normal)\"", 0);
2N/A "\"null\" or \"static\" or \"normal\"", 0);
2N/A** This routine exists for one purpose - to provide a place to put a 2N/A** breakpoint with GDB that can be triggered using TCL code. The use 2N/A** for this is when a particular test fails on (say) the 1485th iteration. 2N/A** In the TCL test script, we can add code like this: 2N/A** if {$i==1485} breakpoint 2N/A** Then run testfixture in the debugger and wait for the breakpoint to 2N/A** fire. Then additional breakpoints can be set to trace down the bug. 2N/A int argc,
/* Number of arguments */ 2N/A char **
argv /* Text of each argument */ 2N/A** Register commands with the TCL interpreter.