gpt4 book ai didi

德尔福: “Parameter object is improperly defined. Inconsistent or incomplete information was provided.”

转载 作者:行者123 更新时间:2023-12-03 14:56:32 25 4
gpt4 key购买 nike

这是一个执行以下操作的函数:

  • Create a random Token with 8 length
  • Insert that Token into the Database
  • If the User has already a token, update it.

  • If the User has no token, insert it.

procedure createToken(BenuNr: integer);
var
AQ_Query: TADOQuery;
strToken: string;
intZaehler: integer;
const cCharSet: string = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
begin
//Random String as Token
SetLength(strToken, 8);
for intZaehler := 1 to 8 do
begin
strToken[intZaehler] := cCharSet[1+Random(Length(cCharSet))];
end;
//Inserts the Token into the Database
with AQ_Query do
begin
try
AQ_Query := TADOQuery.Create(nil);
ConnectionString := strConnectionString;
SQL.Text := 'if EXISTS(select * from TOKN where BENU_NR = :paramBenu_NR) begin update TOKN set TOKEN = :paramTOKEN where BENU_NR = :paramBenu_NR end else insert into TOKN (BENU_NR, TOKEN) values (:paramBENU_NR,:paramTOKEN)';
Prepared := true;
Parameters.ParamByName('paramBENU_NR').DataType := ftInteger;
Parameters.ParamByName('paramTOKEN').DataType := ftString;
Parameters.ParamByName('paramBENU_NR').Value := BenuNr;
Parameters.ParamByName('paramTOKEN').Value := strToken;
ExecSQL; //<< Exception as stated in the title
finally
Free;
end;
end;
end;

执行此操作会引发标题中所述的异常。我把上面的例子删掉了,瞧:不再有异常(exception)了。不幸的是我不明白为什么?

procedure createToken();
var
AQ_Query: TADOQuery;
strToken: string;
intZaehler: integer;
const cCharSet: string = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
begin
//Random String as Token
SetLength(strToken, 8);
for intZaehler := 1 to 8 do
begin
strToken[intZaehler] := cCharSet[1+Random(Length(cCharSet))];
end;
//Inserts the Token into the Database
with AQ_Query do
begin
try
AQ_Query := TADOQuery.Create(nil);
ConnectionString := strConnectionString;
SQL.Text := 'update TOKN set TOKEN = :paramTOKEN where BENU_NR = 1';
Prepared := true;
Parameters.ParamByName('paramTOKEN').DataType := ftString;
Parameters.ParamByName('paramTOKEN').Value := strToken;
ExecSQL; //<< No more exception
finally
Free;
end;
end;
end;

似乎每个 SQL 只允许有 1 个参数。我正在使用 Delphi 7 和 MSSQL Server 2005

知道如何修复第一个代码块以使其正常工作吗?

最佳答案

要实现此目的,您必须在 SQL 子句中仅使用每个参数一次。要多次使用相同的参数,只需用新名称声明它即可。我不知道为什么会这样,但我知道这可能很烦人。

关于德尔福: “Parameter object is improperly defined. Inconsistent or incomplete information was provided.”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1312010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com