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