Last active
December 17, 2019 15:59
-
-
Save tjmtmmnk/2058db9a654315c0c9d79326bbb0ef72 to your computer and use it in GitHub Desktop.
bind sql parameter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sql_text = """ | |
select * from a | |
where x = ? | |
and y = ? | |
""" | |
bind_values_text = """1, 2""" | |
sql = sql_text.replace("\n", " ") | |
_bind_values = bind_values_text.replace(' ', '') | |
bind_values = _bind_values.split(",") | |
param_num = sql.count('?') | |
if len(bind_values) != param_num: | |
exit("not matched bind values num") | |
for value in bind_values: | |
insert_value = "'" + value + "'" | |
sql = sql.replace('?', insert_value, 1) | |
print(sql) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment