Jump to content

QUERIES IN UNIGUI : When using a MySql database, Delphi components work in the same way as in VCL codes ?.


SergioFeitoza

Recommended Posts

  I use the same database components to connect – as well - the VCL Delphi version and the Unigui version.

In the VCL version, when I change a value in my screen the change is automatically done in the MySql tables. I suppose that this is the main function of the database components.

To do this in the VCL version it is sufficient to use the “Delphi” statements like

       try

        SQL.Text := 'SELECT * FROM t_lastcalc';

        Open;

        Append;

          FieldByName('Fuel').AsString := tipo_projetoSTR;

          FieldByName('TypeOfPlant').AsString := tipo_plantaSTR;

        Post;

      finally

        Free;

      end;

 

However, when doing the final tests of my Unigui code, to deploy in the web, I noticed that for the Unigui version the phases above work when the code is running but they are not sufficient to save the changes automatically in the MySql database.  I do not know if I did some undue modification to provoke this.

 

In my Unigui version, to succeed in updating the MySql data base I need to use the classical MySql queries like:

 

      AddNewUser := TMyQuery.Create(nil);

        try

          AddNewUser.Connection := uniMainModule.MyConnection;

          AddNewUser.SQL.Clear;

          AddNewUser.SQL.Add('INSERT INTO hpl.USERS (LOGIN,DATEREGISTER) VALUES (:LOGIN,:DATEREGISTER);');

          AddNewUser.ParamByName('LOGIN').AsString := LOGIN;

          AddNewUser.ParamByName('DATEREGISTER').AsDateTime := now;

          AddNewUser.Execute;

        finally

          AddNewUser.Free;

        end.

 

As I work with a table with some 80 columns it is hard to update the tables using MySql queries.

I think I am missing something. Otherwise, what would be the reason for not using only Delphi native components?

Could you please clarify if, in my Unigui code, I am obliged to use the MySql statements instead of – only - the components language that I use in the VCL version ?

Thanks, in advance.

Link to comment
Share on other sites

2 hours ago, SergioFeitoza said:

       try

        SQL.Text := 'SELECT * FROM t_lastcalc';

        Open;

        Append;

          FieldByName('Fuel').AsString := tipo_projetoSTR;

          FieldByName('TypeOfPlant').AsString := tipo_plantaSTR;

        Post;

      finally

        Free;

      end;

 

I use the same method with VCL & Unigui without problem.

Actually, I have large application, built as VCL desktop, then I have create Unigui application, that share most of code with same DataModule shared between two application without problem.

 

If you can attach a test case, I will look into it to see if you have any issue with your code

 

PS: I use Unidac not  Mydac.

Link to comment
Share on other sites

 

6 hours ago, Mohammed Nasman said:

I use the same method with VCL & Unigui without problem.

Actually, I have large application, built as VCL desktop, then I have create Unigui application, that share most of code with same DataModule shared between two application without problem.

 

If you can attach a test case, I will look into it to see if you have any issue with your code

 

PS: I use Unidac not  Mydac.

Thank you Mohammed  My problem to send  a test case is that my code is a very big one and it is  almost impossible to separate a part representative of the problem (see the figure)

I constructed the program  exactly as you describe your case . I use MySql and I think that -  from the point of view of  saving the data in MySql tables -  the version Unigui was working correctly before. That is, when I changed the boxes in my code (figure) the MySql table was updated. Now what happens is that when I am running the code  everything seems to be OK . I change values and they are changed  but the changes do not aarive to the MySql table. It is like opening MySql workbench , open a table, change a valure BUT do not click the APPLY  button. I do not know the reason.  It iss like being protected

Let me put the question in another way:    Do you know any small demo usinh Unigui + MySql + any database component ? Maybe Unidac.

SWD.png

Link to comment
Share on other sites

3 hours ago, SergioFeitoza said:

Thank you Mohammed  My problem to send  a test case is that my code is a very big one and it is  almost impossible to separate a part representative of the problem (see the figure)

I constructed the program  exactly as you describe your case . I use MySql and I think that -  from the point of view of  saving the data in MySql tables -  the version Unigui was working correctly before. That is, when I changed the boxes in my code (figure) the MySql table was updated. Now what happens is that when I am running the code  everything seems to be OK . I change values and they are changed  but the changes do not aarive to the MySql table. It is like opening MySql workbench , open a table, change a valure BUT do not click the APPLY  button. I do not know the reason.  It iss like being protected

Let me put the question in another way:    Do you know any small demo usinh Unigui + MySql + any database component ? Maybe Unidac.

In all of my projects i'm using UniGUI + MyDAC + MYSQL without any problems.

Link to comment
Share on other sites

34 minutes ago, Hayri ASLAN said:

In all of my projects i'm using UniGUI + MyDAC + MYSQL without any problems.

Thanks for your comments. L will try to  identificate what is not working well here in the update of the MySql table.

The test I will do is the following .MyDac.bmp

I use the code below in the VCL version of my code to duplicate a line of the “MyDacQuery” associated with a table in the MySql. I just click the button with the code below and a new line is created duplicating an existing. It works perfectly and the MySql table is updated doing only this

In my Unigui version I use exactly the same thing and components.

In your opinion this should work well in the Unigui version (from the point of view of the MySql being updated) ?

 

procedure TF0D.DuplicateLineofTableClick(Sender: TObject);

var

  i: integer;

begin

  with MyDacConnection do

  begin

    for i := 0 to DataSetCount - 1 do DataSets[i].DisableControls;

  end;

  try

    DuplicateCurrentRecordJ(MyDacQuery);

  except

    ShowMessage ('Error duplicating a line of MyQuery');

  end;

 

  with MyDacConnection  do

  begin

    for i := 0 to DataSetCount - 1 do  DataSets[i].EnableControls;

  end;

end;

 

procedure TF0D.DuplicateCurrentRecord (aDataSet: TMyQuery);

var

  Data: array of variant;

  aRecord: array of TVarRec;

  i: integer;

  max: integer;

begin

  max := aDataSet.fields.count - 1;

  // set the lenghth of the arecord array to be the same as the number of elements in the data array

  SetLength(aRecord, max + 1);

  SetLength(Data, max + 1);

  // set the variant type pointers to the data array

  for i := 0 to max do

  begin

    aRecord[i].VType := vtVariant;

    aRecord[i].VVariant := @Data[i];

  end;

  // Copy the Record to the Array

  for i := 0 to max do

  begin

    if i <> 1 then

      Data[i] := aDataSet.fields[i].value

    else

      Data[i] := aDataSet.fields[i].value + '_bis';    // change only the title of the new record

  end;

  // finally append the record in one go

  aDataSet.AppendRecord(aRecord);

end;

Link to comment
Share on other sites

Are you using CachedUpdate property?

 

May you have a transaction without commit?

 

As I said before, calling Query.Post will save data immediately to Mysql from Unigui app.

try to start new project with one form that add data to one table on mysql, and try to see if it will do the update or not, if not, please post here so we can check it with you.

Link to comment
Share on other sites

3 minutes ago, Mohammed Nasman said:

Are you using CachedUpdate property?

 

May you have a transaction without commit?

 

As I said before, calling Query.Post will save data immediately to Mysql from Unigui app.

try to start new project with one form that add data to one table on mysql, and try to see if it will do the update or not, if not, please post here so we can check it with you.

Thank you very much Mohammed. You are right. Yesterday I checked again and corrected a mistake I was doing . It is now working well as before and Mydac components are working correctly

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...