QgsOgrProvider: fix query encoding issues

old title: fix encoding issue of spatial index creation (fix #7794)