Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
--TEST--
2
DB_driver::tableInfo
3
--INI--
4
error_reporting = 2047
5
--SKIPIF--
6
<?php
7
 
8
/**
9
 * Calls tableInfo() in various ways and checks to see that the output
10
 * matches what's expected.
11
 *
12
 * These tests account for each DBMS using different column types and
13
 * reporting back different information.  These differences are accounted
14
 * for in the <var>$quirks</var> array, which has the following format:
15
 *
16
 * <pre>
17
 * 'driver' => array(
18
 *     'clob' => DBMS's column type for creating CLOB fields
19
 *     'date' => DBMS's column type for creating DATE fields
20
 *     'dateliteral' => The SQL keyword necessary for defining dates
21
 *     'finds_table' => Can this DBMS determine table names from queries?
22
 *     'size_from_table' => Does this DBMS know the column size via table name?
23
 *     'handles_results' => Can the DBMS get info from query results?
24
 *     'commands' => array(
25
 *         Extra commands to be passed to PHP's eval() function
26
 *     )
27
 *     0 => array(
28
 *         //  Info expected to be reported for phptest_fk.a
29
 *         //  (INTEGER NOT NULL) (UNIQUE KEY with d)
30
 *         'type' => Column type reported by the DBMS
31
 *         'len' => Column size reported by the DBMS
32
 *         'flags' => Flags reported by the DBMS
33
 *     )
34
 *     1 => array()  Info expected to be reported for phptest_fk.fk
35
 *                   (INTEGER NOT NULL) (PRIMARY KEY)
36
 *     2 => array()  Info expected to be reported for phptest_fk.c
37
 *                   (CLOB/CHAR/VARCHAR NULL)
38
 *     3 => array()  Info expected to be reported for phptest_fk.d
39
 *                   (DATE NOT NULL) (UNIQUE KEY with a)
40
 *     4 => array()  Info expected to be reported for phptest_fk.e
41
 *                   (CHAR(2) DEFAULT ' e' NOT NULL)
42
 *     5 => array()  Info expected to be reported for phptest_fk.f
43
 *                   (DECIMAL(2,1) NULL)
44
 *     9 => array()  Info expected to be reported for phptest.d
45
 *                   (VARCHAR(20) NULL)
46
 * )
47
 * </pre>
48
 *
49
 * @category Database
50
 * @package  DB
51
 * @version  $Id: 16tableinfo.phpt 306605 2010-12-24 06:22:59Z aharvey $
52
 * @author   Daniel Convissor <danielc@analysisandsolutions.com>
53
 * @see      DB_common::tableInfo()
54
 */
55
 
56
error_reporting(E_ALL);
57
chdir(dirname(__FILE__));
58
require_once dirname(__FILE__) . '/skipif.inc';
59
$tableInfo = $dbh->tableInfo('ajkdslfajoijkadie');
60
if (DB::isError($tableInfo) && $tableInfo->code == DB_ERROR_NOT_CAPABLE) {
61
    die("skip $tableInfo->message");
62
}
63
 
64
?>
65
--FILE--
66
<?php
67
 
68
//  $Id: 16tableinfo.phpt 306605 2010-12-24 06:22:59Z aharvey $
69
 
70
/**
71
 * Connect to the database and make the phptest table.
72
 */
73
require_once dirname(__FILE__) . '/mktable.inc';
74
 
75
/**
76
 * Local error callback handler.
77
 *
78
 * In general, it prints out an error message and kills the process.
79
 * But some errors are expected and allowed to exist.
80
 *
81
 * @param object  $o  PEAR error object automatically passed to this method
82
 * @return void
83
 * @see PEAR::setErrorHandling()
84
 */
85
function pe($o){
86
    global $dbh, $quirks;
87
 
88
    if ($o->getMessage() == "DB Error: can't distinguish duplicate field names") {
89
        print "NOTICE: $dbh->phptype can't distinguish duplicate field names";
90
        return;
91
    }
92
 
93
    if ($o->getCode() == DB_ERROR_NOT_CAPABLE &&
94
        !$quirks[$dbh->phptype . ':' . $dbh->dbsyntax]['handles_results'])
95
    {
96
        return;
97
    }
98
 
99
    $dbh->setErrorHandling(PEAR_ERROR_RETURN);
100
    drop_table($dbh, 'phptest');
101
    drop_table($dbh, 'phptest_fk');
102
 
103
    die($o->toString());
104
}
105
 
106
/**
107
 * Loop through an array returned from tableInfo(), compare the actual
108
 * contents to the expected contents.  If the actual results match the
109
 * expectations, say so.  If not, say so and show the information.
110
 *
111
 * @param array   $array     the array to be examined
112
 * @param string  $expected  the expected contents of the array
113
 * @param string  $field     field index number of $quriks and table
114
 * @param boolean $query     true if array is from a query or false if array
115
 *                           is tableInfo()
116
 * @return void
117
 */
