Close but not exactly there
- From: "Larry" <lkillen@xxxxxxxxxxx>
- Date: Wed, 28 Jun 2006 12:07:33 -0400
Below is my little test app. It works but is really chatty and I don't
think it has to be. What is in the buffer below is actually coming from a
rabbit processor and memory is limited so I think is is very wasteful to
send the meta data with every packet. Yet I don't know how to teach the
Client Dataset.
I thought that since I had already instanciated the fields in the
ClientDataset, it would not need the Meta data but it chokes when I leave it
out.
But my ultimate question is still the same. How can I write this data to a
Database, efficiencely and safely?
In real operations, the buffer would be coming via TCP/IP.
type
TForm1 = class(TForm)
....
ClientDataSet1: TClientDataSet;
Button1: TButton;
ClientDataSet1TXID: TSmallintField;
ClientDataSet1GroupID: TSmallintField;
ClientDataSet1ScaleID: TSmallintField;
ClientDataSet1LineID: TSmallintField;
ClientDataSet1StationID: TSmallintField;
ClientDataSet1Weight: TBCDField;
ClientDataSet1DateWeighed: TDateTimeField;
qryInsertData: TADOQuery;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
procedure TForm1.Button1Click(Sender: TObject);
const // for test purposes
buffer =
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+
'<DATAPACKET Version="2.0">'+
'<METADATA>'+
'<FIELDS>'+
'<FIELD attrname="TXID" fieldtype="i2"/>'+
'<FIELD attrname="GroupID" fieldtype="i2"/>'+
'<FIELD attrname="ScaleID" fieldtype="i2"/>'+
'<FIELD attrname="LineID" fieldtype="i2"/>'+
'<FIELD attrname="StationID" fieldtype="i2"/>'+
'<FIELD attrname="Weight" fieldtype="fixed" DECIMALS="15" WIDTH="18"/>
'+
'<FIELD attrname="DateWeighed" fieldtype="dateTime"/>'+
'</FIELDS>'+
'<PARAMS/>'+
'</METADATA>'+
'<ROWDATA>'+
'<ROW TXID="3" GroupID="1" ScaleID="1" LineID="1" StationID="1" '+
' Weight="33.344600000000000" DateWeighed="20060627T16:19:00000"/>'+
'<ROW TXID="3" GroupID="2" ScaleID="1" LineID="1" StationID="2" '+
' Weight="59.581200000000000" DateWeighed="20060627T16:24:00000"/> '+
'<ROW TXID="3" GroupID="3" ScaleID="1" LineID="1" StationID="3" '+
' Weight="44.581200000000000" DateWeighed="20060627T16:25:18150"/> '+
'<ROW TXID="3" GroupID="4" ScaleID="1" LineID="1" StationID="4" '+
' Weight="54.580200000000000" DateWeighed="20060627T16:25:30350"/> '+
'<ROW TXID="3" GroupID="5" ScaleID="1" LineID="1" StationID="5" '+
' Weight="34.580200000000000" DateWeighed="20060627T16:25:30350"/> '+
'</ROWDATA>'+
'</DATAPACKET>';
var
S : TStream;
begin
try
S := TStringStream.Create(buffer); // make a stream of the string of
data.
ClientDataSet1.EmptyDataSet; //clear out any old data.
ClientDataSet1.LoadFromStream(S); //load data stream
With qryInsertData, ClientDataSet1 do
Begin
While Not EOF DO
Begin
Parameters.ParamByName('TXID').Value := FieldByName('TXID').AsString;
Parameters.ParamByName('GroupID').Value :=
FieldByName('GroupID').AsString;
Parameters.ParamByName('ScaleID').Value :=
FieldByName('ScaleID').AsString;
Parameters.ParamByName('LineID' ).Value :=
FieldByName('LineID').AsString;
Parameters.ParamByName('StationID').Value :=
FieldByName('StationID').AsString;
Parameters.ParamByName('Weight').Value :=
FieldByName('Weight').AsString;
Parameters.ParamByName('DateWeighed').Value :=
FieldByName('DateWeighed').AsString;
ExecSQL;
Next;
End;
End;
finally
S.Free;
end;
end;
.
- References:
- reading XML string and writing it to a SQL database
- From: Larry
- Re: reading XML string and writing it to a SQL database
- From: Glynn Owen
- Re: reading XML string and writing it to a SQL database
- From: Larry
- Re: reading XML string and writing it to a SQL database
- From: Mike Shkolnik
- reading XML string and writing it to a SQL database
- Prev by Date: Re: TADOConnection error - connection string
- Next by Date: Re: TADOConnection error - connection string
- Previous by thread: Re: reading XML string and writing it to a SQL database
- Next by thread: Test if field in DB exsits
- Index(es):