Fix (again) infinite loop in CDB_QueryStatements

CDB-1797 #resolve