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

新增sql执行行数限制 #2366

Merged
merged 14 commits into from
Nov 6, 2023
11 changes: 11 additions & 0 deletions common/templates/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ <h5 style="color: darkgrey"><b>SQL上线</b></h5>
placeholder="自动驳回的等级,1表示警告驳回,2和空表示错误才驳回,其他表示不驳回" />
</div>
</div>
<div class="form-group">
<label for="max_sql_length"
class="col-sm-4 control-label">MAX_SQL_LENGTH</label>
<div class="col-sm-5">
<input type="number" class="form-control"
id="max_sql_length"
key="max_sql_length"
value="{{ config.max_sql_length }}"
placeholder="最大执行sql行数,默认10000条"/>
</div>
</div>
<div class="form-group">
<label for="enable_backup_switch"
class="col-sm-4 control-label">ENABLE_BACKUP_SWITCH</label>
Expand Down
5 changes: 5 additions & 0 deletions sql_api/api_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ def post(self, request):
check_result = check_engine.execute_check(
db_name=db_name, sql=request.data["full_sql"].strip()
)
max_sql_length = SysConfig().get("max_sql_length", default_value=10000)
if len(check_result.rows) > int(max_sql_length):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该允许设置为 0 , 也就是不做限制

raise serializers.ValidationError(
{"errors": f"执行行数超过{str(max_sql_length)}行,请联系DBA核查!"}
)
except Exception as e:
raise serializers.ValidationError({"errors": f"{e}"})
check_result.rows = check_result.to_dict()
Expand Down