--TEST--
MySQL PDOStatement->execute()/fetch(), Non-SELECT
--SKIPIF--
<?php
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR 'skipif.inc');
require_once(
dirname(__FILE__) . DIRECTORY_SEPARATOR 'mysql_pdo_test.inc');
MySQLPDOTest::skip();
?>
--FILE--
<?php
    
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR 'mysql_pdo_test.inc');
    
$db MySQLPDOTest::factory();
    
MySQLPDOTest::createTestTable($db);

    try {

        
// Emulated PS first
        
$db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY1);
        if (
!= $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
            
printf("[002] Unable to turn on emulated prepared statements\n");

        if (!
is_object($stmt $db->query('DESCRIBE test id')))
            
printf("[003] Emulated PS, DESCRIBE failed, %s\n"var_export($db->errorInfo(), true));

        
$describe = array();
        
$valid false;
        while (
$row $stmt->fetch(PDO::FETCH_ASSOC)) {
            
$describe[] = $row;
            foreach (
$row as $column => $value)
            if (isset(
$row['field']) && ($row['field'] == 'id'))
                
$valid true;
        }
        if (empty(
$describe))
            
printf("[004] Emulated PS, DESCRIBE returned no results\n");
        else if (!
$valid)
            
printf("[005] Emulated PS, DESCRIBE, returned data seems wrong, dumping %s\n",
                
var_export($describetrue));

        if (!
is_object($stmt $db->query('SHOW ENGINES')))
            
printf("[006] Emulated PS, SHOW failed, %s\n"var_export($db->errorInfo(), true));

        
$show = array();
        
$valid false;
        while (
$row $stmt->fetch(PDO::FETCH_ASSOC)) {
            
$show[] = $row;
            foreach (
$row as $column => $value)
                
// MyISAM engine should be part of _every_ MySQL today
                
if ($value == 'MyISAM')
                    
$valid true;
        }
        if (empty(
$show))
            
printf("[007] Emulated PS, SHOW returned no results\n");
        else if (!
$valid)
            
printf("[008] Emulated PS, SHOW data seems wrong, dumping %s\n",
                
var_export($showtrue));

        if (!
is_object($stmt $db->query("EXPLAIN SELECT id FROM test")))
            
printf("[009] Emulated PS, EXPLAIN returned no results\n");

        
$explain = array();
        while (
$row $stmt->fetch(PDO::FETCH_ASSOC))
            
$explain[] = $row;

        if (empty(
$explain))
            
printf("[010] Emulated PS, EXPLAIN returned no results\n");

        
// And now native PS
        
$db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY0);
        if (
!= $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
            
printf("[011] Unable to turn off emulated prepared statements\n");

        
$native_support 'no';
        if (
$db->exec("PREPARE mystmt FROM 'DESCRIBE test id'")) {
            
$native_support 'yes';
            
$db->exec('DEALLOCATE PREPARE mystmt');
        }

        if (!
is_object($stmt $db->query('DESCRIBE test id')))
            
printf("[012] Native PS (native support: %s), DESCRIBE failed, %s\n",
                
$native_support,
                
var_export($db->errorInfo(), true));

        
$describe_native = array();
        
$valid false;
        while (
$row $stmt->fetch(PDO::FETCH_ASSOC)) {
            
$describe_native[] = $row;
            foreach (
$row as $column => $value)
            if (isset(
$row['field']) && ($row['field'] == 'id'))
                
$valid true;
        }
        if (empty(
$describe_native))
            
printf("[013] Native PS (native support: %s), DESCRIBE returned no results\n",
                
$native_support);
        else if (!
$valid)
            
printf("[014] Native PS (native support: %s), DESCRIBE, returned data seems wrong, dumping %s\n",
                
$native_support,
                
var_export($describe_nativetrue));

        if (
$describe != $describe_native)
            
printf("[015] Emulated and native PS (native support: %s) results of DESCRIBE differ: %s vs. %s\n",
                
$native_support,
                
var_export($describetrue),
                
var_export($describe_nativetrue));


        
$native_support 'no';
        if (
$db->exec("PREPARE mystmt FROM 'SHOW ENGINES'")) {
            
$native_support 'yes';
            
$db->exec('DEALLOCATE PREPARE mystmt');
        }

        if (!
is_object($stmt $db->query('SHOW ENGINES')))
            
printf("[016] Native PS (native support: %s), SHOW failed, %s\n",
                
$native_support,
                
var_export($db->errorInfo(), true));

        
$show_native = array();
        
$valid false;
        while (
$row $stmt->fetch(PDO::FETCH_ASSOC)) {
            
$show_native[] = $row;
            foreach (
$row as $column => $value)
                
// MyISAM engine should be part of _every_ MySQL today
                
if ($value == 'MyISAM')
                    
$valid true;
        }
        if (empty(
$show_native))
            
printf("[017] Native PS (native support: %s), SHOW returned no results\n",
                
$native_support);
        else if (!
$valid)
            
printf("[018] Native PS (native support: %s), SHOW data seems wrong, dumping %s\n",
                
var_export($show_nativetrue));

        if (
$show != $show_native)
            
printf("Native PS (native support: %s) and emulated PS returned different data for SHOW: %s vs. %s\n",
                
$native_support,
                
var_export($showtrue),
                
var_export($show_nativetrue));

        
$native_support 'no';
        if (
$db->exec("PREPARE mystmt FROM 'EXPLAIN SELECT id FROM test'")) {
            
$native_support 'yes';
            
$db->exec('DEALLOCATE PREPARE mystmt');
        }

        if (!
is_object($stmt $db->query("EXPLAIN SELECT id FROM test")))
            
printf("[012] Native PS (native support: %s), EXPLAIN failed, %s\n",
                
$native_support,
                
var_export($db->errorInfo(), true));

        
$explain_native = array();
        while (
$row $stmt->fetch(PDO::FETCH_ASSOC))
            
$explain_native[] = $row;

        if (empty(
$explain_native))
            
printf("[013] Native PS (native support: %s), EXPLAIN returned no results\n",
                
$native_support);

        if (
$explain != $explain_native)
            
printf("Native PS (native support: %s) and emulated PS returned different data for EXPLAIN: %s vs. %s\n",
                
$native_support,
                
var_export($explaintrue),
                
var_export($explain_nativetrue));

        
$stmt->execute();
        
$explain_native $stmt->fetchAll(PDO::FETCH_ASSOC);
        if (
$explain != $explain_native)
            
printf("Native PS (native support: %s) and emulated PS returned different data for EXPLAIN: %s vs. %s\n",
                
$native_support,
                
var_export($explaintrue),
                
var_export($explain_nativetrue));

        
$stmt->execute();
        
$stmt->execute();
        
// libmysql needs this - otherwise we get a 2015 error
        
if (!MYSQLPDOTest::isPDOMySQLnd())
            
$stmt->fetchAll(PDO::FETCH_ASSOC);

    } catch (
PDOException $e) {
        
printf("[001] %s [%s] %s\n",
            
$e->getMessage(), $db->errorCode(), implode(' '$db->errorInfo()));
    }

    print 
"done!\n";
?>
--CLEAN--
<?php
require dirname(__FILE__) . '/mysql_pdo_test.inc';
MySQLPDOTest::dropTestTable();
?>
--EXPECTF--
done!