diff --git a/adminer/drivers/elastic.inc.php b/adminer/drivers/elastic.inc.php new file mode 100644 index 00000000..3678eabf --- /dev/null +++ b/adminer/drivers/elastic.inc.php @@ -0,0 +1,247 @@ +_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(); +} diff --git a/adminer/drivers/mssql.inc.php b/adminer/drivers/mssql.inc.php index eb527ca7..77a24975 100644 --- a/adminer/drivers/mssql.inc.php +++ b/adminer/drivers/mssql.inc.php @@ -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"; diff --git a/adminer/drivers/oracle.inc.php b/adminer/drivers/oracle.inc.php index 3dbcbd31..ebd388d6 100644 --- a/adminer/drivers/oracle.inc.php +++ b/adminer/drivers/oracle.inc.php @@ -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"; diff --git a/adminer/drivers/pgsql.inc.php b/adminer/drivers/pgsql.inc.php index 70cc02a2..bc0dbef9 100644 --- a/adminer/drivers/pgsql.inc.php +++ b/adminer/drivers/pgsql.inc.php @@ -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"; diff --git a/adminer/drivers/simpledb.inc.php b/adminer/drivers/simpledb.inc.php index 62388868..08f08464 100644 --- a/adminer/drivers/simpledb.inc.php +++ b/adminer/drivers/simpledb.inc.php @@ -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() { diff --git a/adminer/drivers/sqlite.inc.php b/adminer/drivers/sqlite.inc.php index f97ed10b..dd7b9989 100644 --- a/adminer/drivers/sqlite.inc.php +++ b/adminer/drivers/sqlite.inc.php @@ -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"; diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 4aeec4af..764346bb 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -769,7 +769,7 @@ username.form['auth[driver]'].onchange(); } else { $this->databasesPrint($missing); if (DB == "" || !$missing) { - echo "

" . error() . "\n"; } else { diff --git a/adminer/table.inc.php b/adminer/table.inc.php index b0647baf..84a20a82 100644 --- a/adminer/table.inc.php +++ b/adminer/table.inc.php @@ -27,24 +27,26 @@ if ($fields) { echo "\n"; if (!is_view($table_status)) { - echo "

" . lang('Indexes') . "

\n"; - $indexes = indexes($TABLE); - if ($indexes) { - echo "\n"; - foreach ($indexes as $name => $index) { - ksort($index["columns"]); // enforce correct columns order - $print = array(); - foreach ($index["columns"] as $key => $val) { - $print[] = "" . h($val) . "" - . ($index["lengths"][$key] ? "(" . $index["lengths"][$key] . ")" : "") - . ($index["descs"][$key] ? " DESC" : "") - ; + if (support("indexes")) { + echo "

" . lang('Indexes') . "

\n"; + $indexes = indexes($TABLE); + if ($indexes) { + echo "
\n"; + foreach ($indexes as $name => $index) { + ksort($index["columns"]); // enforce correct columns order + $print = array(); + foreach ($index["columns"] as $key => $val) { + $print[] = "" . h($val) . "" + . ($index["lengths"][$key] ? "(" . $index["lengths"][$key] . ")" : "") + . ($index["descs"][$key] ? " DESC" : "") + ; + } + echo "
$index[type]" . implode(", ", $print) . "\n"; } - echo "
$index[type]" . implode(", ", $print) . "\n"; + echo "
\n"; } - echo "\n"; + echo '

" . lang('Foreign keys') . "

\n"; diff --git a/changes.txt b/changes.txt index 1bd9c769..fa3f7885 100644 --- a/changes.txt +++ b/changes.txt @@ -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