]> git.joonet.de Git - adminer.git/commitdiff
MongoDB: database list, table list, indexes, basic select
authorJakub Vrana <jakub@vrana.cz>
Thu, 8 Aug 2013 20:24:20 +0000 (13:24 -0700)
committerJakub Vrana <jakub@vrana.cz>
Thu, 8 Aug 2013 20:54:06 +0000 (13:54 -0700)
adminer/create.inc.php
adminer/drivers/elastic.inc.php
adminer/drivers/mongo.inc.php [new file with mode: 0644]
adminer/drivers/mssql.inc.php
adminer/drivers/oracle.inc.php
adminer/drivers/pgsql.inc.php
adminer/drivers/sqlite.inc.php
adminer/include/bootstrap.inc.php
changes.txt
readme.txt

index 7df9d79a3206f8902b3cbad67c9b513dcbb1e662..fcbfabcea2582d08019f9627f287487065079336 100644 (file)
@@ -157,7 +157,7 @@ foreach ($engines as $engine) {
 
 <form action="" method="post" id="form">
 <p>
-<?php if (support("table") || $TABLE == "") { ?>
+<?php if (support("columns") || $TABLE == "") { ?>
 <?php echo lang('Table name'); ?>: <input name="name" maxlength="64" value="<?php echo h($row["name"]); ?>" autocapitalize="off">
 <?php if ($TABLE == "" && !$_POST) { ?><script type='text/javascript'>focus(document.getElementById('form')['name']);</script><?php } ?>
 <?php echo ($engines ? "<select name='Engine' onchange='helpClose();'" . on_help("getTarget(event).value", 1) . ">" . optionlist(array("" => "(" . lang('engine') . ")") + $engines, $row["Engine"]) . "</select>" : ""); ?>
@@ -165,7 +165,7 @@ foreach ($engines as $engine) {
  <input type="submit" value="<?php echo lang('Save'); ?>">
 <?php } ?>
 
-<?php if (support("table")) { ?>
+<?php if (support("columns")) { ?>
 <table cellspacing="0" id="edit-fields" class="nowrap">
 <?php
 $comments = ($_POST ? $_POST["comments"] : $row["Comment"] != "");
index 56c18a7caa259f94a161fe0af5d0b8b2e8d7c7a8..b5337a57fb1a5e589ca5dab949ca288fa295eef4 100644 (file)
@@ -162,7 +162,7 @@ if (isset($_GET["elastic"])) {
        }
 
        function support($feature) {
-               return preg_match("~database|table~", $feature);
+               return preg_match("~database|table|columns~", $feature);
        }
 
        function logged_user() {
diff --git a/adminer/drivers/mongo.inc.php b/adminer/drivers/mongo.inc.php
new file mode 100644 (file)
index 0000000..1a6eb30
--- /dev/null
@@ -0,0 +1,294 @@
+<?php
+$drivers["mongo"] = "MongoDB";
+
+if (isset($_GET["mongo"])) {
+       $possible_drivers = array("mongo");
+       define("DRIVER", "mongo");
+
+       if (class_exists('MongoDB')) {
+               class Min_DB {
+                       var $extension = "Mongo", $error, $_link, $_db;
+
+                       function connect($server, $username, $password) {
+                               global $adminer;
+                               $db = $adminer->database();
+                               $options = array();
+                               if ($username != "") {
+                                       $options["username"] = $username;
+                                       $options["password"] = $password;
+                               }
+                               if ($db != "") {
+                                       $options["db"] = $db;
+                               }
+                               try {
+                                       $this->_link = new MongoClient("mongodb://$server", $options);
+                                       return true;
+                               } catch (Exception $ex) {
+                                       $this->error = $ex->getMessage();
+                                       return false;
+                               }
+                       }
+                       
+                       function query($query) {
+                               return false;
+                       }
+
+                       function select_db($database) {
+                               try {
+                                       $this->_db = $this->_link->selectDB($database);
+                                       return true;
+                               } catch (Exception $ex) {
+                                       $this->error = $ex->getMessage();
+                                       return false;
+                               }
+                       }
+
+               }
+
+               class Min_Result {
+                       var $num_rows, $_rows = array(), $_offset = 0, $_charset = array();
+
+                       function Min_Result($result) {
+                               foreach ($result as $item) {
+                                       $row = array();
+                                       foreach ($item as $key => $val) {
+                                               if (is_a($val, 'MongoBinData')) {
+                                                       $this->_charset[$key] = 63;
+                                               }
+                                               $row[$key] =
+                                                       (is_a($val, 'MongoDate') ? gmdate("Y-m-d H:i:s", $val->sec) . " GMT" :
+                                                       (is_a($val, 'MongoBinData') ? $val->bin : //! allow downloading
+                                                       (is_a($val, 'MongoRegex') ? strval($val) :
+                                                       (is_object($val) ? get_class($val) : // MongoMinKey, MongoMaxKey
+                                                       $val
+                                               ))));
+                                       }
+                                       $this->_rows[] = $row;
+                                       foreach ($row as $key => $val) {
+                                               if (!isset($this->_rows[0][$key])) {
+                                                       $this->_rows[0][$key] = null;
+                                               }
+                                       }
+                               }
+                               $this->num_rows = count($this->_rows);
+                       }
+
+                       function fetch_assoc() {
+                               $row = current($this->_rows);
+                               if (!$row) {
+                                       return $row;
+                               }
+                               $return = array();
+                               foreach ($this->_rows[0] as $key => $val) {
+                                       $return[$key] = $row[$key];
+                               }
+                               next($this->_rows);
+                               return $return;
+                       }
+
+                       function fetch_row() {
+                               $return = $this->fetch_assoc();
+                               if (!$return) {
+                                       return $return;
+                               }
+                               return array_values($return);
+                       }
+
+                       function fetch_field() {
+                               $keys = array_keys($this->_rows[0]);
+                               $name = $keys[$this->_offset++];
+                               return (object) array(
+                                       'name' => $name,
+                                       'charsetnr' => $this->_charset[$name],
+                               );
+                       }
+
+               }
+       }
+
+
+
+       class Min_Driver extends Min_SQL {
+               function select($table, $select, $where, $group, $order, $limit, $page) {
+                       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;
+                       }
+                       return new Min_Result($return);
+               }
+       }
+
+
+
+       function connect() {
+               global $adminer;
+               $connection = new Min_DB;
+               $credentials = $adminer->credentials();
+               if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) {
+                       return $connection;
+               }
+               return $connection->error;
+       }
+
+       function error() {
+               global $connection;
+               return h($connection->error);
+       }
+
+       function logged_user() {
+               global $adminer;
+               $credentials = $adminer->credentials();
+               return $credentials[1];
+       }
+
+       function get_databases($flush) {
+               global $connection;
+               $return = array();
+               $dbs = $connection->_link->listDBs();
+               foreach ($dbs['databases'] as $db) {
+                       $return[] = $db['name'];
+               }
+               return $return;
+       }
+
+       function collations() {
+               return array();
+       }
+
+       function db_collation($db, $collations) {
+       }
+
+       function count_tables($databases) {
+               return array();
+       }
+
+       function tables_list() {
+               global $connection;
+               return array_fill_keys($connection->_db->getCollectionNames(true), 'table');
+       }
+
+       function table_status($name = "", $fast = false) {
+               $return = array();
+               foreach (tables_list() as $table => $type) {
+                       $return[$table] = array("Name" => $table);
+                       if ($name == $table) {
+                               return $return[$table];
+                       }
+               }
+               return $return;
+       }
+
+       function information_schema() {
+       }
+
+       function is_view($table_status) {
+       }
+
+       function drop_databases($databases) {
+               global $connection;
+               foreach ($databases as $db) {
+                       $response = $connection->_link->selectDB($db)->drop();
+                       if (!$response['ok']) {
+                               return false;
+                       }
+               }
+               return true;
+       }
+
+       function indexes($table, $connection2 = null) {
+               global $connection;
+               $return = array();
+               foreach ($connection->_db->selectCollection($table)->getIndexInfo() as $index) {
+                       $descs = array();
+                       foreach ($index["key"] as $column => $type) {
+                               $descs[] = ($type == -1 ? '1' : null);
+                       }
+                       $return[$index["name"]] = array(
+                               "type" => ($index["name"] == "_id_" ? "PRIMARY" : ($index["unique"] ? "UNIQUE" : "INDEX")),
+                               "columns" => array_keys($index["key"]),
+                               "descs" => $descs,
+                       );
+               }
+               return $return;
+       }
+
+       function fields($table) {
+               return array("_id" => array(
+                       "field" => "_id",
+                       "auto_increment" => true,
+                       "privileges" => array("select" => 1, "insert" => 1, "update" => 1),
+               ));
+       }
+
+       function convert_field($field) {
+       }
+
+       function foreign_keys($table) {
+               return array();
+       }
+
+       function fk_support($table_status) {
+       }
+
+       function engines() {
+               return array();
+       }
+
+       function found_rows($table_status, $where) {
+               return null;
+       }
+
+       function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
+               global $connection;
+               if ($table == "") {
+                       $connection->_db->createCollection($name);
+                       return true;
+               }
+       }
+
+       function drop_tables($tables) {
+               global $connection;
+               foreach ($tables as $table) {
+                       $response = $connection->_db->selectCollection($table)->drop();
+                       if (!$response['ok']) {
+                               return false;
+                       }
+               }
+               return true;
+       }
+
+       function truncate_tables($tables) {
+               global $connection;
+               foreach ($tables as $table) {
+                       $response = $connection->_db->selectCollection($table)->remove();
+                       if (!$response['ok']) {
+                               return false;
+                       }
+               }
+               return true;
+       }
+
+       function table($idf) {
+               return $idf;
+       }
+
+       function idf_escape($idf) {
+               return $idf;
+       }
+
+       function support($feature) {
+               return preg_match("~database|table|indexes~", $feature);
+       }
+
+       $jush = "mongo";
+       $operators = array("=");
+       $functions = array();
+       $grouping = array();
+       $edit_functions = array();
+}
index 162709f5c2f418f61f5cd214f7884bc2ec244010..ef03c854ed6e48e1e0afcf9baee80ee2271e3847 100644 (file)
@@ -607,7 +607,7 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)
        }
 
        function support($feature) {
-               return preg_match('~^(database|table|sql|indexes|scheme|trigger|view|drop_col)$~', $feature); //! routine|
+               return preg_match('~^(database|table|columns|sql|indexes|scheme|trigger|view|drop_col)$~', $feature); //! routine|
        }
 
        $jush = "mssql";
index e848c91c47d2563395459dc3ef54bf1404e13af0..76c5c449f8aadfad831780e577f56ffe22699e86 100644 (file)
@@ -376,7 +376,7 @@ ORDER BY PROCESS
        }
 
        function support($feature) {
-               return preg_match('~^(database|table|sql|indexes|view|scheme|processlist|drop_col|variables|status)$~', $feature); //!
+               return preg_match('~^(database|table|columns|sql|indexes|view|scheme|processlist|drop_col|variables|status)$~', $feature); //!
        }
 
        $jush = "oracle";
