MongoDB: auto_increment
This commit is contained in:
parent
48848de529
commit
9824540ed8
|
@ -7,7 +7,7 @@ if (isset($_GET["mongo"])) {
|
||||||
|
|
||||||
if (class_exists('MongoDB')) {
|
if (class_exists('MongoDB')) {
|
||||||
class Min_DB {
|
class Min_DB {
|
||||||
var $extension = "Mongo", $error, $_link, $_db;
|
var $extension = "Mongo", $error, $last_id, $_link, $_db;
|
||||||
|
|
||||||
function connect($server, $username, $password) {
|
function connect($server, $username, $password) {
|
||||||
global $adminer;
|
global $adminer;
|
||||||
|
@ -114,6 +114,8 @@ if (isset($_GET["mongo"])) {
|
||||||
|
|
||||||
|
|
||||||
class Min_Driver extends Min_SQL {
|
class Min_Driver extends Min_SQL {
|
||||||
|
public $primary = "_id";
|
||||||
|
|
||||||
function select($table, $select, $where, $group, $order, $limit, $page, $print = false) {
|
function select($table, $select, $where, $group, $order, $limit, $page, $print = false) {
|
||||||
$select = ($select == array("*")
|
$select = ($select == array("*")
|
||||||
? array()
|
? array()
|
||||||
|
@ -137,6 +139,7 @@ if (isset($_GET["mongo"])) {
|
||||||
$return = $this->_conn->_db->selectCollection($table)->insert($set);
|
$return = $this->_conn->_db->selectCollection($table)->insert($set);
|
||||||
$this->_conn->errno = $return['code'];
|
$this->_conn->errno = $return['code'];
|
||||||
$this->_conn->error = $return['err'];
|
$this->_conn->error = $return['err'];
|
||||||
|
$this->_conn->last_id = $set['_id'];
|
||||||
return !$return['err'];
|
return !$return['err'];
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
$this->_conn->error = $ex->getMessage();
|
$this->_conn->error = $ex->getMessage();
|
||||||
|
@ -302,6 +305,11 @@ if (isset($_GET["mongo"])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function last_id() {
|
||||||
|
global $connection;
|
||||||
|
return $connection->last_id;
|
||||||
|
}
|
||||||
|
|
||||||
function table($idf) {
|
function table($idf) {
|
||||||
return $idf;
|
return $idf;
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,6 +118,7 @@ if (isset($_GET["simpledb"])) {
|
||||||
|
|
||||||
|
|
||||||
class Min_Driver extends Min_SQL {
|
class Min_Driver extends Min_SQL {
|
||||||
|
public $primary = "itemName()";
|
||||||
|
|
||||||
function _chunkRequest($ids, $action, $params, $expand = array()) {
|
function _chunkRequest($ids, $action, $params, $expand = array()) {
|
||||||
global $connection;
|
global $connection;
|
||||||
|
|
|
@ -98,14 +98,11 @@ if ($_POST["save"]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!support("table") && !$fields) {
|
if (!support("table") && !$fields) {
|
||||||
$id = ($jush == "mongo" ? "_id" : "itemName()"); // simpledb
|
|
||||||
if (!$where) { // insert
|
if (!$where) { // insert
|
||||||
$result = $driver->select($TABLE, array("*"), $where, array("*"), array(), 1, 0);
|
$result = $driver->select($TABLE, array("*"), $where, array("*"), array(), 1, 0);
|
||||||
if ($result) {
|
$row = ($result ? $result->fetch_assoc() : false);
|
||||||
$row = $result->fetch_assoc();
|
|
||||||
}
|
|
||||||
if (!$row) {
|
if (!$row) {
|
||||||
$row = array($id => "");
|
$row = array($driver->primary => "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($row) {
|
if ($row) {
|
||||||
|
@ -113,7 +110,7 @@ if (!support("table") && !$fields) {
|
||||||
if (!$where) {
|
if (!$where) {
|
||||||
$row[$key] = null;
|
$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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -907,6 +907,7 @@ function process_input($field) {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function fields_from_edit() {
|
function fields_from_edit() {
|
||||||
|
global $driver;
|
||||||
$return = array();
|
$return = array();
|
||||||
foreach ((array) $_POST["field_keys"] as $key => $val) {
|
foreach ((array) $_POST["field_keys"] as $key => $val) {
|
||||||
if ($val != "") {
|
if ($val != "") {
|
||||||
|
@ -917,7 +918,12 @@ function fields_from_edit() {
|
||||||
}
|
}
|
||||||
foreach ((array) $_POST["fields"] as $key => $val) {
|
foreach ((array) $_POST["fields"] as $key => $val) {
|
||||||
$name = bracket_escape($key, 1); // 1 - back
|
$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;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue