#1 2011-01-25 17:15:34

corchi72
Member
Registered: 2010-12-10
Posts: 232

How to read data from a table in the server?

To read the data from the sever usually write:


   Model   := GetDatabaseModel;
   Database:= TSQLRestClientDB.Create(Model, nil, filename, TSQLRestServerDB);
   TSQLRestClientDB(Database).Server.CreateMissingTables(0);


....


procedure TForm1.LoadTempForUser(const AUser: TSQLUser;
  const AList: TStrings);
var
Temp: TSQLTemp;
fIds: TIntegerDynArray;
begin

  if AUser.Temp.SourceGet(Database, AUser.ID, fIds) then
  begin
  Temp:= TSQLTemp.CreateAndFillPrepare(Database, fIds);
  AList.BeginUpdate();
  AList.Clear();
  try
    while Temp.FillOne do
      AList.AddObject(Format('%s', [UTF8ToString(Temp.Name)]), Pointer(Temp.id));
  finally
    AList.EndUpdate();
    FreeAndNil(Temp);
  end;
  end
  else
    AList.Clear();

end;

but if someone changes the values in the table (Es:"temp") in the server, I does not know how to update data on the client side.

Offline

#2 2011-01-26 06:51:12

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: How to read data from a table in the server?

It sounds to me like I already answered to this question to you
http://synopse.info/forum/viewtopic.php?pid=1058#p1058
smile

Or perhaps I'm misunderstanding.

Offline

#3 2011-01-26 08:23:26

corchi72
Member
Registered: 2010-12-10
Posts: 232

Re: How to read data from a table in the server?

Yes I can confirm, but it does not work, I created a table of relations between the user and the "temp" table and if I run the command
Database.UpdateFromServer ([temp.Users], refreshed) does not work

  TSQLTemp = class(TSQLRecord)
  private
   ...
    fUsers: TSQLTempUsers;
  published
   ...  
    property Users: TSQLTempUsers read fUsers;
   
  end;

 TSQLUser = class;
  TSQLTempUsers = class(TSQLRecordMany)
  private
    fSource: TSQLTemp;
    fDest: TSQLUser;
  published
    property Source: TSQLTemp read fSource;
    property Dest: TSQLUser read fDest;

  end;

// load list of Temp assigned to the given User
  temp:= TSQLTemp.Create();
  try
    Database.UpdateFromServer ([temp.Users], refreshed);
    temp.Users.SourceGet(Database, User.ID, clientsIds);
    for i:= low(clientsIds) to high(clientsIds) do
      begin
        // find the client on the list (by ID)
        for j:= 0 to CheckListBox1.Count -1 do
          if Integer(CheckListBox1.Items.Objects[j]) = clientsIds[i] then
              CheckListBox1.Checked[j]:= true;
      end;
  finally
    temp.Free();
    FreeAndNil(User);
  end;

Probably I did not understand how it works the command "Database.UpdateFromServer" with the "TSQLRecordMany" tables

Offline

#4 2011-01-26 08:51:07

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: How to read data from a table in the server?

As far as I understand your code, you should use UpdateFromServer([temp]) instead.

You need to refresh the temp record, not the temp.Users record.

Then SouceGet() will create a dedicated SQL query, so it will work without need to refresh.

Offline

#5 2011-01-26 10:49:49

corchi72
Member
Registered: 2010-12-10
Posts: 232

Re: How to read data from a table in the server?

Sorry but maybe I have not explained,
I use sqlite Manager to view real-time changes in the temp table.
If I run the program and I execurte Database.Update (temp), and then I go to see sqlite Mangager I see new recorcd of temp.
Instead, if I run the program 2 times and one run an update, I see the change in sqlite manager and I can not see in the second program.
So I asked you how can I see the correct data from DB and you told me to use    Database.UpdateFromServer ([temp], refreshed) but the data its not  the same that I read by  sqlite manager.Why?

Offline

#6 2011-01-26 13:42:44

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: How to read data from a table in the server?

I guess... you're not launching one server with two client, but instancing two server instances, with two associated clients...

If you're still using this code:

Model   := GetDatabaseModel;
   Database:= TSQLRestClientDB.Create(Model, nil, filename, TSQLRestClientDB);
   TSQLRestClientDB(Database).Server.CreateMissingTables(0);

This is wrong for the client, because each TSQLRestClientDB creates its own TSQLRestClientDB instance.
This is only good for the server.

Offline

#7 2011-01-26 14:09:23

corchi72
Member
Registered: 2010-12-10
Posts: 232

Re: How to read data from a table in the server?

I do not use this configuration. Now I try to reduce my schedule for an example and try to send


   Model   := GetDatabaseModel;
   Database:= TSQLRestClientDB.Create(Model, nil, filename, TSQLRestServerDB);
   TSQLRestClientDB(Database).Server.CreateMissingTables(0);

Offline

#8 2011-01-26 16:07:23

corchi72
Member
Registered: 2010-12-10
Posts: 232

Re: How to read data from a table in the server?

How can I send you a sample of my program?

Offline

#9 2011-01-26 16:15:07

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: How to read data from a table in the server?

You should use Database := TSQLite3HttpClient.Create... from unit SQLite3HttpClient.pas to create the client.

Use some link tool like http://pastebin.mozilla.org/to send some code.

Offline

#10 2011-01-26 16:24:14

corchi72
Member
Registered: 2010-12-10
Posts: 232

Re: How to read data from a table in the server?

I can not send you a rar file?

Offline

#11 2011-01-26 16:45:55

corchi72
Member
Registered: 2010-12-10
Posts: 232

Re: How to read data from a table in the server?

Do I must create a program that makes a server?

Offline

#12 2011-01-26 16:48:30

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: How to read data from a table in the server?

Just send some code in pastebin.

We'll need both server and client part.

Offline

Board footer

Powered by FluxBB