Overview
Comment: | Add some more SQL functions, and a stub for a SQL virtual table (not yet completed). |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
5522aef2ab34accd32ce29886895c1de |
User & Date: | user on 2018-07-22 19:28:20 |
Other Links: | manifest | tags |
Context
2018-07-22
| ||
20:19 | Add license notice about SDL1 check-in: fc64df1538 user: user tags: trunk | |
19:28 | Add some more SQL functions, and a stub for a SQL virtual table (not yet completed). check-in: 5522aef2ab user: user tags: trunk | |
2018-07-14
| ||
00:23 | Ensure each line of help text ends with a line break check-in: c1a1e6bede user: user tags: trunk | |
Changes
Modified function.c from [dee2ab208b] to [d312f6f623].
︙ | ︙ | |||
11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include "smallxrm.h" #include "heromesh.h" typedef struct { struct sqlite3_vtab_cursor; sqlite3_int64 rowid; char unique,eof; } Cursor; static void find_first_usable_image(const Class*cl,sqlite3_context*cxt) { int i; if(cl->cflags&CF_GROUP) return; if(!cl->images) return; for(i=0;i<cl->nimages;i++) { | > | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include "smallxrm.h" #include "heromesh.h" typedef struct { struct sqlite3_vtab_cursor; sqlite3_int64 rowid; char unique,eof; Uint8 arg[4]; } Cursor; static void find_first_usable_image(const Class*cl,sqlite3_context*cxt) { int i; if(cl->cflags&CF_GROUP) return; if(!cl->images) return; for(i=0;i<cl->nimages;i++) { |
︙ | ︙ | |||
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | case 84: sqlite3_result_int(cxt,cl->shovable); break; case 128: sqlite3_result_double(cxt,cl->volume/(double)max_volume); break; case 129: sqlite3_result_int(cxt,cl->uservars); break; case 130: sqlite3_result_int(cxt,cl->collisionLayers); break; case 132: sqlite3_result_int(cxt,cl->cflags&CF_COMPATIBLE?1:0); break; } } static void fn_modstate(sqlite3_context*cxt,int argc,sqlite3_value**argv) { sqlite3_result_int(cxt,SDL_GetModState()); } static void fn_picture_size(sqlite3_context*cxt,int argc,sqlite3_value**argv) { sqlite3_result_int(cxt,picture_size); } static void fn_read_lump_at(sqlite3_context*cxt,int argc,sqlite3_value**argv) { sqlite3_int64 of=sqlite3_value_int64(argv[0]); | > > > > > > > > > > > > > > > > > > > > > > > > > | 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | case 84: sqlite3_result_int(cxt,cl->shovable); break; case 128: sqlite3_result_double(cxt,cl->volume/(double)max_volume); break; case 129: sqlite3_result_int(cxt,cl->uservars); break; case 130: sqlite3_result_int(cxt,cl->collisionLayers); break; case 132: sqlite3_result_int(cxt,cl->cflags&CF_COMPATIBLE?1:0); break; } } static void fn_cvalue(sqlite3_context*cxt,int argc,sqlite3_value**argv) { int a; if(sqlite3_value_type(*argv)==SQLITE_NULL) return; a=sqlite3_value_int(*argv)&0xFFFF; sqlite3_result_int64(cxt,a|((sqlite3_int64)TY_CLASS<<32)); } static void fn_modstate(sqlite3_context*cxt,int argc,sqlite3_value**argv) { sqlite3_result_int(cxt,SDL_GetModState()); } static void fn_mvalue(sqlite3_context*cxt,int argc,sqlite3_value**argv) { int a; if(sqlite3_value_type(*argv)==SQLITE_NULL) return; a=sqlite3_value_int(*argv)&0xFFFF; sqlite3_result_int64(cxt,a|((sqlite3_int64)TY_MESSAGE<<32LL)); } static void fn_ovalue(sqlite3_context*cxt,int argc,sqlite3_value**argv) { Uint32 a; if(sqlite3_value_type(*argv)==SQLITE_NULL) { sqlite3_result_int(cxt,0); return; } a=sqlite3_value_int64(*argv)&0xFFFFFFFF; if(a>=nobjects || !objects[a] || (objects[a]->dir&IOF_DEAD)) return; // result is null if object does not exist sqlite3_result_int64(cxt,a|((sqlite3_int64)objects[a]->generation<<32)); } static void fn_picture_size(sqlite3_context*cxt,int argc,sqlite3_value**argv) { sqlite3_result_int(cxt,picture_size); } static void fn_read_lump_at(sqlite3_context*cxt,int argc,sqlite3_value**argv) { sqlite3_int64 of=sqlite3_value_int64(argv[0]); |
︙ | ︙ | |||
127 128 129 130 131 132 133 134 135 136 137 138 139 140 | static void fn_sign_extend(sqlite3_context*cxt,int argc,sqlite3_value**argv) { sqlite3_int64 a; if(sqlite3_value_type(*argv)==SQLITE_NULL) return; a=sqlite3_value_int64(*argv)&0xFFFFFFFF; sqlite3_result_int64(cxt,a-(a&0x80000000?0x100000000LL:0)); } static int vt0_close(sqlite3_vtab_cursor*cur) { sqlite3_free(cur); return SQLITE_OK; } static int vt0_connect(sqlite3*db,void*aux,int argc,const char*const*argv,sqlite3_vtab**vt,char**err) { | > > > > > > > | 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | static void fn_sign_extend(sqlite3_context*cxt,int argc,sqlite3_value**argv) { sqlite3_int64 a; if(sqlite3_value_type(*argv)==SQLITE_NULL) return; a=sqlite3_value_int64(*argv)&0xFFFFFFFF; sqlite3_result_int64(cxt,a-(a&0x80000000?0x100000000LL:0)); } static void fn_zero_extend(sqlite3_context*cxt,int argc,sqlite3_value**argv) { sqlite3_int64 a; if(sqlite3_value_type(*argv)==SQLITE_NULL) return; a=sqlite3_value_int64(*argv)&0xFFFFFFFF; sqlite3_result_int64(cxt,a); } static int vt0_close(sqlite3_vtab_cursor*cur) { sqlite3_free(cur); return SQLITE_OK; } static int vt0_connect(sqlite3*db,void*aux,int argc,const char*const*argv,sqlite3_vtab**vt,char**err) { |
︙ | ︙ | |||
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | Module(vt_classes, .xColumn=vt1_classes_column, .xFilter=vt1_classes_filter, .xNext=vt1_classes_next, .xUpdate=vt1_classes_update, ); void init_sql_functions(sqlite3_int64*ptr0,sqlite3_int64*ptr1) { sqlite3_create_function(userdb,"BASENAME",0,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_basename,0,0); sqlite3_create_function(userdb,"CLASS_DATA",2,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_class_data,0,0); sqlite3_create_function(userdb,"LEVEL_CACHEID",0,SQLITE_UTF8|SQLITE_DETERMINISTIC,ptr0,fn_cacheid,0,0); sqlite3_create_function(userdb,"MODSTATE",0,SQLITE_UTF8,0,fn_modstate,0,0); sqlite3_create_function(userdb,"PICTURE_SIZE",0,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_picture_size,0,0); sqlite3_create_function(userdb,"READ_LUMP_AT",2,SQLITE_UTF8,0,fn_read_lump_at,0,0); sqlite3_create_function(userdb,"RESOURCE",-1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_resource,0,0); sqlite3_create_function(userdb,"SIGN_EXTEND",1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_sign_extend,0,0); sqlite3_create_function(userdb,"SOLUTION_CACHEID",0,SQLITE_UTF8|SQLITE_DETERMINISTIC,ptr1,fn_cacheid,0,0); sqlite3_create_module(userdb,"CLASSES",&vt_classes,"CREATE TABLE `CLASSES`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT, `EDITORHELP` TEXT, `HELP` TEXT," "`INPUT` INT, `QUIZ` INT, `TRACEIN` INT, `TRACEOUT` INT, `GROUP` TEXT, `PLAYER` INT);"); sqlite3_create_module(userdb,"MESSAGES",&vt_messages,"CREATE TABLE `MESSAGES`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT, `TRACE` INT);"); } | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | Module(vt_classes, .xColumn=vt1_classes_column, .xFilter=vt1_classes_filter, .xNext=vt1_classes_next, .xUpdate=vt1_classes_update, ); static int vt1_objects_column(sqlite3_vtab_cursor*pcur,sqlite3_context*cxt,int n) { return SQLITE_OK; } static int vt1_objects_filter(sqlite3_vtab_cursor*pcur,int idxNum,const char*idxStr,int argc,sqlite3_value**argv) { return SQLITE_OK; } static int vt1_objects_index(sqlite3_vtab*vt,sqlite3_index_info*info) { return SQLITE_OK; } static int vt1_objects_next(sqlite3_vtab_cursor*pcur) { return SQLITE_OK; } static int vt1_objects_update(sqlite3_vtab*vt,int argc,sqlite3_value**argv,sqlite3_int64*rowid) { if(!main_options['e']) return SQLITE_LOCKED; return SQLITE_OK; } Module(vt_objects, .xBestIndex=vt1_objects_index, .xColumn=vt1_objects_column, .xFilter=vt1_objects_filter, .xNext=vt1_objects_next, .xUpdate=vt1_objects_update, ); void init_sql_functions(sqlite3_int64*ptr0,sqlite3_int64*ptr1) { sqlite3_create_function(userdb,"BASENAME",0,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_basename,0,0); sqlite3_create_function(userdb,"CLASS_DATA",2,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_class_data,0,0); sqlite3_create_function(userdb,"LEVEL_CACHEID",0,SQLITE_UTF8|SQLITE_DETERMINISTIC,ptr0,fn_cacheid,0,0); sqlite3_create_function(userdb,"MODSTATE",0,SQLITE_UTF8,0,fn_modstate,0,0); sqlite3_create_function(userdb,"CVALUE",1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_cvalue,0,0); sqlite3_create_function(userdb,"MVALUE",1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_mvalue,0,0); sqlite3_create_function(userdb,"NVALUE",1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_zero_extend,0,0); sqlite3_create_function(userdb,"OVALUE",1,SQLITE_UTF8,0,fn_ovalue,0,0); sqlite3_create_function(userdb,"PICTURE_SIZE",0,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_picture_size,0,0); sqlite3_create_function(userdb,"READ_LUMP_AT",2,SQLITE_UTF8,0,fn_read_lump_at,0,0); sqlite3_create_function(userdb,"RESOURCE",-1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_resource,0,0); sqlite3_create_function(userdb,"SIGN_EXTEND",1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_sign_extend,0,0); sqlite3_create_function(userdb,"SOLUTION_CACHEID",0,SQLITE_UTF8|SQLITE_DETERMINISTIC,ptr1,fn_cacheid,0,0); sqlite3_create_function(userdb,"ZERO_EXTEND",1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_zero_extend,0,0); sqlite3_create_module(userdb,"CLASSES",&vt_classes,"CREATE TABLE `CLASSES`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT, `EDITORHELP` TEXT, `HELP` TEXT," "`INPUT` INT, `QUIZ` INT, `TRACEIN` INT, `TRACEOUT` INT, `GROUP` TEXT, `PLAYER` INT);"); sqlite3_create_module(userdb,"MESSAGES",&vt_messages,"CREATE TABLE `MESSAGES`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT, `TRACE` INT);"); sqlite3_create_module(userdb,"OBJECTS",&vt_objects,"CREATE TABLE `OBJECTS`(`ID` INTEGER PRIMARY KEY, `CLASS` INT, `MISC1` INT, `MISC2` INT, `MISC3` INT," "`IMAGE` INT, `DIR` INT, `X` INT, `Y` INT, `UP` INT, `DOWN` INT, `DENSITY` INT HIDDEN);"); } |