require 'ibm_db2'
require 'stringio'
require 'test/unit'

class TestIbmDb2 < Test::Unit::TestCase

  def test_145
    assert_equal expected, capture {
      conn = DB2::connect(database, user, password)
      
      if conn
        stmt = DB2::prepare( conn, "INSERT INTO animals (id, breed, name) VALUES (?, ?, ?)" )
      
        id = 999
        breed = NULL
        name = ''
        DB2::bind_param(stmt, 1, 'id')
        DB2::bind_param(stmt, 2, 'breed')
        DB2::bind_param(stmt, 3, 'name')
      
        /* 
         After this statement, we expect that the BREED column will contain
         an SQL NULL value, while the NAME column contains an empty string
        */
        DB2::execute(stmt); 
      
        /* 
         After this statement, we expect that the BREED column will contain
         an SQL NULL value, while the NAME column contains an empty string.
         Use the dynamically bound parameters to ensure that the code paths
         for both DB2::bind_param and DB2::execute treat PHP nulls and empty
         strings the right way.
        */
        DB2::execute(stmt, {1000, NULL, ''}); 
      
        result = DB2::exec(conn, "SELECT id, breed, name FROM animals WHERE breed IS NULL")
        while (row = DB2::fetch_{result})
         var_dump(row)
        end
      else
        puts"Connection failed.\n"
      end
    }
  end

end

__END__
array(3) {
  [0]=>
  int(999)
  [1]=>
  NULL
  [2]=>
  string(16) "                "
}
array(3) {
  [0]=>
  int(1000)
  [1]=>
  NULL
  [2]=>
  string(16) "                "
}