118
function examineArrayData($array, $expected, $field = false, $query = true) {
119
    global $dbh, $quirks;
120
 
121
    $quirk_key = $dbh->phptype . ':' . $dbh->dbsyntax;
122
 
123
    if (DB::isError($array) && $array->getCode() == DB_ERROR_NOT_CAPABLE) {
124
        print "matched expected result\n";
125
        return;
126
    }
127
 
128
    if (!is_array($array)) {
129
        print "This DMBS didn't produce proper results\n";
130
        return;
131
    }
132
 
133
    if (is_int($field)) {
134
        $array = $array[$field];
135
    }
136
 
137
    $actual = '';
138
    foreach ($array as $key => $value) {
139
        if ($field !== false &&
140
            isset($quirks[$quirk_key][$field][$key]))
141
        {
142
            if ($key == 'flags' && $value == '' && $query &&
143
                !$quirks[$quirk_key]['finds_table'])
144
            {
145
                $actual .= "$key ... matched expected value\n";
146
            } else {
147
                if ($quirks[$quirk_key][$field][$key] == $value) {
148
                    $actual .= "$key ... matched expected value\n";
149
                } else {
150
                    if ($value == 0
151
                        && !$quirks[$quirk_key]['size_from_table'])
152
                    {
153
                        $actual .= "$key ... matched expected value\n";
154
                    } else {
155
                        $actual .= "$key ... was '$value' but we expected ";
156
                        $actual .= "'{$quirks[$quirk_key][$field][$key]}'\n";
157
                    }
158
                }
159
            }
160
        } else {
161
            if ($key == 'table') {
162
                if ($field <= 5) {
163
                    if ($value == 'phptest_fk') {
164
                        $actual .= "$key ... matched expected value\n";
165
                    } else {
166
                        if ($value == '' && $query &&
167
                            !$quirks[$quirk_key]['finds_table'])
168
                        {
169
                            $actual .= "$key ... matched expected value\n";
170
                        } else {
171
                            $actual .= "$key ... was '$value' but we expected 'phptest_fk'\n";
172
                        }
173
                    }
174
                } else {
175
                    if ($value == 'phptest') {
176
                        $actual .= "$key ... matched expected value\n";
177
                    } else {
178
                        if ($value == '' && $query &&
179
                            !$quirks[$quirk_key]['finds_table'])
180
                        {
181
                            $actual .= "$key ... matched expected value\n";
182
                        } else {
183
                            $actual .= "$key ... was '$value' but we expected 'phptest_fk'\n";
184
                        }
185
                    }
186
                }
187
            } else {
188
                $actual .= "$key => $value\n";
189
            }
190
        }
191
    }
192
    if ($actual == $expected) {
193
        print "matched expected result\n";
194
    } else {
195
        print "DIDN'T match expected values...\n";
196
        print "~~~~~~~~\nExpected:\n$expected\n";
197
        print "~~~~\nActual:\n$actual\n~~~~~~~~\n\n";
198
    }
199
}
200
 
201
/**
202
 * Loop through an array of table info data and return the results.
203
 *
204
 * @param array  $array  the array to be examined
205
 * @return string
206
 */
207
function returnArrayData($array) {
208
    global $dbh, $quirks;
209
 
210
    $quirk_key = $dbh->phptype . ':' . $dbh->dbsyntax;
211
 
212
    if (!$quirks[$quirk_key]['handles_results']) {
213
        return "\n";
214
    }
215
 
216
    $out = '';
217
    foreach ($array as $key => $value) {
218
        $out .= "$key => $value\n";
219
    }
220
    return $out;
221
}
222
 
223
 
224
$dbh->setErrorHandling(PEAR_ERROR_CALLBACK, 'pe');
225
 
226
 
227
$quirks = array(
228
    'fbsql:fbsql' => array(
229
        'clob' => 'CHAR(29)',
230
        'date' => 'DATE',
231
        'dateliteral' => ' DATE ',
232
        'finds_table' => false,
233
        'size_from_table' => false,
234
        'handles_results' => true,
235
        'commands' => array(
236
        ),
237
 
238
            'type' => 'INTEGER',
239
            'len' => 0,
240
            'flags' => '',
241
        ),
242
        1 => array(
243
            'type' => 'INTEGER',
244
            'len' => 0,
245
            'flags' => 'not_null',
246
        ),
247
        2 => array(
248
            'type' => 'CHARACTER',
249
            'len' => 29,
250
            'flags' => '',
251
        ),
252
        3 => array(
253
            'type' => 'DATE',
254
            'len' => 0,
255
            'flags' => '',
256
        ),
257
        4 => array(
258
            'type' => 'CHARACTER',
259
            'len' => 2,
260
            'flags' => '',
261
        ),
262
        5 => array(
263
            'type' => 'DECIMAL',
264
            'len' => 0,
265
            'flags' => '',
266
        ),
267
        9 => array(
268
            'type' => 'CHARACTER',
269
            'len' => 20,
270
            'flags' => '',
271
        ),
272
    ),
273
 
274
    'ibase:ibase' => array(
275
        'clob' => 'VARCHAR(50)',
276
        'date' => 'DATE',
277
        'dateliteral' => '',
278
        'finds_table' => false,
279
        'size_from_table' => false,
280
        'handles_results' => true,
281
        'commands' => array(
282
        ),
283
 
284
            'type' => 'INTEGER',
285
            'len' => 4,
286
            'flags' => 'unique_key not_null',
287
        ),
288
        1 => array(
289
            'type' => 'INTEGER',
290
            'len' => 4,
291
            'flags' => 'primary_key not_null',
292
        ),
293
        2 => array(
294
            'type' => 'VARCHAR',
295
            'len' => 50,
296
            'flags' => '',
297
        ),
298
        3 => array(
299
            'type' => 'DATE',
300
            'len' => 4,
301
            'flags' => 'unique_key not_null',
302
        ),
303
        4 => array(
304
            'type' => 'CHAR',
305
            'len' => 2,
306
            'flags' => 'not_null default',
307
        ),
308
        5 => array(
309
            'type' => 'NUMERIC(9,1)',
310
            'len' => 4,
311
            'flags' => '',
312
        ),
313
        9 => array(
314
            'type' => 'VARCHAR',
315
            'len' => 20,
316
            'flags' => '',
317
        ),
318
    ),
319
 
