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 "
" . lang('SQL command') . "/" . lang('Import') . "
\n";
+ echo "
" . (support("sql") ? "" . lang('SQL command') . "/" . lang('Import') . "
\n" : "") . "";
if (support("dump")) {
echo "" . lang('Dump') . "
\n";
}
diff --git a/adminer/include/bootstrap.inc.php b/adminer/include/bootstrap.inc.php
index 1f791cb8..085fda7d 100644
--- a/adminer/include/bootstrap.inc.php
+++ b/adminer/include/bootstrap.inc.php
@@ -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
diff --git a/adminer/include/driver.inc.php b/adminer/include/driver.inc.php
index 30637f52..ef2d1642 100644
--- a/adminer/include/driver.inc.php
+++ b/adminer/include/driver.inc.php
@@ -10,6 +10,33 @@
$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 ..."
diff --git a/adminer/include/version.inc.php b/adminer/include/version.inc.php
index c2330274..f8fb264c 100644
--- a/adminer/include/version.inc.php
+++ b/adminer/include/version.inc.php
@@ -1,2 +1,2 @@
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;
+ }
}
- echo $adminer->selectQuery($query);
+ $convert_fields = convert_fields($columns, $fields, $select);
+ if ($convert_fields) {
+ $select2[] = substr($convert_fields, 2);
+ }
+ $result = $driver->select($TABLE, $select2, $where, $group, $order, $limit, $page);
- $connection->next = $_GET["next"];
- $result = $connection->query($query);
- $connection->next = 0;
if (!$result) {
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 "
$index[type] | " . implode(", ", $print) . "\n"; } - echo " |
---|---|
$index[type] | " . implode(", ", $print) . "\n"; + echo " |
' . lang('Alter indexes') . "\n"; } - echo '
' . lang('Alter indexes') . "\n"; if (fk_support($table_status)) { echo "