客户端函数function PostModifyInfo(aTableName,aIndexName:String;aData:Variant):Boolean;var vByte:TByteDynArray;
msByte:TMemoryStream;
I,J,aFlag,aInsertFlag,apicFlag:Integer;
aSqlStr,Id,aSqlStrAll,aIdNew,aStrFiled:String;
tmpClient :TClientDataSet;
begin
try Result := False;
if VarIsEmpty(aData) then
Exit;
tmpClient := TClientDataSet.Create(nil);
apicFlag := 0;
msByte:=TMemoryStream.Create;
try tmpClient.Data := aData;
tmpClient.Active := not tmpClient.IsEmpty;
if tmpClient.Active then
begin
aSqlStrAll := 'begin
';
aInsertFlag := 0;
for I := 0 to tmpClient.RecordCount -1do
begin
aFlag := 0;
aSqlStr := '';
aStrFiled := '';
case tmpClient.UpdateStatus of usUnmodified: begin
aFlag := 1;
Id :=tmpClient.FieldByName(aIndexName).AsString;
end;
usModified: begin
aSqlStr := 'update '+aTableName+' set ';
for J := 0 to tmpClient.FieldCount-1do
begin
if not tmpClient.Fields[J].IsNull then
if tmpClient.Fields[J].DataType <> ftBlob then
aSqlStr :=aSqlStr+tmpClient.Fields[J].FieldName+'='''+tmpClient.Fields[J].AsString+''',' else
begin
apicFlag := 1;
TBlobField(tmpClient.Fields[J]).SaveToStream(msByte);
setlength(vByte,msByte.size);
msByte.position:=0;
msByte.read(vByte[0],msByte.size);
aSqlStr :=aSqlStr+tmpClient.Fields[J].FieldName+'=:Id,';
end;
end;
Delete(aSqlStr,Length(aSqlStr),1);
aSqlStr :=aSqlStr+' where '+aIndexName+' = '''+Id+''';';
end;
usInserted: begin
for J := 0 to tmpClient.FieldCount-1do
begin
aStrFiled := aStrFiled +tmpClient.Fields[J].FieldName+',';
if UpperCase(tmpClient.Fields[J].FieldName) = UpperCase(Trim(aIndexName)) then
begin
aSqlStr :=aSqlStr+'GetTbIndex('''+aTableName+''','''+aIndexName+''','+IntToStr(tmpClient.FieldByName(aIndexName).Size)+'),' end else
begin
if tmpClient.Fields[J].DataType <> ftBlob then
aSqlStr :=aSqlStr+''''+tmpClient.Fields[J].AsString+''',' else
begin
if not tmpClient.Fields[J].IsNull then
begin
apicFlag := 1;
TBlobField(tmpClient.Fields[J]).SaveToStream(msByte);
setlength(vByte,msByte.size);
msByte.position:=0;
msByte.read(vByte[0],msByte.size);
aSqlStr :=aSqlStr+':Id'+',';
end else
aSqlStr :=aSqlStr+''''+tmpClient.Fields[J].AsString+''',';
end;
end;
end;
Delete(aStrFiled,Length(aStrFiled),1);
Delete(aSqlStr,Length(aSqlStr),1);
aSqlStr := 'insert into '+aTableName+' ( '+aStrFiled+') values('+aSqlStr+');
';
aInsertFlag := aInsertFlag +1;
end;
usDeleted: begin
aSqlStr := aSqlStr+'delete from '+aTableName+' where '+aIndexName+' = '''+tmpClient.FieldByName(aIndexName).AsString+''';';
end;
end;
tmpClient.Next;
if aFlag = 0 then
aSqlStrAll := aSqlStrAll +aSqlStr;
end;
aSqlStrAll := aSqlStrAll + ' end;
';
if apicFlag > 0 then
Result := pubExecSqlP(aSqlStrAll,vByte) else
Result := pubExecSql(aSqlStrAll);
end else
begin
Result := False;
end;
finally tmpClient.Free;
msByte.Free;
end;
except if tmpClient <> nil then
tmpClient.Free;
if msByte <> nil then
msByte.Free;
Result := False;
end;
end;
服务端函数var PubQury:TADOQuery;
begin
try try PubQury := TADOQuery.Create(nil);
if AlinkStr = '' then
AlinkStr := 'Provider=MSDAORA.1;Password=''xxx'';User ID=''XXX'';Data Source=ORACLE;Persist Security Info=True';
PubQury.ConnectionString := AlinkStr;
PubQury.SQL.Text := AsqlStr;
PubQury.ExecSQL;
finally PubQury.Free;
end;
Result := true;
except on e:Exceptiondo
begin
Result := False;
end;
end;
end;
给分吧!!