MongoDB: Improve select
This commit is contained in:
parent
39a68b9b14
commit
a7d475e3e7
|
@ -88,7 +88,7 @@ if (isset($_GET["elastic"])) {
|
|||
|
||||
class Min_Driver extends Min_SQL {
|
||||
|
||||
function select($table, $select, $where, $group, $order, $limit, $page) {
|
||||
function select($table, $select, $where, $group, $order, $limit, $page, $print = false) {
|
||||
global $adminer;
|
||||
$query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page);
|
||||
$data = array();
|
||||
|
@ -125,7 +125,9 @@ if (isset($_GET["elastic"])) {
|
|||
$data["query"]["filtered"]["query"] = array("match_all" => array());
|
||||
}
|
||||
}
|
||||
echo $adminer->selectQuery($query);
|
||||
if ($print) {
|
||||
echo $adminer->selectQuery("$query: " . print_r($data, true));
|
||||
}
|
||||
$search = $this->_conn->query($query, $data);
|
||||
if (!$search) {
|
||||
return false;
|
||||
|
|
|
@ -21,7 +21,7 @@ if (isset($_GET["mongo"])) {
|
|||
$options["db"] = $db;
|
||||
}
|
||||
try {
|
||||
$this->_link = new MongoClient("mongodb://$server", $options);
|
||||
$this->_link = @new MongoClient("mongodb://$server", $options);
|
||||
return true;
|
||||
} catch (Exception $ex) {
|
||||
$this->error = $ex->getMessage();
|
||||
|
@ -43,6 +43,10 @@ if (isset($_GET["mongo"])) {
|
|||
}
|
||||
}
|
||||
|
||||
function quote($string) {
|
||||
return $string;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Min_Result {
|
||||
|
@ -110,18 +114,23 @@ if (isset($_GET["mongo"])) {
|
|||
|
||||
|
||||
class Min_Driver extends Min_SQL {
|
||||
function select($table, $select, $where, $group, $order, $limit, $page) {
|
||||
function select($table, $select, $where, $group, $order, $limit, $page, $print = false) {
|
||||
global $connection;
|
||||
if ($select == array("*")) {
|
||||
$select = array();
|
||||
} else {
|
||||
$select = array_fill_keys($select, true);
|
||||
$select = ($select == array("*")
|
||||
? array()
|
||||
: array_fill_keys($select, true)
|
||||
);
|
||||
$sort = array();
|
||||
foreach ($order as $val) {
|
||||
$val = preg_replace('~ DESC$~', '', $val, 1, $count);
|
||||
$sort[$val] = ($count ? -1 : 1);
|
||||
}
|
||||
$return = array();
|
||||
foreach ($connection->_db->selectCollection($table)->find(array(), $select) as $val) {
|
||||
$return[] = $val;
|
||||
}
|
||||
return new Min_Result($return);
|
||||
return new Min_Result(iterator_to_array($connection->_db->selectCollection($table)
|
||||
->find(array(), $select)
|
||||
->sort($sort)
|
||||
->limit(+$limit)
|
||||
->skip($page * $limit)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,6 +244,10 @@ if (isset($_GET["mongo"])) {
|
|||
function convert_field($field) {
|
||||
}
|
||||
|
||||
function unconvert_field($field, $return) {
|
||||
return $return;
|
||||
}
|
||||
|
||||
function foreign_keys($table) {
|
||||
return array();
|
||||
}
|
||||
|
@ -247,7 +260,9 @@ if (isset($_GET["mongo"])) {
|
|||
}
|
||||
|
||||
function found_rows($table_status, $where) {
|
||||
return null;
|
||||
global $connection;
|
||||
//! don't call count_rows()
|
||||
return $connection->_db->selectCollection($_GET["select"])->count($where);
|
||||
}
|
||||
|
||||
function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
|
||||
|
|
|
@ -149,10 +149,10 @@ if (isset($_GET["simpledb"])) {
|
|||
return $return;
|
||||
}
|
||||
|
||||
function select($table, $select, $where, $group, $order, $limit, $page) {
|
||||
function select($table, $select, $where, $group, $order, $limit, $page, $print = false) {
|
||||
global $connection;
|
||||
$connection->next = $_GET["next"];
|
||||
$return = parent::select($table, $select, $where, $group, $order, $limit, $page);
|
||||
$return = parent::select($table, $select, $where, $group, $order, $limit, $page, $print);
|
||||
$connection->next = 0;
|
||||
return $return;
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ if ($_POST["save"]) {
|
|||
$select = array("*");
|
||||
}
|
||||
if ($select) {
|
||||
$result = $driver->select($TABLE, $select, array($where), $select, array(), (isset($_GET["select"]) ? 2 : 1), 0);
|
||||
$result = $driver->select($TABLE, $select, array($where), $select, array(), (isset($_GET["select"]) ? 2 : 1), 0, true);
|
||||
$row = $result->fetch_assoc();
|
||||
if (isset($_GET["select"]) && (!$row || $result->fetch_assoc())) { // $result->num_rows != 1 isn't available in all drivers
|
||||
$row = null;
|
||||
|
|
|
@ -176,10 +176,10 @@ username.form['auth[driver]'].onchange();
|
|||
*/
|
||||
function selectQuery($query) {
|
||||
global $jush;
|
||||
return ($_GET["edit"] != "" ? "" : "<p><code class='jush-$jush'>" . h(str_replace("\n", " ", $query)) . "</code>"
|
||||
return "<p><code class='jush-$jush'>" . h(str_replace("\n", " ", $query)) . "</code>"
|
||||
. (support("sql") ? " <a href='" . h(ME) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a>" : "")
|
||||
. "</p>" // </p> - required for IE9 inline edit
|
||||
);
|
||||
;
|
||||
}
|
||||
|
||||
/** Description of a row in a table
|
||||
|
|
|
@ -18,9 +18,10 @@
|
|||
* @param array result of $adminer->selectOrderProcess()
|
||||
* @param int result of $adminer->selectLimitProcess()
|
||||
* @param int index of page starting at zero
|
||||
* @param bool whether to print the query
|
||||
* @return Min_Result
|
||||
*/
|
||||
function select($table, $select, $where, $group, $order, $limit, $page) {
|
||||
function select($table, $select, $where, $group, $order, $limit, $page, $print = false) {
|
||||
global $adminer, $jush;
|
||||
$is_group = (count($group) < count($select));
|
||||
$query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page);
|
||||
|
@ -33,7 +34,9 @@
|
|||
"\n"
|
||||
);
|
||||
}
|
||||
echo $adminer->selectQuery($query);
|
||||
if ($print) {
|
||||
echo $adminer->selectQuery($query);
|
||||
}
|
||||
return $this->_conn->query($query);
|
||||
}
|
||||
|
||||
|
|
|
@ -256,7 +256,7 @@ if (!$columns && support("table")) {
|
|||
if ($convert_fields) {
|
||||
$select2[] = substr($convert_fields, 2);
|
||||
}
|
||||
$result = $driver->select($TABLE, $select2, $where, $group, $order, $limit, $page);
|
||||
$result = $driver->select($TABLE, $select2, $where, $group, $order, $limit, $page, true);
|
||||
|
||||
if (!$result) {
|
||||
echo "<p class='error'>" . error() . "\n";
|
||||
|
@ -346,7 +346,7 @@ if (!$columns && support("table")) {
|
|||
}
|
||||
$unique_idf = "";
|
||||
foreach ($unique_array as $key => $val) {
|
||||
if (strlen($val) > 64 && ($jush == "sql" || $jush == "pgsql")) {
|
||||
if (($jush == "sql" || $jush == "pgsql") && strlen($val) > 64) {
|
||||
$key = "MD5(" . (strpos($key, '(') ? $key : idf_escape($key)) . ")"; //! columns looking like functions
|
||||
$val = md5($val);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
Adminer 4.0.1-dev:
|
||||
Fix compiled version of Elasticsearch
|
||||
Don't use type=number if a SQL function is used
|
||||
MongoDB: Count tables, display ObjectIds
|
||||
MongoDB: Count tables, display ObjectIds, sort, limit, offset, count rows
|
||||
|
||||
Adminer 4.0.0 (released 2014-01-08):
|
||||
Driver for SimpleDB, MongoDB and Elasticsearch
|
||||
|
|
Loading…
Reference in a new issue