1
0
forked from MTSR/mapserver

case insensitive search

This commit is contained in:
NatureFreshMilk 2019-06-11 13:26:19 +02:00
parent 5fb55a5257
commit 778faec22f
2 changed files with 64 additions and 1 deletions

View File

@ -20,7 +20,7 @@ select o.id, o.type, o.mtime,
from objects o
left join object_attributes oa on o.id = oa.objectid
where o.id in (
select objectid from object_attributes where key = $8 and value like $9
select objectid from object_attributes where key = $8 and value ilike $9
)
and o.type = $1
and o.posx >= $2 and o.posy >= $3 and o.posz >= $4

View File

@ -144,3 +144,66 @@ func TestMapObjectsQueryWithAttribute(t *testing.T) {
panic("length mismatch")
}
}
func TestMapObjectsQueryWithAttributeIgnoreCase(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "TestMapObjects.*.sqlite")
if err != nil {
panic(err)
}
//defer os.Remove(tmpfile.Name())
db, err := New(tmpfile.Name())
if err != nil {
panic(err)
}
err = db.Migrate()
if err != nil {
panic(err)
}
attrs := make(map[string]string)
attrs["X"] = "ABC"
pos := coords.NewMapBlockCoords(0, 0, 0)
o := mapobjectdb.MapObject{
MBPos: pos,
X: 15,
Y: 15,
Z: 15,
Type: "xy",
Mtime: 1234,
Attributes: attrs,
}
err = db.AddMapData(&o)
if err != nil {
panic(err)
}
q := mapobjectdb.SearchQuery{
Pos1: pos,
Pos2: pos,
Type: "xy",
AttributeLike: &mapobjectdb.SearchAttributeLike{
Key: "X",
Value: "%bc",
},
}
objs, err := db.GetMapData(&q)
if err != nil {
panic(err)
}
for _, mo := range objs {
fmt.Println(mo)
}
if len(objs) != 1 {
panic("length mismatch")
}
}