upgrade 0.11.2 pour XML, MySql et SQLite
[mtweb] / mw / app / data / impl / mw_mysql.php
index 3d146c4..4f8e41d 100644 (file)
       return $desc;
     }
 
-    function table_exists($table){\r
+    function table_exists($table_name){\r
       if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password);\r
-      $rst = $this->query("SHOW TABLES");\r
-      while($v_rst = mysql_fetch_array($rst)){\r
-        if(strcmp($v_rst[0], $table) == 0) return true;\r
-      }\r
-      mysql_free_result($rst);\r
-      return false;\r
+      $EXISTS = false;
+      try{
+        $rst = $this->query("SHOW TABLES");
+        while($v_rst = mysql_fetch_row($rst)){\r
+          if($v_rst[0] == $table_name){
+            $EXISTS = true;
+            break;
+          }\r
+        }\r
+        $this->free_result($rst);
+      }
+      catch(Exception $e){
+        throw new Exception($this->exception_out("Impossible de savoir si la table existe"));
+      }
+      return $EXISTS;
     }
 
     function field_exists($table_name, $field_name){
-      if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password);
-      $sql = "SHOW COLUMNS FROM `".$table_name."` LIKE ".$field_name;
-      $rst = $this->query($sql);
-      $exists = false;
-      $v_rst = $this->fetch_assoc($rst);
-      if($v_rst) $exists = true;
-      $this->free_result($rst);
-      return $exists;
+      if(!$this->link) $this->connect($this->host, $this->base, $this->user, $this->password);\r
+      if(!($desc = $this->desc_table($table_name))){
+        throw new Exception($this->exception_out("Impossible de lire la description de la table"));
+      }
+      $EXISTS = false;
+      foreach($desc["attributs"] as $attribut_name => $attribut){
+        if($field_name == $attribut_name){
+          $EXISTS = true;
+          break;
+        }
+      }
+      return $EXISTS;
     }
 
     function query($query_string){\r