Direct Path loader

WWirnsberger

Member²
Hello,

I do not unterstand your example in the documentation.

...
begin
// Copy one record to the array
Loader.Columns[0].SetData(Row, @Records.Line, 0);
loader.Columns[1].SetData(Row, @Records.Text[1],
Length(Records.Text));
Inc(Row);
...

1. What delphi datatype is "Records", "@Records.Line" and "Records.Text"?

2. Can you give me an example in that the source is a delphi-dataset?

Kind regards
 
Hello,

I did some tests and the following example produces three times the same record in the data base, but the input records are diffrent!

procedure TfrmMain.btnDirectLoadClick(Sender: TObject);
var
Loader: TOracleDirectPathLoader;
i, Row, BuffLen: Integer;
sBuff1: String;
dBuff1: Double;
begin
//
// Create a Loader at run time
Loader := TOracleDirectPathLoader.Create(nil);
try
// Set the session and table name
Loader.Session := DataModule1.OracleSession1;
Loader.TableName := 'MUAI_CONTACT';
// Get the default columns for the record_data table
//Loader.GetDefaultColumns(True);

Loader.Columns.Add('WEB_EDITED');
Loader.ColumnByName('WEB_EDITED').DataType := dpString;
Loader.ColumnByName('WEB_EDITED').DataSize := 1020;

Loader.Columns.Add('CONTACT_ID');
Loader.ColumnByName('CONTACT_ID').DataType := dpFloat;
Loader.ColumnByName('CONTACT_ID').DataSize := 8;

Loader.Columns.Add('RN_DESCRIPTOR');
Loader.ColumnByName('RN_DESCRIPTOR').DataType := dpString;
Loader.ColumnByName('RN_DESCRIPTOR').DataSize := 1020;

// Prepare the loader
Loader.Prepare;
// Process all data in batches of records
DataModule1.ADOTableFrom.First;
Row := 0;
//-- DataModule1.ADOTableFrom.RecordCount - 1
for i := 0 to 2 do
begin
// Copy one record to the array

sBuff1 := DataModule1.ADOTableFrom.Fields[0].AsString;
BuffLen := Length(sBuff1);
Loader.ColumnByName('WEB_EDITED').SetData(Row, @sBuff1[1], BuffLen);

dBuff1 := DataModule1.ADOTableFrom.Fields[1].AsFloat;
BuffLen := 8;
Loader.ColumnByName('CONTACT_ID').SetData(Row, @dBuff1, BuffLen);

sBuff1 := DataModule1.ADOTableFrom.Fields[2].AsString;
BuffLen := Length(sBuff1);
Loader.ColumnByName('RN_DESCRIPTOR').SetData(Row, @sBuff1[1], BuffLen);

Inc(Row);
DataModule1.ADOTableFrom.Next;
// The array is filled, or we have preocessed all records:
// load this batch of records
if (Row = Loader.MaxRows) or (i = 2 ) then //* Records.Count - 1 *//
begin
try
Loader.Load(Row);
except
// In case of an error: show where things went wrong
// and abort the load operation
on E:EOracleError do
begin
ShowMessage(E.Message + #13#10 +
'Row = ' + IntToStr(Loader.LastRow) + #13#10
+ 'Col = ' + IntToStr(Loader.LastColumn));
Loader.Abort;
raise;
end;
end;
Row := 0;
end;
end;
// Commit the loaded data
Loader.Finish;
finally
FreeAndNil(Loader);
end;
//
end;
 
The DirectPath project in the Demos subdirectory of the Direct Oracle Access provides a complete example.

The most common pitfall for the Direct Path Loader is that the data of the pointers that are passed to the SetData procedure must remain valid until you call Load. This is because the SetData function does not copy the data, it merely passes the pointer. As a result, your example does not work because the sBuf1 variable is reused for each row.
 
Back
Top