]> git.joonet.de Git - adminer.git/commitdiff
Prepare Elasticsearch
authorJakub Vrana <jakub@vrana.cz>
Wed, 10 Jul 2013 00:38:13 +0000 (17:38 -0700)
committerJakub Vrana <jakub@vrana.cz>
Thu, 11 Jul 2013 18:19:59 +0000 (11:19 -0700)
13 files changed:
adminer/drivers/elastic.inc.php [new file with mode: 0644]
adminer/drivers/mssql.inc.php
adminer/drivers/oracle.inc.php
adminer/drivers/pgsql.inc.php
adminer/drivers/simpledb.inc.php
adminer/drivers/sqlite.inc.php
adminer/include/adminer.inc.php
adminer/include/bootstrap.inc.php
adminer/include/driver.inc.php
adminer/include/version.inc.php
adminer/select.inc.php
adminer/table.inc.php
changes.txt

diff --git a/adminer/drivers/elastic.inc.php b/adminer/drivers/elastic.inc.php
new file mode 100644 (file)
index 0000000..3678eab
--- /dev/null
@@ -0,0 +1,247 @@
+<?php
+$drivers["elastic"] = "Elasticsearch";
+
+if (isset($_GET["elastic"])) {
+       $possible_drivers = array("json");
+       define("DRIVER", "elastic");
+       
+       if (function_exists('json_decode')) {
+               class Min_DB {
+                       var $extension = "JSON", $server_info, $errno, $error, $_url;
+                       
+                       function query($path) {
+                               $file = @file_get_contents($this->_url . ($this->_db != "" ? "$this->_db/" : "") . $path, false, stream_context_create(array('http' => array(
+                                       'ignore_errors' => 1, // available since PHP 5.2.10
+                               ))));
+                               @ini_set('track_errors', 1); // @ - may be disabled
+                               if (!$file) {
+                                       $this->error = $php_errormsg;
+                                       return $file;
+                               }
+                               if (!eregi('^HTTP/[0-9.]+ 2', $http_response_header[0])) {
+                                       $this->error = $file;
+                                       return false;
+                               }
+                               $return = json_decode($file, true);
+                               if (!$return) {
+                                       $this->errno = json_last_error();
+                                       if (function_exists('json_last_error_msg')) {
+                                               $this->error = json_last_error_msg();
+                                       } else {
+                                               $constants = get_defined_constants(true);
+                                               foreach ($constants['json'] as $name => $value) {
+                                                       if ($value == $this->errno && ereg('^JSON_ERROR_', $name)) {
+                                                               $this->error = $name;
+                                                               break;
+                                                       }
+                                               }
+                                       }
+                               }
+                               return $return;
+                       }
+                       
+                       function connect($server, $username, $password) {
+                               $this->_url = "http://$username:$password@$server/";
+                               $return = $this->query('');
+                               if ($return) {
+                                       $this->server_info = $return['version']['number'];
+                               }
+                               return (bool) $return;
+                       }
+                       
+                       function select_db($database) {
+                               $this->_db = $database;
+                               return true;
+                       }
+                       
+                       function quote($string) {
+                               return $string;
+                       }
+                       
+               }
+               
+               class Min_Result {
+                       var $_rows;
+                       
+                       function Min_Result($rows) {
+                               $this->_rows = $rows;
+                               reset($this->_rows);
+                       }
+                       
+                       function fetch_assoc() {
+                               $return = current($this->_rows);
+                               next($this->_rows);
+                               return $return;
+                       }
+                       
+                       function fetch_row() {
+                               return array_values($this->fetch_assoc());
+                       }
+                       
+               }
+               
+       }
+       
+       
+       
+       class Min_Driver extends Min_SQL {
+               
+               function select($table, $select, $where, $group, $order, $limit, $page) {
+                       global $adminer;
+                       $query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page);
+                       if (!$query) {
+                               $query = "$table/_search";
+                       }
+                       $search = $this->_conn->query($query);
+                       if (!$search) {
+                               return false;
+                       }
+                       $return = array();
+                       foreach ($search['hits']['hits'] as $hit) {
+                               $row = array();
+                               foreach ($hit['_source'] as $key => $val) {
+                                       $row[$key] = (is_array($val) ? implode(", ", $val) : $val);
+                               }
+                               $return[] = $row;
+                       }
+                       echo $adminer->selectQuery($query);
+                       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 support($feature) {
+               return ereg("database|table", $feature);
+       }
+       
+       function logged_user() {
+               global $adminer;
+               $credentials = $adminer->credentials();
+               return $credentials[1];
+       }
+       
+       function get_databases() {
+               global $connection;
+               $return = $connection->query('_aliases');
+               if ($return) {
+                       $return = array_keys($return);
+               }
+               return $return;
+       }
+       
+       function collations() {
+               return array();
+       }
+       
+       function db_collation($db, $collations) {
+       }
+       
+       function count_tables($databases) {
+               global $connection;
+               $return = $connection->query('_mapping');
+               if ($return) {
+                       $return = array_map('count', $return);
+               }
+               return $return;
+       }
+       
+       function tables_list() {
+               global $connection;
+               $return = $connection->query('_mapping');
+               if ($return) {
+                       $return = array_fill_keys(array_keys(reset($return)), 'table');
+               }
+               return $return;
+       }
+       
+       function table_status($name = "", $fast = false) {
+               $return = tables_list();
+               if ($return) {
+                       foreach ($return as $key => $type) { // _stats have just info about database
+                               $return[$key] = array("Name" => $key, "Engine" => $type);
+                               if ($name != "") {
+                                       return $return[$name];
+                               }
+                       }
+               }
+               return $return;
+       }
+       
+       function error() {
+               global $connection;
+               return h($connection->error);
+       }
+       
+       function information_schema() {
+       }
+       
+       function is_view($table_status) {
+       }
+       
+       function indexes($table, $connection2 = null) {
+               return array(
+                       array("type" => "PRIMARY", "columns" => array("_id")),
+               );
+       }
+       
+       function fields($table) {
+               global $connection;
+               $mapping = $connection->query("$table/_mapping");
+               $return = array();
+               if ($mapping) {
+                       foreach ($mapping[$table]['properties'] as $name => $field) {
+                               $return[$name] = array(
+                                       "field" => $name,
+                                       "full_type" => $field["type"],
+                                       "type" => $field["type"],
+                                       "privileges" => array("insert" => 1, "select" => 1, "update" => 1),
+                               );
+                       }
+               }
+               return $return;
+       }
+       
+       function foreign_keys($table) {
+               return array();
+       }
+       
+       function table($idf) {
+               return $idf;
+       }
+       
+       function idf_escape($idf) {
+               return $idf;
+       }
+       
+       function convert_field($field) {
+       }
+               
+       function unconvert_field($field, $return) {
+               return $return;
+       }
+       
+       function fk_support($table_status) {
+       }
+       
+       function found_rows($table_status, $where) {
+               return null;
+       }
+       
+       $jush = "elastic";
+       $operators = array("=");
+       $functions = array();
+       $grouping = array();
+       $edit_functions = array();
+}
index eb527ca772c07d583acbe99f653b74337123ed66..77a24975f41c116f346d4622490db95fe509c177 100644 (file)
@@ -607,7 +607,7 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)
        }
        
        function support($feature) {
-               return ereg('^(database|table|scheme|trigger|view|drop_col)$', $feature); //! routine|
+               return ereg('^(database|table|sql|indexes|scheme|trigger|view|drop_col)$', $feature); //! routine|
        }
        
        $jush = "mssql";
