xref: /PHP-7.1/ext/mysqli/tests/bug35103.phpt (revision eb0e09f5)
1--TEST--
2Bug #35103 (Bad handling of unsigned bigint)
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10
11$drop = <<<EOSQL
12DROP TABLE test_bint;
13DROP TABLE test_buint;
14EOSQL;
15	require_once("connect.inc");
16
17	$mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
18	$mysql->query("DROP TABLE IF EXISTS test_bint");
19	$mysql->query("CREATE TABLE test_bint (a bigint(20) default NULL) ENGINE=MYISAM");
20	$mysql->query("INSERT INTO test_bint VALUES (9223372036854775807),(-9223372036854775808),(-2147483648),(-2147483649),(-2147483647),(2147483647),(2147483648),(2147483649)");
21
22	$mysql->query("DROP TABLE IF EXISTS test_buint");
23	$mysql->query("CREATE TABLE test_buint (a bigint(20) unsigned default NULL)");
24	$mysql->query("INSERT INTO test_buint VALUES (18446744073709551615),(9223372036854775807),(9223372036854775808),(2147483647),(2147483649),(4294967295)");
25
26	$stmt = $mysql->prepare("SELECT a FROM test_bint ORDER BY a");
27	$stmt->bind_result($v);
28	$stmt->execute();
29	$i=0;
30	echo "BIG INT SIGNED, TEST\n";
31	while ($i++ < 8) {
32		$stmt->fetch();
33		echo $v, "\n";
34	}
35	$stmt->close();
36
37	echo str_repeat("-", 20), "\n";
38
39	$stmt = $mysql->prepare("SELECT a FROM test_buint ORDER BY a");
40	$stmt->bind_result($v2);
41	$stmt->execute();
42	$j=0;
43	echo "BIG INT UNSIGNED TEST\n";
44	while ($j++ < 6) {
45		$stmt->fetch();
46		echo $v2, "\n";
47	}
48	$stmt->close();
49
50	$mysql->multi_query($drop);
51
52	$mysql->close();
53?>
54--CLEAN--
55<?php
56require_once("connect.inc");
57if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
58   printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
59
60if (!mysqli_query($link, "DROP TABLE IF EXISTS test_bint") || !mysqli_query($link, "DROP TABLE IF EXISTS test_buint"))
61	printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
62
63mysqli_close($link);
64?>
65--EXPECT--
66BIG INT SIGNED, TEST
67-9223372036854775808
68-2147483649
69-2147483648
70-2147483647
712147483647
722147483648
732147483649
749223372036854775807
75--------------------
76BIG INT UNSIGNED TEST
772147483647
782147483649
794294967295
809223372036854775807
819223372036854775808
8218446744073709551615
83