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