Suppose I have want to do a string prefix search in database, say
select * from some_table where name like 'abcde%';
where abcde is actually some user input string. How do I do it in MySQLdb in python? I could think of two ways:
cursor.execute("""select * from some_table where name like '%s%%'""", (some_prefix_to_search))
OR
cursor.execute("""select * from some_table where name like %s""", (some_prefix_to_search + '%'))
Which one is the correct way? For method 1, will MySQLdb correctly figure out '%s%%' is a whole, so it will generate 'abcde%' instead of something like ''abcde'%', i.e. will %s be substituted as the string value with or without the quote mark?
For method 2, will the % in the input string be thought as some special value and escaped?
Thanks.