[Lazarus] SQL select problem

Eric Kom erickom at metropolitancollege.co.za
Tue Nov 20 13:47:42 CET 2012


Good day all,

I got 3 rows in the table login that I used as credentials for 
authenticate.

the last usernameLogin field in the table as erickom and the first 2 ajm 
and ajm1.

on the authentication form, when I entered erickom and its password, 
everything goes well, when I entered an unknown username everything goes 
well as well like 'Failed to connect using: ' + getUsername; but when I 
entered the 2 first usernames that are in the table (ajm & ajm1) its not 
responding as expected, the if condition jump after display the message 
Retrieving information for: ' + retUsername to  Failed to connect using: 
' + getUsername. Abnormal behave.

Please view below my code and Thank in advance:

if MySQL55.Connected=True then begin;

         //SQLQueryMySQL.SQL.Text := 'SELECT usernameLogin, 
passwordLogin, fullNameLogin FROM scholarly.login WHERE usernameLogin = 
'':getUsername'' AND passwordLogin = '':getPasswordHash''';
         SQLQueryMySQL.SQL.Text := 'SELECT usernameLogin, passwordLogin, 
fullNameLogin FROM scholarly.login';
         SQLTransactionMySQl.StartTransaction;
         SQLQueryMySQL.Open;

      while not SQLQueryMySQL.EOF do begin
         //Retrieved data fields and assigned to a string variables
         retUsername := SQLQueryMySQL.Fields[0].AsString;
         retPassword := SQLQueryMySQL.Fields[1].AsString;
         retFullname := SQLQueryMySQL.Fields[2].AsString;

         if (getUsername = retUsername) AND (getPasswordHash = 
retPassword) then begin
            ShowString('Retrieving information for: ' + retUsername);
            StatusBarLogin.Update;
            sleep(2000);
            ShowString('Connected to server as: ' + retUsername + ', 
known as ' + retFullname);
         end
         else
            ShowString('Failed to connect using: ' + getUsername);
         SQLQueryMySQL.Next;
        end;

         SQLQueryMySQL.Close;
         SQLTransactionMySQL.Commit;
      end;
  except
   on D: EDatabaseError do
   ShowString('Connection to database as failed, please check your 
network.');
  end;

-- 
Kind Regards

Eric Kom

System Administrator - Metropolitan College
  _________________________________________
/ You are scrupulously honest, frank, and \
| straightforward. Therefore you have few |
\ friends.                                /
  -----------------------------------------
    \
     \
         .--.
        |o_o |
        |:_/ |
       //   \ \
      (| Kom | )
     /'\_   _/`\
     \___)=(___/

2 Hennie Van Till, White River, 1240
Tel: 013 750 2255 | Fax: 013 750 0105 | Cell: 078 879 1334
erickom at kom.za.net | erickom at metropolitancollege.co.za
www.kom.za.net | www.kom.za.org | www.erickom.co.za

Key fingerprint: 513E E91A C243 3020 8735 09BB 2DBC 5AD7 A9DA 1EF5





More information about the Lazarus mailing list