#1 2015-01-28 10:27:22

Kais2000
Member
Registered: 2015-01-28
Posts: 3

Transfer Data (MSSQL)

Hi, I am a newbie and I could need some help.
I would like to transfer data over the internet into identical MSSQL tables.
I can easily get data from the server like this:

    

...
   aModel   := DataModel;
   aClient  := TSQLHttpClientWinHTTP.Create(SERVER,SERVER_PORT,aModel);
   AMyTable := TMyTable.CreateAndFillPrepare(aClient,'ID>0');

   while AMyTable.FillOne do
     begin
    

     Memo1.Lines.Add( AMyTable.MyDataField );

     end;

    AMyTable.Free;
    aClient.Free;
    aModel.Free;
...

Now I would like to store the data on my Server.
My first thought was the "oldfashioned" way:

...while AMyTable.FillOne do
     begin

     MyAdoQuery.SQL.Add('INSERT MyTable (MyDataField) Values( ' + AMyTable.MyDataField + ')')

     end;
   MyAdoQuery.ExecSQL; 

My second thought:
mORMot is such a great piece of software architecture, they probably have impelemented this task in a much more elegant way.

Thank you for any hints /examples.

Offline

#2 2015-01-28 18:37:24

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

Re: Transfer Data (MSSQL)

'ID>0' does not mean anything - so you can avoid writing such an always true condition.

For sending data on the server, just use the ORM, and the TSQLRest.Add() method.

Offline

#3 2015-01-29 14:01:05

Kais2000
Member
Registered: 2015-01-28
Posts: 3

Re: Transfer Data (MSSQL)

Yes, thank you, the "just use ..." suggests a quick and easy implementation.

I aleady found

     AClient.Add()

and even better   

      AClient.BatchStart(TPerson);
      AClient.BatchAdd(APerson,true);
      AClient.BatchSend(Res);

I only found TSQLRestClient and TSQLRestServer, but I need to store the data in my local MSSQL Database.
So my question is:

- Should I use TSQLRestClientDB? And how do I connect ?

Offline

#4 2015-01-29 14:30:42

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

Re: Transfer Data (MSSQL)

Create a 2nd TSQLRestServerDB/TSQLRestClientDB, then register the local MSSQL database, and BatchAdd() on this one.

But I do not understand your design?
Which not directly connect from the client to the server, via HTTP, and use the local MSSQL database as storage on the server side?

Offline

#5 2015-01-30 09:51:16

Kais2000
Member
Registered: 2015-01-28
Posts: 3

Re: Transfer Data (MSSQL)

Of course I am open for any better solution.
Is there any example for " directly connect from the client to the server, via HTTP, and use the local MSSQL database as storage on the server side" ?
Thank you very much!

Offline

#6 2015-01-30 10:12:03

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

Re: Transfer Data (MSSQL)

Please take a look at sample "28 - Simple RESTful ORM Server".
It is for PostgreSQL, but you just have one line to change so that it would use MSSQL.

Take a look at the documentation and the samples supplied.
Especially http://synopse.info/files/html/Synopse% … ml#TITL_27

Offline

Board footer

Powered by FluxBB