Index: main.c ================================================================== --- main.c +++ main.c @@ -73,11 +73,10 @@ static sqlite3_int64 reset_usercache(FILE*fp,const char*nam,struct stat*stats,const char*suffix) { sqlite3_stmt*st; sqlite3_int64 t,id; char buf[128]; int i,z; - if(z=sqlite3_exec(userdb,"BEGIN;",0,0,0)) fatal("SQL error (%d): %s\n",z,sqlite3_errmsg(userdb)); if(z=sqlite3_prepare_v2(userdb,"DELETE FROM `USERCACHEDATA` WHERE `FILE` = (SELECT `ID` FROM `USERCACHEINDEX` WHERE `NAME` = ?1);",-1,&st,0)) { fatal("SQL error (%d): %s\n",z,sqlite3_errmsg(userdb)); } sqlite3_bind_text(st,1,nam,-1,0); while((z=sqlite3_step(st))==SQLITE_ROW); @@ -134,11 +133,10 @@ if(z!=SQLITE_DONE) fatal("SQL error (%d): %s\n",z,sqlite3_errmsg(userdb)); fseek(fp,t,SEEK_CUR); } done: sqlite3_finalize(st); - if(z=sqlite3_exec(userdb,"COMMIT;",0,0,0)) fatal("SQL error (%d): %s\n",z,sqlite3_errmsg(userdb)); return id; } unsigned char*read_lump(int sol,int lvl,long*sz,sqlite3_value**us) { // Returns a pointer to the data; must be freed using free(). @@ -203,10 +201,11 @@ char*nam1; char*nam2; char*nam3; struct stat fst; fprintf(stderr,"Initializing user cache...\n"); + if(z=sqlite3_exec(userdb,"BEGIN;",0,0,0)) fatal("SQL error (%d): %s\n",z,sqlite3_errmsg(userdb)); if(z=sqlite3_prepare_v2(userdb,"SELECT `ID`, `TIME` FROM `USERCACHEINDEX` WHERE `NAME` = ?1;",-1,&st,0)) fatal("SQL error (%d): %s\n",z,sqlite3_errmsg(userdb)); nam1=sqlite3_mprintf("%s.level",basefilename); if(!nam1) fatal("Allocation failed\n"); nam2=realpath(nam1,0); if(!nam2) fatal("Cannot find real path of '%s': %m\n",nam1); @@ -252,10 +251,11 @@ free(nam2); free(nam3); if(z=sqlite3_prepare_v3(userdb,"SELECT * FROM `USERCACHEDATA` WHERE `FILE` = ?1 AND `LEVEL` = ?2;",-1,SQLITE_PREPARE_PERSISTENT,&readusercachest,0)) { fatal("SQL error (%d): %s\n",z,sqlite3_errmsg(userdb)); } + if(z=sqlite3_exec(userdb,"COMMIT;",0,0,0)) fatal("SQL error (%d): %s\n",z,sqlite3_errmsg(userdb)); fprintf(stderr,"Done\n"); } static void init_sql(void) { char*s; Index: picture.c ================================================================== --- picture.c +++ picture.c @@ -229,11 +229,11 @@ if(!j) break; if(i<2 || i>255) fatal("Invalid picture size %d\n",i); wantsize[nwantsize++]=i; v+=j; } - sqlite3_exec(userdb,"BEGIN;",0,0,0); + if(n=sqlite3_exec(userdb,"BEGIN;",0,0,0)) fatal("SQL error (%d): %s\n",n,sqlite3_errmsg(userdb)); if(sqlite3_prepare_v2(userdb,"INSERT INTO `PICTURES`(`ID`,`NAME`,`OFFSET`) VALUES(?1,?2,?3);",-1,&st,0)) fatal("Unable to prepare SQL statement while loading pictures: %s\n",sqlite3_errmsg(userdb)); nam=malloc(256); if(!nam) fatal("Allocation failed\n"); n=0; @@ -297,13 +297,13 @@ fseek(fp,sqlite3_column_int64(st,1),SEEK_SET); load_one_picture(fp,sqlite3_column_int(st,0),altImage); } sqlite3_finalize(st); fclose(fp); - sqlite3_exec(userdb,"COMMIT;",0,0,0); SDL_SetColorKey(picts,SDL_SRCCOLORKEY|SDL_RLEACCEL,0); done: + if(n=sqlite3_exec(userdb,"COMMIT;",0,0,0)) fatal("SQL error (%d): %s\n",n,sqlite3_errmsg(userdb)); fprintf(stderr,"Done\n"); } void init_screen(void) { const char*v;