⇒ http://my.opera.com/tech-nova/blog/
Un site qui recense les astuces et évolutions des possibilités de SPIP.
[11440] SQL views in the API
Avril 2008, par tech-nova3 new functions enable to create and delete views for PG, SQlite and MySQL :
- sql_get_select() : same arguments as sql_select() but returns the query without evaluating it
- sql_create_view($view_name, $select_request) : creates the view $view_name for the select request $select_request.
- sql_drop_view($view_name) : drops the view.
/ !\ Warning ! Yous must give an explicit name to every field prefixed with a table name or an alias. Elsewhere SQLite won’t be able to read the view (which contains ’a.titre’ instead of ’titre’).
Example :
$sel = sql_get_select( array( 'id_article'=>'id_article', 'titre'=>'titre' ), 'spip_articles'); echo "requete select : $sel
"; sql_create_view('vue_nom', $sel); $res = sql_select(array('id_article', 'titre'),'vue_nom',,,,'10'); if ($res){ while ($r = sql_fetch($res)){ echo "*" . $r['id_article'] . " - " . $r['titre'] . "
"; } } sql_drop_view('vue_nom');
→ Lire la suite sur le site d’origine…