我使用Delphi XE3並使用SQLite數據庫和DB express。Delphi + SQLite +數據庫快速選擇帶參數錯誤
這是我user validation
代碼:
function validateUser(UserName, Password: string): Boolean;
var
AParams: TParams;
SQLTxt: string;
MD5 : TIdHashMessageDigest5;
RecCount: integer;
begin
AParams := TParams.Create(nil);
MD5 := TIdHashMessageDigest5.Create;
try
Result := False;
AParams.CreateParam(ftString, 'username', ptInput).Value := UserName;
AParams.CreateParam(ftString, 'password', ptInput).Value :=
MD5.HashBytesAsHex(MD5.HashString(Password));
SQLTxt := 'SELECT login_id FROM login WHERE '+
'login_username = :username AND login_password = :password ;';
with Form1.sqlqry1 do
begin
SQL.Clear;
SQL.Text := SQLTxt;
Params := AParams;
//Params.Items[0].Value := AParams.Items[0].Value;
//Params.Items[1].Value := AParams.Items[1].Value;
Prepared := true;
Open;
end;
RecCount := Form1.sqlqry1.RecordCount;// I have error here
if RecCount = 0 then
Result := False
else
Result := True;
// end
finally
AParams.Free;
MD5.Free;
end;
end;
應用告訴我[0x0005]: Operation Not Supported
錯誤。
什麼問題?爲什麼?
這是[已知問題](http://edn.embarcadero.com/article/28494)。我會通過執行'SELECT COUNT(*)FROM ...'查詢並從字段中獲取值來解決此問題。 – TLama
@TLama:不適用於COUNT(*); –
它應該。 SQLite支持'COUNT'函數,所以如果你執行這樣的查詢,你應該從第一個字段'SQLQuery1.Fields [0] .AsInteger'獲得計數。這將是替換有問題的'RecordCount'屬性。 – TLama