PHP  
 PHP_5_4
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

Test Failure Report for ext/pdo_odbc/tests/pdo_018.phpt ('ODBC PDO Common: serializing')

Script

1: <?php
2:
if (getenv('REDIR_TEST_DIR') === falseputenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
3: require_once 
getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
4:
$db PDOTest::factory();
5:
6: class 
TestBase implements Serializable
7:
{
8:     public    
$BasePub 'Public';
9:     protected 
$BasePro 'Protected';
10:     private   
$BasePri 'Private';
11:     
12:     function 
serialize()
13:     {
14:         
$serialized = array();
15:         foreach(
$this as $prop => $val) {
16:             
$serialized[$prop] = $val;
17:         }
18:         
$serialized serialize($serialized);
19:         echo 
__METHOD__ "() = '$serialized'\n";
20:         return 
$serialized;
21:     }
22:     
23:     function 
unserialize($serialized)
24:     {
25:         echo 
__METHOD__ "($serialized)\n";
26:         foreach(
unserialize($serialized) as $prop => $val) {
27:             
$this->$prop '#'.$val;
28:         }
29:         return 
true;
30:     }
31: }
32:
33: class 
TestDerived extends TestBase
34:
{
35:     public    
$BasePub    'DerivedPublic';
36:     protected 
$BasePro    'DerivdeProtected';
37:     public    
$DerivedPub 'Public';
38:     protected 
$DerivedPro 'Protected';
39:     private   
$DerivedPri 'Private';
40:
41:     function 
serialize()
42:     {
43:         echo 
__METHOD__ "()\n";
44:         return 
TestBase::serialize();
45:     }
46:     
47:     function 
unserialize($serialized)
48:     {
49:         echo 
__METHOD__ "()\n";
50:         return 
TestBase::unserialize($serialized);
51:     }
52: }
53:
54: class 
TestLeaf extends TestDerived
55:
{
56: }
57:
58:
$db->exec('CREATE TABLE classtypes(id int NOT NULL PRIMARY KEY, name VARCHAR(20) NOT NULL UNIQUE)');
59:
$db->exec('INSERT INTO classtypes VALUES(0, \'stdClass\')'); 
60:
$db->exec('INSERT INTO classtypes VALUES(1, \'TestBase\')'); 
61:
$db->exec('INSERT INTO classtypes VALUES(2, \'TestDerived\')'); 
62:
$db->exec('CREATE TABLE test(id int NOT NULL PRIMARY KEY, classtype int, val VARCHAR(255))');
63:
64:
$db->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
65:
66:
var_dump($db->query('SELECT COUNT(*) FROM classtypes')->fetchColumn());
67:
var_dump($db->query('SELECT id, name FROM classtypes ORDER by id')->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE));
68:
69:
$objs = array();
70:
$objs[0] = new stdClass;
71:
$objs[1] = new TestBase;
72:
$objs[2] = new TestDerived;
73:
$objs[3] = new TestLeaf;
74:
75:
$stmt $db->prepare('SELECT id FROM classtypes WHERE name=:cname');
76:
$stmt->bindParam(':cname'$cname);
77:
78:
$ctypes = array();
79:
80: foreach(
$objs as $obj)
81: {
82:     
$cname get_class($obj);
83:     
$ctype NULL/* set default for non stored class name */
84:     
$stmt->execute();
85:     
$stmt->bindColumn('id'$ctype);
86:     
$stmt->fetch(PDO::FETCH_BOUND);
87:     
$ctypes[$cname] = $ctype;
88: }
89:
90: echo 
"===TYPES===\n";
91:
var_dump($ctypes);
92:
93: unset(
$stmt);
94:
95: echo 
"===INSERT===\n";
96:
$stmt $db->prepare('INSERT INTO test VALUES(:id, :classtype, :val)');
97:
$stmt->bindParam(':id'$idx);
98:
$stmt->bindParam(':classtype'$ctype);
99:
$stmt->bindParam(':val'$val);
100:
101: foreach(
$objs as $idx => $obj)
102: {
103:     
$ctype $ctypes[get_class($obj)];
104:     if (
method_exists($obj'serialize'))
105:     {
106:         
$val $obj->serialize();
107:     }
108:     else
109:     {
110:         
$val '';
111:     }
112:     
$stmt->execute();    
113: }
114:
115: unset(
$stmt);
116:
117: echo 
"===DATA===\n";
118:
$res $db->query('SELECT test.val FROM test')->fetchAll(PDO::FETCH_COLUMN);
119:
120:
// For Oracle map NULL to empty string so the test doesn't diff
121:
if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'oci' && $res[0] === null) {
122:     
$res[0] = "";
123: }
124:
var_dump($res);
125:
126: echo 
"===FAILURE===\n";
127: try
128: {
129:     
$db->query('SELECT classtypes.name AS name, test.val AS val FROM test LEFT JOIN classtypes ON test.classtype=classtypes.id')->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_CLASSTYPE|PDO::FETCH_SERIALIZE'TestLeaf', array());
130: }
131: catch (
PDOException $e)
132: {
133:     echo 
'Exception:';
134:     echo 
$e->getMessage()."\n";
135: }
136:
137: echo 
"===COUNT===\n";
138:
var_dump($db->query('SELECT COUNT(*) FROM test LEFT JOIN classtypes ON test.classtype=classtypes.id WHERE (classtypes.id IS NULL OR classtypes.id > 0)')->fetchColumn());
139:
140: echo 
"===DATABASE===\n";
141:
$stmt $db->prepare('SELECT classtypes.name AS name, test.val AS val FROM test LEFT JOIN classtypes ON test.classtype=classtypes.id WHERE (classtypes.id IS NULL OR classtypes.id > 0)');
142:
143:
$stmt->execute();
144:
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
145:
146: echo 
"===FETCHCLASS===\n";
147:
$stmt->execute();
148:
var_dump($stmt->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_CLASSTYPE|PDO::FETCH_SERIALIZE'TestLeaf'));
149:
150:
151:
?>
152:

Expected

string(1) "3"
array(3) {
  [0]=>
  string(8) "stdClass"
  [1]=>
  string(8) "TestBase"
  [2]=>
  string(11) "TestDerived"
}
===TYPES===
array(4) {
  ["stdClass"]=>
  string(1) "0"
  ["TestBase"]=>
  string(1) "1"
  ["TestDerived"]=>
  string(1) "2"
  ["TestLeaf"]=>
  NULL
}
===INSERT===
TestBase::serialize() = 'a:3:{s:7:"BasePub";s:6:"Public";s:7:"BasePro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}'
TestDerived::serialize()
TestBase::serialize() = 'a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}'
TestDerived::serialize()
TestBase::serialize() = 'a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}'
===DATA===
array(4) {
  [0]=>
  string(0) ""
  [1]=>
  string(91) "a:3:{s:7:"BasePub";s:6:"Public";s:7:"BasePro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}"
  [2]=>
  string(172) "a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}"
  [3]=>
  string(172) "a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}"
}
===FAILURE===
Exception:SQLSTATE[HY000]: General error: cannot unserialize class
===COUNT===
string(1) "3"
===DATABASE===
array(3) {
  [0]=>
  array(2) {
    ["name"]=>
    string(8) "TestBase"
    ["val"]=>
    string(91) "a:3:{s:7:"BasePub";s:6:"Public";s:7:"BasePro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}"
  }
  [1]=>
  array(2) {
    ["name"]=>
    string(11) "TestDerived"
    ["val"]=>
    string(172) "a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}"
  }
  [2]=>
  array(2) {
    ["name"]=>
    NULL
    ["val"]=>
    string(172) "a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}"
  }
}
===FETCHCLASS===
TestBase::unserialize(a:3:{s:7:"BasePub";s:6:"Public";s:7:"BasePro";s:9:"Protected";s:7:"BasePri";s:7:"Private";})
TestDerived::unserialize()
TestBase::unserialize(a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";})
TestDerived::unserialize()
TestBase::unserialize(a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";})
array(3) {
  [0]=>
  object(TestBase)#%d (3) {
    ["BasePub"]=>
    string(7) "#Public"
    ["BasePro":protected]=>
    string(10) "#Protected"
    ["BasePri":"TestBase":private]=>
    string(8) "#Private"
  }
  [1]=>
  object(TestDerived)#%d (6) {
    ["BasePub"]=>
    string(14) "#DerivedPublic"
    ["BasePro":protected]=>
    string(17) "#DerivdeProtected"
    ["DerivedPub"]=>
    string(7) "#Public"
    ["DerivedPro":protected]=>
    string(10) "#Protected"
    ["DerivedPri":"TestDerived":private]=>
    string(7) "Private"
    ["BasePri":"TestBase":private]=>
    string(8) "#Private"
  }
  [2]=>
  object(TestLeaf)#%d (6) {
    ["BasePub"]=>
    string(14) "#DerivedPublic"
    ["BasePro":protected]=>
    string(17) "#DerivdeProtected"
    ["DerivedPub"]=>
    string(7) "#Public"
    ["DerivedPro":protected]=>
    string(10) "#Protected"
    ["DerivedPri":"TestDerived":private]=>
    string(7) "Private"
    ["BasePri":"TestBase":private]=>
    string(8) "#Private"
  }
}

Output

string(1) "3"
array(3) {
  [0]=>
  string(8) "stdClass"
  [1]=>
  string(8) "TestBase"
  [2]=>
  string(11) "TestDerived"
}

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 [MySQL][ODBC 5.1 Driver][mysqld-5.1.73]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 (SQLExecute[1064] at /var/php_gcov/PHP_5_4/ext/pdo_odbc/odbc_stmt.c:254)' in /var/php_gcov/PHP_5_4/ext/pdo_odbc/tests/pdo_018.php:84
Stack trace:
#0 /var/php_gcov/PHP_5_4/ext/pdo_odbc/tests/pdo_018.php(84): PDOStatement->execute()
#1 {main}
  thrown in /var/php_gcov/PHP_5_4/ext/pdo_odbc/tests/pdo_018.php on line 84

