Problem with TUniLoader, SQLServer and Identity Columns
Posted: Mon 13 Jan 2014 15:59
I am using Delphi XE on Windows XP for this.
I have an sql script which contains thousands of inserts into different tables. I am trying to convert this script to use TUniLoader to decrease the loading times.
Each insert statement does not always contain all the columns for the table and each insert statement never includes an identity column.
For these reasons, in my PutData procedure, I want to initialise every column to null and then set the values I want to insert.
If the table being inserted has an identity column then an 'EOLEDBError' 'Unspecified error' exception is raised when the second row is inserted. If the table has no identity column then the inserts work correctly.
The following code demonstrates the problem. If table AgrH contains an identity column then the code will fail in PutData when i = 1.
{------------------------------------------------------------------------------}
procedure TForm1.PutData (Sender: TDALoader);
var i, j: integer;
begin
for i := 0 to 1 do
begin
{ Initialise every column to null }
for j := 0 to Sender.Columns.Count - 1 do
Sender.PutColumnData (j, i+1, null);
{ Load the actual data }
...
end;
end;
{------------------------------------------------------------------------------}
procedure TForm1.Button1Click(Sender: TObject);
var UniLoader: TUniLoader;
begin
UniLoader := TUniLoader.Create (nil);
try
UniLoader.Connection := UniConnection;
UniLoader.TableName := 'AgrH';
UniLoader.CreateColumns;
UniLoader.OnPutData := PutData;
UniLoader.Load;
finally
UniLoader.Free;
end;
end;
I have an sql script which contains thousands of inserts into different tables. I am trying to convert this script to use TUniLoader to decrease the loading times.
Each insert statement does not always contain all the columns for the table and each insert statement never includes an identity column.
For these reasons, in my PutData procedure, I want to initialise every column to null and then set the values I want to insert.
If the table being inserted has an identity column then an 'EOLEDBError' 'Unspecified error' exception is raised when the second row is inserted. If the table has no identity column then the inserts work correctly.
The following code demonstrates the problem. If table AgrH contains an identity column then the code will fail in PutData when i = 1.
{------------------------------------------------------------------------------}
procedure TForm1.PutData (Sender: TDALoader);
var i, j: integer;
begin
for i := 0 to 1 do
begin
{ Initialise every column to null }
for j := 0 to Sender.Columns.Count - 1 do
Sender.PutColumnData (j, i+1, null);
{ Load the actual data }
...
end;
end;
{------------------------------------------------------------------------------}
procedure TForm1.Button1Click(Sender: TObject);
var UniLoader: TUniLoader;
begin
UniLoader := TUniLoader.Create (nil);
try
UniLoader.Connection := UniConnection;
UniLoader.TableName := 'AgrH';
UniLoader.CreateColumns;
UniLoader.OnPutData := PutData;
UniLoader.Load;
finally
UniLoader.Free;
end;
end;