Skip to content

Commit

Permalink
Subtle bug in TMVCActiveRecord refresh for nullable types
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleteti committed Jan 20, 2025
1 parent 23fbace commit e9ee7bb
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 62 deletions.
24 changes: 14 additions & 10 deletions ideexpert/DMVC.Expert.CodeGen.Commands.pas
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@ procedure TUnitWebModuleDeclarationCommand.ExecuteImplementation(

Section
.AppendLine(' MVCFramework.Middleware.ActiveRecord,')
.AppendLine(' MVCFramework.Middleware.Session,')
.AppendLine(' MVCFramework.Middleware.Redirect,')
.AppendLine(' MVCFramework.Middleware.StaticFiles,')
.AppendLine(' MVCFramework.Middleware.Analytics,')
Expand All @@ -834,11 +835,9 @@ procedure TUnitWebModuleDeclarationCommand.ExecuteImplementation(
.AppendLine
.AppendLine('procedure ' + Model.S[TConfigKey.webmodule_classname] + '.WebModuleCreate(Sender: TObject);')
.AppendLine('begin')
.AppendLine(' FMVC := TMVCEngine.Create(Self,')
.AppendLine(' fMVC := TMVCEngine.Create(Self,')
.AppendLine(' procedure(Config: TMVCConfig)')
.AppendLine(' begin')
.AppendLine(' // session timeout (0 means session cookie)')
.AppendLine(' Config[TMVCConfigKey.SessionTimeout] := dotEnv.Env(''dmvc.session_timeout'', ''0'');')
.AppendLine(' //default content-type')
.AppendLine(' Config[TMVCConfigKey.DefaultContentType] := dotEnv.Env(''dmvc.default.content_type'', ' + default_media_type + ');')
.AppendLine(' //default content charset')
Expand All @@ -864,7 +863,7 @@ procedure TUnitWebModuleDeclarationCommand.ExecuteImplementation(
.AppendLine(' end);')
.AppendLine
.AppendLine(' // Controllers')
.AppendLine(' FMVC.AddController(' + Model[TConfigKey.controller_classname] + ');')
.AppendLine(' fMVC.AddController(' + Model[TConfigKey.controller_classname] + ');')
.AppendLine(' // Controllers - END')
.AppendLine;

Expand All @@ -874,7 +873,7 @@ procedure TUnitWebModuleDeclarationCommand.ExecuteImplementation(
lAddURLEncodedSerializer := True;
Section
.AppendLine(' // Server Side View')
.AppendLine(' FMVC.SetViewEngine(TMVCTemplateProViewEngine);')
.AppendLine(' fMVC.SetViewEngine(TMVCTemplateProViewEngine);')
.AppendLine(' // Server Side View - END')
.AppendLine;
end;
Expand All @@ -884,7 +883,7 @@ procedure TUnitWebModuleDeclarationCommand.ExecuteImplementation(
lAddURLEncodedSerializer := True;
Section
.AppendLine(' // Server Side View')
.AppendLine(' FMVC.SetViewEngine(TMVCWebStencilsViewEngine);')
.AppendLine(' fMVC.SetViewEngine(TMVCWebStencilsViewEngine);')
.AppendLine(' // Server Side View - END')
.AppendLine;
end;
Expand All @@ -894,7 +893,7 @@ procedure TUnitWebModuleDeclarationCommand.ExecuteImplementation(
lAddURLEncodedSerializer := True;
Section
.AppendLine(' // Server Side View')
.AppendLine(' FMVC.SetViewEngine(TMVCMustacheViewEngine);')
.AppendLine(' fMVC.SetViewEngine(TMVCMustacheViewEngine);')
.AppendLine(' // Server Side View - END')
.AppendLine;
end;
Expand All @@ -903,13 +902,18 @@ procedure TUnitWebModuleDeclarationCommand.ExecuteImplementation(
begin
Section
.AppendLine(' // Serializers')
.AppendLine(' FMVC.AddSerializer(TMVCMediaType.APPLICATION_FORM_URLENCODED, TMVCURLEncodedSerializer.Create(nil));')
.AppendLine(' fMVC.AddSerializer(TMVCMediaType.APPLICATION_FORM_URLENCODED, TMVCURLEncodedSerializer.Create(nil));')
.AppendLine(' // Serializers - END')
.AppendLine;
end;

Section
.AppendLine(' // Middleware');
.AppendLine(' // Middleware')
.AppendLine(' // To use memory session uncomment the following line')
.AppendLine(' // fMVC.AddMiddleware(UseMemorySessionMiddleware);')
.AppendLine(' //')
.AppendLine(' // To use file based session uncomment the following line')
.AppendLine(' // fMVC.AddMiddleware(UseFileSessionMiddleware);');

if Model.B[TConfigKey.webmodule_middleware_analytics] then
begin
Expand Down Expand Up @@ -974,7 +978,7 @@ procedure TUnitWebModuleDeclarationCommand.ExecuteImplementation(
.AppendLine
.AppendLine('procedure ' + Model.S[TConfigKey.webmodule_classname] + '.WebModuleDestroy(Sender: TObject);')
.AppendLine('begin')
.AppendLine(' FMVC.Free;')
.AppendLine(' fMVC.Free;')
.AppendLine('end;')
.AppendLine
.AppendLine('end.')
Expand Down
6 changes: 4 additions & 2 deletions packages/d120/dmvcframeworkRT.dpk
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,13 @@ contains
sqids in '..\..\sources\sqids.pas',
MVCFramework.View.Renderers.TemplatePro in '..\..\sources\MVCFramework.View.Renderers.TemplatePro.pas',
TemplatePro in '..\..\sources\TemplatePro.pas',
MVCFramework.HTMX in '..\..\sources\MVCFramework.HTMX.pas',
MVCFramework.Session.Database in '..\..\sources\MVCFramework.Session.Database.pas',
MVCFramework.SQLGenerators.MSSQL in '..\..\sources\MVCFramework.SQLGenerators.MSSQL.pas',
MVCFramework.RQL.AST2MSSQL in '..\..\sources\MVCFramework.RQL.AST2MSSQL.pas',
MVCFramework.Middleware.Session.Internal in '..\..\sources\MVCFramework.Middleware.Session.Internal.pas';
MVCFramework.Middleware.Session.Internal in '..\..\sources\MVCFramework.Middleware.Session.Internal.pas',
MVCFramework.HTMX in '..\..\sources\MVCFramework.HTMX.pas',
MVCFramework.IntfObjectPool in '..\..\sources\MVCFramework.IntfObjectPool.pas',
MVCFramework.ObjectPool in '..\..\sources\MVCFramework.ObjectPool.pas';

end.

Expand Down
4 changes: 3 additions & 1 deletion packages/d120/dmvcframeworkRT.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,13 @@
<DCCReference Include="..\..\sources\sqids.pas"/>
<DCCReference Include="..\..\sources\MVCFramework.View.Renderers.TemplatePro.pas"/>
<DCCReference Include="..\..\sources\TemplatePro.pas"/>
<DCCReference Include="..\..\sources\MVCFramework.HTMX.pas"/>
<DCCReference Include="..\..\sources\MVCFramework.Session.Database.pas"/>
<DCCReference Include="..\..\sources\MVCFramework.SQLGenerators.MSSQL.pas"/>
<DCCReference Include="..\..\sources\MVCFramework.RQL.AST2MSSQL.pas"/>
<DCCReference Include="..\..\sources\MVCFramework.Middleware.Session.Internal.pas"/>
<DCCReference Include="..\..\sources\MVCFramework.HTMX.pas"/>
<DCCReference Include="..\..\sources\MVCFramework.IntfObjectPool.pas"/>
<DCCReference Include="..\..\sources\MVCFramework.ObjectPool.pas"/>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
Expand Down
6 changes: 3 additions & 3 deletions samples/sessions/WebModuleUnit1.pas
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ procedure TWebModule1.WebModuleCreate(Sender: TObject);
MVC.AddController(TApp1MainController);

{To use memory session}
MVC.AddMiddleware(UseMemorySessionMiddleware);
// MVC.AddMiddleware(UseMemorySessionMiddleware);

{To use file based session}
//MVC.AddMiddleware(UseFileSessionMiddleware);

{To use database based session (firebird)}
MVC.AddMiddleware(TMVCActiveRecordMiddleware.Create('firebirddb'));
MVC.AddMiddleware(UseDatabaseSessionMiddleware(0));
// MVC.AddMiddleware(TMVCActiveRecordMiddleware.Create('firebirddb'));
// MVC.AddMiddleware(UseDatabaseSessionMiddleware(0));
end;

end.
3 changes: 2 additions & 1 deletion sources/MVCFramework.HTMX.pas
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,13 @@ function THTMXResponseHelper.HXTriggerClientEvents(EventsDescriptors: TJSONObjec
function THTMXResponseHelper.HXTriggerClientEvents(Names: TArray<string>; After: TClientEventType): TMVCWebResponse;
var
Value: string;
I: Integer;
begin
if Length(Names) = 0 then
Exit(Self);

Value := Names[0];
for var I := Low(Names) + 1 to High(Names) do
for I := Low(Names) + 1 to High(Names) do
Value := Value + ', ' + Names[I];

SetCustomHeader(ClientEventTypes[After], Value);
Expand Down
4 changes: 3 additions & 1 deletion sources/MVCFramework.IntfObjectPool.pas
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,11 @@ procedure TIntfCleanupThread<IInterface>.Execute;

function TIntfCleanupThread<IInterface>.GetAveragePoolSize(
var SizeSamples: TPoolSizeSamples): Integer;
var
I: Integer;
begin
Result := 0;
for var I := Low(TPoolSizeSamples) to High(TPoolSizeSamples) do
for I := Low(TPoolSizeSamples) to High(TPoolSizeSamples) do
begin
Inc(Result, SizeSamples[I]);
end;
Expand Down
4 changes: 3 additions & 1 deletion sources/MVCFramework.ObjectPool.pas
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,11 @@ procedure TCleanupThread<T>.Execute;

function TCleanupThread<T>.GetAveragePoolSize(
var SizeSamples: TPoolSizeSamples): Integer;
var
I: Integer;
begin
Result := 0;
for var I := Low(TPoolSizeSamples) to High(TPoolSizeSamples) do
for I := Low(TPoolSizeSamples) to High(TPoolSizeSamples) do
begin
Inc(Result, SizeSamples[I]);
end;
Expand Down
2 changes: 1 addition & 1 deletion sources/MVCFramework.Serializer.Commons.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,7 @@ function MapDataSetFieldToNullableRTTIField(const AValue: TValue; const AField:
begin
if AField.IsNull then
begin
aRTTIField.GetValue(AObject).AsType<NullableString>().Clear;
aRTTIField.SetValue(AObject, TValue.From<NullableString>(nil));
end
else
begin
Expand Down
42 changes: 0 additions & 42 deletions sources/MVCFramework.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2462,48 +2462,6 @@ procedure TWebContext.SessionStop(const ARaiseExceptionIfExpired: Boolean);
end;

fSessionFactory.TryDeleteSessionID(SId);

// if Assigned(fWebSession) then
// begin
// fWebSession.StopSession;
// FWebSession := nil;
// try
// TMVCSessionFactory.GetInstance.TryDeleteSessionID(Config[TMVCConfigKey.SessionType], SId);
// except
// on E: Exception do
// begin
// LogException(E, 'Cannot delete session file for sessionid: ' + SId);
// end;
// end;
// end;


// TMonitor.Enter(GlobalSessionList);
// try
// SID := SessionId;
// if (SId = '') and (ARaiseExceptionIfExpired) then
// begin
// raise EMVCSessionExpiredException.Create('Session not started');
// end;
//
// GlobalSessionList.Remove(SId);
//
// if SId <> '' then
// begin
// FWebSession := nil;
// try
// TMVCSessionFactory.GetInstance.TryDeleteSessionID(Config[TMVCConfigKey.SessionType], SId);
// except
// on E: Exception do
// begin
// LogException(E, 'Cannot delete session file for sessionid: ' + SId);
// end;
// end;
// end;
// finally
// TMonitor.Exit(GlobalSessionList);
// end;

FIsSessionStarted := False;
FSessionMustBeClose := True;
end;
Expand Down

0 comments on commit e9ee7bb

Please sign in to comment.