<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog d&#039;un développeur multi-support &#187; SQL</title>
	<atom:link href="http://www.oni-ecchi.info/blog/category/sql/feed" rel="self" type="application/rss+xml" />
	<link>http://www.oni-ecchi.info/blog</link>
	<description>[DIM] pour les intimes :)</description>
	<lastBuildDate>Mon, 06 Feb 2012 18:51:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Symfony &amp; Doctrine &amp; schema.yml</title>
		<link>http://www.oni-ecchi.info/blog/decouverte-php/symfony-doctrine-schema-yml.html</link>
		<comments>http://www.oni-ecchi.info/blog/decouverte-php/symfony-doctrine-schema-yml.html#comments</comments>
		<pubDate>Mon, 01 Feb 2010 19:00:35 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Découverte PHP]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[astuce]]></category>
		<category><![CDATA[découverte]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=504</guid>
		<description><![CDATA[J&#8217;espère que vous utilisé Doctrine car ce mini article pourrait vous plaire ! Quand vous débutez un projet, la partie conception BDD et création du fichier yml prennent du temps et on aimerait pouvoir faire tout d&#8217;un coup. Personnellement je fais ma conception sur Workbench puis je repart &#171;&#160;from scratch&#160;&#187; pour faire mon (mes) fichier(s) [...]]]></description>
			<content:encoded><![CDATA[<p>J&#8217;espère que vous utilisé Doctrine car ce mini article pourrait vous plaire ! Quand vous débutez un projet, la partie conception BDD et création du fichier yml prennent du temps et on aimerait pouvoir faire tout d&#8217;un coup.</p>
<p>Personnellement je fais ma conception sur Workbench puis je repart &laquo;&nbsp;from scratch&nbsp;&raquo; pour faire mon (mes) fichier(s) yml. (Oui oui on peut en avoir plusieurs de yml :p). </p>
<p>Quand j&#8217;étais sur Propel J&#8217;avais perdu quelque cheveux quand j&#8217;avais essayé l&#8217;autre méthode (cad de générer le fichier SQL, l&#8217;insérer en base, et laisser faire <a href="http://www.oni-ecchi.info/blog/tag/symfony" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec Symfony">symfony</a> pour du reverse engineirng). Le souci du reverse c&#8217;est que ça produisait trop de code inutile (sur les foreign key par exemple) et au final repasser derrière pour arranger le model m&#8217;avait fait perdre pas mal de temps.</p>
<p>Hors ce soir j&#8217;ai trouvé, je ne sais comment, un plugin pour Workbench pour écrire  le fichier yml directement à partir de celui ci, adieu les étapes &laquo;&nbsp;insertion bdd, reverse&nbsp;&raquo;. Et en plus sur les (mini) tests que j&#8217;ai fait tout à l&#8217;air propre, les conventions doctrines sont respectés, tout est bien indiqué. Il suffit de suivre la marche à suivre suivante : <a href="http://code.google.com/p/mysql-workbench-doctrine-plugin/wiki/WorkbenchPreparationForDoctrinePlugin">http://code.google.com/p/mysql-workbench-doctrine-plugin/wiki/WorkbenchPreparationForDoctrinePlugin</a></p>
<p>Bref, en un mot c&#8217;est bon plugin Workbench bien utile :p</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/decouverte-php/symfony-doctrine-schema-yml.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>APE Project &#8211; Mysql</title>
		<link>http://www.oni-ecchi.info/blog/sql/ape-project-mysql.html</link>
		<comments>http://www.oni-ecchi.info/blog/sql/ape-project-mysql.html#comments</comments>
		<pubDate>Sat, 30 Jan 2010 21:55:27 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[APE Project]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=489</guid>
		<description><![CDATA[Bonjour, j&#8217;ai eu un souci sur APE avec Mysql et comme je suis fier de ma solution je vous la propose : Le souci c&#8217;est quand vous faites une requête SQL qui peut retourner des valeurs null dans vos colonnes, ben ça plante. Vous avez l&#8217;erreur &#171;&#160;segmentation fault&#171;&#160;. Normallement l&#8217;erreur devrait être corriger dans les [...]]]></description>
			<content:encoded><![CDATA[<p>Bonjour, j&#8217;ai eu un souci sur APE avec <a href="http://www.oni-ecchi.info/blog/tag/mysql" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec mysql">Mysql</a> et comme je suis fier de ma solution je vous la propose :</p>
<p>Le souci c&#8217;est quand vous faites une requête <a class="zem_slink" href="http://en.wikipedia.org/wiki/SQL" title="SQL" rel="wikipedia">SQL</a> qui peut retourner des valeurs null dans vos colonnes, ben ça plante. Vous avez l&#8217;erreur &laquo;&nbsp;<a class="zem_slink" href="http://en.wikipedia.org/wiki/Segmentation_fault" title="Segmentation fault" rel="wikipedia">segmentation fault</a>&laquo;&nbsp;. Normallement l&#8217;erreur devrait être corriger dans les prochaines versions d&#8217;APE mais en attendant voici le fix.</p>
<blockquote><p>La fonction IFNULL de Mysql !</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p489code2'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4892"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p489code2"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> IFNULL<span style="color: #66cc66;">&#40;</span>champ1<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">as</span> champ1<span style="color: #66cc66;">,</span> IFNULL<span style="color: #66cc66;">&#40;</span>champ2<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">as</span> champ2 <span style="color: #993333; font-weight: bold;">FROM</span> matable</pre></td></tr></table></div>

</blockquote>
<p>Et ouais, ça suffit à contourner le bug. Vous aurez des 0 au lieu de la valeur null, à vous d&#8217;adapter votre code en fonction !</p>
<p>Simple &amp; court !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/sql/ape-project-mysql.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Mysql] Procédure Stocké</title>
		<link>http://www.oni-ecchi.info/blog/sql/mysql-procedure-stocke.html</link>
		<comments>http://www.oni-ecchi.info/blog/sql/mysql-procedure-stocke.html#comments</comments>
		<pubDate>Tue, 02 Dec 2008 19:29:45 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[procédure stocké]]></category>
		<category><![CDATA[Zend framework]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=91</guid>
		<description><![CDATA[Pour un projet d&#8217;annuaire de Flux RSS, j&#8217;ai du faire en sorte que l&#8217;on puisse importer ses Flux dans l&#8217;annuaire via un fichier XML opml que tout bon agrégateur (google reader, netvibes) fournit. Donc admettons que l&#8217;on a 100 flux RSS à importer il faut pour chaque flux vérifier si le flux n&#8217;existe pas déjà [...]]]></description>
			<content:encoded><![CDATA[<p>Pour un projet d&#8217;annuaire de Flux RSS, j&#8217;ai du faire en sorte que l&#8217;on puisse importer ses Flux dans l&#8217;annuaire via un fichier XML opml que tout bon agrégateur (google reader, netvibes) fournit. Donc admettons que l&#8217;on a 100 flux RSS à importer il faut pour chaque flux vérifier si le flux n&#8217;existe pas déjà sinon le créer en base. Donc il faut prévoir un maximum de 200 requêtes SQL.</p>
<p>Seulement voilà, si on fait les instructions de test d&#8217;existence et d&#8217;insertion au niveau <a href="http://www.oni-ecchi.info/blog/tag/php" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec php">PHP</a>, cela fait 200 aller retour entre <a href="http://www.oni-ecchi.info/blog/tag/php" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec php">PHP</a> et la base <a href="http://www.oni-ecchi.info/blog/tag/mysql" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec mysql">Mysql</a>. Hors ce qui plombe un script c&#8217;est souvent ces aller retour incessants .. Un moyen d&#8217;optimiser ce traitement a été de créer une <a href="http://www.oni-ecchi.info/blog/tag/procedure-stocke" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec procédure stocké">procédure stocké</a> qui prend en paramètre le fichier XML (où plutôt une représentation épuré plus strict), et de faire exécuter les 200 requêtes DANS Mysql. Chouette non ? Plus rapide, plus stable, plus optimisé .. que du bonheur.</p>
<h3>Procédure Stocké en Mysql</h3>
<p>Vous allez rire, mais d&#8217;après mes recherches googlidiennes très peu de personnes font des procédures en Mysql. Cela vient sans doute du fait qu&#8217;elles sont apparru avec mysql 5 et que c&#8217;est encore &laquo;&nbsp;neuf&nbsp;&raquo;.</p>
<p>Tous les exemples que l&#8217;on trouve sur le sujet sont pour SQL serveur PRo, donc du transact-SQL. Et le souci c&#8217;est qu&#8217;il n&#8217;y pas forcement d&#8217;équivalence entre les fonctions transact-SQL et les fonctions mysql. La synthaxe n&#8217;est décidement pas la même.</p>
<h3>Outil utilisé</h3>
<p><a href="http://dev.mysql.com/downloads/gui-tools/5.0.html">Mysql query browser !</a></p>
<p>L&#8217;exemple que je donne n&#8217;est valable qu&#8217;a travers sont interface .. zarb.. m&#8217;enfin c&#8217;est un très bon outil quand même, rien à voir avec un phpMyAdmin tout POURRI !</p>
<h3>Création de la requête</h3>
<p>Voilà la précédure allégé que j&#8217;ai crée (je fais d&#8217;autres test en version un peu plus lourde). Je vais essayer de la commenter au mieux.</p>
<p>La procédure s&#8217;appelle import, elle est dans la base de donné nommé &laquo;&nbsp;Fluxe&nbsp;&raquo; et on l&#8217;appelle et l&#8217;utilise comme ceci</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p91code5'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p915"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p91code5"><pre class="sql" style="font-family:monospace;">call import<span style="color: #66cc66;">&#40;</span>
<span style="color: #ff0000;">&quot;premier flux|http://monsite|http://monsite/fluxrss|description;
deuxieme flix|http://monsite2|http://www.google.fr/bidule.xml|autre description;
troisieme|http://monsite3|http://monsite2/rss.xml|description;&quot;</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>Le premier paramètre est la chaine retravaillé coté PHP qui correspond à chaque ligne de l&#8217;XML, et le deuxième paramètre est le nombre de flux. Une entré se fini via un &laquo;&nbsp;;&nbsp;&raquo; et chaque colonne est séparé via un &nbsp;&raquo; | &laquo;&nbsp;. Bon je sais, mes délimiteurs ne sont pas assez complexe dans cet exemple et cela serait risque de bug si une description ou url comporterait des points virgules et des pipes&#8230;</p>
<p>Voici la requête :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p91code6'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p916"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
</pre></td><td class="code" id="p91code6"><pre class="sql" style="font-family:monospace;">DELIMITER $$  <span style="color: #808080; font-style: italic;">-- pas trop compris l'interet O_o</span>
<span style="color: #993333; font-weight: bold;">DROP</span> PROCEDURE <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> <span style="color: #ff0000;">`fluxe`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`import`</span> $$
<span style="color: #808080; font-style: italic;">-- Supprime la procédure si elle existe (je suis fort en anglais hein ? ^^) </span>
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> DEFINER<span style="color: #66cc66;">=</span><span style="color: #ff0000;">`root`</span>@<span style="color: #ff0000;">`localhost`</span> PROCEDURE <span style="color: #ff0000;">`import`</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">In</span> myCsv Text<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">In</span> nbElement Int<span style="color: #66cc66;">&#41;</span>
<span style="color: #808080; font-style: italic;">-- crée la procédure avec deux paramètres &quot;IN&quot; de type Text et Int. C'est à dire que c'est deux paramètres obligatoires pour exécuter la requête.  </span>
&nbsp;
BEGIN <span style="color: #808080; font-style: italic;">-- Debut de la procédure</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- Declare mes variables correspondant aux colonnes de ma table Flux</span>
DECLARE nom varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>;
DECLARE urlSite varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>;
DECLARE myurlFlux varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>;
DECLARE description text;
DECLARE  ligne_flux VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">-- correspondra à une ligne de Flux</span>
DECLARE cpt int; <span style="color: #808080; font-style: italic;">-- un petit compteur pour faire une jolie boucle While</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">set</span> cpt <span style="color: #66cc66;">=</span> nbElement;  <span style="color: #808080; font-style: italic;">-- / !  Voilà comment on définit une variable SET var = valeur; </span>
&nbsp;
WHILE cpt <span style="color: #66cc66;">&lt;=</span> nbElement <span style="color: #993333; font-weight: bold;">and</span> cpt <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span> do  <span style="color: #808080; font-style: italic;">-- j'aurais pu utiliser une boucle Loop aussi.</span>
&nbsp;
  <span style="color: #993333; font-weight: bold;">select</span> <span style="color: #993333; font-weight: bold;">replace</span><span style="color: #66cc66;">&#40;</span>substring<span style="color: #66cc66;">&#40;</span>substring_index<span style="color: #66cc66;">&#40;</span>myCsv<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">';'</span><span style="color: #66cc66;">,</span> cpt<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> length<span style="color: #66cc66;">&#40;</span>substring_index<span style="color: #66cc66;">&#40;</span>myCsv<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">';'</span><span style="color: #66cc66;">,</span> cpt <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">';'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">as</span> ligne <span style="color: #993333; font-weight: bold;">into</span> ligne_flux;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Outch &quot;KEKECER ?&quot; vous devez vous pausez comme question :)</span>
  <span style="color: #808080; font-style: italic;">-- c'est simple, je découpe le premier paramètre In pour en extraire la 1er ligne trouvé.</span>
  <span style="color: #808080; font-style: italic;">-- Les fonctions appellés ne sont pas du php mais bien du SQL ! Puissant non ?</span>
  <span style="color: #808080; font-style: italic;">-- l'idée de récupèrer la 1er ligne DANS une variable &quot;ligne_flux&quot;, d'où le &quot;select ... INTO variable&quot; </span>
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Parsage de la chaine &quot;ligne_flux&quot; pour en extraire les colonnes, rebelote quoi ..</span>
  <span style="color: #993333; font-weight: bold;">select</span>  <span style="color: #993333; font-weight: bold;">replace</span><span style="color: #66cc66;">&#40;</span>substring<span style="color: #66cc66;">&#40;</span>substring_index<span style="color: #66cc66;">&#40;</span>ligne_flux<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> length<span style="color: #66cc66;">&#40;</span>substring_index<span style="color: #66cc66;">&#40;</span>ligne_flux<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">into</span> nom;
  <span style="color: #993333; font-weight: bold;">select</span>  <span style="color: #993333; font-weight: bold;">replace</span><span style="color: #66cc66;">&#40;</span>substring<span style="color: #66cc66;">&#40;</span>substring_index<span style="color: #66cc66;">&#40;</span>ligne_flux<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> length<span style="color: #66cc66;">&#40;</span>substring_index<span style="color: #66cc66;">&#40;</span>ligne_flux<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">into</span> urlSite;
  <span style="color: #993333; font-weight: bold;">select</span>  <span style="color: #993333; font-weight: bold;">replace</span><span style="color: #66cc66;">&#40;</span>substring<span style="color: #66cc66;">&#40;</span>substring_index<span style="color: #66cc66;">&#40;</span>ligne_flux<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> length<span style="color: #66cc66;">&#40;</span>substring_index<span style="color: #66cc66;">&#40;</span>ligne_flux<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">3</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">into</span> myurlFlux;
  <span style="color: #993333; font-weight: bold;">select</span>  <span style="color: #993333; font-weight: bold;">replace</span><span style="color: #66cc66;">&#40;</span>substring<span style="color: #66cc66;">&#40;</span>substring_index<span style="color: #66cc66;">&#40;</span>ligne_flux<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> length<span style="color: #66cc66;">&#40;</span>substring_index<span style="color: #66cc66;">&#40;</span>ligne_flux<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">into</span> description;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Insertion que si la ligne n'existe pas. Le critère est l'url du flux.</span>
  <span style="color: #993333; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">select</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">from</span> flux <span style="color: #993333; font-weight: bold;">where</span> urlFlux <span style="color: #66cc66;">=</span> myurlFlux<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> THEN
       <span style="color: #993333; font-weight: bold;">insert</span> <span style="color: #993333; font-weight: bold;">into</span> flux <span style="color: #66cc66;">&#40;</span>nom<span style="color: #66cc66;">,</span>urlSite<span style="color: #66cc66;">,</span>urlFlux<span style="color: #66cc66;">,</span>description<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">values</span> <span style="color: #66cc66;">&#40;</span>nom<span style="color: #66cc66;">,</span>urlSite<span style="color: #66cc66;">,</span>myurlFlux<span style="color: #66cc66;">,</span>description<span style="color: #66cc66;">&#41;</span>;
   end <span style="color: #993333; font-weight: bold;">if</span>;
&nbsp;
 <span style="color: #808080; font-style: italic;">-- on décrémente le compteur</span>
 <span style="color: #993333; font-weight: bold;">set</span> cpt <span style="color: #66cc66;">=</span> cpt <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span>;
end while;
&nbsp;
END $$
DELIMITER ;</pre></td></tr></table></div>

<p>Et voilà c&#8217;est fini !</p>
<h3>Lien de référence</h3>
<p>La base :<a href="http://dev.mysql.com/doc/refman/5.0/fr/stored-procedure-syntax.html">http://dev.mysql.com/doc/refman/5.0/fr/stored-procedure-syntax.html</a></p>
<p>les variables : <a href="http://dev.mysql.com/doc/refman/5.0/fr/variables-in-stored-procedures.html">http://dev.mysql.com/doc/refman/5.0/fr/variables-in-stored-procedures.html</a><br />
If, while, case, et tous les contrôles : <a href="http://dev.mysql.com/doc/refman/5.0/fr/flow-control-constructs.html">http://dev.mysql.com/doc/refman/5.0/fr/flow-control-constructs.html</a></p>
<p>Mis à part la documentation officiel, j&#8217;ai rien trouvé d&#8217;autres à me mettre sous la dent ..</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/sql/mysql-procedure-stocke.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