index 9f1158d38c86c96a0d68be77a1fd550e19d20346..e6c4ba2300aa4673d859cad8e8943324efb95173 100644 (file)
@@ -612,7 +612,7 @@ AND typelem = 0"
        }
 
        function support($feature) {
-               return preg_match('~^(database|table|sql|indexes|comment|view|scheme|processlist|sequence|trigger|type|variables|drop_col)$~', $feature); //! routine|
+               return preg_match('~^(database|table|columns|sql|indexes|comment|view|scheme|processlist|sequence|trigger|type|variables|drop_col)$~', $feature); //! routine|
        }
 
        $jush = "pgsql";
index 09b592fd09c419d442e81a96947ca5a0b248b900..edf0607305c890aa31bc822a4a764aa48057d37f 100644 (file)
@@ -693,7 +693,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
        }
 
        function support($feature) {
-               return preg_match('~^(database|table|sql|indexes|view|trigger|variables|status|dump|move_col|drop_col)$~', $feature);
+               return preg_match('~^(database|table|columns|sql|indexes|view|trigger|variables|status|dump|move_col|drop_col)$~', $feature);
        }
 
        $jush = "sqlite";
index 9163d4379254f5230d069c48a5b9f697c9de389d..3a1bc35e48d974764aa619b7f538d5fcb581b04e 100644 (file)
@@ -64,6 +64,7 @@ include "../adminer/drivers/sqlite.inc.php";
 include "../adminer/drivers/pgsql.inc.php";
 include "../adminer/drivers/oracle.inc.php";
 include "../adminer/drivers/mssql.inc.php";
