847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
|
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
|
arg=sqlite3_str_errcode(str);
info->idxStr=sqlite3_str_finish(str);
info->needToFreeIdxStr=1;
return arg;
}
static int vt1_objects_update(sqlite3_vtab*vt,int argc,sqlite3_value**argv,sqlite3_int64*rowid) {
sqlite3_int64 id;
int x,y,z;
if(!main_options['e']) return SQLITE_LOCKED;
if(argc==1) {
// DELETE
id=sqlite3_value_int64(argv[0]);
pfunlink(id);
free(objects[id]);
objects[id]=0;
} else if(sqlite3_value_type(argv[0])==SQLITE_NULL) {
// INSERT
if(sqlite3_value_type(argv[1])!=SQLITE_NULL || sqlite3_value_type(argv[2])!=SQLITE_NULL) return SQLITE_CONSTRAINT_VTAB;
if(sqlite3_value_type(argv[3])==SQLITE_NULL) return SQLITE_CONSTRAINT_NOTNULL;
if(sqlite3_value_type(argv[7])==SQLITE_NULL) return SQLITE_CONSTRAINT_NOTNULL;
if(sqlite3_value_type(argv[11])!=SQLITE_NULL) return SQLITE_CONSTRAINT_VTAB;
if(sqlite3_value_type(argv[12])!=SQLITE_NULL) return SQLITE_CONSTRAINT_VTAB;
x=sqlite3_value_int(argv[9]);
y=sqlite3_value_int(argv[10]);
if(x<1 || x>pfwidth || y<1 || y>pfheight) return SQLITE_CONSTRAINT_CHECK;
z=sqlite3_value_type(argv[3]);
if(z<=0 || z>=0x4000 || !classes[z]) return SQLITE_CONSTRAINT_FOREIGNKEY;
if(sqlite3_value_int(argv[7])<0 || sqlite3_value_int(argv[7])>=classes[z]->nimages) return SQLITE_CONSTRAINT_CHECK;
id=objalloc(z);
if(id==VOIDLINK) return SQLITE_CONSTRAINT_VTAB;
goto update;
} else {
// UPDATE
id=sqlite3_value_int64(argv[0]);
if(id!=sqlite3_value_int64(argv[1]) || id!=sqlite3_value_int64(argv[2])) return SQLITE_CONSTRAINT_VTAB;
if(sqlite3_value_type(argv[3])==SQLITE_NULL) return SQLITE_CONSTRAINT_NOTNULL;
if(sqlite3_value_type(argv[7])==SQLITE_NULL) return SQLITE_CONSTRAINT_NOTNULL;
x=sqlite3_value_int(argv[9]);
y=sqlite3_value_int(argv[10]);
if(x<1 || x>pfwidth || y<1 || y>pfheight) return SQLITE_CONSTRAINT_CHECK;
if(sqlite3_value_int(argv[3])!=objects[id]->class) return SQLITE_CONSTRAINT_VTAB;
if(sqlite3_value_int(argv[13])!=objects[id]->density) return SQLITE_CONSTRAINT_VTAB;
z=objects[id]->class;
if(sqlite3_value_int(argv[7])<0 || sqlite3_value_int(argv[7])>=classes[z]->nimages) return SQLITE_CONSTRAINT_CHECK;
if(x!=objects[id]->x || y!=objects[id]->y) {
pfunlink(id);
update:
objects[id]->x=x;
objects[id]->y=y;
pflink(id);
}
objects[id]->image=sqlite3_value_int(argv[7]);
objects[id]->dir=sqlite3_value_int(argv[8])&7;
objects[id]->misc1.u=sqlite3_value_int64(argv[4])&0xFFFF;
objects[id]->misc1.t=sqlite3_value_int64(argv[4])>>32;
if(objects[id]->misc1.t&~3) objects[id]->misc1=NVALUE(0);
objects[id]->misc2.u=sqlite3_value_int64(argv[5])&0xFFFF;
objects[id]->misc2.t=sqlite3_value_int64(argv[5])>>32;
if(objects[id]->misc2.t&~3) objects[id]->misc2=NVALUE(0);
objects[id]->misc3.u=sqlite3_value_int64(argv[6])&0xFFFF;
objects[id]->misc3.t=sqlite3_value_int64(argv[6])>>32;
if(objects[id]->misc3.t&~3) objects[id]->misc3=NVALUE(0);
}
return SQLITE_OK;
}
Module(vt_objects,
.xBestIndex=vt1_objects_index,
.xColumn=vt1_objects_column,
.xFilter=vt1_objects_filter,
|