Annotation of embedaddon/php/ext/pdo/tests/pdo_011.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: PDO Common: PDO::FETCH_FUNC and statement overloading
! 3: --SKIPIF--
! 4: <?php # vim:ft=php
! 5: if (!extension_loaded('pdo')) die('skip');
! 6: $dir = getenv('REDIR_TEST_DIR');
! 7: if (false == $dir) die('skip no driver');
! 8: require_once $dir . 'pdo_test.inc';
! 9: PDOTest::skip();
! 10: ?>
! 11: --FILE--
! 12: <?php
! 13: if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
! 14: require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
! 15: $db = PDOTest::factory();
! 16:
! 17: $db->exec('CREATE TABLE test(id int NOT NULL PRIMARY KEY, val VARCHAR(10), grp VARCHAR(10))');
! 18: $db->exec('INSERT INTO test VALUES(1, \'A\', \'Group1\')');
! 19: $db->exec('INSERT INTO test VALUES(2, \'B\', \'Group1\')');
! 20: $db->exec('INSERT INTO test VALUES(3, \'C\', \'Group2\')');
! 21: $db->exec('INSERT INTO test VALUES(4, \'D\', \'Group2\')');
! 22:
! 23: class DerivedStatement extends PDOStatement
! 24: {
! 25: private function __construct($name, $db)
! 26: {
! 27: $this->name = $name;
! 28: echo __METHOD__ . "($name)\n";
! 29: }
! 30:
! 31: function reTrieve($id, $val) {
! 32: echo __METHOD__ . "($id,$val)\n";
! 33: return array($id=>$val);
! 34: }
! 35: }
! 36:
! 37: $select1 = $db->prepare('SELECT grp, id FROM test');
! 38: $select2 = $db->prepare('SELECT id, val FROM test');
! 39: $derived = $db->prepare('SELECT id, val FROM test', array(PDO::ATTR_STATEMENT_CLASS=>array('DerivedStatement', array('Overloaded', $db))));
! 40:
! 41: class Test1
! 42: {
! 43: public function __construct($id, $val)
! 44: {
! 45: echo __METHOD__ . "($id,$val)\n";
! 46: $this->id = $id;
! 47: $this->val = $val;
! 48: }
! 49:
! 50: static public function factory($id, $val)
! 51: {
! 52: echo __METHOD__ . "($id,$val)\n";
! 53: return new self($id, $val);
! 54: }
! 55: }
! 56:
! 57: function test($id,$val='N/A')
! 58: {
! 59: echo __METHOD__ . "($id,$val)\n";
! 60: return array($id=>$val);
! 61: }
! 62:
! 63: $f = new Test1(0,0);
! 64:
! 65: $select1->execute();
! 66: var_dump($select1->fetchAll(PDO::FETCH_FUNC|PDO::FETCH_GROUP, 'test'));
! 67:
! 68: $select2->execute();
! 69: var_dump($select2->fetchAll(PDO::FETCH_FUNC, 'test'));
! 70:
! 71: $select2->execute();
! 72: var_dump($select2->fetchAll(PDO::FETCH_FUNC, array('Test1','factory')));
! 73:
! 74: $select2->execute();
! 75: var_dump($select2->fetchAll(PDO::FETCH_FUNC, array($f, 'factory')));
! 76:
! 77: var_dump(get_class($derived));
! 78: $derived->execute();
! 79: var_dump($derived->fetchAll(PDO::FETCH_FUNC, array($derived, 'retrieve')));
! 80: $derived->execute();
! 81: var_dump($derived->fetchAll(PDO::FETCH_FUNC, array($derived, 'reTrieve')));
! 82: $derived->execute();
! 83: var_dump($derived->fetchAll(PDO::FETCH_FUNC, array($derived, 'RETRIEVE')));
! 84:
! 85: ?>
! 86: --EXPECTF--
! 87: DerivedStatement::__construct(Overloaded)
! 88: Test1::__construct(0,0)
! 89: test(1,N/A)
! 90: test(2,N/A)
! 91: test(3,N/A)
! 92: test(4,N/A)
! 93: array(2) {
! 94: ["Group1"]=>
! 95: array(2) {
! 96: [0]=>
! 97: array(1) {
! 98: [1]=>
! 99: string(3) "N/A"
! 100: }
! 101: [1]=>
! 102: array(1) {
! 103: [2]=>
! 104: string(3) "N/A"
! 105: }
! 106: }
! 107: ["Group2"]=>
! 108: array(2) {
! 109: [0]=>
! 110: array(1) {
! 111: [3]=>
! 112: string(3) "N/A"
! 113: }
! 114: [1]=>
! 115: array(1) {
! 116: [4]=>
! 117: string(3) "N/A"
! 118: }
! 119: }
! 120: }
! 121: test(1,A)
! 122: test(2,B)
! 123: test(3,C)
! 124: test(4,D)
! 125: array(4) {
! 126: [0]=>
! 127: array(1) {
! 128: [1]=>
! 129: string(1) "A"
! 130: }
! 131: [1]=>
! 132: array(1) {
! 133: [2]=>
! 134: string(1) "B"
! 135: }
! 136: [2]=>
! 137: array(1) {
! 138: [3]=>
! 139: string(1) "C"
! 140: }
! 141: [3]=>
! 142: array(1) {
! 143: [4]=>
! 144: string(1) "D"
! 145: }
! 146: }
! 147: Test1::factory(1,A)
! 148: Test1::__construct(1,A)
! 149: Test1::factory(2,B)
! 150: Test1::__construct(2,B)
! 151: Test1::factory(3,C)
! 152: Test1::__construct(3,C)
! 153: Test1::factory(4,D)
! 154: Test1::__construct(4,D)
! 155: array(4) {
! 156: [0]=>
! 157: object(Test1)#%d (2) {
! 158: ["id"]=>
! 159: string(1) "1"
! 160: ["val"]=>
! 161: string(1) "A"
! 162: }
! 163: [1]=>
! 164: object(Test1)#%d (2) {
! 165: ["id"]=>
! 166: string(1) "2"
! 167: ["val"]=>
! 168: string(1) "B"
! 169: }
! 170: [2]=>
! 171: object(Test1)#%d (2) {
! 172: ["id"]=>
! 173: string(1) "3"
! 174: ["val"]=>
! 175: string(1) "C"
! 176: }
! 177: [3]=>
! 178: object(Test1)#%d (2) {
! 179: ["id"]=>
! 180: string(1) "4"
! 181: ["val"]=>
! 182: string(1) "D"
! 183: }
! 184: }
! 185: Test1::factory(1,A)
! 186: Test1::__construct(1,A)
! 187: Test1::factory(2,B)
! 188: Test1::__construct(2,B)
! 189: Test1::factory(3,C)
! 190: Test1::__construct(3,C)
! 191: Test1::factory(4,D)
! 192: Test1::__construct(4,D)
! 193: array(4) {
! 194: [0]=>
! 195: object(Test1)#%d (2) {
! 196: ["id"]=>
! 197: string(1) "1"
! 198: ["val"]=>
! 199: string(1) "A"
! 200: }
! 201: [1]=>
! 202: object(Test1)#%d (2) {
! 203: ["id"]=>
! 204: string(1) "2"
! 205: ["val"]=>
! 206: string(1) "B"
! 207: }
! 208: [2]=>
! 209: object(Test1)#%d (2) {
! 210: ["id"]=>
! 211: string(1) "3"
! 212: ["val"]=>
! 213: string(1) "C"
! 214: }
! 215: [3]=>
! 216: object(Test1)#%d (2) {
! 217: ["id"]=>
! 218: string(1) "4"
! 219: ["val"]=>
! 220: string(1) "D"
! 221: }
! 222: }
! 223: string(16) "DerivedStatement"
! 224: DerivedStatement::reTrieve(1,A)
! 225: DerivedStatement::reTrieve(2,B)
! 226: DerivedStatement::reTrieve(3,C)
! 227: DerivedStatement::reTrieve(4,D)
! 228: array(4) {
! 229: [0]=>
! 230: array(1) {
! 231: [1]=>
! 232: string(1) "A"
! 233: }
! 234: [1]=>
! 235: array(1) {
! 236: [2]=>
! 237: string(1) "B"
! 238: }
! 239: [2]=>
! 240: array(1) {
! 241: [3]=>
! 242: string(1) "C"
! 243: }
! 244: [3]=>
! 245: array(1) {
! 246: [4]=>
! 247: string(1) "D"
! 248: }
! 249: }
! 250: DerivedStatement::reTrieve(1,A)
! 251: DerivedStatement::reTrieve(2,B)
! 252: DerivedStatement::reTrieve(3,C)
! 253: DerivedStatement::reTrieve(4,D)
! 254: array(4) {
! 255: [0]=>
! 256: array(1) {
! 257: [1]=>
! 258: string(1) "A"
! 259: }
! 260: [1]=>
! 261: array(1) {
! 262: [2]=>
! 263: string(1) "B"
! 264: }
! 265: [2]=>
! 266: array(1) {
! 267: [3]=>
! 268: string(1) "C"
! 269: }
! 270: [3]=>
! 271: array(1) {
! 272: [4]=>
! 273: string(1) "D"
! 274: }
! 275: }
! 276: DerivedStatement::reTrieve(1,A)
! 277: DerivedStatement::reTrieve(2,B)
! 278: DerivedStatement::reTrieve(3,C)
! 279: DerivedStatement::reTrieve(4,D)
! 280: array(4) {
! 281: [0]=>
! 282: array(1) {
! 283: [1]=>
! 284: string(1) "A"
! 285: }
! 286: [1]=>
! 287: array(1) {
! 288: [2]=>
! 289: string(1) "B"
! 290: }
! 291: [2]=>
! 292: array(1) {
! 293: [3]=>
! 294: string(1) "C"
! 295: }
! 296: [3]=>
! 297: array(1) {
! 298: [4]=>
! 299: string(1) "D"
! 300: }
! 301: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>