kaffa / textpattern

Automatically exported from code.google.com/p/textpattern
0 stars 0 forks source link

do_list_unique() - more correct SQL queries #192

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
<txp:article_custom section="ss,ss,ss,ss,ss" category="cc,cc,cc,c2,c2" 
author="aa,aa,aa,aa" id="1,2,3,4,3,3,3" keywords="kk,kk,kk,kk" />

Duplicate values ​​- is the output of other tags.

What is the expected output?

---
select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as 
uExpires, unix_timestamp(LastMod) as uLastMod from txp_textpattern as 
textpattern where 1=1 and Status = 4 and Posted <= now() and (now() <= Expires 
or Expires = '0000-00-00 00:00:00') and ID IN (1,2,3,4) and (Category1 IN 
('cc','c2') or Category2 IN ('cc','c2')) and Section IN ('ss') and AuthorID IN 
('aa') and (FIND_IN_SET('kk',Keywords)) order by field(id, 1,2,3,4) limit 0, 10

---

What do you see instead?

---
select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as 
uExpires, unix_timestamp(LastMod) as uLastMod from txp_textpattern as 
textpattern where 1=1 and Status >= 4 and Posted <= now() and (now() <= Expires 
or Expires = '0000-00-00 00:00:00') and ID IN (1,2,3,4,3,3,3) and (Category1 IN 
('cc','cc','cc','c2','c2') or Category2 IN ('cc','cc','cc','c2','c2')) and 
Section IN ('ss','ss','ss','ss','ss') and AuthorID IN ('aa','aa','aa','aa') and 
(FIND_IN_SET('kk',Keywords) or FIND_IN_SET('kk',Keywords) or 
FIND_IN_SET('kk',Keywords) or FIND_IN_SET('kk',Keywords)) order by Posted desc 
limit 0, 10

---

Solution:
Replace the call to do_list() do_list_unique()

---
function do_list_unique($list, $delim = ','){
    return array_unique(do_list($list, $delim));
}

---
This was tested in aks_article plugin.

Original issue reported on code.google.com by zasl...@gmail.com on 22 May 2012 at 10:11

GoogleCodeExporter commented 8 years ago

Original comment by r.wetzlmayr on 22 May 2012 at 11:56

GoogleCodeExporter commented 8 years ago
I checked all the function calls do_list() - 53 matches
and have not seen a single case where a need is not a unique array.

Therefore, I think a logical change do_list() to return an array of unique 
values.

Original comment by zasl...@gmail.com on 24 May 2012 at 6:48

Attachments:

GoogleCodeExporter commented 8 years ago
Strictly changing core function behavior that would break all backwards 
compatibility. Textpattern's core isn't the only one using the function. There 
are other including our rah projects from which number use do_list() and none 
expect only unique values. We merely use the function because it allows use of 
callback pseudo-type and trims whitespace from values.

Original comment by jukka.svahn@rahinaa.biz on 25 May 2012 at 12:37

GoogleCodeExporter commented 8 years ago
Why did I say "allows use of callback pseudo-type". But anyways, merely 
changing the behavior isn't an option in my opinion. It just would break other 
potential uses without a good reason. The unique filter is better served as a 
separate new function or as a third argument.

Original comment by jukka.svahn@rahinaa.biz on 25 May 2012 at 12:42

GoogleCodeExporter commented 8 years ago
Make it a unique list is a good idea! Set it as a third argument with preset 
value! So it won't be break anything.

Original comment by chasoft on 10 Jun 2012 at 12:37

GoogleCodeExporter commented 8 years ago

Original comment by r.wetzlmayr on 9 Jul 2012 at 4:24

GoogleCodeExporter commented 8 years ago

Original comment by r.wetzlmayr on 25 Dec 2013 at 9:50