Annotation of embedaddon/php/ext/pdo_pgsql/tests/copy_to.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: PDO PgSQL pgsqlCopyToArray and pgsqlCopyToFile
                      3: --SKIPIF--
                      4: <?php # vim:se ft=php:
                      5: if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded');
                      6: require dirname(__FILE__) . '/config.inc';
                      7: require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
                      8: PDOTest::skip();
                      9: ?>
                     10: --FILE--
                     11: <?php
                     12: require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
                     13: $db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
                     14: $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                     15: $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
                     16: 
                     17: $db->exec('CREATE TABLE test (a integer not null primary key, b text, c integer)');
                     18: 
                     19: $db->beginTransaction();
                     20: try {
                     21: 
                     22: echo "Preparing test table for CopyTo tests\n";
                     23: $stmt = $db->prepare("INSERT INTO test (a, b, c) values (?, ?, ?)");
                     24: 
                     25: for($i=0;$i<3;$i++) {
                     26:        $firstParameter = $i;
                     27:        $secondParameter = "test insert {$i}";
                     28:        $thirdParameter = NULL;
                     29:        $stmt->bindValue(1, $firstParameter);
                     30:        $stmt->bindValue(2, $secondParameter);
                     31:        $stmt->bindValue(3, $thirdParameter);
                     32:        $stmt->execute();
                     33: }
                     34: 
                     35: $db->commit();
                     36: 
                     37: echo "Testing pgsqlCopyToArray() with default parameters\n";
                     38: var_dump($db->pgsqlCopyToArray('test'));
                     39: echo "Testing pgsqlCopyToArray() with different field separator and not null indicator\n";
                     40: var_dump($db->pgsqlCopyToArray('test',";","NULL"));
                     41: echo "Testing pgsqlCopyToArray() with only selected fields\n";
                     42: var_dump($db->pgsqlCopyToArray('test',";","NULL",'a,c'));
                     43: 
                     44: echo "Testing pgsqlCopyToArray() with error\n";
                     45: var_dump($db->pgsqlCopyToArray('test_error'));
                     46: 
                     47: 
                     48: echo "Testing pgsqlCopyToFile() with default parameters\n";
                     49: 
                     50: $filename="test_pgsqlCopyToFile.csv";
                     51: var_dump($db->pgsqlCopyToFile('test',$filename));
                     52: echo file_get_contents($filename);
                     53: echo "Testing pgsqlCopyToFile() with different field separator and not null indicator\n";
                     54: var_dump($db->pgsqlCopyToFile('test',$filename,";","NULL"));
                     55: echo file_get_contents($filename);
                     56: echo "Testing pgsqlCopyToFile() with only selected fields\n";
                     57: var_dump($db->pgsqlCopyToFile('test',$filename,";","NULL",'a,c'));
                     58: echo file_get_contents($filename);
                     59: 
                     60: echo "Testing pgsqlCopyToFile() with error\n";
                     61: var_dump($db->pgsqlCopyToFile('test_error',$filename));
                     62: 
                     63: 
                     64: } catch (Exception $e) {
                     65:        /* catch exceptions so that we can show the relative error */
                     66:        echo "Exception! at line ", $e->getLine(), "\n";
                     67:        var_dump($e->getMessage());
                     68: }
                     69: if(isset($filename)) {
                     70:        @unlink($filename);
                     71: }
                     72: ?>
                     73: --EXPECT--
                     74: Preparing test table for CopyTo tests
                     75: Testing pgsqlCopyToArray() with default parameters
                     76: array(3) {
                     77:   [0]=>
                     78:   string(19) "0        test insert 0   \N
                     79: "
                     80:   [1]=>
                     81:   string(19) "1        test insert 1   \N
                     82: "
                     83:   [2]=>
                     84:   string(19) "2        test insert 2   \N
                     85: "
                     86: }
                     87: Testing pgsqlCopyToArray() with different field separator and not null indicator
                     88: array(3) {
                     89:   [0]=>
                     90:   string(21) "0;test insert 0;NULL
                     91: "
                     92:   [1]=>
                     93:   string(21) "1;test insert 1;NULL
                     94: "
                     95:   [2]=>
                     96:   string(21) "2;test insert 2;NULL
                     97: "
                     98: }
                     99: Testing pgsqlCopyToArray() with only selected fields
                    100: array(3) {
                    101:   [0]=>
                    102:   string(7) "0;NULL
                    103: "
                    104:   [1]=>
                    105:   string(7) "1;NULL
                    106: "
                    107:   [2]=>
                    108:   string(7) "2;NULL
                    109: "
                    110: }
                    111: Testing pgsqlCopyToArray() with error
                    112: bool(false)
                    113: Testing pgsqlCopyToFile() with default parameters
                    114: bool(true)
                    115: 0      test insert 0   \N
                    116: 1      test insert 1   \N
                    117: 2      test insert 2   \N
                    118: Testing pgsqlCopyToFile() with different field separator and not null indicator
                    119: bool(true)
                    120: 0;test insert 0;NULL
                    121: 1;test insert 1;NULL
                    122: 2;test insert 2;NULL
                    123: Testing pgsqlCopyToFile() with only selected fields
                    124: bool(true)
                    125: 0;NULL
                    126: 1;NULL
                    127: 2;NULL
                    128: Testing pgsqlCopyToFile() with error
                    129: bool(false)

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>