Sites Web : SPIP commits - by tech-nova

Publié le lundi 21 avril 2008

⇒ http://my.opera.com/tech-nova/blog/

Un site qui recense les astuces et évolutions des possibilités de SPIP.

[11435] MySQL views can be used in SPIP loops

Avril 2008, par tech-nova

SQL views are known to be used like tables.
They enable to :
- mask the schema complexity ( -> simplification of queries)
- give access to a limited number of fields ( -> security)
- manipulate calculated fields (sum(), max(), avg(), ..)

Now you can avoid writing complexe loops by using views :

Example :

mysql> create view v AS 
SELECT a.titre,a.id_article,b.id_rubrique,b.titre AS titre_rub 
FROM spip_articles AS a 
LEFT JOIN spip_rubriques AS b ON(a.id_rubrique=b.id_rubrique)
WHERE b.titre REGEXP '^A'
ORDER BY a.titre DESC;

template :

#TITRE : #TITRE_RUB

SPIP implements this for MySQL and sqlite
(for sqlite you must explicit the name of the fields used in the view)

Fantastic, no ?

(PS. : note that views do not improve the performance of your queries, so use them sparingly)

→ Lire la suite sur le site d’origine…


Revenir en haut