class TestIbmDb2 < Test::Unit::TestCase

  def prepare_blob conn
    # Drop the test table, in case it exists
    drop = 'DROP TABLE animal_pics'
    result = DB2::exec(conn, drop) rescue nil
    
    # Create the test table
    create = 'CREATE TABLE animal_pics (name VARCHAR(32), picture BLOB(16K))'
    result = DB2::exec conn, create
    
    # Populate the test table
    animals = [
      ['Spook', 'spook.png'],
      ['Helmut', 'pic1.jpg'],
    ]
    
    # Insert the pictures
    insert = 'INSERT INTO animal_pics (name, picture) VALUES (?, ?)'
    stmt = DB2::prepare conn, insert
    if !stmt
     throw "Attempt to prepare statement failed."
    end
    for animal in animals
      name = animal[0]
      picture = open(animal[1]) {|f| f.read}
      if !picture
       throw "Could not retrieve picture '#{animal[1]}'."
      end
      DB2::bind_param stmt, 1, 'name', DB2::PARAM_IN
      DB2::bind_param stmt, 2, 'picture', DB2::PARAM_IN, DB2::BINARY
      result = DB2::execute stmt
    end
  end

end
