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

  1. use DB2CLI;
  2.  
  3. SQLAllocEnv($henv)                and message("AllocEnv");
  4. SQLAllocConnect($henv, $hdbc)            and message("AllocConnect");
  5. SQLConnect($hdbc, 'SAMPLE', 'DBA', '')        and message("Connect");
  6. SQLSetConnectOption($hdbc, SQL_AUTOCOMMIT(), SQL_AUTOCOMMIT_OFF());
  7. SQLAllocStmt($hdbc, $hstmt)            and message("AllocStmt");
  8.  
  9. SQLPrepare($hstmt, <<)                and message("Prepare");
  10.     INSERT INTO admin.emp_photo (empno,photo_format,picture)
  11.            VALUES (?, 'GIF', ?)
  12.  
  13. SQLExecute2($hstmt,
  14.         SQL_C_CHAR(), SQL_CHAR(), '998',
  15.         SQL_C_CHAR(), SQL_BLOB(), "303132")
  16.                         and message("Execute2 1");
  17. SQLExecute2($hstmt,
  18.         SQL_C_CHAR(),   SQL_CHAR(), '999',
  19.         SQL_C_BINARY(), SQL_BLOB(), "\x41\x42\x43")
  20.                         and message("Execute2 2");
  21.  
  22. SQLTransact($henv, $hdbc, SQL_ROLLBACK());
  23.  
  24. SQLFreeStmt($hstmt, SQL_DROP())            and message("FreeStmt");
  25. SQLDisconnect($hdbc)                and message("Disconnect");
  26. SQLFreeConnect($hdbc)                and message("FreeConnect");
  27. SQLFreeEnv($henv)                and message("FreeEnv");
  28.  
  29. exit 0;
  30.  
  31. sub message
  32. {
  33.     my ($where, $retcode) = @_;
  34.     my ($state, $native, $text);
  35.     if (SQLError($henv, $hdbc, $hstmt, $state, $native, $text) >= 0) {
  36.     print "$where: $state,$native:\n$text\n";
  37.     SQLTransact($henv, $hdbc, SQL_ROLLBACK());
  38.     exit 1;
  39.     }
  40.     print "$where: cannot retrieve error info, retcode=$retcode\n";
  41.     SQLTransact($henv, $hdbc, SQL_ROLLBACK());
  42.     exit 2;
  43. }
  44.