bug52891.phpt 4.1 KB

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