I am working on Typhon IDE (v.5.1 and FPC v.2.7.1)and am creating user login function, utilizing PostgreSQL 9.3 as database and Zeos 7.2 as data connector.
I have this following code:
// ZQ: TZQuery;
zq := ExecSQL('SELECT '+
'role_name, '+
'role_enabled, '+
'uid, '+
'role_uid, '+
'user_name, '+
'enabled, '+
'full_name, '+
'user_email '+
'FROM vw_usr_users '+
'where user_name = '+QuotedStr(AUserName)+' and enabled = ''Y'' and user_password = md5('+QuotedStr(APassword)+');');
ShowDebugSQL(zq.SQL);
ShowMessage(IntToStr(zq.FieldCount));
ShowMessage(zq.FieldByName('role_uid').AsString);
if not zq.IsEmpty then
begin
if zq.FieldByName('role_uid').AsString = '' then
begin
MessageDlg('Error','User have no role...',mtError, [mbOK], 0);
end
else
begin
Self.FId:=zq.FieldByName('uid').AsString;
Self.FUserName:=AUserName;
Self.FPassword:=APassword;
Self.fEnabled:= zq.FieldByName('enabled').AsString = 'Y';
Self.fRoleID:=zq.FieldByName('role_uid').AsString;
Self.FRoleName:=zq.FieldByName('role_name').AsString;
Self.FFullName:= zq.FieldByName('full_name').AsString;
Self.FEmail:= zq.FieldByName('user_email').AsString;
Self.Log(LOG_ACTIVITY_LOGIN);
Result := True;
end;
end
//......
- ExecSQL is a helper function, create TZQuery instance, assign connection and SQL, then open it.
When I run above code, I get error message stating that field 'role_uid' not found.
and the
ShowMessage(IntToStr(zq.FieldCount));
displayed only 6 fields, but helper ShowDebugSQL I made to show up SQL within a memo
ShowDebugSQL(zq.SQL);
gave me expected SQL
and correct result as I tested on pgAdmin:
I have tested the resulted field list using loop and got only 6 fields. Please help me point out what was wrong with my code. Many thanks.