#pragma ident "%Z%%M% %I% %E% SMI"
/*
** This program tests the ability of SQLite database to recover from a crash.
** This program runs under Unix only, but the results are applicable to all
** systems.
**
** The main process first constructs a test database, then starts creating
** subprocesses that write to that database. Each subprocess is killed off,
** without a chance to clean up its database connection, after a random
** delay. This killing of the subprocesses simulates a crash or power
** failure. The next subprocess to open the database should rollback
** whatever operation was in process at the time of the simulated crash.
**
** If any problems are encountered, an error is reported and the test stops.
** If no problems are seen after a large number of tests, we assume that
** the rollback mechanism is working.
*/
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <sched.h>
#include "sqlite.h"
char *zErr;
int cnt = 0;
static char zBig[] =
"-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
"-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
if( access("./test.db-journal",0)==0 ){
/*printf("pid %d: journal exists. rollback will be required\n",getpid());*/ unlink("test.db-saved");
system("cp test.db test.db-saved");
unlink("test.db-journal-saved");
system("cp test.db-journal test.db-journal-saved");
}
if( db==0 ){
}
exit(1);
}
cnt++;
"INSERT INTO t1 VALUES(%d,'%d%s')", 0, 0, &zErr,
}
if( rc==SQLITE_CORRUPT ){
}
}
}
int i;
char *zErr;
int status;
unlink("test.db");
unlink("test.db-journal");
if( db==0 ){
return 1;
}
for(i=0; i<10000; i++){
if( pid==0 ){
sched_yield();
return 0;
}
}
return 0;
}