Skip to content

Commit

Permalink
fixed: SQL command for insert, create table, etc. new: create/rename …
Browse files Browse the repository at this point in the history
…table, add/drop/change type for column
  • Loading branch information
morozovsk authored and vrana committed Nov 11, 2019
1 parent 6777744 commit 6ae81cd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
42 changes: 40 additions & 2 deletions adminer/drivers/clickhouse.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ function rootQuery($db, $query) {
}
$return = json_decode($file, true);
if ($return === null) {
if (!$this->isQuerySelectLike($query) && $file === '') {
return true;
}

$this->errno = json_last_error();
if (function_exists('json_last_error_msg')) {
$this->error = json_last_error_msg();
Expand Down Expand Up @@ -123,6 +127,9 @@ function fetch_field() {

class Min_Driver extends Min_SQL {
function delete($table, $queryWhere, $limit = 0) {
if ($queryWhere === '') {
$queryWhere = 'WHERE 1=1';
}
return queries("ALTER TABLE " . table($table) . " DELETE $queryWhere");
}

Expand Down Expand Up @@ -154,12 +161,43 @@ function found_rows($table_status, $where) {
}

function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
$alter = $order = array();
foreach ($fields as $field) {
if ($field[1][2] === " NULL") {
$field[1][1] = " Nullable({$field[1][1]})";
} elseif ($field[1][2] === ' NOT NULL') {
$field[1][2] = '';
}
unset($field[1][2]);

if ($field[1][3]) {
$field[1][3] = '';
}

$alter[] = ($field[1]
? ($table != "" ? ($field[0] != "" ? "MODIFY COLUMN " : "ADD COLUMN ") : " ") . implode($field[1])
: "DROP COLUMN " . idf_escape($field[0])
);

$order[] = $field[1][0];
}

$alter = array_merge($alter, $foreign);
$status = ($engine ? " ENGINE " . $engine : "");
if ($table == "") {
return queries("CREATE TABLE " . table($name) . " (\n" . implode(",\n", $alter) . "\n)$status$partitioning" . ' ORDER BY (' . implode(',', $order) . ')');
}
if ($table != $name) {
$result = queries("RENAME TABLE " . table($table) . " TO " . table($name));
if ($alter) {
$table = $name;
} else {
return $result;
}
}
if ($status) {
$alter[] = ltrim($status);
}
return ($alter || $partitioning ? queries("ALTER TABLE " . table($table) . "\n" . implode(",\n", $alter) . $partitioning) : true);
}

function truncate_tables($tables) {
Expand Down Expand Up @@ -331,7 +369,7 @@ function last_id() {
}

function support($feature) {
return preg_match("~^(columns|sql|status|table)$~", $feature);
return preg_match("~^(columns|sql|status|table|drop_col)$~", $feature);
}

$jush = "clickhouse";
Expand Down
1 change: 1 addition & 0 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Adminer 4.7.5-dev:
Add id="" to cells with failed inline edit (bug #708)
PostgreSQL, Oracle: Set schema for EXPLAIN queries in SQL command (bug #706)
ClickHouse: SQL command
Swedish translation

Adminer 4.7.4 (released 2019-10-22):
Expand Down

0 comments on commit 6ae81cd

Please sign in to comment.