Annotation of embedaddon/php/ext/mysql/tests/mysql_unbuffered_query.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: mysql_unbuffered_query()
                      3: --SKIPIF--
                      4: <?php
                      5: require_once('skipif.inc');
                      6: require_once('skipifconnectfailure.inc');
                      7: ?>
                      8: --FILE--
                      9: <?php
                     10: include_once("connect.inc");
                     11: 
                     12: $tmp    = NULL;
                     13: $link   = NULL;
                     14: 
                     15: if (false !== ($tmp = @mysql_unbuffered_query($link)))
                     16:        printf("[001] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
                     17: 
                     18: require('table.inc');
                     19: 
                     20: if (NULL !== ($tmp = @mysql_unbuffered_query("SELECT 1 AS a", $link, "foo")))
                     21:        printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
                     22: 
                     23: if (false !== ($tmp = mysql_unbuffered_query('THIS IS NOT SQL', $link)))
                     24:        printf("[003] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
                     25: 
                     26: if (false !== ($tmp = mysql_unbuffered_query("SELECT 'this is sql but with backslash g'\g", $link)))
                     27:        printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
                     28: 
                     29: if ((0 === mysql_errno($link)) || ('' == mysql_error($link)))
                     30:        printf("[005] mysql_errno()/mysql_error should return some error\n");
                     31: 
                     32: if (!$res = mysql_unbuffered_query("SELECT 'this is sql but with semicolon' AS valid ; ", $link))
                     33:        printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link));
                     34: 
                     35: var_dump(mysql_fetch_assoc($res));
                     36: mysql_free_result($res);
                     37: 
                     38: if (false !== ($res = mysql_unbuffered_query("SELECT 'this is sql but with semicolon' AS valid ; SHOW VARIABLES", $link)))
                     39:        printf("[007] [%d] %s\n", mysql_errno($link), mysql_error($link));
                     40: 
                     41: if (mysql_unbuffered_query('DROP PROCEDURE IF EXISTS p', $link)) {
                     42:        // let's try to play with stored procedures
                     43:        if (mysql_unbuffered_query('CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) BEGIN SELECT VERSION() INTO ver_param; END;', $link)) {
                     44:                $res = mysql_unbuffered_query('CALL p(@version)', $link);
                     45:                $res = mysql_unbuffered_query('SELECT @version AS p_version', $link);
                     46:                $tmp = mysql_fetch_assoc($res);
                     47:                if (!isset($tmp['p_version']) || ('' == $tmp['p_version'])) {
                     48:                        printf("[008] Result seems wrong, dumping\n");
                     49:                        var_dump($tmp);
                     50:                }
                     51:                if ((version_compare(PHP_VERSION, '5.9.9', '>') == 1) && !is_unicode($tmp['p_version'])) {
                     52:                        printf("[009] Expecting unicode string, dumping\n");
                     53:                        var_dump($tmp);
                     54:                }
                     55:                mysql_free_result($res);
                     56:        } else {
                     57:                printf("[010] [%d] %s\n", mysql_errno($link), mysql_error($link));
                     58:        }
                     59: 
                     60:        mysql_unbuffered_query('DROP FUNCTION IF EXISTS f', $link);
                     61:        if (mysql_unbuffered_query('CREATE FUNCTION f( ver_param VARCHAR(25)) RETURNS VARCHAR(25) DETERMINISTIC RETURN ver_param;', $link)) {
                     62:                $res = mysql_unbuffered_query('SELECT f(VERSION()) AS f_version', $link);
                     63:                $tmp = mysql_fetch_assoc($res);
                     64:                if (!isset($tmp['f_version']) || ('' == $tmp['f_version'])) {
                     65:                        printf("[011] Result seems wrong, dumping\n");
                     66:                        var_dump($tmp);
                     67:                }
                     68:                if ((version_compare(PHP_VERSION, '5.9.9', '>') == 1) && !is_unicode($tmp['f_version'])) {
                     69:                        printf("[012] Expecting unicode string, dumping\n");
                     70:                        var_dump($tmp);
                     71:                }
                     72:                mysql_free_result($res);
                     73:        } else {
                     74:                printf("[012] [%d] %s\n", mysql_errno($link), mysql_error($link));
                     75:        }
                     76: }
                     77: 
                     78: var_dump(mysql_unbuffered_query('INSERT INTO test(id) VALUES (100)', $link));
                     79: var_dump($res = mysql_unbuffered_query('SELECT id FROM test', $link));
                     80: var_dump(mysql_num_rows($res));
                     81: 
                     82: mysql_close($link);
                     83: 
                     84: if (false !== ($tmp = mysql_unbuffered_query("SELECT id FROM test", $link)))
                     85:        printf("[010] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
                     86: 
                     87: print "done!";
                     88: ?>
                     89: --CLEAN--
                     90: <?php
                     91: require_once('connect.inc');
                     92: 
                     93: // connect + select_db
                     94: if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket)) {
                     95:        printf("[clean] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
                     96:          $host, $myhost, $user, $db, $port, $socket);
                     97: }
                     98: 
                     99: if (!mysql_query('DROP TABLE IF EXISTS test', $link)) {
                    100:        printf("[clean] Failed to drop test table: [%d] %s\n", mysql_errno($link), mysql_error($link));
                    101: }
                    102: 
                    103: /* MySQL server may not support this - ignore errors */
                    104: @mysql_query('DROP PROCEDURE IF EXISTS p', $link);
                    105: @mysql_query('DROP FUNCTION IF EXISTS f', $link);
                    106: 
                    107: mysql_close($link);
                    108: ?>
                    109: --EXPECTF--
                    110: array(1) {
                    111:   [%u|b%"valid"]=>
                    112:   %unicode|string%(30) "this is sql but with semicolon"
                    113: }
                    114: bool(true)
                    115: resource(%d) of type (mysql result)
                    116: int(0)
                    117: 
                    118: Notice: mysql_close(): Function called without first fetching all rows from a previous unbuffered query in %s on line %d
                    119: 
                    120: Warning: mysql_unbuffered_query(): %d is not a valid MySQL-Link resource in %s on line %d
                    121: done!

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>