Search code examples
mysqllazarus

How to make request to sql and fetch results using lazarus


I have problem making sql request such as

SELECT * FROM 'users' WHERE 1

using lazarus SqlQuery,SqlTransaction and MySql55Connection.But when I'm trying to open SqlQuery(

SqlQuery1.Open;

) it causes exception:

Sql statement not set.

Solution

  • I understood my problem. I should for first set sql request and then open query and connection. Like this:

    SqlQuery1.Sql.text:='SELECT FROM "users" WHERE 1'
    MySql55Connection1.Open;
    SqlQuery1.Open;
    while not SqlQuery1.EOF
    begin
      //fetch result
      SqlQuery1.Next;
    end;
    SqlQuery1.Close;
    MySql55Connection1.Close;//Close connection