// Path: src/main/java/com/pgasync/ResultSet.java
// public interface ResultSet extends Iterable<Row> {
// 
//     Map<String, PgColumn> getColumnsByName();
// 
//     List<PgColumn> getOrderedColumns();
// 
//     /**
//      * @param index Row index starting from 0
//      * @return Row, never null
//      */
//     Row at(int index);
// 
//     /**
//      * @return Amount of result rows.
//      */
//     int size();
// 
//     /**
//      * @return Amount of modified rows.
//      */
//     int affectedRows();
// 
// }
// 
// Path: src/main/java/com/pgasync/SqlException.java
// public class SqlException extends RuntimeException {
// 
//     private static final long serialVersionUID = 1L;
//     private static final int MAX_CAUSE_DEPTH = 100;
// 
//     final String code;
// 
//     public SqlException(String level, String code, String message) {
//         super(level + ": SQLSTATE=" + code + ", MESSAGE=" + message);
//         this.code = code;
//     }
// 
//     public SqlException(String message) {
//         super(message);
//         this.code = null;
//     }
// 
//     public SqlException(Throwable cause) {
//         super(cause);
//         this.code = null;
//     }
// 
//     public String getCode() {
//         return code;
//     }
// 
//     @FunctionalInterface
//     public interface CheckedRunnable {
// 
//         void run() throws Exception;
//     }
// 
//     public static boolean ifCause(Throwable th, Consumer<SqlException> action, CheckedRunnable others) throws Exception {
//         int depth = 1;
//         while (depth++ < MAX_CAUSE_DEPTH && th != null && !(th instanceof SqlException)) {
//             th = th.getCause();
//         }
//         if (th instanceof SqlException) {
//             action.accept((SqlException) th);
//             return true;
//         } else {
//             others.run();
//             return false;
//         }
//     }
// }


import com.pgasync.ResultSet;
import com.pgasync.SqlException;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;

        ResultSet firstSelectResult = results.get(1);
        Assert.assertEquals(0, firstSelectResult.affectedRows());
        Assert.assertEquals(2, firstSelectResult.size());
        Assert.assertEquals(1, firstSelectResult.at(0).getLong("first_id").intValue());
        Assert.assertEquals(2, firstSelectResult.at(1).getLong("first_id").intValue());
        Assert.assertEquals(1, firstSelectResult.getOrderedColumns().size());
        Assert.assertEquals("first_id", firstSelectResult.getOrderedColumns().get(0).getName());
        Assert.assertEquals(1, firstSelectResult.getColumnsByName().size());
        Assert.assertTrue(firstSelectResult.getColumnsByName().containsKey("first_id"));


        ResultSet secondInsertResult = results.get(2);
        Assert.assertEquals(3, secondInsertResult.affectedRows());
        Assert.assertEquals(0, secondInsertResult.size());
        Assert.assertTrue(secondInsertResult.getOrderedColumns().isEmpty());
        Assert.assertTrue(secondInsertResult.getColumnsByName().isEmpty());

        ResultSet secondSelectResult = results.get(3);
        Assert.assertEquals(0, secondSelectResult.affectedRows());
        Assert.assertEquals(3, secondSelectResult.size());
        Assert.assertEquals(3, secondSelectResult.at(0).getLong("second_id").intValue());
        Assert.assertEquals(4, secondSelectResult.at(1).getLong("second_id").intValue());
        Assert.assertEquals(5, secondSelectResult.at(2).getLong("second_id").intValue());
        Assert.assertEquals(1, secondSelectResult.getOrderedColumns().size());
        Assert.assertEquals("second_id", secondSelectResult.getOrderedColumns().get(0).getName());
        Assert.assertEquals(1, secondSelectResult.getColumnsByName().size());
        Assert.assertTrue(secondSelectResult.getColumnsByName().containsKey("second_id"));
    }

