~ubuntu-branches/ubuntu/quantal/php5/quantal

« back to all changes in this revision

Viewing changes to ext/mysqli/tests/mysqli_next_result.phpt

  • Committer: Bazaar Package Importer
  • Author(s): Sean Finney
  • Date: 2009-07-01 09:12:10 UTC
  • mto: (0.9.1) (1.1.17 upstream)
  • mto: This revision was merged to the branch mainline in revision 58.
  • Revision ID: james.westby@ubuntu.com-20090701091210-go0h6506p62on17r
Tags: upstream-5.3.0
ImportĀ upstreamĀ versionĀ 5.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--TEST--
 
2
mysqli_next_result()
 
3
--SKIPIF--
 
4
<?php 
 
5
require_once('skipif.inc');
 
6
require_once('skipifemb.inc'); 
 
7
require_once('skipifconnectfailure.inc');
 
8
?>
 
9
--FILE--
 
10
<?php
 
11
        include "connect.inc";
 
12
 
 
13
        $strict_on = false;
 
14
        if (defined('E_STRICT')) {
 
15
                error_reporting(((int)ini_get('error_reporting')) | E_STRICT );
 
16
                $strict_on = true;
 
17
        }
 
18
 
 
19
        $tmp    = NULL;
 
20
        $link   = NULL;
 
21
 
 
22
        if (!is_null($tmp = @mysqli_next_result()))
 
23
                printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
 
24
 
 
25
        if (!is_null($tmp = @mysqli_next_result($link)))
 
26
                printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
 
27
 
 
28
        require('table.inc');
 
29
 
 
30
        if ($strict_on)
 
31
                ob_start();
 
32
 
 
33
        if (false !== ($tmp = mysqli_next_result($link)))
 
34
                printf("[003] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
 
35
 
 
36
        if ($strict_on) {
 
37
                $tmp = ob_get_contents();
 
38
                ob_end_clean();
 
39
                if (!preg_match('@Strict Standards: mysqli_next_result\(\): There is no next result set@ismU', $tmp)) {
 
40
                        printf("[003a] Strict Standards warning missing\n");
 
41
                } else {
 
42
                        $tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\(\).*on line \d+@ism', '', $tmp));
 
43
                }
 
44
                print trim($tmp) . "\n";
 
45
                ob_start();
 
46
        }
 
47
 
 
48
        $res = mysqli_query($link, "SELECT 1 AS res");
 
49
        if (false !== ($tmp = mysqli_next_result($link)))
 
50
                printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
 
51
 
 
52
        if ($strict_on) {
 
53
                $tmp = ob_get_contents();
 
54
                ob_end_clean();
 
55
                if (!preg_match('@Strict Standards: mysqli_next_result\(\): There is no next result set@ismU', $tmp)) {
 
56
                        printf("[004a] Strict Standards warning missing\n");
 
57
                } else {
 
58
                        $tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\(\).*on line \d+@ism', '', $tmp));
 
59
                }
 
60
                print trim($tmp) . "\n";
 
61
        }
 
62
 
 
63
        mysqli_free_result($res);
 
64
 
 
65
        function func_test_mysqli_next_result($link, $query, $offset, $num_results, $strict_on) {
 
66
 
 
67
                if (!mysqli_multi_query($link, $query))
 
68
                        printf("[%03d] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
 
69
 
 
70
                $i = 0;
 
71
                if ($strict_on)
 
72
                        ob_start();
 
73
 
 
74
                do {
 
75
                        if ($res = mysqli_store_result($link)) {
 
76
                                mysqli_free_result($res);
 
77
                                $i++;
 
78
                        }
 
79
                } while (true === mysqli_next_result($link));
 
80
 
 
81
                if ($strict_on) {
 
82
                        $tmp = ob_get_contents();
 
83
                        ob_end_clean();
 
84
                        if (!preg_match('@Strict Standards: mysqli_next_result\(\): There is no next result set@ismU', $tmp)) {
 
85
                                printf("[%03d] Strict Standards warning missing\n", $offset + 1);
 
86
                        } else {
 
87
                                $tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\(\).*on line \d+@ism', '', $tmp));
 
88
                        }
 
89
                        print trim($tmp) . "\n";
 
90
                }
 
91
 
 
92
                if ($i !== $num_results) {
 
93
                        printf("[%03d] Expecting %d result(s), got %d result(s)\n", $offset + 2, $num_results, $i);
 
94
                }
 
95
 
 
96
                if (mysqli_more_results($link))
 
97
                        printf("[%03d] mysqli_more_results() indicates more results than expected\n", $offset + 3);
 
98
 
 
99
                if (!($res = mysqli_query($link, "SELECT 1 AS b"))) {
 
100
                        printf("[%03d] [%d] %s\n", $offset + 4, mysqli_errno($link), mysqli_error($link));
 
101
                } else {
 
102
                        mysqli_free_result($res);
 
103
                }
 
104
 
 
105
        }
 
106
 
 
107
        func_test_mysqli_next_result($link, "SELECT 1 AS a; SELECT 1 AS a, 2 AS b; SELECT id FROM test ORDER BY id LIMIT 3", 5, 3, $strict_on);
 
108
        func_test_mysqli_next_result($link, "SELECT 1 AS a; INSERT INTO test(id, label) VALUES (100, 'y'); SELECT 1 AS a, 2 AS b", 8, 2, $strict_on);
 
109
        func_test_mysqli_next_result($link, "DELETE FROM test WHERE id >= 100; SELECT 1 AS a; ", 11, 1, $strict_on);
 
110
 
 
111
        mysqli_close($link);
 
112
 
 
113
        var_dump(mysqli_next_result($link));
 
114
 
 
115
        print "done!";
 
116
?>
 
117
--EXPECTF--
 
118
Warning: mysqli_next_result(): Couldn't fetch mysqli in %s on line %d
 
119
NULL
 
120
done!
 
 
b'\\ No newline at end of file'