-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
Closed as not planned
Closed as not planned
Copy link
Labels
type-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
import mysql.connector as SQL
mycon=SQL.connect(host='localhost',user='root',password='sa123',database='test_404')
if mycon.is_connected():
name=input('Name: ')
phone=int(input('Mobile No.: '))
cur=mycon.cursor()
cur.execute(f'INSERT INTO TEMP VALUES(1,\'{name}\',{phone})')
mycon.commit()
mycon.close()Introduce a standardized, safe, and ergonomic way to construct SQL queries using f-string-like syntax while preserving parameterization and protection against SQL injection.
Proposed Solution
Introduce a new SQL-aware formatted string literal, for example:
cursor.execute(sqlf"INSERT INTO TEMP VALUES(1,\'{name}\',{phone})")Under the hood, Python would:
- Extract embedded expressions
- Convert them into parameters
- Generate a driver-compatible query
- Pass parameters safely to the database driver
Benefits
- Prevents SQL injection by design
- Improves readability and developer productivity
- Reduces boilerplate
- Standardizes parameter style across drivers
- Helps beginners write secure database code
Backward Compatibility
No breaking changes. This would introduce a new literal form or library feature.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type-featureA feature request or enhancementA feature request or enhancement