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,v 1.32 2005/02/14 17:04:17 danielc Exp $
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 './skipif.inc';
59
$tableInfo = $db->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,v 1.32 2005/02/14 17:04:17 danielc Exp $
69
 
70
/**
71
 * Connect to the database and make the phptest table.
72
 */
73
require_once './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' => 19,
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',
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' => 2,
566
            'flags' => 'not_null multiple_key group_by',
567
        ),
568
        1 => array(
569
            'type' => 'int',
570
            'len' => 0,
571
            'flags' => 'not_null primary_key group_by',
572
        ),
573
        2 => array(
574
            'type' => 'blob',
575
            'len' => 0,
576
            'flags' => 'blob',
577
        ),
578
        3 => array(
579
            'type' => 'date',
580
            'len' => 10,
581
            'flags' => 'not_null multiple_key',
582
        ),
583
        4 => array(
584
            'type' => 'char',
585
            'len' => 0,
586
            'flags' => 'not_null',
587
        ),
588
        5 => array(
589
            'type' => 'decimal',
590
            'len' => 0,
591
            'flags' => 'group_by',
592
        ),
593
        9 => array(
594
            'type' => 'varchar',
595
            'len' => 10,
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 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' => 32768,
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
// $null is set in mktable.inc
917
 
918
switch ($dbh->phptype) {
919
    case 'msql':
920
        $dbh->query("
921
            CREATE TABLE phptest_fk (
922
                a INTEGER NOT NULL,
923
                fk INTEGER NOT NULL,
924
                c {$quirks[$quirk_key]['clob']} $null,
925
                d {$quirks[$quirk_key]['date']} NOT NULL,
926
                e CHAR(2) $default_e NOT NULL,
927
                f $decimal $null
928
            )
929
        ");
930
        $dbh->query('CREATE UNIQUE INDEX fkpk ON phptest_fk (fk)');
931
        $dbh->query('CREATE UNIQUE INDEX fkuk ON phptest_fk (a, d)');
932
        break;
933
    default:
934
        $dbh->query("
935
            CREATE TABLE phptest_fk (
936
                a INTEGER NOT NULL,
937
                fk INTEGER NOT NULL,
938
                c {$quirks[$quirk_key]['clob']} $null,
939
                d {$quirks[$quirk_key]['date']} NOT NULL,
940
                e CHAR(2) $default_e NOT NULL,
941
                f $decimal $null,
942
                PRIMARY KEY (fk),
943
                UNIQUE (a, d)
944
            )
945
        ");
946
}
947
 
948
$dbh->query("CREATE INDEX thedidx ON phptest_fk (d)");
949
$dbh->query("INSERT INTO phptest_fk VALUES (10, 1, 'One',"
950
            . $quirks[$quirk_key]['dateliteral'] . "'2001-02-16',  'c1', 1.1)");
951
$dbh->query("INSERT INTO phptest_fk VALUES (20, 2, 'Two',"
952
            . $quirks[$quirk_key]['dateliteral'] . "'2001-02-15', 'c2', 2.2)");
953
$dbh->query("INSERT INTO phptest_fk VALUES (30, 3, 'Three',"
954
            . $quirks[$quirk_key]['dateliteral'] . "'2001-02-14', 'c3', 3.3)");
955
 
956
function &runQuery() {
957
    global $dbh, $resultobj;
958
 
959
    $quirk_key = $dbh->phptype . ':' . $dbh->dbsyntax;
960
 
961
    switch ($quirk_key) {
962
        case 'odbc:db2':
963
            // can't extract blob's this way so make a fake column
964
            $query = "SELECT phptest_fk.a, phptest_fk.fk, 'tempxyz' AS c,"
965
                   . ' phptest_fk.d, phptest_fk.e, phptest_fk.f,'
966
                   . ' phptest.a, phptest.b, phptest.c, phptest.d'
967
                   . ' FROM phptest_fk, phptest'
968
                   . ' WHERE phptest.a = phptest_fk.fk';
969
            break;
970
        case 'msql:msql':
971
            $query = 'SELECT phptest_fk.a, phptest_fk.fk, phptest_fk.c,'
972
                   . ' phptest_fk.d, phptest_fk.e, phptest_fk.f,'
973
                   . ' phptest.a, phptest.b, phptest.c, phptest.d'
974
                   . ' FROM phptest_fk, phptest'
975
                   . ' WHERE phptest.a = phptest_fk.fk';
976
            break;
977
        default:
978
            $query = 'SELECT phptest_fk.a, phptest_fk.fk, phptest_fk.c,'
979
                   . ' phptest_fk.d, phptest_fk.e, phptest_fk.f,'
980
                   . ' phptest.a, phptest.b, phptest.c, phptest.d'
981
                   . ' FROM phptest_fk, phptest'
982
                   . ' WHERE phptest.a = phptest_fk.fk';
983
    }
984
    $resultobj =& $dbh->query($query);
985
    return $resultobj;
986
}
987
 
988
 
989
$expected01 = 'table ... matched expected value
990
name => a
991
type ... matched expected value
992
len ... matched expected value
993
flags ... matched expected value
994
';
995
 
996
$expected02 = 'table ... matched expected value
997
name => fk
998
type ... matched expected value
999
len ... matched expected value
1000
flags ... matched expected value
1001
';
1002
 
1003
$expected03 = 'table ... matched expected value
1004
name => c
1005
type ... matched expected value
1006
len ... matched expected value
1007
flags ... matched expected value
1008
';
1009
 
1010
$expected04 = 'table ... matched expected value
1011
name => d
1012
type ... matched expected value
1013
len ... matched expected value
1014
flags ... matched expected value
1015
';
1016
 
1017
$expected05 = 'table ... matched expected value
1018
name => e
1019
type ... matched expected value
1020
len ... matched expected value
1021
flags ... matched expected value
1022
';
1023
 
1024
$expected06 = 'table ... matched expected value
1025
name => f
1026
type ... matched expected value
1027
len ... matched expected value
1028
flags ... matched expected value
1029
';
1030
 
1031
$expected10 = 'table ... matched expected value
1032
name => d
1033
type ... matched expected value
1034
len ... matched expected value
1035
flags ... matched expected value
1036
';
1037
 
1038
 
1039
 
1040
print "\n==========================================\n";
1041
print "Passing result OBJECT to method in DB_<type>.\n";
1042
print "Output = default.\n";
1043
print "------------------------------------------\n";
1044
$resultobj =& runQuery();
1045
$array = $dbh->tableInfo($resultobj);
1046
 
1047
print "\ncolumn 0:\n";
1048
examineArrayData($array, $expected01, 0);
1049
 
1050
print "\ncolumn 9:\n";
1051
examineArrayData($array, $expected10, 9);
1052
 
1053
 
1054
print "\n==========================================\n";
1055
print "Passing result ID to method in DB_<type>.\n";
1056
print "Output = DB_TABLEINFO_ORDER.\n";
1057
print "------------------------------------------\n";
1058
$resultobj =& runQuery();
1059
$array = $dbh->tableInfo($resultobj->result, DB_TABLEINFO_ORDER);
1060
 
1061
print "\ncolumn 0:\n";
1062
examineArrayData($array, $expected01, 0);
1063
 
1064
print "\ncolumn 3:\n";
1065
examineArrayData($array, $expected04, 3);
1066
 
1067
print "\nnum_fields: ";
1068
if ($quirks[$quirk_key]['handles_results'] && $array['num_fields'] == 10) {
1069
    print "matched expected result\n";
1070
} elseif (DB::isError($array) && $array->getCode() == DB_ERROR_NOT_CAPABLE) {
1071
    print "matched expected result\n";
1072
} else {
1073
    print "This DMBS didn't produce proper results\n";
1074
}
1075
 
1076
print "\norder:\n";
1077
if ($quirks[$quirk_key]['handles_results'] && is_array($array['order'])) {
1078
    $expected = 'a => 6
1079
b => 7
1080
c => 8
1081
d => 9
1082
e => 4
1083
f => 5
1084
fk => 1
1085
';
1086
    ksort($array['order']);
1087
    examineArrayData($array['order'], $expected);
1088
} elseif (DB::isError($array) && $array->getCode() == DB_ERROR_NOT_CAPABLE) {
1089
    print "matched expected result\n";
1090
} else {
1091
    print "This DMBS didn't produce proper results\n";
1092
}
1093
 
1094
 
1095
 
1096
print "\n==========================================\n";
1097
print "Passing DB_TABLEINFO_ORDERTABLE to method in DB_result.\n";
1098
print "Output = DB_TABLEINFO_ORDERTABLE.\n";
1099
print "------------------------------------------\n";
1100
$resultobj =& runQuery();
1101
$array = $resultobj->tableInfo(DB_TABLEINFO_ORDERTABLE);
1102
// Free this to keep interbase happy.
1103
$resultobj->free();
1104
 
1105
print "\ncolumn 0:\n";
1106
examineArrayData($array, $expected01, 0);
1107
 
1108
print "\ncolumn 3:\n";
1109
examineArrayData($array, $expected04, 3);
1110
 
1111
print "\nnum_fields: ";
1112
if ($quirks[$quirk_key]['handles_results'] && $array['num_fields'] == 10) {
1113
    print "matched expected result\n";
1114
} elseif (DB::isError($array) && $array->getCode() == DB_ERROR_NOT_CAPABLE) {
1115
    print "matched expected result\n";
1116
} else {
1117
    print "This DMBS didn't produce proper results\n";
1118
}
1119
 
1120
 
1121
print 'ordertable[phptest]: ';
1122
$expected = 'a => 6
1123
b => 7
1124
c => 8
1125
d => 9
1126
';
1127
if ($quirks[$quirk_key]['handles_results']
1128
    && isset($array['ordertable']['phptest'])) {
1129
    $actual = returnArrayData($array['ordertable']['phptest']);
1130
} else {
1131
    $actual = '';
1132
}
1133
if ($actual == $expected) {
1134
    print "matched expected result\n";
1135
} else {
1136
    if (($quirks[$quirk_key]['finds_table'] === false
1137
        || DB::isError($array) && $array->getCode() == DB_ERROR_NOT_CAPABLE)
1138
        && $actual == '') {
1139
        print "matched expected result\n";
1140
    } else {
1141
        print "DIDN'T match expected values...\n";
1142
        print "~~~~~~~~\nExpected:\n$expected\n";
1143
        print "~~~~\nActual:\n$actual\n~~~~~~~~\n\n";
1144
    }
1145
}
1146
 
1147
 
1148
print 'ordertable[phptest_fk]: ';
1149
$expected = 'a => 0
1150
fk => 1
1151
c => 2
1152
d => 3
1153
e => 4
1154
f => 5
1155
';
1156
if ($quirks[$quirk_key]['handles_results']
1157
    && isset($array['ordertable']['phptest_fk'])) {
1158
    $actual = returnArrayData($array['ordertable']['phptest_fk']);
1159
} else {
1160
    $actual = '';
1161
}
1162
if ($actual == $expected) {
1163
    print "matched expected result\n";
1164
} else {
1165
    if (($quirks[$quirk_key]['finds_table'] === false
1166
        || DB::isError($array) && $array->getCode() == DB_ERROR_NOT_CAPABLE)
1167
        && $actual == '') {
1168
        print "matched expected result\n";
1169
    } else {
1170
        print "DIDN'T match expected values...\n";
1171
        print "~~~~~~~~\nExpected:\n$expected\n";
1172
        print "~~~~\nActual:\n$actual\n~~~~~~~~\n\n";
1173
    }
1174
}
1175
 
1176
 
1177
print "\n==========================================\n";
1178
print "Passing TABLE NAME 'phptest_fk' to method in DB_<driver>.\n";
1179
print "Output = default.\n";
1180
print "------------------------------------------\n";
1181
$array = $dbh->tableInfo('phptest_fk');
1182
 
1183
print "\ncolumn 0:\n";
1184
examineArrayData($array, $expected01, 0, false);
1185
 
1186
print "\ncolumn 1:\n";
1187
examineArrayData($array, $expected02, 1, false);
1188
 
1189
print "\ncolumn 2:\n";
1190
examineArrayData($array, $expected03, 2, false);
1191
 
1192
print "\ncolumn 3:\n";
1193
examineArrayData($array, $expected04, 3, false);
1194
 
1195
print "\ncolumn 4:\n";
1196
examineArrayData($array, $expected05, 4, false);
1197
 
1198
print "\ncolumn 5:\n";
1199
examineArrayData($array, $expected06, 5, false);
1200
 
1201
 
1202
print "\n==========================================\n";
1203
print "Passing TABLE NAME 'phptest_fk' to method in DB_<driver>.\n";
1204
print "Output = DB_TABLEINFO_FULL.\n";
1205
print "------------------------------------------\n";
1206
$array = $dbh->tableInfo('phptest_fk', DB_TABLEINFO_FULL);
1207
 
1208
print "\ncolumn 0:\n";
1209
examineArrayData($array, $expected01, 0, false);
1210
 
1211
print "\norder:\n";
1212
$expect ='a => 0
1213
fk => 1
1214
c => 2
1215
d => 3
1216
e => 4
1217
f => 5
1218
';
1219
examineArrayData($array['order'], $expect, false, false);
1220
 
1221
print "\nordertable[phptest_fk]:\n";
1222
$expect ='a => 0
1223
fk => 1
1224
c => 2
1225
d => 3
1226
e => 4
1227
f => 5
1228
';
1229
examineArrayData($array['ordertable']['phptest_fk'], $expect);
1230
 
1231
 
1232
 
1233
print "\n==========================================\n";
1234
print "Passing TABLE NAME 'phptest_fk' to method in DB_<driver> AGAIN.\n";
1235
print "Output = DB_TABLEINFO_FULL, lowercasing turned off.\n";
1236
print "------------------------------------------\n";
1237
$dbh->setOption('portability', DB_PORTABILITY_ALL ^ DB_PORTABILITY_LOWERCASE);
1238
$array = $dbh->tableInfo('phptest_fk', DB_TABLEINFO_FULL);
1239
 
1240
// testing non-lowercasing above to ensure program doesn't die.
1241
// lowercase the names here to ensure test uniformity.
1242
$array[0]['table'] = strtolower($array[0]['table']);
1243
$array[0]['name'] = strtolower($array[0]['name']);
1244
 
1245
print "\ncolumn 0:\n";
1246
examineArrayData($array, 0, false);
1247
 
1248
 
1249
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
1250
drop_table($dbh, 'phptest');
1251
drop_table($dbh, 'phptest_fk');
1252
 
1253
?>
1254
--EXPECT--
1255
==========================================
1256
Passing result OBJECT to method in DB_<type>.
1257
Output = default.
1258
------------------------------------------
1259
 
1260
column 0:
1261
matched expected result
1262
 
1263
column 9:
1264
matched expected result
1265
 
1266
==========================================
1267
Passing result ID to method in DB_<type>.
1268
Output = DB_TABLEINFO_ORDER.
1269
------------------------------------------
1270
 
1271
column 0:
1272
matched expected result
1273
 
1274
column 3:
1275
matched expected result
1276
 
1277
num_fields: matched expected result
1278
 
1279
order:
1280
matched expected result
1281
 
1282
==========================================
1283
Passing DB_TABLEINFO_ORDERTABLE to method in DB_result.
1284
Output = DB_TABLEINFO_ORDERTABLE.
1285
------------------------------------------
1286
 
1287
column 0:
1288
matched expected result
1289
 
1290
column 3:
1291
matched expected result
1292
 
1293
num_fields: matched expected result
1294
ordertable[phptest]: matched expected result
1295
ordertable[phptest_fk]: matched expected result
1296
 
1297
==========================================
1298
Passing TABLE NAME 'phptest_fk' to method in DB_<driver>.
1299
Output = default.
1300
------------------------------------------
1301
 
1302
column 0:
1303
matched expected result
1304
 
1305
column 1:
1306
matched expected result
1307
 
1308
column 2:
1309
matched expected result
1310
 
1311
column 3:
1312
matched expected result
1313
 
1314
column 4:
1315
matched expected result
1316
 
1317
column 5:
1318
matched expected result
1319
 
1320
==========================================
1321
Passing TABLE NAME 'phptest_fk' to method in DB_<driver>.
1322
Output = DB_TABLEINFO_FULL.
1323
------------------------------------------
1324
 
1325
column 0:
1326
matched expected result
1327
 
1328
order:
1329
matched expected result
1330
 
1331
ordertable[phptest_fk]:
1332
matched expected result
1333
 
1334
==========================================
1335
Passing TABLE NAME 'phptest_fk' to method in DB_<driver> AGAIN.
1336
Output = DB_TABLEINFO_FULL, lowercasing turned off.
1337
------------------------------------------
1338
 
1339
column 0:
1340
matched expected result