Annotation of embedaddon/php/ext/oci8/tests/conn_attr.inc, revision 1.1.1.1

1.1       misho       1: <?php
                      2: 
                      3: require(dirname(__FILE__)."/connect.inc");
                      4: 
                      5: $sv = oci_server_version($c);
                      6: $sv = preg_match('/Release (11\.2|12)\./', $sv, $matches);
                      7: if ($sv == 1) {
                      8:     // Server is Oracle 11.2+
                      9:     $stmtarray = array(
                     10:         "drop user testuser cascade",
                     11:         "create user testuser identified by testuser",
                     12:         "grant connect,resource,dba to testuser",
                     13:         "alter user testuser enable editions",
                     14:         "drop edition myedition1",
                     15:         "drop edition myedition",
                     16:         "grant create any edition to testuser",
                     17:         "create edition myedition",
                     18:         "create edition myedition1 as child of myedition",
                     19:         "grant use on edition myedition to testuser",
                     20:         "grant use on edition myedition1 to testuser",
                     21:     );
                     22: }
                     23: else {
                     24:     // Server is Pre 11.2 
                     25:     $stmtarray = array(
                     26:         "drop user testuser cascade",
                     27:         "create user testuser identified by testuser",
                     28:         "grant connect,resource,dba to testuser",
                     29:     );
                     30: }
                     31: 
                     32: foreach ($stmtarray as $stmt) {
                     33:     $s = oci_parse($c, $stmt);
                     34:     $r = @oci_execute($s);
                     35:        if (!$r) {
                     36:                $m = oci_error($s);
                     37:                if (!in_array($m['code'], array(   // ignore expected errors
                     38:                         942 // table or view does not exist
                     39:                      , 1918 // user does not exist 
                     40:                      , 2289 // sequence does not exist
                     41:                      , 4080 // trigger does not exist
                     42:                     , 38802 // edition does not exist
                     43:                 ))) {
                     44:                        echo "Error:" . $stmt . PHP_EOL . $m['message'] . PHP_EOL;
                     45:             if ($m['code'] == 38807) {
                     46:                 echo "You appear to already have an edition in use that prevents this PHP test from running.  Query DBA_EDITIONS to see existing editions.". PHP_EOL;
                     47:             }
                     48:             die;
                     49:                }
                     50:        }
                     51: }
                     52: 
                     53: function get_attr($conn,$attr)
                     54: {
                     55:     $sel_stmt="select " .$attr. " from v\$session where sid = 
                     56:        (select sid from v\$session where audsid = 
                     57:        sys_context('userenv','sessionid')) order by 1";
                     58:     $s2 = oci_parse($conn,$sel_stmt);
                     59:     oci_execute($s2,OCI_DEFAULT);
                     60:     while (oci_fetch($s2)) {
                     61:         echo "The value of ".$attr ." is ".oci_result($s2,1)."\n";
                     62:     }
                     63: }
                     64: 
                     65: /* Pass $conn_type=1 for a connection with oci_connect() 
                     66:    Pass $conn_type=2 for ooci_pconnect 
                     67:    Default will give a oci_new_connect */
                     68: 
                     69: function get_conn($conn_type)
                     70: {
                     71:        $user = 'testuser';
                     72:        $password = 'testuser';
                     73:        $dbase = $GLOBALS['dbase'];
                     74:        switch($conn_type) {
                     75:         case 1:
                     76:             echo "Testing with oci_connect()\n";
                     77:             return(oci_connect($user,$password,$dbase));
                     78:             break;
                     79:         case 2:
                     80:             echo "Testing with oci_pconnect()\n";
                     81:             return(oci_pconnect($user,$password,$dbase));
                     82:             break;
                     83:         default:
                     84:             echo "Testing with oci_new_connect()\n";
                     85:             return(oci_new_connect($user,$password,$dbase));
                     86:             break;
                     87:        }
                     88: }
                     89: 
                     90: function set_attr($conn,$attr,$sufix)
                     91: {
                     92:        if (!strcmp($attr,'MODULE')) 
                     93:                $r = oci_set_module_name($conn,'PHP TEST'.$sufix);
                     94:        else if (!strcmp($attr,'ACTION')) 
                     95:         $r = oci_set_action($conn,'TASK'.$sufix);
                     96:        else if (!strcmp($attr,'CLIENT_INFO')) 
                     97:         $r = oci_set_client_info($conn,'INFO1'.$sufix);
                     98:        else if (!strcmp($attr,'CLIENT_IDENTIFIER')) 
                     99:         $r = oci_set_client_identifier($conn,'ID00'.$sufix);
                    100:        else
                    101:                echo "Pass one of the above four attibutes!!!\n";
                    102:        if ($r) {
                    103:                echo "Value of $attr has been set successfully\n";
                    104:     }
                    105:     
                    106:        //Do a round-trip here
                    107:        oci_server_version($conn);
                    108:        return $r;    
                    109: }
                    110: 
                    111: function set_edit_attr($value)
                    112: {
                    113:        $r = oci_set_edition($value);
                    114:     if ($r) {
                    115:                echo " The value of edition has been successfully set\n";
                    116:     }
                    117:        return $r;
                    118: }
                    119: 
                    120: function get_edit_attr ($conn) {
                    121:        $sel_stmt = "select sys_context('USERENV', 'CURRENT_EDITION_NAME') from dual";
                    122:     $s2 = oci_parse($conn,$sel_stmt);
                    123:     oci_execute($s2,OCI_DEFAULT);
                    124:     while (oci_fetch($s2)) {
                    125:         echo "The value of current EDITION is ".oci_result($s2,1)."\n";
                    126:     }
                    127: }
                    128: 
                    129: function get_sys_attr($conn,$attr)
                    130: {
                    131:        $sel_stmt="select " .$attr. " from v\$session where sid = 
                    132:        (select sid from v\$session where audsid = sys_context('userenv','sessionid')) order by 1";
                    133:     $s2 = oci_parse($conn,$sel_stmt);
                    134:     oci_execute($s2,OCI_DEFAULT);
                    135:     while (oci_fetch($s2)) {
                    136:         echo "The value of ".$attr ." is ".oci_result($s2,1)."\n";
                    137:     }
                    138: }
                    139: 
                    140: function clean_up($c) {
                    141:        $stmtarray = array(
                    142:         "drop user testuser cascade",
                    143:         "drop edition myedition1",
                    144:         "drop edition myedition",
                    145:        );
                    146:     
                    147:        foreach ($stmtarray as $stmt) {
                    148:         $s = oci_parse($c, $stmt);
                    149:         @oci_execute($s);
                    150:        }
                    151: }

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