title: local variable 'sql' referenced before assignment
body: <p>Hi im trying to write a function using if/elif , i'm having trouble when trying to execute the final cursor function after the elif. I think my indent is wrong and i been trying to find where the mistake at over a day now :</p>
  
  <pre><code>def api_report(request):
      params = request.GET
      if params["type"] == 'revenue':
          sql = get_revenue_query(params)
  
      elif params["type"] == 'order_count':
          sql = get_order_created_count(params)
  
      elif params["type"] == 'product_count':
          sql = get_product_count(params)
  
      elif params["type"] == 'order_card_created_count':
          sql = get_order_card_created_count(params)
  
      elif params["type"] == 'product_count':
          sql = get_product_count(params)
  
      elif params["type"] == 'card':
          sql = get_card_query(params)
  
      elif params["type"] == 'order_not_card_created_count':
          sql = get_order_not_card_created_count(params)
  
      elif params["type"] == 'product':
          get_product_report(params)
  
      elif params["type"] == 'order_rate_by_district':
          sql = get_order_rate_by_district(params)
  
          with connection.cursor() as cursor:
              cursor.execute(sql)
              rows = cursor.fetchall()
              data = []
              for row in rows:
                  data.append(OrderRateDataEntry(row[0], row[1], row[2]))
          serializer = OrderRateDataEntrySerializer(data, many=True)
          return JsonResponse(serializer.data, safe=False)
  
      with connection.cursor() as cursor:
          cursor.execute(sql)
          rows = cursor.fetchall()
          data = []
          for row in rows:
              data.append(TimeSeriesDataEntry(row[0], row[1]))
      serializer = TimeSeriesDataEntrySerializer(data, many=True)
      return JsonResponse(serializer.data, safe=False)
  </code></pre>
  
  <p>The error:</p>
  
  <pre><code>cursor.execute(sql)  UnboundLocalError: 
      local variable 'sql' referenced before assignment
  </code></pre>
  
  <p>The <code>elif params["type"] == 'product':</code> and <code>elif params["type"] == 'order_rate_by_district':</code> have they own function to execute, I want the other conditions to jump to the last cursor function at the end of the code.</p>