procedure TQueue.Put(aStream: TStream; AutoCommit: Boolean=True);
var
SQLStr : String;
RecordNo : Integer;
begin
Assert(Assigned(aStream));
FDatabase.StartTransaction;
try
with FQuery do
begin
//将数据插入队列
SQLStr := 'INSERT INTO %s(SESSION,TRANSACTION,PRIORITY,TIMETOLIVE,DATAFIELD)'
+ ' VALUES(%d, ''%s'', %d, %d,
ATAFIELD)';
SQL.Text := Format(SQLStr, [FName, FSession, WriteNotCommit, FPriority, FTTL]);
aStream.Seek(0, soFrombeginning);
Params[0].LoadFromStream(aStream, ftBlob); //Params[0] 对应 DataField 参数
ExecSQL;
if AutoCommit then
begin
//查询当前数据的记录号, 记录号为自增加字段, 所以最大记录号
//为当前数据的记录号
SQLStr := 'SELECT MAX(RECORDNO) FROM %s WHERE SESSION=%d';
SQL.Text := Format(SQLStr, [FName, FSession]);
Open;
RecordNo := Fields[0].AsInteger;
//更新事物状态标志为已提交
SQLStr := 'UPDATE %s SET TRANSACTION=''%s'' WHERE RECORDNO=%d';
SQL.Text := Format(SQLStr, [FName, Commited, RecordNo]);
ExecSQL;
end;
end;
FDatabase.Commit;
except
FDatabase.Rollback;
raise;
end;
end;