I am trying to count features that have the text "Fehler" in a certain field. This only works, when using the OGRSQL-dialect, but returns None when using SQLITE. I want to use the SQLITE-dialect, because I am looping over several SQL-Strings, and some of them contain SUM(LENGTH)/1000, which only works in SQLITE, and not with OGRSQL. I am using Python 2.7.5 an gdal 2.1.3 Here is the code that I am using:
import os
try:
from osgeo import ogr
from osgeo import gdal
except:
sys.exit("Failed to import OGR-module. Please check the GDAL-Installation!")
srcFile = r"D:\Didi\Tmp\OGR_Select_Bug\Export.shp"
driver = ogr.GetDriverByName('ESRI Shapefile')
destFileDS = driver.Open(srcFile, 0)
sql = u"SELECT COUNT(*) as Anzahl from %s WHERE rstatus like '%%Fehler'" % (os.path.basename(srcFile)[:-4])
#Works
actLayer = destFileDS.ExecuteSQL(statement=sql.encode('utf-8'), dialect='OGRSQL')
actFeat = actLayer.GetNextFeature()
destFileDS.ReleaseResultSet(actLayer)
#Returns none
actLayer = destFileDS.ExecuteSQL(statement=sql.encode('utf-8'), dialect='SQLITE')
actFeat = actLayer.GetNextFeature()
destFileDS.ReleaseResultSet(actLayer)