+include "../adminer/drivers/mongo.inc.php";
 include "../adminer/drivers/elastic.inc.php";
 include "../adminer/drivers/simpledb.inc.php";
 include "../adminer/drivers/mysql.inc.php"; // must be included as last driver
index 69493a82797fd6f77d45e3fcc58779c04968931f..449ee1c3b5c0487446273e8b9e3a0038e036c705 100644 (file)
@@ -1,5 +1,5 @@
 Adminer 4.0.0-dev:
-Driver for SimpleDB and Elasticsearch
+Driver for MongoDB, SimpleDB and Elasticsearch
 Save and continue edit by AJAX
 Split SQL command and import
 Add a new column in alter table on key press
index 5e457b0c7b2f059226e36aef85f257a273f75ae0..21807c78fd73d7af7f10bf7ba5ea28b95d031631 100644 (file)
@@ -3,7 +3,7 @@ Adminer Editor - Data manipulation for end-users
 
 http://www.adminer.org/
 Supports: MySQL, PostgreSQL, SQLite, MS SQL, Oracle, SimpleDB, Elasticsearch
-Requirements: PHP 4.3.3+ or PHP 5+
+Requirements: PHP 5+
 Apache License 2.0 or GPL 2
 
 adminer/index.php - Run development version of Adminer