--TEST-- Playing with SELECT FORMAT(...) AS _format - see also bugs.php.net/42378 --SKIPIF-- --INI-- memory_limit=83886080 --FILE-- $v) $expected[$k] = number_format(round($v), 0, '.', ','); test_format($link, 'id AS order_by_col, FORMAT(col1, 0)', 'test', 'id', $expected, 100); $expected = create_table($link, 'FLOAT UNSIGNED', 0, 10000, $engine, 110); foreach ($expected as $k => $v) $expected[$k] = number_format(round($v), 0, '.', ','); test_format($link, 'id AS order_by_col, FORMAT(col1, 0)', 'test', 'id', $expected, 120); $expected = create_table($link, 'TINYINT', -128, 127, $engine, 130); foreach ($expected as $k => $v) $expected[$k] = number_format(round($v), 0, '.', ','); test_format($link, 'id AS order_by_col, FORMAT(col1, 0)', 'test', 'id', $expected, 140); $expected = create_table($link, 'SMALLINT UNSIGNED', 0, 65535, $engine, 150); foreach ($expected as $k => $v) $expected[$k] = number_format(round($v), 0, '.', ','); test_format($link, 'id AS order_by_col, FORMAT(col1, 0)', 'test', 'id', $expected, 160); $expected = create_table($link, 'MEDIUMINT', 0, 8388607, $engine, 170); foreach ($expected as $k => $v) $expected[$k] = number_format(round($v), 0, '.', ','); test_format($link, 'id AS order_by_col, FORMAT(col1, 0)', 'test', 'id', $expected, 180); $expected = create_table($link, 'INT UNSIGNED', 0, 1000, $engine, 190); foreach ($expected as $k => $v) $expected[$k] = number_format(round($v), 0, '.', ','); test_format($link, 'id AS order_by_col, FORMAT(col1, 0)', 'test', 'id', $expected, 200); $expected = create_table($link, 'BIGINT', -1000, 1000, $engine, 210); foreach ($expected as $k => $v) $expected[$k] = number_format(round($v), 0, '.', ','); test_format($link, 'id AS order_by_col, FORMAT(col1, 0)', 'test', 'id', $expected, 220); $expected = create_table($link, 'DECIMAL(5,0)', -1000, 1000, $engine, 230); foreach ($expected as $k => $v) $expected[$k] = number_format(round($v), 0, '.', ','); test_format($link, 'id AS order_by_col, FORMAT(col1, 0)', 'test', 'id', $expected, 240); // http://bugs.php.net/bug.php?id=42378 if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) { printf("[300] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } if (mysqli_query($link, "CREATE TABLE `test` ( `targetport` int(11) NOT NULL default '0', `sources` double(17,4) default NULL, `current_sources` double(17,4) default NULL, `reports` double(17,4) default NULL, `current_reports` double(17,4) default NULL, `targets` double(17,4) default NULL, `current_targets` double(17,4) default NULL, `maxsources` int(11) default NULL, `maxtargets` int(11) default NULL, `maxreports` int(11) default NULL, `trend` float default NULL, PRIMARY KEY (`targetport`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1")) { do { $values = array(); for ($i = 0; $i < 200; $i++) { $current_targets = mt_rand(-100000, 100000) / 10; do { $trend = (mt_rand(0, 3) > 1) ? (mt_rand(-10000, 10000) / 100) : 'NULL'; } while (isset($values[$trend])); $sql = sprintf('INSERT INTO test(targetport, current_targets, maxreports, trend) VALUES (%d, %f, %s, %s)', $i, $current_targets, (mt_rand(0, 1) > 0) ? mt_rand(0, 1000) : 'NULL', $trend); if (!mysqli_query($link, $sql)) { printf("[301] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); break 2; } if ($current_targets > 0 && $trend !== 'NULL') $values[$trend] = $i; } krsort($values); if (!$stmt = mysqli_stmt_init($link)) { printf("[302] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); break; } if (!mysqli_stmt_prepare($stmt, 'SELECT trend, targetport, FORMAT(trend, 2) FROM test WHERE current_targets > 0 AND trend IS NOT NULL ORDER BY trend DESC LIMIT 100')) { printf("[303] [%d] %s\n", mysqli_stmt_errno($link), mysqli_stmt_error($link)); break; } if (!mysqli_stmt_execute($stmt)) { printf("[304] [%d] %s\n", mysqli_stmt_errno($link), mysqli_stmt_error($link)); break; } if (!mysqli_stmt_store_result($stmt)) { printf("[305] [%d] %s\n", mysqli_stmt_errno($link), mysqli_stmt_error($link)); break; } $trend = $targetport = $format = null; if (!mysqli_stmt_bind_result($stmt, $trend, $targetport, $format)) { printf("[305] [%d] %s\n", mysqli_stmt_errno($link), mysqli_stmt_error($link)); break; } reset($values); while (mysqli_stmt_fetch($stmt)) { list($exp_trend, $exp_targetport) = each($values); if ($targetport != $exp_targetport) { printf("[306] Values fetched from MySQL seem to be wrong, check manually\n"); printf("%s/%s - %s/%s - '%s'\n", $trend, $exp_trend, $targetport, $exp_targetport, $format); } } mysqli_stmt_free_result($stmt); mysqli_stmt_close($stmt); // same but OO interface if (!$stmt = mysqli_stmt_init($link)) { printf("[307] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); break; } if (!$stmt->prepare('SELECT trend, targetport, FORMAT(trend, 2) FROM test WHERE current_targets > 0 AND trend IS NOT NULL ORDER BY trend DESC LIMIT 100')) { printf("[308] [%d] %s\n", mysqli_stmt_errno($link), mysqli_stmt_error($link)); break; } if (!$stmt->execute()) { printf("[309] [%d] %s\n", mysqli_stmt_errno($link), mysqli_stmt_error($link)); break; } if (!$stmt->store_result()) { printf("[310] [%d] %s\n", mysqli_stmt_errno($link), mysqli_stmt_error($link)); break; } $trend = $targetport = $format = null; if (!$stmt->bind_result($trend, $targetport, $format)) { printf("[311] [%d] %s\n", mysqli_stmt_errno($link), mysqli_stmt_error($link)); break; } reset($values); while ($stmt->fetch()) { list($exp_trend, $exp_targetport) = each($values); if ($targetport != $exp_targetport) { printf("[312] Values fetched from MySQL seem to be wrong, check manually\n"); printf("%s/%s - %s/%s - '%s'\n", $trend, $exp_trend, $targetport, $exp_targetport, $format); } } $stmt->free_result(); $stmt->close(); } while (false); } else { var_dump(mysqli_error($link)); } mysqli_close($link); print "done!"; ?> --CLEAN-- --EXPECTF-- done!