{collecte}

  • Apparu en : SPIP 2.0

De voorwaarde {collecte} geeft de "collation" aan van een door een lus gemaakte query aan (het aanroepen van «COLLATE» in MySQL [1]).

Het is een specifieke sorteervolgorde van "ORDER BY" (SPIP voorwaarde {par ...}).

Voorbeeld

We hebben een database in UTF-8 met tabellen in UTF8 (DEFAULT CHARSET = utf8).

In deze tekenset (CHARACTER_SET_NAME) is het mogelijk 21 verschillende collations te gebruiken [2]:

COLLATION_NAME CHARACTER_SET_NAME
utf8_bin utf8
utf8_czech_ci utf8
utf8_danish_ci utf8
utf8_esperanto_ci utf8
utf8_estonian_ci utf8
utf8_general_ci utf8
utf8_hungarian_ci utf8
utf8_icelandic_ci utf8
utf8_latvian_ci utf8
utf8_lithuanian_ci utf8
utf8_persian_ci utf8
utf8_polish_ci utf8
utf8_roman_ci utf8
utf8_romanian_ci utf8
utf8_slovak_ci utf8
utf8_slovenian_ci utf8
utf8_spanish2_ci utf8
utf8_spanish_ci utf8
utf8_swedish_ci utf8
utf8_turkish_ci utf8
utf8_unicode_ci utf8

Stel je voor dat in de tabel «spip_articles» van de database die standaard sorteert op utf8_general_ci, artikelen met de volgende titels staan:

Nana
nina
Nina
Niña
Ñiña
ñina
Ñina
Nono
Nunu

De lus:

<BOUCLE_a(ARTICLES) {par titre} {"<br />"}>
  #TITRE
</BOUCLE_a>

retourneert deze artikelen in alfabetische volgorde van de standaard sorteerwijze:

Nana
nina
Ñina
Nina
Niña
Ñiña
ñina
Nono
Nunu

De lus:

#SET{collation, utf8_spanish2_ci}
<BOUCLE_a(ARTICLES) {par titre} {collecte #GET{collation}} {"<br />"}>
  #TITRE
</BOUCLE_a>

retourneert deze artikelen in alfabetische volgorde van de aangegeven sorteerwijze:

Nana
nina
Nina
Niña
Nono
Nunu
Ñina
ñina
Ñiña

Dus de ñ (n met een tilde) worden achter de n (kale n) gerangschikt.
Dit komt overeen met de Catalaanse volgorde:

  • «De ñ is de vijftiende letter van de Catalaanse versie van het Latijnse alfabet, tussen N en O

De gegenereerde MySQL query is:

  SELECT articles.titre, articles.lang
      FROM spip_articles AS <span class="base64" title="PGNvZGUgY2xhc3M9InNwaXBfY29kZSBzcGlwX2NvZGVfaW5saW5lIiBkaXI9Imx0ciI+YXJ0aWNsZXM8L2NvZGU+"></span>
    WHERE articles.statut = 'publie'
        AND articles.date < '9999-12-31'
ORDER BY articles.titre COLLATE utf8_spanish2_ci

Beperking

Het is niet mogelijk de voorwaarde {collecte} direct in de lus te voorzien van het argument: de {collecte utf8_spanish2_ci}, {collecte 'utf8_spanish2_ci'}, {collecte{utf8_spanish2_ci}}... zullen een PHP-foutmelding geven.
Je kunt de parameter uitsluitend doorgeven via een #GET{} na die eerst te hebben gedefinieerd met een #SET{}.

Voetnoot

[1Zie de officiële documentatie van "COLLATE" in MySQL: http://dev.mysql.com/doc/refman/5.7... en: Een voorbeeld van het effect

[2In latin1 zijn het er 8:

| COLLATION_NAME | CHARACTER_SET_NAME | | latin1_bin | latin1 | | latin1_danish_ci | latin1 | | latin1_general_ci | latin1 | | latin1_general_cs | latin1 | | latin1_german1_ci | latin1 | | latin1_german2_ci | latin1 | | latin1_spanish_ci | latin1 | | latin1_swedish_ci | latin1 |

Auteur Hanjo Gepubliceerd op: Aangepast: 11/12/17

Vertalingen: català, English, Español, français, Nederlands