Created
February 6, 2015 15:27
-
-
Save joeRinehart/b1decb087673d5423a76 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Adds a SQL-server specific callRows() method to Groovy Sql that functions like rows() against stored | |
procedures that perform DML before doing a select. | |
Essentially, it's just a set nocount on/off wrapper. | |
Usage: | |
sql.callRows( | |
"someProcName", | |
[ | |
paramOne: 'valOne', | |
paramTwo: 'valTwo', | |
] | |
) | |
*/ | |
Sql.metaClass.callRows << { String procName, Map params -> | |
// build a statement | |
String statement = "{call ${procName}(" | |
params.eachWithIndex { k, v, i -> | |
statement+= i>0 ? ',' : '' + ':' + k | |
} | |
statement += ')}' | |
// do the wrapped call | |
def result | |
sql.withTransaction { | |
sql.execute('set nocount on') | |
result = sql.rows(statement, params) | |
sql.execute('set nocount off') | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment