下午,5点54分钟,正当我美滋滋的等待下班的时候一则“不幸”找上了我,我心里咯噔一下,心想完蛋
看到有bug,我第一时间就去看报错信息,以至于忽略了填写的信息,导致成了我sb的开始。 初看报错信息,我不由得轻蔑一笑:“就这么一个小问题,还想耽误小爷下班?不可能!” 随即,我又疑惑了起来,好端端的代码怎么还少了一块?
当我胸有成竹的找到功能代码的时候,我沉默了。这查询的sql没理由会报错啊,代码都是完整的啊,怎么回事? 难道是浏览器缓存?或者是页面没刷新?代码没同步? 不对啊,这是后端的问题!
string cust = "SBen'ergy";
string objid = "19ba1a95-f3e0-4971-89c7-e53e584d4d25";
string glCust = "";
string custSql = string.Format("select cust.*,user.Name as name1 from i_D146801Sr4if42cp65q4jshuo9b02hii2 cust left join H_User user on user.objectid=cust.OwnerId where cust.F0000001='{0}' and cust.objectid!='{1}' and cust.objectid!='{2}'", cust, objid, glCust);
眼看已经到了下班那个点,我更是汗流浃背。而当我找到报错的那个信息之后,我沉默了。这有个单引号在上面,难怪会报错。 而我再三确认,这是不是填错了,得到的答案都是对的。
好吧好吧,谁让我是个可怜的打工仔。
string cust = "SBen'ergy";
string objid = "19ba1a95-f3e0-4971-89c7-e53e584d4d25";
string glCust = "";
if(cust.Contains("'"))
{
cust = cust.Replace("'", @"\'"); // @强制不转换,而是保留着转义字符,到sql再转换
}
string custSql = string.Format("select cust.*,user.Name as name1 from i_D146801Sr4if42cp65q4jshuo9b02hii2 cust left join H_User user on user.objectid=cust.OwnerId where cust.F0000001='{0}' and cust.objectid!='{1}' and cust.objectid!='{2}'", cust, objid, glCust);
到此,也是结束了。虽然一整个问题很简单,但我只想说:“麻麻我长大了,我长见识了!原来公司名还会有单引号的。”
感谢各位姥爷的观看,祝各位姥爷面试必成功,跳槽必涨薪,早九晚六周末双休,父母健康,家庭和睦,万事如意,心想事成......