[prev in list] [next in list] [prev in thread] [next in thread] 

List:       midware
Subject:    Re: [midware] Need advise
From:       "Arthur Hoornweg" <arthur.hoornweg () wanadoo ! nl>
Date:       2002-12-18 11:49:45
[Download RAW message or body]

> I would like to create a simple query server that provides datasets to
> remote clients and resolves changes back.  I would also like the server
> to execute raw SQL from the cient.

I think I would use an ADO dataset. Execute the query on your
Midware server, save the result into an XML or ADT file, load
this file into a tMemorystream and send it to the client as
a "datagram" (not as a tMwbuffer - much too slow).


The code below is untested and has no exception handling but it
should give you some idea on how it could work.


Make sure the Ado database connection on the midwar server
uses the following properties: cursorlocation=clUseclient,
cursortype=ctstatic and locktype=ltbatchoptimistic.
This will keep your Midware server "stateless" with no transactions
open just as it should be for a multi-user system.

At the client side, you receive the datagram, save it into an XML file
again, and load it into a tAdodataset a form (simply using
tadodataset.loadfromfile). This form needs only a tadodataset and
tdatasource plus some visual db-aware components. As soon as
you set tadodataset.active to TRUE, you'll see the results on
your screen.

The client computer can now modify the data and POST all changes.
Subsequently save the XML file again, and send it back to the server
using the same method I described above.
The server must now load the xml file it into a tadodataset again,
connect this tadodataset to an active tAdoconnection and call
"updatebatch". That will post all changes to the database.








Uses classes, sysutils,adodb, Adoint;

...

// function to retrieve data from a database and pack it into a
// tmemorystream, which can be sent through a Midware datagram:

Function GetResultFromDatabase (connection:tadoconnection;
sqlcommand:String) : tmemorystream;
VAR RS: _recordset;
               tf : tfilestream;
begin
  result:=tmemorystream.create;
  rs:=conn.Execute (sqlcommand);
  rs.save ('test.xml');
  rs:=NIL;
  tf:=tfilestream.create('test.xml',fmopenread);
  result.copyfrom(tf,0);
  tf.free;
  deletefile('test.xml');
end;



PS don't forget to destroy the tMemorystream once you've sent it
as a datagram. Or else you'll have a HUGE memory leak in your
program.





---
My outgoing mail is checked for viruses.

Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.427 / Virus Database: 240 - Release Date: 06.12.2002


_______________________________________________
Midware mailing list [http://www.elists.org/mailman/listinfo/midware]
Visit our website at: http://www.overbyte.be

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic