class TestIbmDb2 < Test::Unit::TestCase

  def prepare conn
    # Drop the test view, in case it exists
    drop = 'DROP TABLE anime_cat'
    result = DB2::exec(conn, drop) rescue nil
    
    # Drop the test table, in case it exists
    drop = 'DROP TABLE animals'
    result = DB2::exec(conn, drop) rescue nil
    
    # Drop the test table for LOBs, in case it exists
    drop = 'DROP TABLE animal_pics'
    result = DB2::exec(conn, drop) rescue nil
    
    # Create the test table
    create = 'CREATE TABLE animals (id INTEGER, breed VARCHAR(32), name CHAR(16), weight DECIMAL(7,2))'
    result = DB2::exec conn, create
    
    # Populate the test table
    animals = [
      [0, 'cat', 'Pook', 3.2],
      [1, 'dog', 'Peaches', 12.3],
      [2, 'horse', 'Smarty', 350.0],
      [3, 'gold fish', 'Bubbles', 0.1],
      [4, 'budgerigar', 'Gizmo', 0.2],
      [5, 'goat', 'Rickety Ride', 9.7],
      [6, 'llama', 'Sweater', 150]
    ]
    
    insert = 'INSERT INTO animals (id, breed, name, weight) VALUES (?, ?, ?, ?)'
    stmt = DB2::prepare conn, insert
    if stmt
      for animal in animals
        result = DB2::execute stmt, animal
      end
    end
    
    # Create test view
    DB2::exec(conn, 'CREATE VIEW anime_cat AS
      SELECT name, breed FROM animals
      WHERE id = 0')
  end

end
