Skip to content

Commit

Permalink
Updated sample to show TryGetNamedSQLQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleteti committed Oct 17, 2023
1 parent 7f6c3e2 commit 52a5840
Show file tree
Hide file tree
Showing 14 changed files with 288 additions and 209 deletions.
8 changes: 5 additions & 3 deletions COMPATIBILITY_MANTAINERS.MD
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ If you use a Delphi version that is not the latest, and you find an issue, check

|Delphi Version | Compatibility Mantainer |
|---|---|
|Delphi 10.4 Sydney | Daniele Teti |
|Delphi 10.3.1 Rio |Daniele Teti, João Fernandes, Emilio Perez |
|Delphi 11 Alexandria | Daniele Teti |
|Delphi 10.4 Sydney | ... |
|Delphi 10.3.1 Rio |João Fernandes, Emilio Perez |
|Delphi 10.2.3 Tokyo |Daniele Barbato, Mohammed Nasman, MJ Wille |
|Delphi 10.2 Community Edition|Akrom Obidov|
|Delphi 10.1.2 Berlin | Emilio Perez, Akrom Obidov, Akbar Khayitov |
|Delphi 10.0 Seattle | Davut Eryılmaz |
| | |



### What is expected by a compatibility mantainer?

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# DelphiMVCFramework ![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg) ![GitHub All Releases](https://img.shields.io/github/downloads/danieleteti/delphimvcframework/total?label=Downloads)

