Need a little help with SQLite and FireDAC.

Need a little help with SQLite and FireDAC.

A pretty simple query where I look up a username and when found pull down it's associated fields into variables. But I need to do error checking along the way; i.e. if connection fails and if username is not found, etc.

Basic code I am working with is below, would someone mind helping me tweak this code to take care of dealing with the error conditions? And of course if I have made an mistakes in my code to begin with.

FDConnection1.DriverName := 'SQLITE';
FDConnection1.Params.Values['Database'] := 'C:\Users\Admin\Desktop\test_app\TestDatabase.db3';

FDConnection1.Open;

query := TFDQuery.Create(nil);
    
query.Connection := FDConnection1;
query.SQL.Text := 'Select password from Test_Table where username=usernameEntered';
query.Open();

dbPassword := query.FieldByName('password').AsString;
dbName := query.FieldByName('Name').AsString;

query.Close;
query.DisposeOf;

Comments