Skip to content

Commit

Permalink
traduction 9.5 plpgsql.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
edelamusse authored and gleu committed Feb 15, 2016
1 parent f892c79 commit 329dcf0
Showing 1 changed file with 100 additions and 87 deletions.
187 changes: 100 additions & 87 deletions postgresql/plpgsql.xml
Original file line number Diff line number Diff line change
Expand Up @@ -884,16 +884,17 @@ PREPARE <replaceable>nom_instruction</replaceable>(integer, integer) AS SELECT $
au PL/SQL.
</para>

<para>
Si le type de données du résultat de l'expression ne correspond pas au type de donnée
de la variable, the value will be coerced as though by an assignment cast
(see <xref linkend="typeconv-query"/>). If no assignment cast is known
for the pair of data types involved, the <application>PL/pgSQL</application>
interpreter will attempt to convert the result value textually, that is
by applying the result type's output function followed by the variable
type's input function. Note that this could result in run-time errors
generated by the input function, if the string form of the result value
is not acceptable to the input function.
<para> Si le type de données du résultat de l'expression ne
correspond pas au type de donnée de la variable, la valeur sera
convertie via une conversion d'affectation (cf <xref
linkend="typeconv-query" />. Si aucune conversion
d'affectation n'est connue pour les 2 types de données concernée,
l'interpréteur <application>PL/pgSQL</application> tentera de
convertir le résultat textuellement, c'est à dire en appliquant
successivement la fonction de sortie du type résultat puis la
fonction d'entrée du type de la variable. Notez que la fonction
d'entrée peut générer des erreurs d'exécution si la chaîne passée
en paramètre n'est pas acceptable pour le type de la variable.
</para>

<para>
Expand Down Expand Up @@ -1232,22 +1233,24 @@ EXECUTE 'SELECT count(*) FROM '
INTO c
USING utilisateur_verifie, date_verifiee;
</programlisting>
A cleaner approach is to use <function>format()</function>'s <literal>%I</literal>
specification for table or column names (strings separated by a
newline are concatenated):
<programlisting>
EXECUTE format('SELECT count(*) FROM %I '
'WHERE inserted_by = $1 AND inserted &lt;= $2', tabname)
INTO c
USING checked_user, checked_date;
</programlisting>
Une autre restriction sur les symboles de paramètres est qu'ils ne marchent
que dans les commandes <command>SELECT</command>, <command>INSERT</command>,
<command>UPDATE</command> et <command>DELETE</command>. Dans les autres
types d'instructions (appellés de manière générique commandes utilitaires),
vous devez insérer les valeurs sous forme de texte même si ce ne sont
que des données.
</para>
Une meilleure solution est d'utiliser la spécification de formatage
<literal>%I</literal> de la fonction <function>format()</function>
pour les noms de tables ou de colonnes (les chaînes de caractères
séparées par un retour à la ligne sont concaténées):
<programlisting>
EXECUTE format('SELECT count(*) FROM %I '
'WHERE insere_par = $1 AND insere &lt;= $2', matable)
INTO c
USING utilisateur_verifie, date_verifiee;
</programlisting>
Une autre restriction sur les symboles de paramètres est qu'ils ne
fonctionnent que dans les commandes <command>SELECT</command>,
<command>INSERT</command>, <command>UPDATE</command> et
<command>DELETE</command>. Dans les autres types d'instructions
(appellés de manière générique commandes utilitaires), vous devez
insérer les valeurs sous forme de texte même si ce ne sont que des
données.
</para>

