ZMSQL: Fix SELECT DISTINCT query to not require any aggregate function (https://forum.lazarus.freepascal.org/index.php/topic,56155.msg417368.html). Patch by paweld.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8087 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2021-09-13 08:06:43 +00:00
parent 8659037313
commit 8dca997d00
3 changed files with 44 additions and 19 deletions

View File

@ -1,9 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="11"/>
<Version Value="12"/>
<General>
<MainUnit Value="0"/>
<Flags>
<CompatibilityMode Value="True"/>
</Flags>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
</General>
@ -15,15 +17,16 @@
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|o|so);*~;backup"/>
</PublishOptions>
<RunParams>
<local>
<LaunchingApplication PathPlusParams="/usr/bin/xterm -T &apos;Lazarus Run Output&apos; -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
<FormatVersion Value="2"/>
<Modes Count="1">
<Mode0 Name="default">
<local>
<LaunchingApplication PathPlusParams="/usr/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
<LaunchingApplication PathPlusParams="/usr/bin/xterm -T &apos;Lazarus Run Output&apos; -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
</Mode0>
</Modes>
@ -55,8 +58,8 @@
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/>
<IsVisibleTab Value="True"/>
<TopLine Value="45"/>
<CursorPos X="23" Y="74"/>
<TopLine Value="42"/>
<CursorPos X="39" Y="60"/>
<UsageCount Value="46"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>

View File

@ -1,13 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="11"/>
<Version Value="12"/>
<General>
<MainUnit Value="0"/>
<Flags>
<CompatibilityMode Value="True"/>
</Flags>
<Title Value="project2"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
<Icon Value="0"/>
</General>
<i18n>
<EnableI18N LFM="False"/>
@ -17,15 +18,16 @@
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<IncludeFileFilter Value="*.(pas|pp|inc|frm|ppr|lrs|ctpr|ctpkg|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|o|so);*~;backup"/>
</PublishOptions>
<RunParams>
<local>
<LaunchingApplication PathPlusParams="/usr/bin/xterm -T &apos;Typhon Run Output&apos; -e $(TyphonDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
<FormatVersion Value="2"/>
<Modes Count="1">
<Mode0 Name="default">
<local>
<LaunchingApplication PathPlusParams="/usr/bin/xterm -T 'Typhon Run Output' -e $(TyphonDir)/tools/runwait.sh $(TargetCmdLine)"/>
<LaunchingApplication PathPlusParams="/usr/bin/xterm -T &apos;Typhon Run Output&apos; -e $(TyphonDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
</Mode0>
</Modes>
@ -55,8 +57,8 @@
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<IsVisibleTab Value="True"/>
<TopLine Value="64"/>
<CursorPos X="3" Y="49"/>
<TopLine Value="61"/>
<CursorPos X="53" Y="78"/>
<UsageCount Value="200"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>

View File

@ -565,7 +565,7 @@ var
t1,t2,t3:integer;
i,c,i3,c3:integer;
idx:integer;
bAggregate:boolean;
bAggregate, bGroup:boolean;
selectfieldfunctions:array of TTokenOperator;
tablecount, outputfieldcount:integer;
sqloutput:TjanSQLOutput;
@ -855,7 +855,17 @@ begin
matchtables(0);
// process any group by clause
if bAggregate and (recordsets[t3].recordcount>1) then
bGroup := bAggregate;
if not bGroup then
begin
for i := 0 to query.FTokens.Count - 1 do
if query.tokens[i]._operator=tosqlGROUP then
begin
bGroup := True;
break;
end
end;
if (bAggregate or bGroup) and (recordsets[t3].recordcount>1) then
groupby(recordsets[t3],grouplist);
FMatchrecordSet:=t3;
@ -929,7 +939,7 @@ var
idx:integer;
outputfieldcount:integer;
selectfieldfunctions:array of TTokenOperator;
bAggregate:boolean;
bAggregate, bGroup:boolean;
sqloutput:TjanSQLOutput;
@ -1145,7 +1155,17 @@ begin
FMatchrecordSet:=t3;
// process any group by clause
if bAggregate and (recordsets[t3].recordcount>1) then begin
bGroup := bAggregate;
if not bGroup then
begin
for i := 0 to query.FTokens.Count - 1 do
if query.tokens[i]._operator=tosqlGROUP then
begin
bGroup := True;
break;
end
end;
if (bAggregate or bGroup) and (recordsets[t3].recordcount>1) then begin
groupby(recordsets[t3],grouplist);
end;
c3:=recordsets[t3].recordcount;