︙ | | | ︙ | |
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#include "heromesh.h"
static const char schema[]=
"BEGIN;"
"PRAGMA APPLICATION_ID(1296388936);"
"PRAGMA RECURSIVE_TRIGGERS(1);"
"CREATE TABLE IF NOT EXISTS `USERCACHEINDEX`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT, `TIME` INT);"
"CREATE TABLE IF NOT EXISTS `USERCACHEDATA`(`ID` INTEGER PRIMARY KEY, `FILE` INT, `LEVEL` INT, `NAME` TEXT, `OFFSET` INT, `DATA` BLOB, `USERSTATE` BLOB);"
"CREATE UNIQUE INDEX IF NOT EXISTS `USERCACHEDATA_I1` ON `USERCACHEDATA`(`FILE`, `LEVEL`);"
"CREATE TEMPORARY TABLE `PICTURES`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT, `OFFSET` INT);"
"CREATE TEMPORARY TABLE `VARIABLES`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT);"
"COMMIT;"
;
sqlite3*userdb;
xrm_db*resourcedb;
const char*basefilename;
|
|
|
|
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#include "heromesh.h"
static const char schema[]=
"BEGIN;"
"PRAGMA APPLICATION_ID(1296388936);"
"PRAGMA RECURSIVE_TRIGGERS(1);"
"CREATE TABLE IF NOT EXISTS `USERCACHEINDEX`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT, `TIME` INT);"
"CREATE TABLE IF NOT EXISTS `USERCACHEDATA`(`ID` INTEGER PRIMARY KEY, `FILE` INT, `LEVEL` INT, `NAME` TEXT COLLATE NOCASE, `OFFSET` INT, `DATA` BLOB, `USERSTATE` BLOB);"
"CREATE UNIQUE INDEX IF NOT EXISTS `USERCACHEDATA_I1` ON `USERCACHEDATA`(`FILE`, `LEVEL`);"
"CREATE TEMPORARY TABLE `PICTURES`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT COLLATE NOCASE, `OFFSET` INT);"
"CREATE TEMPORARY TABLE `VARIABLES`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT);"
"COMMIT;"
;
sqlite3*userdb;
xrm_db*resourcedb;
const char*basefilename;
|
︙ | | | ︙ | |
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
sqlite3_bind_int(st,2,lvl);
sqlite3_bind_text(st,3,lvl==LUMP_CLASS_DEF?"CLASS.DEF":lvl==LUMP_LEVEL_IDX?"LEVEL.IDX":sol?".SOL":".LVL",-1,SQLITE_STATIC);
sqlite3_bind_blob64(st,4,data,sz,0);
while((e=sqlite3_step(st))==SQLITE_ROW);
if(e!=SQLITE_DONE) fatal("SQL error (%d): %s\n",e,sqlite3_errmsg(userdb));
sqlite3_finalize(st);
}
static void init_usercache(void) {
sqlite3_stmt*st;
int z;
sqlite3_int64 t1,t2;
char*nam1;
char*nam2;
|
>
>
>
>
|
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
sqlite3_bind_int(st,2,lvl);
sqlite3_bind_text(st,3,lvl==LUMP_CLASS_DEF?"CLASS.DEF":lvl==LUMP_LEVEL_IDX?"LEVEL.IDX":sol?".SOL":".LVL",-1,SQLITE_STATIC);
sqlite3_bind_blob64(st,4,data,sz,0);
while((e=sqlite3_step(st))==SQLITE_ROW);
if(e!=SQLITE_DONE) fatal("SQL error (%d): %s\n",e,sqlite3_errmsg(userdb));
sqlite3_finalize(st);
}
static void flush_usercache(void) {
}
static void init_usercache(void) {
sqlite3_stmt*st;
int z;
sqlite3_int64 t1,t2;
char*nam1;
char*nam2;
|
︙ | | | ︙ | |
440
441
442
443
444
445
446
447
448
449
450
451
452
453
|
}
break;
case SDL_QUIT:
exit(0);
break;
}
}
int main(int argc,char**argv) {
int optind=1;
while(argc>optind && argv[optind][0]=='-') {
int i;
const char*s=argv[optind++];
if(s[1]=='-' && !s[2]) break;
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
|
}
break;
case SDL_QUIT:
exit(0);
break;
}
}
static void do_sql_mode(void) {
int m=sqlite3_limit(userdb,SQLITE_LIMIT_SQL_LENGTH,-1);
char*txt=malloc(m);
int n=0;
int c;
int bail=1;
if(m>1000000) m=1000000;
txt=malloc(m+2);
if(!txt) fatal("Allocation failed\n");
for(;;) {
c=fgetc(stdin);
if(c=='\n' || c==EOF) {
if(!n) continue;
if(*txt=='#') {
n=0;
} else if(*txt=='.') {
txt[n]=0;
n=0;
switch(txt[1]) {
case 'b': bail=strtol(txt+2,0,0); break;
case 'f': sqlite3_db_cacheflush(userdb); sqlite3_db_release_memory(userdb); break;
case 'i': puts(sqlite3_db_filename(userdb,"main")); break;
case 'q': exit(0); break;
case 'u': flush_usercache(); break;
case 'x': sqlite3_enable_load_extension(userdb,strtol(txt+2,0,0)); break;
default: fatal("Invalid dot command .%c\n",txt[1]);
}
} else {
txt[n]=0;
if(sqlite3_complete(txt)) {
n=sqlite3_exec(userdb,txt,test_sql_callback,0,0);
if(bail && n) fatal("SQL error (%d): %s\n",n,sqlite3_errmsg(userdb));
n=0;
} else {
txt[n++]='\n';
}
}
if(c==EOF) break;
} else {
txt[n++]=c;
}
if(n>=m) fatal("Too long SQL statement\n");
}
if(n) fatal("Unterminated SQL statement\n");
free(txt);
}
int main(int argc,char**argv) {
int optind=1;
while(argc>optind && argv[optind][0]=='-') {
int i;
const char*s=argv[optind++];
if(s[1]=='-' && !s[2]) break;
|
︙ | | | ︙ | |
479
480
481
482
483
484
485
486
487
488
|
load_pictures();
if(main_options['T']) {
test_mode();
return 0;
}
init_usercache();
load_classes();
return 0;
}
|
>
>
>
>
>
|
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
|
load_pictures();
if(main_options['T']) {
test_mode();
return 0;
}
init_usercache();
load_classes();
if(main_options['x']) {
fprintf(stderr,"Ready for executing SQL statements.\n");
do_sql_mode();
return 0;
}
return 0;
}
|