From: Ulf Wendel Date: Thu, 12 Jul 2007 20:20:57 +0000 (+0000) Subject: Adding tests for mysqli_affected_rows() and mysqli_autocommit() X-Git-Tag: BEFORE_IMPORT_OF_MYSQLND~159 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ed4021d8571d6ca25d22ed6db6d9ef15d5c72b13;p=php Adding tests for mysqli_affected_rows() and mysqli_autocommit() --- diff --git a/ext/mysqli/tests/mysqli_affected_rows.phpt b/ext/mysqli/tests/mysqli_affected_rows.phpt new file mode 100644 index 0000000000..a3d2a5c0ed --- /dev/null +++ b/ext/mysqli/tests/mysqli_affected_rows.phpt @@ -0,0 +1,128 @@ +--TEST-- +mysqli_affected_rows() +--SKIPIF-- + + +--FILE-- + $charset) { + if (!($res = mysqli_query($link, sprintf('SHOW CHARACTER SET LIKE "%s"', $charset)))) + continue; + mysqli_free_result($res); + if (true !== ($tmp = mysqli_set_charset($link, $charset))) + printf("[026] Expecting boolean/true got %s/%s\n", + gettype($tmp), $tmp); + if (0 !== ($tmp = mysqli_affected_rows($link))) + printf("[027] Expecting int/0 got %s/%s\n", gettype($tmp), $tmp); + } + + if (!mysqli_query($link, "UPDATE test SET label = 'a' WHERE id = 2")) { + printf("[028] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } + + if (0 !== ($tmp = mysqli_affected_rows($link))) + printf("[029] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp); + + if (!mysqli_query($link, "UPDATE test SET label = 'a' WHERE id = 100")) { + printf("[030] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } + + if (0 !== ($tmp = mysqli_affected_rows($link))) + printf("[031] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp); + + if (!mysqli_query($link, 'DROP TABLE IF EXISTS test')) + printf("[032] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + + mysqli_close($link); + + if (NULL !== ($tmp = @mysqli_affected_rows($link))) + printf("[033] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + print "done!"; +?> +--EXPECTF-- +done! \ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_affected_rows_oo.phpt b/ext/mysqli/tests/mysqli_affected_rows_oo.phpt new file mode 100644 index 0000000000..bb010a3af4 --- /dev/null +++ b/ext/mysqli/tests/mysqli_affected_rows_oo.phpt @@ -0,0 +1,103 @@ +--TEST-- +mysqli->affected_rows +--SKIPIF-- + + +--FILE-- +affected_rows)) + printf("[002] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp); + + if (!$mysqli->query('DROP TABLE IF EXISTS test')) + printf("[003] [%d] %s\n", $mysqli->errno, $mysqli->error); + + if (!$mysqli->query('CREATE TABLE test(id INT, label CHAR(1), PRIMARY KEY(id)) ENGINE = ' . $engine)) + printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error); + + if (!$mysqli->query('INSERT INTO test(id, label) VALUES (1, "a")')) + printf("[005] [%d] %s\n", $mysqli->errno, $mysqli->error); + + if (1 !== ($tmp = $mysqli->affected_rows)) + printf("[006] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp); + + // ignore INSERT error, NOTE: command line returns 0, affected_rows returns -1 as documented + $mysqli->query('INSERT INTO test(id, label) VALUES (1, "a")'); + if (-1 !== ($tmp = $mysqli->affected_rows)) + printf("[007] Expecting int/-1, got %s/%s\n", gettype($tmp), $tmp); + + if (!$mysqli->query('INSERT INTO test(id, label) VALUES (1, "a") ON DUPLICATE KEY UPDATE id = 4')) + printf("[008] [%d] %s\n", $mysqli->errno, $mysqli->error); + + if (2 !== ($tmp = $mysqli->affected_rows)) + printf("[009] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp); + + if (!$mysqli->query("INSERT INTO test(id, label) VALUES (2, 'b'), (3, 'c')")) + printf("[010] [%d] %s\n", $mysqli->errno, $mysqli->error); + + if (2 !== ($tmp = $mysqli->affected_rows)) + printf("[011] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp); + + if (!$mysqli->query("INSERT IGNORE INTO test(id, label) VALUES (1, 'a')")) { + printf("[012] [%d] %s\n", $mysqli->errno, $mysqli->error); + } + + if (1 !== ($tmp = $mysqli->affected_rows)) + printf("[013] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp); + + if (!$mysqli->query("INSERT INTO test(id, label) SELECT id + 10, label FROM test")) + printf("[014] [%d] %s\n", $mysqli->errno, $mysqli->error); + + if (4 !== ($tmp = $mysqli->affected_rows)) + printf("[015] Expecting int/4, got %s/%s\n", gettype($tmp), $tmp); + + if (!$mysqli->query("REPLACE INTO test(id, label) values (4, 'd')")) + printf("[015] [%d] %s\n", $mysqli->errno, $mysqli->error); + + if (2 !== ($tmp = $mysqli->affected_rows)) + printf("[016] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp); + + if (!$mysqli->query("REPLACE INTO test(id, label) values (5, 'e')")) + printf("[017] [%d] %s\n", $mysqli->errno, $mysqli->error); + + if (1 !== ($tmp = $mysqli->affected_rows)) + printf("[018] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp); + + if (!$mysqli->query("UPDATE test SET label = 'a' WHERE id = 2")) + printf("[019] [%d] %s\n", $mysqli->errno, $mysqli->error); + + if (1 !== ($tmp = $mysqli->affected_rows)) + printf("[020] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp); + + if (!$mysqli->query("UPDATE test SET label = 'a' WHERE id = 2")) { + printf("[021] [%d] %s\n", $mysqli->errno, $mysqli->error); + } + + if (0 !== ($tmp = $mysqli->affected_rows)) + printf("[022] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp); + + if (!$mysqli->query("UPDATE test SET label = 'a' WHERE id = 100")) { + printf("[023] [%d] %s\n", $mysqli->errno, $mysqli->error); + } + + if (0 !== ($tmp = $mysqli->affected_rows)) + printf("[024] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp); + + if (!$mysqli->query('DROP TABLE IF EXISTS test')) + printf("[025] [%d] %s\n", $mysqli->errno, $mysqli->error); + + $mysqli->close(); + + if (NULL !== ($tmp = @$mysqli->affected_rows)) + printf("[026] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + print "done!"; +?> +--EXPECTF-- +done! \ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_autocommit.phpt b/ext/mysqli/tests/mysqli_autocommit.phpt new file mode 100644 index 0000000000..2671a434a4 --- /dev/null +++ b/ext/mysqli/tests/mysqli_autocommit.phpt @@ -0,0 +1,152 @@ +--TEST-- +mysqli_autocommit() +--SKIPIF-- + + + +--FILE-- + +--EXPECTF-- +done! \ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_autocommit_oo.phpt b/ext/mysqli/tests/mysqli_autocommit_oo.phpt new file mode 100644 index 0000000000..42959e80ec --- /dev/null +++ b/ext/mysqli/tests/mysqli_autocommit_oo.phpt @@ -0,0 +1,141 @@ +--TEST-- +mysqli->autocommit() +--SKIPIF-- + + +query("SHOW VARIABLES LIKE 'have_innodb'")) { + printf("skip Cannot fetch have_innodb variable\n"); + exit(1); + } + + $row = $res->fetch_row(); + $res->free_result(); + $mysqli->close(); + + if ($row[1] == "DISABLED" || $row[1] == "NO") { + printf ("skip Innodb support is not installed or enabled."); + exit(1); + } +?> +--FILE-- +autocommit(true))) + printf("[002] Expecting boolean/any, got %s/%s\n", gettype($tmp), $tmp); + + if (!$mysqli->query('SET AUTOCOMMIT = 0')) + printf("[003] [%d] %s\n", $mysqli->errno, $mysqli->error); + + if (!$res = $mysqli->query('SELECT @@autocommit as auto_commit')) + printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error); + + $tmp = $res->fetch_assoc(); + $res->free_result(); + if ($tmp['auto_commit']) + printf("[005] Cannot turn off autocommit\n"); + + if (true !== ($tmp = $mysqli->autocommit( true))) + printf("[006] Expecting true, got %s/%s\n", gettype($tmp), $tmp); + + if (!$res = $mysqli->query('SELECT @@autocommit as auto_commit')) + printf("[007] [%d] %s\n", $mysqli->errno, $mysqli->error); + $tmp = $res->fetch_assoc(); + $res->free_result(); + if (!$tmp['auto_commit']) + printf("[008] Cannot turn on autocommit\n"); + + if (!$mysqli->query('DROP TABLE IF EXISTS test')) + printf("[009] [%d] %s\n", $mysqli->errno, $mysqli->error); + + if (!$mysqli->query('CREATE TABLE test(id INT) ENGINE = InnoDB')) { + printf("[010] Cannot create test table, [%d] %s\n", $mysqli->errno, $mysqli->error); + } + + if (!$mysqli->query('INSERT INTO test(id) VALUES (1)')) + printf("[011] [%d] %s\n", $mysqli->errno, $mysqli->error); + + if (!$mysqli->query('ROLLBACK')) + printf("[012] [%d] %s\n", $mysqli->errno, $mysqli->error); + + if (!$res = $mysqli->query('SELECT COUNT(*) AS num FROM test')) + printf("[013] [%d] %s\n", $mysqli->errno, $mysqli->error); + + if ((!$tmp = $res->fetch_assoc()) || (1 != $tmp['num'])) + printf("[014] Expecting 1 row in table test, found %d rows. [%d] %s\n", + $tmp['num'], $mysqli->errno, $mysqli->error); + + $res->free_result(); + + if (!$mysqli->query('DROP TABLE IF EXISTS test')) + printf("[015] [%d] %s\n", $mysqli->errno, $mysqli->error); + + if (!$mysqli->query('SET AUTOCOMMIT = 1')) + printf("[016] [%d] %s\n", $mysqli->errno, $mysqli->error); + + if (!$res = $mysqli->query('SELECT @@autocommit as auto_commit')) + printf("[017] [%d] %s\n", $mysqli->errno, $mysqli->error); + + $tmp = $res->fetch_assoc(); + $res->free_result(); + if (!$tmp['auto_commit']) + printf("[018] Cannot turn on autocommit\n"); + + if (true !== ($tmp = $mysqli->autocommit( false))) + printf("[019] Expecting true, got %s/%s\n", gettype($tmp), $tmp); + + if (!$mysqli->query('CREATE TABLE test(id INT) ENGINE = InnoDB')) { + printf("[020] Cannot create test table, [%d] %s\n", $mysqli->errno, $mysqli->error); + } + + if (!$mysqli->query('INSERT INTO test(id) VALUES (1)')) + printf("[021] [%d] %s\n", $mysqli->errno, $mysqli->error); + + if (!$mysqli->query('ROLLBACK')) + printf("[022] [%d] %s\n", $mysqli->errno, $mysqli->error); + + if (!$res = $mysqli->query('SELECT COUNT(*) AS num FROM test')) + printf("[023] [%d] %s\n", $mysqli->errno, $mysqli->error); + $tmp = $res->fetch_assoc(); + if (0 != $tmp['num']) + printf("[24] Expecting 0 rows in table test, found %d rows\n", $tmp['num']); + $res->free_result(); + + if (!$mysqli->query('INSERT INTO test(id) VALUES (1)')) + printf("[025] [%d] %s\n", $mysqli->errno, $mysqli->error); + + if (!$mysqli->query('COMMIT')) + printf("[025] [%d] %s\n", $mysqli->errno, $mysqli->error); + + if (!$res = $mysqli->query('SELECT COUNT(*) AS num FROM test')) + printf("[027] [%d] %s\n", $mysqli->errno, $mysqli->error); + + if ((!$tmp = $res->fetch_assoc()) || (1 != $tmp['num'])) + printf("[028] Expecting 1 row in table test, found %d rows. [%d] %s\n", + $tmp['num'], $mysqli->errno, $mysqli->error); + $res->free_result(); + + if (!$mysqli->query('DROP TABLE IF EXISTS test')) + printf("[029] [%d] %s\n", $mysqli->errno, $mysqli->error); + + $mysqli->close(); + + if (NULL !== ($tmp = @$mysqli->autocommit( false))) + printf("[030] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + print "done!\n"; +?> +--EXPECTF-- +done! \ No newline at end of file