]> git.joonet.de Git - adminer.git/commitdiff
MongoDB: auto_increment
authorJakub Vrana <jakub@vrana.cz>
Sun, 12 Jan 2014 01:27:04 +0000 (17:27 -0800)
committerJakub Vrana <jakub@vrana.cz>
Sun, 12 Jan 2014 01:27:04 +0000 (17:27 -0800)
adminer/drivers/mongo.inc.php
adminer/drivers/simpledb.inc.php
adminer/edit.inc.php
adminer/include/functions.inc.php

index 874bf10007b2282bd2a9511138d922448a810e55..9d9fe222c65c4e87571c2bc2056fc76660895aa1 100644 (file)
@@ -7,7 +7,7 @@ if (isset($_GET["mongo"])) {
 
        if (class_exists('MongoDB')) {
                class Min_DB {
-                       var $extension = "Mongo", $error, $_link, $_db;
+                       var $extension = "Mongo", $error, $last_id, $_link, $_db;
 
                        function connect($server, $username, $password) {
                                global $adminer;
@@ -114,6 +114,8 @@ if (isset($_GET["mongo"])) {
 
 
        class Min_Driver extends Min_SQL {
+               public $primary = "_id";
+               
                function select($table, $select, $where, $group, $order, $limit, $page, $print = false) {
                        $select = ($select == array("*")
                                ? array()
@@ -137,6 +139,7 @@ if (isset($_GET["mongo"])) {
                                $return = $this->_conn->_db->selectCollection($table)->insert($set);
                                $this->_conn->errno = $return['code'];
                                $this->_conn->error = $return['err'];
+                               $this->_conn->last_id = $set['_id'];
                                return !$return['err'];
                        } catch (Exception $ex) {
                                $this->_conn->error = $ex->getMessage();
@@ -302,6 +305,11 @@ if (isset($_GET["mongo"])) {
                return true;
        }
 
+       function last_id() {
+               global $connection;
+               return $connection->last_id;
+       }
+
        function table($idf) {
                return $idf;
        }
index 231791d3c8366583356cd26993dfa2f3c5229c93..fec66c00723e7a0fdd1d3bb5806eb4030411557e 100644 (file)
@@ -118,6 +118,7 @@ if (isset($_GET["simpledb"])) {
 
 
        class Min_Driver extends Min_SQL {
+               public $primary = "itemName()";
 
                function _chunkRequest($ids, $action, $params, $expand = array()) {
                        global $connection;
index d1ac2e9b1befa32373c5aca01402f29d992dd12c..50a75e34513242028567dfea22e5ba80146605ff 100644 (file)
@@ -98,14 +98,11 @@ if ($_POST["save"]) {
 }
 
 if (!support("table") && !$fields) {
-       $id = ($jush == "mongo" ? "_id" : "itemName()"); // simpledb
        if (!$where) { // insert
                $result = $driver->select($TABLE, array("*"), $where, array("*"), array(), 1, 0);
-               if ($result) {
-                       $row = $result->fetch_assoc();
-               }
+               $row = ($result ? $result->fetch_assoc() : false);
                if (!$row) {
-                       $row = array($id => "");
+                       $row = array($driver->primary => "");
                }
        }
        if ($row) {
@@ -113,7 +110,7 @@ if (!support("table") && !$fields) {
                        if (!$where) {
                                $row[$key] = null;
                        }
-                       $fields[$key] = array("field" => $key, "null" => ($key != $id), "auto_increment" => ($key == $id));
+                       $fields[$key] = array("field" => $key, "null" => ($key != $driver->primary), "auto_increment" => ($key == $driver->primary));
                }
        }
 }
index ed5705418185bddfaf5d0a46a73a9b78670a5d3f..513023948f957aa58561e9060ef9981a4fd22f8e 100644 (file)
@@ -907,6 +907,7 @@ function process_input($field) {
 * @return array
 */
 function fields_from_edit() {
+       global $driver;
        $return = array();
        foreach ((array) $_POST["field_keys"] as $key => $val) {
                if ($val != "") {
@@ -917,7 +918,12 @@ function fields_from_edit() {
        }
        foreach ((array) $_POST["fields"] as $key => $val) {
                $name = bracket_escape($key, 1); // 1 - back
-               $return[$name] = array("field" => $name, "privileges" => array("insert" => 1, "update" => 1), "null" => 1);
+               $return[$name] = array(
+                       "field" => $name,
+                       "privileges" => array("insert" => 1, "update" => 1),
+                       "null" => 1,
+                       "auto_increment" => ($key == $driver->primary),
+               );
        }
        return $return;
 }