![](https://img.shields.io/badge/Current%20Version-dmvcframework--3.4.0--neon-blue)
![](https://img.shields.io/badge/Beta%20Version-dmvcframework--4.0.0--oxygen--beta-red)
![](https://img.shields.io/badge/stable-dmvcframework--3.4.0--neon-blue)
![](https://img.shields.io/badge/beta-dmvcframework--3.4.1--sodium--beta-red)

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
Expand Down Expand Up @@ -215,7 +215,7 @@ Congratulations to Daniele Teti and all the staff for the excellent work!" -- Ma
> "I managed to generate an API for my application thanks to this framework, it is truly useful and efficient!" -- J. Urbani

## What's New in DelphiMVCFramework-3.4.0-neon (current stable version)
## What's New in DelphiMVCFramework-3.4.0-neon (stable version)

>👉 Deeper analisys of what's new in DelphiMVCFramework-3.4.0-neone is available on [Daniele Teti Blog](http://www.danieleteti.it/post/delphimvcframework-3-4-0-neon/) 👈
Expand Down Expand Up @@ -336,7 +336,7 @@ Congratulations to Daniele Teti and all the staff for the excellent work!" -- Ma
- ⚡ Improved `TMVCResponse` type to better suits the new functional actions.
`TMVCResponse` can be used with "message based" responses and also with "data based" responses (with single object, with a list of objects or with a dictionary of objects).
More info [here](http://www.danieleteti.it/post/delphimvcframework-3-4-0-neon/)
- Removed `statuscode`, `reasonstring` and all the field with a default value from exception's JSON rendering. All the high-level rendering methods will emit standard `ReasonString`.
Expand Down
8 changes: 4 additions & 4 deletions packages/d110/dmvcframework_group.groupproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<Dependencies/>
</Projects>
<Projects Include="dmvcframeworkDT.dproj">
<Dependencies/>
<Dependencies>dmvcframeworkRT.dproj</Dependencies>
</Projects>
</ItemGroup>
<ProjectExtensions>
Expand Down Expand Up @@ -50,13 +50,13 @@
<Target Name="dmvcframeworkRT:Make">
<MSBuild Projects="dmvcframeworkRT.dproj" Targets="Make"/>
</Target>
<Target Name="dmvcframeworkDT">
<Target Name="dmvcframeworkDT" DependsOnTargets="dmvcframeworkRT">
<MSBuild Projects="dmvcframeworkDT.dproj"/>
</Target>
<Target Name="dmvcframeworkDT:Clean">
<Target Name="dmvcframeworkDT:Clean" DependsOnTargets="dmvcframeworkRT:Clean">
<MSBuild Projects="dmvcframeworkDT.dproj" Targets="Clean"/>
</Target>
<Target Name="dmvcframeworkDT:Make">
<Target Name="dmvcframeworkDT:Make" DependsOnTargets="dmvcframeworkRT:Make">
<MSBuild Projects="dmvcframeworkDT.dproj" Targets="Make"/>
</Target>
<Target Name="Build">
Expand Down
3 changes: 3 additions & 0 deletions samples/activerecord_showcase/EntitiesU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,15 @@ TOrder = class;

[MVCNameCase(ncLowerCase)]
[MVCTable('customers')]
[MVCNamedSQLQuery('BestCustomers', 'select * from customers where rating >=4')]
[MVCNamedSQLQuery('WithRatingGtOrEqTo', 'select * from customers where rating >=?')]
[MVCNamedSQLQuery('RatingLessThanPar', 'select * from customers where rating < ? order by code, city desc')]
[MVCNamedSQLQuery('RatingEqualsToPar', 'select /*firebird*/ * from customers where rating = ? order by code, city desc', TMVCActiveRecordBackEnd.FirebirdSQL)]
[MVCNamedSQLQuery('RatingEqualsToPar', 'select /*postgres*/ * from customers where rating = ? order by code, city desc', TMVCActiveRecordBackEnd.PostgreSQL)]
[MVCNamedSQLQuery('RatingEqualsToPar', 'select /*all*/ * from customers where rating = ? order by code, city desc')]
[MVCNamedRQLQuery('RatingLessThanPar', 'lt(rating,%d);sort(+code,-city)')]
[MVCNamedRQLQuery('RatingEqualsToPar', 'eq(rating,%d);sort(+code,-city)')]
[MVCNamedSQLQuery('GetAllCustomers', 'select * from sp_get_customers()', TMVCActiveRecordBackEnd.PostgreSQL)]
TCustomer = class(TCustomEntity)
private
{$IFNDEF USE_SEQUENCES}
Expand Down
66 changes: 59 additions & 7 deletions samples/activerecord_showcase/MainFormU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ TMainForm = class(TForm)
procedure btnIntegersAsBoolClick(Sender: TObject);
private
procedure Log(const Value: string);
procedure LoadCustomers;
procedure LoadCustomers(const HowManyCustomers: Integer = 50);
public
{ Public declarations }
end;
Expand Down Expand Up @@ -712,8 +712,35 @@ procedure TMainForm.btnMultiThreadingClick(Sender: TObject);
procedure TMainForm.btnNamedQueryClick(Sender: TObject);
begin
Log('** Named SQL Query');

LoadCustomers(10);

Log('QuerySQL: BestCustomers');
var lCustomers := TMVCActiveRecord.SelectByNamedQuery<TCustomer>('BestCustomers', [], []);
try
for var lCustomer in lCustomers do
begin
Log(Format('%4d - %8.5s - %s', [lCustomer.ID.ValueOrDefault, lCustomer.Code.ValueOrDefault,
lCustomer.CompanyName.ValueOrDefault]));
end;
finally
lCustomers.Free;
end;

Log('QuerySQL: WithRatingGtOrEqTo');
lCustomers := TMVCActiveRecord.SelectByNamedQuery<TCustomer>('WithRatingGtOrEqTo', [4], [ftInteger]);
try
for var lCustomer in lCustomers do
begin
Log(Format('%4d - %8.5s - %s', [lCustomer.ID.ValueOrDefault, lCustomer.Code.ValueOrDefault,
lCustomer.CompanyName.ValueOrDefault]));
end;
finally
lCustomers.Free;
end;

Log('QuerySQL: RatingLessThanPar');
var lCustomers := TMVCActiveRecord.SelectByNamedQuery<TCustomer>('RatingLessThanPar', [4], [ftInteger]);
lCustomers := TMVCActiveRecord.SelectByNamedQuery<TCustomer>('RatingLessThanPar', [4], [ftInteger]);
try
for var lCustomer in lCustomers do
begin
Expand Down Expand Up @@ -749,6 +776,23 @@ procedure TMainForm.btnNamedQueryClick(Sender: TObject);
lCustomers.Free;
end;


var lTmpSQLQueryWithName: TSQLQueryWithName;
if TMVCActiveRecord.TryGetSQLQuery<TCustomer>('GetAllCustomers', lTmpSQLQueryWithName) then
begin
Log('QuerySQL: Stored Procedure "GetAllCustomers"');
lCustomers := TMVCActiveRecord.SelectByNamedQuery<TCustomer>('GetAllCustomers', [], [], [loIgnoreNotExistentFields]);
try
for var lCustomer in lCustomers do
begin
Log(Format('%4d - %8.5s - %s', [lCustomer.ID.ValueOrDefault, lCustomer.Code.ValueOrDefault,
lCustomer.CompanyName.ValueOrDefault]));
end;
finally
lCustomers.Free;
end;
end;

Log('** Named RQL Query');
Log('QueryRQL: RatingLessThanPar');
lCustomers := TMVCActiveRecord.SelectRQLByNamedQuery<TCustomer>('RatingLessThanPar', [4], 1000);
Expand All @@ -774,7 +818,6 @@ procedure TMainForm.btnNamedQueryClick(Sender: TObject);
lCustomersList.Free;
end;


Log('QueryRQL: RatingEqualsToPar');
lCustomers := TMVCActiveRecord.SelectRQLByNamedQuery<TCustomer>('RatingEqualsToPar', [3], 1000);
try
Expand All @@ -787,7 +830,16 @@ procedure TMainForm.btnNamedQueryClick(Sender: TObject);
lCustomers.Free;
end;


//RatingLessThanPar
var lTmpRQLQueryWithName: TRQLQueryWithName;
if TMVCActiveRecord.TryGetRQLQuery<TCustomer>('RatingLessThanPar', lTmpRQLQueryWithName) then
begin
Log(Format('"%s" RQLQuery is available with text: %s', [lTmpRQLQueryWithName.Name, lTmpRQLQueryWithName.RQLText]));
end
else
begin
Log(Format('"%s" RQLQuery is not available', ['RatingLessThanPar']));
end;
end;

procedure TMainForm.btnNullablesClick(Sender: TObject);
Expand Down Expand Up @@ -2033,20 +2085,20 @@ procedure TMainForm.FormShow(Sender: TObject);
btnJSON_XML_Types.Enabled := ActiveRecordConnectionsRegistry.GetCurrentBackend = 'postgresql';
end;

procedure TMainForm.LoadCustomers;
procedure TMainForm.LoadCustomers(const HowManyCustomers: Integer = 50);
var
lCustomer: TCustomer;
I: Integer;
begin
TMVCActiveRecord.DeleteAll(TCustomer);
for I := 1 to 50 do
for I := 1 to HowManyCustomers do
begin
lCustomer := TCustomer.Create;
try
lCustomer.CompanyName := Stuff[Random(4)] + ' ' + CompanySuffix[Random(5)];
lCustomer.Code := Random(100).ToString.PadLeft(5, '0');
lCustomer.City := Cities[Random(4)];
lCustomer.Rating := Random(5);
lCustomer.Rating := I mod 6;
lCustomer.Note := Stuff[Random(4)];
lCustomer.Insert;
finally
Expand Down
Loading

0 comments on commit 52a5840

Please sign in to comment.