/** * A variant of {@link #rows(String, java.util.List, int, int)} * 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 * @return a list of GroovyRowResult objects * @throws SQLException if a database access error occurs * @since 1.8.7 */ public List<GroovyRowResult> rows(Map params, String sql, int offset, int maxRows) throws SQLException { return rows(sql, singletonList(params), offset, maxRows); }
/** * Performs the given SQL query and return the rows of the result set. * <p> * Example usage: * <pre> * def ans = sql.rows("select * from PERSON where firstname like 'S%'") * println "Found ${ans.size()} rows" * </pre> * <p> * Resource handling is performed automatically where appropriate. * * @param sql the SQL statement * @return a list of GroovyRowResult objects * @throws SQLException if a database access error occurs */ public List<GroovyRowResult> rows(String sql) throws SQLException { return rows(sql, 0, 0, null); }
/** * Performs the given SQL query and return the rows of the result set. * <p> * This method supports named and named ordinal parameters by supplying such * parameters in the <code>params</code> array. See the class Javadoc for more details. * <p> * An Object array variant of {@link #rows(String, List, int, int)}. * * @param sql the SQL statement * @param params an array 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 * @return a list of GroovyRowResult objects * @throws SQLException if a database access error occurs */ public List<GroovyRowResult> rows(String sql, Object[] params, int offset, int maxRows) throws SQLException { return rows(sql, Arrays.asList(params), offset, maxRows, null); }
/** * Performs the given SQL query and return the rows of the result set. * The query may contain placeholder question marks which match the given list of parameters. * <p> * Example usage: * <pre> * def ans = sql.rows("select * from PERSON where lastname like ?", ['%a%']) * println "Found ${ans.size()} rows" * </pre> * <p> * This method supports named and named ordinal parameters by supplying such * parameters in the <code>params</code> list. See the class Javadoc for more details. * <p> * Resource handling is performed automatically where appropriate. * * @param sql the SQL statement * @param params a list of parameters * @return a list of GroovyRowResult objects * @throws SQLException if a database access error occurs */ public List<GroovyRowResult> rows(String sql, List<Object> params) throws SQLException { return rows(sql, params, null); }
/** * Performs the given SQL query and return a "page" of rows from the result set. A page is defined as starting at * a 1-based offset, and containing a maximum number of rows. * The query may contain GString expressions. * <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. * <p> * Resource handling is performed automatically where appropriate. * * @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 * @return a list of GroovyRowResult objects * @throws SQLException if a database access error occurs */ public List<GroovyRowResult> rows(GString sql, int offset, int maxRows) throws SQLException { return rows(sql, offset, maxRows, null); }
/** * Performs the given SQL query and return a "page" of rows from the result set. A page is defined as starting at * a 1-based offset, and containing a maximum number of rows. * 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. * <p> * This method supports named and named ordinal parameters by supplying such * parameters in the <code>params</code> list. See the class Javadoc for more details. * <p> * Resource handling is performed automatically where appropriate. * * @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 * @return a list of GroovyRowResult objects * @throws SQLException if a database access error occurs */ public List<GroovyRowResult> rows(String sql, List<Object> params, int offset, int maxRows) throws SQLException { return rows(sql, params, offset, maxRows, null); }
/** * A variant of {@link #rows(String, java.util.List)} * useful when providing the named parameters as named arguments. * * @param params a map containing the named parameters * @param sql the SQL statement * @return a list of GroovyRowResult objects * @throws SQLException if a database access error occurs * @since 1.8.7 */ public List<GroovyRowResult> rows(Map params, String sql) throws SQLException { return rows(sql, singletonList(params)); }
/** * A variant of {@link #rows(String, java.util.List, int, int, 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 offset the 1-based offset for the first row to be processed * @param maxRows the maximum number of rows to be processed * @param metaClosure called for meta data (only once after sql execution) * @return a list of GroovyRowResult objects * @throws SQLException if a database access error occurs * @since 1.8.7 */ public List<GroovyRowResult> rows(String sql, Map params, int offset, int maxRows, @ClosureParams(value=SimpleType.class, options="java.sql.ResultSetMetaData") Closure metaClosure) throws SQLException { return rows(sql, singletonList(params), offset, maxRows, metaClosure); }
/** * A variant of {@link #rows(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 metaClosure called for meta data (only once after sql execution) * @return a list of GroovyRowResult objects * @throws SQLException if a database access error occurs * @since 1.8.7 */ public List<GroovyRowResult> rows(Map params, String sql, int offset, int maxRows, @ClosureParams(value=SimpleType.class, options="java.sql.ResultSetMetaData") Closure metaClosure) throws SQLException { return rows(sql, singletonList(params), offset, maxRows, metaClosure); }
List<Object> params = getParameters(gstring); String sql = asSql(gstring, params); return rows(sql, params, metaClosure);
/** * Performs the given SQL query and return the rows of the result set. * * @param sql the SQL statement * @return a list of GroovyRowResult objects * @throws SQLException if a database access error occurs */ public List rows(String sql) throws SQLException { return rows(sql, (Closure) null); }
/** * Performs the given SQL query and return the rows of the result set. * * @param sql the SQL statement * @return a list of GroovyRowResult objects * @throws SQLException if a database access error occurs */ public List rows(String sql) throws SQLException { return rows(sql, (Closure) null); }
/** * Performs the given SQL query and return the first row of the result set. * * @param sql the SQL statement * @return a GroovyRowResult object * @throws SQLException if a database access error occurs */ public Object firstRow(String sql) throws SQLException { List rows = rows(sql); if (rows.isEmpty()) return null; return (rows.get(0)); }
/** * Performs the given SQL query and return the first row of the result set. * * @param sql the SQL statement * @return a GroovyRowResult object * @throws SQLException if a database access error occurs */ public Object firstRow(String sql) throws SQLException { List rows = rows(sql); if (rows.isEmpty()) return null; return (rows.get(0)); }
/** * Performs the given SQL query with the list of params and return * the first row of the result set. * * @param sql the SQL statement * @param params a list of parameters * @return a GroovyRowResult object * @throws SQLException if a database access error occurs */ public Object firstRow(String sql, List params) throws SQLException { List rows = rows(sql, params); if (rows.isEmpty()) return null; return rows.get(0); }
/** * A variant of {@link #rows(String, java.util.List)} * useful when providing the named parameters as named arguments. * * @param params a map containing the named parameters * @param sql the SQL statement * @return a list of GroovyRowResult objects * @throws SQLException if a database access error occurs * @since 1.8.7 */ public List<GroovyRowResult> rows(Map params, String sql) throws SQLException { return rows(sql, singletonList(params)); }
/** * A variant of {@link #rows(String, java.util.List)} * useful when providing the named parameters as named arguments. * * @param params a map containing the named parameters * @param sql the SQL statement * @return a list of GroovyRowResult objects * @throws SQLException if a database access error occurs * @since 1.8.7 */ public List<GroovyRowResult> rows(Map params, String sql) throws SQLException { return rows(sql, singletonList(params)); }
/** * A variant of {@link #rows(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 metaClosure called for meta data (only once after sql execution) * @return a list of GroovyRowResult objects * @throws SQLException if a database access error occurs * @since 1.8.7 */ public List<GroovyRowResult> rows(Map params, String sql, Closure metaClosure) throws SQLException { return rows(sql, singletonList(params), metaClosure); }
/** * Performs the given SQL query and return the rows of the result set. * * @param gstring a GString containing the SQL query with embedded params * @return a list of GroovyRowResult objects * @throws SQLException if a database access error occurs */ public List rows(GString gstring) throws SQLException { List params = getParameters(gstring); String sql = asSql(gstring, params); return rows(sql, params); }
/** * Performs the given SQL query and return the rows of the result set. * * @param gstring a GString containing the SQL query with embedded params * @return a list of GroovyRowResult objects * @throws SQLException if a database access error occurs */ public List rows(GString gstring) throws SQLException { List params = getParameters(gstring); String sql = asSql(gstring, params); return rows(sql, params); }