source: sandbox/2.3-MailArchiver/calendar/js/dhtmlx/codebase/connector/db_oracle.php @ 6779

Revision 6779, 2.4 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado Expresso(branch 2.3) integrado ao MailArchiver?.

Line 
1<?php
2require_once("db_common.php");
3/*! Implementation of DataWrapper for Oracle
4**/
5class OracleDBDataWrapper extends DBDataWrapper{
6        private $last_id=""; //id of previously inserted record
7        private $insert_operation=false; //flag of insert operation
8       
9        public function query($sql){
10                LogMaster::log($sql);
11                $stm = oci_parse($this->connection,$sql);
12                if ($stm===false) throw new Exception("Oracle - sql parsing failed\n".oci_error($this->connection));
13               
14                $out = array(0=>null);
15                if($this->insert_operation){
16                        oci_bind_by_name($stm,":outID",$out[0],999);
17                        $this->insert_operation=false;
18                }
19               
20               
21                $mode = ($this->is_record_transaction() || $this->is_global_transaction())?OCI_DEFAULT:OCI_COMMIT_ON_SUCCESS;
22                $res=oci_execute($stm,$mode);
23                if ($res===false) throw new Exception("Oracle - sql execution failed\n".oci_error($this->connection));
24               
25                $this->last_id=$out[0];
26               
27                return $stm;
28        }
29       
30        public function get_next($res){
31                $data = oci_fetch_assoc($res);
32                if (array_key_exists("VALUE",$data))
33                        $data["value"]=$data["VALUE"];
34                return $data;
35        }
36       
37        protected function get_new_id(){
38                /*
39                Oracle doesn't support identity or auto-increment fields
40                Insert SQL returns new ID value, which stored in last_id field
41                */
42                return $this->last_id;
43        }
44       
45        protected function insert_query($data,$request){
46                $sql = parent::insert_query($data,$request);
47                $this->insert_operation=true;
48                return $sql." returning ".$this->config->id["db_name"]." into :outID";
49        }               
50       
51        protected function select_query($select,$from,$where,$sort,$start,$count){
52                $sql="SELECT ".$select." FROM ".$from;
53                if ($where) $sql.=" WHERE ".$where;
54                if ($sort) $sql.=" ORDER BY ".$sort;
55                if ($start || $count)
56                        $sql="SELECT * FROM ( select /*+ FIRST_ROWS(".$count.")*/dhx_table.*, ROWNUM rnum FROM (".$sql.") dhx_table where ROWNUM <= ".($count+$start)." ) where rnum >".$start;
57                return $sql;
58        }
59
60        public function escape($data){
61                /*
62                as far as I can see the only way to escape data is by using oci_bind_by_name
63                while it is neat solution in common case, it conflicts with existing SQL building logic
64                fallback to simple escaping
65                */
66                return str_replace("'","''",$data);
67        }
68       
69        public function begin_transaction(){
70                //auto-start of transaction
71        }
72        public function commit_transaction(){
73                oci_commit($this->connection);
74        }
75        public function rollback_transaction(){
76                oci_rollback($this->connection);
77        }       
78}
79?>
Note: See TracBrowser for help on using the repository browser.