--- /dev/null
+<?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();
+}
}
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";
}
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";
}
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";
- class Min_Driver {
+ class Min_Driver extends Min_SQL {
function _chunkRequest($ids, $action, $params, $expand = array()) {
global $connection;
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),
}
function support($feature) {
- return false;
+ return ereg('sql', $feature);
}
function logged_user() {
}
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";
} 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";
}
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
$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 ..."
<?php
-$VERSION = "3.7.2-dev";
+$VERSION = "4.0.0-dev";
$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 {
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";
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