2010-05-14 16:37:06 +00:00
< ? php
2010-10-29 13:24:06 +00:00
$drivers [ " oracle " ] = " Oracle " ;
2010-05-14 16:37:06 +00:00
if ( isset ( $_GET [ " oracle " ])) {
2010-10-29 13:24:06 +00:00
$possible_drivers = array ( " OCI8 " , " PDO_OCI " );
2010-05-14 16:37:06 +00:00
define ( " DRIVER " , " oracle " );
if ( extension_loaded ( " oci8 " )) {
class Min_DB {
var $extension = " oci8 " , $_link , $_result , $server_info , $affected_rows , $error ;
function _error ( $errno , $error ) {
if ( ini_bool ( " html_errors " )) {
$error = html_entity_decode ( strip_tags ( $error ));
}
$error = ereg_replace ( '^[^:]*: ' , '' , $error );
$this -> error = $error ;
}
function connect ( $server , $username , $password ) {
2010-11-19 15:14:17 +00:00
$this -> _link = @ oci_new_connect ( $username , $password , $server , " AL32UTF8 " );
2010-05-14 16:37:06 +00:00
if ( $this -> _link ) {
$this -> server_info = oci_server_version ( $this -> _link );
return true ;
}
$error = oci_error ();
$this -> error = $error [ " message " ];
return false ;
}
function quote ( $string ) {
return " ' " . str_replace ( " ' " , " '' " , $string ) . " ' " ;
}
function select_db ( $database ) {
return true ;
}
function query ( $query , $unbuffered = false ) {
$result = oci_parse ( $this -> _link , $query );
if ( ! $result ) {
$error = oci_error ( $this -> _link );
$this -> error = $error [ " message " ];
return false ;
}
set_error_handler ( array ( $this , '_error' ));
$return = @ oci_execute ( $result );
restore_error_handler ();
if ( $return ) {
if ( oci_num_fields ( $result )) {
return new Min_Result ( $result );
}
$this -> affected_rows = oci_num_rows ( $result );
}
return $return ;
}
function multi_query ( $query ) {
return $this -> _result = $this -> query ( $query );
}
function store_result () {
return $this -> _result ;
}
function next_result () {
return false ;
}
function result ( $query , $field = 1 ) {
$result = $this -> query ( $query );
if ( ! is_object ( $result ) || ! oci_fetch ( $result -> _result )) {
return false ;
}
return oci_result ( $result -> _result , $field );
}
}
class Min_Result {
var $_result , $_offset = 1 , $num_rows ;
function Min_Result ( $result ) {
$this -> _result = $result ;
}
2010-05-20 15:35:30 +00:00
function _convert ( $row ) {
foreach (( array ) $row as $key => $val ) {
if ( is_a ( $val , 'OCI-Lob' )) {
$row [ $key ] = $val -> load ();
}
}
return $row ;
}
2010-05-14 16:37:06 +00:00
function fetch_assoc () {
2010-05-20 15:35:30 +00:00
return $this -> _convert ( oci_fetch_assoc ( $this -> _result ));
2010-05-14 16:37:06 +00:00
}
function fetch_row () {
2010-05-20 15:35:30 +00:00
return $this -> _convert ( oci_fetch_row ( $this -> _result ));
2010-05-14 16:37:06 +00:00
}
function fetch_field () {
$column = $this -> _offset ++ ;
$return = new stdClass ;
$return -> name = oci_field_name ( $this -> _result , $column );
$return -> orgname = $return -> name ;
$return -> type = oci_field_type ( $this -> _result , $column );
$return -> charsetnr = ( ereg ( " raw|blob|bfile " , $return -> type ) ? 63 : 0 ); // 63 - binary
return $return ;
}
function __destruct () {
oci_free_statement ( $this -> _result );
}
}
} elseif ( extension_loaded ( " pdo_oci " )) {
class Min_DB extends Min_PDO {
var $extension = " PDO_OCI " ;
function connect ( $server , $username , $password ) {
2010-11-19 15:14:17 +00:00
$this -> dsn ( " oci:dbname=// $server ;charset=AL32UTF8 " , $username , $password );
2010-11-19 15:13:49 +00:00
return true ;
2010-05-14 16:37:06 +00:00
}
function select_db ( $database ) {
2010-11-19 15:13:49 +00:00
return true ;
2010-05-14 16:37:06 +00:00
}
}
}
function idf_escape ( $idf ) {
return '"' . str_replace ( '"' , '""' , $idf ) . '"' ;
}
function table ( $idf ) {
return idf_escape ( $idf );
}
function connect () {
global $adminer ;
$connection = new Min_DB ;
$credentials = $adminer -> credentials ();
if ( $connection -> connect ( $credentials [ 0 ], $credentials [ 1 ], $credentials [ 2 ])) {
return $connection ;
}
return $connection -> error ;
}
function get_databases () {
return get_vals ( " SELECT tablespace_name FROM user_tablespaces " );
}
function limit ( $query , $where , $limit , $offset = 0 , $separator = " " ) {
2011-05-24 13:20:13 +00:00
return ( $offset ? " * FROM (SELECT t.*, rownum AS rnum FROM (SELECT $query $where ) t WHERE rownum <= " . ( $limit + $offset ) . " ) WHERE rnum > $offset "
: ( isset ( $limit ) ? " * FROM (SELECT $query $where ) WHERE rownum <= " . ( $limit + $offset )
: " $query $where "
));
2010-05-14 16:37:06 +00:00
}
function limit1 ( $query , $where ) {
return " $query $where " ;
}
function db_collation ( $db , $collations ) {
2010-05-17 16:10:04 +00:00
global $connection ;
return $connection -> result ( " SELECT value FROM nls_database_parameters WHERE parameter = 'NLS_CHARACTERSET' " ); //! respect $db
2010-05-14 16:37:06 +00:00
}
function engines () {
return array ();
}
function logged_user () {
global $connection ;
return $connection -> result ( " SELECT USER FROM DUAL " );
}
function tables_list () {
2010-10-13 16:04:40 +00:00
return get_key_vals ( " SELECT table_name, 'table' FROM all_tables WHERE tablespace_name = " . q ( DB ) . "
2010-05-27 09:53:40 +00:00
UNION SELECT view_name , 'view' FROM user_views "
); //! views don't have schema
2010-05-14 16:37:06 +00:00
}
function count_tables ( $databases ) {
return array ();
}
function table_status ( $name = " " ) {
$return = array ();
2010-10-13 16:04:40 +00:00
$search = q ( $name );
foreach ( get_rows ( 'SELECT table_name "Name", \'table\' "Engine" FROM all_tables WHERE tablespace_name = ' . q ( DB ) . ( $name != " " ? " AND table_name = $search " : " " ) . "
2010-05-27 09:53:40 +00:00
UNION SELECT view_name , 'view' FROM user_views " . ( $name != " " ? " WHERE view_name = $search " : " " )
2010-10-13 15:53:59 +00:00
) as $row ) {
2010-05-14 16:37:06 +00:00
if ( $name != " " ) {
return $row ;
}
$return [ $row [ " Name " ]] = $row ;
}
return $return ;
}
2010-05-27 11:31:08 +00:00
function is_view ( $table_status ) {
return $table_status [ " Engine " ] == " view " ;
}
2010-05-14 16:37:06 +00:00
function fk_support ( $table_status ) {
2010-05-20 15:35:30 +00:00
return true ;
2010-05-14 16:37:06 +00:00
}
2010-11-11 09:47:32 +00:00
function fields ( $table ) {
2010-05-14 16:37:06 +00:00
$return = array ();
2010-10-13 16:04:40 +00:00
foreach ( get_rows ( " SELECT * FROM all_tab_columns WHERE table_name = " . q ( $table ) . " ORDER BY column_id " ) as $row ) {
2010-10-13 15:53:59 +00:00
$type = $row [ " DATA_TYPE " ];
$length = " $row[DATA_PRECISION] , $row[DATA_SCALE] " ;
if ( $length == " , " ) {
$length = $row [ " DATA_LENGTH " ];
} //! int
$return [ $row [ " COLUMN_NAME " ]] = array (
" field " => $row [ " COLUMN_NAME " ],
" full_type " => $type . ( $length ? " ( $length ) " : " " ),
" type " => strtolower ( $type ),
" length " => $length ,
" default " => $row [ " DATA_DEFAULT " ],
" null " => ( $row [ " NULLABLE " ] == " Y " ),
//! "auto_increment" => false,
//! "collation" => $row["CHARACTER_SET_NAME"],
" privileges " => array ( " insert " => 1 , " select " => 1 , " update " => 1 ),
//! "comment" => $row["Comment"],
//! "primary" => ($row["Key"] == "PRI"),
);
2010-05-14 16:37:06 +00:00
}
return $return ;
}
function indexes ( $table , $connection2 = null ) {
2011-05-06 16:04:03 +00:00
$return = array ();
foreach ( get_rows ( " SELECT uic.*, uc.constraint_type
FROM user_ind_columns uic
LEFT JOIN user_constraints uc ON uic . index_name = uc . constraint_name AND uic . table_name = uc . table_name
WHERE uic . table_name = " . q( $table ) . "
ORDER BY uc . constraint_type , uic . column_position " , $connection2 ) as $row ) {
$return [ $row [ " INDEX_NAME " ]][ " type " ] = ( $row [ " CONSTRAINT_TYPE " ] == " P " ? " PRIMARY " : ( $row [ " CONSTRAINT_TYPE " ] == " U " ? " UNIQUE " : " INDEX " ));
$return [ $row [ " INDEX_NAME " ]][ " columns " ][] = $row [ " COLUMN_NAME " ];
$return [ $row [ " INDEX_NAME " ]][ " lengths " ][] = ( $row [ " CHAR_LENGTH " ] && $row [ " CHAR_LENGTH " ] != $row [ " COLUMN_LENGTH " ] ? $row [ " CHAR_LENGTH " ] : null );
}
return $return ;
2010-05-14 16:37:06 +00:00
}
2010-05-27 09:53:40 +00:00
function view ( $name ) {
2010-10-13 16:04:40 +00:00
$rows = get_rows ( 'SELECT text "select" FROM user_views WHERE view_name = ' . q ( $name ));
2010-10-13 15:53:59 +00:00
return reset ( $rows );
2010-05-27 09:53:40 +00:00
}
2010-05-14 16:37:06 +00:00
function collations () {
return array (); //!
}
function information_schema ( $db ) {
return false ;
}
function error () {
global $connection ;
return h ( $connection -> error ); //! highlight sqltext from offset
}
function exact_value ( $val ) {
2010-10-13 16:04:40 +00:00
return q ( $val );
2010-05-14 16:37:06 +00:00
}
function explain ( $connection , $query ) {
2010-07-15 14:21:27 +00:00
$connection -> query ( " EXPLAIN PLAN FOR $query " );
return $connection -> query ( " SELECT * FROM plan_table " );
2010-05-14 16:37:06 +00:00
}
2011-07-29 15:08:06 +00:00
function found_rows ( $table_status , $where ) {
}
2010-05-17 16:10:04 +00:00
function alter_table ( $table , $name , $fields , $foreign , $comment , $engine , $collation , $auto_increment , $partitioning ) {
$alter = $drop = array ();
foreach ( $fields as $field ) {
$val = $field [ 1 ];
if ( $val && $field [ 0 ] != " " && idf_escape ( $field [ 0 ]) != $val [ 0 ]) {
2010-05-20 15:35:30 +00:00
queries ( " ALTER TABLE " . table ( $table ) . " RENAME COLUMN " . idf_escape ( $field [ 0 ]) . " TO $val[0] " );
2010-05-17 16:10:04 +00:00
}
if ( $val ) {
$alter [] = ( $table != " " ? ( $field [ 0 ] != " " ? " MODIFY ( " : " ADD ( " ) : " " ) . implode ( $val ) . ( $table != " " ? " ) " : " " ); //! error with name change only
} else {
$drop [] = idf_escape ( $field [ 0 ]);
}
}
if ( $table == " " ) {
return queries ( " CREATE TABLE " . table ( $name ) . " ( \n " . implode ( " , \n " , $alter ) . " \n ) " );
}
2010-05-20 15:35:30 +00:00
return ( ! $alter || queries ( " ALTER TABLE " . table ( $table ) . " \n " . implode ( " \n " , $alter )))
&& ( ! $drop || queries ( " ALTER TABLE " . table ( $table ) . " DROP ( " . implode ( " , " , $drop ) . " ) " ))
&& ( $table == $name || queries ( " ALTER TABLE " . table ( $table ) . " RENAME TO " . table ( $name )))
2010-05-17 16:10:04 +00:00
;
2010-05-14 16:37:06 +00:00
}
2010-05-17 16:10:04 +00:00
2010-05-20 15:35:30 +00:00
function foreign_keys ( $table ) {
return array (); //!
}
2010-05-14 16:37:06 +00:00
function truncate_tables ( $tables ) {
2010-05-17 16:18:32 +00:00
return apply_queries ( " TRUNCATE TABLE " , $tables );
2010-05-14 16:37:06 +00:00
}
function drop_views ( $views ) {
2010-05-17 16:18:32 +00:00
return apply_queries ( " DROP VIEW " , $views );
2010-05-14 16:37:06 +00:00
}
function drop_tables ( $tables ) {
2010-05-17 16:18:32 +00:00
return apply_queries ( " DROP TABLE " , $tables );
2010-05-14 16:37:06 +00:00
}
function begin () {
return true ; // automatic start
}
function insert_into ( $table , $set ) {
return queries ( " INSERT INTO " . table ( $table ) . " ( " . implode ( " , " , array_keys ( $set )) . " ) \n VALUES ( " . implode ( " , " , $set ) . " ) " ); //! no columns
}
function last_id () {
return 0 ; //!
}
function schemas () {
2012-05-10 14:13:20 +00:00
return get_vals ( " SELECT DISTINCT owner FROM dba_segments WHERE owner IN (SELECT username FROM dba_users WHERE default_tablespace NOT IN ('SYSTEM','SYSAUX')) " );
2010-05-14 16:37:06 +00:00
}
function get_schema () {
2012-05-10 14:13:20 +00:00
global $connection ;
return $connection -> result ( " SELECT sys_context('USERENV', 'SESSION_USER') FROM dual " );
2010-05-14 16:37:06 +00:00
}
function set_schema ( $scheme ) {
2012-05-10 14:13:20 +00:00
global $connection ;
return $connection -> query ( " ALTER SESSION SET CURRENT_SCHEMA = " . idf_escape ( $scheme ));
2010-05-14 16:37:06 +00:00
}
2010-07-15 14:20:20 +00:00
function show_variables () {
return get_key_vals ( 'SELECT name, display_value FROM v$parameter' );
}
function show_status () {
2010-10-13 15:53:59 +00:00
$rows = get_rows ( 'SELECT * FROM v$instance' );
return reset ( $rows );
2010-07-15 14:20:20 +00:00
}
2010-05-14 16:37:06 +00:00
function support ( $feature ) {
2012-05-10 14:13:20 +00:00
return ereg ( " view|scheme|drop_col|variables|status " , $feature ); //!
2010-05-14 16:37:06 +00:00
}
$jush = " oracle " ;
$types = array ();
$structured_types = array ();
foreach ( array (
lang ( 'Numbers' ) => array ( " number " => 38 , " binary_float " => 12 , " binary_double " => 21 ),
2010-05-17 16:10:04 +00:00
lang ( 'Date and time' ) => array ( " date " => 10 , " timestamp " => 29 , " interval year " => 12 , " interval day " => 28 ), //! year(), day() to second()
2010-05-14 16:37:06 +00:00
lang ( 'Strings' ) => array ( " char " => 2000 , " varchar2 " => 4000 , " nchar " => 2000 , " nvarchar2 " => 4000 , " clob " => 4294967295 , " nclob " => 4294967295 ),
lang ( 'Binary' ) => array ( " raw " => 2000 , " long raw " => 2147483648 , " blob " => 4294967295 , " bfile " => 4294967296 ),
) as $key => $val ) {
$types += $val ;
$structured_types [ $key ] = array_keys ( $val );
}
$unsigned = array ();
2011-01-30 01:07:27 +00:00
$operators = array ( " = " , " < " , " > " , " <= " , " >= " , " != " , " LIKE " , " LIKE %% " , " IN " , " IS NULL " , " NOT LIKE " , " NOT REGEXP " , " NOT IN " , " IS NOT NULL " , " " );
2010-05-14 16:37:06 +00:00
$functions = array ( " length " , " lower " , " round " , " upper " );
$grouping = array ( " avg " , " count " , " count distinct " , " max " , " min " , " sum " );
$edit_functions = array (
array ( //! no parentheses
" date " => " current_date " ,
" timestamp " => " current_timestamp " ,
), array (
" number|float|double " => " +/- " ,
" date|timestamp " => " + interval/- interval " ,
" char|clob " => " || " ,
)
);
}