-5

i have this SQL

default code is a string

cr.execute(
                    '''SELECT product FROM product_product
                       WHERE default_code = '%s' limit 1'''
                    % (default_code,)
                )

and linter gets me an erro E8103: SQL injection risk. Use parameters if you can.

same with other SQL

cr.execute(
                        f"SELECT id FROM product_supplierinfo"
                        f" WHERE product_tmpl_id = {str(product_tmpl)}"
                        f" AND name = {partner.id}"
                    )
Chaban33
  • 1,362
  • 11
  • 38
  • 1
    The linter is telling you the problem and the solution... your code (both examples) has an SQL injection risk and the solution is to use parameters (in both cases you can) – Jiří Baum Sep 09 '22 at 12:39

1 Answers1

2

It is recommended to set the queries this way:

query = """Update employee set Salary = %s where id = %s"""
tuple1 = (8000, 5)
cursor.execute(query, tuple1)

More info here: https://pynative.com/python-mysql-execute-parameterized-query-using-prepared-statement/

ssanga
  • 335
  • 3
  • 11