Blame db/parser.py

4656ad
4656ad
4656ad
def parse(typebychar, connection, text, *args, **kvargs):
4656ad
  i = iter(text)
4656ad
  index = 0
4656ad
  result = ''
4656ad
  try:
4656ad
    while True:
4656ad
      try: c = next(i)
4656ad
      except StopIteration: break
4656ad
      if c == '%':
4656ad
        c = next(i)
4656ad
        if c == '(':
4656ad
          field = ''
4656ad
          while True:
4656ad
            c = next(i)
4656ad
            if c == ')': break
4656ad
            field += c
4656ad
          c = next(i)
4656ad
          result += typebychar[c].to_db(connection, kvargs[field])
4656ad
        elif c == '%':
4656ad
          result += '%'
4656ad
        else:
4656ad
          result += typebychar[c].to_db(connection, args[index])
4656ad
          index += 1
4656ad
      else:
4656ad
        result += c
4656ad
  except StopIteration:
4656ad
    raise Exception('unexpeted end of sql template')
4656ad
  return result
4656ad