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

View File

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

View File

@@ -565,7 +565,7 @@ var
t1,t2,t3:integer; t1,t2,t3:integer;
i,c,i3,c3:integer; i,c,i3,c3:integer;
idx:integer; idx:integer;
bAggregate:boolean; bAggregate, bGroup:boolean;
selectfieldfunctions:array of TTokenOperator; selectfieldfunctions:array of TTokenOperator;
tablecount, outputfieldcount:integer; tablecount, outputfieldcount:integer;
sqloutput:TjanSQLOutput; sqloutput:TjanSQLOutput;
@@ -855,7 +855,17 @@ begin
matchtables(0); matchtables(0);
// process any group by clause // 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); groupby(recordsets[t3],grouplist);
FMatchrecordSet:=t3; FMatchrecordSet:=t3;
@@ -929,7 +939,7 @@ var
idx:integer; idx:integer;
outputfieldcount:integer; outputfieldcount:integer;
selectfieldfunctions:array of TTokenOperator; selectfieldfunctions:array of TTokenOperator;
bAggregate:boolean; bAggregate, bGroup:boolean;
sqloutput:TjanSQLOutput; sqloutput:TjanSQLOutput;
@@ -1145,7 +1155,17 @@ begin
FMatchrecordSet:=t3; FMatchrecordSet:=t3;
// process any group by clause // 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); groupby(recordsets[t3],grouplist);
end; end;
c3:=recordsets[t3].recordcount; c3:=recordsets[t3].recordcount;