I need to perform SQL query which will get products from database based on few dimensions which I will pass in URL.import itertoolssql_where = ''dimensions = ['a','b', 'c', 'd', 'e', 'f', 'f2', 'g']for dimension in dimensions:    for onetwo, direction in zip( range(1, 3), itertools.cycle('><') ):        globals()[dimension+str(onetwo)] = str( request.GET.get( dimension+str(onetwo) ) )        sql_where +=  AND ( `{dimension}` {direction}= '{get_dimension}' OR '{get_dimension}' = ('None' OR '') ).format(dimension=dimension, direction=direction, get_dimension=globals()[dimension+str(onetwo)])sql = SELECT * FROM t_wishbone_dimensions WHERE 1=1 + sql_whereprint sqlExample output for /search?a1=34&a2=37&c1=50&c2=75SELECT * FROM t_wishbone_dimensions WHERE 1=1 AND ( `a` >= '34' OR '34' = ('None' OR '') ) AND ( `a` <= '37' OR '37' = ('None' OR '') ) AND ( `b` >= 'None' OR 'None' = ('None' OR '') ) AND ( `b` <= 'None' OR 'None' = ('None' OR '') ) AND ( `c` >= '50' OR '50' = ('None' OR '') ) AND ( `c` <= '75' OR '75' = ('None' OR '') ) AND ( `d` >= 'None' OR 'None' = ('None' OR '') ) AND ( `d` <= 'None' OR 'None' = ('None' OR '') ) AND ( `e` >= 'None' OR 'None' = ('None' OR '') ) AND ( `e` <= 'None' OR 'None' = ('None' OR '') ) AND ( `f` >= 'None' OR 'None' = ('None' OR '') ) AND ( `f` <= 'None' OR 'None' = ('None' OR '') ) AND ( `f2` >= 'None' OR 'None' = ('None' OR '') ) AND ( `f2` <= 'None' OR 'None' = ('None' OR '') ) AND ( `g` >= 'None' OR 'None' = ('None' OR '') ) AND ( `g` <= 'None' OR 'None' = ('None' OR '') )What do you think about my solution?
Generate SQL query by loop
python;mysql