From 06932cc381da431e9d4f4c3aec5c7cafeabe9b18 Mon Sep 17 00:00:00 2001 From: Bogdanova Olga Date: Tue, 6 Apr 2021 10:00:36 +0300 Subject: [PATCH] Issues-523: support different query types --- DebugPlugin/controllers/api/SqlApiController.php | 12 +++++++----- DebugPlugin/openapi/sql.yml | 7 ++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/DebugPlugin/controllers/api/SqlApiController.php b/DebugPlugin/controllers/api/SqlApiController.php index f10ad6e..7980c98 100644 --- a/DebugPlugin/controllers/api/SqlApiController.php +++ b/DebugPlugin/controllers/api/SqlApiController.php @@ -22,17 +22,19 @@ public function index(array $query) { $this->permission('Garden.Settings.Manage'); $in = $this->schema([ - 'sql:s' => 'Sql query' + 'sql:s' => 'Sql query', + 'type:s' => 'Type' ], 'in')->setDescription('Get a list of records.'); $query = $in->validate($query); $sql = $query['sql']; + $type = $query['type']; - if (strpos(strtolower($sql), 'select') !== 0) { - throw new ClientException('Unable to execute this query.'); - } + // if (strpos(strtolower($sql), 'select') !== 0) { + // throw new ClientException('Unable to execute this query.'); + // } - $data = Gdn::sql()->query($sql, 'select')->resultArray(); + $data = Gdn::sql()->query($sql, $type)->resultArray(); return $data; } diff --git a/DebugPlugin/openapi/sql.yml b/DebugPlugin/openapi/sql.yml index bde252d..ce532af 100644 --- a/DebugPlugin/openapi/sql.yml +++ b/DebugPlugin/openapi/sql.yml @@ -4,11 +4,16 @@ paths: /sql: get: parameters: - - description: SQL select query. + - description: SQL query. in: query name: sql schema: type: string + - description: SQL type query. + in: query + name: type + schema: + type: string responses: '200': content: