bug72524.phpt 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. --TEST--
  2. Bug #72524 (Binding null values triggers ORA-24816 error)
  3. --EXTENSIONS--
  4. oci8
  5. --SKIPIF--
  6. <?php
  7. $target_dbs = array('oracledb' => true, 'timesten' => true); // test runs on these DBs
  8. require(__DIR__.'/skipif.inc');
  9. ?>
  10. --FILE--
  11. <?php
  12. require(__DIR__.'/connect.inc');
  13. // Initialize
  14. $stmtarray = array(
  15. "CREATE TABLE mytable (clob_col CLOB DEFAULT NULL, varchar2_col VARCHAR2(255) DEFAULT NULL)"
  16. );
  17. oci8_test_sql_execute($c, $stmtarray);
  18. // Run test
  19. $sql = "INSERT INTO mytable VALUES (:clob_col, :varchar2_col)";
  20. echo "Test 1 - P1 Value: NULL P1 Length: Default P1 Type: Default P2 Value: NULL P2 Length: Default P2 Type: Default\n";
  21. $stmt = oci_parse($c, $sql);
  22. $clob = NULL;
  23. $varchar2 = NULL;
  24. oci_bind_by_name($stmt, ':clob_col', $clob);
  25. oci_bind_by_name($stmt, ':varchar2_col', $varchar2);
  26. var_dump(oci_execute($stmt));
  27. echo "Test 2 - P1 Value: '' P1 Length: Default P1 Type: Default P2 Value: '' P2 Length: Default P2 Type: Default\n";
  28. $clob = '';
  29. $varchar2 = '';
  30. oci_bind_by_name($stmt, ':clob_col', $clob);
  31. oci_bind_by_name($stmt, ':varchar2_col', $varchar2);
  32. var_dump(oci_execute($stmt));
  33. echo "Test 3 - P1 Value: 'abc' P1 Length: 0 P1 Type: Default P2 Value: '' P2 Length: 0 P2 Type: Default\n";
  34. $clob = 'abc';
  35. $varchar2 = 'abc';
  36. oci_bind_by_name($stmt, ':clob_col', $clob, 0);
  37. oci_bind_by_name($stmt, ':varchar2_col', $varchar2, 0);
  38. var_dump(oci_execute($stmt));
  39. echo "Test 4 - P1 Value: NULL P1 Length: -1 P1 Type: SQLT_LNG P2 Value: NULL P2 Length: -1 P2 Type:Default\n";
  40. $clob = NULL;
  41. $varchar2 = NULL;
  42. oci_bind_by_name($stmt, ':clob_col', $clob, -1, SQLT_LNG);
  43. oci_bind_by_name($stmt, ':varchar2_col', $varchar2, -1, SQLT_LNG);
  44. var_dump(oci_execute($stmt));
  45. echo "Test 5 - P1 Value: NULL P1 Length: 0 P1 Type: SQLT_LNG P2 Value: NULL P2 Length: 0 P2 Type:Default\n";
  46. $clob = NULL;
  47. $varchar2 = NULL;
  48. oci_bind_by_name($stmt, ':clob_col', $clob, 0, SQLT_LNG);
  49. oci_bind_by_name($stmt, ':varchar2_col', $varchar2, 0, SQLT_LNG);
  50. var_dump(oci_execute($stmt));
  51. // Cleanup
  52. $stmtarray = array(
  53. "DROP TABLE mytable"
  54. );
  55. oci8_test_sql_execute($c, $stmtarray);
  56. ?>
  57. --EXPECTF--
  58. Test 1 - P1 Value: NULL P1 Length: Default P1 Type: Default P2 Value: NULL P2 Length: Default P2 Type: Default
  59. bool(true)
  60. Test 2 - P1 Value: '' P1 Length: Default P1 Type: Default P2 Value: '' P2 Length: Default P2 Type: Default
  61. bool(true)
  62. Test 3 - P1 Value: 'abc' P1 Length: 0 P1 Type: Default P2 Value: '' P2 Length: 0 P2 Type: Default
  63. bool(true)
  64. Test 4 - P1 Value: NULL P1 Length: -1 P1 Type: SQLT_LNG P2 Value: NULL P2 Length: -1 P2 Type:Default
  65. Warning: oci_execute(): ORA-24816: %s in %s on line %d
  66. bool(false)
  67. Test 5 - P1 Value: NULL P1 Length: 0 P1 Type: SQLT_LNG P2 Value: NULL P2 Length: 0 P2 Type:Default
  68. Warning: oci_execute(): ORA-24816: %s in %s on line %d
  69. bool(false)