/* ** This program is used to generate and verify databases with hot journals. ** Use this program to generate a hot journal on one machine and verify ** that it rolls back correctly on another machine with a different ** architecture. ** ** Usage: ** ** rollback-test new [-utf8] [-utf16le] [-utf16be] [-pagesize=N] DATABASE ** rollback-test check DATABASE ** rollback-test crash [-wal] [-rollback] DATABASE */ #include #include #include #include "sqlite3.h" static void usage(char *argv0){ fprintf(stderr, "Usage: %s new [-utf8] [-utf16le] [-utf16be] [-pagesize=N] DATABASE\n" " %s check DATABASE\n" " %s crash [-wal] DATABASE\n", argv0, argv0, argv0 ); exit(1); } static sqlite3 *openDb(const char *zFilename){ int rc; sqlite3 *db; rc = sqlite3_open(zFilename, &db); if( rc ){ fprintf(stderr, "Cannot open \"%s\": %s\n", zFilename, sqlite3_errmsg(db)); sqlite3_close(db); exit(1); } return db; } static int nReply = 0; static char zReply[1000]; static int execCallback(void *NotUsed, int nArg, char **azArg, char **azCol){ int i, n; char *z; for(i=0; i0 && nReply=sizeof(zReply)-1 ) n = sizeof(zReply) - nReply - 1; memcpy(&zReply[nReply], z, n); nReply += n; zReply[nReply] = 0; } return 0; } static void runSql(sqlite3 *db, const char *zSql){ char *zErr = 0; int rc; nReply = 0; rc = sqlite3_exec(db, zSql, execCallback, 0, &zErr); if( zErr ){ fprintf(stderr, "SQL error: %s\n", zErr); exit(1); } if( rc ){ fprintf(stderr, "SQL error: %s\n", sqlite3_errmsg(db)); exit(1); } } int main(int argc, char **argv){ sqlite3 *db; int i; if( argc<3 ) usage(argv[0]); if( strcmp(argv[1], "new")==0 ){ db = openDb(argv[argc-1]); for(i=2; i('abcdefghijklmnopqrstuvwxyz' || x)" ); if( strcmp(zReply, "0")!=0 ){ fprintf(stderr, "Wrong content\n"); exit(1); } printf("Ok\n"); }else if( strcmp(argv[1], "crash")==0 ){ db = openDb(argv[argc-1]); for(i=2; i