home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl502b.zip / ext / DB2CLI / t2.pl < prev    next >
Text File  |  1995-08-10  |  1KB  |  39 lines

  1. use DB2CLI;
  2.  
  3. SQLAllocEnv($henv)                and message("AllocEnv");
  4. SQLAllocConnect($henv, $hdbc)            and message("AllocConnect");
  5. SQLConnect($hdbc, 'SAMPLE', 'AK', '')        and message("Connect");
  6. SQLAllocStmt($hdbc, $hstmt)            and message("AllocStmt");
  7.  
  8. SQLPrepare($hstmt, <<)                and message("Prepare");
  9.     SELECT name,salary FROM ADMIN.STAFF
  10.         WHERE salary >= ?
  11.  
  12. SQLExecute($hstmt, 20000)            and message("Execute");
  13.  
  14. while (($r = SQLFetch($hstmt)) == 0) {
  15.     SQLGetData($hstmt, 1, SQL_C_CHAR(), $name)    and message("GetData");
  16.     SQLGetData($hstmt, 2, SQL_C_DOUBLE(), $sal)    and message("GetData");
  17.     print "$name,$sal\n";
  18. }
  19. message("Fetch", $r) if $r != SQL_NO_DATA_FOUND();
  20.  
  21. SQLFreeStmt($hstmt)                and message("FreeStmt");
  22. SQLDisconnect($hdbc)                and message("Disconnect");
  23. SQLFreeConnect($hdbc)                and message("FreeConnect");
  24. SQLFreeEnv($henv)                and message("FreeEnv");
  25.  
  26. exit 0;
  27.  
  28. sub message
  29. {
  30.     my ($where, $retcode) = @_;
  31.     my ($state, $native, $text);
  32.     if (SQLError($henv, $hdbc, $hstmt, $state, $native, $text) >= 0) {
  33.     print "$where: $state,$native: $text\n";
  34.     exit 1;
  35.     }
  36.     print "$where: cannot retrieve error info, retcode=$retcode\n";
  37.     exit 2;
  38. }
  39.