index 3dbcbd31b79129fe630268f039fac4d70628fb51..ebd388d60595975cad0cf6fe63aad378ec00ab05 100644 (file)
@@ -376,7 +376,7 @@ ORDER BY PROCESS
        }
        
        function support($feature) {
-               return ereg("database|table|view|scheme|processlist|drop_col|variables|status", $feature); //!
+               return ereg('^(database|table|sql|indexes|view|scheme|processlist|drop_col|variables|status)$', $feature); //!
        }
        
        $jush = "oracle";
index 70cc02a2a0214844878e15ec0b21f0739f0ede61..bc0dbef92e087aa70e884ff1ecec887f5f823bcb 100644 (file)
@@ -613,7 +613,7 @@ AND typelem = 0"
        }
        
        function support($feature) {
-               return ereg('^(database|table|comment|view|scheme|processlist|sequence|trigger|type|variables|drop_col)$', $feature); //! routine|
+               return ereg('^(database|table|sql|indexes|comment|view|scheme|processlist|sequence|trigger|type|variables|drop_col)$', $feature); //! routine|
        }
        
        $jush = "pgsql";
index 62388868b995930f3a2899dd981e849e7fcee701..08f08464f7f01cb6f79ed49f24f7d42dc63e5a03 100644 (file)
@@ -119,7 +119,7 @@ if (isset($_GET["simpledb"])) {
        
        
        
-       class Min_Driver {
+       class Min_Driver extends Min_SQL {
                
                function _chunkRequest($ids, $action, $params, $expand = array()) {
                        global $connection;
@@ -151,6 +151,14 @@ if (isset($_GET["simpledb"])) {
                        return $return;
                }
                
+               function select($table, $select, $where, $group, $order, $limit, $page) {
+                       global $connection;
+                       $connection->next = $_GET["next"];
+                       $return = parent::select($table, $select, $where, $group, $order, $limit, $page);
+                       $connection->next = 0;
+                       return $return;
+               }
+               
                function delete($table, $queryWhere, $limit = 0) {
                        return $this->_chunkRequest(
                                $this->_extractIds($table, $queryWhere, $limit),
@@ -231,7 +239,7 @@ if (isset($_GET["simpledb"])) {
        }
        
        function support($feature) {
-               return false;
+               return ereg('sql', $feature);
        }
        
        function logged_user() {
index f97ed10ba8364d33f62d7af1af3158a1c61942c7..dd7b9989eaca130665d422881e3b9acdf84a26e6 100644 (file)
@@ -680,7 +680,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
        }
        
        function support($feature) {
-               return ereg('^(database|table|view|trigger|variables|status|dump|move_col|drop_col)$', $feature);
+               return ereg('^(database|table|sql|indexes|view|trigger|variables|status|dump|move_col|drop_col)$', $feature);
        }
        
        $jush = "sqlite";
index 4aeec4af3713e306771216a53fbe3e2b93134b33..764346bb169813cb4665ef44e76ccff3cc8cbbe8 100644 (file)
@@ -769,7 +769,7 @@ username.form['auth[driver]'].onchange();
                } else {
                        $this->databasesPrint($missing);
                        if (DB == "" || !$missing) {
-                               echo "<p class='links'><a href='" . h(ME) . "sql='" . bold(isset($_GET["sql"])) . ">" . lang('SQL command') . "/" . lang('Import') . "</a><br>\n";
+                               echo "<p class='links'>" . (support("sql") ? "<a href='" . h(ME) . "sql='" . bold(isset($_GET["sql"])) . ">" . lang('SQL command') . "/" . lang('Import') . "</a><br>\n" : "") . "";
                                if (support("dump")) {
                                        echo "<a href='" . h(ME) . "dump=" . urlencode(isset($_GET["table"]) ? $_GET["table"] : $_GET["select"]) . "' id='dump'" . bold(isset($_GET["dump"])) . ">" . lang('Dump') . "</a><br>\n";
                                }
index 1f791cb8f6ecac81aa0618ac15fb6e066494877b..085fda7d995df1d0c83d402593dba4e52ff7db72 100644 (file)
@@ -63,6 +63,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/elastic.inc.php";
 include "../adminer/drivers/simpledb.inc.php";
 include "../adminer/drivers/mysql.inc.php"; // must be included as last driver
 
index 30637f526e1153dd3ad490effe2a2f067ee878dc..ef2d16424c1dbadce71db94a9e3ec183d2433d68 100644 (file)
                $this->_conn = $connection;
        }
        
+       /** Select data from table
+       * @param string
+       * @param array result of $adminer->selectColumnsProcess()[0]
+       * @param array result of $adminer->selectSearchProcess()
+       * @param array result of $adminer->selectColumnsProcess()[1]
+       * @param array result of $adminer->selectOrderProcess()
+       * @param int result of $adminer->selectLimitProcess()
+       * @param int index of page starting at zero
+       * @return Min_Result
+       */
+       function select($table, $select, $where, $group, $order, $limit, $page) {
+               global $adminer, $jush;
+               $is_group = (count($group) < count($select));
+               $query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page);
+               if (!$query) {
+                       $query = "SELECT" . limit(
+                               ($_GET["page"] != "last" && +$limit && $group && $is_group && $jush == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . implode(", ", $select) . "\nFROM " . table($table),
+                               ($where ? "\nWHERE " . implode(" AND ", $where) : "") . ($group && $is_group ? "\nGROUP BY " . implode(", ", $group) : "") . ($order ? "\nORDER BY " . implode(", ", $order) : ""),
+                               ($limit != "" ? +$limit : null),
+                               ($page ? $limit * $page : 0),
+                               "\n"
+                       );
+               }
+               echo $adminer->selectQuery($query);
+               return $this->_conn->query($query);
+       }
+       
        /** Delete data from table
        * @param string
        * @param string " WHERE ..."
index c2330274038bf9d4b9b4da0fbaf6c67182f6a8a3..f8fb264cf7d0f83bb0a4f9408e28f2c8b294fdb0 100644 (file)
@@ -1,2 +1,2 @@
 <?php
-$VERSION = "3.7.2-dev";
+$VERSION = "4.0.0-dev";
index 252b11055e04805c460a662d18a4ba7c8ec09150..adcef7397fce50b8f26a56678a47da661167118e 100644 (file)
@@ -245,21 +245,19 @@ if (!$columns && support("table")) {
                $page = floor(max(0, $found_rows - 1) / $limit);
        }
 
-       $query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page);
-       if (!$query) {
-               $query = "SELECT" . limit(
-                       ($_GET["page"] != "last" && +$limit && $group && $is_group && $jush == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . $from,
-                       ($where ? "\nWHERE " . implode(" AND ", $where) : "") . $group_by,
-                       ($limit != "" ? +$limit : null),
-                       ($page ? $limit * $page : 0),
-                       "\n"
-               );
+       $select2 = $select;
+       if (!$select2) {
+               $select2[] = "*";
+               if ($oid) {
+                       $select2[] = $oid;
+               }
+       }
+       $convert_fields = convert_fields($columns, $fields, $select);
+       if ($convert_fields) {
+               $select2[] = substr($convert_fields, 2);
        }
-       echo $adminer->selectQuery($query);
+       $result = $driver->select($TABLE, $select2, $where, $group, $order, $limit, $page);
        
-       $connection->next = $_GET["next"];
-       $result = $connection->query($query);
-       $connection->next = 0;
        if (!$result) {
                echo "<p class='error'>" . error() . "\n";
        } else {
index b0647baff05634059fa3e7d608b7142b4a15e90b..84a20a82d22a2d5c5ebc4886039e3f339da401c7 100644 (file)
@@ -27,24 +27,26 @@ if ($fields) {
        echo "</table>\n";
        
        if (!is_view($table_status)) {
-               echo "<h3 id='indexes'>" . lang('Indexes') . "</h3>\n";
-               $indexes = indexes($TABLE);
-               if ($indexes) {
-                       echo "<table cellspacing='0'>\n";
-                       foreach ($indexes as $name => $index) {
-                               ksort($index["columns"]); // enforce correct columns order
-                               $print = array();
-                               foreach ($index["columns"] as $key => $val) {
-                                       $print[] = "<i>" . h($val) . "</i>"
-                                               . ($index["lengths"][$key] ? "(" . $index["lengths"][$key] . ")" : "")
-                                               . ($index["descs"][$key] ? " DESC" : "")
-                                       ;
+               if (support("indexes")) {
+                       echo "<h3 id='indexes'>" . lang('Indexes') . "</h3>\n";
+                       $indexes = indexes($TABLE);
+                       if ($indexes) {
+                               echo "<table cellspacing='0'>\n";
+                               foreach ($indexes as $name => $index) {
+                                       ksort($index["columns"]); // enforce correct columns order
+                                       $print = array();
+                                       foreach ($index["columns"] as $key => $val) {
+                                               $print[] = "<i>" . h($val) . "</i>"
+                                                       . ($index["lengths"][$key] ? "(" . $index["lengths"][$key] . ")" : "")
+                                                       . ($index["descs"][$key] ? " DESC" : "")
+                                               ;
+                                       }
+                                       echo "<tr title='" . h($name) . "'><th>$index[type]<td>" . implode(", ", $print) . "\n";
                                }
-                               echo "<tr title='" . h($name) . "'><th>$index[type]<td>" . implode(", ", $print) . "\n";
+                               echo "</table>\n";
                        }
-                       echo "</table>\n";
+                       echo '<p class="links"><a href="' . h(ME) . 'indexes=' . urlencode($TABLE) . '">' . lang('Alter indexes') . "</a>\n";
                }
-               echo '<p class="links"><a href="' . h(ME) . 'indexes=' . urlencode($TABLE) . '">' . lang('Alter indexes') . "</a>\n";
                
                if (fk_support($table_status)) {
                        echo "<h3 id='foreign-keys'>" . lang('Foreign keys') . "</h3>\n";
index 1bd9c769f6f96e27f5dffb2111de8bb6f3014fc6..fa3f788565b537846d71fbce13646728ed833d03 100644 (file)
@@ -1,5 +1,5 @@
 Adminer 4.0.0-dev:
-Driver for SimpleDB
+Driver for SimpleDB and Elasticsearch
 Save and continue edit by AJAX
 Add a new column in alter table on key press
 Mark length as required for strings