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();
$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;
$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();
}
}
+ function quote($string) {
+ return $string;
+ }
+
}
class Min_Result {
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);
- }
- $return = array();
- foreach ($connection->_db->selectCollection($table)->find(array(), $select) as $val) {
- $return[] = $val;
+ $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 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)
+ ));
}
}
function convert_field($field) {
}
+ function unconvert_field($field, $return) {
+ return $return;
+ }
+
function foreign_keys($table) {
return array();
}
}
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) {
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;
}
$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;
*/
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
* @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);
"\n"
);
}
- echo $adminer->selectQuery($query);
+ if ($print) {
+ echo $adminer->selectQuery($query);
+ }
return $this->_conn->query($query);
}
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";
}
$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);
}
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