Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/tool/rollback-test.c # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / tool / rollback-test.c` 155 lines ยท 4400 bytes Raw Blame History 1 /* 2 ** This program is used to generate and verify databases with hot journals. 3 ** Use this program to generate a hot journal on one machine and verify 4 ** that it rolls back correctly on another machine with a different 5 ** architecture. 6 ** 7 ** Usage: 8 ** 9 ** rollback-test new [-utf8] [-utf16le] [-utf16be] [-pagesize=N] DATABASE 10 ** rollback-test check DATABASE 11 ** rollback-test crash [-wal] [-rollback] DATABASE 12 */ 13 #include 14 #include 15 #include 16 #include "sqlite3.h" 17 18 static void usage(char *argv0){ 19 fprintf(stderr, 20 "Usage: %s new [-utf8] [-utf16le] [-utf16be] [-pagesize=N] DATABASE\n" 21 " %s check DATABASE\n" 22 " %s crash [-wal] DATABASE\n", 23 argv0, argv0, argv0 24 ); 25 exit(1); 26 } 27 28 static sqlite3 *openDb(const char *zFilename){ 29 int rc; 30 sqlite3 *db; 31 rc = sqlite3_open(zFilename, &db); 32 if( rc ){ 33 fprintf(stderr, "Cannot open \"%s\": %s\n", 34 zFilename, sqlite3_errmsg(db)); 35 sqlite3_close(db); 36 exit(1); 37 } 38 return db; 39 } 40 41 static int nReply = 0; 42 static char zReply[1000]; 43 44 static int execCallback(void *NotUsed, int nArg, char **azArg, char **azCol){ 45 int i, n; 46 char *z; 47 for(i=0; i0 && nReply=sizeof(zReply)-1 ) n = sizeof(zReply) - nReply - 1; 53 memcpy(&zReply[nReply], z, n); 54 nReply += n; 55 zReply[nReply] = 0; 56 } 57 return 0; 58 } 59 60 static void runSql(sqlite3 *db, const char *zSql){ 61 char *zErr = 0; 62 int rc; 63 nReply = 0; 64 rc = sqlite3_exec(db, zSql, execCallback, 0, &zErr); 65 if( zErr ){ 66 fprintf(stderr, "SQL error: %s\n", zErr); 67 exit(1); 68 } 69 if( rc ){ 70 fprintf(stderr, "SQL error: %s\n", sqlite3_errmsg(db)); 71 exit(1); 72 } 73 } 74 75 int main(int argc, char **argv){ 76 sqlite3 *db; 77 int i; 78 79 if( argc<3 ) usage(argv[0]); 80 if( strcmp(argv[1], "new")==0 ){ 81 db = openDb(argv[argc-1]); 82 for(i=2; i('abcdefghijklmnopqrstuvwxyz' || x)" 127 ); 128 if( strcmp(zReply, "0")!=0 ){ 129 fprintf(stderr, "Wrong content\n"); 130 exit(1); 131 } 132 printf("Ok\n"); 133 }else if( strcmp(argv[1], "crash")==0 ){ 134 db = openDb(argv[argc-1]); 135 for(i=2; i