home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / sequences.inc < prev    next >
Encoding:
Text File  |  2004-03-24  |  2.4 KB  |  96 lines

  1.  
  2. <?php // -*- PHP -*-
  3.  
  4. function error_handler(&$obj) {
  5.     print "sequences.inc error_handler:\n    ";
  6.     print $obj->getMessage();
  7. }
  8. ob_implicit_flush(true);
  9.  
  10. $drop = $dbh->dropSequence('test');
  11. if (DB::isError($drop) &&
  12.     $drop->getMessage() != 'DB Error: no such table')
  13. {
  14.     print 'Could not drop sequence... ' . $drop->getMessage() . "\n";
  15.     if ($dbh->phptype == 'ibase' &&
  16.         $drop->getMessage() == 'DB Error: insufficient permissions')
  17.     {
  18.         print "Use this query to provide the permissions needed:\n";
  19.         print '   grant all on RDB$GENERATORS to <USERNAME>';
  20.     }
  21.     exit;
  22. }
  23.  
  24. // 1) test that sequences are not created if "ondemand" is false
  25.  
  26. $e = $dbh->nextId("test", false);
  27. if (DB::isError($e)) {
  28.     print $e->getMessage() . "\n";
  29. } else {
  30.     print "test 1) failed!\n";
  31. }
  32.  
  33. // 2) test that the sequence is not created but the error is
  34. // handled by the class error handler
  35. $dbh->setErrorHandling(PEAR_ERROR_PRINT, "%s <- good error catched\n");
  36. $e = $dbh->nextId("test", false);
  37. if (!DB::isError($e)) {
  38.     print "test 2) failed!\n";
  39. }
  40. $dbh->_default_error_mode = null;
  41.  
  42. // 3) test that sequences are created if "ondemand" is true, and that
  43. // two successive nextIds return adjacent values
  44. $a = $dbh->nextId("test");
  45. $b = $dbh->nextId("test");
  46. if (DB::isError($a)) {
  47.     print "a: ".$a->toString()."\n";
  48. } else {
  49.     print "a=$a\n";
  50. }
  51. if (DB::isError($b)) {
  52.     print "b: ".$b->toString()."\n";
  53. } else {
  54.     print "b=$b\n";
  55. }
  56. print "b-a=".($b-$a)."\n";
  57.  
  58. // 4) test that the user-specified error handler is really disabled
  59. // during nextId, with per-object handler as well as global handler
  60. $dbh->dropSequence("test");
  61.  
  62. $dbh->setErrorHandling(PEAR_ERROR_CALLBACK, "error_handler");
  63. $c = $dbh->nextId("test");
  64. if (DB::isError($c)) {
  65.     print "c: ".$c->toString()."\n";
  66. } else {
  67.     print "c=$c\n";
  68. }
  69. $dbh->dropSequence("test");
  70. $dbh->_default_error_mode = null;
  71. PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, "error_handler");
  72. $d = $dbh->nextId("test");
  73. if (DB::isError($d)) {
  74.     print "d: ".$d->toString()."\n";
  75. } else {
  76.     print "d=$d\n";
  77. }
  78.  
  79. // 5) test that the sequence is handled right when the table is empty
  80.  
  81. // Backend with real sequences may don't like that
  82. PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
  83. $dbh->query('DELETE FROM test_seq');
  84. PEAR::popErrorHandling();
  85. $e = $dbh->nextID('test');
  86. if (DB::isError($d)) {
  87.     print "e: ".$d->toString()."\n";
  88. } else {
  89.     print "e=$d\n";
  90. }
  91.  
  92. // final clean-up
  93. $dbh->dropSequence("test");
  94.  
  95. ?>
  96.