Annotation of embedaddon/php/ext/pdo_pgsql/tests/large_objects.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: PDO PgSQL Large Objects
        !             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 (blobid integer not null primary key, bloboid OID)');
        !            18: 
        !            19: $db->beginTransaction();
        !            20: $oid = $db->pgsqlLOBCreate();
        !            21: try {
        !            22: $stm = $db->pgsqlLOBOpen($oid, 'w+b');
        !            23: fwrite($stm, "Hello dude\n");
        !            24: 
        !            25: $stmt = $db->prepare("INSERT INTO test (blobid, bloboid) values (?, ?)");
        !            26: $stmt->bindValue(1, 1);
        !            27: /* bind as LOB; the oid from the pgsql stream will be inserted instead
        !            28:  * of the stream contents. Binding other streams will attempt to bind
        !            29:  * as bytea, and will most likely lead to an error.
        !            30:  * You can also just bind the $oid in as a string. */
        !            31: $stmt->bindParam(2, $stm, PDO::PARAM_LOB);
        !            32: $stmt->execute();
        !            33: $stm = null;
        !            34: 
        !            35: /* Pull it out */
        !            36: $stmt = $db->prepare("SELECT * from test");
        !            37: $stmt->bindColumn('bloboid', $lob, PDO::PARAM_LOB);
        !            38: $stmt->execute();
        !            39: echo "Fetching:\n";
        !            40: while (($row = $stmt->fetch(PDO::FETCH_ASSOC))) {
        !            41:        var_dump($row['blobid']);
        !            42:        var_dump(stream_get_contents($lob));
        !            43: }
        !            44: echo "Fetched!\n";
        !            45: 
        !            46: /* Try again, with late bind */
        !            47: $stmt = $db->prepare("SELECT * from test");
        !            48: $stmt->execute();
        !            49: $stmt->bindColumn('bloboid', $lob, PDO::PARAM_LOB);
        !            50: echo "Fetching late bind:\n";
        !            51: while (($row = $stmt->fetch(PDO::FETCH_ASSOC))) {
        !            52:        var_dump($row['blobid']);
        !            53:        var_dump(is_int($row['bloboid']));
        !            54: }
        !            55: echo "Fetched!\n";
        !            56: 
        !            57: /* Try again, with NO  bind */
        !            58: $stmt = $db->prepare("SELECT * from test");
        !            59: $stmt->execute();
        !            60: $stmt->bindColumn('bloboid', $lob, PDO::PARAM_LOB);
        !            61: echo "Fetching NO bind:\n";
        !            62: while (($row = $stmt->fetch(PDO::FETCH_ASSOC))) {
        !            63:        var_dump($row['blobid']);
        !            64:        var_dump(is_int($row['bloboid']));
        !            65: }
        !            66: echo "Fetched!\n";
        !            67: 
        !            68: } catch (Exception $e) {
        !            69:        /* catch exceptions so that we can guarantee to clean
        !            70:         * up the LOB */
        !            71:        echo "Exception! at line ", $e->getLine(), "\n";
        !            72:        var_dump($e->getMessage());
        !            73: }
        !            74: 
        !            75: /* Now to remove the large object from the database, so it doesn't
        !            76:  * linger and clutter up the storage */
        !            77: $db->pgsqlLOBUnlink($oid);
        !            78: 
        !            79: ?>
        !            80: --EXPECT--
        !            81: Fetching:
        !            82: int(1)
        !            83: string(11) "Hello dude
        !            84: "
        !            85: Fetched!
        !            86: Fetching late bind:
        !            87: int(1)
        !            88: bool(true)
        !            89: Fetched!
        !            90: Fetching NO bind:
        !            91: int(1)
        !            92: bool(true)
        !            93: Fetched!

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