Annotation of embedaddon/php/ext/oci8/tests/xmltype_01.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Basic XMLType test
                      3: --SKIPIF--
                      4: <?php 
                      5: if (!extension_loaded("simplexml")) die("skip no simplexml extension");
                      6: $target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
                      7: require(dirname(__FILE__).'/skipif.inc');
                      8: --FILE--
                      9: <?php
                     10: 
                     11: require(dirname(__FILE__)."/connect.inc");
                     12: 
                     13: // Initialization
                     14: 
                     15: $stmtarray = array(
                     16:        "drop table xtt",
                     17:        "create table xtt
                     18:                   (xt_id number, xt_spec xmltype)
                     19:                   xmltype xt_spec store as clob",
                     20:        "insert into xtt (xt_id, xt_spec) values
                     21:          (1,
                     22:           xmltype('<?xml version=\"1.0\"?>
                     23:                <Xt>
                     24:                  <XtId>1</XtId>
                     25:                  <Size>Big</Size>
                     26:                  <Area>12345</Area>
                     27:                  <Hardness>20</Hardness>
                     28:                  <Lip>Curved</Lip>
                     29:                  <Color>Red</Color>
                     30:                  <Nice>N</Nice>
                     31:                  <Compact>Tiny</Compact>
                     32:                  <Material>Steel</Material>
                     33:                </Xt>'))"
                     34: );
                     35: 
                     36: oci8_test_sql_execute($c, $stmtarray);
                     37: 
                     38: function do_query($c)
                     39: {
                     40:        $s = oci_parse($c, 'select XMLType.getClobVal(xt_spec)
                     41:                                        from xtt where xt_id = 1');
                     42:        oci_execute($s);
                     43:        $row = oci_fetch_row($s);
                     44:        $data = $row[0]->load();
                     45:        var_dump($data);
                     46:        return($data);
                     47: }
                     48: 
                     49: // Check
                     50: echo "Initial Data\n";
                     51: $data = do_query($c);
                     52: 
                     53: // Manipulate the data using SimpleXML
                     54: $sx = simplexml_load_string($data);
                     55: $sx->Hardness = $sx->Hardness - 1;
                     56: $sx->Nice = 'Y';
                     57: 
                     58: // Insert changes using a temporary CLOB
                     59: $s = oci_parse($c, 'update xtt
                     60:                                        set xt_spec = XMLType(:clob)
                     61:                                        where xt_id = 1');
                     62: $lob = oci_new_descriptor($c, OCI_D_LOB);
                     63: oci_bind_by_name($s, ':clob', $lob, -1, OCI_B_CLOB);
                     64: $lob->writeTemporary($sx->asXml());
                     65: oci_execute($s);
                     66: $lob->close();
                     67: 
                     68: // Verify
                     69: echo "Verify\n";
                     70: $data = do_query($c);
                     71: 
                     72: // Cleanup
                     73: 
                     74: $stmtarray = array(
                     75:        "drop table xtt",
                     76: );
                     77: 
                     78: oci8_test_sql_execute($c, $stmtarray);
                     79: 
                     80: echo "Done\n";
                     81: 
                     82: ?>
                     83: --EXPECT--
                     84: Initial Data
                     85: string(250) "<?xml version="1.0"?>
                     86:                <Xt>
                     87:                  <XtId>1</XtId>
                     88:                  <Size>Big</Size>
                     89:                  <Area>12345</Area>
                     90:                  <Hardness>20</Hardness>
                     91:                  <Lip>Curved</Lip>
                     92:                  <Color>Red</Color>
                     93:                  <Nice>N</Nice>
                     94:                  <Compact>Tiny</Compact>
                     95:                  <Material>Steel</Material>
                     96:                </Xt>"
                     97: Verify
                     98: string(249) "<?xml version="1.0"?>
                     99: <Xt>
                    100:                  <XtId>1</XtId>
                    101:                  <Size>Big</Size>
                    102:                  <Area>12345</Area>
                    103:                  <Hardness>19</Hardness>
                    104:                  <Lip>Curved</Lip>
                    105:                  <Color>Red</Color>
                    106:                  <Nice>Y</Nice>
                    107:                  <Compact>Tiny</Compact>
                    108:                  <Material>Steel</Material>
                    109:                </Xt>
                    110: "
                    111: Done

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