<para>
Un <command>EXECUTE</command> avec une chaîne de commande constante et des
Expand Down Expand Up @@ -1318,15 +1321,18 @@ EXECUTE format('SELECT count(*) FROM %I '
</para>

<para>
Dynamic values require careful handling since they might contain
quote characters.
An example using <function>format()</function> (this assumes that you are
dollar quoting the function body so quote marks need not be doubled):
<programlisting>
EXECUTE format('UPDATE tbl SET %I = $1 '
'WHERE key = $2', colname) USING newvalue, keyvalue;
</programlisting>
It is also possible to call the quoting functions directly:
Les valeurs dynamiques qui sont à insérer dans la requête
construite requièrent une attention spéciale car elles pourraient
elles-même contenir des guillemets. Un exemple utilisant la fonction
<function>format()</function> (ceci suppose que vous utilisiez les
guillemets dollar pour la fonction dans sa globalité, dans ce cas
les guillemets n'ont pas besoin d'être doublés)&nbsp;:
<programlisting>
EXECUTE format('UPDATE table SET %I = $1 '
'WHERE clef = $2', nom_colonne) USING nouvelle_valeur, valeur_clef;
</programlisting>
Il est également possible d'appeler explicitement les fonctions
d'échappement:
<programlisting>EXECUTE 'UPDATE tbl SET '
|| quote_ident(nom_colonne)
|| ' = '
Expand Down Expand Up @@ -1418,20 +1424,21 @@ EXECUTE 'UPDATE tbl SET '
sécurité en utilisant la fonction <function>format</function> (voir
<xref linkend="functions-string"/>). Par exemple&nbsp;:
<programlisting>
EXECUTE format('UPDATE tbl SET %I = %L '
'WHERE key = %L', colname, newvalue, keyvalue);
EXECUTE format('UPDATE matable SET %I = %L '
'WHERE clef = %L', nom_colonne, nouvelle_valeur, valeur_clef);
</programlisting>
<literal>%I</literal> is equivalent to <function>quote_ident</function>, and
<literal>%L</literal> is equivalent to <function>quote_nullable</function>.
<literal>%I</literal> est équivalent à <function>quote_ident</function>, et
<literal>%L</literal> est équivalent à <function>quote_nullable</function>.
La fonction <function>format</function> peut être utilisée avec la
clause <literal>USING</literal>&nbsp;:
<programlisting>
EXECUTE format('UPDATE tbl SET %I = $1 WHERE cle = $2', nom_colonne)
USING nouvellevaleur, clevaleur;
</programlisting>
This form is better because the variables are handled in their native
data type format, rather than unconditionally converting them to
text and quoting them via <literal>%L</literal>. It is also more efficient.
Cette forme est meilleure car les variables sont traitées
dans le format natif à leur type plutôt que de les convertir
inconditionnellement en texte et de les échapper via le spécifieur
de format <literal>%L</literal>. C'est également plus performant.
</para>

</para>
Expand Down Expand Up @@ -2361,9 +2368,9 @@ BEGIN

-- À présent vues_mat contient un enregistrement de cs_vues_materialisees

RAISE NOTICE 'Rafraichissement de la vue matérialisée %s ...', quote_ident(mviews.mv_name);
EXECUTE format('TRUNCATE TABLE %I', mviews.mv_name);
EXECUTE format('INSERT INTO %I %s', mviews.mv_name, mviews.mv_query);
RAISE NOTICE 'Rafraichissement de la vue matérialisée %s ...', quote_ident(mviews.mv_name);
EXECUTE format('TRUNCATE TABLE %I', vues_mat.vm_nom);
EXECUTE format('INSERT INTO %I %s', vues_mat.vm_nom, vues_mat.vm_nom);
END LOOP;

RAISE NOTICE 'Fin du rafraichissement des vues matérialisées.';
Expand Down Expand Up @@ -2623,11 +2630,11 @@ END;
<title>Exceptions avec <command>UPDATE</command>/<command>INSERT</command></title>
<para>
Cet exemple utilise un gestionnaire d'exceptions pour réaliser soit un
<command>UPDATE</command> soit un <command>INSERT</command>, comme approprié. It is
recommended that applications use <command>INSERT</command> with
<literal>ON CONFLICT DO UPDATE</literal> rather than actually using
this pattern. This example serves primarily to illustrate use of
<application>PL/pgSQL</application> control flow structures&nbsp;:
<command>UPDATE</command> soit un <command>INSERT</command>, comme approprié.
Il est recommandé d'utiliser la commande <command>INSERT<command>
avec la clause <literal>ON CONFLICT DO UPDATE</literal> plutôt
que cette logique. Cet exemple ne sert qu'à illustrer l'usage des
structures de contrôle de <application>PL/pgSQL</application>&nbsp;:

<programlisting>CREATE TABLE base (a INT PRIMARY KEY, b TEXT);

Expand Down Expand Up @@ -2992,12 +2999,13 @@ CONTEXT: PL/pgSQL function fonction_externe() line 3 at RETURN

<para>
Exemple&nbsp;:
<programlisting>+OPEN curs1 FOR EXECUTE format('SELECT * FROM %I WHERE col1 = $1',tabname) USING keyvalue;
<programlisting>OPEN curs1 FOR EXECUTE format('SELECT * FROM %I WHERE nom_colonne = $1', ma_table) USING valeur_clef;
</programlisting>
In this example, the table name is inserted into the query via
<function>format()</function>. The comparison value for <literal>col1</literal>
is inserted via a <literal>USING</literal> parameter, so it needs
no quoting.
Dans cet exemple, le nom de la table est inséré dans la requête
via la fonction <function>format()</format>. La valeur de la colonne
<literal>nom_colonne</literal> utilisée pour la comparaison est
insérée via le paramètre <literal>USING</literal>, c'est la raison
pour laquelle elle n'a pas besoin d'être échappée.
</para>
</sect3>

Expand Down Expand Up @@ -3387,11 +3395,11 @@ END LOOP <optional> <replaceable>label</replaceable> </optional>;
<title>Erreurs et messages</title>

<sect2 id="plpgsql-statements-raise">
<title>Reporting Errors and Messages</title>
<title>Rapporter des erreurs et messages</title>

<indexterm>
<primary>RAISE</primary>
<secondary>in PL/pgSQL</secondary>
<secondary>en PL/pgSQL</secondary>
</indexterm>

<indexterm>
Expand Down Expand Up @@ -3433,9 +3441,9 @@ RAISE ;
<literal>%</literal> est remplacé par la représentation de la valeur du
prochain argument. Écrivez <literal>%%</literal> pour saisir un
<literal>%</literal> litéral.
The number of arguments must match the number of <literal>%</literal>
placeholders in the format string, or an error is raised during
the compilation of the function.
Le nombre des arguments doit correspondre au nombre de
<literal>%</literal> dans la chaîne format, sinon une erreur est
levée durant la compilation de la fonction.
</para>

<para>
Expand Down Expand Up @@ -3582,60 +3590,65 @@ RAISE unique_violation USING MESSAGE = 'Duplicate user ID: ' || user_id;
</sect2>

<sect2 id="plpgsql-statements-assert">
<title>Checking Assertions</title>
<title>Vérification d'assertions</title>

<indexterm>
<primary>ASSERT</primary>
<secondary>in PL/pgSQL</secondary>
<secondary>en PL/pgSQL</secondary>
</indexterm>

<indexterm>
<primary>assertions</primary>
<secondary>in PL/pgSQL</secondary>
<secondary>en PL/pgSQL</secondary>
</indexterm>

<indexterm>
<primary><varname>plpgsql.check_asserts</varname> configuration parameter</primary>
<primary><varname>plpgsql.check_asserts</varname> paramètre de configuration</primary>
</indexterm>

<para>
The <command>ASSERT</command> statement is a convenient shorthand for
inserting debugging checks into <application>PL/pgSQL</application>
functions.
L'instruction <command>ASSERT</command> est un moyen pratique
d'insérer dans les fonctions <application>PL/pgSQL</application>
des vérifications d'assertions.

<synopsis>
ASSERT <replaceable class="parameter">condition</replaceable> <optional> , <replaceable class="parameter">message</replaceable> </optional>;
</synopsis>

The <replaceable class="parameter">condition</replaceable> is a Boolean
expression that is expected to always evaluate to true; if it does,
the <command>ASSERT</command> statement does nothing further. If the
result is false or null, then an <literal>ASSERT_FAILURE</literal> exception
is raised. (If an error occurs while evaluating
the <replaceable class="parameter">condition</replaceable>, it is
reported as a normal error.)
La <replaceable class="parameter">condition</replaceable>
est une expression booléenne qui est censée être toujours
vraie. Si c'est le cas l'instruction <command>ASSERT</command>
ne fait rien. Si le résultat est faux ou nul, alors une
exception <literal>ASSERT_FAILURE</literal> est levée (si
une erreur survient lors de l'évaluation de la <replaceable
class="parameter">condition</replaceable>, elle est rapportée
normalement).
</para>

<para>
If the optional <replaceable class="parameter">message</replaceable> is
provided, it is an expression whose result (if not null) replaces the
default error message text <quote>assertion failed</quote>, should
the <replaceable class="parameter">condition</replaceable> fail.
The <replaceable class="parameter">message</replaceable> expression is
not evaluated in the normal case where the assertion succeeds.
Si le <replaceable class="parameter">message</replaceable>
optionnel est fourni, cela doit être une expression dont
le résultat (si non nul) remplacera le message d'erreur par
défaut <quote>assertion failed</quote>, si la <replaceable
class="parameter">condition</replaceable> est fausse. L'expression
<replaceable class="parameter">message</replaceable> n'est pas
évaluée dans le cas normal où l'assertion est vraie.
</para>

<para>
Testing of assertions can be enabled or disabled via the configuration
parameter <literal>plpgsql.check_asserts</literal>, which takes a Boolean
value; the default is <literal>on</literal>. If this parameter
is <literal>off</literal> then <command>ASSERT</command> statements do nothing.
La vérification des assertions peut être activée
ou désactivée via le paramètre de configuration
<literal>plpgsql.check_asserts</literal> qui prend une valeur
booléenne, par défaut à <literal>on</literal>. Si ce
paramètre est à <literal>off</literal> alors l'instruction
<command>ASSERT</command> ne fait rien.
</para>

<para>
Note that <command>ASSERT</command> is meant for detecting program
bugs, not for reporting ordinary error conditions. Use
the <command>RAISE</command> statement, described above, for that.
Notez que l'instruction <command>ASSERT</command> sert à
détecter des erreurs de programmation, pas à rapporter des
erreurs ordinaires. Pour cela veuillez utiliser l'instruction
<command>RAISE</command> décrite ci-dessus.
</para>

</sect2>
Expand Down

0 comments on commit 329dcf0

Please sign in to comment.