]> git.joonet.de Git - adminer.git/commitdiff
ElasticDB: Prepare for insert
authorJakub Vrana <jakub@vrana.cz>
Thu, 9 Jan 2014 08:38:48 +0000 (00:38 -0800)
committerJakub Vrana <jakub@vrana.cz>
Thu, 9 Jan 2014 08:46:12 +0000 (00:46 -0800)
adminer/drivers/mongo.inc.php
adminer/edit.inc.php

index ccee27609741b44a51d592dd1245a48fed531748..c3a0dce9dd097096785cc5c5010928d63e7665c5 100644 (file)
@@ -115,7 +115,6 @@ if (isset($_GET["mongo"])) {
 
        class Min_Driver extends Min_SQL {
                function select($table, $select, $where, $group, $order, $limit, $page, $print = false) {
-                       global $connection;
                        $select = ($select == array("*")
                                ? array()
                                : array_fill_keys($select, true)
@@ -125,13 +124,25 @@ if (isset($_GET["mongo"])) {
                                $val = preg_replace('~ DESC$~', '', $val, 1, $count);
                                $sort[$val] = ($count ? -1 : 1);
                        }
-                       return new Min_Result(iterator_to_array($connection->_db->selectCollection($table)
+                       return new Min_Result(iterator_to_array($this->_conn->_db->selectCollection($table)
                                ->find(array(), $select)
                                ->sort($sort)
                                ->limit(+$limit)
                                ->skip($page * $limit)
                        ));
                }
+               
+               function insert($table, $set) {
+                       try {
+                               $return = $this->_conn->_db->selectCollection($table)->insert($set);
+                               $this->_conn->errno = $return['code'];
+                               $this->_conn->error = $return['err'];
+                               return !$return['err'];
+                       } catch (Exception $ex) {
+                               $this->_conn->error = $ex->getMessage();
+                               return false;
+                       }
+               }
        }
 
 
index 6e3037298f4760bdea7653317f46cbbd5dad5f29..116f12345fb877f85e81f278f06545b41ee2c7d3 100644 (file)
@@ -98,18 +98,17 @@ if ($_POST["save"]) {
 }
 
 if (!support("table") && !$fields) {
+       $id = ($jush == "mongo" ? "_id" : "itemName()"); // simpledb
        if (!$where) { // insert
-               $row = reset(get_rows("SELECT * FROM " . table($TABLE) . " LIMIT 1"));
-               if (!$row) {
-                       $row = array("itemName()" => "");
-               }
+               $row = $driver->select($TABLE, array("*"), $where, array("*"), array(), 1, 0);
+               $row = ($row ? $row->fetch_assoc() : array($id => ""));
        }
        if ($row) {
                foreach ($row as $key => $val) {
                        if (!$where) {
                                $row[$key] = null;
                        }
-                       $fields[$key] = array("field" => $key, "null" => ($key != "itemName()"), "auto_increment" => ($key == "itemName()"));
+                       $fields[$key] = array("field" => $key, "null" => ($key != $id), "auto_increment" => ($key == $id));
                }
        }
 }