From bc96a6866a779e14ec41a565ba55abf9e605c486 Mon Sep 17 00:00:00 2001 From: Daniele Teti Date: Wed, 7 Apr 2021 19:41:02 +0200 Subject: [PATCH] [+] Improved some samples --- samples/CustomAuth/MyWebModuleU.pas | 6 +--- samples/activerecord_showcase/MainFormU.pas | 32 ++++++++++++++++--- .../vclclient/MainClientFormU.pas | 4 ++- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/samples/CustomAuth/MyWebModuleU.pas b/samples/CustomAuth/MyWebModuleU.pas index 9cb60638..9221ccd6 100644 --- a/samples/CustomAuth/MyWebModuleU.pas +++ b/samples/CustomAuth/MyWebModuleU.pas @@ -2,7 +2,7 @@ // // Delphi MVC Framework // -// Copyright (c) 2010-2020 Daniele Teti and the DMVCFramework Team +// Copyright (c) 2010-2021 Daniele Teti and the DMVCFramework Team // // https://github.com/danieleteti/delphimvcframework // @@ -84,10 +84,6 @@ begin TCustomAuth.Create, '/system/users/logged' )); -// FMVC.AddMiddleware(TMVCStaticFilesMiddleware.Create( -// '/app', { StaticFilesPath } -// ExtractFilePath(GetModuleName(HInstance)) + 'www' { DocumentRoot } -// )); end; procedure TMyWebModule.WebModuleDestroy(Sender: TObject); diff --git a/samples/activerecord_showcase/MainFormU.pas b/samples/activerecord_showcase/MainFormU.pas index 7aaa77d4..02a01e9f 100644 --- a/samples/activerecord_showcase/MainFormU.pas +++ b/samples/activerecord_showcase/MainFormU.pas @@ -1111,6 +1111,9 @@ var lCustomer: TCustomerWithSpaces; lID: Integer; I: Integer; + cRQL1: string; + lList: TMVCActiveRecordList; + lItem: TMVCActiveRecord; begin Log('** Simple CRUD (table and fields with spaces) test'); Log('There are ' + TMVCActiveRecord.Count().ToString + ' row/s for entity ' + @@ -1121,7 +1124,8 @@ begin begin lCustomer := TCustomerWithSpaces.Create; try - lCustomer.ID := I; + lID := I; + lCustomer.ID := lID; // just for test!! case I mod 3 of 0: @@ -1134,7 +1138,6 @@ begin lCustomer.City := 'Montain View, CA'; lCustomer.Note := 'Hello there!'; lCustomer.Insert; - lID := lCustomer.ID; Log('Just inserted Customer ' + lID.ToString); finally lCustomer.Free; @@ -1143,8 +1146,12 @@ begin Log('Now there are ' + TMVCActiveRecord.Count().ToString + ' row/s for entity ' + TCustomerWithSpaces.ClassName); - TMVCActiveRecord.DeleteRQL(TCustomerWithSpaces, 'lt(id,90)'); + Log('Deleting using RQL...'); + TMVCActiveRecord.DeleteRQL(TCustomerWithSpaces, 'lt(id,80)'); + Log('Now there are ' + TMVCActiveRecord.Count().ToString + + ' row/s for entity ' + TCustomerWithSpaces.ClassName); + //gets the last inserted customer lCustomer := TMVCActiveRecord.GetByPK(lID); try Assert(not lCustomer.Code.HasValue); @@ -1172,6 +1179,21 @@ begin finally lCustomer.Free; end; + + cRQL1 := 'eq(CompanyName,"Google Inc.")'; + Log('>> RQL Query (customers with spaces) - ' + cRQL1); + lList := TMVCActiveRecord.SelectRQL(TCustomerWithSpaces, cRQL1, 20); + try + Log(lList.Count.ToString + ' record/s found'); + for lItem in lList do + begin + lCustomer := TCustomerWithSpaces(lItem); + Log(Format('%5s - %s (%s)', [lCustomer.Code.ValueOrDefault, + lCustomer.CompanyName.ValueOrDefault, lCustomer.City])); + end; + finally + lList.Free; + end; end; procedure TMainForm.FormDestroy(Sender: TObject); @@ -1227,8 +1249,8 @@ begin {$ENDIF} btnWithSpaces.Enabled := (ActiveRecordConnectionsRegistry.GetCurrentBackend = 'postgresql') or -// (ActiveRecordConnectionsRegistry.GetCurrentBackend = 'firebird') or -// (ActiveRecordConnectionsRegistry.GetCurrentBackend = 'interbase') or + (ActiveRecordConnectionsRegistry.GetCurrentBackend = 'firebird') or + (ActiveRecordConnectionsRegistry.GetCurrentBackend = 'interbase') or (ActiveRecordConnectionsRegistry.GetCurrentBackend = 'sqlite'); btnJSON_XML_Types.Enabled := ActiveRecordConnectionsRegistry.GetCurrentBackend = 'postgresql'; diff --git a/samples/authenticationauthorization/vclclient/MainClientFormU.pas b/samples/authenticationauthorization/vclclient/MainClientFormU.pas index 1b8177c1..0e7966a4 100644 --- a/samples/authenticationauthorization/vclclient/MainClientFormU.pas +++ b/samples/authenticationauthorization/vclclient/MainClientFormU.pas @@ -36,7 +36,9 @@ begin lClient := TMVCRESTClient.New.BaseURL('localhost', 8080); lClient.SetBasicAuthorization('user1', 'user1'); lRest := lClient.Get('/admin/role1?par1=daniele'); - ShowMessage(lRest.Content); + ShowMessage( + Format('%d %s', [lRest.StatusCode, lRest.StatusText]) + sLineBreak + + lRest.Content); end; end.