def static CleanUpPerson(AccountID, log) { def db = Sql.newInstance('jdbc:oracle:thin:@server:port:database', 'userid', 'password', 'oracle.jdbc.OracleDriver') // If the AccountID exists, we need to delete it for cleanliness // conditional if - on whether there's anything in the first cell of the first row' def myString this.AccountID = AccountID // if (db.eachRow("SELECT AccountUserName FROM TABLE WHERE accountid = 'AccountID0002'"){ row -> log.info(row[0])}) { db.eachRow("SELECT AccountUserName FROM TABLE WHERE accountid = 'ccountID0002'") { row -> (myString = row[0])} if (myString) { // IF WE GOT HERE, WE FOUND AT LEAST ONE INSTANCE OF AccountID0002 log.info("AccountID found - will delete it now") // first, delete all entries in side_table related to accountID0002 // this is a complex query - nestling a query to get the person.id value within the delete state log.info(" deleting side entries") db.execute("DELETE FROM side_table WHERE person_id = (select id from person where AccountID = 'AccountID0002')") // next, delete the row from authorities where accountid = 'AccountID0002' log.info(" deleting entries in auth_table") db.execute("DELETE FROM auth_table where username = (select accountusername from sperson where accountid = 'AccountID0002')") // next, delete the entire row in the LDSFSPERSON table log.info(" deleting entries from sperson") db.execute("DELETE FROM person WHERE accountid = 'AccountID0002'") } else { log.info("AccountID not found - proceed to next step") } }