package net.squarelabs.sqorm;

import org.apache.commons.dbcp.BasicDataSource;
import org.junit.Assert;
import org.junit.Test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

public class SqormCursorTest {

    @Test
    public void canIterate() throws Exception {
        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName("com.mysql.jdbc.Driver");
        ds.setUsername("sqorm");
        ds.setPassword("sqorm");
        ds.setUrl("jdbc:mysql://127.0.0.1/sqorm");

        boolean recordsValid = true;
        int count = 0;

        try(Connection con = ds.getConnection()) {
            con.setAutoCommit(true);

            // drop tables
            String drop = "drop table if exists `sqorm`.`customer`;";
            try(PreparedStatement stmt = con.prepareStatement(drop)) {
                stmt.execute();
            }

            // Create customers
            String createTables = "CREATE TABLE `sqorm`.`customer` (\n" +
                    "  `customer_id` INT NOT NULL,\n" +
                    "  `name` VARCHAR(45) NOT NULL,\n" +
                    "  PRIMARY KEY (`customer_id`));";
            try(PreparedStatement stmt = con.prepareStatement(createTables)) {
                stmt.execute();
            }

            // Select from tables
            String selectQuery = "select * from customer;";
            try(PreparedStatement stmt = con.prepareStatement(selectQuery)) {
                SqormCursor cur = new SqormCursor(stmt);
                while(cur.hasNext()) {
                    Object record = cur.next();
                    if(record == null) {
                        recordsValid = false;
                    }
                    count++;
                }
            }
        }
        Assert.assertEquals("All records iterable", 1, count);
        Assert.assertTrue("All records valid", recordsValid);
    }
}

@@ -701,24 +701,218 @@
 mit(true);%0A%0A
+            // use schema%0A            String useSchema = %22use sqorm;%22;%0A            try(PreparedStatement stmt = con.prepareStatement(useSchema)) %7B%0A                stmt.execute();%0A            %7D%0A%0A
             
@@ -974,33 +974,24 @@
  exists 
-%60sqorm%60.%60
 customer
 %60;%22;%0A   
@@ -982,17 +982,16 @@
 customer
-%60
 ;%22;%0A    
@@ -1188,25 +1188,16 @@
 BLE 
-%60sqorm%60.%60
 customer
 %60 (%5C
@@ -1192,17 +1192,16 @@
 customer
-%60
  (%5Cn%22 +%0A

Use schema to prevent erroneous dropping of tables