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

Revision 6779, 1.9 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 PostgreSQL
4**/
5class PostgreDBDataWrapper extends DBDataWrapper{
6        public function query($sql){
7                LogMaster::log($sql);
8               
9                $res=pg_query($this->connection,$sql);
10                if ($res===false) throw new Exception("Postgre - sql execution failed\n".pg_last_error($this->connection));
11               
12                return $res;
13        }
14       
15        protected function select_query($select,$from,$where,$sort,$start,$count){
16                $sql="SELECT ".$select." FROM ".$from;
17                if ($where) $sql.=" WHERE ".$where;
18                if ($sort) $sql.=" ORDER BY ".$sort;
19                if ($start || $count)
20                        $sql.=" OFFSET ".$start." LIMIT ".$count;
21                return $sql;
22        }
23               
24        public function get_next($res){
25                return pg_fetch_assoc($res);
26        }
27       
28        protected function get_new_id(){
29                $res  = pg_query( $this->connection, "SELECT LASTVAL() AS seq");
30                $data = pg_fetch_assoc($res);
31                                pg_free_result($res);
32                return $data['seq'];
33        }
34       
35        public function escape($data){
36                //need to use oci_bind_by_name
37                return pg_escape_string($this->connection,$data);
38        }
39
40        public function tables_list() {
41                $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'";
42                $res = pg_query($this->connection, $sql);
43                $tables = array();
44                while ($table = pg_fetch_assoc($res)) {
45                        $tables[] = $table['table_name'];
46                }
47                return $tables;
48        }
49
50        public function fields_list($table) {
51                $sql = "SELECT * FROM information_schema.constraint_column_usage";
52                $result = pg_query($this->connection, $sql);
53                $field = pg_fetch_assoc($result);
54                $id = $field['column_name'];
55
56                $sql = "SELECT * FROM information_schema.columns WHERE table_name ='".$table."';";
57                $result = pg_query($this->connection, $sql);
58                $fields = array();
59        $id = "";
60                while ($field = pg_fetch_assoc($result)) {
61                    $fields[] = $field["column_name"];
62                }
63                return array('fields' => $fields, 'key' => $id );
64        }
65}
66?>
Note: See TracBrowser for help on using the repository browser.