320
    'ibase:firebird' => array(
321
        'clob' => 'VARCHAR(50)',
322
        'date' => 'DATE',
323
        'dateliteral' => '',
324
        'finds_table' => false,
325
        'size_from_table' => false,
326
        'handles_results' => true,
327
        'commands' => array(
328
        ),
329
 
330
            'type' => 'INTEGER',
331
            'len' => 4,
332
            'flags' => 'unique_key not_null',
333
        ),
334
        1 => array(
335
            'type' => 'INTEGER',
336
            'len' => 4,
337
            'flags' => 'primary_key not_null',
338
        ),
339
        2 => array(
340
            'type' => 'VARCHAR',
341
            'len' => 50,
342
            'flags' => '',
343
        ),
344
        3 => array(
345
            'type' => 'DATE',
346
            'len' => 4,
347
            'flags' => 'unique_key not_null',
348
        ),
349
        4 => array(
350
            'type' => 'CHAR',
351
            'len' => 2,
352
            'flags' => 'not_null default',
353
        ),
354
        5 => array(
355
            'type' => 'NUMERIC(9,1)',
356
            'len' => 4,
357
            'flags' => '',
358
        ),
359
        9 => array(
360
            'type' => 'VARCHAR',
361
            'len' => 20,
362
            'flags' => '',
363
        ),
364
    ),
365
 
366
    'ifx:ifx' => array(
367
        'clob' => 'CHAR(29)',
368
        'date' => 'CHAR(10)',
369
        'dateliteral' => '',
370
        'finds_table' => false,
371
        'size_from_table' => false,
372
        'handles_results' => true,
373
        'commands' => array(
374
        ),
375
 
376
            'type' => 'SQLINT',
377
            'len' => 4,
378
            'flags' => 'not_null',
379
        ),
380
        1 => array(
381
            'type' => 'SQLINT',
382
            'len' => 4,
383
            'flags' => 'not_null',
384
        ),
385
        2 => array(
386
            'type' => 'SQLCHAR',
387
            'len' => 29,
388
            'flags' => '',
389
        ),
390
        3 => array(
391
            'type' => 'SQLCHAR',
392
            'len' => 10,
393
            'flags' => 'not_null',
394
        ),
395
        4 => array(
396
            'type' => 'SQLCHAR',
397
            'len' => 2,
398
            'flags' => 'not_null',
399
        ),
400
        5 => array(
401
            'type' => 'SQLDECIMAL',
402
            'len' => 513,
403
            'flags' => '',
404
        ),
405
        9 => array(
406
            'type' => 'SQLCHAR',
407
            'len' => 20,
408
            'flags' => '',
409
        ),
410
    ),
411
 
412
    'msql:msql' => array(
413
        'clob' => 'TEXT(255)',
414
        'date' => 'CHAR(10)',
415
        'dateliteral' => '',
416
        'finds_table' => true,
417
        'size_from_table' => true,
418
        'handles_results' => true,
419
        'commands' => array(
420
        ),
421
 
422
            'type' => 'int',
423
            'len' => 4,
424
            'flags' => 'not_null',
425
        ),
426
        1 => array(
427
            'type' => 'int',
428
            'len' => 4,
429
            // for some reason, the unique property always contains 0
430
            // 'flags' => 'unique_key not_null',
431
            'flags' => 'not_null',
432
        ),
433
        2 => array(
434
            'type' => 'text',
435
            'len' => 255,
436
            'flags' => '',
437
        ),
438
        3 => array(
439
            'type' => 'char',
440
            'len' => 10,
441
            'flags' => 'not_null',
442
        ),
443
        4 => array(
444
            'type' => 'char',
445
            'len' => 2,
446
            'flags' => 'not_null',
447
        ),
448
        5 => array(
449
            'type' => 'real',
450
            'len' => 8,
451
            'flags' => '',
452
        ),
453
        9 => array(
454
            'type' => 'char',
455
            'len' => 20,
456
            'flags' => '',
457
        ),
458
    ),
459
 
460
    'mssql:mssql' => array(
461
        'clob' => 'TEXT',
462
        'date' => 'SMALLDATETIME',
463
        'dateliteral' => '',
464
        'finds_table' => false,
465
        'size_from_table' => false,
466
        'handles_results' => true,
467
        'commands' => array(
468
            'ini_set("mssql.datetimeconvert", "Off");',
469
            '$dbh->query("SET DATEFORMAT ymd");',
470
        ),
471
 
472
            'type' => 'int',
473
            'len' => 4,
474
            'flags' => 'multiple_key unique_key not_null',
475
        ),
476
        1 => array(
477
            'type' => 'int',
478
            'len' => 4,
479
            'flags' => 'primary_key not_null',
480
        ),
481
        2 => array(
482
            'type' => 'text',
483
            'len' => 4096,
484
            'flags' => '',
485
        ),
486
        3 => array(
487
            'type' => 'datetime',
488
            'len' => 4,
489
            'flags' => 'multiple_key unique_key not_null',
490
        ),
491
        4 => array(
492
            'type' => 'char',
493
            'len' => 2,
494
            'flags' => 'not_null',
495
        ),
496
        5 => array(
497
            'type' => 'real',
498
            'len' => 8,
499
            'flags' => '',
500
        ),
501
        9 => array(
502
            'type' => 'char',
503
            'len' => 20,
504
            'flags' => '',
505
        ),
506
    ),
507
 
508
    'mysql:mysql' => array(
509
        'clob' => 'TEXT',
510
        'date' => 'DATE',
511
        'dateliteral' => '',
512
        'finds_table' => true,
513
        'size_from_table' => true,
514
        'handles_results' => true,
515
        'commands' => array(
516
        ),
517
 
518
            'type' => 'int',
519
            'len' => 11,
520
            'flags' => 'not_null multiple_key',
521
        ),
522
        1 => array(
523
            'type' => 'int',
524
            'len' => 11,
525
            'flags' => 'not_null primary_key',
526
        ),
527
        2 => array(
528
            'type' => 'blob',
529
            'len' => 65535,
530
            'flags' => 'blob',
531
        ),
532
        3 => array(
533
            'type' => 'date',
534
            'len' => 10,
535
            'flags' => 'not_null multiple_key binary',
536
        ),
537
        4 => array(
538
            'type' => 'string',
539
            'len' => 2,
540
            'flags' => 'not_null',
541
        ),
542
        5 => array(
543
            'type' => 'real',
544
            'len' => 4,
545
            'flags' => '',
546
        ),
547
        9 => array(
548
            'type' => 'string',
549
            'len' => 20,
550
            'flags' => '',
551
        ),
552
    ),
553
 
554
    'mysqli:mysqli' => array(
555
        'clob' => 'TEXT',
556
        'date' => 'DATE',
557
        'dateliteral' => '',
558
        'finds_table' => true,
559
        'size_from_table' => false,
560
        'handles_results' => true,
561
        'commands' => array(
562
        ),
563
 
564
            'type' => 'int',
565
            'len' => 11,
566
            'flags' => 'not_null multiple_key',
567
        ),
568
        1 => array(
569
            'type' => 'int',
570
            'len' => 11,
571
            'flags' => 'not_null primary_key',
572
        ),
573
        2 => array(
574
            'type' => 'blob',
575
            'len' => 65535,
576
            'flags' => 'blob',
577
        ),
578
        3 => array(
579
            'type' => 'date',
580
            'len' => 10,
581
            'flags' => 'not_null multiple_key binary',
582
        ),
583
        4 => array(
584
            'type' => 'string',
585
            'len' => 2,
586
            'flags' => 'not_null',
587
        ),
588
        5 => array(
589
            'type' => 'real',
590
            'len' => 4,
591
            'flags' => '',
592
        ),
593
        9 => array(
594
            'type' => 'string',
595
            'len' => 20,
596
            'flags' => '',
597
        ),
598
    ),
599
 
600
    'oci8:oci8' => array(
601
        'clob' => 'CLOB',
602
        'date' => 'DATE',
603
        'dateliteral' => '',
604
        'finds_table' => false,
605
        'size_from_table' => false,
606
        'handles_results' => true,
607
        'commands' => array(
608
            '$dbh->query("ALTER SESSION SET NLS_DATE_FORMAT = \'YYYY-MM-DD\'");',
609
        ),
610
 
611
            'type' => 'NUMBER',
612
            'len' => 22,
613
            'flags' => 'not_null',
614
        ),
615
        1 => array(
616
            'type' => 'NUMBER',
617
            'len' => 22,
618
            'flags' => 'not_null',
619
        ),
620
        2 => array(
621
            'type' => 'CLOB',
622
            'len' => 4000,
623
            'flags' => '',
624
        ),
625
        3 => array(
626
            'type' => 'DATE',
627
            'len' => 7,
628
            'flags' => 'not_null',
629
        ),
630
        4 => array(
631
            'type' => 'CHAR',
632
            'len' => 2,
633
            'flags' => 'not_null',
634
        ),
635
        5 => array(
636
            'type' => 'NUMBER',
637
            'len' => 22,
638
            'flags' => '',
639
        ),
640
        9 => array(
641
            'type' => 'VARCHAR',
642
            'len' => 20,
643
            'flags' => '',
644
        ),
645
    ),
646
 
647
    'odbc:access' => array(
648
        'clob' => 'TEXT',
649
        'date' => 'DATETIME',
650
        'dateliteral' => '',
651
        'finds_table' => false,
652
        'size_from_table' => false,
653
        'handles_results' => true,
654
        'commands' => array(
655
        ),
656
 
657
            'type' => 'INTEGER',
658
            'len' => 10,
659
            'flags' => 'not_null',
660
        ),
661
        1 => array(
662
            'type' => 'INTEGER',
663
            'len' => 10,
664
            'flags' => 'not_null',
665
        ),
666
        2 => array(
667
            'type' => 'LONGCHAR',
668
            'len' => 255,
669
            'flags' => '',
670
        ),
671
        3 => array(
672
            'type' => 'DATETIME',
673
            'len' => 19,
674
            'flags' => 'not_null',
675
        ),
676
        4 => array(
677
            'type' => 'VARCHAR',
678
            'len' => 2,
679
            'flags' => 'not_null',
680
        ),
681
        5 => array(
682
            'type' => 'DECIMAL',
683
            'len' => 15,
684
            'flags' => '',
685
        ),
686
        9 => array(
687
            'type' => 'VARCHAR',
688
            'len' => 20,
689
            'flags' => '',
690
        ),
691
    ),
692
 
693
    'odbc:db2' => array(
694
        'clob' => 'CLOB',
695
        'date' => 'DATE',
696
        'dateliteral' => '',
697
        'finds_table' => false,
698
        'size_from_table' => false,
699
        'handles_results' => true,
700
        'commands' => array(
701
        ),
702
 
703
            'type' => 'INTEGER',
704
            'len' => 10,
705
            'flags' => 'not_null',
706
        ),
707
        1 => array(
708
            'type' => 'INTEGER',
709
            'len' => 10,
710
            'flags' => 'not_null',
711
        ),
712
        2 => array(
713
            'type' => 'CLOB',
714
            'len' => 1048576,
715
            'flags' => '',
716
        ),
717
        3 => array(
718
            'type' => 'DATE',
719
            'len' => 10,
720
            'flags' => 'not_null',
721
        ),
722
        4 => array(
723
            'type' => 'CHAR',
724
            'len' => 2,
725
            'flags' => 'not_null',
726
        ),
727
        5 => array(
728
            'type' => 'DECIMAL',
729
            'len' => 2,
730
            'flags' => '',
731
        ),
732
        9 => array(
733
            'type' => 'VARCHAR',
734
            'len' => 20,
735
            'flags' => '',
736
        ),
737
    ),
738
 
739
    'pgsql:pgsql' => array(
740
        'clob' => 'TEXT',
741
        'date' => 'DATE',
742
        'dateliteral' => '',
743
        'finds_table' => false,
744
        'size_from_table' => false,
745
        'handles_results' => true,
746
        'commands' => array(
747
            '$dbh->query("SET DATESTYLE = ISO");',
748
        ),
749
 
750
            'type' => 'int4',
751
            'len' => 4,
752
            'flags' => 'not_null unique_key multiple_key',
753
        ),
754
        1 => array(
755
            'type' => 'int4',
756
            'len' => 4,
757
            'flags' => 'not_null primary_key',
758
        ),
759
        2 => array(
760
            'type' => 'text',
761
            'len' => -1,
762
            'flags' => '',
763
        ),
764
        3 => array(
765
            'type' => 'date',
766
            'len' => 4,
767
            'flags' => 'not_null unique_key multiple_key',
768
        ),
769
        4 => array(
770
            'type' => 'bpchar',
771
            'len' => -1,
772
            'flags' => 'not_null default_%20e',
773
        ),
774
        5 => array(
775
            'type' => 'numeric',
776
            'len' => -1,
777
            'flags' => '',
778
        ),
779
        9 => array(
780
            'type' => 'varchar',
781
            'len' => -1,
782
            'flags' => '',
783
        ),
784
    ),
785
 
786
    'sqlite:sqlite' => array(
787
        'clob' => 'CLOB',
788
        'date' => 'DATE',
789
        'dateliteral' => '',
790
        'finds_table' => false,
791
        'size_from_table' => false,
792
        'handles_results' => false,
793
        'commands' => array(
794
        ),
795
 
796
            'type' => 'INTEGER',
797
            'len' => 0,
798
            'flags' => 'not_null',
799
        ),
800
        1 => array(
801
            'type' => 'INTEGER',
802
            'len' => 0,
803
            'flags' => 'primary_key auto_increment not_null',
804
        ),
805
        2 => array(
806
            'type' => 'CLOB',
807
            'len' => 0,
808
            'flags' => '',
809
        ),
810
        3 => array(
811
            'type' => 'DATE',
812
            'len' => 0,
813
            'flags' => 'not_null',
814
        ),
815
        4 => array(
816
            'type' => 'CHAR',
817
            'len' => 2,
818
            'flags' => 'not_null default_%20e',
819
        ),
820
        5 => array(
821
            'type' => 'DECIMAL',
822
            'len' => 2,
823
            'flags' => '',
824
        ),
825
        9 => array(
826
            'type' => 'VARCHAR',
827
            'len' => 20,
828
            'flags' => '',
829
        ),
830
    ),
831
 
832
    'sybase:sybase' => array(
833
        'clob' => 'TEXT',
834
        'date' => 'SMALLDATETIME',
835
        'dateliteral' => '',
836
        'finds_table' => false,
837
        'size_from_table' => false,
838
        'handles_results' => true,
839
        'commands' => array(
840
            '$dbh->query("SET DATEFORMAT ymd");',
841
        ),
842
 
843
            'type' => 'int',
844
            'len' => 11,
845
            'flags' => 'multiple_key unique_key',
846
        ),
847
        1 => array(
848
            'type' => 'int',
849
            'len' => 11,
850
            'flags' => 'unique_key',
851
        ),
852
        2 => array(
853
            'type' => 'string',
854
            'len' => 64512,
855
            'flags' => '',
856
        ),
857
        3 => array(
858
            'type' => 'datetime',
859
            'len' => 29,
860
            'flags' => 'multiple_key unique_key',
861
        ),
862
        4 => array(
863
            'type' => 'string',
864
            'len' => 2,
865
            'flags' => '',
866
        ),
867
        5 => array(
868
            'type' => 'real',
869
            'len' => 4,
870
            'flags' => '',
871
        ),
872
        9 => array(
873
            'type' => 'string',
874
            'len' => 20,
875
            'flags' => '',
876
        ),
877
    ),
878
);
879
 
880
 
881
$quirk_key = $dbh->phptype . ':' . $dbh->dbsyntax;
882
 
883
if (!isset($quirks[$quirk_key])) {
884
    die("This test does not yet support $quirk_key");
885
}
886
 
887
if (count($quirks[$quirk_key]['commands'])) {
888
    foreach ($quirks[$quirk_key]['commands'] as $value) {
889
        eval($value);
890
    }
891
}
892
 
893
 
894
$dbh->query('DELETE FROM phptest');
895
$dbh->query("INSERT INTO phptest VALUES (1, 'one', 'One', '2001-02-16')");
896
$dbh->query("INSERT INTO phptest VALUES (2, 'two', 'Two', '2001-02-15')");
897
$dbh->query("INSERT INTO phptest VALUES (3, 'three', 'Three', '2001-02-14')");
898
 
899
 
900
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
901
drop_table($dbh, 'phptest_fk');
902
$dbh->setErrorHandling(PEAR_ERROR_CALLBACK, 'pe');
903
 
904
 
