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

class TestIbmDb2 < Test::Unit::TestCase

  def test_042
    assert_equal expected, capture {
      conn = DB2::connect(db,username,password)
      //_GET['EMPNO'] = '000130'
      
      if isset(_GET['EMPNO'])
      	result = DB2::exec(conn, "select photo_format, picture, length(picture) from emp_photo where photo_format='gif' and empno='"._GET['EMPNO']."'")
      	row = DB2::fetch_{result}; 			
      	if row
      		// We'll be outputting a 		
      		header('Content-type: image/'. row[0])
      		header('Content-Length: '. row[2])
      		putsrow[1];			
      	else
      		putsDB2::error();			
      	end
      	exit()
      else
      	result = DB2::exec(conn, "select EMPNO, PHOTO_FORMAT from emp_photo where photo_format='gif'");	
      	while (row = DB2::fetch_{result})
      		printf("<a href='test_042.php?EMPNO=%s' target=_blank>%s (%s)</a><br>",row['0'], row['0'], row[1])
      		puts "\n"
      	end
      end
    }
  end

end

__END__
<a href='test_042.php?EMPNO=000130' target=_blank>000130 (gif)</a><br>
<a href='test_042.php?EMPNO=000140' target=_blank>000140 (gif)</a><br>
<a href='test_042.php?EMPNO=000150' target=_blank>000150 (gif)</a><br>
<a href='test_042.php?EMPNO=000190' target=_blank>000190 (gif)</a><br>