Diff

# original source file: ext/pdo/tests/pdo_018.phpt
010+ 
011+ Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 [MySQL][ODBC 5.1 Driver][mysqld-5.1.73]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 (SQLExecute[1064] at /var/php_gcov/PHP_5_4/ext/pdo_odbc/odbc_stmt.c:254)' in /var/php_gcov/PHP_5_4/ext/pdo_odbc/tests/pdo_018.php:84
012+ Stack trace:
013+ #0 /var/php_gcov/PHP_5_4/ext/pdo_odbc/tests/pdo_018.php(84): PDOStatement->execute()
014+ #1 {main}
015+   thrown in /var/php_gcov/PHP_5_4/ext/pdo_odbc/tests/pdo_018.php on line 84
010- ===TYPES===
011- array(4) {
012-   ["stdClass"]=>
013-   string(1) "0"
014-   ["TestBase"]=>
015-   string(1) "1"
016-   ["TestDerived"]=>
017-   string(1) "2"
018-   ["TestLeaf"]=>
019-   NULL
020- }
021- ===INSERT===
022- TestBase::serialize() = 'a:3:{s:7:"BasePub";s:6:"Public";s:7:"BasePro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}'
023- TestDerived::serialize()
024- TestBase::serialize() = 'a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}'
025- TestDerived::serialize()
026- TestBase::serialize() = 'a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}'
027- ===DATA===
028- array(4) {
029-   [0]=>
030-   string(0) ""
031-   [1]=>
032-   string(91) "a:3:{s:7:"BasePub";s:6:"Public";s:7:"BasePro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}"
033-   [2]=>
034-   string(172) "a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}"
035-   [3]=>
036-   string(172) "a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}"
037- }
038- ===FAILURE===
039- Exception:SQLSTATE[HY000]: General error: cannot unserialize class
040- ===COUNT===
041- string(1) "3"
042- ===DATABASE===
043- array(3) {
044-   [0]=>
045-   array(2) {
046-     ["name"]=>
047-     string(8) "TestBase"
048-     ["val"]=>
049-     string(91) "a:3:{s:7:"BasePub";s:6:"Public";s:7:"BasePro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}"
050-   }
051-   [1]=>
052-   array(2) {
053-     ["name"]=>
054-     string(11) "TestDerived"
055-     ["val"]=>
056-     string(172) "a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}"
057-   }
058-   [2]=>
059-   array(2) {
060-     ["name"]=>
061-     NULL
062-     ["val"]=>
063-     string(172) "a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";}"
064-   }
065- }
066- ===FETCHCLASS===
067- TestBase::unserialize(a:3:{s:7:"BasePub";s:6:"Public";s:7:"BasePro";s:9:"Protected";s:7:"BasePri";s:7:"Private";})
068- TestDerived::unserialize()
069- TestBase::unserialize(a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";})
070- TestDerived::unserialize()
071- TestBase::unserialize(a:5:{s:7:"BasePub";s:13:"DerivedPublic";s:7:"BasePro";s:16:"DerivdeProtected";s:10:"DerivedPub";s:6:"Public";s:10:"DerivedPro";s:9:"Protected";s:7:"BasePri";s:7:"Private";})
072- array(3) {
073-   [0]=>
074-   object(TestBase)#%d (3) {
075-     ["BasePub"]=>
076-     string(7) "#Public"
077-     ["BasePro":protected]=>
078-     string(10) "#Protected"
079-     ["BasePri":"TestBase":private]=>
080-     string(8) "#Private"
081-   }
082-   [1]=>
083-   object(TestDerived)#%d (6) {
084-     ["BasePub"]=>
085-     string(14) "#DerivedPublic"
086-     ["BasePro":protected]=>
087-     string(17) "#DerivdeProtected"
088-     ["DerivedPub"]=>
089-     string(7) "#Public"
090-     ["DerivedPro":protected]=>
091-     string(10) "#Protected"
092-     ["DerivedPri":"TestDerived":private]=>
093-     string(7) "Private"
094-     ["BasePri":"TestBase":private]=>
095-     string(8) "#Private"
096-   }
097-   [2]=>
098-   object(TestLeaf)#%d (6) {
099-     ["BasePub"]=>
100-     string(14) "#DerivedPublic"
101-     ["BasePro":protected]=>
102-     string(17) "#DerivdeProtected"
103-     ["DerivedPub"]=>
104-     string(7) "#Public"
105-     ["DerivedPro":protected]=>
106-     string(10) "#Protected"
107-     ["DerivedPri":"TestDerived":private]=>
108-     string(7) "Private"
109-     ["BasePri":"TestBase":private]=>
110-     string(8) "#Private"
111-   }
112- }

 

Generated at Tue, 25 Nov 2014 09:11:11 +0000 (44 hours ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.