def build_limit_clause(limit):
  """Build limit clause for a query."""

  if not limit:
    return '', {}

  if not isinstance(limit, tuple):
    limit = (limit,)

  bind_vars = {'limit_row_count': limit[0]}
  if len(limit) == 1:
    return 'LIMIT %(limit_row_count)s', bind_vars

  bind_vars = {'limit_offset': limit[0],
               'limit_row_count': limit[1]}
  return 'LIMIT %(limit_offset)s,%(limit_row_count)s', bind_vars