bug52891.phpt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. --TEST--
  2. Bug #52891 (Wrong data inserted with mysqli/mysqlnd when using bind_param,value > LONG_MAX)
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifconnectfailure.inc');
  7. if (!$IS_MYSQLND) {
  8. die("skip: test applies only to mysqlnd");
  9. }
  10. ?>
  11. --FILE--
  12. <?php
  13. require_once("connect.inc");
  14. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
  15. printf("[001] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  16. }
  17. if (!$link->query("DROP TABLE IF EXISTS tuint") ||
  18. !$link->query("DROP TABLE IF EXISTS tsint")) {
  19. printf("[002] [%d] %s\n", $link->errno, $link->error);
  20. }
  21. if (!$link->query("CREATE TABLE tuint(a BIGINT UNSIGNED) ENGINE=" . $engine) ||
  22. !$link->query("CREATE TABLE tsint(a BIGINT) ENGINE=" . $engine)) {
  23. printf("[003] [%d] %s\n", $link->errno, $link->error);
  24. }
  25. if (!$stmt1 = $link->prepare("INSERT INTO tuint VALUES(?)"))
  26. printf("[004] [%d] %s\n", $link->errno, $link->error);
  27. if (!$stmt2 = $link->prepare("INSERT INTO tsint VALUES(?)"))
  28. printf("[005] [%d] %s\n", $link->errno, $link->error);
  29. $param = 42;
  30. if (!$stmt1->bind_param("i", $param))
  31. printf("[006] [%d] %s\n", $stmt1->errno, $stmt1->error);
  32. if (!$stmt2->bind_param("i", $param))
  33. printf("[007] [%d] %s\n", $stmt2->errno, $stmt2->error);
  34. /* first insert normal value to force initial send of types */
  35. if (!$stmt1->execute())
  36. printf("[008] [%d] %s\n", $stmt1->errno, $stmt1->error);
  37. if (!$stmt2->execute())
  38. printf("[009] [%d] %s\n", $stmt2->errno, $stmt2->error);
  39. /* now try values that don't fit in long, on 32bit, new types should be sent or 0 will be inserted */
  40. $param = -4294967297;
  41. if (!$stmt2->execute())
  42. printf("[010] [%d] %s\n", $stmt2->errno, $stmt2->error);
  43. /* again normal value */
  44. $param = 43;
  45. if (!$stmt1->execute())
  46. printf("[011] [%d] %s\n", $stmt1->errno, $stmt1->error);
  47. if (!$stmt2->execute())
  48. printf("[012] [%d] %s\n", $stmt2->errno, $stmt2->error);
  49. /* again conversion */
  50. $param = -4294967295;
  51. if (!$stmt2->execute())
  52. printf("[013] [%d] %s\n", $stmt2->errno, $stmt2->error);
  53. $param = 4294967295;
  54. if (!$stmt1->execute())
  55. printf("[014] [%d] %s\n", $stmt1->errno, $stmt1->error);
  56. if (!$stmt2->execute())
  57. printf("[015] [%d] %s\n", $stmt2->errno, $stmt2->error);
  58. $param = 4294967297;
  59. if (!$stmt1->execute())
  60. printf("[016] [%d] %s\n", $stmt1->errno, $stmt1->error);
  61. if (!$stmt2->execute())
  62. printf("[017] [%d] %s\n", $stmt2->errno, $stmt2->error);
  63. $result = $link->query("SELECT * FROM tsint ORDER BY a ASC");
  64. $result2 = $link->query("SELECT * FROM tuint ORDER BY a ASC");
  65. echo "tsint:\n";
  66. while ($row = $result->fetch_assoc()) {
  67. var_dump($row);
  68. }
  69. echo "tuint:\n";
  70. while ($row = $result2->fetch_assoc()) {
  71. var_dump($row);
  72. }
  73. echo "done";
  74. ?>
  75. --CLEAN--
  76. <?php
  77. require_once('connect.inc');
  78. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
  79. printf("[clean] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  80. $host, $user, $db, $port, $socket);
  81. }
  82. if (!mysqli_query($link, 'DROP TABLE IF EXISTS tuint')) {
  83. printf("[clean] Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  84. }
  85. if (!mysqli_query($link, 'DROP TABLE IF EXISTS tsint')) {
  86. printf("[clean] Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  87. }
  88. mysqli_close($link);
  89. ?>
  90. --EXPECTF--
  91. tsint:
  92. array(1) {
  93. ["a"]=>
  94. string(11) "-4294967297"
  95. }
  96. array(1) {
  97. ["a"]=>
  98. string(11) "-4294967295"
  99. }
  100. array(1) {
  101. ["a"]=>
  102. string(2) "42"
  103. }
  104. array(1) {
  105. ["a"]=>
  106. string(2) "43"
  107. }
  108. array(1) {
  109. ["a"]=>
  110. string(10) "4294967295"
  111. }
  112. array(1) {
  113. ["a"]=>
  114. string(10) "4294967297"
  115. }
  116. tuint:
  117. array(1) {
  118. ["a"]=>
  119. string(2) "42"
  120. }
  121. array(1) {
  122. ["a"]=>
  123. string(2) "43"
  124. }
  125. array(1) {
  126. ["a"]=>
  127. string(10) "4294967295"
  128. }
  129. array(1) {
  130. ["a"]=>
  131. string(10) "4294967297"
  132. }
  133. done