905
if ($quirk_key == 'odbc:access') {
906
    $default_e = '';
907
    $decimal   = 'NUMERIC';
908
} elseif ($quirk_key == 'msql:msql') {
909
    $default_e = '';
910
    $decimal   = 'REAL';
911
} else {
912
    $default_e = "DEFAULT ' e'";
913
    $decimal   = 'DECIMAL(2,1)';
914
}
915
 
916
if ($quirk_key == 'mssql:mssql') {
917
    /* We need to reset the expected length of phptest_fk.c to match
918
     * @@TEXTSIZE, since the default value seems to vary based on the version
919
     * of SQL Server we're talking to and its configuration. */
920
    $textsize = $dbh->getOne('SELECT @@TEXTSIZE');
921
    if (DB::isError($textsize)) {
922
        echo 'Error retrieving @@TEXTSIZE: '.$textsize->getMessage()."\n";
923
    } else {
924
        $quirks[$quirk_key][2]['len'] = (integer) $textsize;
925
    }
926
}
927
 
928
// $null is set in mktable.inc
929
 
930
switch ($dbh->phptype) {
931
    case 'msql':
932
        $dbh->query("
933
            CREATE TABLE phptest_fk (
934
                a INTEGER NOT NULL,
935
                fk INTEGER NOT NULL,
936
                cc {$quirks[$quirk_key]['clob']} $null,
937
                d {$quirks[$quirk_key]['date']} NOT NULL,
938
                e CHAR(2) $default_e NOT NULL,
939
                f $decimal $null
940
            )
941
        ");
942
        $dbh->query('CREATE UNIQUE INDEX fkpk ON phptest_fk (fk)');
943
        $dbh->query('CREATE UNIQUE INDEX fkuk ON phptest_fk (a, d)');
944
        break;
945
    default:
946
        $dbh->query("
947
            CREATE TABLE phptest_fk (
948
                a INTEGER NOT NULL,
949
                fk INTEGER NOT NULL,
950
                cc {$quirks[$quirk_key]['clob']} $null,
951
                d {$quirks[$quirk_key]['date']} NOT NULL,
952
                e CHAR(2) $default_e NOT NULL,
953
                f $decimal $null,
954
                PRIMARY KEY (fk),
955
                UNIQUE (a, d)
956
            )
957
        ");
958
}
959
 
960
$dbh->query("CREATE INDEX thedidx ON phptest_fk (d)");
961
$dbh->query("INSERT INTO phptest_fk VALUES (10, 1, 'One',"
962
            . $quirks[$quirk_key]['dateliteral'] . "'2001-02-16',  'c1', 1.1)");
963
$dbh->query("INSERT INTO phptest_fk VALUES (20, 2, 'Two',"
964
            . $quirks[$quirk_key]['dateliteral'] . "'2001-02-15', 'c2', 2.2)");
965
$dbh->query("INSERT INTO phptest_fk VALUES (30, 3, 'Three',"
966
            . $quirks[$quirk_key]['dateliteral'] . "'2001-02-14', 'c3', 3.3)");
967
 
968
function &runQuery() {
969
    global $dbh, $resultobj;
970
 
971
    $quirk_key = $dbh->phptype . ':' . $dbh->dbsyntax;
972
 
973
    switch ($quirk_key) {
974
        case 'odbc:db2':
975
            // can't extract blob's this way so make a fake column
976
            $query = "SELECT phptest_fk.a, phptest_fk.fk, 'tempxyz' AS cc,"
977
                   . ' phptest_fk.d, phptest_fk.e, phptest_fk.f,'
978
                   . ' phptest.a, phptest.b, phptest.cc, phptest.d'
979
                   . ' FROM phptest_fk, phptest'
980
                   . ' WHERE phptest.a = phptest_fk.fk';
981
            break;
982
        case 'msql:msql':
983
            $query = 'SELECT phptest_fk.a, phptest_fk.fk, phptest_fk.cc,'
984
                   . ' phptest_fk.d, phptest_fk.e, phptest_fk.f,'
985
                   . ' phptest.a, phptest.b, phptest.cc, phptest.d'
986
                   . ' FROM phptest_fk, phptest'
987
                   . ' WHERE phptest.a = phptest_fk.fk';
988
            break;
989
        default:
990
            $query = 'SELECT phptest_fk.a, phptest_fk.fk, phptest_fk.cc,'
991
                   . ' phptest_fk.d, phptest_fk.e, phptest_fk.f,'
992
                   . ' phptest.a, phptest.b, phptest.cc, phptest.d'
993
                   . ' FROM phptest_fk, phptest'
994
                   . ' WHERE phptest.a = phptest_fk.fk';
995
    }
996
    $resultobj =& $dbh->query($query);
997
    return $resultobj;
998
}
999
 
1000
 
1001
$expected01 = 'table ... matched expected value
1002
name => a
1003
type ... matched expected value
1004
len ... matched expected value
1005
flags ... matched expected value
1006
';
1007
 
1008
$expected02 = 'table ... matched expected value
1009
name => fk
1010
type ... matched expected value
1011
len ... matched expected value
1012
flags ... matched expected value
1013
';
1014
 
1015
$expected03 = 'table ... matched expected value
1016
name => cc
1017
type ... matched expected value
1018
len ... matched expected value
1019
flags ... matched expected value
1020
';
1021
 
1022
$expected04 = 'table ... matched expected value
1023
name => d
1024
type ... matched expected value
1025
len ... matched expected value
1026
flags ... matched expected value
1027
';
1028
 
1029
$expected05 = 'table ... matched expected value
1030
name => e
1031
type ... matched expected value
1032
len ... matched expected value
1033
flags ... matched expected value
1034
';
1035
 
1036
$expected06 = 'table ... matched expected value
1037
name => f
1038
type ... matched expected value
1039
len ... matched expected value
1040
flags ... matched expected value
1041
';
1042
 
1043
$expected10 = 'table ... matched expected value
1044
name => d
1045
type ... matched expected value
1046
len ... matched expected value
1047
flags ... matched expected value
1048
';
1049
 
1050
 
1051
 
1052
print "\n==========================================\n";
1053
print "Passing result OBJECT to method in DB_<type>.\n";
1054
print "Output = default.\n";
1055
print "------------------------------------------\n";
1056
$resultobj =& runQuery();
1057
// This numRows call provides a regression test for bug #4388.
1058
$resultobj->numRows();
1059
$array = $dbh->tableInfo($resultobj);
1060
 
1061
print "\ncolumn 0:\n";
1062
examineArrayData($array, $expected01, 0);
1063
 
1064
print "\ncolumn 9:\n";
1065
examineArrayData($array, $expected10, 9);
1066
 
1067
 
1068
print "\n==========================================\n";
1069
print "Passing result ID to method in DB_<type>.\n";
1070
print "Output = DB_TABLEINFO_ORDER.\n";
1071
print "------------------------------------------\n";
1072
$resultobj =& runQuery();
1073
$array = $dbh->tableInfo($resultobj->result, DB_TABLEINFO_ORDER);
1074
 
1075
print "\ncolumn 0:\n";
1076
examineArrayData($array, $expected01, 0);
1077
 
1078
print "\ncolumn 3:\n";
1079
examineArrayData($array, $expected04, 3);
1080
 
1081
print "\nnum_fields: ";
1082
if ($quirks[$quirk_key]['handles_results'] && $array['num_fields'] == 10) {
1083
    print "matched expected result\n";
1084
} elseif (DB::isError($array) && $array->getCode() == DB_ERROR_NOT_CAPABLE) {
1085
    print "matched expected result\n";
1086
} else {
1087
    print "This DMBS didn't produce proper results\n";
1088
}
1089
 
1090
print "\norder:\n";
1091
if ($quirks[$quirk_key]['handles_results'] && is_array($array['order'])) {
1092
    $expected = 'a => 6
1093
b => 7
1094
cc => 8
1095
d => 9
1096
e => 4
1097
f => 5
1098
fk => 1
1099
';
1100
    ksort($array['order']);
1101
    examineArrayData($array['order'], $expected);
1102
} elseif (DB::isError($array) && $array->getCode() == DB_ERROR_NOT_CAPABLE) {
1103
    print "matched expected result\n";
1104
} else {
1105
    print "This DMBS didn't produce proper results\n";
1106
}
1107
 
1108
 
1109
 
1110
print "\n==========================================\n";
1111
print "Passing DB_TABLEINFO_ORDERTABLE to method in DB_result.\n";
1112
print "Output = DB_TABLEINFO_ORDERTABLE.\n";
1113
print "------------------------------------------\n";
1114
$resultobj =& runQuery();
1115
$array = $resultobj->tableInfo(DB_TABLEINFO_ORDERTABLE);
1116
// Free this to keep interbase happy.
1117
$resultobj->free();
1118
 
1119
print "\ncolumn 0:\n";
1120
examineArrayData($array, $expected01, 0);
1121
 
1122
print "\ncolumn 3:\n";
1123
examineArrayData($array, $expected04, 3);
1124
 
1125
print "\nnum_fields: ";
1126
if ($quirks[$quirk_key]['handles_results'] && $array['num_fields'] == 10) {
1127
    print "matched expected result\n";
1128
} elseif (DB::isError($array) && $array->getCode() == DB_ERROR_NOT_CAPABLE) {
1129
    print "matched expected result\n";
1130
} else {
1131
    print "This DMBS didn't produce proper results\n";
1132
}
1133
 
1134
 
1135
print 'ordertable[phptest]: ';
1136
$expected = 'a => 6
1137
b => 7
1138
cc => 8
1139
d => 9
1140
';
1141
if ($quirks[$quirk_key]['handles_results']
1142
    && isset($array['ordertable']['phptest'])) {
1143
    $actual = returnArrayData($array['ordertable']['phptest']);
1144
} else {
1145
    $actual = '';
1146
}
1147
if ($actual == $expected) {
1148
    print "matched expected result\n";
1149
} else {
1150
    if (($quirks[$quirk_key]['finds_table'] === false
1151
        || DB::isError($array) && $array->getCode() == DB_ERROR_NOT_CAPABLE)
1152
        && $actual == '') {
1153
        print "matched expected result\n";
1154
    } else {
1155
        print "DIDN'T match expected values...\n";
1156
        print "~~~~~~~~\nExpected:\n$expected\n";
1157
        print "~~~~\nActual:\n$actual\n~~~~~~~~\n\n";
1158
    }
1159
}
1160
 
1161
 
1162
print 'ordertable[phptest_fk]: ';
1163
$expected = 'a => 0
1164
fk => 1
1165
cc => 2
1166
d => 3
1167
e => 4
1168
f => 5
1169
';
1170
if ($quirks[$quirk_key]['handles_results']
1171
    && isset($array['ordertable']['phptest_fk'])) {
1172
    $actual = returnArrayData($array['ordertable']['phptest_fk']);
1173
} else {
1174
    $actual = '';
1175
}
1176
if ($actual == $expected) {
1177
    print "matched expected result\n";
1178
} else {
1179
    if (($quirks[$quirk_key]['finds_table'] === false
1180
        || DB::isError($array) && $array->getCode() == DB_ERROR_NOT_CAPABLE)
1181
        && $actual == '') {
1182
        print "matched expected result\n";
1183
    } else {
1184
        print "DIDN'T match expected values...\n";
1185
        print "~~~~~~~~\nExpected:\n$expected\n";
1186
        print "~~~~\nActual:\n$actual\n~~~~~~~~\n\n";
1187
    }
1188
}
1189
 
1190
 
1191
print "\n==========================================\n";
1192
print "Passing TABLE NAME 'phptest_fk' to method in DB_<driver>.\n";
1193
print "Output = default.\n";
1194
print "------------------------------------------\n";
1195
$array = $dbh->tableInfo('phptest_fk');
1196
 
1197
print "\ncolumn 0:\n";
1198
examineArrayData($array, $expected01, 0, false);
1199
 
1200
print "\ncolumn 1:\n";
1201
examineArrayData($array, $expected02, 1, false);
1202
 
1203
print "\ncolumn 2:\n";
1204
examineArrayData($array, $expected03, 2, false);
1205
 
1206
print "\ncolumn 3:\n";
1207
examineArrayData($array, $expected04, 3, false);
1208
 
1209
print "\ncolumn 4:\n";
1210
examineArrayData($array, $expected05, 4, false);
1211
 
1212
print "\ncolumn 5:\n";
1213
examineArrayData($array, $expected06, 5, false);
1214
 
1215
 
1216
print "\n==========================================\n";
1217
print "Passing TABLE NAME 'phptest_fk' to method in DB_<driver>.\n";
1218
print "Output = DB_TABLEINFO_FULL.\n";
1219
print "------------------------------------------\n";
1220
$array = $dbh->tableInfo('phptest_fk', DB_TABLEINFO_FULL);
1221
 
1222
print "\ncolumn 0:\n";
1223
examineArrayData($array, $expected01, 0, false);
1224
 
1225
print "\norder:\n";
1226
$expect ='a => 0
1227
fk => 1
1228
cc => 2
1229
d => 3
1230
e => 4
1231
f => 5
1232
';
1233
examineArrayData($array['order'], $expect, false, false);
1234
 
1235
print "\nordertable[phptest_fk]:\n";
1236
$expect ='a => 0
1237
fk => 1
1238
cc => 2
1239
d => 3
1240
e => 4
1241
f => 5
1242
';
1243
examineArrayData($array['ordertable']['phptest_fk'], $expect);
1244
 
1245
 
1246
 
1247
print "\n==========================================\n";
1248
print "Passing TABLE NAME 'phptest_fk' to method in DB_<driver> AGAIN.\n";
1249
print "Output = DB_TABLEINFO_FULL, lowercasing turned off.\n";
1250
print "------------------------------------------\n";
1251
$dbh->setOption('portability', DB_PORTABILITY_ALL ^ DB_PORTABILITY_LOWERCASE);
1252
$array = $dbh->tableInfo('phptest_fk', DB_TABLEINFO_FULL);
1253
 
1254
// testing non-lowercasing above to ensure program doesn't die.
1255
// lowercase the names here to ensure test uniformity.
1256
$array[0]['table'] = strtolower($array[0]['table']);
1257
$array[0]['name'] = strtolower($array[0]['name']);
1258
 
1259
print "\ncolumn 0:\n";
1260
examineArrayData($array, 0, false);
1261
 
1262
 
1263
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
1264
drop_table($dbh, 'phptest');
1265
drop_table($dbh, 'phptest_fk');
1266
 
1267
?>
1268
--EXPECT--
1269
==========================================
1270
Passing result OBJECT to method in DB_<type>.
1271
Output = default.
1272
------------------------------------------
1273
 
1274
column 0:
1275
matched expected result
1276
 
1277
column 9:
1278
matched expected result
1279
 
1280
==========================================
1281
Passing result ID to method in DB_<type>.
1282
Output = DB_TABLEINFO_ORDER.
1283
------------------------------------------
1284
 
1285
column 0:
1286
matched expected result
1287
 
1288
column 3:
1289
matched expected result
1290
 
1291
num_fields: matched expected result
1292
 
1293
order:
1294
matched expected result
1295
 
1296
==========================================
1297
Passing DB_TABLEINFO_ORDERTABLE to method in DB_result.
1298
Output = DB_TABLEINFO_ORDERTABLE.
1299
------------------------------------------
1300
 
1301
column 0:
1302
matched expected result
1303
 
1304
column 3:
1305
matched expected result
1306
 
1307
num_fields: matched expected result
1308
ordertable[phptest]: matched expected result
1309
ordertable[phptest_fk]: matched expected result
1310
 
1311
==========================================
1312
Passing TABLE NAME 'phptest_fk' to method in DB_<driver>.
1313
Output = default.
1314
------------------------------------------
1315
 
1316
column 0:
1317
matched expected result
1318
 
1319
column 1:
1320
matched expected result
1321
 
1322
column 2:
1323
matched expected result
1324
 
1325
column 3:
1326
matched expected result
1327
 
1328
column 4:
1329
matched expected result
1330
 
1331
column 5:
1332
matched expected result
1333
 
1334
==========================================
1335
Passing TABLE NAME 'phptest_fk' to method in DB_<driver>.
1336
Output = DB_TABLEINFO_FULL.
1337
------------------------------------------
1338
 
1339
column 0:
1340
matched expected result
1341
 
1342
order:
1343
matched expected result
1344
 
1345
ordertable[phptest_fk]:
1346
matched expected result
1347
 
1348
==========================================
1349
Passing TABLE NAME 'phptest_fk' to method in DB_<driver> AGAIN.
1350
Output = DB_TABLEINFO_FULL, lowercasing turned off.
1351
------------------------------------------
1352
 
1353
column 0:
1354
matched expected result