conn_attr_4.phpt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. --TEST--
  2. Set and get of connection attributes with errors.
  3. --EXTENSIONS--
  4. oci8
  5. --SKIPIF--
  6. <?php
  7. $target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs
  8. require(__DIR__.'/skipif.inc');
  9. if (getenv('SKIP_SLOW_TESTS')) die('skip slow tests excluded by request');
  10. if (strcasecmp($user, "system") && strcasecmp($user, "sys")) die("skip needs to be run as a DBA user");
  11. if ($test_drcp) die("skip output might vary with DRCP");
  12. preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
  13. if (!(isset($matches[0]) &&
  14. (($matches[1] == 11 && $matches[2] >= 2) ||
  15. ($matches[1] >= 12)
  16. ))) {
  17. // Bug fixed in 11.2 prevents client_info being reset
  18. die("skip expected output only valid when using Oracle 11gR2 or greater database server");
  19. }
  20. ?>
  21. --FILE--
  22. <?php
  23. error_reporting(E_ALL ^ E_DEPRECATED);
  24. $testuser = 'testuser_attr_4'; // Used in conn_attr.inc
  25. $testpassword = 'testuser';
  26. require(__DIR__."/conn_attr.inc");
  27. $attr_array = array('MODULE','ACTION','CLIENT_INFO','CLIENT_IDENTIFIER');
  28. echo"**Test Negative cases************\n";
  29. echo "\nInvalid Connection resource 1\n";
  30. $nc1=NULL;
  31. // Invalid connection handle.
  32. try {
  33. oci_set_action($nc1,$nc1);
  34. } catch (TypeError $e) {
  35. var_dump($e->getMessage());
  36. }
  37. // Variable instead of a connection resource.
  38. echo "\nInvalid Connection resource 2\n";
  39. $str1= 'not a conn';
  40. try {
  41. oci_set_client_info($str1,$str1);
  42. } catch (TypeError $e) {
  43. var_dump($e->getMessage());
  44. }
  45. // Setting an Invalid value.
  46. echo "\nInvalid Action value \n";
  47. $c1=oci_connect($testuser,$testpassword,$dbase);
  48. try {
  49. oci_set_action($c1,$c1);
  50. } catch (TypeError $e) {
  51. var_dump($e->getMessage());
  52. }
  53. // Setting values multiple times.
  54. echo "\nSet Values multiple times \n";
  55. var_dump(oci_set_action($c1,'ACTION1'));
  56. var_dump(oci_set_action($c1,'ACTION1'));
  57. var_dump(oci_set_action($c1,'ACTION2'));
  58. var_dump(oci_set_action($c1,'ACTION1'));
  59. get_attr($c1,'ACTION');
  60. // Testing with different types of values
  61. // NB. This may diff in 11.1.0.6 due to a bug causing CLIENT_INFO of NULL to be ignored.
  62. echo "\nSetting to different values \n";
  63. $values_array = array(1000,NULL,'this is a very huge string with a length > 64 !!!!!this is a very huge string with a length > 64 !!!!!this is a very huge string with a length > 64 !!!!!this is a very huge string with a length > 64 !!!!!');
  64. foreach($values_array as $val ) {
  65. oci_set_module_name($c1,$val);
  66. oci_set_client_identifier($c1,$val);
  67. oci_set_client_info($c1,$val);
  68. $r = oci_set_action($c1,$val);
  69. if ($r) {
  70. echo "Values set successfully to $val\n";
  71. foreach($attr_array as $attr) {
  72. get_attr($c1,$attr);
  73. }
  74. }
  75. }
  76. clean_up($c);
  77. echo "Done\n";
  78. ?>
  79. --EXPECTF--
  80. **Test Negative cases************
  81. Invalid Connection resource 1
  82. string(%d) "oci_set_action(): Argument #1 ($connection) must be of type resource, null given"
  83. Invalid Connection resource 2
  84. string(%d) "oci_set_client_info(): Argument #1 ($connection) must be of type resource, string given"
  85. Invalid Action value
  86. string(%d) "oci_set_action(): Argument #2 ($action) must be of type string, resource given"
  87. Set Values multiple times
  88. bool(true)
  89. bool(true)
  90. bool(true)
  91. bool(true)
  92. The value of ACTION is ACTION1
  93. Setting to different values
  94. Values set successfully to 1000
  95. The value of MODULE is 1000
  96. The value of ACTION is 1000
  97. The value of CLIENT_INFO is 1000
  98. The value of CLIENT_IDENTIFIER is 1000
  99. Values set successfully to
  100. The value of MODULE is
  101. The value of ACTION is
  102. The value of CLIENT_INFO is
  103. The value of CLIENT_IDENTIFIER is
  104. Warning: oci_set_module_name(): ORA-24960: %s OCI_ATTR_MODULE %s on line %d
  105. Warning: oci_set_client_identifier(): ORA-24960: %s OCI_ATTR_CLIENT_IDENTIFIER %s on line %d
  106. Warning: oci_set_client_info(): ORA-24960: %s OCI_ATTR_CLIENT_INFO %s on line %d
  107. Warning: oci_set_action(): ORA-24960: %s OCI_ATTR_ACTION %s on line %d
  108. Done