package test;

import java.sql.*;

public class Test08 implements Test.Case
{
    private String error;
    private Exception ex;

    public boolean run() throws Exception {
        int res;
        Class.forName("org.sqlite.JDBC");
        Connection conn = DriverManager.getConnection(
            "jdbc:sqlite:build/test/test.db");
        Statement stat = conn.createStatement();

        ResultSet rs;
        String msg;

        rs = stat.executeQuery("SELECT pid, firstname, surname FROM People;");
        ResultSetMetaData meta = rs.getMetaData();

        if (meta.getColumnCount() != 3) {
            error = "bad column count: " + meta.getColumnCount(); return false;
        }
        if (!"People".equals(meta.getCatalogName(1))) {
            error = "bad catalog name: " + meta.getCatalogName(1); return false;
        }
        if (!"pid".equals(meta.getColumnName(1))) {
            error = "bad column 1 name: " + meta.getColumnName(1); return false;
        }
        if (!"firstname".equals(meta.getColumnName(2))) {
            error = "bad column 2 name: " + meta.getColumnName(2); return false;
        }
        if (!"surname".equals(meta.getColumnName(3))) {
            error = "bad column 3 name: " + meta.getColumnName(3); return false;
        }

        msg = null;
        try { meta.getCatalogName(4); }
        catch (SQLException e) { msg = e.getMessage(); }
        if (!"column 4 out of bounds [1,3]".equals(msg)) {
            error = "bad error for out of bounds catalog: " + msg; return false;
        }

        msg = null;
        try { meta.getColumnName(4); }
        catch (SQLException e) { msg = e.getMessage(); }
        if (!"column 4 out of bounds [1,3]".equals(msg)) {
            error = "bad error for out of bounds colname: " + msg; return false;
        }

        if (meta.getColumnType(1) != Types.INTEGER) {
            error = "expected type INTEGER for col 1"; return false;
        }
        if (meta.getColumnType(2) != Types.VARCHAR) {
            error = "expected type VARCHAR for col 2"; return false;
        }
        if (meta.getColumnType(3) != Types.VARCHAR) {
            error = "expected type VARCHAR for col 3"; return false;
        }

        if (!meta.isAutoIncrement(1)) {
            error = "expected col 1 to be auto-increment"; return false;
        }
        if (meta.isAutoIncrement(2)) {
            error = "expected col 2 to not be auto-increment"; return false;
        }
        if (meta.isAutoIncrement(3)) {
            error = "expected col 3 to not be auto-increment"; return false;
        }
        if (meta.isNullable(1) != meta.columnNoNulls) {
            error = "expected col 1 to take NoNulls"; return false;
        }
        if (meta.isNullable(2) != meta.columnNullable) {
            error = "expected col 2 to take nulls"; return false;
        }
        if (meta.isNullable(3) != meta.columnNullable) {
            error = "expected col 3 to take nulls"; return false;
        }

        rs.close();
        stat.close();
        conn.close();

        return true;
    }

    public String name() { return "RSMetaData"; }
    public String error() { return error; }
    public Exception ex() { return ex; }
}

@@ -285,52 +285,21 @@
 ion(
-%0A            %22jdbc:sqlite:build/test/test.db
+%22jdbc:sqlite:
 %22);%0A
@@ -346,16 +346,315 @@
 ement();
+%0A        stat.executeUpdate(%0A            %22create table People (pid integer primary key autoincrement, %22%0A            + %22 firstname string, surname string, dob date);%22);%0A        stat.executeUpdate(%0A            %22insert into people values (null, 'Mohandas', 'Gandhi', %22%0A            + %22 '1869-10-02');%22);
 %0A%0A      
@@ -3243,32 +3243,823 @@
 lse;%0A        %7D%0A%0A
+        rs.close();%0A%0A        rs = stat.executeQuery(%22select * from people;%22);%0A        meta = rs.getMetaData();%0A        if (meta.getColumnCount() != 4) %7B%0A            error = %22expected 4 cols in people *%22; return false;%0A        %7D%0A        if (!%22pid%22.equals(meta.getColumnName(1))) %7B%0A            error = %22bad * 1 name: %22 + meta.getColumnName(1); return false;%0A        %7D%0A        if (!%22firstname%22.equals(meta.getColumnName(2))) %7B%0A            error = %22bad * 2 name: %22 + meta.getColumnName(2); return false;%0A        %7D%0A        if (!%22surname%22.equals(meta.getColumnName(3))) %7B%0A            error = %22bad * 3 name: %22 + meta.getColumnName(3); return false;%0A        %7D%0A        if (!%22dob%22.equals(meta.getColumnName(4))) %7B%0A            error = %22bad * 3 name: %22 + meta.getColumnName(4); return false;%0A        %7D%0A%0A
         rs.close

test column count when using *