Recent

Author Topic: fpweb and sqlquery  (Read 4735 times)

dasa2

  • New member
  • *
  • Posts: 9
fpweb and sqlquery
« on: June 14, 2021, 10:19:02 pm »
I am building an HTTP server application with fpweb and want to run a sqlquery to verify that the username exist in db but getting an access violation when i try to run my sqlquery. What am i doing wrong here?

 with SQLQuery1 do -> SQLQuery1 = <TSQLQUERY> = Cannot access memory at address 0x170

Code: Pascal  [Select][+][-]
  1. unit umain;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   SysUtils, Classes, httpdefs, fpHTTP, fpWeb, SQLDB, DB, SQLite3Conn, httproute;
  9.  
  10. type
  11.  
  12.   { TFPWebModule1 }
  13.  
  14.   TFPWebModule1 = class(TFPWebModule)
  15.     SQLConnector1: TSQLConnector;
  16.     SQLTransaction1: TSQLTransaction;
  17.     SQLQuery1: TSQLQuery;
  18.     procedure DoStart(ARequest:TRequest; AResponse : TResponse);
  19.   private
  20.  
  21.   public
  22.  
  23.   end;
  24.  
  25. var
  26.   FPWebModule1: TFPWebModule1;
  27.  
  28. implementation
  29.  
  30. {$R *.lfm}
  31.  
  32. { TFPWebModule1 }
  33.  
  34.  
  35. procedure TFPWebModule1.DoStart(ARequest:TRequest; AResponse : TResponse);
  36. var user : String;
  37. begin
  38.   user := ARequest.ContentFields.Values['user'];
  39.   if user = EmptyStr then
  40.     with AResponse.Contents do
  41.     begin
  42.       Add('<form action="' + ARequest.URI + '" method="POST"');
  43.       Add('<label for="user">User:</label>');
  44.       Add('<input type="text" name="user" id="user" />');
  45.       Add('<input type="submit" value="Check user" />');
  46.       Add('</form>');
  47.     end
  48.   else
  49.     begin
  50.       with SQLQuery1 do
  51.         begin
  52.           Close();
  53.           Clear();
  54.           SQL.Text:='SELECT username, password FROM user WHERE username='+QuotedStr(user);
  55.           SQLConnection.Connected:=True;
  56.           SQLTransaction.Active:=True;
  57.           SQLQuery1.Active:=True;
  58.           Open();
  59.         end;
  60.       if SQLQuery1.RecordCount = 1 then
  61.         AResponse.Content := 'user: ' + user +'!'
  62.       else
  63.         AResponse.Content := 'Bad login';
  64.     end;
  65. end;
  66.  
  67.  
  68. initialization
  69.   RegisterHTTPModule('TFPWebModule1', TFPWebModule1);
  70.   HTTPRouter.RegisterRoute('*', @FPWebModule1.DoStart);
  71.  
  72. end.
  73.  
  74.  
« Last Edit: June 14, 2021, 10:58:59 pm by dasa2 »

iLya2IK

  • New Member
  • *
  • Posts: 34
Re: fpweb and sqlquery
« Reply #1 on: June 15, 2021, 04:25:23 pm »
I think, that you have not created an instance of the class and are trying to access it.
Look carefully - SQLQuery1 is not even exist

egsuh

  • Hero Member
  • *****
  • Posts: 1273
Re: fpweb and sqlquery
« Reply #2 on: June 16, 2021, 04:04:13 am »
What does TSQLQuery.Clear do?  Aren't you trying to SQLQuery1.SQL.Clear; ?

 

TinyPortal © 2005-2018