// Path: src/main/java/com/pgasync/ResultSet.java
// public interface ResultSet extends Iterable<Row> {
// 
//     Map<String, PgColumn> getColumnsByName();
// 
//     List<PgColumn> getOrderedColumns();
// 
//     /**
//      * @param index Row index starting from 0
//      * @return Row, never null
//      */
//     Row at(int index);
// 
//     /**
//      * @return Amount of result rows.
//      */
//     int size();
// 
//     /**
//      * @return Amount of modified rows.
//      */
//     int affectedRows();
// 
// }
// 
// Path: src/main/java/com/pgasync/SqlException.java
// public class SqlException extends RuntimeException {
// 
//     private static final long serialVersionUID = 1L;
//     private static final int MAX_CAUSE_DEPTH = 100;
// 
//     final String code;
// 
//     public SqlException(String level, String code, String message) {
//         super(level + ": SQLSTATE=" + code + ", MESSAGE=" + message);
//         this.code = code;
//     }
// 
//     public SqlException(String message) {
//         super(message);
//         this.code = null;
//     }
// 
//     public SqlException(Throwable cause) {
//         super(cause);
//         this.code = null;
//     }
// 
//     public String getCode() {
//         return code;
//     }
// 
//     @FunctionalInterface
//     public interface CheckedRunnable {
// 
//         void run() throws Exception;
//     }
// 
//     public static boolean ifCause(Throwable th, Consumer<SqlException> action, CheckedRunnable others) throws Exception {
//         int depth = 1;
//         while (depth++ < MAX_CAUSE_DEPTH && th != null && !(th instanceof SqlException)) {
//             th = th.getCause();
//         }
//         if (th instanceof SqlException) {
//             action.accept((SqlException) th);
//             return true;
//         } else {
//             others.run();
//             return false;
//         }
//     }
// }


// Path: src/test/java/com/github/pgasync/ScriptResultsTest.java
import com.pgasync.ResultSet;
import com.pgasync.SqlException;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;


        ResultSet firstSelectResult = results.get(1);
        Assert.assertEquals(0, firstSelectResult.affectedRows());
        Assert.assertEquals(2, firstSelectResult.size());
        Assert.assertEquals(1, firstSelectResult.at(0).getLong("first_id").intValue());
        Assert.assertEquals(2, firstSelectResult.at(1).getLong("first_id").intValue());
        Assert.assertEquals(1, firstSelectResult.getOrderedColumns().size());
        Assert.assertEquals("first_id", firstSelectResult.getOrderedColumns().get(0).getName());
        Assert.assertEquals(1, firstSelectResult.getColumnsByName().size());
        Assert.assertTrue(firstSelectResult.getColumnsByName().containsKey("first_id"));


        ResultSet secondInsertResult = results.get(2);
        Assert.assertEquals(3, secondInsertResult.affectedRows());
        Assert.assertEquals(0, secondInsertResult.size());
        Assert.assertTrue(secondInsertResult.getOrderedColumns().isEmpty());
        Assert.assertTrue(secondInsertResult.getColumnsByName().isEmpty());

        ResultSet secondSelectResult = results.get(3);
        Assert.assertEquals(0, secondSelectResult.affectedRows());
        Assert.assertEquals(3, secondSelectResult.size());
        Assert.assertEquals(3, secondSelectResult.at(0).getLong("second_id").intValue());
        Assert.assertEquals(4, secondSelectResult.at(1).getLong("second_id").intValue());
        Assert.assertEquals(5, secondSelectResult.at(2).getLong("second_id").intValue());
        Assert.assertEquals(1, secondSelectResult.getOrderedColumns().size());
        Assert.assertEquals("second_id", secondSelectResult.getOrderedColumns().get(0).getName());
        Assert.assertEquals(1, secondSelectResult.getColumnsByName().size());
        Assert.assertTrue(secondSelectResult.getColumnsByName().containsKey("second_id"));
    }

    @Test(expected = SqlException.class)