简体   繁体   English

无法解决这个错误

[英]cant figure this error out

Can you guys see any obvious error in this query? 你们可以在这个查询中看到任何明显的错误吗? The error im getting is: `Unknown column 003ADF50 in field list. 我得到的错误是:`字段列表中的未知列003ADF50。 003ADF50 wtf? 003ADF50 wtf?

query << "UPDATE `record` SET `record` = " << lastRecord << ", `time` = " << time;

What looks to be happening here is that one of those values that you're injecting into your sql is coming up as 003ADF50. 这里看起来正在发生的是你注入你的sql中的那些值之一即将出现为003ADF50。 (Probably the time value?) (可能是time价值?)

Brendan Long is correct: you should be using prepared statements to properly handle parameters in your SQL. Brendan Long是正确的:您应该使用预准备语句来正确处理SQL中的参数。 Manually concatenating strings leads to quoting problems like you see here, which can be serious security problems in your code. 手动连接字符串会导致引用问题,就像您在此处看到的那样,这可能是您代码中的严重安全问题。 The specific quoting problem you're running into here is that the parameters aren't quoted in your resulting query string. 您在此处遇到的具体引用问题是您的结果查询字符串中未引用参数。 If you were typing the SQL manually into the mysql client, you'd say something like: 如果你手动将SQL输入mysql客户端,你会说:

UPDATE `record` set `record` = 'foo';

If instead you left out the quotes on 'foo' , you'd have: 如果你把'foo'上的引号遗漏了,你就会:

UPDATE `record` set `record` = foo;

which is trying to set the record column to the value of the foo column, rather than the literal string 'foo' . 它试图将记录列设置为foo列的值,而不是文字字符串'foo' The same thing is happening with the SQL you're generating from your C++. 使用C ++生成的SQL也会发生同样的事情。 Trying to solve this by manually adding quotes isn't a good idea -- what happens when the string parameter contains a quote character? 试图通过手动添加引号来解决这个问题并不是一个好主意 - 当字符串参数包含引号字符时会发生什么? The best thing to do is to use prepared statements. 最好的办法是使用准备好的语句。

Also, Google "little bobby tables" for a well-known XKCD comic about sql parameter injection, and consider what would happen if Bobby Tables' name found its way into one of your program's variables. 另外,谷歌有关sql参数注入的着名XKCD漫画的“小武器表”,并考虑如果Bobby Tables的名字进入你的程序变量之一会发生什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM