From 01e52a0cde5a90de30eaf998fac7547c5c4a2004 Mon Sep 17 00:00:00 2001
From: "Committo,Ergo:sum" <esj@rezo.net>
Date: Wed, 3 Oct 2007 20:44:21 +0000
Subject: [PATCH] =?UTF-8?q?Abstraction=20de=20tous=20les=20appels=20{{{=20?=
 =?UTF-8?q?spip=5Fquery("SELECT=20.....=20WHERE=20...=20}}}=20pour=20que?=
 =?UTF-8?q?=20les=20champs=20de=20type=20Date=20dans=20la=20clause=20WHERE?=
 =?UTF-8?q?=20soient=20transform=C3=A9=20pour=20Postgres.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Dépot obtenu par:

{{{
for i in $(grep -l 'spip_query..SELECT.*FROM.*WHERE[^A-Z]*;$' [a-i]*/*php)
do
# Pour la clause DISTINCT, laisser intact pour le moment.
sed 's/spip_query..SELECT *\([^D]*[^ ]\) *FROM *\(.*[^ ]\) *WHERE *\([^A-Z]*;\)$/sql_select("\1", "\2", "\3/;s/ "" *\.//;s/ch(sql_select\(.*\));/sel\1;/' $i > x
echo $i
mv x $i
done
#}}}

et deux suppressions manuelles de lourdeurs syntaxiques résultantes.
Pas d'intervention sur le fichier inc/meta: au test, include manquant. À controler.
---
 ecrire/action/acceder_document.php          |  2 +-
 ecrire/action/copier_local.php              |  2 +-
 ecrire/action/dater.php                     |  2 +-
 ecrire/action/editer_article.php            |  8 ++++----
 ecrire/action/editer_auteur.php             |  2 +-
 ecrire/action/editer_breve.php              |  8 ++++----
 ecrire/action/editer_mot.php                |  2 +-
 ecrire/action/editer_rubrique.php           |  4 ++--
 ecrire/action/editer_signatures.php         |  2 +-
 ecrire/action/editer_site.php               |  6 +++---
 ecrire/action/ical.php                      | 10 +++++-----
 ecrire/action/instituer_forum.php           |  2 +-
 ecrire/action/instituer_langue_rubrique.php |  2 +-
 ecrire/action/instituer_mot.php             |  2 +-
 ecrire/action/pass.php                      |  2 +-
 ecrire/action/referencer_traduction.php     |  4 ++--
 ecrire/action/reorganiser.php               |  6 +++---
 ecrire/action/rss.php                       | 10 +++++-----
 ecrire/action/supprimer.php                 |  6 +++---
 ecrire/action/supprimer_traduction.php      |  2 +-
 ecrire/action/tester_taille.php             |  2 +-
 ecrire/action/tourner.php                   |  2 +-
 ecrire/balise/formulaire_inscription.php    |  2 +-
 ecrire/exec/articles.php                    |  2 +-
 ecrire/exec/articles_forum.php              |  2 +-
 ecrire/exec/articles_versions.php           |  2 +-
 ecrire/exec/auteur_infos.php                |  2 +-
 ecrire/exec/breves_edit.php                 |  8 ++++----
 ecrire/exec/breves_voir.php                 |  6 +++---
 ecrire/exec/brouteur.php                    |  6 +++---
 ecrire/exec/controle_forum.php              |  8 ++++----
 ecrire/exec/controle_petition.php           |  2 +-
 ecrire/exec/dater.php                       |  2 +-
 ecrire/exec/editer_mot.php                  |  4 ++--
 ecrire/exec/export_all.php                  |  2 +-
 ecrire/exec/forum_envoi.php                 |  4 ++--
 ecrire/exec/grouper_mots.php                |  2 +-
 ecrire/exec/iconifier.php                   |  2 +-
 ecrire/exec/instituer_auteur.php            |  2 +-
 ecrire/exec/message.php                     |  6 +++---
 ecrire/exec/message_edit.php                |  6 +++---
 ecrire/exec/mots_edit.php                   |  2 +-
 ecrire/exec/mots_tous.php                   |  4 ++--
 ecrire/exec/mots_type.php                   |  2 +-
 ecrire/exec/naviguer.php                    |  6 +++---
 ecrire/exec/puce_statut.php                 |  2 +-
 ecrire/exec/rechercher.php                  |  6 +++---
 ecrire/exec/referencer_traduction.php       |  2 +-
 ecrire/exec/rubriques_edit.php              |  4 ++--
 ecrire/exec/sites.php                       |  2 +-
 ecrire/exec/sites_edit.php                  |  4 ++--
 ecrire/exec/statistiques_repartition.php    |  4 ++--
 ecrire/exec/virtualiser.php                 |  2 +-
 ecrire/genie/syndic.php                     |  6 +++---
 ecrire/inc/acces.php                        |  2 +-
 ecrire/inc/actions.php                      |  2 +-
 ecrire/inc/afficher_objets.php              |  6 +++---
 ecrire/inc/agenda.php                       |  2 +-
 ecrire/inc/article_select.php               | 10 +++++-----
 ecrire/inc/auth_ldap.php                    |  2 +-
 ecrire/inc/auth_spip.php                    |  2 +-
 ecrire/inc/autoriser.php                    | 10 +++++-----
 ecrire/inc/chercher_rubrique.php            |  2 +-
 ecrire/inc/distant.php                      | 10 +++++-----
 ecrire/inc/documenter.php                   |  2 +-
 ecrire/inc/documents.php                    | 10 +++++-----
 ecrire/inc/editer_auteurs.php               |  2 +-
 ecrire/inc/editer_mot.php                   |  6 +++---
 ecrire/inc/extra.php                        |  2 +-
 ecrire/inc/forum.php                        |  6 +++---
 ecrire/inc/forum_insert.php                 |  4 ++--
 ecrire/inc/import_insere.php                |  2 +-
 ecrire/inc/informer.php                     |  2 +-
 ecrire/inc/informer_auteur.php              |  4 ++--
 ecrire/inc/legender.php                     |  2 +-
 ecrire/inc/modifier.php                     |  8 ++++----
 ecrire/inc/notifications.php                | 12 ++++++------
 ecrire/inc/petitionner.php                  |  2 +-
 ecrire/inc/presentation.php                 |  2 +-
 ecrire/inc/puce_statut.php                  |  2 +-
 ecrire/inc/referencer_traduction.php        |  6 +++---
 ecrire/inc/regler_moderation.php            |  2 +-
 ecrire/inc/revisions.php                    |  2 +-
 ecrire/inc/rubriques.php                    |  2 +-
 ecrire/inc/securiser_action.php             |  2 +-
 ecrire/inc/selectionner.php                 |  2 +-
 ecrire/inc/signatures.php                   |  2 +-
 ecrire/inc/tourner.php                      |  4 ++--
 ecrire/install/etape_4.php                  |  2 +-
 89 files changed, 172 insertions(+), 172 deletions(-)

diff --git a/ecrire/action/acceder_document.php b/ecrire/action/acceder_document.php
index bc2aaf9641..be982670b1 100644
--- a/ecrire/action/acceder_document.php
+++ b/ecrire/action/acceder_document.php
@@ -40,7 +40,7 @@ function action_acceder_document_dist() {
 		$where = "documents.fichier="._q(set_spip_doc($file))
 		. ($arg ? " AND documents.id_document=".intval($arg): '');
 
-		$s = spip_query("SELECT documents.id_document, documents.titre, documents.descriptif, documents.distant, documents.fichier, types.mime_type FROM spip_documents AS documents LEFT JOIN spip_types_documents AS types ON documents.extension=types.extension WHERE ".$where);
+		$s = sql_select("documents.id_document, documents.titre, documents.descriptif, documents.distant, documents.fichier, types.mime_type", "spip_documents AS documents LEFT JOIN spip_types_documents AS types ON documents.extension=types.extension",$where);
 		if (!$doc = sql_fetch($s)) {
 			$status = 404;
 		} else {
diff --git a/ecrire/action/copier_local.php b/ecrire/action/copier_local.php
index 00a797e9d4..22cc47387c 100644
--- a/ecrire/action/copier_local.php
+++ b/ecrire/action/copier_local.php
@@ -38,7 +38,7 @@ function action_copier_local_dist() {
 function action_copier_local_post($id_document) {
 
 	// Il faut la source du document pour le copier
-	$s = spip_query("SELECT fichier, descriptif FROM spip_documents WHERE id_document=$id_document");
+	$s = sql_select("fichier, descriptif", "spip_documents", "id_document=$id_document");
 	$row = sql_fetch($s);
 	$source = $row['fichier'];
 
diff --git a/ecrire/action/dater.php b/ecrire/action/dater.php
index 3340e27cea..43b73425c0 100644
--- a/ecrire/action/dater.php
+++ b/ecrire/action/dater.php
@@ -57,7 +57,7 @@ function action_dater_post($r)
 
 	if (($type == 'article')
 	AND $GLOBALS['meta']["post_dates"] == "non") {
-		$t = sql_fetch(spip_query("SELECT statut, id_rubrique FROM spip_articles WHERE id_article=$id"));
+		$t = sql_fetsel("statut, id_rubrique", "spip_articles", "id_article=$id");
 		if ($t['statut'] == 'publie') {
 			include_spip('inc/rubriques');
 			if  (strtotime($date) >  time())
diff --git a/ecrire/action/editer_article.php b/ecrire/action/editer_article.php
index 5d5d744208..90da49cec2 100644
--- a/ecrire/action/editer_article.php
+++ b/ecrire/action/editer_article.php
@@ -69,7 +69,7 @@ function insert_article($id_rubrique) {
 	// Si id_rubrique vaut 0 ou n'est pas definie, creer l'article
 	// dans la premiere rubrique racine
 	if (!$id_rubrique = intval($id_rubrique)) {
-		$row = sql_fetch(sql_select("id_rubrique", "spip_rubriques", "id_parent=0",'', '0+titre,titre', "1"));
+		$row = sql_fetsel("id_rubrique", "spip_rubriques", "id_parent=0",'', '0+titre,titre', "1");
 		$id_rubrique = $row['id_rubrique'];
 	}
 
@@ -86,7 +86,7 @@ function insert_article($id_rubrique) {
 		}
 	}
 
-	$row = sql_fetch(spip_query("SELECT lang, id_secteur FROM spip_rubriques WHERE id_rubrique=$id_rubrique"));
+	$row = sql_fetsel("lang, id_secteur", "spip_rubriques", "id_rubrique=$id_rubrique");
 
 	$id_secteur = $row['id_secteur'];
 
@@ -157,7 +157,7 @@ function instituer_article($id_article, $c, $calcul_rub=true) {
 	include_spip('inc/rubriques');
 	include_spip('inc/modifier');
 
-	$s = spip_query("SELECT statut, id_rubrique FROM spip_articles WHERE id_article=$id_article");
+	$s = sql_select("statut, id_rubrique", "spip_articles", "id_article=$id_article");
 	$row = sql_fetch($s);
 	$id_rubrique = $row['id_rubrique'];
 	$statut_ancien = $statut = $row['statut'];
@@ -266,7 +266,7 @@ function editer_article_heritage($id_article, $id_rubrique, $statut, $champs, $c
 	//  changer aussi son secteur et sa langue (si heritee)
 	if (isset($champs['id_rubrique'])) {
 
-		$row_rub = sql_fetch(spip_query("SELECT id_secteur, lang FROM spip_rubriques WHERE id_rubrique="._q($champs['id_rubrique'])));
+		$row_rub = sql_fetsel("id_secteur, lang", "spip_rubriques", "id_rubrique="._q($champs['id_rubrique']));
 
 		$langue = $row_rub['lang'];
 		$champs['id_secteur'] = $row_rub['id_secteur'];
diff --git a/ecrire/action/editer_auteur.php b/ecrire/action/editer_auteur.php
index 7cf39fcbfc..9ac52411fb 100644
--- a/ecrire/action/editer_auteur.php
+++ b/ecrire/action/editer_auteur.php
@@ -54,7 +54,7 @@ function action_legender_auteur_post($r) {
 //
 	$auteur = array();
 	if ($id_auteur) {
-		$auteur = sql_fetch(spip_query("SELECT * FROM spip_auteurs WHERE id_auteur=$id_auteur"));
+		$auteur = sql_fetsel("*", "spip_auteurs", "id_auteur=$id_auteur");
 	  }
 	if (!$auteur) {
 		$id_auteur = 0;
diff --git a/ecrire/action/editer_breve.php b/ecrire/action/editer_breve.php
index e18ce3e70d..ab3fe4f6e1 100644
--- a/ecrire/action/editer_breve.php
+++ b/ecrire/action/editer_breve.php
@@ -58,12 +58,12 @@ function insert_breve($id_rubrique) {
 	// Si id_rubrique vaut 0 ou n'est pas definie, creer la breve
 	// dans la premiere rubrique racine
 	if (!$id_rubrique = intval($id_rubrique)) {
-		$row = sql_fetch(sql_select("id_rubrique", "spip_rubriques", "id_parent=0",'', '0+titre,titre', "1"));
+		$row = sql_fetsel("id_rubrique", "spip_rubriques", "id_parent=0",'', '0+titre,titre', "1");
 		$id_rubrique = $row['id_rubrique'];
 	}
 
 	// La langue a la creation : c'est la langue de la rubrique
-	$row = sql_fetch(spip_query("SELECT lang, id_secteur FROM spip_rubriques WHERE id_rubrique=$id_rubrique"));
+	$row = sql_fetsel("lang, id_secteur", "spip_rubriques", "id_rubrique=$id_rubrique");
 	$choisie = 'non';
 	$lang = $row['lang'];
 	$id_rubrique = $row['id_secteur']; // garantir la racine
@@ -98,7 +98,7 @@ function revisions_breves ($id_breve, $c=false) {
 	}
 
 	// Changer le statut de la breve ?
-	$row = sql_fetch(spip_query("SELECT statut, id_rubrique,lang, langue_choisie FROM spip_breves WHERE id_breve=$id_breve"));
+	$row = sql_fetsel("statut, id_rubrique,lang, langue_choisie", "spip_breves", "id_breve=$id_breve");
 
 	$id_rubrique = $row['id_rubrique'];
 	$statut_ancien = $statut = $row['statut'];
@@ -192,7 +192,7 @@ function revisions_breves ($id_breve, $c=false) {
 function revisions_breves_langue($id_breve, $id_rubrique, $changer_lang)
 {
 	if ($changer_lang == "herit") {
-		$row = sql_fetch(spip_query("SELECT lang FROM spip_rubriques WHERE id_rubrique=$id_rubrique"));
+		$row = sql_fetsel("lang", "spip_rubriques", "id_rubrique=$id_rubrique");
 		$langue_parent = $row['lang'];
 		spip_query("UPDATE spip_breves SET lang=" . _q($langue_parent) . ", langue_choisie='non' WHERE id_breve=$id_breve");
 	} else 	{
diff --git a/ecrire/action/editer_mot.php b/ecrire/action/editer_mot.php
index 74ce4e13c1..c122a365d8 100644
--- a/ecrire/action/editer_mot.php
+++ b/ecrire/action/editer_mot.php
@@ -75,7 +75,7 @@ function action_editer_mot_post($r)
 	if (preg_match(',exec=grouper_mots,',$redirect)){
 		// mettre a jour le total de mots dans la liste pour eviter les pb de cache navigateur avec ajax
 		$id_groupe = parametre_url($redirect,'id_groupe'); // recuperer l'id_groupe dans l'url
-		$groupe = sql_fetch(spip_query("SELECT COUNT(*) AS n FROM spip_mots WHERE id_groupe="._q($id_groupe)));
+		$groupe = sql_fetsel("COUNT(*) AS n", "spip_mots", "id_groupe="._q($id_groupe));
 		$redirect = parametre_url($redirect,'total',$groupe['n'],'&');
 	}
 	    
diff --git a/ecrire/action/editer_rubrique.php b/ecrire/action/editer_rubrique.php
index bb4072a4be..5777c48dd0 100644
--- a/ecrire/action/editer_rubrique.php
+++ b/ecrire/action/editer_rubrique.php
@@ -76,7 +76,7 @@ function revisions_rubriques($id_rubrique, $c=false) {
 		if (strpos(",$id_parent',", "$,filles,") != false)
 			spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent");
 		else {
-			$s = sql_fetch(spip_query("SELECT id_parent, statut FROM spip_rubriques WHERE id_rubrique=$id_rubrique"));
+			$s = sql_fetsel("id_parent, statut", "spip_rubriques", "id_rubrique=$id_rubrique");
 			$old_parent = $s['id_parent'];
 
 			if (!($id_parent != $old_parent
@@ -152,7 +152,7 @@ function editer_rubrique_breves($id_rubrique, $id_parent, $c=false)
 	if (!$t) return true;
 	$t = (_request('confirme_deplace', $c) <> 'oui');
 	if ($t) return false;
-	$id_secteur = sql_fetch(spip_query("SELECT id_secteur FROM spip_rubriques WHERE id_rubrique=$id_parent"));
+	$id_secteur = sql_fetsel("id_secteur", "spip_rubriques", "id_rubrique=$id_parent");
 	if ($id_secteur= $id_secteur['id_secteur'])
 		spip_query("UPDATE spip_breves SET id_rubrique=$id_secteur WHERE id_rubrique=$id_rubrique");
 	return true;
diff --git a/ecrire/action/editer_signatures.php b/ecrire/action/editer_signatures.php
index 262a8941bc..23bbbc6b24 100644
--- a/ecrire/action/editer_signatures.php
+++ b/ecrire/action/editer_signatures.php
@@ -42,7 +42,7 @@ function action_editer_signatures_post($r)
 	// Invalider les pages ayant trait aux petitions
 	if ($id) {
 		include_spip('inc/invalideur');
-		$id_article = sql_fetch(spip_query("SELECT id_article FROM spip_signatures WHERE id_signature=$id"));
+		$id_article = sql_fetsel("id_article", "spip_signatures", "id_signature=$id");
 		$id_article = $id_article['id_article'];
 		suivre_invalideur("id='varia/pet$id_article'");
 	}
diff --git a/ecrire/action/editer_site.php b/ecrire/action/editer_site.php
index b5edc7fc3a..1edcffe356 100644
--- a/ecrire/action/editer_site.php
+++ b/ecrire/action/editer_site.php
@@ -140,13 +140,13 @@ function insert_syndic($id_rubrique) {
 	// Si id_rubrique vaut 0 ou n'est pas definie, creer le site
 	// dans la premiere rubrique racine
 	if (!$id_rubrique = intval($id_rubrique)) {
-		$row = sql_fetch(sql_select("id_rubrique", "spip_rubriques", "id_parent=0",'', '0+titre,titre', "1"));
+		$row = sql_fetsel("id_rubrique", "spip_rubriques", "id_parent=0",'', '0+titre,titre', "1");
 		$id_rubrique = $row['id_rubrique'];
 	}
 
 
 	// Le secteur a la creation : c'est le secteur de la rubrique
-	$row = sql_fetch(spip_query("SELECT id_secteur FROM spip_rubriques WHERE id_rubrique=$id_rubrique"));
+	$row = sql_fetsel("id_secteur", "spip_rubriques", "id_rubrique=$id_rubrique");
 	$id_secteur = $row['id_secteur'];
 
 	$id_syndic = sql_insert("spip_syndic",
@@ -182,7 +182,7 @@ function revisions_sites ($id_syndic, $c=false) {
 			$champs[$champ] = corriger_caracteres($val);
 	}
 
-	$s = spip_query("SELECT statut, id_rubrique, id_secteur FROM spip_syndic WHERE id_syndic=$id_syndic");
+	$s = sql_select("statut, id_rubrique, id_secteur", "spip_syndic", "id_syndic=$id_syndic");
 	$row = sql_fetch($s);
 	$id_rubrique = $row['id_rubrique'];
 	$statut_ancien = $row['statut'];
diff --git a/ecrire/action/ical.php b/ecrire/action/ical.php
index c2d26fd99e..2e4608ff40 100644
--- a/ecrire/action/ical.php
+++ b/ecrire/action/ical.php
@@ -38,7 +38,7 @@ function action_ical_dist()
 	}
 
 	if (verifier_low_sec($id_auteur, $arg, $action)) {
-		$result = spip_query("SELECT * FROM spip_auteurs WHERE id_auteur=" . intval($id_auteur));
+		$result = sql_select("*", "spip_auteurs", "id_auteur=" . intval($id_auteur));
 
 		if ($row = sql_fetch($result)) {
 			$id_utilisateur=$row['id_auteur'];
@@ -197,7 +197,7 @@ function spip_ical_taches($id_utilisateur, $nom_site)
 // http://doc.spip.org/@spip_ical_articles
 function spip_ical_articles($nom_site)
 {
-	$result_articles = spip_query("SELECT id_article, titre, date FROM spip_articles WHERE statut = 'prop'");
+	$result_articles = sql_select("id_article, titre, date", "spip_articles", "statut = 'prop'");
 	$titres = array();
 	while($row=sql_fetch($result_articles)){
 		$id_article=$row['id_article'];
@@ -222,7 +222,7 @@ function spip_ical_articles($nom_site)
 function spip_ical_breves($nom_site)
 {
 	$titres = array();
-	$result = spip_query("SELECT id_breve, titre, date_heure FROM spip_breves WHERE statut = 'prop'");
+	$result = sql_select("id_breve, titre, date_heure", "spip_breves", "statut = 'prop'");
 	while($row=sql_fetch($result)){
 		$id_breve=$row['id_breve'];
 		$titre = supprimer_numero($row['titre']);
@@ -273,7 +273,7 @@ function spip_ical_messages($id_utilisateur, $nom_site)
 				$titre = $row_forum["titre"];
 				$id_auteur = $row_forum["id_auteur"];
 
-				$result_auteurs2 = spip_query("SELECT * FROM spip_auteurs WHERE id_auteur = $id_auteur");
+				$result_auteurs2 = sql_select("*", "spip_auteurs", "id_auteur = $id_auteur");
 				if ($row_auteur2 = sql_fetch($result_auteurs2)){
 					$nom_auteur = $row_auteur2['nom'];
 					$email = $row_auteur2 ['email'];
@@ -305,7 +305,7 @@ function spip_ical_messages($id_utilisateur, $nom_site)
 // http://doc.spip.org/@spip_ical_forums
 function spip_ical_forums($id_utilisateur, $nom_site)
 {
-	$result_forum = spip_query("SELECT * FROM spip_forum WHERE statut = 'prop'");
+	$result_forum = sql_select("*", "spip_forum", "statut = 'prop'");
 
 	$nb_forum = 0;
 	while($row=sql_fetch($result_forum)){
diff --git a/ecrire/action/instituer_forum.php b/ecrire/action/instituer_forum.php
index 98e2b458a7..407c84ba59 100644
--- a/ecrire/action/instituer_forum.php
+++ b/ecrire/action/instituer_forum.php
@@ -20,7 +20,7 @@ function action_instituer_forum_dist() {
 
 	list($id_forum, $statut) = preg_split('/\W/', $arg);
 	$id_forum = intval($id_forum);
-	$result = spip_query("SELECT * FROM spip_forum WHERE id_forum=$id_forum");
+	$result = sql_select("*", "spip_forum", "id_forum=$id_forum");
 	if (!($row = sql_fetch($result)))
 		return;
 
diff --git a/ecrire/action/instituer_langue_rubrique.php b/ecrire/action/instituer_langue_rubrique.php
index d5de8795e0..701a3a2a53 100644
--- a/ecrire/action/instituer_langue_rubrique.php
+++ b/ecrire/action/instituer_langue_rubrique.php
@@ -31,7 +31,7 @@ function action_instituer_langue_rubrique_dist() {
 			if ($id_parent == 0)
 				$langue_parent = $GLOBALS['meta']['langue_site'];
 			else {
-				$row = sql_fetch(spip_query("SELECT lang FROM spip_rubriques WHERE id_rubrique=$id_parent"));
+				$row = sql_fetsel("lang", "spip_rubriques", "id_rubrique=$id_parent");
 				$langue_parent = $row['lang'];
 			}
 			spip_query("UPDATE spip_rubriques SET lang=" . _q($langue_parent) . ", langue_choisie='non' WHERE id_rubrique=$id_rubrique");
diff --git a/ecrire/action/instituer_mot.php b/ecrire/action/instituer_mot.php
index cd1dea8d3f..88e788bdbf 100644
--- a/ecrire/action/instituer_mot.php
+++ b/ecrire/action/instituer_mot.php
@@ -53,7 +53,7 @@ function action_instituer_mot_post($r)
 function ajouter_nouveau_mot($id_groupe, $table, $table_id, $id_mot, $id)
 {
 	if (un_seul_mot_dans_groupe($id_groupe)) {
-		$mots = spip_query("SELECT id_mot FROM spip_mots WHERE id_groupe = $id_groupe");
+		$mots = sql_select("id_mot", "spip_mots", "id_groupe = $id_groupe");
 		$a = array();
 		while ($r = sql_fetch($mots)) $a[]=  $r['id_mot'];
 		sql_delete("spip_mots_$table", "id_mot IN (" . join(',',$a) .") AND $table_id=$id");
diff --git a/ecrire/action/pass.php b/ecrire/action/pass.php
index d5e61f68d4..d04071ee5a 100644
--- a/ecrire/action/pass.php
+++ b/ecrire/action/pass.php
@@ -42,7 +42,7 @@ function message_oubli($email, $param)
 	if (!is_array($declaration))
 		return $declaration;
 
-	$res = spip_query("SELECT id_auteur,statut,pass FROM spip_auteurs WHERE email =" . _q($declaration['mail']));
+	$res = sql_select("id_auteur,statut,pass", "spip_auteurs", "email =" . _q($declaration['mail']));
 
 	if (!$row = sql_fetch($res)) 
 		return _T('pass_erreur_non_enregistre', array('email_oubli' => htmlspecialchars($email)));
diff --git a/ecrire/action/referencer_traduction.php b/ecrire/action/referencer_traduction.php
index de95a73600..b1fada5e37 100644
--- a/ecrire/action/referencer_traduction.php
+++ b/ecrire/action/referencer_traduction.php
@@ -29,7 +29,7 @@ function action_referencer_traduction_dist() {
 	  // supprimer le lien de traduction
 		spip_query("UPDATE spip_articles SET id_trad=0 WHERE id_article=" . $r[1]);
 		// Verifier si l'ancien groupe ne comporte plus qu'un seul article. Alors mettre a zero.
-		$cpt = sql_fetch(spip_query("SELECT COUNT(*) AS n FROM spip_articles WHERE id_trad=" . $r[2]));
+		$cpt = sql_fetsel("COUNT(*) AS n", "spip_articles", "id_trad=" . $r[2]);
 
 		if ($cpt['n'] == 1)
 			spip_query("UPDATE spip_articles SET id_trad = 0 WHERE id_trad=" . $r[2]);
@@ -55,7 +55,7 @@ function instituer_langue_article($id_article, $id_rubrique) {
 			$langues = calculer_langues_utilisees();
 			ecrire_meta('langues_utilisees', $langues);
 		} else {
-			$langue_parent = sql_fetch(spip_query("SELECT lang FROM spip_rubriques WHERE id_rubrique=" . $id_rubrique));
+			$langue_parent = sql_fetsel("lang", "spip_rubriques", "id_rubrique=" . $id_rubrique);
 			$langue_parent=$langue_parent['lang'];
 			spip_query("UPDATE spip_articles SET lang=" . _q($langue_parent) . ", langue_choisie='non' WHERE id_article=$id_article");
 		}
diff --git a/ecrire/action/reorganiser.php b/ecrire/action/reorganiser.php
index 7691c56051..24e85e95c5 100644
--- a/ecrire/action/reorganiser.php
+++ b/ecrire/action/reorganiser.php
@@ -36,7 +36,7 @@ function reorganiser_article_rubrique($id_article, $id_rubrique)
 
 		include_spip('action/editer_article');
 		include_spip('inc/rubriques');
-		$s = spip_query("SELECT statut, id_rubrique FROM spip_articles WHERE id_article=$id_article");
+		$s = sql_select("statut, id_rubrique", "spip_articles", "id_article=$id_article");
 		$s = sql_fetch($s);
 		editer_article_heritage($id_article,
 					$s['id_rubrique'], 
@@ -54,12 +54,12 @@ function reorganiser_rubrique_rubrique($id_quoi, $id_cible)
 		if (!$id_cible)
 			$id_secteur = $id_quoi;
 		else {
-			$s = spip_query("SELECT id_secteur FROM spip_rubriques WHERE id_rubrique=$id_cible");
+			$s = sql_select("id_secteur", "spip_rubriques", "id_rubrique=$id_cible");
 			$s = sql_fetch($s);
 			$id_secteur = $s['id_secteur'];
 		}
 
-		$s = spip_query("SELECT statut, id_parent FROM spip_rubriques WHERE id_rubrique=$id_quoi");
+		$s = sql_select("statut, id_parent", "spip_rubriques", "id_rubrique=$id_quoi");
 
 		spip_query("UPDATE spip_rubriques SET id_parent="._q($id_cible).", id_secteur=$id_secteur WHERE id_rubrique="._q($id_quoi));
 
diff --git a/ecrire/action/rss.php b/ecrire/action/rss.php
index 9885099774..2a07fa8b23 100644
--- a/ecrire/action/rss.php
+++ b/ecrire/action/rss.php
@@ -234,27 +234,27 @@ switch($op) {
 		include_spip('inc/forum');
 		if ($id = intval($a['id_article'])) {
 			$critere = "statut='publie' AND id_article=$id";
-			$r = sql_fetch(spip_query("SELECT titre FROM spip_articles WHERE id_article=$id"));
+			$r = sql_fetsel("titre", "spip_articles", "id_article=$id");
 			$url = generer_url_article($id);
 		}
 		else if ($id = intval($a['id_syndic'])) {
 			$critere = "statut='publie' AND id_syndic=$id";
-			$r = sql_fetch(spip_query("SELECT nom_site AS titre FROM spip_syndic WHERE id_article=$id"));
+			$r = sql_fetsel("nom_site AS titre", "spip_syndic", "id_article=$id");
 			$url = generer_url_site($id);
 		}
 		else if ($id = intval($a['id_breve'])) {
 			$critere = "statut='publie' AND id_breve=$id";
-			$r = sql_fetch(spip_query("SELECT titre FROM spip_articles WHERE id_article=$id"));
+			$r = sql_fetsel("titre", "spip_articles", "id_article=$id");
 			$url = generer_url_breve($id);
 		}
 		else if ($id = intval($a['id_rubrique'])) {
 			$critere = "statut='publie' AND id_rubrique=$id";
-			$r = sql_fetch(spip_query("SELECT titre FROM spip_articles WHERE id_article=$id"));
+			$r = sql_fetsel("titre", "spip_articles", "id_article=$id");
 			$url = generer_url_rubrique($id);
 		}
 		else if ($id = intval($a['id_thread'])) {
 			$critere = "statut='publie' AND id_thread=$id";
-			$r = sql_fetch(spip_query("SELECT titre FROM spip_articles WHERE id_article=$id"));
+			$r = sql_fetsel("titre", "spip_articles", "id_article=$id");
 			$url = generer_url_forum($id);
 		}
 		if ($id) $rss = rss_suivi_forums($a, "spip_forum", $critere, false);
diff --git a/ecrire/action/supprimer.php b/ecrire/action/supprimer.php
index 6920fe1943..da853a2a2a 100644
--- a/ecrire/action/supprimer.php
+++ b/ecrire/action/supprimer.php
@@ -53,7 +53,7 @@ function action_supprimer_rubrique($r)
 	// deviennent redacteurs
 	// (il y a sans doute moyen de faire ca avec un having)
 
-	$q = spip_query("SELECT id_auteur FROM spip_auteurs_rubriques WHERE id_rubrique=$id_rubrique");
+	$q = sql_select("id_auteur", "spip_auteurs_rubriques", "id_rubrique=$id_rubrique");
 
 	while ($r = sql_fetch($q)) {
 		$id_auteur = $r['id_auteur'];
@@ -76,7 +76,7 @@ function action_supprimer_rubrique($r)
 // http://doc.spip.org/@supprimer_document_et_vignette
 function supprimer_document_et_vignette($arg)
 {
-	$result = spip_query("SELECT id_vignette, fichier FROM spip_documents WHERE id_document=$arg");
+	$result = sql_select("id_vignette, fichier", "spip_documents", "id_document=$arg");
 	if ($row = sql_fetch($result)) {
 		spip_unlink(get_spip_doc($row['fichier']));
 		sql_delete("spip_documents", "id_document=$arg");
@@ -86,7 +86,7 @@ function supprimer_document_et_vignette($arg)
 		sql_delete("spip_documents_breves", "id_document=$arg");
 		$id_vignette = $row['id_vignette'];
 		if ($id_vignette > 0) {
-			$result = spip_query("SELECT fichier FROM spip_documents	WHERE id_document=$id_vignette");
+			$result = sql_select("fichier", "spip_documents	", "id_document=$id_vignette");
 
 			if ($row = sql_fetch($result)) {
 				spip_unlink(get_spip_doc($row['fichier']));
diff --git a/ecrire/action/supprimer_traduction.php b/ecrire/action/supprimer_traduction.php
index 4cdaaeccc1..1249a6b7e8 100644
--- a/ecrire/action/supprimer_traduction.php
+++ b/ecrire/action/supprimer_traduction.php
@@ -30,7 +30,7 @@ function action_supprimer_traduction_post($r)
 	// Si l'ancien groupe ne comporte plus qu'un seul article
 	// mettre a zero.
 
-	$cpt = sql_fetch(spip_query("SELECT COUNT(*) AS n FROM spip_articles WHERE id_trad=" . $r[2]));
+	$cpt = sql_fetsel("COUNT(*) AS n", "spip_articles", "id_trad=" . $r[2]);
 
 	if ($cpt['n'] == 1)
 		spip_query("UPDATE spip_articles SET id_trad = 0 WHERE id_trad=" . $r[2]);
diff --git a/ecrire/action/tester_taille.php b/ecrire/action/tester_taille.php
index 1e1cb1399e..44353d151f 100644
--- a/ecrire/action/tester_taille.php
+++ b/ecrire/action/tester_taille.php
@@ -49,7 +49,7 @@ function action_tester_taille_dist() {
 			$dummy = propre("<doc1>");
 
 			$image_source = _DIR_IMG_PACK."test.png";
-			$res = spip_query("SELECT valeur FROM spip_meta WHERE nom='max_taille_vignettes_test'");
+			$res = sql_select("valeur", "spip_meta", "nom='max_taille_vignettes_test'");
 			if ($row = sql_fetch($res))
 				$max_size_test = $row['valeur'];
 			if (!$max_size_test OR $max_size_test>$s)
diff --git a/ecrire/action/tourner.php b/ecrire/action/tourner.php
index 270d6e22ac..75ae4e90c5 100644
--- a/ecrire/action/tourner.php
+++ b/ecrire/action/tourner.php
@@ -28,7 +28,7 @@ function action_tourner_dist() {
 function action_tourner_post($r)
 {
 	$arg = $r[1];
-	$result = spip_query("SELECT fichier FROM spip_documents WHERE id_document=$arg");
+	$result = sql_select("fichier", "spip_documents", "id_document=$arg");
 
 	if (!$row = sql_fetch($result))
 		return;
diff --git a/ecrire/balise/formulaire_inscription.php b/ecrire/balise/formulaire_inscription.php
index 2fa4eb38b9..1b106a0b7a 100644
--- a/ecrire/balise/formulaire_inscription.php
+++ b/ecrire/balise/formulaire_inscription.php
@@ -112,7 +112,7 @@ function message_inscription($mail, $nom, $mode, $id=0) {
 	if (is_string($declaration))
 		return  $declaration;
 
-	$row = spip_query("SELECT statut, id_auteur, login, email FROM spip_auteurs WHERE email=" . _q($declaration['email']));
+	$row = sql_select("statut, id_auteur, login, email", "spip_auteurs", "email=" . _q($declaration['email']));
 	$row = sql_fetch($row);
 
 	if (!$row) 
diff --git a/ecrire/exec/articles.php b/ecrire/exec/articles.php
index 7d79100642..2f1219b9d8 100644
--- a/ecrire/exec/articles.php
+++ b/ecrire/exec/articles.php
@@ -22,7 +22,7 @@ function exec_articles_dist()
 
 	pipeline('exec_init',array('args'=>array('exec'=>'articles','id_article'=>$id_article),'data'=>''));
 
-	$row = sql_fetch(spip_query("SELECT * FROM spip_articles WHERE id_article=$id_article"));
+	$row = sql_fetsel("*", "spip_articles", "id_article=$id_article");
 
 	if (!$row
 	OR !autoriser('voir', 'article', $id_article)) {
diff --git a/ecrire/exec/articles_forum.php b/ecrire/exec/articles_forum.php
index e727db1932..f5d5f46f9a 100644
--- a/ecrire/exec/articles_forum.php
+++ b/ecrire/exec/articles_forum.php
@@ -29,7 +29,7 @@ function exec_articles_forum_dist()
 	if (!$pack) $pack = 5; // nb de forums affiches par page
 	if (!$enplus) $enplus = 200;	// intervalle affiche autour du debut
 
-	$result = spip_query("SELECT titre, id_rubrique FROM spip_articles WHERE id_article=$id_article");
+	$result = sql_select("titre, id_rubrique", "spip_articles", "id_article=$id_article");
 
 	if ($row = sql_fetch($result)) {
 		$titre = $row["titre"];
diff --git a/ecrire/exec/articles_versions.php b/ecrire/exec/articles_versions.php
index 25fe38d45f..33ac47ea78 100644
--- a/ecrire/exec/articles_versions.php
+++ b/ecrire/exec/articles_versions.php
@@ -31,7 +31,7 @@ function exec_articles_versions_dist()
 // Lire l'article
 //
 
-	$row = sql_fetch(spip_query("SELECT * FROM spip_articles WHERE id_article=$id_article"));
+	$row = sql_fetsel("*", "spip_articles", "id_article=$id_article");
 
 	if (!autoriser('voirrevisions', 'article', $id_article) 
 		OR !$row) {
diff --git a/ecrire/exec/auteur_infos.php b/ecrire/exec/auteur_infos.php
index 47867cb4bc..5837176cce 100644
--- a/ecrire/exec/auteur_infos.php
+++ b/ecrire/exec/auteur_infos.php
@@ -33,7 +33,7 @@ function exec_auteur_infos_dist() {
 	);
 
 	if ($id_auteur) {
-		$s = spip_query("SELECT * FROM spip_auteurs WHERE id_auteur=$id_auteur");
+		$s = sql_select("*", "spip_auteurs", "id_auteur=$id_auteur");
 		$auteur = sql_fetch($s);
 	} else {
 		$auteur = array();
diff --git a/ecrire/exec/breves_edit.php b/ecrire/exec/breves_edit.php
index 865016af88..8ee1547bb9 100644
--- a/ecrire/exec/breves_edit.php
+++ b/ecrire/exec/breves_edit.php
@@ -35,7 +35,7 @@ function exec_breves_edit_dist()
 		$id_rubrique = $row_rub['id_rubrique'];
 		if (!autoriser('creerbrevedans','rubrique',$id_rubrique )){
 			// manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises
-			$res = spip_query("SELECT id_rubrique FROM spip_rubriques WHERE id_parent=0");
+			$res = sql_select("id_rubrique", "spip_rubriques", "id_parent=0");
 			while (!autoriser('creerbrevedans','rubrique',$id_rubrique ) && $row_rub = sql_fetch($res)){
 				$id_rubrique = $row_rub['id_rubrique'];
 			}
@@ -52,7 +52,7 @@ function exec_breves_edit_dist()
 	}
 
 	if ($new != "oui") {
-		$result = spip_query("SELECT * FROM spip_breves WHERE id_breve=$id_breve");
+		$result = sql_select("*", "spip_breves", "id_breve=$id_breve");
 
 	
 		if ($row=sql_fetch($result)) {
@@ -78,7 +78,7 @@ function exec_breves_edit_dist()
 		$lien_titre='';
 		$lien_url='';
 		$statut = "prop";
-		$row = sql_fetch(spip_query("SELECT id_secteur FROM spip_rubriques WHERE id_rubrique=$id_rubrique"));
+		$row = sql_fetsel("id_secteur", "spip_rubriques", "id_rubrique=$id_rubrique");
 		$id_rubrique = $row['id_secteur'];
 	}
 
@@ -121,7 +121,7 @@ if ($connect_statut=="0minirezo" OR $statut=="prop" OR $new == "oui") {
 
 	if ($id_rubrique == 0) $logo_parent = "racine-site-24.gif";
 	else {
-		$result=spip_query("SELECT id_parent FROM spip_rubriques WHERE id_rubrique=$id_rubrique");
+		$result=sql_select("id_parent", "spip_rubriques", "id_rubrique=$id_rubrique");
 
 		while($row=sql_fetch($result)){
 			$parent_parent=$row['id_parent'];
diff --git a/ecrire/exec/breves_voir.php b/ecrire/exec/breves_voir.php
index fe44d02ef2..4544112d17 100644
--- a/ecrire/exec/breves_voir.php
+++ b/ecrire/exec/breves_voir.php
@@ -21,7 +21,7 @@ include_spip("inc/indexation");
 function afficher_breves_voir($id_breve, $cherche_mot, $select_groupe)
 {
 	global $champs_extra, $les_notes, $spip_display, $spip_lang_left, $spip_lang_right;
-	$result = spip_query("SELECT * FROM spip_breves WHERE id_breve=$id_breve");
+	$result = sql_select("*", "spip_breves", "id_breve=$id_breve");
 
 	if ($row = sql_fetch($result)) {
 		$id_breve=$row['id_breve'];
@@ -199,7 +199,7 @@ function langue_breve($id_breve, $row){
 	//
 	// Langue de la breve
 	//
-	$row2 = sql_fetch(spip_query("SELECT lang FROM spip_rubriques WHERE id_rubrique=$id_rubrique"));
+	$row2 = sql_fetsel("lang", "spip_rubriques", "id_rubrique=$id_rubrique");
 	$langue_parent = $row2['lang'];
 	
 	$langue_breve = $row['lang'];
@@ -258,4 +258,4 @@ function afficher_breve_rubrique($id_breve, $id_rubrique, $statut)
 		. fin_cadre_couleur(true);
 
 }
-?>
\ No newline at end of file
+?>
diff --git a/ecrire/exec/brouteur.php b/ecrire/exec/brouteur.php
index 778a00ee9d..a9bb4cb908 100644
--- a/ecrire/exec/brouteur.php
+++ b/ecrire/exec/brouteur.php
@@ -43,7 +43,7 @@ function exec_brouteur_dist()
 	if ($id_rubrique) {
 		$j = $nb_col;
 		while ($id_rubrique > 0) {
-			$result=spip_query("SELECT id_parent FROM spip_rubriques WHERE id_rubrique=$id_rubrique");
+			$result=sql_select("id_parent", "spip_rubriques", "id_rubrique=$id_rubrique");
 			if ($row=sql_fetch($result)){
 				$j--;
 				$dest[$j] = $id_rubrique;
@@ -62,7 +62,7 @@ function exec_brouteur_dist()
 			
 			$la_rubrique = $dest[0];
 			
-			$result = spip_query("SELECT id_parent FROM spip_rubriques WHERE id_rubrique ='$la_rubrique'");
+			$result = sql_select("id_parent", "spip_rubriques", "id_rubrique ='$la_rubrique'");
 			if ($row = sql_fetch($result)) {
 				$la_rubrique =$row['id_parent'];
 			}
@@ -70,7 +70,7 @@ function exec_brouteur_dist()
 			$compteur = 0;
 			$ret = '';
 			while ($la_rubrique > 0) {
-				$result = spip_query("SELECT titre, id_parent FROM spip_rubriques WHERE id_rubrique ='$la_rubrique'");
+				$result = sql_select("titre, id_parent", "spip_rubriques", "id_rubrique ='$la_rubrique'");
 				if ($row = sql_fetch($result)) {
 					$compteur++;
 					$titre = typo($row['titre']);
diff --git a/ecrire/exec/controle_forum.php b/ecrire/exec/controle_forum.php
index a99e4634b3..927962ab17 100644
--- a/ecrire/exec/controle_forum.php
+++ b/ecrire/exec/controle_forum.php
@@ -30,7 +30,7 @@ function forum_parent($id_forum) {
 	$forum_stat=$row['statut'];
 
 	if ($forum_id_article > 0) {
-	  $row=sql_fetch(spip_query("SELECT id_article, titre, statut FROM spip_articles WHERE id_article=$forum_id_article"));
+	  $row=sql_fetsel("id_article, titre, statut", "spip_articles", "id_article=$forum_id_article");
 	  $id_article = $row['id_article'];
 	  $titre = $row['titre'];
 	  $statut = $row['statut'];
@@ -50,7 +50,7 @@ function forum_parent($id_forum) {
 	  }
 	}
 	else if ($forum_id_rubrique > 0) {
-	  $row = sql_fetch(spip_query("SELECT * FROM spip_rubriques WHERE id_rubrique=$forum_id_rubrique"));
+	  $row = sql_fetsel("*", "spip_rubriques", "id_rubrique=$forum_id_rubrique");
 	  $id_rubrique = $row['id_rubrique'];
 	  $titre = $row['titre'];
 	  return array('pref' => _T('lien_reponse_rubrique'),
@@ -60,7 +60,7 @@ function forum_parent($id_forum) {
 		       'titre' => $titre);
 	}
 	else if ($forum_id_syndic > 0) {
-	  $row = sql_fetch(spip_query("SELECT * FROM spip_syndic WHERE id_syndic=$forum_id_syndic"));
+	  $row = sql_fetsel("*", "spip_syndic", "id_syndic=$forum_id_syndic");
 	  $id_syndic = $row['id_syndic'];
 	  $titre = $row['nom_site'];
 	  $statut = $row['statut'];
@@ -71,7 +71,7 @@ function forum_parent($id_forum) {
 		       'titre' => $titre);
 	}
 	else if ($forum_id_breve > 0) {
-	  $row = sql_fetch(spip_query("SELECT * FROM spip_breves WHERE id_breve=$forum_id_breve"));
+	  $row = sql_fetsel("*", "spip_breves", "id_breve=$forum_id_breve");
 	  $id_breve = $row['id_breve'];
 	  $date_heure = $row['date_heure'];
 	  $titre = $row['titre'];
diff --git a/ecrire/exec/controle_petition.php b/ecrire/exec/controle_petition.php
index 1c3b9a38e9..cf96f3fe4a 100644
--- a/ecrire/exec/controle_petition.php
+++ b/ecrire/exec/controle_petition.php
@@ -21,7 +21,7 @@ function exec_controle_petition_dist()
 	$titre =' ';
 	$statut='new';
 	if ($id_article) {
-		if ($row = sql_fetch(spip_query("SELECT titre,statut FROM spip_articles WHERE id_article=$id_article")));
+		if ($row = sql_fetsel("titre,statut", "spip_articles", "id_article=$id_article"));
 		if (!$row)
 			$id_article = 0;
 		else {
diff --git a/ecrire/exec/dater.php b/ecrire/exec/dater.php
index e3b3cc6933..232c04f835 100644
--- a/ecrire/exec/dater.php
+++ b/ecrire/exec/dater.php
@@ -27,7 +27,7 @@ function exec_dater_dist()
 	}
 
 	$table = ($type=='syndic') ? 'syndic' : ($type . 's');
-	$row = sql_fetch(spip_query("SELECT * FROM spip_$table WHERE id_$type=$id"));
+	$row = sql_fetsel("*", "spip_$table", "id_$type=$id");
 
 	$statut = $row['statut'];
 	$date = $row[($type!='breve')?"date":"date_heure"];
diff --git a/ecrire/exec/editer_mot.php b/ecrire/exec/editer_mot.php
index 9317711070..6357ba62dc 100644
--- a/ecrire/exec/editer_mot.php
+++ b/ecrire/exec/editer_mot.php
@@ -27,9 +27,9 @@ function exec_editer_mot_dist()
 		$droit = autoriser('publierdans','rubrique',$id_objet);
 	else {
 		if ($objet == 'breve')
-			$droit = spip_query("SELECT id_rubrique FROM spip_breves WHERE id_breve="._q($id_objet));
+			$droit = sql_select("id_rubrique", "spip_breves", "id_breve="._q($id_objet));
 		else
-			$droit = spip_query("SELECT id_rubrique FROM spip_syndic WHERE id_syndic="._q($id_objet));
+			$droit = sql_select("id_rubrique", "spip_syndic", "id_syndic="._q($id_objet));
 		$droit = autoriser('publierdans','rubrique',$droit['id_rubrique']);
 	}
 
diff --git a/ecrire/exec/export_all.php b/ecrire/exec/export_all.php
index e590347e63..598f7ae7ea 100644
--- a/ecrire/exec/export_all.php
+++ b/ecrire/exec/export_all.php
@@ -136,7 +136,7 @@ function complete_secteurs($les_rubriques)
 	$res = array();
 	foreach($les_rubriques as $r) {
 		do {
-			$r = spip_query("SELECT id_parent FROM spip_rubriques WHERE id_rubrique=$r");
+			$r = sql_select("id_parent", "spip_rubriques", "id_rubrique=$r");
 			$r = sql_fetch($r);
 			if ($r AND $r = $r['id_parent']) {
 				if ((isset($les_rubriques[$r])) OR isset($res[$r]))
diff --git a/ecrire/exec/forum_envoi.php b/ecrire/exec/forum_envoi.php
index 177bedde47..b1bafeaa48 100644
--- a/ecrire/exec/forum_envoi.php
+++ b/ecrire/exec/forum_envoi.php
@@ -59,7 +59,7 @@ function forum_envoi(
 
 	if (!$titre_message) {
 		if ($table) {
-			$q = spip_query("SELECT $titre AS titre FROM spip_$table WHERE $objet=$id");
+			$q = sql_select("$titre AS titre", "spip_$table", "$objet=$id");
 			$q = sql_fetch($q);
 			$titre_message = $q['titre'];
 		} else 	$titre_message = _T('texte_nouveau_message');
@@ -77,7 +77,7 @@ function forum_envoi(
 // http://doc.spip.org/@forum_envoi_parent
 function forum_envoi_parent($id)
 {
-	$r = spip_query("SELECT * FROM spip_forum WHERE id_forum=" . _q($id));
+	$r = sql_select("*", "spip_forum", "id_forum=" . _q($id));
 	if (!$row = sql_fetch($r))
 		return array('titre' =>'', 'texte' =>'', 'id_message' =>'');
 
diff --git a/ecrire/exec/grouper_mots.php b/ecrire/exec/grouper_mots.php
index 160e575986..f29fe95cd7 100644
--- a/ecrire/exec/grouper_mots.php
+++ b/ecrire/exec/grouper_mots.php
@@ -18,7 +18,7 @@ include_spip('inc/actions');
 function exec_grouper_mots_dist()
 {
 	$id_groupe = intval(_request('id_groupe'));
-	$cpt = sql_fetch(spip_query("SELECT COUNT(*) AS n FROM spip_mots WHERE id_groupe=$id_groupe"));
+	$cpt = sql_fetsel("COUNT(*) AS n", "spip_mots", "id_groupe=$id_groupe");
 	if (! ($cpt = $cpt['n'])) ajax_retour('') ;
 	$grouper_mots = charger_fonction('grouper_mots', 'inc');
 	ajax_retour($grouper_mots($id_groupe, $cpt));
diff --git a/ecrire/exec/iconifier.php b/ecrire/exec/iconifier.php
index 27bb727050..df49cbf2a9 100644
--- a/ecrire/exec/iconifier.php
+++ b/ecrire/exec/iconifier.php
@@ -39,7 +39,7 @@ function exec_iconifier_dist()
 	  $droit = $connect_toutes_rubriques;
 	else {
 		$table=substr($type, 3) . (($type == 'id_syndic') ? '' : 's');
-		$row = sql_fetch(spip_query("SELECT id_rubrique, statut FROM spip_$table WHERE $type=$id"));
+		$row = sql_fetsel("id_rubrique, statut", "spip_$table", "$type=$id");
 		$droit = autoriser('publierdans','rubrique',$row['id_rubrique']);
 		if (!$droit AND  ($row['statut'] == 'prepa' OR $row['statut'] == 'prop' OR $row['statut'] == 'poubelle'))
 			$droit = sql_count(determiner_auteurs_objet('article',$id, "id_auteur=$connect_id_auteur"));
diff --git a/ecrire/exec/instituer_auteur.php b/ecrire/exec/instituer_auteur.php
index 301056ff70..3d6bec0b69 100644
--- a/ecrire/exec/instituer_auteur.php
+++ b/ecrire/exec/instituer_auteur.php
@@ -18,7 +18,7 @@ function exec_instituer_auteur_dist()
 	$id_auteur = intval(_request('id_auteur'));
 
 	include_spip('inc/actions');
-	$auteur = sql_fetch(spip_query("SELECT * FROM spip_auteurs WHERE id_auteur=$id_auteur"));
+	$auteur = sql_fetsel("*", "spip_auteurs", "id_auteur=$id_auteur");
 
 	$instituer_auteur = charger_fonction('instituer_auteur', 'inc');
 	ajax_retour($instituer_auteur($auteur));
diff --git a/ecrire/exec/message.php b/ecrire/exec/message.php
index ef08e26bdb..06fa732f2e 100644
--- a/ecrire/exec/message.php
+++ b/ecrire/exec/message.php
@@ -25,7 +25,7 @@ function exec_message_dist()
 	$forcer_dest = _request('forcer_dest');
 	$cherche_auteur = _request('cherche_auteur');
 
-	$row = sql_fetch(spip_query("SELECT type FROM spip_messages WHERE id_message=$id_message"));
+	$row = sql_fetsel("type", "spip_messages", "id_message=$id_message");
 
 	if ($row['type'] != "affich"){
 		$res = sql_fetch(spip_query("SELECT vu FROM spip_auteurs_messages WHERE id_auteur=$connect_id_auteur AND id_message=$id_message"));
@@ -77,7 +77,7 @@ function http_auteurs_ressemblants($cherche_auteur, $id_message)
   else if (count($resultat) == 1) {
     // action/editer_message a du prendre en compte ce cas
     list(, $nouv_auteur) = each($resultat);
-    $row = sql_fetch(spip_query("SELECT nom FROM spip_auteurs WHERE id_auteur=$nouv_auteur"));
+    $row = sql_fetsel("nom", "spip_auteurs", "id_auteur=$nouv_auteur");
     $nom_auteur = $row['nom'];
     return "<b>"._T('info_ajout_participant')."</b><br />" .
       "<ul><li><span class='verdana1 spip_small'><b><span class='spip_medium'>$nom_auteur</span></b></span></li>\n</ul>";
@@ -319,7 +319,7 @@ function http_affiche_message($id_message, $expediteur, $statut, $type, $texte,
 function exec_affiche_message_dist($id_message, $cherche_auteur, $forcer_dest)
 {
   global $echelle, $partie_cal;
-  $row = sql_fetch(spip_query("SELECT * FROM spip_messages WHERE id_message=$id_message"));
+  $row = sql_fetsel("*", "spip_messages", "id_message=$id_message");
   if ($row) {
 	$id_message = $row['id_message'];
 	$date_heure = $row["date_heure"];
diff --git a/ecrire/exec/message_edit.php b/ecrire/exec/message_edit.php
index 214ffa6f14..303185c200 100644
--- a/ecrire/exec/message_edit.php
+++ b/ecrire/exec/message_edit.php
@@ -28,7 +28,7 @@ function exec_message_edit_dist()
 		$onfocus = "\nonfocus=\"if(!antifocus){this.value='';antifocus=true;}\"";
 	} else $onfocus = '';
 
-	$row = sql_fetch(spip_query("SELECT * FROM spip_messages WHERE id_message=$id_message"));
+	$row = sql_fetsel("*", "spip_messages", "id_message=$id_message");
 
 	$id_message = $row['id_message'];
 	$date_heure = $row["date_heure"];
@@ -66,7 +66,7 @@ function exec_message_edit_dist()
 	echo debut_gauche('', true);
 	
 	if($type == 'normal' AND $dest) {
-		$nom = sql_fetch(spip_query("SELECT nom, email FROM spip_auteurs WHERE id_auteur=$dest"));
+		$nom = sql_fetsel("nom, email", "spip_auteurs", "id_auteur=$dest");
 		if (strlen($nom['email']) > 3) {
 			echo icone(_T('info_envoyer_message_prive'), "mailto:".$nom['email'], "envoi-message-24.gif");
 		}
@@ -88,7 +88,7 @@ function exec_message_edit_dist()
 		  $res .="<input type='text' class='formo' name='cherche_auteur' id='cherche_auteur' value='' size='40'/>";
 		}
 	} else {
-		$nom = sql_fetch(spip_query("SELECT nom FROM spip_auteurs WHERE id_auteur=$dest"));
+		$nom = sql_fetsel("nom", "spip_auteurs", "id_auteur=$dest");
 		$res .="<br /><b>" .
 		  _T('info_nom_destinataire') .
 		  "</b>&nbsp;:&nbsp;&nbsp; " .
diff --git a/ecrire/exec/mots_edit.php b/ecrire/exec/mots_edit.php
index 7c53aecd6b..19356ea3a0 100644
--- a/ecrire/exec/mots_edit.php
+++ b/ecrire/exec/mots_edit.php
@@ -35,7 +35,7 @@ global  $champs_extra, $connect_statut, $spip_display, $les_notes;
 //
 // Recupere les donnees
 //
-	$row = sql_fetch(spip_query("SELECT * FROM spip_mots WHERE id_mot=$id_mot"));
+	$row = sql_fetsel("*", "spip_mots", "id_mot=$id_mot");
 	 if ($row) {
 		$id_mot = $row['id_mot'];
 		$titre_mot = $row['titre'];
diff --git a/ecrire/exec/mots_tous.php b/ecrire/exec/mots_tous.php
index b06e6e9fd5..4a2bd97c69 100644
--- a/ecrire/exec/mots_tous.php
+++ b/ecrire/exec/mots_tous.php
@@ -102,7 +102,7 @@ function exec_mots_tous_dist()
 		// Afficher les mots-cles du groupe
 		//
 
-		$groupe = sql_fetch(spip_query("SELECT COUNT(*) AS n FROM spip_mots WHERE id_groupe=$id_groupe"));
+		$groupe = sql_fetsel("COUNT(*) AS n", "spip_mots", "id_groupe=$id_groupe");
 		$groupe = $groupe['n'];
 
 		echo "<div\nid='editer_mot-$id_groupe' style='position: relative;'>";
@@ -148,7 +148,7 @@ function exec_mots_tous_dist()
 // http://doc.spip.org/@confirmer_mot
 function confirmer_mot ($conf_mot, $son_groupe, $total)
 {
-	$row = sql_fetch(spip_query("SELECT * FROM spip_mots WHERE id_mot=$conf_mot"));
+	$row = sql_fetsel("*", "spip_mots", "id_mot=$conf_mot");
 	if (!$row) return ""; // deja detruit (acces concurrent etc)
 
 	$id_mot = $row['id_mot'];
diff --git a/ecrire/exec/mots_type.php b/ecrire/exec/mots_type.php
index b52becbbda..399bada706 100644
--- a/ecrire/exec/mots_type.php
+++ b/ecrire/exec/mots_type.php
@@ -36,7 +36,7 @@ function exec_mots_type_dist()
 	  $row = array();
 	} else {
 
-		$result_groupes = spip_query("SELECT * FROM spip_groupes_mots WHERE id_groupe=$id_groupe");
+		$result_groupes = sql_select("*", "spip_groupes_mots", "id_groupe=$id_groupe");
 
 		if ($row = sql_fetch($result_groupes)) {
 			$id_groupe = $row['id_groupe'];
diff --git a/ecrire/exec/naviguer.php b/ecrire/exec/naviguer.php
index d858d9e91f..67135a8451 100644
--- a/ecrire/exec/naviguer.php
+++ b/ecrire/exec/naviguer.php
@@ -223,12 +223,12 @@ function langue_naviguer($id_rubrique, $id_parent, $flag_editable)
 	$res = "";
 	if ($id_rubrique>0 AND $GLOBALS['meta']['multi_rubriques'] == 'oui' AND ($GLOBALS['meta']['multi_secteurs'] == 'non' OR $id_parent == 0) AND $flag_editable) {
 
-		$row = sql_fetch(spip_query("SELECT lang, langue_choisie FROM spip_rubriques WHERE id_rubrique=$id_rubrique"));
+		$row = sql_fetsel("lang, langue_choisie", "spip_rubriques", "id_rubrique=$id_rubrique");
 		$langue_rubrique = $row['lang'];
 		$langue_choisie_rubrique = $row['langue_choisie'];
 		$langue_parent = '';
 		if ($id_parent) {
-			$row = sql_fetch(spip_query("SELECT lang FROM spip_rubriques WHERE id_rubrique=$id_parent"));
+			$row = sql_fetsel("lang", "spip_rubriques", "id_rubrique=$id_parent");
 			$langue_parent = $row['lang'];
 		} 
 		if (!$langue_parent)
@@ -315,7 +315,7 @@ function contenu_naviguer($id_rubrique, $id_parent) {
 		if ($id_rubrique == 0 
 		AND autoriser('publierdans','rubrique',$id_rubrique)) {
 	
-			$cpt = sql_fetch(spip_query("SELECT COUNT(*) AS n FROM spip_syndic_articles WHERE statut='dispo'"));
+			$cpt = sql_fetsel("COUNT(*) AS n", "spip_syndic_articles", "statut='dispo'");
 			if ($cpt = $cpt['n'])
 				$res .= "<br /><small><a href='" .
 					generer_url_ecrire("sites_tous") .
diff --git a/ecrire/exec/puce_statut.php b/ecrire/exec/puce_statut.php
index 2b27d9fbbb..98ac5c144d 100644
--- a/ecrire/exec/puce_statut.php
+++ b/ecrire/exec/puce_statut.php
@@ -21,7 +21,7 @@ function exec_puce_statut_dist()
 	$type = _request('type');
 
 	if ($type == 'article') {
-		$s = spip_query("SELECT id_rubrique,statut FROM spip_articles WHERE id_article=$id");
+		$s = sql_select("id_rubrique,statut", "spip_articles", "id_article=$id");
 		$r = sql_fetch($s);
 		$statut = $r['statut'];
 		$id_rubrique = $r['id_rubrique'];
diff --git a/ecrire/exec/rechercher.php b/ecrire/exec/rechercher.php
index 6a7661c44c..3bfed970bf 100644
--- a/ecrire/exec/rechercher.php
+++ b/ecrire/exec/rechercher.php
@@ -45,7 +45,7 @@ function exec_rechercher_dist()
 	} else
 		$where_exclus = '';
 
-	$res = spip_query("SELECT id_rubrique, id_parent, titre FROM spip_rubriques WHERE $where_id$where_exclus");
+	$res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_id$where_exclus");
 
 	$points = $rub = array();
 
@@ -55,7 +55,7 @@ function exec_rechercher_dist()
 		$rub[$id_rubrique]["id_parent"] = $row["id_parent"];
 		$points[$id_rubrique] = $points[$id_rubrique] + 3;
 	}
-	$res = spip_query("SELECT id_rubrique, id_parent, titre FROM spip_rubriques WHERE $where_titre$where_exclus");
+	$res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_titre$where_exclus");
 	while ($row = sql_fetch($res)) {
 		$id_rubrique = $row["id_rubrique"];
 		$rub[$id_rubrique]["titre"] = typo ($row["titre"]);
@@ -64,7 +64,7 @@ function exec_rechercher_dist()
 		  $points[$id_rubrique] += 2;
 		else $points[$id_rubrique] = 0;
 	}
-	$res = spip_query("SELECT id_rubrique, id_parent, titre FROM spip_rubriques WHERE $where_desc$where_exclus");
+	$res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_desc$where_exclus");
 	while ($row = sql_fetch($res)) {
 		$id_rubrique = $row["id_rubrique"];
 		$rub[$id_rubrique]["titre"] = typo ($row["titre"]);
diff --git a/ecrire/exec/referencer_traduction.php b/ecrire/exec/referencer_traduction.php
index 7224b390c7..7464fa3a21 100644
--- a/ecrire/exec/referencer_traduction.php
+++ b/ecrire/exec/referencer_traduction.php
@@ -23,7 +23,7 @@ function exec_referencer_traduction_dist()
 		exit;
 	}
 	include_spip('inc/actions');
-	$row = sql_fetch(spip_query("SELECT id_trad, id_rubrique FROM spip_articles WHERE id_article=$id_article"));
+	$row = sql_fetsel("id_trad, id_rubrique", "spip_articles", "id_article=$id_article");
 
 	$referencer_traduction = charger_fonction('referencer_traduction', 'inc');
 	ajax_retour($referencer_traduction($id_article, 'ajax', $row['id_rubrique'], $row['id_trad'])); 
diff --git a/ecrire/exec/rubriques_edit.php b/ecrire/exec/rubriques_edit.php
index 784a4c36e3..dd6a5e0ccd 100644
--- a/ecrire/exec/rubriques_edit.php
+++ b/ecrire/exec/rubriques_edit.php
@@ -36,7 +36,7 @@ function exec_rubriques_edit_dist()
 	} else {
 		$id_rubrique = intval(_request('id_rubrique'));
 
-		$row = sql_fetch(spip_query("SELECT * FROM spip_rubriques WHERE id_rubrique=$id_rubrique"));
+		$row = sql_fetsel("*", "spip_rubriques", "id_rubrique=$id_rubrique");
 	
 		if (!$row) exit;
 	
@@ -67,7 +67,7 @@ function exec_rubriques_edit_dist()
 
 	if ($id_parent == 0) $logo_parent = "racine-site-24.gif";
 	else {
-		$id_secteur = sql_fetch(spip_query("SELECT id_secteur FROM spip_rubriques WHERE id_rubrique=$id_parent"));
+		$id_secteur = sql_fetsel("id_secteur", "spip_rubriques", "id_rubrique=$id_parent");
 		$id_secteur = $id_secteur['id_secteur'];
 		if ($id_parent == $id_secteur)
 			$logo_parent = "secteur-24.gif";
diff --git a/ecrire/exec/sites.php b/ecrire/exec/sites.php
index cdd3ec5ffb..24aeb64982 100644
--- a/ecrire/exec/sites.php
+++ b/ecrire/exec/sites.php
@@ -26,7 +26,7 @@ function exec_sites_dist()
 		exit;
 	}
 
-	$result = spip_query("SELECT * FROM spip_syndic WHERE id_syndic=$id_syndic");
+	$result = sql_select("*", "spip_syndic", "id_syndic=$id_syndic");
 
 	if ($row = sql_fetch($result)) {
 		$id_rubrique = $row["id_rubrique"];
diff --git a/ecrire/exec/sites_edit.php b/ecrire/exec/sites_edit.php
index 0d2e9d3cb3..1f439aa02a 100644
--- a/ecrire/exec/sites_edit.php
+++ b/ecrire/exec/sites_edit.php
@@ -19,7 +19,7 @@ function exec_sites_edit_dist()
 	global $connect_statut, $connect_id_rubrique, $spip_lang_right;
 
 	$id_syndic = intval(_request('id_syndic'));
-	$result = spip_query("SELECT * FROM spip_syndic WHERE id_syndic=$id_syndic");
+	$result = sql_select("*", "spip_syndic", "id_syndic=$id_syndic");
 
 	if ($row = sql_fetch($result)) {
 		$id_syndic = $row["id_syndic"];
@@ -44,7 +44,7 @@ function exec_sites_edit_dist()
 		}
 		if (!autoriser('creersitedans','rubrique',$id_rubrique )){
 			// manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises
-			$res = spip_query("SELECT id_rubrique FROM spip_rubriques WHERE id_parent=0");
+			$res = sql_select("id_rubrique", "spip_rubriques", "id_parent=0");
 			while (!autoriser('creersitedans','rubrique',$id_rubrique ) && $row_rub = sql_fetch($res)){
 				$id_rubrique = $row_rub['id_rubrique'];
 			}
diff --git a/ecrire/exec/statistiques_repartition.php b/ecrire/exec/statistiques_repartition.php
index 0a7d9a86e5..44b35649c5 100644
--- a/ecrire/exec/statistiques_repartition.php
+++ b/ecrire/exec/statistiques_repartition.php
@@ -20,14 +20,14 @@ function enfants($id_parent, $critere){
 
 	global $nombre_abs;
 
-	$result = spip_query("SELECT id_rubrique FROM spip_rubriques WHERE id_parent=$id_parent");
+	$result = sql_select("id_rubrique", "spip_rubriques", "id_parent=$id_parent");
 
 	$nombre = 0;
 
 	while($row = sql_fetch($result)) {
 		$id_rubrique = $row['id_rubrique'];
 
-		$result2 = spip_query("SELECT SUM(".$critere.") AS cnt FROM spip_articles WHERE id_rubrique=$id_rubrique");
+		$result2 = sql_select("SUM(".$critere.") AS cnt", "spip_articles", "id_rubrique=$id_rubrique");
 
 		$visites = 0;
 		if ($row2 = sql_fetch($result2)) {
diff --git a/ecrire/exec/virtualiser.php b/ecrire/exec/virtualiser.php
index 0aa47d0e7c..754fe9716a 100644
--- a/ecrire/exec/virtualiser.php
+++ b/ecrire/exec/virtualiser.php
@@ -23,7 +23,7 @@ function exec_virtualiser_dist()
 		exit;
 	}
 	include_spip('inc/actions');
-	$r = sql_fetch(spip_query("SELECT chapo FROM spip_articles WHERE id_article=$id_article"));
+	$r = sql_fetsel("chapo", "spip_articles", "id_article=$id_article");
 
 	$virtuel = $r['chapo'];
 
diff --git a/ecrire/genie/syndic.php b/ecrire/genie/syndic.php
index 09c21b5220..863bfeb04d 100644
--- a/ecrire/genie/syndic.php
+++ b/ecrire/genie/syndic.php
@@ -39,7 +39,7 @@ function executer_une_syndication() {
 	AND statut='publie'
 	AND date_syndic < DATE_SUB(NOW(), INTERVAL
 	"._PERIODE_SYNDICATION_SUSPENDUE." MINUTE)";
-	$row = sql_fetch(sql_select("id_syndic", "spip_syndic", $where, '', "date_syndic", "1"));
+	$row = sql_fetsel("id_syndic", "spip_syndic", $where, '', "date_syndic", "1");
 	if ($row) {
 		$id_syndic = $row["id_syndic"];
 		$res1 = syndic_a_jour($id_syndic, 'off');
@@ -49,7 +49,7 @@ function executer_une_syndication() {
 	$where = "syndication='oui'
 	AND statut='publie'
 	AND date_syndic < DATE_SUB(NOW(), INTERVAL "._PERIODE_SYNDICATION." MINUTE)";
-	$row = sql_fetch(sql_select("id_syndic", "spip_syndic", $where, '', "date_syndic", "1"));
+	$row = sql_fetsel("id_syndic", "spip_syndic", $where, '', "date_syndic", "1");
 
 	if ($row) {
 		$id_syndic = $row["id_syndic"];
@@ -74,7 +74,7 @@ function syndic_a_jour($now_id_syndic, $statut = 'off') {
 		spip_log("syndic_a_jour doit etre appelee par Cron. Cf. " .
 			 "http://trac.rezo.net/trac/spip/changeset/10294",
 			 'vieilles_defs');
-	$result = spip_query("SELECT * FROM spip_syndic WHERE id_syndic=$now_id_syndic");
+	$result = sql_select("*", "spip_syndic", "id_syndic=$now_id_syndic");
 
 	if (!$row = sql_fetch($result))
 		return;
diff --git a/ecrire/inc/acces.php b/ecrire/inc/acces.php
index e963f148b7..0651f6d971 100644
--- a/ecrire/inc/acces.php
+++ b/ecrire/inc/acces.php
@@ -87,7 +87,7 @@ function low_sec($id_auteur) {
 		}
 	}
 	else {
-		$result = spip_query("SELECT * FROM spip_auteurs WHERE id_auteur = $id_auteur");
+		$result = sql_select("*", "spip_auteurs", "id_auteur = $id_auteur");
 
 		if ($row = sql_fetch($result)) {
 			$low_sec = $row["low_sec"];
diff --git a/ecrire/inc/actions.php b/ecrire/inc/actions.php
index 507aa4318a..4cfaa60476 100644
--- a/ecrire/inc/actions.php
+++ b/ecrire/inc/actions.php
@@ -264,7 +264,7 @@ function determine_upload($type='') {
 // http://doc.spip.org/@lire_php_auth
 function lire_php_auth($user, $pw) {
 
-	$row = spip_query("SELECT * FROM spip_auteurs WHERE login=" . _q($user));
+	$row = sql_select("*", "spip_auteurs", "login=" . _q($user));
 
 	$row = sql_fetch($row);
 	if ($row AND $row['source'] != 'ldap')
diff --git a/ecrire/inc/afficher_objets.php b/ecrire/inc/afficher_objets.php
index 5a57af2d9d..30f811a7c0 100644
--- a/ecrire/inc/afficher_objets.php
+++ b/ecrire/inc/afficher_objets.php
@@ -185,7 +185,7 @@ function afficher_complement_site($row){
 	}
 	if ($syndication == "oui" OR $syndication == "off" OR $syndication == "sus") {
 		$id_syndic = $row['id_syndic'];
-		$total_art = sql_fetch(spip_query("SELECT COUNT(*) AS n FROM spip_syndic_articles WHERE id_syndic=$id_syndic"));
+		$total_art = sql_fetsel("COUNT(*) AS n", "spip_syndic_articles", "id_syndic=$id_syndic");
 		$s .= " " . $total_art['n'] . " " . _T('info_syndication_articles');
 	} else {
 			$s .= "&nbsp;";
@@ -198,7 +198,7 @@ function afficher_complement_syndic_article($row){
 		$id_syndic = $row['id_syndic'];
 		// $my_sites cache les resultats des requetes sur les sites
 		if (!$my_sites[$id_syndic])
-			$my_sites[$id_syndic] = sql_fetch(spip_query("SELECT nom_site, moderation, miroir FROM spip_syndic WHERE id_syndic=$id_syndic"));
+			$my_sites[$id_syndic] = sql_fetsel("nom_site, moderation, miroir", "spip_syndic", "id_syndic=$id_syndic");
 
 		$aff = $my_sites[$id_syndic]['nom_site'];
 		if ($my_sites[$id_syndic]['moderation'] == 'oui')
@@ -313,7 +313,7 @@ function afficher_objet_boucle($row, &$tous_id,  $voir_logo, $own)
 		
 		$s = "";
 		if ($affrub && $id_rubrique) {
-			$rub = sql_fetch(spip_query("SELECT id_rubrique, titre FROM spip_rubriques WHERE id_rubrique=$id_rubrique"));
+			$rub = sql_fetsel("id_rubrique, titre", "spip_rubriques", "id_rubrique=$id_rubrique");
 			$id_rubrique = $rub['id_rubrique'];
 			$s .= "<a href='" . generer_url_ecrire("naviguer","id_rubrique=$id_rubrique") . "' style=\"display:block;\">".typo($rub['titre'])."</a>";
 		} else 
diff --git a/ecrire/inc/agenda.php b/ecrire/inc/agenda.php
index c4b5c6a2a3..63fbed1d08 100644
--- a/ecrire/inc/agenda.php
+++ b/ecrire/inc/agenda.php
@@ -1257,7 +1257,7 @@ function calendrier_categories($table, $num, $objet)
     return generer_calendrier_class($table, $num, $objet);
   else {
     // cf agenda.css
-    $result= sql_fetch(spip_query("SELECT " . (($objet != 'id_breve') ? 'id_secteur' : 'id_rubrique') . " AS id FROM	$table WHERE	$objet=$num"));
+    $result= sql_fetsel((($objet != 'id_breve') ? 'id_secteur' : 'id_rubrique') . " AS id", $table, "$objet=$num");
     if ($result) $num = $result['id'];
     return 'calendrier-couleur' . (($num%14)+1);
   }
diff --git a/ecrire/inc/article_select.php b/ecrire/inc/article_select.php
index 9733bdef83..2976beb6b9 100644
--- a/ecrire/inc/article_select.php
+++ b/ecrire/inc/article_select.php
@@ -35,7 +35,7 @@ function article_select($id_article, $id_rubrique=0, $lier_trad=0, $id_version=0
 			include_spip('inc/drapeau_edition');
 			signale_edition ($id_article,  $GLOBALS['auteur_session'], 'article');
 		}
-		$row = sql_fetch(spip_query("SELECT * FROM spip_articles WHERE id_article=$id_article"));
+		$row = sql_fetsel("*", "spip_articles", "id_article=$id_article");
 	// si une ancienne revision est demandee, la charger
 	// en lieu et place de l'actuelle ; attention les champs
 	// qui etaient vides ne sont pas vide's. Ca permet de conserver
@@ -72,7 +72,7 @@ function article_select($id_article, $id_rubrique=0, $lier_trad=0, $id_version=0
 		}
 		if (!autoriser('creerarticledans','rubrique',$row['id_rubrique'] )){
 			// manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises
-			$res = spip_query("SELECT id_rubrique FROM spip_rubriques WHERE id_parent=0");
+			$res = sql_select("id_rubrique", "spip_rubriques", "id_parent=0");
 			while (!autoriser('creerarticledans','rubrique',$row['id_rubrique'] ) && $row_rub = sql_fetch($res)){
 				$row['id_rubrique'] = $row_rub['id_rubrique'];
 			}
@@ -81,7 +81,7 @@ function article_select($id_article, $id_rubrique=0, $lier_trad=0, $id_version=0
 
 	// recuperer le secteur, pour affecter les bons champs extras
 	if (!$row['id_secteur']) {
-		$row_rub = sql_fetch(spip_query("SELECT id_secteur FROM spip_rubriques WHERE id_rubrique=$id_rubrique"));
+		$row_rub = sql_fetsel("id_secteur", "spip_rubriques", "id_rubrique=$id_rubrique");
 		$row['id_secteur'] = $row_rub['id_secteur'];
 	}
 
@@ -95,7 +95,7 @@ function article_select($id_article, $id_rubrique=0, $lier_trad=0, $id_version=0
 // http://doc.spip.org/@article_select_trad
 function article_select_trad($lier_trad) {
 	// Recuperer les donnees de l'article original
-	$result = spip_query("SELECT * FROM spip_articles WHERE id_article=$lier_trad");
+	$result = sql_select("*", "spip_articles", "id_article=$lier_trad");
 	if ($row = sql_fetch($result)) {
 		$row['titre'] = filtrer_entites(_T('info_nouvelle_traduction')).' '.$row["titre"];
 		$id_rubrique = $row['id_rubrique'];
@@ -118,7 +118,7 @@ function article_select_trad($lier_trad) {
 				$id_parent = 0;
 			} else {
 				// on cherche une rubrique soeur dans la bonne langue
-				$row_rub = sql_fetch(spip_query("SELECT id_parent FROM spip_rubriques WHERE id_rubrique=$id_rubrique"));
+				$row_rub = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=$id_rubrique");
 
 				$id_parent = $row_rub['id_parent'];
 			}
diff --git a/ecrire/inc/auth_ldap.php b/ecrire/inc/auth_ldap.php
index 956299f804..f720d69a25 100644
--- a/ecrire/inc/auth_ldap.php
+++ b/ecrire/inc/auth_ldap.php
@@ -110,7 +110,7 @@ function auth_ldap_inserer($dn, $statut)
 	include_spip('base/abstract_sql');
 	$n = sql_insert('spip_auteurs', '(source, nom, login, email, bio, statut, pass)', "('ldap', " . _q($nom) . ", " . _q($login) . ", " . _q($email) . ", " . _q($bio) . ", " . _q($statut) . ", '')");
 
-	return spip_query("SELECT * FROM spip_auteurs WHERE id_auteur=$n");
+	return sql_select("*", "spip_auteurs", "id_auteur=$n");
 }
 
 
diff --git a/ecrire/inc/auth_spip.php b/ecrire/inc/auth_spip.php
index f7b51f300f..94615b6667 100644
--- a/ecrire/inc/auth_spip.php
+++ b/ecrire/inc/auth_spip.php
@@ -23,7 +23,7 @@ function inc_auth_spip_dist ($login, $pass) {
 
 	  // si envoi non crypte, crypter maintenant
 	if (!$md5pass AND $pass) {
-			$result = spip_query("SELECT alea_actuel, alea_futur FROM spip_auteurs WHERE login=" . _q($login));
+			$result = sql_select("alea_actuel, alea_futur", "spip_auteurs", "login=" . _q($login));
 
 			if ($row = sql_fetch($result)) {
 				$md5pass = md5($row['alea_actuel'] . $pass);
diff --git a/ecrire/inc/autoriser.php b/ecrire/inc/autoriser.php
index 88ba852f6f..af0320fe98 100644
--- a/ecrire/inc/autoriser.php
+++ b/ecrire/inc/autoriser.php
@@ -59,7 +59,7 @@ function autoriser_dist($faire, $type='', $id=0, $qui = NULL, $opt = NULL) {
 	if ($qui === NULL)
 	  $qui = $GLOBALS['auteur_session'] ? $GLOBALS['auteur_session'] : array('statut' => '', 'id_auteur' =>0);
 	elseif (is_numeric($qui)) {
-		$s = spip_query("SELECT * FROM spip_auteurs WHERE id_auteur=".$qui);
+		$s = sql_select("*", "spip_auteurs", "id_auteur=".$qui);
 		$qui = sql_fetch($s);
 	}
 
@@ -187,7 +187,7 @@ function autoriser_site_modifier_dist($faire, $type, $id, $qui, $opt) {
 	if ($qui['statut'] == '0minirezo')
 		return true;
 
-	$s = spip_query("SELECT id_rubrique,statut FROM spip_syndic WHERE id_syndic="._q($id));
+	$s = sql_select("id_rubrique,statut", "spip_syndic", "id_syndic="._q($id));
 	return ($t = sql_fetch($s)
 		AND autoriser('voir','rubrique',$t['id_rubrique'])
 		AND ($t['statut'] == 'prop')
@@ -238,7 +238,7 @@ function autoriser_document_modifier_dist($faire, $type, $id, $qui, $opt){
 		foreach($jointures as $j) {
 			$type = preg_replace(',s?_?documents?_?|s$,', '', $j);
 			$id_table = id_table_objet($type);
-			$s = spip_query("SELECT $id_table FROM spip_$j WHERE id_document="._q($id));
+			$s = sql_select("$id_table", "spip_$j", "id_document="._q($id));
 			while ($t = sql_fetch($s)) {
 				spip_log($t);
 				if (autoriser('modifier', $type, $t[$id_table], $qui, $opt)) {
@@ -343,7 +343,7 @@ function autoriser_voir_dist($faire, $type, $id, $qui, $opt) {
 	if (!$id) return false;
 
 	// un article 'prepa' ou 'poubelle' dont on n'est pas auteur : interdit
-	$s = spip_query("SELECT statut FROM spip_articles WHERE id_article="._q($id));
+	$s = sql_select("statut", "spip_articles", "id_article="._q($id));
 	$r = sql_fetch($s);
 	include_spip('inc/auth'); // pour auteurs_article si espace public
 	return
@@ -484,7 +484,7 @@ function autoriser_auteur_modifier_dist($faire, $type, $id, $qui, $opt) {
 					return true;
 			}
 			else if ($id_auteur = intval($id)) {
-				$s = spip_query("SELECT statut FROM spip_auteurs WHERE id_auteur=$id_auteur");
+				$s = sql_select("statut", "spip_auteurs", "id_auteur=$id_auteur");
 				if ($t = sql_fetch($s)
 				AND $t['statut'] != '0minirezo')
 					return true;
diff --git a/ecrire/inc/chercher_rubrique.php b/ecrire/inc/chercher_rubrique.php
index aa49badc91..93a06c3eb4 100644
--- a/ecrire/inc/chercher_rubrique.php
+++ b/ecrire/inc/chercher_rubrique.php
@@ -165,7 +165,7 @@ function selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem=0, $do)
        ## la verification est faite a l'arrivee des donnees (Fil)
 
 	if ($id_rubrique) {
-		$titre = sql_fetch(spip_query("SELECT titre FROM spip_rubriques WHERE id_rubrique=$id_rubrique"));
+		$titre = sql_fetsel("titre", "spip_rubriques", "id_rubrique=$id_rubrique");
 		$titre = $titre['titre'];
 	} else if ($type == 'auteur')
 		$titre = '&nbsp;';
diff --git a/ecrire/inc/distant.php b/ecrire/inc/distant.php
index 689c8285bb..0be237872a 100644
--- a/ecrire/inc/distant.php
+++ b/ecrire/inc/distant.php
@@ -306,7 +306,7 @@ function fichier_copie_locale($source) {
 		($path_parts = pathinfo($source) AND $ext = $path_parts['extension'])
 		) {
 			// verifier que c'est un type autorise
-			$t = sql_fetch(spip_query("SELECT extension FROM spip_types_documents WHERE extension="._q($ext)));
+			$t = sql_fetsel("extension", "spip_types_documents", "extension="._q($ext));
 			if ($t)
 				$extension = $t['extension'];
 		}
@@ -347,19 +347,19 @@ function recuperer_infos_distantes($source, $max=0, $charger_si_petite_image = t
 		$t = null;
 		if (($mime_type == 'text/plain' OR $mime_type == '')
 		AND preg_match(',\.([a-z0-9]+)(\?.*)?$,', $source, $rext)) {
-			$t = sql_fetch(spip_query("SELECT extension FROM spip_types_documents WHERE extension=" . _q($rext[1])));
+			$t = sql_fetsel("extension", "spip_types_documents", "extension=" . _q($rext[1]));
 		}
 
 		// Autre mime/type (ou text/plain avec fichier d'extension inconnue)
 		if (!$t)
-			$t = sql_fetch(spip_query("SELECT extension FROM spip_types_documents WHERE mime_type=" . _q($mime_type)));
+			$t = sql_fetsel("extension", "spip_types_documents", "mime_type=" . _q($mime_type));
 
 		// Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
 		// On essaie de nouveau avec l'extension
 		if (!$t
 		AND $mime_type != 'text/plain'
 		AND preg_match(',\.([a-z0-9]+)(\?.*)?$,', $source, $rext)) {
-			$t = sql_fetch(spip_query("SELECT extension FROM spip_types_documents WHERE extension=" . _q($rext[1])));
+			$t = sql_fetsel("extension", "spip_types_documents", "extension=" . _q($rext[1]));
 		}
 
 
@@ -369,7 +369,7 @@ function recuperer_infos_distantes($source, $max=0, $charger_si_petite_image = t
 		} else {
 			# par defaut on retombe sur '.bin' si c'est autorise
 			spip_log("mime-type $mime_type inconnu");
-			$t = sql_fetch(spip_query("SELECT extension FROM spip_types_documents WHERE extension='bin'"));
+			$t = sql_fetsel("extension", "spip_types_documents", "extension='bin'");
 			if (!$t) return false;
 			$a['extension'] = $t['extension'];
 		}
diff --git a/ecrire/inc/documenter.php b/ecrire/inc/documenter.php
index f5956c2133..1c4ca8bd48 100644
--- a/ecrire/inc/documenter.php
+++ b/ecrire/inc/documenter.php
@@ -54,7 +54,7 @@ function inc_documenter_dist(
 	/*if ($type=='article'
 	AND !isset($GLOBALS['doublons_documents_inclus'])
 	AND is_int($doc)) {
-		$r = sql_fetch(spip_query("SELECT chapo,texte FROM spip_articles WHERE id_article="._q($doc)));
+		$r = sql_fetsel("chapo,texte", "spip_articles", "id_article="._q($doc));
 		propre(join(" ",$r));
 	}*/
 
diff --git a/ecrire/inc/documents.php b/ecrire/inc/documents.php
index 7e1b48d3fb..b4b6939b3a 100644
--- a/ecrire/inc/documents.php
+++ b/ecrire/inc/documents.php
@@ -48,7 +48,7 @@ function get_spip_doc($fichier) {
 function generer_url_document_dist($id_document, $args='', $ancre='') {
 	if (intval($id_document) <= 0)
 		return '';
-	$row = sql_fetch(spip_query("SELECT fichier,distant FROM spip_documents WHERE id_document="._q($id_document)));
+	$row = sql_fetsel("fichier,distant", "spip_documents", "id_document="._q($id_document));
 	if (!$row) return '';
 	// Cette variable de configuration peut etre posee par un plugin
 	// par exemple acces_restreint
@@ -117,7 +117,7 @@ function document_et_vignette($document, $url, $portfolio=false) {
 	$vignette = $document['id_vignette'];
 
 	if ($vignette) 
-		$vignette = sql_fetch(spip_query("SELECT * FROM spip_documents WHERE id_document = ".$vignette));
+		$vignette = sql_fetsel("*", "spip_documents", "id_document = ".$vignette);
 	if ($vignette) {
 			if (!$portfolio OR !($GLOBALS['meta']['creer_preview'] == 'oui')) {
 				$image = image_pattern($vignette);
@@ -158,7 +158,7 @@ function document_et_vignette($document, $url, $portfolio=false) {
 	if (!$url)
 		return $image;
 	else {
-		$t = sql_fetch(spip_query("SELECT mime_type FROM spip_types_documents WHERE extension="._q($document['extension'])));
+		$t = sql_fetsel("mime_type", "spip_types_documents", "extension="._q($document['extension']));
 		return "<a href='$url'\n\ttype='".$t['mime_type']."'>$image</a>";
 	}
 }
@@ -300,7 +300,7 @@ function afficher_case_document($id_document, $id, $script, $type, $deplier=fals
 	charger_generer_url();
 	$res = spip_query("SELECT docs.id_document, docs.id_vignette,docs.extension,docs.titre,docs.descriptif,docs.fichier,docs.largeur,docs.hauteur,docs.taille,docs.mode,docs.distant, docs.date, l.vu FROM spip_documents AS docs JOIN spip_documents_".$type."s AS l ON l.id_document=docs.id_document WHERE l.id_$type="._q($id)." AND l.id_document="._q($id_document));
 	if (!$document = sql_fetch($res)) return "";
-	//$document = sql_fetch(spip_query("SELECT * FROM spip_documents WHERE id_document = " . intval($id_document)));
+	//$document = sql_fetsel("*", "spip_documents", "id_document = " . intval($id_document));
 
 	$id_vignette = $document['id_vignette'];
 	$extension = $document['extension'];
@@ -319,7 +319,7 @@ function afficher_case_document($id_document, $id, $script, $type, $deplier=fals
 
 	$cadre = strlen($titre) ? $titre : basename($fichier);
 
-	$result = spip_query("SELECT titre,inclus FROM spip_types_documents WHERE extension="._q($extension));
+	$result = sql_select("titre,inclus", "spip_types_documents", "extension="._q($extension));
 	if ($letype = sql_fetch($result)) {
 		$type_inclus = $letype['inclus'];
 		$type_titre = $letype['titre'];
diff --git a/ecrire/inc/editer_auteurs.php b/ecrire/inc/editer_auteurs.php
index c110b4fa84..8bb23d88a6 100644
--- a/ecrire/inc/editer_auteurs.php
+++ b/ecrire/inc/editer_auteurs.php
@@ -155,7 +155,7 @@ function rechercher_auteurs_objet($cherche_auteur, $ids, $type, $id, $script_edi
 	}
 	elseif (preg_match('/^\d+$/',$ids)) {
 
-		$row = sql_fetch(spip_query("SELECT nom FROM spip_auteurs WHERE id_auteur=$ids"));
+		$row = sql_fetsel("nom", "spip_auteurs", "id_auteur=$ids");
 		return "<b>"._T('texte_ajout_auteur')."</b><br /><ul><li><span class='verdana1 spip_small'><b><span class='spip_medium'>".typo($row['nom'])."</span></b></span></li></ul>";
 	}
 	else {
diff --git a/ecrire/inc/editer_mot.php b/ecrire/inc/editer_mot.php
index 4e7168bf7a..0a7019e658 100644
--- a/ecrire/inc/editer_mot.php
+++ b/ecrire/inc/editer_mot.php
@@ -115,7 +115,7 @@ function recherche_mot_cle($cherche_mots, $id_groupe, $objet, $id_objet, $table,
 	else if ($table == 'breves') $ou = _T('info_la_breve');
 	else if ($table == 'rubriques') $ou = _T('info_la_rubrique');
 
-	$result = spip_query("SELECT id_mot, titre FROM spip_mots WHERE id_groupe=" . _q($id_groupe));
+	$result = sql_select("id_mot, titre", "spip_mots", "id_groupe=" . _q($id_groupe));
 
 	$table_mots = array();
 	$table_ids = array();
@@ -136,7 +136,7 @@ function recherche_mot_cle($cherche_mots, $id_groupe, $objet, $id_objet, $table,
 		}
 		else if (count($resultat) == 1) {
 			$nouveaux_mots[] = $resultat[0];
-			$row = sql_fetch(spip_query("SELECT titre FROM spip_mots WHERE id_mot=$resultat[0]"));
+			$row = sql_fetsel("titre", "spip_mots", "id_mot=$resultat[0]");
 			$res .= "<b>"._T('info_mot_cle_ajoute')." $ou : </b><br />\n<ul>";
 			$res .= "\n<li><span class='verdana1 spip_small'><b><span class='spip_medium'>".typo($row['titre'])."</span></b></span></li>";
 			$res .= "\n</ul>";
@@ -181,7 +181,7 @@ function afficher_mots_cles($flag_editable, $objet, $id_objet, $table, $table_id
 			$url = generer_url_ecrire('mots_edit', "id_mot=$id_mot&redirect=$ret");
 			$vals= array("<a href='$url'>$cle</a>");
 
-			$r = sql_fetch(spip_query("SELECT titre, unseul FROM spip_groupes_mots WHERE id_groupe = $id_groupe"));
+			$r = sql_fetsel("titre, unseul", "spip_groupes_mots", "id_groupe = $id_groupe");
 			$unseul = $r['unseul'];
 	// On recupere le typo_mot ici, et non dans le mot-cle lui-meme; sinon bug avec arabe
 			$type_mot = typo($r['titre']);
diff --git a/ecrire/inc/extra.php b/ecrire/inc/extra.php
index bae2f72413..4fd1a36cbb 100644
--- a/ecrire/inc/extra.php
+++ b/ecrire/inc/extra.php
@@ -384,7 +384,7 @@ function extra_update($type, $id, $c = false) {
 	// passer de 'articles' a 'article' :-(
 	$t = preg_replace(',s$,', '', $type);
 
-	$orig = spip_query("SELECT extra FROM " . table_objet_sql($t)." WHERE ".id_table_objet($t)."=".intval($id));
+	$orig = sql_select("extra", table_objet_sql($t), id_table_objet($t)."=".intval($id));
 	$orig = sql_fetch($orig);
 
 	if (isset($orig['extra'])
diff --git a/ecrire/inc/forum.php b/ecrire/inc/forum.php
index bb8a9a9e0a..cc5c725560 100644
--- a/ecrire/inc/forum.php
+++ b/ecrire/inc/forum.php
@@ -242,7 +242,7 @@ function calculer_threads() {
 // http://doc.spip.org/@racine_forum
 function racine_forum($id_forum){
 	if (!$id_forum = intval($id_forum)) return;
-	$result = spip_query("SELECT id_parent, id_rubrique, id_article, id_breve, id_syndic, id_message, id_thread FROM spip_forum WHERE id_forum=".$id_forum);
+	$result = sql_select("id_parent, id_rubrique, id_article, id_breve, id_syndic, id_message, id_thread", "spip_forum", "id_forum=".$id_forum);
 
 	if (!$row = sql_fetch($result))
 		return false;
@@ -272,7 +272,7 @@ function racine_forum($id_forum){
 // http://doc.spip.org/@parent_forum
 function parent_forum($id_forum) {
 	if (!$id_forum = intval($id_forum)) return;
-	$result = spip_query("SELECT id_parent, id_rubrique, id_article, id_breve, id_syndic FROM spip_forum WHERE id_forum=".$id_forum);
+	$result = sql_select("id_parent, id_rubrique, id_article, id_breve, id_syndic", "spip_forum", "id_forum=".$id_forum);
 	if($row = sql_fetch($result)){
 		if($row['id_parent']) return array('forum', $row['id_parent']);
 		if($row['id_rubrique']) return array('rubrique', $row['id_rubrique']);
@@ -312,7 +312,7 @@ function conserver_original($id_forum) {
 		return ''; // pas d'erreur
 
 	// recopier le forum
-	$t = sql_fetch(spip_query("SELECT * FROM spip_forum WHERE id_forum="._q($id_forum)));
+	$t = sql_fetsel("*", "spip_forum", "id_forum="._q($id_forum));
 
 	if ($t) {
 		unset($t['id_forum']);
diff --git a/ecrire/inc/forum_insert.php b/ecrire/inc/forum_insert.php
index f7245d618a..e2e5543b90 100644
--- a/ecrire/inc/forum_insert.php
+++ b/ecrire/inc/forum_insert.php
@@ -48,7 +48,7 @@ function controler_forum($id) {
 
 	// Reglage forums d'article
 	if ($id) {
-		$q = spip_query("SELECT accepter_forum FROM spip_articles WHERE id_article=$id");
+		$q = sql_select("accepter_forum", "spip_articles", "id_article=$id");
 		if ($r = sql_fetch($q))
 			$id = $r['accepter_forum'];
 	}
@@ -182,7 +182,7 @@ function inc_forum_insert_dist() {
 	$id_message = sql_insert('spip_forum', '(date_heure)', '(NOW())');
 
 	if ($id_forum) {
-		$id_thread = sql_fetch(spip_query("SELECT id_thread FROM spip_forum WHERE id_forum = $id_forum"));
+		$id_thread = sql_fetsel("id_thread", "spip_forum", "id_forum = $id_forum");
 		$id_thread = $id_thread['id_thread'];
 	}
 	else
diff --git a/ecrire/inc/import_insere.php b/ecrire/inc/import_insere.php
index d951f7d67a..bd0480be82 100644
--- a/ecrire/inc/import_insere.php
+++ b/ecrire/inc/import_insere.php
@@ -313,7 +313,7 @@ function import_identifie_id_type($values, $table, $desc, $request) {
 // deux groupes de mots ne peuvent avoir le meme titre ==> identification
 // http://doc.spip.org/@import_identifie_id_groupe
 function import_identifie_id_groupe($values, $table, $desc, $request)  {
-	$r = sql_fetch(spip_query("SELECT id_groupe AS id, titre FROM spip_groupes_mots WHERE titre=" . _q($values['titre'])));
+	$r = sql_fetsel("id_groupe AS id, titre", "spip_groupes_mots", "titre=" . _q($values['titre']));
 	return $r ? array($r['id'], $r['titre']) : false;
 }
 
diff --git a/ecrire/inc/informer.php b/ecrire/inc/informer.php
index 568151cb9e..ed7182e1a9 100644
--- a/ecrire/inc/informer.php
+++ b/ecrire/inc/informer.php
@@ -21,7 +21,7 @@ function inc_informer_dist($id, $col, $exclus, $rac, $type, $do='aff')
 
 	include_spip('inc/texte');
 	if ($type == "rubrique") {
-		$res = spip_query("SELECT titre, descriptif FROM spip_rubriques WHERE id_rubrique = $id");
+		$res = sql_select("titre, descriptif", "spip_rubriques", "id_rubrique = $id");
 		if ($row = sql_fetch($res)) {
 			$titre = typo($row["titre"]);
 			$descriptif = propre($row["descriptif"]);
diff --git a/ecrire/inc/informer_auteur.php b/ecrire/inc/informer_auteur.php
index acd9c43fd7..fd5ec467e9 100644
--- a/ecrire/inc/informer_auteur.php
+++ b/ecrire/inc/informer_auteur.php
@@ -22,12 +22,12 @@ function inc_informer_auteur_dist($id)
 	include_spip('inc/presentation');
 	include_spip('inc/formater_auteur');
 
-	$res = spip_query("SELECT * FROM spip_auteurs WHERE id_auteur = $id");
+	$res = sql_select("*", "spip_auteurs", "id_auteur = $id");
 	if ($row = sql_fetch($res)) {
 			$nom = typo(extraire_multi($row["nom"]));
 			$bio = propre($row["bio"]);
 			$mail = formater_auteur_mail($row, $id);
-			$nb = sql_fetch(spip_query("SELECT COUNT(*) AS n FROM spip_auteurs_articles WHERE id_auteur=$id"));
+			$nb = sql_fetsel("COUNT(*) AS n", "spip_auteurs_articles", "id_auteur=$id");
 			if ($nb['n'] > 1)
 			$nb = $nb['n']."&nbsp;"._T('info_article_2');
 			else if($nb['n'] == 1)
diff --git a/ecrire/inc/legender.php b/ecrire/inc/legender.php
index 9920cb9bfa..b016a46c85 100644
--- a/ecrire/inc/legender.php
+++ b/ecrire/inc/legender.php
@@ -34,7 +34,7 @@ function inc_legender_dist($id_document, $document, $script, $type, $id, $ancre,
 	} else
 	// retour d'Ajax
 	if ($id_document) {
-		$res = spip_query("SELECT * FROM spip_documents WHERE id_document = " . intval($id_document));
+		$res = sql_select("*", "spip_documents", "id_document = " . intval($id_document));
 		$document = sql_fetch($res);
 		$document['vu'] = 'non';
 		$res = spip_query("SELECT vu FROM spip_documents_".$type."s WHERE id_$type=$id AND id_document=".intval($id_document));
diff --git a/ecrire/inc/modifier.php b/ecrire/inc/modifier.php
index 5853bd87b7..854ecd89eb 100644
--- a/ecrire/inc/modifier.php
+++ b/ecrire/inc/modifier.php
@@ -106,7 +106,7 @@ function marquer_doublons_documents($champs,$id,$id_table_objet,$table_objet){
 	if (!isset($champs['chapo'])) $load = 'chapo';
 	if ($load){
 		$champs[$load] = "";
-		$res = spip_query("SELECT $load FROM spip_$table_objet WHERE $id_table_objet="._q($id));
+		$res = sql_select("$load", "spip_$table_objet", "$id_table_objet="._q($id));
 		if ($row = sql_fetch($res) AND isset($row[$load]))
 			$champs[$load] = $row[$load];
 	}
@@ -168,7 +168,7 @@ function revision_mot($id_mot, $c=false) {
 	// regler le groupe
 	if (NULL !== ($id_groupe = _request('id_groupe',$c))
 	OR NULL !== ($type = _request('type',$c))) {
-		$result = spip_query("SELECT titre FROM spip_groupes_mots WHERE id_groupe="._q($id_groupe));
+		$result = sql_select("titre", "spip_groupes_mots", "id_groupe="._q($id_groupe));
 		if ($row = sql_fetch($result))
 			$type = $row['titre'];
 		else
@@ -200,7 +200,7 @@ function revision_petition($id_article, $c=false) {
 // http://doc.spip.org/@revision_forum
 function revision_forum($id_forum, $c=false) {
 
-	$s = spip_query("SELECT * FROM spip_forum WHERE id_forum="._q($id_forum));
+	$s = sql_select("*", "spip_forum", "id_forum="._q($id_forum));
 	if (!$t = sql_fetch($s)) {
 		spip_log("erreur forum $id_forum inexistant");
 		return;
@@ -244,7 +244,7 @@ function revision_forum($id_forum, $c=false) {
 	AND count($cles = array_intersect(array_keys($c),
 		array('id_article', 'id_rubrique', 'id_syndic', 'id_breve')))
 	) {
-		$thread = sql_fetch(spip_query("SELECT id_thread FROM spip_forum WHERE id_forum=$id_forum"));
+		$thread = sql_fetsel("id_thread", "spip_forum", "id_forum=$id_forum");
 		foreach ($cles as $k)
 			spip_query("UPDATE spip_forum SET $k="._q($c[$k])." WHERE id_thread=".$thread['id_thread']." AND statut!='original'");
 		// on n'affecte pas $r, car un deplacement ne change pas l'auteur
diff --git a/ecrire/inc/notifications.php b/ecrire/inc/notifications.php
index 82a0214a0a..46718f0f56 100644
--- a/ecrire/inc/notifications.php
+++ b/ecrire/inc/notifications.php
@@ -85,7 +85,7 @@ function notifier_publication_article($id_article) {
 	$suivi_edito = $GLOBALS['meta']["suivi_edito"];
 
 	if ($suivi_edito == "oui") {
-		$result = spip_query("SELECT * FROM spip_articles WHERE id_article = $id_article");
+		$result = sql_select("*", "spip_articles", "id_article = $id_article");
 
 		if ($row = sql_fetch($result)) {
 
@@ -122,7 +122,7 @@ function notifier_proposition_article($id_article) {
 	$suivi_edito = $GLOBALS['meta']["suivi_edito"];
 
 	if ($suivi_edito == "oui") {
-		$row = sql_fetch(spip_query("SELECT * FROM spip_articles WHERE id_article = $id_article"));
+		$row = sql_fetsel("*", "spip_articles", "id_article = $id_article");
 		if ($row) {
 
 			if ($l = $row['lang']) $l = lang_select($l);
@@ -191,11 +191,11 @@ function email_notification_forum ($t, $email) {
 	}
 
 	if ($t['id_article']) {
-		$article = sql_fetch(spip_query("SELECT titre FROM spip_articles WHERE id_article="._q($t['id_article'])));
+		$article = sql_fetsel("titre", "spip_articles", "id_article="._q($t['id_article']));
 		$titre = textebrut(typo($article['titre']));
 	}
 	if ($t['id_message']) {
-		$message = sql_fetch(spip_query("SELECT titre FROM spip_messages WHERE id_message="._q($t['id_message'])));
+		$message = sql_fetsel("titre", "spip_messages", "id_message="._q($t['id_message']));
 		$titre = textebrut(typo($message['titre']));
 	}
 
@@ -236,7 +236,7 @@ function email_notification_forum ($t, $email) {
 // suivre si le forum est valide directement ('pos' ou 'abo')
 // http://doc.spip.org/@notifications_forumvalide_dist
 function notifications_forumvalide_dist($quoi, $id_forum) {
-	$s = spip_query("SELECT * FROM spip_forum WHERE id_forum="._q($id_forum));
+	$s = sql_select("*", "spip_forum", "id_forum="._q($id_forum));
 	if (!$t = sql_fetch($s))
 		return;
 
@@ -293,7 +293,7 @@ function notifications_forumvalide_dist($quoi, $id_forum) {
 
 // http://doc.spip.org/@notifications_forumposte_dist
 function notifications_forumposte_dist($quoi, $id_forum) {
-	$s = spip_query("SELECT * FROM spip_forum WHERE id_forum="._q($id_forum));
+	$s = sql_select("*", "spip_forum", "id_forum="._q($id_forum));
 	if (!$t = sql_fetch($s))
 		return;
 
diff --git a/ecrire/inc/petitionner.php b/ecrire/inc/petitionner.php
index a4bfaa300f..148e190331 100644
--- a/ecrire/inc/petitionner.php
+++ b/ecrire/inc/petitionner.php
@@ -21,7 +21,7 @@ function inc_petitionner_dist($id_article, $script, $args)
 {
 	global $spip_lang_right;
 
-	$petition = sql_fetch(spip_query("SELECT * FROM spip_petitions WHERE id_article=$id_article"));
+	$petition = sql_fetsel("*", "spip_petitions", "id_article=$id_article");
 
 	$res = petitionner_choisir($petition);
 
diff --git a/ecrire/inc/presentation.php b/ecrire/inc/presentation.php
index 7f83f7cd23..e0a6499de8 100644
--- a/ecrire/inc/presentation.php
+++ b/ecrire/inc/presentation.php
@@ -1424,7 +1424,7 @@ function afficher_hierarchie($id_rubrique) {
 
 	while ($id_rubrique) {
 
-		$res = sql_fetch(spip_query("SELECT id_parent, titre, lang FROM spip_rubriques WHERE id_rubrique=$id_rubrique"));
+		$res = sql_fetsel("id_parent, titre, lang", "spip_rubriques", "id_rubrique=$id_rubrique");
 
 		if (!$res) break; // rubrique inexistante
 
diff --git a/ecrire/inc/puce_statut.php b/ecrire/inc/puce_statut.php
index 120d66f5cb..15e98b7c87 100644
--- a/ecrire/inc/puce_statut.php
+++ b/ecrire/inc/puce_statut.php
@@ -206,7 +206,7 @@ function puce_statut_breve($id, $statut, $id_rubrique, $type, $ajax='') {
 // http://doc.spip.org/@puce_statut_site
 function puce_statut_site($id_site, $statut, $id_rubrique, $type, $ajax=''){
 
-	$s = spip_query("SELECT syndication FROM spip_syndic WHERE id_syndic="._q($id_site));
+	$s = sql_select("syndication", "spip_syndic", "id_syndic="._q($id_site));
 	$t = sql_fetch($s);
 	if ($t['syndication'] == 'off' OR $t['syndication'] == 'sus')
 		$anim = 'anim';
diff --git a/ecrire/inc/referencer_traduction.php b/ecrire/inc/referencer_traduction.php
index 5052fdd289..fc27c362ef 100644
--- a/ecrire/inc/referencer_traduction.php
+++ b/ecrire/inc/referencer_traduction.php
@@ -24,7 +24,7 @@ function inc_referencer_traduction_dist($id_article, $flag, $id_rubrique, $id_tr
 			AND ($GLOBALS['meta']['gerer_trad'] == 'oui'))) )
 		return '';
 
-	$langue_article = sql_fetch(spip_query("SELECT lang FROM spip_articles WHERE id_article=$id_article"));
+	$langue_article = sql_fetsel("lang", "spip_articles", "id_article=$id_article");
 
 	$langue_article = $langue_article['lang'];
 
@@ -32,7 +32,7 @@ function inc_referencer_traduction_dist($id_article, $flag, $id_rubrique, $id_tr
 	// Choix langue article
 	if ($GLOBALS['meta']['multi_articles'] == 'oui' AND $flag) {
 
-		$row = sql_fetch(spip_query("SELECT lang FROM spip_rubriques WHERE id_rubrique=$id_rubrique"));
+		$row = sql_fetsel("lang", "spip_rubriques", "id_rubrique=$id_rubrique");
 		$langue_parent = $row['lang'];
 
 		if (!$langue_parent)
@@ -147,7 +147,7 @@ function articles_traduction($id_article, $id_trad)
 {
 	global $connect_toutes_rubriques;
 
-	$result_trad = spip_query("SELECT id_article, id_rubrique, titre, lang, statut FROM spip_articles WHERE id_trad = $id_trad");
+	$result_trad = sql_select("id_article, id_rubrique, titre, lang, statut", "spip_articles", "id_trad = $id_trad");
 	
 	$table= array();
 	$puce_statut = charger_fonction('puce_statut', 'inc');
diff --git a/ecrire/inc/regler_moderation.php b/ecrire/inc/regler_moderation.php
index 9b470b6ebb..d4f7575a18 100644
--- a/ecrire/inc/regler_moderation.php
+++ b/ecrire/inc/regler_moderation.php
@@ -17,7 +17,7 @@ if (!defined("_ECRIRE_INC_VERSION")) return;
 function get_forums_publics($id_article=0) {
 
 	if ($id_article) {
-		$res = spip_query("SELECT accepter_forum FROM spip_articles WHERE id_article=$id_article");
+		$res = sql_select("accepter_forum", "spip_articles", "id_article=$id_article");
 
 		if ($obj = sql_fetch($res))
 			return $obj['accepter_forum'];
diff --git a/ecrire/inc/revisions.php b/ecrire/inc/revisions.php
index 602f084b21..42721d3b10 100644
--- a/ecrire/inc/revisions.php
+++ b/ecrire/inc/revisions.php
@@ -603,7 +603,7 @@ function enregistrer_premiere_revision($x) {
 
 		if (!sql_countsel('spip_versions',"id_article=$id_article")) {
 			$select = join(", ", liste_champs_versionnes($x['args']['table']));
-			$query = spip_query("SELECT $select, date, date_modif FROM spip_articles WHERE id_article=$id_article");
+			$query = sql_select("$select, date, date_modif", "spip_articles", "id_article=$id_article");
 			$champs_originaux = sql_fetch($query);
 			// Si le titre est vide, c'est qu'on vient de creer l'article
 			if ($champs_originaux['titre'] != '') {
diff --git a/ecrire/inc/rubriques.php b/ecrire/inc/rubriques.php
index 16d9745f34..347969f6b4 100644
--- a/ecrire/inc/rubriques.php
+++ b/ecrire/inc/rubriques.php
@@ -93,7 +93,7 @@ function depublier_branche_rubrique_if($id_rubrique)
 		spip_query("UPDATE spip_rubriques SET statut='0' WHERE id_rubrique=$id_pred");
 #		spip_log("depublier_rubrique $id_pred");
 
-		$r = sql_fetch(spip_query("SELECT id_parent FROM spip_rubriques WHERE id_rubrique=$id_pred"));
+		$r = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=$id_pred");
 
 		$id_pred = $r['id_parent'];
 	}
diff --git a/ecrire/inc/securiser_action.php b/ecrire/inc/securiser_action.php
index 63e4dc80fd..708a50476d 100644
--- a/ecrire/inc/securiser_action.php
+++ b/ecrire/inc/securiser_action.php
@@ -76,7 +76,7 @@ function caracteriser_auteur() {
 	if (isset($auteur_session['pass']) AND $auteur_session['pass'])
 		return $caracterisation = array($id_auteur, $auteur_session['pass']); 
 	else {
-		$t = spip_query("SELECT id_auteur, pass FROM spip_auteurs WHERE id_auteur=$id_auteur");
+		$t = sql_select("id_auteur, pass", "spip_auteurs", "id_auteur=$id_auteur");
 		if ($t = sql_fetch($t))
 			return $caracterisation = array($t['id_auteur'], $t['pass']);
 		include_spip('inc/minipres');
diff --git a/ecrire/inc/selectionner.php b/ecrire/inc/selectionner.php
index 08387f3264..752f316eb7 100644
--- a/ecrire/inc/selectionner.php
+++ b/ecrire/inc/selectionner.php
@@ -127,7 +127,7 @@ function mini_hier ($id_rubrique) {
 
 // http://doc.spip.org/@mini_hierarchie_rub
 function mini_hierarchie_rub ($id_rubrique) {
-	$row = sql_fetch(spip_query("SELECT id_parent FROM spip_rubriques WHERE id_rubrique = " . intval($id_rubrique)));
+	$row = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique = " . intval($id_rubrique));
 	return $row["id_parent"];
 }
 
diff --git a/ecrire/inc/signatures.php b/ecrire/inc/signatures.php
index c447647a06..290d4082c8 100644
--- a/ecrire/inc/signatures.php
+++ b/ecrire/inc/signatures.php
@@ -105,7 +105,7 @@ function signatures_edit($script, $id, $debut, $row) {
 		$res .= '<br />' . message_de_signature($row);
 		
 		if (!$id) {
-			$r = sql_fetch(spip_query("SELECT titre, statut FROM spip_articles WHERE id_article=$id_article"));
+			$r = sql_fetsel("titre, statut", "spip_articles", "id_article=$id_article");
 
 			$res .= "<span class='arial1' style='float: $spip_lang_right; color: black; padding-$spip_lang_left: 4px;'><b>"
 			. _T('info_numero_abbreviation')
diff --git a/ecrire/inc/tourner.php b/ecrire/inc/tourner.php
index 70a3206cf0..d174ef084e 100644
--- a/ecrire/inc/tourner.php
+++ b/ecrire/inc/tourner.php
@@ -23,11 +23,11 @@ function inc_tourner_dist($id_document, $document, $script, $flag, $type)
 
 	if (!$document) {
 		// retour d'Ajax
-		$document = sql_fetch(spip_query("SELECT * FROM spip_documents WHERE id_document = " . intval($id_document)));
+		$document = sql_fetsel("*", "spip_documents", "id_document = " . intval($id_document));
 	}
 
 	if (preg_match('/^\w+$/',$type)) { // securite
-		$id = sql_fetch(spip_query("SELECT id_$type FROM spip_documents_$type" . "s WHERE id_document = " . intval($id_document)));
+		$id = sql_fetsel("id_$type", "spip_documents_$type" . "s", "id_document = " . intval($id_document));
 		$id = $id["id_$type"];
 	} else $id = 0; // le hash sera inutilisable
 
diff --git a/ecrire/install/etape_4.php b/ecrire/install/etape_4.php
index 42e69a99ba..8a57275370 100644
--- a/ecrire/install/etape_4.php
+++ b/ecrire/install/etape_4.php
@@ -64,7 +64,7 @@ function install_etape_4_dist()
 		# pour le passwd, bizarrement il faut le convertir comme s'il avait
 		# ete tape en iso-8859-1 ; car c'est en fait ce que voit md5.js
 		$pass = unicode2charset(utf_8_to_unicode($pass), 'iso-8859-1');
-		$result = spip_query("SELECT id_auteur FROM spip_auteurs WHERE login=" . _q($login));
+		$result = sql_select("id_auteur", "spip_auteurs", "login=" . _q($login));
 
 		unset($id_auteur);
 		if ($row = sql_fetch($result, $server_db)) $id_auteur = $row['id_auteur'];
-- 
GitLab