|
Example - Direct Path Loading |
Top Previous Next |
|
次のサンプルは動的にToracleDirectPathLoaderインスタンスを作成し、必要なプロパティを設定し、デフォルトカラム定義を作成、そしてデータを読み込みます。 このデータはRecords構造体に置かれますが、このサンプルでは話を簡単にするために省略しています。 それぞれのレコードは整数値Lineと文字列値Textから成ります。 // Perform the Direct Path Load procedure LoadRecords; var Loader: TOracleDirectPathLoader; i, Row: Integer; begin // Create a Loader at run time Loader := TOracleDirectPathLoader.Create(nil); try // Set the session and table name Loader.Session := MainSession; Loader.TableName := 'record_data'; // Get the default columns for the record_data table Loader.GetDefaultColumns(False); // Prepare the loader Loader.Prepare; // Process all data in batches of <MaxRows> records Row := 0; for i := 0 to Records.Count - 1 do begin // Copy one record to the array Loader.Columns[0].SetData(Row, @Records[i].Line, 0); loader.Columns[1].SetData(Row, @Records[i].Text[1], Length(Records[i].Text)); Inc(Row); // The array is filled, or we have preocessed all records: // load this batch of records if (Row = Loader.MaxRows) or (i = Records.Count - 1) then 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 Loader.Free; end; end; |