懒得修改了参数里应该再加个字段名称有兴趣修改下目前是根据VersionNO来判断读时候也可以根据数据库中流长度来比较最好是通过外界手段自己控制吧
function TDataModuleDataBase.LoadRecFromDB(const aName, TableName: ;
var Rec; RecSize: Integer): Boolean;
var
MS: TMemoryStream;
begin
Result := False;
Trim(aName)=\'\' then
Exit;
MS := TMemoryStream.Create;
try
try
ADOConnection.Open;
except
Exit;
end;
with ADOQuery do begin
Active:=False;
SQL.Text:=\'SELECT * FROM \'+ TableName +\' WHERE Name=\'+\'\'\'\'+ aName +\'\'\'\' + \' and AppVersion=\' + \'\'\'\' + VersionNO + \'\'\'\';
Active:=True;
RecordCount <> 1 then
Exit;
with FieldByName(\'RecOLE\') as TBlobField do begin
MS.Position := 0;
SaveToStream(MS);
MS.Position := 0;
MS.Read(Rec, RecSize);
end;
end;
finally
ADOConnection.Close;
MS.Free;
end;
Result := True;
end;
function TDataModuleDataBase.SaveRecToDB(const aName, TableName: ;
var Rec; RecSize: Integer): Boolean;
var
MS: TMemoryStream;
begin
Result := False;
MS := TMemoryStream.Create;
try
try
ADOConnection.Open;
except
Exit;
end;
with ADOQuery do begin
Active:=False;
SQL.Clear;
SQL.Text:=\'SELECT * FROM \' + TableName + \' WHERE Name=\'+\'\'\'\'+ aName + \'\'\'\';
Active:=True;
RecordCount>=1 then
Exit;
Active:=False;
SQL.Text:=\'SELECT * FROM \' + TableName;
Prepared;
Open;
Append;[Page]
FieldByName(\'Name\').Value := aName;
FieldByName(\'AppVersion\').Value := VersionNO;
with FieldByName(\'RecOLE\') as TBlobField do begin
MS.Position := 0;
MS.Write(Rec, RecSize);
MS.Position := 0;
LoadFromStream(MS);
end;
Post;
end;
finally
ADOConnection.Close;
MS.Free;
end;
Result := True;
end;
最新评论