/** * A variant of {@link #eachRow(String, java.util.List, groovy.lang.Closure)} * useful when providing the named parameters as a map. * * @param sql the sql statement * @param params a map of named parameters * @param closure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs * @since 1.8.7 */ public void eachRow(String sql, Map params, @ClosureParams(value=SimpleType.class, options="groovy.sql.GroovyResultSet") Closure closure) throws SQLException { eachRow(sql, singletonList(params), closure); }
/** * A variant of {@link #eachRow(String, java.util.List, int, int, groovy.lang.Closure)} * useful when providing the named parameters as named arguments. * * @param params a map of named parameters * @param sql the sql statement * @param offset the 1-based offset for the first row to be processed * @param maxRows the maximum number of rows to be processed * @param closure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs * @since 1.8.7 */ public void eachRow(Map params, String sql, int offset, int maxRows, @ClosureParams(value=SimpleType.class, options="groovy.sql.GroovyResultSet") Closure closure) throws SQLException { eachRow(sql, singletonList(params), offset, maxRows, closure); }
/** * Performs the given SQL query calling the given Closure with each row of the result set. * The row will be a <code>GroovyResultSet</code> which is a <code>ResultSet</code> * that supports accessing the fields using property style notation and ordinal index values. * The query may contain placeholder question marks which match the given list of parameters. * <p> * Example usage: * <pre> * sql.eachRow("select * from PERSON where lastname like ?", ['%a%']) { row -> * println "${row[1]} $row.lastname" * } * </pre> * <p> * Resource handling is performed automatically where appropriate. * * @param sql the sql statement * @param params a list of parameters * @param closure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs */ public void eachRow(String sql, List<Object> params, @ClosureParams(value=SimpleType.class, options="groovy.sql.GroovyResultSet") Closure closure) throws SQLException { eachRow(sql, params, null, closure); }
/** * Performs the given SQL query calling the given <code>closure</code> with each row of the result set starting at * the provided <code>offset</code>, and including up to <code>maxRows</code> number of rows. * The row will be a <code>GroovyResultSet</code> which is a <code>ResultSet</code> * that supports accessing the fields using property style notation and ordinal index values. * The query may contain placeholder question marks which match the given list of parameters. * <p> * Note that the underlying implementation is based on either invoking <code>ResultSet.absolute()</code>, * or if the ResultSet type is <code>ResultSet.TYPE_FORWARD_ONLY</code>, the <code>ResultSet.next()</code> method * is invoked equivalently. The first row of a ResultSet is 1, so passing in an offset of 1 or less has no effect * on the initial positioning within the result set. * <p> * Note that different database and JDBC driver implementations may work differently with respect to this method. * Specifically, one should expect that <code>ResultSet.TYPE_FORWARD_ONLY</code> may be less efficient than a * "scrollable" type. * * @param sql the sql statement * @param params a list of parameters * @param offset the 1-based offset for the first row to be processed * @param maxRows the maximum number of rows to be processed * @param closure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs */ public void eachRow(String sql, List<Object> params, int offset, int maxRows, @ClosureParams(value=SimpleType.class, options="groovy.sql.GroovyResultSet") Closure closure) throws SQLException { eachRow(sql, params, null, offset, maxRows, closure); }
/** * A variant of {@link #eachRow(String, java.util.List, groovy.lang.Closure)} * useful when providing the named parameters as named arguments. * * @param params a map of named parameters * @param sql the sql statement * @param closure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs * @since 1.8.7 */ public void eachRow(Map params, String sql, @ClosureParams(value=SimpleType.class, options="groovy.sql.GroovyResultSet") Closure closure) throws SQLException { eachRow(sql, singletonList(params), closure); }
/** * A variant of {@link #eachRow(String, java.util.List, groovy.lang.Closure, groovy.lang.Closure)} * useful when providing the named parameters as named arguments. * * @param params a map of named parameters * @param sql the sql statement * @param metaClosure called for meta data (only once after sql execution) * @param rowClosure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs * @since 1.8.7 */ public void eachRow(Map params, String sql, @ClosureParams(value=SimpleType.class, options="java.sql.ResultSetMetaData") Closure metaClosure, @ClosureParams(value=SimpleType.class, options="groovy.sql.GroovyResultSet") Closure rowClosure) throws SQLException { eachRow(sql, singletonList(params), metaClosure, rowClosure); }
@ClosureParams(value=SimpleType.class, options="java.sql.ResultSetMetaData") Closure metaClosure, @ClosureParams(value=SimpleType.class, options="groovy.sql.GroovyResultSet") Closure rowClosure) throws SQLException { eachRow(sql, params, metaClosure, 0, 0, rowClosure);
@ClosureParams(value=SimpleType.class, options="java.sql.ResultSetMetaData") Closure metaClosure, @ClosureParams(value=SimpleType.class, options="groovy.sql.GroovyResultSet") Closure rowClosure) throws SQLException { eachRow(sql, singletonList(params), metaClosure, rowClosure);
/** * Performs the given SQL query calling the closure with each row of the * result set. * * @param sql the sql statement * @param closure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs */ public void eachRow(String sql, Closure closure) throws SQLException { eachRow(sql, (Closure) null, closure); }
/** * Performs the given SQL query calling the closure with each row of the * result set. * * @param sql the sql statement * @param closure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs */ public void eachRow(String sql, Closure closure) throws SQLException { eachRow(sql, (Closure) null, closure); }
/** * @deprecated please use eachRow instead */ public void queryEach(String sql, Closure closure) throws SQLException { warnDeprecated(); eachRow(sql, closure); }
/** * @deprecated please use eachRow instead */ public void queryEach(GString gstring, Closure closure) throws SQLException { warnDeprecated(); eachRow(gstring, closure); }
/** * @deprecated please use eachRow instead */ public void queryEach(String sql, List params, Closure closure) throws SQLException { warnDeprecated(); eachRow(sql, params, closure); }
/** * A variant of {@link #eachRow(String, java.util.List, groovy.lang.Closure)} * useful when providing the named parameters as a map. * * @param sql the sql statement * @param params a map of named parameters * @param closure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs * @since 1.8.7 */ public void eachRow(String sql, Map params, Closure closure) throws SQLException { eachRow(sql, singletonList(params), closure); }
/** * A variant of {@link #eachRow(String, java.util.List, groovy.lang.Closure)} * useful when providing the named parameters as named arguments. * * @param params a map of named parameters * @param sql the sql statement * @param closure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs * @since 1.8.7 */ public void eachRow(Map params, String sql, Closure closure) throws SQLException { eachRow(sql, singletonList(params), closure); }
/** * A variant of {@link #eachRow(String, java.util.List, groovy.lang.Closure, groovy.lang.Closure)} * useful when providing the named parameters as a map. * * @param sql the sql statement * @param params a map of named parameters * @param metaClosure called for meta data (only once after sql execution) * @param rowClosure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs * @since 1.8.7 */ public void eachRow(String sql, Map params, Closure metaClosure, Closure rowClosure) throws SQLException { eachRow(sql, singletonList(params), metaClosure, rowClosure); }
/** * A variant of {@link #eachRow(String, java.util.List, groovy.lang.Closure, groovy.lang.Closure)} * useful when providing the named parameters as named arguments. * * @param params a map of named parameters * @param sql the sql statement * @param metaClosure called for meta data (only once after sql execution) * @param rowClosure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs * @since 1.8.7 */ public void eachRow(Map params, String sql, Closure metaClosure, Closure rowClosure) throws SQLException { eachRow(sql, singletonList(params), metaClosure, rowClosure); }
/** * Performs the given SQL query calling the closure with the result set. * * @param gstring a GString containing the SQL query with embedded params * @param closure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs */ public void eachRow(GString gstring, Closure closure) throws SQLException { List params = getParameters(gstring); String sql = asSql(gstring, params); eachRow(sql, params, closure); }
/** * Performs the given SQL query calling the closure with the result set. * * @param gstring a GString containing the SQL query with embedded params * @param closure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs */ public void eachRow(GString gstring, Closure closure) throws SQLException { List params = getParameters(gstring); String sql = asSql(gstring, params); eachRow(sql, params, closure); }
/** * A variant of {@link #eachRow(String, java.util.List, groovy.lang.Closure)} * useful when providing the named parameters as named arguments. * * @param params a map of named parameters * @param sql the sql statement * @param closure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs * @since 1.8.7 */ public void eachRow(Map params, String sql, @ClosureParams(value=SimpleType.class, options="groovy.sql.GroovyResultSet") Closure closure) throws SQLException { eachRow(sql, singletonList(params), closure); }