I'm given a sql query and I have to decide if it's a write statement or read statement.
I'm not sure how to go about it and I can't find anything online that already has this capability.
I'm assuming the only way to do it is to inspect the string for words like select vs update alter delete insert drop etc...
But I'll have to strip out all string literals first.
def is_write_query(query):
# returns true or false
# strip string literals
# if contains key words:
# UPDATE, DELETE, INSERT, CREATE, ALTER, DROP
# return true, else false
Does anyone know a better way to do this? do you know about a package that has this capability?
if this is the best way to do it, what's the easiest way to handle the string parsing? Specifically stripping out the string literals.