Forum Discussion
John_Overbaugh
18 years agoOccasional Contributor
Hey Ole... Yeah, I actually have it wrapped up in a class (I neglected to copy/past that info my attachment) so that can't be the problem. Is there any way to 'debug' a script once it's been moved to a central location?
Here's my class:
class PersonInfoSharedScripts
{
def log
def AccountID
def static CleanUpPerson(AccountID, log)
{
def db = Sql.newInstance('jdbc:oracle:thin:@server:1234:db', 'username', '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 = 'AccountID0002'")
{ 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 sperson_sideaccountusername related to accoutID0002
// this is a complex query - nestling a query to get the fsperson.id value within the delete state
log.info(" deleting sidetable entries")
db.execute("DELETE FROM fsperson_sidetable WHERE sperson_id = (select id from sperson where AccountID = 'AccountID0002')")
// next, delete the row from auth_table where accountid = 'AccountID0002'
log.info(" deleting entries in auth_table")
db.execute("DELETE FROM auth_table where username = (select accountusername from person where accountid = 'AccountID0002')")
// next, delete the entire row in the SPERSON table
log.info(" deleting entries from person")
db.execute("DELETE FROM person WHERE accountid = 'AccountID0002'")
}
else
{
log.info("AccountID not found - proceed to next step")
}
}
}
Here's my class:
class PersonInfoSharedScripts
{
def log
def AccountID
def static CleanUpPerson(AccountID, log)
{
def db = Sql.newInstance('jdbc:oracle:thin:@server:1234:db', 'username', '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 = 'AccountID0002'")
{ 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 sperson_sideaccountusername related to accoutID0002
// this is a complex query - nestling a query to get the fsperson.id value within the delete state
log.info(" deleting sidetable entries")
db.execute("DELETE FROM fsperson_sidetable WHERE sperson_id = (select id from sperson where AccountID = 'AccountID0002')")
// next, delete the row from auth_table where accountid = 'AccountID0002'
log.info(" deleting entries in auth_table")
db.execute("DELETE FROM auth_table where username = (select accountusername from person where accountid = 'AccountID0002')")
// next, delete the entire row in the SPERSON table
log.info(" deleting entries from person")
db.execute("DELETE FROM person WHERE accountid = 'AccountID0002'")
}
else
{
log.info("AccountID not found - proceed to next step")
}
}
}