/**
 * 
 */
package com.traderoot.tests.mysqltest;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;

import com.mysql.jdbc.util.BaseBugReport;

/**
 * @author paul.mouton
 * 
 */
public class NulabablePatameterBugReport extends BaseBugReport {
  private Connection connection;

  /*
   * (non-Javadoc)
   * 
   * @see com.mysql.jdbc.util.BaseBugReport#runTest()
   */
  public void runTest() throws Exception {
    DatabaseMetaData dbMeta = connection.getMetaData();
    ResultSet rset = dbMeta.getProcedureColumns("test", null, "nullableParameterTest", null);
    while (rset.next()) {
      String columnName = rset.getString(4);
      Short columnType = new Short(rset.getShort(5));
      int columnTypeValue = columnType.intValue();
      Integer dataType = new Integer(rset.getInt(6));
      String columnTypeName = rset.getString(7);
      Integer dataLength = new Integer(rset.getInt(9));
      Short scale = new Short(rset.getShort(10));
      Short columnNullable = new Short(rset.getShort(12));
      assertTrue("Parameter " + columnName + " do not allow null arguments", columnNullable.intValue() == java.sql.DatabaseMetaData.procedureNullable);
    }
  }

  /*
   * (non-Javadoc)
   * 
   * @see com.mysql.jdbc.util.BaseBugReport#setUp()
   */
  public void setUp() throws Exception {
    connection = getConnection();
    connection.setCatalog("test");
    // Statement stmt = connection.createStatement();
    // stmt.execute("drop procedure nullableParameterTest;" + "delimiter ?" + "create procedure nullableParameterTest (IN intInput int, IN charArrayInput char(50),IN textInput text, OUT errorMsg char(80))" + "begin" + "" + "end ?" + "delimiter ;");
    // Create the Procedure
    /*
     * drop procedure nullableParameterTest; delimiter ? create procedure nullableParameterTest (IN intInput int, IN charArrayInput char(50),IN textInput text, OUT errorMsg char(80)) begin end ? delimiter ;
     */
  }

  /*
   * (non-Javadoc)
   * 
   * @see com.mysql.jdbc.util.BaseBugReport#tearDown()
   */
  public void tearDown() throws Exception {
    // Statement stmt = connection.createStatement();
    // stmt.executeQuery("drop procedure nullableParameterTest;");
  }

  public static void main(String[] args) throws Exception {
    try {
      new NulabablePatameterBugReport().run();
    } catch (Exception e) {
      e.printStackTrace();
      throw e;
    }
  }

  // TODO REMOVE THIS !!
  public String getUrl() {
    return "jdbc:mysql:///test?user=root&password=";
  }
}
