说明:
程序的目的是,从PASSENGER_PHOTO表往PASSENGER_PHOTO_HISTORY表中插入记录,但是两张表都有PHOTO字段,PHOTO字段存的是照片.错误提示:
当PASSENGER_PHOTO表向PASSENGER_PHOTO_HISTORY表中插记录达到3000多条时,就出现以下错误。ERROR MESSAGE:
Project DataInsert.exe raised exception class EDBEngineError with message 'Key violation.
[Oracle][ODBC][Ora]ORA-03127:在活动操作结束之前不允许进行新的操作'.Process stopped
Use Step or Run to continue.
以下是我的代码: With Qty_Photo do //打开PASSENGER_PHOTO表的所有记录
While not Eof do
begin
s_flight := Qty_Photo.FieldByName('flight').AsString; //主键一的值
s_strt := Qty_Photo.FieldByName('strt').AsString; //主键二的值
s_bdno := Qty_Photo.FieldByName('bdno').AsString; //主键三的值 s_sql := '';
s_sql := 'SELECT COUNT(*) FROM PASSENGER_PHOTO_HISTORY WHERE ';
s_sql := s_sql + 'flight = ''' + s_flight ;
s_sql := s_sql + ' and strt = ''' + s_strt ;
s_sql := s_sql + ''' and bdno = ''' + s_bdno + '''' ; Qty_Exec.Active := False;
Qty_Exec.DatabaseName := is_ServerName;
Qty_Exec.SQL.Clear;
Qty_Exec.SQL.Add(s_sql);
Qty_Exec.Active := True; //如果在PASSENGER_PHOTO_HISTORY 表中无冲突记录,则插入PASSENGER_PHOTO的记录
if Qty_Exec.Fields[0].AsInteger < 1 then
begin
try
QTY_PHOTO_HISTORY.Append;
QTY_PHOTO_HISTORY.FieldByName('FLIGHT').AsString := Qty_Photo.FieldByName('FLIGHT').AsString;
QTY_PHOTO_HISTORY.FieldByName('OFFDAY').AsDateTime := Qty_Photo.FieldByName('OFFDAY').AsDateTime;
QTY_PHOTO_HISTORY.FieldByName('STRT').AsString := Qty_Photo.FieldByName('STRT').AsString;
QTY_PHOTO_HISTORY.FieldByName('BDNO').AsString := Qty_Photo.FieldByName('BDNO').AsString;
QTY_PHOTO_HISTORY.FieldByName('CHECK_TIME').AsDateTime := Qty_Photo.FieldByName('CHECK_TIME').AsDateTime;
QTY_PHOTO_HISTORY.FieldByName('CHANNEL_NO').AsString := Qty_Photo.FieldByName('CHANNEL_NO').AsString;
TempStream := TMemoryStream.Create;
try
TBlobField(FieldByName('PHOTO')).SaveToStream(TempStream);
TempStream.Position := 0;
TBlobField(QTY_PHOTO_HISTORY.FieldByName('PHOTO')).LoadFromStream(TempStream);
finally
TempStream.Free;
end;
QTY_PHOTO_HISTORY.Post;
except
end;
end;
Next; //下一条
end;
程序的目的是,从PASSENGER_PHOTO表往PASSENGER_PHOTO_HISTORY表中插入记录,但是两张表都有PHOTO字段,PHOTO字段存的是照片.错误提示:
当PASSENGER_PHOTO表向PASSENGER_PHOTO_HISTORY表中插记录达到3000多条时,就出现以下错误。ERROR MESSAGE:
Project DataInsert.exe raised exception class EDBEngineError with message 'Key violation.
[Oracle][ODBC][Ora]ORA-03127:在活动操作结束之前不允许进行新的操作'.Process stopped
Use Step or Run to continue.
以下是我的代码: With Qty_Photo do //打开PASSENGER_PHOTO表的所有记录
While not Eof do
begin
s_flight := Qty_Photo.FieldByName('flight').AsString; //主键一的值
s_strt := Qty_Photo.FieldByName('strt').AsString; //主键二的值
s_bdno := Qty_Photo.FieldByName('bdno').AsString; //主键三的值 s_sql := '';
s_sql := 'SELECT COUNT(*) FROM PASSENGER_PHOTO_HISTORY WHERE ';
s_sql := s_sql + 'flight = ''' + s_flight ;
s_sql := s_sql + ' and strt = ''' + s_strt ;
s_sql := s_sql + ''' and bdno = ''' + s_bdno + '''' ; Qty_Exec.Active := False;
Qty_Exec.DatabaseName := is_ServerName;
Qty_Exec.SQL.Clear;
Qty_Exec.SQL.Add(s_sql);
Qty_Exec.Active := True; //如果在PASSENGER_PHOTO_HISTORY 表中无冲突记录,则插入PASSENGER_PHOTO的记录
if Qty_Exec.Fields[0].AsInteger < 1 then
begin
try
QTY_PHOTO_HISTORY.Append;
QTY_PHOTO_HISTORY.FieldByName('FLIGHT').AsString := Qty_Photo.FieldByName('FLIGHT').AsString;
QTY_PHOTO_HISTORY.FieldByName('OFFDAY').AsDateTime := Qty_Photo.FieldByName('OFFDAY').AsDateTime;
QTY_PHOTO_HISTORY.FieldByName('STRT').AsString := Qty_Photo.FieldByName('STRT').AsString;
QTY_PHOTO_HISTORY.FieldByName('BDNO').AsString := Qty_Photo.FieldByName('BDNO').AsString;
QTY_PHOTO_HISTORY.FieldByName('CHECK_TIME').AsDateTime := Qty_Photo.FieldByName('CHECK_TIME').AsDateTime;
QTY_PHOTO_HISTORY.FieldByName('CHANNEL_NO').AsString := Qty_Photo.FieldByName('CHANNEL_NO').AsString;
TempStream := TMemoryStream.Create;
try
TBlobField(FieldByName('PHOTO')).SaveToStream(TempStream);
TempStream.Position := 0;
TBlobField(QTY_PHOTO_HISTORY.FieldByName('PHOTO')).LoadFromStream(TempStream);
finally
TempStream.Free;
end;
QTY_PHOTO_HISTORY.Post;
except
end;
end;
Next; //下一条
end;
begin
Database1.StartTransaction;
try
{插入记录操作}
Database1.Commit; {成功}
except
Database1.Rollback; {失敗}
raise;
end;
end;
还有Stream不用在循环体内不断建立和释放不过量过多时最好能分成几个事务操作