Index: TODO ================================================================== --- TODO +++ TODO @@ -31,5 +31,7 @@ * Level 232 of SUPERHRO puzzle set (the Lava shouldn't expand? why?) * Display solution comments/timestamp * VCR mode * Portable mode, not needing installing files in home directory * Command-line switch for batch import/export levels +* SQL + * Implement the GROUP column in the CLASSES table Index: function.c ================================================================== --- function.c +++ function.c @@ -35,10 +35,21 @@ } static void fn_cacheid(sqlite3_context*cxt,int argc,sqlite3_value**argv) { sqlite3_result_int64(cxt,*(sqlite3_int64*)sqlite3_user_data(cxt)); } + +static void fn_cl(sqlite3_context*cxt,int argc,sqlite3_value**argv) { + int a; + const char*s=sqlite3_value_text(*argv); + if(!s) return; + for(a=1;a<0x4000;a++) { + if(classes[a] && !(classes[a]->cflags&CF_NOCLASS2) && !strcmp(s,classes[a]->name)) goto found; + } + return; + found: sqlite3_result_int(cxt,a); +} static void fn_class_data(sqlite3_context*cxt,int argc,sqlite3_value**argv) { int id=sqlite3_value_int(argv[0]); Class*cl; if(id<0 || id>=0x4000 || !classes[id]) return; @@ -950,10 +961,11 @@ .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,"CL",1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_cl,0,0); sqlite3_create_function(userdb,"CLASS_DATA",2,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_class_data,0,0); sqlite3_create_function(userdb,"CVALUE",1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_cvalue,0,0); sqlite3_create_function(userdb,"HEROMESH_ESCAPE",1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_heromesh_escape,0,0); sqlite3_create_function(userdb,"HEROMESH_TYPE",1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_heromesh_type,0,0); sqlite3_create_function(userdb,"HEROMESH_UNESCAPE",1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_heromesh_unescape,0,0); Index: sql.doc ================================================================== --- sql.doc +++ sql.doc @@ -9,10 +9,15 @@ BASENAME() The base name, which is a copy of the first command-line argument (not counting the switches or the program name). +CL(text) + Returns the class number, given the class name. If there is no such + class, then the result is null. (This may be useful as a shortcut when + used with the "OBJECTS" or "CLASSES" table.) + CLASS_DATA(id,info) Returns data about a class. CVALUE(number) Makes a game value of type 'class', given the class number. You can also