Annotation of embedaddon/php/ext/pdo_mysql/tests/pdo_mysql_stmt_fetch_non_select.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: MySQL PDOStatement->execute()/fetch(), Non-SELECT
                      3: --SKIPIF--
                      4: <?php
                      5: require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
                      6: require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
                      7: MySQLPDOTest::skip();
                      8: ?>
                      9: --FILE--
                     10: <?php
                     11:        require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
                     12:        $db = MySQLPDOTest::factory();
                     13:        MySQLPDOTest::createTestTable($db);
                     14: 
                     15:        try {
                     16: 
                     17:                // Emulated PS first
                     18:                $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 1);
                     19:                if (1 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
                     20:                        printf("[002] Unable to turn on emulated prepared statements\n");
                     21: 
                     22:                if (!is_object($stmt = $db->query('DESCRIBE test id')))
                     23:                        printf("[003] Emulated PS, DESCRIBE failed, %s\n", var_export($db->errorInfo(), true));
                     24: 
                     25:                $describe = array();
                     26:                $valid = false;
                     27:                while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                     28:                        $describe[] = $row;
                     29:                        foreach ($row as $column => $value)
                     30:                        if (isset($row['field']) && ($row['field'] == 'id'))
                     31:                                $valid = true;
                     32:                }
                     33:                if (empty($describe))
                     34:                        printf("[004] Emulated PS, DESCRIBE returned no results\n");
                     35:                else if (!$valid)
                     36:                        printf("[005] Emulated PS, DESCRIBE, returned data seems wrong, dumping %s\n",
                     37:                                var_export($describe, true));
                     38: 
                     39:                if (!is_object($stmt = $db->query('SHOW ENGINES')))
                     40:                        printf("[006] Emulated PS, SHOW failed, %s\n", var_export($db->errorInfo(), true));
                     41: 
                     42:                $show = array();
                     43:                $valid = false;
                     44:                while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                     45:                        $show[] = $row;
                     46:                        foreach ($row as $column => $value)
                     47:                                // MyISAM engine should be part of _every_ MySQL today
                     48:                                if ($value == 'MyISAM')
                     49:                                        $valid = true;
                     50:                }
                     51:                if (empty($show))
                     52:                        printf("[007] Emulated PS, SHOW returned no results\n");
                     53:                else if (!$valid)
                     54:                        printf("[008] Emulated PS, SHOW data seems wrong, dumping %s\n",
                     55:                                var_export($show, true));
                     56: 
                     57:                if (!is_object($stmt = $db->query("EXPLAIN SELECT id FROM test")))
                     58:                        printf("[009] Emulated PS, EXPLAIN returned no results\n");
                     59: 
                     60:                $explain = array();
                     61:                while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
                     62:                        $explain[] = $row;
                     63: 
                     64:                if (empty($explain))
                     65:                        printf("[010] Emulated PS, EXPLAIN returned no results\n");
                     66: 
                     67:                // And now native PS
                     68:                $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 0);
                     69:                if (0 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
                     70:                        printf("[011] Unable to turn off emulated prepared statements\n");
                     71: 
                     72:                $native_support = 'no';
                     73:                if ($db->exec("PREPARE mystmt FROM 'DESCRIBE test id'")) {
                     74:                        $native_support = 'yes';
                     75:                        $db->exec('DEALLOCATE PREPARE mystmt');
                     76:                }
                     77: 
                     78:                if (!is_object($stmt = $db->query('DESCRIBE test id')))
                     79:                        printf("[012] Native PS (native support: %s), DESCRIBE failed, %s\n",
                     80:                                $native_support,
                     81:                                var_export($db->errorInfo(), true));
                     82: 
                     83:                $describe_native = array();
                     84:                $valid = false;
                     85:                while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                     86:                        $describe_native[] = $row;
                     87:                        foreach ($row as $column => $value)
                     88:                        if (isset($row['field']) && ($row['field'] == 'id'))
                     89:                                $valid = true;
                     90:                }
                     91:                if (empty($describe_native))
                     92:                        printf("[013] Native PS (native support: %s), DESCRIBE returned no results\n",
                     93:                                $native_support);
                     94:                else if (!$valid)
                     95:                        printf("[014] Native PS (native support: %s), DESCRIBE, returned data seems wrong, dumping %s\n",
                     96:                                $native_support,
                     97:                                var_export($describe_native, true));
                     98: 
                     99:                if ($describe != $describe_native)
                    100:                        printf("[015] Emulated and native PS (native support: %s) results of DESCRIBE differ: %s vs. %s\n",
                    101:                                $native_support,
                    102:                                var_export($describe, true),
                    103:                                var_export($describe_native, true));
                    104: 
                    105: 
                    106:                $native_support = 'no';
                    107:                if ($db->exec("PREPARE mystmt FROM 'SHOW ENGINES'")) {
                    108:                        $native_support = 'yes';
                    109:                        $db->exec('DEALLOCATE PREPARE mystmt');
                    110:                }
                    111: 
                    112:                if (!is_object($stmt = $db->query('SHOW ENGINES')))
                    113:                        printf("[016] Native PS (native support: %s), SHOW failed, %s\n",
                    114:                                $native_support,
                    115:                                var_export($db->errorInfo(), true));
                    116: 
                    117:                $show_native = array();
                    118:                $valid = false;
                    119:                while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                    120:                        $show_native[] = $row;
                    121:                        foreach ($row as $column => $value)
                    122:                                // MyISAM engine should be part of _every_ MySQL today
                    123:                                if ($value == 'MyISAM')
                    124:                                        $valid = true;
                    125:                }
                    126:                if (empty($show_native))
                    127:                        printf("[017] Native PS (native support: %s), SHOW returned no results\n",
                    128:                                $native_support);
                    129:                else if (!$valid)
                    130:                        printf("[018] Native PS (native support: %s), SHOW data seems wrong, dumping %s\n",
                    131:                                var_export($show_native, true));
                    132: 
                    133:                if ($show != $show_native)
                    134:                        printf("Native PS (native support: %s) and emulated PS returned different data for SHOW: %s vs. %s\n",
                    135:                                $native_support,
                    136:                                var_export($show, true),
                    137:                                var_export($show_native, true));
                    138: 
                    139:                $native_support = 'no';
                    140:                if ($db->exec("PREPARE mystmt FROM 'EXPLAIN SELECT id FROM test'")) {
                    141:                        $native_support = 'yes';
                    142:                        $db->exec('DEALLOCATE PREPARE mystmt');
                    143:                }
                    144: 
                    145:                if (!is_object($stmt = $db->query("EXPLAIN SELECT id FROM test")))
                    146:                        printf("[012] Native PS (native support: %s), EXPLAIN failed, %s\n",
                    147:                                $native_support,
                    148:                                var_export($db->errorInfo(), true));
                    149: 
                    150:                $explain_native = array();
                    151:                while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
                    152:                        $explain_native[] = $row;
                    153: 
                    154:                if (empty($explain_native))
                    155:                        printf("[013] Native PS (native support: %s), EXPLAIN returned no results\n",
                    156:                                $native_support);
                    157: 
                    158:                if ($explain != $explain_native)
                    159:                        printf("Native PS (native support: %s) and emulated PS returned different data for EXPLAIN: %s vs. %s\n",
                    160:                                $native_support,
                    161:                                var_export($explain, true),
                    162:                                var_export($explain_native, true));
                    163: 
                    164:                $stmt->execute();
                    165:                $explain_native = $stmt->fetchAll(PDO::FETCH_ASSOC);
                    166:                if ($explain != $explain_native)
                    167:                        printf("Native PS (native support: %s) and emulated PS returned different data for EXPLAIN: %s vs. %s\n",
                    168:                                $native_support,
                    169:                                var_export($explain, true),
                    170:                                var_export($explain_native, true));
                    171: 
                    172:                $stmt->execute();
                    173:                $stmt->execute();
                    174:                // libmysql needs this - otherwise we get a 2015 error
                    175:                if (!MYSQLPDOTest::isPDOMySQLnd())
                    176:                        $stmt->fetchAll(PDO::FETCH_ASSOC);
                    177: 
                    178:        } catch (PDOException $e) {
                    179:                printf("[001] %s [%s] %s\n",
                    180:                        $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
                    181:        }
                    182: 
                    183:        print "done!\n";
                    184: ?>
                    185: --CLEAN--
                    186: <?php
                    187: require dirname(__FILE__) . '/mysql_pdo_test.inc';
                    188: MySQLPDOTest::dropTestTable();
                    189: ?>
                    190: --EXPECTF--
                    191: done!

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