LJ Archive
def build_query( cnx, TableName, qfields,\
 form ) :
 ###########
  q = "Select * from " + TableName
  if len( qfields ) > 0 :
   q = q + " where "
   order = None
   for h in qfields :
      if order is not None :
         q = q + " and "
      else :
         order = " order by " + h
         val = form[ h ]
      if h[ -3: ] = "num" :
         q = q + h + "  " + val
      else :
         # Faster than a wildcard
         # search when indexed ?
         q = q + h + " > '" + val\
         + "' and " + h +"\
         <'" + val[ :-1 ] +\
         chr( ord( val[ -1 ] )\
          + 1 ) + "'"
   q = q + order
return q
LJ Archive