implementation sgbd herite de mw_sgbd
[mtweb] / mw / env / modules / mw_env_data.php
index e5c3c4c..3cb19d1 100644 (file)
 
   }
 
+  // -------------------------------------------------------------------------------------------
+  //                                                                               class mw_data
+  //
+
   class mw_data extends empty_class{
 
     public function call_default($inst, $method_name, $arguments){
 
   }
 
-  class mw_sgbd{
+  // -------------------------------------------------------------------------------------------
+  //                                                                               class mw_sgbd
+  //
 
-    public $sgbd_impl;
-    public $env;
+  abstract class mw_sgbd{
 
-    public function __construct($sgbd_impl, $env){
-      $this->sgbd_impl = $sgbd_impl;
+    public $env;
+    public $link;
+    public $host;
+    public $base;
+    public $user;
+    public $password;
+    public $EXTENTION_OK;
+
+    public function __construct($env, $params = array()){
       $this->env = $env;
+      $default_params = $this->default_params();
+      $params = $this->prepare_params($params);
+      $this->host = isset($params["host"]) ? $params["host"] : $default_params["host"];
+      $this->base = isset($params["base"]) ? $params["base"] : $default_params["base"];
+      $this->user = isset($params["user"]) ? $params["user"] : $default_params["user"];
+      $this->password = isset($params["password"]) ? $params["password"] : $default_params["password"];
+      $this->EXTENTION_OK = $this->validate_extention();
     }
 
-    public function extention_ok(){
-      return $this->sgbd_impl->extention_ok($this->env);
+    public function name(){
+      return "";
     }
 
-    public function authentication_required(){
-      return $this->sgbd_impl->authentication_required();
+    public function default_params(){
+      return array(
+        "host" => "",
+        "base" => "",
+        "user" => "",
+        "password" => ""
+      );
     }
 
-    public function connect($host, $base, $user, $password){
-      return $this->sgbd_impl->connect($host, $base, $user, $password);
+    public function prepare_params($params){
+      return $params;
     }
 
-    public function select_db($db_name){
-      return $this->sgbd_impl->select_db($db_name);
+    public function validate_extention(){
+      return false;
     }
 
-    # ---------------------------------------------------------------------------------
-    #                                                                               SQL
-    #
-
-    public function desc_table($table_name){
-      if(!method_exists($this->sgbd_impl, "desc_table")) return false;
-      return $this->sgbd_impl->desc_table(
-        ($prefix_codes = array_keys($this->env->bdd("table_prefix"))) ?
-          str_replace($prefix_codes, array_values($this->env->bdd("table_prefix")), $table_name)
-        : $table_name
-      );
+    public function authentication_required(){
+      return false;
     }
 
-    public function table_exists($table_name){
-      if(!method_exists($this->sgbd_impl, "table_exists")) return false;
-      return $this->sgbd_impl->table_exists(
-        ($prefix_codes = array_keys($this->env->bdd("table_prefix"))) ?
-          str_replace($prefix_codes, array_values($this->env->bdd("table_prefix")), $table_name)
-        : $table_name
-      );
+    public function get_link(){
+      return $this->link;
     }
 
-    public function field_exists($table_name, $field_name){
-      if(!method_exists($this->sgbd_impl, "field_exists")) return false;
-      return $this->sgbd_impl->field_exists(
-        (
-          $prefix_codes = array_keys($this->env->bdd("table_prefix"))) ?
-          str_replace($prefix_codes, array_values($this->env->bdd("table_prefix")), $table_name)
-        : $table_name,
-        $field_name
-      );
+    public function extention_ok(){
+      return $this->EXTENTION_OK;
     }
 
-    public function query($sql){
-      if(!method_exists($this->sgbd_impl, "query")) return false;
-      return $this->sgbd_impl->query(
+    public function replace_prefixes($content){
+      return (
         ($prefix_codes = array_keys($this->env->bdd("table_prefix"))) ?
-          str_replace($prefix_codes, array_values($this->env->bdd("table_prefix")), $sql)
-        : $sql
+          str_replace($prefix_codes, array_values($this->env->bdd("table_prefix")), $content)
+        : $content
       );
     }
 
-    public function insert_id(){
-      if(!method_exists($this->sgbd_impl, "insert_id")) return false;
-      return $this->sgbd_impl->insert_id();
-    }
-
-    public function fetch_assoc($rst){
-      if(!method_exists($this->sgbd_impl, "fetch_assoc")) return false;
-      return $this->sgbd_impl->fetch_assoc($rst);
-    }
-
-    public function free_result($rst){
-      if(!method_exists($this->sgbd_impl, "")) return false;
-      return $this->sgbd_impl->free_result($rst);
-    }
-
-    public function close(){
-      if(!method_exists($this->sgbd_impl, "")) return false;
-      return $this->sgbd_impl->close();
-    }
-
-    # ---------------------------------------------------------------------------------
-    #                                                                               XML
-    #
-
-    public function data_exists($data_path){
-      if(!method_exists($this->sgbd_impl, "data_exists")) return false;
-      return $this->sgbd_impl->data_exists($data_path);
-    }
-
-    public function create_data($data_path){
-      if(!method_exists($this->sgbd_impl, "create_data")) return false;
-      return $this->sgbd_impl->create_data($data_path);
-    }
-
-    public function get_data($data_path, $data_id){
-      if(!method_exists($this->sgbd_impl, "get_data")) return false;
-      return $this->sgbd_impl->get_data($data_path, $data_id);
-    }
-
-    public function open_data($data_path, $FETCH = true){
-      if(!method_exists($this->sgbd_impl, "open_data")) return false;
-      return $this->sgbd_impl->open_data($data_path, $FETCH);
-    }
-
-    public function fetch_data($dh){
-      if(!method_exists($this->sgbd_impl, "fetch_data")) return false;
-      return $this->sgbd_impl->fetch_data($dh);
-    }
-
-    public function add_data($data_path, $data, $index = null){
-      if(!method_exists($this->sgbd_impl, "add_data")) return false;
-      return $this->sgbd_impl->add_data($data_path, $data, $index);
-    }
-
-    public function last_index($dh){
-      if(!method_exists($this->sgbd_impl, "last_index")) return false;
-      return $this->sgbd_impl->last_index($dh);
-    }
-
-    public function set_data($data_path, $data_id, $data){
-      if(!method_exists($this->sgbd_impl, "set_data")) return false;
-      return $this->sgbd_impl->set_data($data_path, $data_id, $data);
-    }
-
-    public function del_data($data_path, $data_id){
-      if(!method_exists($this->sgbd_impl, "del_data")) return false;
-      return $this->sgbd_impl->del_data($data_path, $data_id);
-    }
-
-    public function close_data($dh){
-      if(!method_exists($this->sgbd_impl, "close_data")) return false;
-      return $this->sgbd_impl->close_data($dh);
-    }
-
-    public function remove_data($data_path){
-      if(!method_exists($this->sgbd_impl, "remove_data")) return false;
-      return $this->sgbd_impl->remove_data($data_path);
-    }
-
   }