You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
...
sql = '''SELECT aa, bb, refresh_time FROM table_name_%03d WHERE id = %s ORDER BY refresh_time DESC'''
...
cursor.execute(sql, ((id / 10) % 1000), id)
data = cursor.fetchall()
Additional context
I konw,PyMySQL convert all objects including integer to formatted and quoted string.
But when my table name is table_name_003.I expected it to be table_name_003 but I got table_name_'003'
I have also tried to make mysql not add automatically ''.But I failed.
Do you have any good suggestions, please
...
table_name="table_name_%03d"% ((id/10) %1000)
sql=f'''SELECT aa, bb, refresh_time FROM {table_name} WHERE id = %s ORDER BY refresh_time DESC'''
...
cursor.execute(sql, (id,))
data=cursor.fetchall()
Thanks, it's not a problem to handle in python.
However, this approach still carries the risk of SQL injection.
While in the majority of scenarios, the use of ID is reliable.
This discussion was converted from issue #1150 on December 06, 2023 09:53.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.
Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.
🎥 Watch TMZ Live
TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.
(id / 10) % 1000)
never have SQL injection risk.Do not use untrusted input for table name, off course.