//**************************************************************************************************************** // // This method takes a query string and an index, and executes the query with no return // // Parameters: // queryString - the string to be executed by the query to return a single entry in a row // log - the soapUI logging object // stopOnError - indicates whether to throw an exception or error silently. Usually you want to throw an exception // UNLESS you want/expect the query to return null (for instance, if you want to ensure a delete // succeeded and the object is no longer in the database) // // **************************************************************************************************************** def static CountEntriesInTable(entryColumnName, entryValue, tableName, log, stopOnError) { def myCount def myQuery myQuery = "SELECT COUNT ($entryColumnName) from $tableName WHERE $entryColumnName = '$entryValue'" log.info("Counting the instances of $entryValue in column $entryColumnName in table $tableName") log.info(myQuery) // Wrap everything in a try-catch-finally try { // First, set up the database def db = Sql.newInstance('jdbc:oracle:thin:@server:port:a237', 'username', 'pw', 'oracle.jdbc.OracleDriver') // Now execute the query which was passed in log.info(" - Executing query to find the count of $entryValue in $tableName") log.info(" - SELECT COUNT ($entryColumnName) from $tableName WHERE $entryColumnName = '$entryValue'") //db.eachRow("SELECT COUNT ('$entryColumnName') from '$tableName' WHERE '$entryColumnName' = '$entryValue'") db.eachRow(myQuery) { row -> (myCount = row[0])} log.info(" - myCount = " + myCount) log.info(" - executed successfully") } catch (Exception e) { if (stopOnError) { log.info(" - Errored, fell into catch statement. " + e.toString()) throw new Exception ("Failed") } } finally { log.info(" - Count = " + myCount) return myCount } }