e6cb0000f531689dbbeee33bf58d4c5e451f894f
[mtweb] / mw / env / modules / mw_env_data.php
1 <?php
2
3   class mw_env_data extends mw_env{
4
5     var $data;
6
7     function set_data(&$data){
8       $this->data = &$data;
9     }
10
11     function data(){
12       return isset($this->data) ? $this->data : false;
13     }
14
15   }
16
17   class mw_data extends empty_class{
18
19     function call_default($inst, $method_name, $arguments){
20       return $this->call_data_auto_crud($method_name, $arguments);
21     }
22
23   }
24
25   class mw_sgbd{
26
27     var $sgbd_impl;
28     var $env;
29
30     function mw_sgbd($sgbd_impl, $env){
31       $this->sgbd_impl = $sgbd_impl;
32       $this->env = $env;
33     }
34
35     function extention_ok(){
36       return $this->sgbd_impl->extention_ok($this->env);
37     }
38
39     function authentication_required(){
40       return $this->sgbd_impl->authentication_required();
41     }
42
43     function connect($host, $base, $user, $password){
44       return $this->sgbd_impl->connect($host, $base, $user, $password);
45     }
46
47     function select_db($db_name){
48       return $this->sgbd_impl->select_db($db_name);
49     }
50
51     # ---------------------------------------------------------------------------------
52     #                                                                               SQL
53     #
54
55     function desc_table($table_name){
56       if(!method_exists($this->sgbd_impl, "desc_table")) return false;
57       return $this->sgbd_impl->desc_table(
58         ($prefix_codes = array_keys($this->env->bdd("table_prefix"))) ?
59           str_replace($prefix_codes, array_values($this->env->bdd("table_prefix")), $table_name)
60         : $table_name
61       );
62     }
63
64     function table_exists($table_name){
65       if(!method_exists($this->sgbd_impl, "table_exists")) return false;
66       return $this->sgbd_impl->table_exists(
67         ($prefix_codes = array_keys($this->env->bdd("table_prefix"))) ?
68           str_replace($prefix_codes, array_values($this->env->bdd("table_prefix")), $table_name)
69         : $table_name
70       );
71     }
72
73     function field_exists($table_name, $field_name){
74       if(!method_exists($this->sgbd_impl, "field_exists")) return false;
75       return $this->sgbd_impl->field_exists(
76         (
77           $prefix_codes = array_keys($this->env->bdd("table_prefix"))) ?
78           str_replace($prefix_codes, array_values($this->env->bdd("table_prefix")), $table_name)
79         : $table_name,
80         $field_name
81       );
82     }
83
84     function query($sql){
85       if(!method_exists($this->sgbd_impl, "query")) return false;
86       return $this->sgbd_impl->query(
87         ($prefix_codes = array_keys($this->env->bdd("table_prefix"))) ?
88           str_replace($prefix_codes, array_values($this->env->bdd("table_prefix")), $sql)
89         : $sql
90       );
91     }
92
93     function insert_id(){
94       if(!method_exists($this->sgbd_impl, "insert_id")) return false;
95       return $this->sgbd_impl->insert_id();
96     }
97
98     function fetch_assoc($rst){
99       if(!method_exists($this->sgbd_impl, "fetch_assoc")) return false;
100       return $this->sgbd_impl->fetch_assoc($rst);
101     }
102
103     function free_result($rst){
104       if(!method_exists($this->sgbd_impl, "")) return false;
105       return $this->sgbd_impl->free_result($rst);
106     }
107
108     function close(){
109       if(!method_exists($this->sgbd_impl, "")) return false;
110       return $this->sgbd_impl->close();
111     }
112
113     # ---------------------------------------------------------------------------------
114     #                                                                               XML
115     #
116
117     function data_exists($data_path){
118       if(!method_exists($this->sgbd_impl, "data_exists")) return false;
119       return $this->sgbd_impl->data_exists($data_path);
120     }
121
122     function create_data($data_path){
123       if(!method_exists($this->sgbd_impl, "create_data")) return false;
124       return $this->sgbd_impl->create_data($data_path);
125     }
126
127     function get_data($data_path, $data_id){
128       if(!method_exists($this->sgbd_impl, "get_data")) return false;
129       return $this->sgbd_impl->get_data($data_path, $data_id);
130     }
131
132     function open_data($data_path, $FETCH = true){
133       if(!method_exists($this->sgbd_impl, "open_data")) return false;
134       return $this->sgbd_impl->open_data($data_path, $FETCH);
135     }
136
137     function fetch_data($dh){
138       if(!method_exists($this->sgbd_impl, "fetch_data")) return false;
139       return $this->sgbd_impl->fetch_data($dh);
140     }
141
142     function add_data($data_path, $data, $index = null){
143       if(!method_exists($this->sgbd_impl, "add_data")) return false;
144       return $this->sgbd_impl->add_data($data_path, $data, $index);
145     }
146
147     function last_index($dh){
148       if(!method_exists($this->sgbd_impl, "last_index")) return false;
149       return $this->sgbd_impl->last_index($dh);
150     }
151
152     function set_data($data_path, $data_id, $data){
153       if(!method_exists($this->sgbd_impl, "set_data")) return false;
154       return $this->sgbd_impl->set_data($data_path, $data_id, $data);
155     }
156
157     function del_data($data_path, $data_id){
158       if(!method_exists($this->sgbd_impl, "del_data")) return false;
159       return $this->sgbd_impl->del_data($data_path, $data_id);
160     }
161
162     function close_data($dh){
163       if(!method_exists($this->sgbd_impl, "close_data")) return false;
164       return $this->sgbd_impl->close_data($dh);
165     }
166
167     function remove_data($data_path){
168       if(!method_exists($this->sgbd_impl, "remove_data")) return false;
169       return $this->sgbd_impl->remove_data($data_path);
170     }
171
172   }
173
174 ?>