[英]SQLite Delphi thowing up incorrect exception
Project CompetitionServer.exe raised exception class ESQLiteException with message 'Error executing SQL.
项目CompetitionServer.exe引发异常类ESQLiteException,并显示消息“执行SQL错误。
Error [1]: SQL error or missing database.错误[1]:SQL错误或缺少数据库。
"INSERT INTO MatchesTable(MatchesID,RoundID,AkaFirstName,AoFirstName)VALUES(1,2,p,o)": no such column: p'.“将INERT插入MatchesTable(MatchesID,RoundID,AkaFirstName,AoFirstName)VALUES(1,2,p,o)”:没有这样的列:p'。 Process stopped.
进程已停止。 Use Step or Run to continue.
使用“步骤”或“运行”继续。
Yes, p is NOT a column, it is the data I am trying to insert. 是的,p不是列,而是我要插入的数据。 How can I fix this problem?
我该如何解决这个问题?
In SQL, string constants that are data must be enclosed in quotes. 在SQL中,作为数据的字符串常量必须用引号引起来。 Otherwise the string is interpreted as a keyword, table name, or column name, which is what's happening here.
否则,字符串将被解释为关键字,表名或列名,这就是这里发生的情况。 Use 'p' instead of plain p.
使用“ p”代替普通的p。
You value 'p' is a constant, so you need to put it in quotes. 您的值'p'是一个常数,因此您需要将其用引号引起来。 So the statement needs to be
因此,该声明需要
INSERT INTO MatchesTable(MatchesID,RoundID,AkaFirstName,AoFirstName)VALUES(1,2,'p','o')
You have to use SQL parameters. 您必须使用SQL参数。 The standard Delphi approach to that:
标准的Delphi方法:
Query1.SQL.Text := 'INSERT INTO MatchesTable(MatchesID,RoundID,AkaFirstName,AoFirstName)VALUES(1,2,:p,:o)';
Query1.Params[0].Value := ...;
Query1.Params[1].Value := ...;
Query1.ExecSQL;
But details may depend on the data access components you are using. 但是细节可能取决于您使用的数据访问组件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.