mysqli_get_warnings.phpt 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. --TEST--
  2. mysqli_get_warnings() - TODO
  3. --EXTENSIONS--
  4. mysqli
  5. --SKIPIF--
  6. <?php
  7. require_once('skipifconnectfailure.inc');
  8. require_once('connect.inc');
  9. if (!$TEST_EXPERIMENTAL)
  10. die("skip - experimental (= unsupported) feature");
  11. ?>
  12. --FILE--
  13. <?php
  14. require_once("connect.inc");
  15. $tmp = NULL;
  16. $link = NULL;
  17. if (!is_null($tmp = @mysqli_get_warnings()))
  18. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  19. if (!is_null($tmp = @mysqli_get_warnings($link)))
  20. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  21. if (!is_null($tmp = @mysqli_get_warnings('')))
  22. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  23. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
  24. printf("[003] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  25. }
  26. if (false !== ($tmp = mysqli_get_warnings($link))) {
  27. printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), (is_object($tmp) ? var_dump($tmp, true) : $tmp));
  28. }
  29. if (!mysqli_query($link, "DROP TABLE IF EXISTS test"))
  30. printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  31. if (!mysqli_query($link, "CREATE TABLE test (id SMALLINT)"))
  32. printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  33. if (!mysqli_query($link, "INSERT INTO test (id) VALUES (1000000)"))
  34. printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  35. if (!is_object($warning = mysqli_get_warnings($link)) || 'mysqli_warning' != get_class($warning)) {
  36. printf("[008] Expecting object/mysqli_warning, got %s/%s\n", gettype($tmp), (is_object($tmp) ? var_dump($tmp, true) : $tmp));
  37. }
  38. if (!method_exists($warning, 'next'))
  39. printf("[009] Borked object, method next is missing\n");
  40. $properties = array_merge(get_object_vars($warning), get_class_vars(get_class($warning)));
  41. if (!empty($properties))
  42. printf("[010] Properties have always been magic, hidden things - why are they visible now, a BC break...\n");
  43. if ((!is_string($warning->message)) || ('' == $warning->message)) /* NULL or not there at all */
  44. printf("[011] Expecting string/not empty, got %s/%s\n", gettype($warning->message), $warning->message);
  45. if ((!is_string($warning->sqlstate)) || ('' == $warning->sqlstate)) /* NULL or not there at all */
  46. printf("[012] Expecting string/not empty, got %s/%s\n", gettype($warning->sqlstate), $warning->sqlstate);
  47. if ((!is_int($warning->errno)) || (0 == $warning->errno)) /* NULL or not there at all */
  48. printf("[013] Expecting int/not 0, got %s/%s\n", gettype($warning->errno), $warning->errno);
  49. if (false !== ($tmp = $warning->next()))
  50. printf("[014] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  51. if (!mysqli_query($link, "INSERT INTO test (id) VALUES (1000000), (1000001)"))
  52. printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  53. if (($tmp = mysqli_warning_count($link)) !== 2)
  54. printf("[016] Expecting 2 warnings, got %d warnings", $tmp);
  55. if (!is_object($warning = mysqli_get_warnings($link)) || 'mysqli_warning' != get_class($warning)) {
  56. printf("[017] Expecting object/mysqli_warning, got %s/%s\n", gettype($tmp), (is_object($tmp) ? var_dump($tmp, true) : $tmp));
  57. }
  58. if (true !== ($tmp = $warning->next()))
  59. printf("[018] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  60. if (false !== ($tmp = $warning->next()))
  61. printf("[020] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  62. mysqli_close($link);
  63. if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
  64. printf("[021] Cannot create mysqli object: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  65. if (!$mysqli->query("DROP TABLE IF EXISTS t1"))
  66. printf("[022] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  67. if (!$mysqli->query("CREATE TABLE t1 (a smallint)"))
  68. printf("[023] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  69. if (!is_object($warning = new mysqli_warning($mysqli)))
  70. printf("[024] Expecting object/mysqli_warning, got %s/%s", gettype($warning), $warning);
  71. if (!is_string($warning->message) || ('' == $warning->message))
  72. printf("[025] Expecting string, got %s/%s", gettype($warning->message), $warning->message);
  73. if (!$mysqli->query("DROP TABLE t1"))
  74. printf("[026] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  75. /* Yes, I really want to check if the object property is empty */
  76. if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
  77. printf("[027] Cannot create mysqli object: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  78. $warning = new mysqli_warning($mysqli);
  79. if (false !== ($tmp = $warning->next()))
  80. printf("[028] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  81. if ('' != ($tmp = $warning->message))
  82. printf("[029] Expecting string/empty, got %s/%s\n", gettype($tmp), $tmp);
  83. if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
  84. printf("[030] Cannot create mysqli object: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  85. if (!$mysqli->query("DROP TABLE IF EXISTS t1"))
  86. printf("[031] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  87. if (!$mysqli->query("CREATE TABLE t1 (a smallint)"))
  88. printf("[032] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  89. /* out of range, three warnings */
  90. if (!$mysqli->query("INSERT IGNORE INTO t1(a) VALUES (65536), (65536), (65536)"))
  91. printf("[033] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  92. $warning = new mysqli_warning($mysqli);
  93. $i = 1;
  94. while ($warning->next() && ('' != ($tmp = $warning->message))) {
  95. $i++;
  96. }
  97. if (3 != $i)
  98. printf("[034] Expecting three warnings, got %d warnings\n", $i);
  99. $stmt = mysqli_stmt_init();
  100. $warning = new mysqli_warning($stmt);
  101. if (false !== ($tmp = $warning->next()))
  102. printf("[035] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  103. print "done!";
  104. ?>
  105. <?php
  106. require_once("connect.inc");
  107. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  108. printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  109. if (!mysqli_query($link, "DROP TABLE IF EXISTS test"))
  110. printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  111. if (!mysqli_query($link, "DROP TABLE IF EXISTS t1"))
  112. printf("[c003] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  113. mysqli_close($link);
  114. ?>
  115. --EXPECT--
  116. done!