空格导致的一次线上事故
发布表单模型【check form and publish】的时候报错:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=update_time,asin)' at line 1
导致发布失败。
症状:
----------xxxxx----------
2024-11-05 17:08:56
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=update_time,asin)' at line 1
at Instrument.DBS.DbHelper.ExecuteNonQuery(String sql, MySqlParameter[] sqlparemeter)
at SassServer.etc.InstrumentX.auto_check_table_index_with_code(String tabid)
at SassServer.Controllers.EngineController.publish_form_and_create_database_table(String coulmn, String tablename, String tabid, String prefixv, String tabledesc, Dictionary`2 dictionary)
at SassServer.Controllers.EngineController.operate(Dictionary`2 dictionary)
at lambda_method(Closure , Object , Object[] )
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()
[41m[30mfail[39m[22m[49m: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HN7TF5N07JS8", Request id "0HN7TF5N07JS8:00000001": An unhandled exception was thrown by the application.
MySql.Data.MySqlClient.MySqlException (0x80004005): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
原因分析:
near '=update_time,asin)' at line 1--》这里是自动创建index,tmd竟然有一个等于=符号,找到对应的程序里面创建index的代码,
if (x.trim_all().StartsWith("sort=")) { var arrKeys = x.Replace("sort=", "").Replace("\"", "").Replace(";", "").Split(','); foreach (var xKey in arrKeys) { string key = xKey.Replace("desc", "").Replace("asc", "").trim_all(); if (key.is_not_null_or_empty()) hashSet.Add(key.ToLower()); } }
if判断条件是ok的,那就是需要把
var arrKeys = x.Replace("sort=", "").Replace("\"", "").Replace(";", "").Split(',');
改为:
var arrKeys = x.trim_all().Replace("sort=", "").Replace("\"", "").Replace(";", "").Split(',');
还有就是把 sort = "update_time desc"; 直接改为:sort="update_time desc";-- 不包含空格即可。
done