The task is to identify if the SQL statements is a DML / DDL or not.
So I had to use an array and push all the DML/DDL patterns into that and search for them by iterating.
Below is a simple code snippet where
- I am sending an SQL query as a parameter
- Check if it has update, alter, drop, delete
def check_dml_statementent (self,sql)
actions = ['update', 'alter', 'drop', 'delete']
for action in actions
if ( re.search (action,sql.lower() ) :
print "This is a dml statement "
But there are some edge cases, for which I need to code for
To consider
Update table table_name where ... alter table table_name create table table_name delete * from table_name drop table_nameNot to consider:
select * from table where action='drop'
So, the task is to identify only SQL statements which modify, drop, create, alter table etc.
One specific idea is to check if an SQL statement starts with above array values using startswith function.