Skip to content

Commit

Permalink
fix sql delete bug
Browse files Browse the repository at this point in the history
Signed-off-by: Doug Davis <[email protected]>
  • Loading branch information
duglin committed Jan 10, 2025
1 parent ff16788 commit 00d9259
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 5 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,15 @@ TODOs:
- add "validation" attribute - schema
- error w/o ?nested + children
- Add content-disposition header for hasdoc resources
- make sure ID only has valid chars
- inline=model, requires ?nested. Make sure /meta requires ?nested too
- add "compatibility" to resources
- multi-delete must ignore all attributes except id and epoch
- fix init.sql, it's too slow due to latest xref stuff in commit 9c583e7
- add support for inline=endpoints.*
- support ETag/If-Match
- update epoch/modifiedat of parent when nested entity is added/removed
- ?nested isn't needed to update `model` or `meta` attributes
- test to ensure meta epoch changes as versions are added/removed
- ?nested isn't needed to update `model` or `meta` attributes
- test the timestamps in meta. Should change as versions are added/removed.
- remove entities from cache upon delete
- test creating a resource + lots of versions w/o ?defaultversionid-should fail
Expand Down
22 changes: 22 additions & 0 deletions registry/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ func (e *Entity) Query(query string, args ...any) ([][]any, error) {
}

data := ([][]any)(nil)
/*
Ks := make([]string, len(results.colTypes))
for i, t := range results.colTypes {
Ks[i] = t.Kind().String()
}
*/

for row := results.NextRow(); row != nil; row = results.NextRow() {
if data == nil {
data = [][]any{}
Expand All @@ -292,6 +300,20 @@ func (e *Entity) Query(query string, args ...any) ([][]any, error) {
r := make([]any, len(row))
for i, d := range row {
r[i] = d
/*
k := Ks[i]
if k == "slice" {
r[i] = NotNilString(d)
} else if k == "int64" || k == "uint64" {
r[i] = NotNilInt(d)
} else {
log.Printf("%v", reflect.ValueOf(*d).Type().String())
log.Printf("%v", reflect.ValueOf(*d).Type().Kind().String())
log.Printf("Ks: %v", Ks)
log.Printf("i: %d", i)
panic("help")
}
*/
}
data = append(data, r)
}
Expand Down
2 changes: 1 addition & 1 deletion registry/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ CREATE TABLE Registries (
CREATE TRIGGER RegistryTrigger BEFORE DELETE ON Registries
FOR EACH ROW
BEGIN
DELETE FROM Props WHERE EntitySID=OLD.SID @
DELETE FROM Props WHERE RegistrySID=OLD.SID @
DELETE FROM "Groups" WHERE RegistrySID=OLD.SID @
DELETE FROM Models WHERE RegistrySID=OLD.SID @
END ;
Expand Down
2 changes: 1 addition & 1 deletion registry/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func NotNilString(val *any) string {
}

if reflect.ValueOf(*val).Kind() != reflect.Slice {
panic("Not a slice")
panic(fmt.Sprintf("Not a slice: %T (%#v)", *val, *val))
}

b := (*val).([]byte)
Expand Down
1 change: 1 addition & 0 deletions tests/http1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4720,6 +4720,7 @@ func TestHTTPEpochTimesAddRemove(t *testing.T) {
}
`)
}

func TestHTTPEnum(t *testing.T) {
reg := NewRegistry("TestHTTPEnum")
defer PassDeleteReg(t, reg)
Expand Down
1 change: 0 additions & 1 deletion tests/multireg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,4 @@ func TestMultiReg(t *testing.T) {
"versionscount": 1
}
`)

}
8 changes: 8 additions & 0 deletions tests/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ func PassDeleteReg(t *testing.T, reg *registry.Registry) {
// We do this to make sure that we can support more than
// one registry in the DB at a time
reg.Delete()

/*
rows, err := reg.Query("select * from Props")
if err != nil || len(rows) != 0 {
fmt.Printf("Rows: %s", ToJSON(rows))
panic(fmt.Sprintf("Props left around: %s / %d", err, len(rows)))
}
*/
}
registry.DefaultRegDbSID = ""
}
Expand Down

0 comments on commit 00d9259

Please sign in to comment.