mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-16 05:59:28 +02:00
* Completion of put/patch split
This commit is contained in:
parent
ffa14ee448
commit
6e5c5f599e
@ -159,6 +159,7 @@ Type
|
||||
Class Var FDBHandlerClass : TSQLDBRestDBHandlerClass;
|
||||
private
|
||||
FAdminUserIDs: TStrings;
|
||||
FAfterPatch: TRestOperationEvent;
|
||||
FConnectionManager: TSQLDBConnectionManager;
|
||||
FCORSAllowCredentials: Boolean;
|
||||
FCORSAllowedOrigins: String;
|
||||
@ -182,6 +183,7 @@ Type
|
||||
FBeforeGet: TRestOperationEvent;
|
||||
FBeforePost: TRestOperationEvent;
|
||||
FBeforePut: TRestOperationEvent;
|
||||
FBeforePatch: TRestOperationEvent;
|
||||
FConnections: TSQLDBRestConnectionList;
|
||||
FDefaultConnection: UTF8String;
|
||||
FEnforceLimit: Integer;
|
||||
@ -370,6 +372,10 @@ Type
|
||||
Property BeforeGet : TRestOperationEvent Read FBeforeGet Write FBeforeGet;
|
||||
// Called After a GET request.
|
||||
Property AfterGet : TRestOperationEvent Read FAfterGet Write FAfterGet;
|
||||
// Called before a PATCH request.
|
||||
Property BeforePatch : TRestOperationEvent Read FBeforePatch Write FBeforePatch;
|
||||
// Called after a PATCH request.
|
||||
Property AfterPatch : TRestOperationEvent Read FAfterPatch Write FAfterPatch;
|
||||
// Called before a PUT request.
|
||||
Property BeforePut : TRestOperationEvent Read FBeforePut Write FBeforePut;
|
||||
// Called After a PUT request.
|
||||
@ -1003,7 +1009,7 @@ begin
|
||||
Def:=[foInInsert,foInUpdate,foFilter];
|
||||
Result:=TSQLDBRestResource.Create(Nil);
|
||||
Result.ResourceName:=Strings.GetRestString(rpConnectionResourceName);
|
||||
Result.AllowedOperations:=[roGet,roPut,roPost,roDelete];
|
||||
Result.AllowedOperations:=[roGet,roPut,roPatch,roPost,roDelete];
|
||||
if rdoHandleCORS in DispatchOptions then
|
||||
Result.AllowedOperations:=Result.AllowedOperations+[roOptions,roHead];
|
||||
Result.Fields.AddField('name',rftString,Def+[foInKey,foRequired]);
|
||||
@ -1133,11 +1139,7 @@ begin
|
||||
M:=aRequest.CustomHeaders.Values['Access-Control-Request-Method'];
|
||||
Case lowercase(M) of
|
||||
'get' : Result:=roGet;
|
||||
'put' :
|
||||
begin
|
||||
Result:=roPut;
|
||||
|
||||
end;
|
||||
'put' : Result:=roPut;
|
||||
'post' : Result:=roPost;
|
||||
'delete' : Result:=roDelete;
|
||||
'options' : Result:=roOptions;
|
||||
@ -1254,6 +1256,13 @@ begin
|
||||
if assigned(BP) then
|
||||
ResEvt:=BP.BeforeDatabaseRead;
|
||||
end;
|
||||
roPatch:
|
||||
begin
|
||||
R:=FBeforePatch;
|
||||
Evt:=BeforeDatabaseUpdate;
|
||||
if assigned(BP) then
|
||||
ResEvt:=BP.BeforeDatabaseUpdate;
|
||||
end;
|
||||
roPut :
|
||||
begin
|
||||
R:=FBeforePut;
|
||||
@ -1300,6 +1309,13 @@ begin
|
||||
if assigned(BP) then
|
||||
ResEvt:=BP.AfterDatabaseUpdate;
|
||||
end;
|
||||
roPatch :
|
||||
begin
|
||||
R:=FAfterPatch;
|
||||
Evt:=AfterDatabaseUpdate;
|
||||
if assigned(BP) then
|
||||
ResEvt:=BP.AfterDatabaseUpdate;
|
||||
end;
|
||||
roPost :
|
||||
begin
|
||||
R:=FAfterPost;
|
||||
|
@ -142,6 +142,7 @@ begin
|
||||
Case IO.Operation of
|
||||
roGet : DoHandleGet;
|
||||
roPut : DoHandlePut;
|
||||
roPatch : DoHandlePatch;
|
||||
roPost : DoHandlePost;
|
||||
roDelete : DoHandleDelete;
|
||||
else
|
||||
@ -497,6 +498,7 @@ begin
|
||||
case aOperation of
|
||||
roGet : Sources:=[vsQuery,vsRoute];
|
||||
roPost,
|
||||
roPatch,
|
||||
roPut : Sources:=[vsQuery,vsContent,vsRoute];
|
||||
roDelete : Sources:=[vsQuery,vsRoute];
|
||||
else
|
||||
@ -1029,6 +1031,9 @@ end;
|
||||
procedure TSQLDBRestDBHandler.UpdateExistingRecord(OldData: TDataset;
|
||||
IsPatch: Boolean);
|
||||
|
||||
const
|
||||
putpatch : Array [Boolean] of TRestOperation = (roPut,roPatch);
|
||||
|
||||
Var
|
||||
S : TSQLQuery;
|
||||
aRowsAffected: Integer;
|
||||
@ -1036,6 +1041,7 @@ Var
|
||||
WhereFilterList : TRestFilterPairArray;
|
||||
RequestFields : TSQLDBRestFieldArray;
|
||||
|
||||
|
||||
begin
|
||||
if (OldData=ExternalDataset) then
|
||||
begin
|
||||
@ -1065,9 +1071,9 @@ begin
|
||||
S.SQL.Text:=SQL;
|
||||
if (not isPatch) and UseLegacyPUT then
|
||||
SetPostParams(S.Params,OldData.Fields);
|
||||
FillParams(roGet,S.Params,WhereFilterList);
|
||||
FillParams(PutPatch[isPatch],S.Params,WhereFilterList);
|
||||
// Give user a chance to look at it.
|
||||
FResource.CheckParams(io.RestContext,roPut,S.Params);
|
||||
FResource.CheckParams(io.RestContext,PutPatch[IsPatch],S.Params);
|
||||
S.ExecSQL;
|
||||
if CheckUpdateCount then
|
||||
begin
|
||||
|
Loading…
Reference in New Issue
Block a user