 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Don Gollahon Guest
|
Posted: Mon Apr 05, 2004 8:59 pm Post subject: Re: BatchMove vs Append |
|
|
"Paul Toms" <pault (AT) navigator (DOT) co.uk> wrote
| Quote: | Compared to an iterative 'append' to a paradox table, a batchmove is
extremely fast. No doubt it shortcuts many of the record writing overhead
with some efficient file streaming code. So the difference in batching or
appending 500 records is that of 1-2 secs and 20 secs respectively (rough
tests done on a 10Mb LAN).
I have a memory table (TkbmMemTable) whose contents I want to commit to a
paradox table of the same structure. The trouble is the memtable descends
from TDataSet and without the BDE involved I can't connect a TBatchmove
component.
So my question is, how can I get around this? Does anyone know how to
implement the raw code which the BDE must be calling with some dbiXXX
function? Is there a clever custom Batchmove component out there (I'm
happy to pay for one)? Any other ideas?
|
Delphi Informant had a generic one last year. Free download. If you have
access to their site it is the di200303bt_f.zip. It works with tDataset
based components (with a few restrictions if I remember correctly). No BDE
required.
If you can't get to the site, email me at [email]dlgllhn (AT) InHisStepsSoftware (DOT) com[/email] and
I will send it to you. I think that is okay to do that. If I'm wrong,
someone let me know. Don't remember if there was a restriction on
distribution of code samples.
Here is some code I use to create a table on the fly. It doesn't do the
indices but that could be added fairly easily using something like
vtbl.IndexDefs.Assign(pQuery.IndexDefs) I think:
function mkTable(pPath, pTable : string; pQuery : TDataset;
pTransferData : boolean) : boolean;
//Creates a table (pTable) in pPath that can receive the records from the
data
//in pQuery. pQuery must be any TDataset compatible object.
//NOTE: if pTable exists it will be overwritten!
//If pTransferData is True then the data in pQuery will also be transfered
//to the new table. You can use this function to create answer tables in
the
//private directory from a SQL query on an Interbase table, for instance.
var
vfield : tField;
i : integer;
vstr, vQryStr, vfldnm : string;
vqry : tquery;
vtbl : ttable;
begin
result := false;
i := -1;
vstr := '';
vQryStr := '';
try
vtbl := ttable.Create(application);
vtbl.DatabaseName := ppath;
vtbl.TableName := ptable;
except
on E: Exception do
begin
showmessage(getError(E));
exit;
end;
end;
vtbl.FieldDefs.Assign(pQuery.FieldDefs);
//Create the table.
try
vtbl.CreateTable;
except
on E: Exception do
begin
MyError(application, E);
exit;
end;
end;
if pTransferData then
begin
vtbl.Open;
if not TransferData(pQuery, vtbl) then
begin
vtbl.close;
vtbl.Free;
exit;
end;
vtbl.Close;
vtbl.Free;
end;
result := true;
{
These come from BorlansourcevclIBHeader.pas:
Here are the SQL field type constants. //Paradox Equivalent:
SQL_VARYING = 448; //Alpha (A)
SQL_TEXT = 452; //Alpha (A)
SQL_DOUBLE = 480; //Number (N)
SQL_FLOAT = 482; //Number (N)
SQL_LONG = 496; //Long (I)
SQL_SHORT = 500; //Short (S)
SQL_TIMESTAMP = 510; //Date (D, T, @) (USE
TIMESTAMP)
//For Dialect 3, this is
Timestamp type.
SQL_BLOB = 520; //Blob (M, F)
SQL_D_FLOAT = 530; //Number (N) ?
SQL_ARRAY = 540; //?
SQL_QUAD = 550; //?
SQL_TYPE_TIME = 560; //Time
SQL_TYPE_DATE = 570; //Date
SQL_INT64 = 580; //Number
SQL_DATE = SQL_TIMESTAMP;
}
end;
function TransferData(pQuery : TDataset; pDataSet : tDataSet) : boolean;
//Transfers data from the query pQuery (any tDataset source) to the paradox
dataset pDataset.
var
i, j, vType : integer;
vStr : String;
begin
result := false;
if not pDataset.Active then
pDataset.Open;
j := pdataset.FieldCount;
while not pQuery.EOF do
begin
pdataset.Append;
for i := 0 to j - 1 do
try
pdataset.Fields[i].asVariant := pQuery.Fields[i].AsVariant;
except
on E: Exception do
begin
vStr := GetEnumName(TypeInfo(TFieldType),
Ord(pdataset.Fields[i].DataType));
//dataTypeToString(pdataset.Fields[i].DataType);
showmessage('Incompatible field types. Field Name: '+
pQuery.Fields[i].Name+', Field Type: '+
FieldTypeNames[pQuery.Fields[i].DataType]+', Paradox type: '+
vStr+'.'#13#10+getError(E));
end;
end;
pdataset.Post;
pQuery.Next;
end;
result := True;
end;
| Quote: |
TIA
Paul
PS - I'm aware the Rx TmemoryTable component descends from TDBDataSet, but
alas it does support to support BLOB fields :-(
|
--
Don Gollahon
[email]gollahon (AT) geneseo (DOT) net[/email]
|
|
| Back to top |
|
 |
Paul Toms Guest
|
Posted: Tue Apr 06, 2004 3:58 pm Post subject: Re: BatchMove vs Append |
|
|
Many thanks. I managed to get hold of the zip; I'll take a look at it
later this week.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|