Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复pgsql数据库下执行计划查看 #2638

Merged
merged 5 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sql/engines/pgsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ def query_check(self, db_name=None, sql=""):
except IndexError:
result["bad_query"] = True
result["msg"] = "没有有效的SQL语句"
if re.match(r"^select", sql, re.I) is None:
if re.match(r"^select|^explain", sql, re.I) is None:
result["bad_query"] = True
result["msg"] = "不支持的查询语法类型!"
if "*" in sql:
result["has_star"] = True
result["msg"] = "SQL语句中含有 * "
result["msg"] += "SQL语句中含有 * "
return result

def query(
Expand Down
14 changes: 14 additions & 0 deletions sql/engines/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,20 @@ def test_query_check_star_sql(self):
},
)

def test_query_check_explain(self):
sql = "explain select x from xx "
new_engine = PgSQLEngine(instance=self.ins)
check_result = new_engine.query_check(db_name="archery", sql=sql)
self.assertDictEqual(
check_result,
{
"msg": "",
"bad_query": False,
"filtered_sql": sql.strip(),
"has_star": False,
},
)

def test_filter_sql_with_delimiter(self):
sql = "select * from xx;"
new_engine = PgSQLEngine(instance=self.ins)
Expand Down
2 changes: 1 addition & 1 deletion sql/templates/sqlquery.html
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ <h4 class="modal-title text-danger">收藏语句</h4>
else if (sql === 'show create table') {
sqlContent = "desc " + $("#table_name").val() + ";"
}
} else if (optgroup === "MySQL") {
} else if (optgroup === "MySQL" || optgroup === "PgSQL" ) {
//查看执行计划
if (sql === 'explain') {
sqlContent = 'explain ' + sqlContent
Expand Down
Loading