1

在过去的 5 个小时里,我一直在努力让这个程序正常工作。我已经尝试将它修剪到可以工作并以此为基础的程度,但仍然没有成功。我非常感谢一些帮助,因为我必须在明天早上以工作状态展示这个项目。

我已经修剪了我的代码(因为它很长),但问题仍然很明显。

sqlCon.Connected := true;  //TSQLConnection
sqlUsers.Active := true;  //TSQLTable
sqlGames.Active := true;  //TSQLTable
sqlPredictions.Active := true;  //TSQLTable

sqlUsers.First;

//All following variables are integers.

rugbyChampionshipScore := 10;
rugbyChampionshipGamesPredicted:= 10;
rugbyChampionshipGamesCorrect:= 10;
rugbyChampionshipGamesAlmost:= 10;
rugbyChampionshipGamesWrong:= 10;
currieCupScore := 10;
currieCupGamesPredicted := 10;
currieCupGamesCorrect := 10;
currieCupGamesAlmost := 10;
currieCupGamesWrong := 10;

sqlQueryUpdate.Close;  //TSQLQuery

sqlQueryUpdate.CommandText := 'UPDATE users SET overallScore=:parScore, overallGamesPredicted=:parGamesPredicted, overallGamesCorrect=:parGamesCorrect, overallGamesAlmost=:parGamesAlmost, overallGamesWrong=:parGamesWrong, overallAccuracy=:parAccuracy WHERE username=:parUsername';
sqlQueryUpdate.Params.Clear;
sqlQueryUpdate.Params.CreateParam(ftUnknown, 'parUsername', ptUnknown).AsString := sqlUsers.FieldByName('username').AsString;
sqlQueryUpdate.Params.CreateParam(ftUnknown, 'parScore', ptUnknown).AsInteger := Round((rugbyChampionshipScore + currieCupScore) / (rugbyChampionshipGamesPredicted + currieCupGamesPredicted));
sqlQueryUpdate.Params.CreateParam(ftUnknown, 'parGamesPredicted', ptUnknown).AsInteger := rugbyChampionshipGamesPredicted + currieCupGamesPredicted;
sqlQueryUpdate.Params.CreateParam(ftUnknown, 'parGamesCorrect', ptUnknown).AsInteger := rugbyChampionshipGamesCorrect + currieCupGamesCorrect;
sqlQueryUpdate.Params.CreateParam(ftUnknown, 'parGamesAlmost', ptUnknown).AsInteger := rugbyChampionshipGamesAlmost + currieCupGamesAlmost;
sqlQueryUpdate.Params.CreateParam(ftUnknown, 'parGamesWrong', ptUnknown).AsInteger := rugbyChampionshipGamesWrong + currieCupGamesWrong;
sqlQueryUpdate.Params.CreateParam(ftUnknown, 'parAccuracy', ptUnknown).AsInteger := Round(100 / (rugbyChampionshipGamesPredicted + currieCupGamesPredicted)*(rugbyChampionshipGamesCorrect + currieCupGamesCorrect) + ((rugbyChampionshipGamesAlmost + currieCupGamesAlmost)/2));

sqlQueryUpdate.ExecSQL();
sqlQueryUpdate.Close;

sqlUsers.Active := false;
sqlGames.Active := false;
sqlPredictions.Active := false;
4

1 回答 1

-1

这很奇怪。我遵循了每个评论者的建议,我发现我创建参数的顺序会影响查询。

不起作用的代码:

sqlCon.Connected := true;
sqlUsers.Active := true;
sqlGames.Active := true;
sqlPredictions.Active := true;

sqlUsers.First;

sqlQueryUpdate.Close;

sqlQueryUpdate.SQL.Clear;
sqlQueryUpdate.SQL.Add('UPDATE users SET overallScore=:parScore WHERE username=:parUsername');
sqlQueryUpdate.Params.Clear;

sqlQueryUpdate.Params.CreateParam(ftUnknown, 'parUsername', ptUnknown).AsString := sqlUsers.FieldByName('username').AsString;
sqlQueryUpdate.Params.CreateParam(ftUnknown, 'parScore', ptUnknown).AsInteger := 200;


sqlQueryUpdate.ExecSQL();
sqlQueryUpdate.Close;

有效的代码:

...
sqlQueryUpdate.Params.CreateParam(ftUnknown, 'parScore', ptUnknown).AsInteger := 200;
sqlQueryUpdate.Params.CreateParam(ftUnknown, 'parUsername', ptUnknown).AsString := sqlUsers.FieldByName('username').AsString;
...

所以简单地交换这两条线就可以了?谁能告诉我为什么?我好奇...

于 2013-10-04T14:47:37.280 回答