IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SQL Procédural MySQL Discussion :

Boucle repeat qui s'arrête au premier enregistrement


Sujet :

SQL Procédural MySQL

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Septembre 2009
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2009
    Messages : 5
    Par défaut Boucle repeat qui s'arrête au premier enregistrement
    Bonjour à tous,
    j'essaie depuis des heures de trouver ce qui empêche ma proc. de "tourner rond" et je n'arrive à rien ! le premier curseur est censé être traité et inséré dans une table (préalablement vidée à chaque lancement de la procédure) mais une seule ligne est insérée (1er résultat de la requête) et j'ai bien vérifié le résultat de la requête du dit curseur, je suis censé avoir plus de 20000 enregistrements ! je ne comprends pas !

    Help me please !

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    DROP PROCEDURE IF EXISTS export;
    CREATE PROCEDURE export()
    general: BEGIN
     
    	DECLARE exit_proc INT DEFAULT 0;
       DECLARE userid INT;
       DECLARE useremail CHAR(250);
       DECLARE titlech CHAR(250);
       DECLARE firstname CHAR(250);
       DECLARE lastname CHAR(250);
       DECLARE companych CHAR(250);
       DECLARE address1 CHAR(250);
       DECLARE address2 CHAR(250);
       DECLARE zipch INT;
       DECLARE citych CHAR(250);
       DECLARE countrych CHAR(250);
       DECLARE phone1 CHAR(250);
       DECLARE phone2 CHAR(250);
       DECLARE bdaych CHAR(250);
       DECLARE newsletterch CHAR(250);
       DECLARE lastvisitDatech CHAR(250);
       DECLARE formatmsgid INT DEFAULT 2;
       DECLARE date_bday CHAR(10);
       DECLARE date_lastvisite CHAR(10);
       DECLARE maxcouponval INT DEFAULT 0;
    	DECLARE maxcouponcode CHAR(15) DEFAULT "RAZ-DOLIST";
    	DECLARE maxcoupondate CHAR(10) DEFAULT "01/01/1900";
       DECLARE nbcmd INT DEFAULT 0;
       DECLARE date_cmd CHAR(10);
       DECLARE totalmontantcmd int DEFAULT 0;
       DECLARE orderid INT;
       DECLARE lastdatech CHAR(10);
       DECLARE ordertotal INT DEFAULT 0;
       DECLARE couponcode CHAR(10);
       DECLARE couponvalue INT default 0;
       DECLARE datefincoup CHAR(10);
       DECLARE title INT DEFAULT 2;
       DECLARE countryid INT DEFAULT 1;
       DECLARE familial CHAR(1) default '';
       DECLARE ambiance CHAR(1)  default '';
       DECLARE geeks CHAR(1)  default '';
       DECLARE duo CHAR(1)  default '';
       DECLARE enfants CHAR(1)  default '';
       DECLARE cursorallclients CURSOR FOR SELECT distinct inf.user_id,user_email,title,first_name,last_name,company,address_1,address_2,zip,city,country,phone_1,phone_2,date_format(bday, '%Y-%m-%d') bday,newsletter,date_format(lastvisitDate, '%Y-%m-%d') lastvisitDate From jos_vm_user_info inf,jos_users us Where inf.user_id=us.id and inf.address_type = 'BT' and inf.address_1 <> '' and inf.user_id not in (62,63) and user_email not like '%@espritjeu.com' order by inf.user_id desc;
       DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET exit_proc = 1;
     
    	Truncate exportdolist;
       OPEN cursorallclients;
       REPEAT
    		SET date_bday = '1900-01-01';
          SET formatmsgid = 2;
          SET date_lastvisite = '1900-01-01';
          FETCH cursorallclients into userid,useremail,titlech,firstname,lastname,companych,address1,address2,zipch,citych,countrych,phone1,phone2,bdaych,newsletterch,lastvisitDatech;
          /*formatage titre */
        	if(titlech = 'Mr')then
    			set title = '3';
    		elseif(titlech = 'Mme')then
    			set title = '1';
    		end if;
          /*Formatage Adresse*/
          Set address1 = "";
    		set address1 = replace(address1,"\'", "'");
    		set address1 = replace(address1,"\r", "");
    		set address1 = replace(address1,"\n", "");
    		set address1 = replace(address1,'\"', '"');
    		set address2 = replace(address2,"\'", "'");
    		set address2 = replace(address2,"\r", "");
    		set address2 = replace(address2,"\n", "");
    		set address2 = replace(address2,'\"', '"');
          /*Formatage Pays*/
    		if(countrych = "BEL")then
    			set countryid = "2";
    		elseif(countrych = "SUI")then
    			set countryid = "36";
    		elseif(countrych = "FIN")then
    			set countryid = "32";
    		elseif(countrych = "ROY")then
    			set countryid = "61";
    		end if;
     
          /*format des mails par défaut (2 = html; 1 = texte ; 3 = AOL)*/
          SET formatmsgid = 2;
          IF(LOCATE('aol.', useremail) <> 0)then
    			SET formatmsgid = 3;
    		end if;
    		/*formatage date anniversaire*/
    		IF(bdaych = '0000-00-00' || bdaych = '1930-01-01')then
    			SET date_bday = '1900-01-01';
    		else
    			SET date_bday = bdaych;
    		end if;
    		/*formatage date dernière visite*/
    		if(lastvisitDatech = '0000-00-00')then
    			SET date_lastvisite = '1900-01-01';
    		else
    			SET date_lastvisite = lastvisitDatech;
    		end if;
    		/* recup des commandes validées ou réglées ou expédiées pour chaque client*/
          cmd: BEGIN
       		DECLARE nborder int default 0;
       	  	DECLARE cursorcmd CURSOR FOR SELECT distinct order_id,from_unixtime(cdate, '%Y-%m-%d') lastdate, order_total from jos_vm_orders where user_id = userid and order_status not in ('p','x','r','l') order by cdate asc;
             OPEN cursorcmd;
             SELECT count(order_id) into nborder from jos_vm_orders where user_id = userid and order_status not in ('p','x','r','l') order by cdate asc;
             SET maxcouponval = 0;
       		SET maxcouponcode = "RAZ-DOLIST";
             SET maxcoupondate = "1900-01-01";
          	SET nbcmd = 0;
             SET totalmontantcmd = 0;
          	SET date_cmd = '1900-01-01';
       		REPEAT
                FETCH cursorcmd into orderid,lastdatech,ordertotal;
                SET nbcmd = nbcmd +1;
                SET date_cmd = lastdatech;
                SET totalmontantcmd = totalmontantcmd + ordertotal;
                /*recherche d'un coupon valide correspondant à la commande en cours*/
                SELECT coupon_code,coupon_value,DATE_FORMAT(coupon_datef, '%Y-%m-%d') datef into couponcode,couponvalue,datefincoup FROM jos_vm_coupons 
                      WHERE (coupon_code like concat(orderid,'D%') or coupon_code like concat(orderid,'B%') or coupon_code like concat(orderid,'A%')) and coupon_used = 0 and CURDATE() BETWEEN coupon_dated and coupon_datef;
     
       			      If(couponvalue >= maxcouponval)then
          					SET maxcouponval = round(couponvalue,0);
          					SET maxcouponcode = couponcode;
          					SET maxcoupondate = datefincoup; 
          				End If;
     
             UNTIL nbcmd >= nborder  END REPEAT;
             close cursorcmd;
          END cmd;
     
    		/*classement par type de joueur*/
    		/*Familial*/
    		select distinct "F" into familial from jos_vm_orders where order_id in (
        				select order_id from jos_vm_order_item where product_id in (
          					select product_id from jos_vm_product_category_xref where category_id in (36,19,52,2))) and user_id = userid;
     
    		/*Ambiance*/
    		select distinct "A" into ambiance from jos_vm_orders where order_id in (
        				select order_id from jos_vm_order_item where product_id in (
          					select product_id from jos_vm_product_category_xref where category_id in (40,17,7,8,18,51))) and user_id = userid;
     
    		/*Geeks*/
    		select distinct "G" into geeks from jos_vm_orders where order_id in (
        				select order_id from jos_vm_order_item where product_id in (
          					select product_id from jos_vm_product_category_xref where category_id in (21,3,53))) and user_id = userid;
     
    		/*Duo*/
    		select distinct "D" into duo from jos_vm_orders where order_id in (
        				select order_id from jos_vm_order_item where product_id in (
          					select product_id from jos_vm_product_category_xref where category_id in (13,14,15))) and user_id = userid;
     
    		/*Enfants*/
    		select distinct "E" into enfants from jos_vm_orders where order_id in (
        				select order_id from jos_vm_order_item where product_id in (
          					select product_id from jos_vm_product_category_xref where category_id = "12") ) and user_id = userid;
     
    		/*Tramage de la ligne*/
                    /*set ligne ="Email\tSalutationId\tFirstName\tLastName\tCompany\tAddress 1\tAddress 2\tAddress 3\tZipCode\tCity\tCountryID\tPhone\tFax\tMobile Phone\tMsgFormatId\tSaleMgt\tBirthdate\tCustomDate1\tCustomDate2\tCustomDate3\tCustomStr1\tCustomStr2\tCustomStr3\tCustomStr4\tCustomStr5\tCustomStr6\tCustomStr7\tCustomStr8\tCustomStr9\tCustomStr10\tCustomStr11\tCustomStr12\tCustomStr13\tCustomStr14\tCustomStr15\tCustomStr16\tCustomStr17\tCustomStr18\tCustomStr19\tCustomStr20\tCustomStr21\tCustomStr22\tCustomStr23\tCustomStr24\tCustomStr25\tCustomStr26\tCustomStr27\tCustomStr28\tCustomStr29\tCustomStr30\tCustomInt1\tCustomInt2\tCustomInt3\tCustomInt4\tCustomInt5\tCustomInt6\tCustomInt7\tCustomInt8\tCustomInt9\tCustomInt10\n" ;
                    /*set ligne = $row['user_email'] ."\t". title ."\t". ucfirst($row['first_name']) ."\t". ucfirst($row['last_name']) ."\t".$row['company']."\t".$address1."\t".$address2."\t\t".$row['zip']."\t".ucfirst($row['city'])."\t".$countryid."\t\t\t\t".$formatmsgid."\t1\t".$date_bday."\t".$date_lastvisite."\t".$date_cmd."\t".$maxcoupondate."\t".$row['newsletter']."\t". $maxcouponcode ."\t". $familial ."\t". $ambiance ."\t". $geeks ."\t".$duo."\t".$enfants."\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t". round($maxcouponval,0) ."\t".$nbcmd."\t".round($totalmontantcmd,0)."\t\t\t\t\t\t\t\n";
    		/*sortie en table EsportDolist*/
     
       Insert into exportdolist values(userid,useremail,title,firstname,lastname,companych,address1,address2,'',zipch,citych,countryid,null,null,null,formatmsgid,1,date_bday,date_lastvisite,date_cmd,maxcoupondate,newsletterch,maxcouponcode,familial,ambiance,geeks,duo,enfants,'','','','','','','','','','','','','','','','','','','','','','','',round(maxcouponval,0),nbcmd,round(totalmontantcmd,0),null,null,null,null,null,null,null);
     
    	UNTIL exit_proc END REPEAT;
       CLOSE cursorallclients;
     
    END general

  2. #2
    Membre Expert
    Avatar de ericd69
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2011
    Messages
    1 919
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2011
    Messages : 1 919
    Billets dans le blog
    1
    Par défaut
    Salut,

    Essaye d'utiliser le type bool pour exit_proc déjà, 1 octect c'est mieux que 4 pour un pauvre vrai/faux

    Ensuite, si tu as des curseurs et 1 seul continue handler général, tu dois sauvegarder l'état de la variable qu'il modifie avant d'entrer dans le curseur interne et le restituer en sortie de celui ci sous peine de ne lire que la première ligne du curseur externe et de sortir direct...

    Comme là

    2ème solution tu peux déclarer un handler dans ton begin end, celui de cmd ici, qui modifiera une autre variable bool déclarée avec lui...


    tout bête

  3. #3
    Membre éclairé Avatar de magicbisous-nours
    Inscrit en
    Octobre 2005
    Messages
    277
    Détails du profil
    Informations forums :
    Inscription : Octobre 2005
    Messages : 277
    Par défaut
    Salut je ne sais pas si ça peut aider mais dans les procédures stockées dont j'ai hérité de la maintenance avant chaque repeat la variable qui sert pour le handler (en l'occurrence pour toi exit_proc) était initialisée à 0 ce que je n'ai pas vu avant ton premier repeat... Peut être que pour lui proc_exit vaut 1 tout de suite et il ne passe donc qu'une fois dans ta boucle...

  4. #4
    Futur Membre du Club
    Profil pro
    Inscrit en
    Septembre 2009
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2009
    Messages : 5
    Par défaut
    bonjour et merci pour cette réponse, malheureusement j'ai beau essayer, je n'arrive à rien ! j'ai modifié le mode de sortie des boucles, cela fonctionne mieux mai il reste des résultats incohérents, je reviendrais poster dès que j'aurais trouvé la solution.

    merci en tout cas,

    bon week end

  5. #5
    Membre Expert
    Avatar de ericd69
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2011
    Messages
    1 919
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2011
    Messages : 1 919
    Billets dans le blog
    1
    Par défaut
    salut,

    Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    delimiter |
    DROP PROCEDURE IF EXISTS export;
    CREATE PROCEDURE export()
    BEGIN
     
    	DECLARE exit_proc INT DEFAULT 0;
       DECLARE userid INT;
       DECLARE useremail CHAR(250);
       DECLARE titlech CHAR(250);
       DECLARE firstname CHAR(250);
       DECLARE lastname CHAR(250);
       DECLARE companych CHAR(250);
       DECLARE address1 CHAR(250);
       DECLARE address2 CHAR(250);
       DECLARE zipch INT;
       DECLARE citych CHAR(250);
       DECLARE countrych CHAR(250);
       DECLARE phone1 CHAR(250);
       DECLARE phone2 CHAR(250);
       DECLARE bdaych CHAR(250);
       DECLARE newsletterch CHAR(250);
       DECLARE lastvisitDatech CHAR(250);
       DECLARE formatmsgid INT DEFAULT 2;
       DECLARE date_bday CHAR(10);
       DECLARE date_lastvisite CHAR(10);
       DECLARE maxcouponval INT DEFAULT 0;
    	DECLARE maxcouponcode CHAR(15) DEFAULT "RAZ-DOLIST";
    	DECLARE maxcoupondate CHAR(10) DEFAULT "01/01/1900";
       DECLARE nbcmd INT DEFAULT 0;
       DECLARE date_cmd CHAR(10);
       DECLARE totalmontantcmd int DEFAULT 0;
       DECLARE orderid INT;
       DECLARE lastdatech CHAR(10);
       DECLARE ordertotal INT DEFAULT 0;
       DECLARE couponcode CHAR(10);
       DECLARE couponvalue INT DEFAULT 0;
       DECLARE datefincoup CHAR(10);
       DECLARE title INT DEFAULT 2;
       DECLARE countryid INT DEFAULT 1;
       DECLARE familial CHAR(1) DEFAULT '';
       DECLARE ambiance CHAR(1)  DEFAULT '';
       DECLARE geeks CHAR(1)  DEFAULT '';
       DECLARE duo CHAR(1)  DEFAULT '';
       DECLARE enfants CHAR(1)  DEFAULT '';
       DECLARE cursorallclients CURSOR FOR SELECT DISTINCT inf.user_id,user_email,title,first_name,last_name,company,address_1,address_2,zip,city,country,phone_1,phone_2,date_format(bday, '%Y-%m-%d') bday,newsletter,date_format(lastvisitDate, '%Y-%m-%d') lastvisitDate FROM jos_vm_user_info inf,jos_users us WHERE inf.user_id=us.id AND inf.address_type = 'BT' AND inf.address_1 <> '' AND inf.user_id NOT IN (62,63) AND user_email NOT LIKE '%@espritjeu.com' ORDER BY inf.user_id DESC;
       DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET exit_proc = 1;
     
    	TRUNCATE exportdolist;
       OPEN cursorallclients;
       REPEAT
    		SET date_bday = '1900-01-01';
          SET formatmsgid = 2;
          SET date_lastvisite = '1900-01-01';
          FETCH cursorallclients INTO userid,useremail,titlech,firstname,lastname,companych,address1,address2,zipch,citych,countrych,phone1,phone2,bdaych,newsletterch,lastvisitDatech;
          /*formatage titre */
        	IF(titlech = 'Mr')then
    			SET title = '3';
    		elseif(titlech = 'Mme')then
    			SET title = '1';
    		end IF;
          /*Formatage Adresse*/
          SET address1 = "";
    		SET address1 = REPLACE(address1,"\'", "'");
    		SET address1 = REPLACE(address1,"\r", "");
    		SET address1 = REPLACE(address1,"\n", "");
    		SET address1 = REPLACE(address1,'\"', '"');
    		SET address2 = REPLACE(address2,"\'", "'");
    		SET address2 = REPLACE(address2,"\r", "");
    		SET address2 = REPLACE(address2,"\n", "");
    		SET address2 = REPLACE(address2,'\"', '"');
          /*Formatage Pays*/
    		IF(countrych = "BEL")then
    			SET countryid = "2";
    		elseif(countrych = "SUI")then
    			SET countryid = "36";
    		elseif(countrych = "FIN")then
    			SET countryid = "32";
    		elseif(countrych = "ROY")then
    			SET countryid = "61";
    		end IF;
     
          /*format des mails par défaut (2 = html; 1 = texte ; 3 = AOL)*/
          SET formatmsgid = 2;
          IF(LOCATE('aol.', useremail) <> 0)then
    			SET formatmsgid = 3;
    		end IF;
    		/*formatage date anniversaire*/
    		IF(bdaych = '0000-00-00' || bdaych = '1930-01-01')then
    			SET date_bday = '1900-01-01';
    		else
    			SET date_bday = bdaych;
    		end IF;
    		/*formatage date dernière visite*/
    		IF(lastvisitDatech = '0000-00-00')then
    			SET date_lastvisite = '1900-01-01';
    		else
    			SET date_lastvisite = lastvisitDatech;
    		end IF;
    		/* recup des commandes validées ou réglées ou expédiées pour chaque client*/
          cmd: BEGIN
          	DECLARE exit_cmd bool default 0;
       		DECLARE nborder int DEFAULT 0;
       	  	DECLARE cursorcmd CURSOR FOR SELECT DISTINCT order_id,from_unixtime(cdate, '%Y-%m-%d') lastdate, order_total FROM jos_vm_orders WHERE user_id = userid AND order_status NOT IN ('p','x','r','l') ORDER BY cdate ASC;
       	  	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET exit_cmd = 1;
             OPEN cursorcmd;
             SELECT count(order_id) INTO nborder FROM jos_vm_orders WHERE user_id = userid AND order_status NOT IN ('p','x','r','l') ORDER BY cdate ASC;
             SET maxcouponval = 0;
       		SET maxcouponcode = "RAZ-DOLIST";
             SET maxcoupondate = "1900-01-01";
          	SET nbcmd = 0;
             SET totalmontantcmd = 0;
          	SET date_cmd = '1900-01-01';
       		REPEAT
                FETCH cursorcmd INTO orderid,lastdatech,ordertotal;
                SET nbcmd = nbcmd +1;
                SET date_cmd = lastdatech;
                SET totalmontantcmd = totalmontantcmd + ordertotal;
                /*recherche d'un coupon valide correspondant à la commande en cours*/
                SELECT coupon_code,coupon_value,DATE_FORMAT(coupon_datef, '%Y-%m-%d') datef INTO couponcode,couponvalue,datefincoup FROM jos_vm_coupons 
                      WHERE (coupon_code LIKE concat(orderid,'D%') OR coupon_code LIKE concat(orderid,'B%') OR coupon_code LIKE concat(orderid,'A%')) AND coupon_used = 0 AND CURDATE() BETWEEN coupon_dated AND coupon_datef;
     
       			      IF(couponvalue >= maxcouponval)then
          					SET maxcouponval = round(couponvalue,0);
          					SET maxcouponcode = couponcode;
          					SET maxcoupondate = datefincoup; 
          				End IF;
     
             UNTIL nbcmd >= nborder  END REPEAT;
             close cursorcmd;
          END cmd;
     
    		/*classement par type de joueur*/
    		/*Familial*/
    		SELECT DISTINCT "F" INTO familial FROM jos_vm_orders WHERE order_id IN (
        				SELECT order_id FROM jos_vm_order_item WHERE product_id IN (
          					SELECT product_id FROM jos_vm_product_category_xref WHERE category_id IN (36,19,52,2))) AND user_id = userid;
     
    		/*Ambiance*/
    		SELECT DISTINCT "A" INTO ambiance FROM jos_vm_orders WHERE order_id IN (
        				SELECT order_id FROM jos_vm_order_item WHERE product_id IN (
          					SELECT product_id FROM jos_vm_product_category_xref WHERE category_id IN (40,17,7,8,18,51))) AND user_id = userid;
     
    		/*Geeks*/
    		SELECT DISTINCT "G" INTO geeks FROM jos_vm_orders WHERE order_id IN (
        				SELECT order_id FROM jos_vm_order_item WHERE product_id IN (
          					SELECT product_id FROM jos_vm_product_category_xref WHERE category_id IN (21,3,53))) AND user_id = userid;
     
    		/*Duo*/
    		SELECT DISTINCT "D" INTO duo FROM jos_vm_orders WHERE order_id IN (
        				SELECT order_id FROM jos_vm_order_item WHERE product_id IN (
          					SELECT product_id FROM jos_vm_product_category_xref WHERE category_id IN (13,14,15))) AND user_id = userid;
     
    		/*Enfants*/
    		SELECT DISTINCT "E" INTO enfants FROM jos_vm_orders WHERE order_id IN (
        				SELECT order_id FROM jos_vm_order_item WHERE product_id IN (
          					SELECT product_id FROM jos_vm_product_category_xref WHERE category_id = "12") ) AND user_id = userid;
     
    		/*Tramage de la ligne*/
                    /*set ligne ="Email\tSalutationId\tFirstName\tLastName\tCompany\tAddress 1\tAddress 2\tAddress 3\tZipCode\tCity\tCountryID\tPhone\tFax\tMobile Phone\tMsgFormatId\tSaleMgt\tBirthdate\tCustomDate1\tCustomDate2\tCustomDate3\tCustomStr1\tCustomStr2\tCustomStr3\tCustomStr4\tCustomStr5\tCustomStr6\tCustomStr7\tCustomStr8\tCustomStr9\tCustomStr10\tCustomStr11\tCustomStr12\tCustomStr13\tCustomStr14\tCustomStr15\tCustomStr16\tCustomStr17\tCustomStr18\tCustomStr19\tCustomStr20\tCustomStr21\tCustomStr22\tCustomStr23\tCustomStr24\tCustomStr25\tCustomStr26\tCustomStr27\tCustomStr28\tCustomStr29\tCustomStr30\tCustomInt1\tCustomInt2\tCustomInt3\tCustomInt4\tCustomInt5\tCustomInt6\tCustomInt7\tCustomInt8\tCustomInt9\tCustomInt10\n" ;
                    /*set ligne = $row['user_email'] ."\t". title ."\t". ucfirst($row['first_name']) ."\t". ucfirst($row['last_name']) ."\t".$row['company']."\t".$address1."\t".$address2."\t\t".$row['zip']."\t".ucfirst($row['city'])."\t".$countryid."\t\t\t\t".$formatmsgid."\t1\t".$date_bday."\t".$date_lastvisite."\t".$date_cmd."\t".$maxcoupondate."\t".$row['newsletter']."\t". $maxcouponcode ."\t". $familial ."\t". $ambiance ."\t". $geeks ."\t".$duo."\t".$enfants."\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t". round($maxcouponval,0) ."\t".$nbcmd."\t".round($totalmontantcmd,0)."\t\t\t\t\t\t\t\n";
    		/*sortie en table EsportDolist*/
     
       INSERT INTO exportdolist VALUES(userid,useremail,title,firstname,lastname,companych,address1,address2,'',zipch,citych,countryid,NULL,NULL,NULL,formatmsgid,1,date_bday,date_lastvisite,date_cmd,maxcoupondate,newsletterch,maxcouponcode,familial,ambiance,geeks,duo,enfants,'','','','','','','','','','','','','','','','','','','','','','','',round(maxcouponval,0),nbcmd,round(totalmontantcmd,0),NULL,NULL,NULL,NULL,NULL,NULL,NULL);
     
    	UNTIL exit_proc END REPEAT;
       CLOSE cursorallclients;
     
    END|
    delimiter ;
    ça devrait marcher

  6. #6
    Membre éclairé Avatar de magicbisous-nours
    Inscrit en
    Octobre 2005
    Messages
    277
    Détails du profil
    Informations forums :
    Inscription : Octobre 2005
    Messages : 277
    Par défaut
    j'ai le même problème...
    j'ai ajouté une variable pour compter le nombre de passage dans la boucle et cela vaut toujours 1...
    voici mon code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    begin	
     
    	declare vAmount float;
    	declare vUnitPriceMorningBegin float;
    	declare vUnitPriceMorningEnd float;
    	declare vUnitPriceAfternoonBegin float;
    	declare vUnitPriceAftenoonEnd float;
    	declare vUnitPriceAllTimes float;
     
        declare vAmountMorningBegin float;
        declare vAmountMorningEnd float;
        declare vAmountAfternoonBegin float;
        declare vAmountAfternoonEnd float;
        declare vAmountAllTimes float;
     
    	declare vQuantityMorningBegin integer;
    	declare vQuantityMorningEnd integer;
    	declare vQuantityAfternoonBegin integer;
    	declare vQuantityAfternoonEnd integer;
    	declare vQuantityAllTimes integer;
     
        declare vScheduleMorningBegin integer;
        declare vScheduleMorningEnd integer;
        declare vScheduleAfternoonBegin integer;
        declare vScheduleAfternoonEnd integer;
     
     
     
    	declare vLabelItem varchar(255);	
     
     
    	-- GBAR - 23/05/2011 - Répercussion de la réduction sur la facturation
     
    	declare vNbJoursInscriptions integer;
     
    	declare vIdSchool integer;
     
    	declare vNbSchoolDiscount integer;
     
    	declare vOsMorningBegin integer;
     
    	declare vOsMorningEnd integer;
     
    	declare vOsAfternoonBegin integer; 
     
    	declare vOsAfternoonEnd integer;
     
    	declare vCsDate date;
     
    	declare vNbJoursOuvres integer;
     
    	declare vIsDayOff boolean;
     
    	declare vPourcentPresence float;
     
    	declare vPresenceThreshold integer;
     
    	declare vDiscountRatio integer;
     
    	declare vRoundDown boolean;
     
    	declare vMontantReduction float;
     
          declare vFamiliy_quotient float;
     
    	declare done int default 0;
     
    	declare cpt int default 0;
     
    	declare cCompteJoursinscription cursor for select cs_date, os_morning_begin, os_morning_end, os_afternoon_begin, os_afternoon_end from t_calendar_school where cs_date between pFromDate and pThruDate;
     
    	declare continue handler for sqlstate '02000' set done = 1;
     
    	-- Fin GBAR - 23/05/2011 - Répercussion de la réduction sur la facturation
     
     
    	select get_out_school_child_unit_price(pIdChild, 'SCHEDULE_MORNING_BEGIN')    into vUnitPriceMorningBegin;
    	select get_out_school_child_unit_price(pIdChild, 'SCHEDULE_MORNING_END')      into vUnitPriceMorningEnd;
    	select get_out_school_child_unit_price(pIdChild, 'SCHEDULE_AFTERNOON_BEGIN')  into vUnitPriceAfternoonBegin;
    	select get_out_school_child_unit_price(pIdChild, 'SCHEDULE_AFTERNOON_END')    into vUnitPriceAftenoonEnd;
    	select get_out_school_child_unit_price(pIdChild, 'SCHEDULE_ALL_TIMES')        into vUnitPriceAllTimes;
     
     
     
     
      select count(id_enum_hour_type) into vScheduleMorningBegin
        from t_out_school_schedule, t_out_school, t_child
       where t_child.id_child = pIdChild
         and t_child.id_school = t_out_school.id_school
         and t_out_school_schedule.id_out_school = t_out_school.id_out_school
         and t_out_school_schedule.id_enum_hour_type = "SCHEDULE_MORNING_BEGIN";
     
      select count(id_enum_hour_type) into vScheduleMorningEnd
        from t_out_school_schedule, t_out_school, t_child
       where t_child.id_child = pIdChild
         and t_child.id_school = t_out_school.id_school
         and t_out_school_schedule.id_out_school = t_out_school.id_out_school
         and t_out_school_schedule.id_enum_hour_type = "SCHEDULE_MORNING_END";
     
      select count(id_enum_hour_type) into vScheduleAfternoonBegin
        from t_out_school_schedule, t_out_school, t_child
       where t_child.id_child = pIdChild
         and t_child.id_school = t_out_school.id_school
         and t_out_school_schedule.id_out_school = t_out_school.id_out_school
         and t_out_school_schedule.id_enum_hour_type = "SCHEDULE_AFTERNOON_BEGIN";
     
      select count(id_enum_hour_type) into vScheduleAfternoonEnd
        from t_out_school_schedule, t_out_school, t_child
       where t_child.id_child = pIdChild
         and t_child.id_school = t_out_school.id_school
         and t_out_school_schedule.id_out_school = t_out_school.id_out_school
         and t_out_school_schedule.id_enum_hour_type = "SCHEDULE_AFTERNOON_END";
     
      if (vUnitPriceAllTimes = -1) then
     
     
        set vQuantityAllTimes = 0;
        if (vUnitPriceMorningBegin <> -1) then
          select count(cs_date) into vQuantityMorningBegin
          from t_calendar_school
          where id_child = pIdChild and cs_date between pFromDate and pThruDate and
            os_morning_begin = '1' and os_unsubscr_morning_begin = '0'
            and cs_date not in (
              select csu_date
              from  t_calendar_school_urgency
              where os_morning_begin = '1' and
                    id_school = (select id_school from t_child where t_child.id_child = pIdChild) and 
              csu_date between pFromDate and pThruDate
            );
        else
          set vQuantityMorningBegin = 0;
        end if;
        if (vUnitPriceMorningEnd <> -1) then
     
          select count(cs_date) into vQuantityMorningEnd
          from t_calendar_school
          where id_child = pIdChild and cs_date between pFromDate and pThruDate and
            os_morning_end = '1' and os_unsubscr_morning_end = '0'
            and (sm_lunch = '0' or sm_unsubscr_lunch = '1')
            and cs_date not in (
              select csu_date
              from  t_calendar_school_urgency
              where os_morning_end = '1' and
                    id_school = (select id_school from t_child where t_child.id_child = pIdChild) and
              csu_date between pFromDate and pThruDate
            );
        else
          set vQuantityMorningEnd = 0;
        end if;
     
        if (vUnitPriceAfternoonBegin <> -1) then
     
          select count(cs_date) into vQuantityAfternoonBegin
          from t_calendar_school
          where id_child = pIdChild and cs_date between pFromDate and pThruDate and
            os_afternoon_begin = '1' and os_unsubscr_afternoon_begin = '0'
            and (sm_lunch = '0' or sm_unsubscr_lunch = '1')
            and cs_date not in (
              select csu_date
              from  t_calendar_school_urgency
              where os_afternoon_begin = '1' and
                    id_school = (select id_school from t_child where t_child.id_child = pIdChild) and
              csu_date between pFromDate and pThruDate
            );
        else
          set vQuantityAfternoonBegin = 0;
        end if;
     
        if (vUnitPriceAftenoonEnd <> -1) then
     
          select count(cs_date) into vQuantityAfternoonEnd
          from t_calendar_school
          where id_child = pIdChild and cs_date between pFromDate and pThruDate and
            os_afternoon_end = '1' and os_unsubscr_afternoon_end = '0'
            and cs_date not in (
              select csu_date
              from  t_calendar_school_urgency
              where os_afternoon_end = '1' and
                    id_school = (select id_school from t_child where t_child.id_child = pIdChild) and  
              csu_date between pFromDate and pThruDate
            );
        else
          set vQuantityAfternoonEnd = 0;
        end if;
     
     
      else
     
     
        if (vUnitPriceMorningBegin = -1 and
            vUnitPriceMorningEnd = -1 and
            vUnitPriceAfternoonBegin = -1 and
            vUnitPriceAftenoonEnd = -1) then
     
     
          select count(cs_date) into vQuantityAllTimes
            from t_calendar_school
             where id_child = pIdChild and cs_date between pFromDate and pThruDate and
              ((os_morning_begin = '1' and os_unsubscr_morning_begin = '0') or
              (os_morning_end = '1' and os_unsubscr_morning_end = '0' and (sm_lunch = '0' or sm_unsubscr_lunch = '1')) or
              (os_afternoon_begin = '1' and os_unsubscr_afternoon_begin = '0' and (sm_lunch = '0' or sm_unsubscr_lunch = '1')) or
              (os_afternoon_end = '1' and os_unsubscr_afternoon_end = '0'))
              and cs_date not in (
                select csu_date
                from  t_calendar_school_urgency
                where (os_morning_end = '1' or  os_morning_begin = '1' or os_afternoon_begin = '1' or os_afternoon_end = '1') and
                      id_school = (select id_school from t_child where t_child.id_child = pIdChild) and 
                csu_date between pFromDate and pThruDate
              );
        else 
     
     
     
          select count(cs_date) into vQuantityAllTimes
            from t_calendar_school
             where id_child = pIdChild and cs_date between pFromDate and pThruDate and
              ((os_morning_begin = '1' and os_unsubscr_morning_begin = '0' and vScheduleMorningBegin = 1) or
                 vScheduleMorningBegin = 0) and
              ((os_morning_end = '1' and os_unsubscr_morning_end = '0' and vScheduleMorningEnd = 1 and (sm_lunch = '0' or sm_unsubscr_lunch = '1')) or
                 vScheduleMorningEnd = 0) and
              ((os_afternoon_begin = '1' and os_unsubscr_afternoon_begin = '0' and vScheduleAfternoonBegin = 1 and (sm_lunch = '0' or sm_unsubscr_lunch = '1')) or
                 vScheduleAfternoonBegin = 0) and
              ((os_afternoon_end = '1' and os_unsubscr_afternoon_end = '0' and vScheduleAfternoonEnd = 1) or
                 vScheduleAfternoonEnd = 0)
              and cs_date not in (
                select csu_date
                from  t_calendar_school_urgency
                where (os_morning_end = '1' or  os_morning_begin = '1' or os_afternoon_begin = '1' or os_afternoon_end = '1') and
                      id_school = (select id_school from t_child where t_child.id_child = pIdChild) and 
                csu_date between pFromDate and pThruDate
              );
     
     
          select count(cs_date) into vQuantityMorningBegin
            from t_calendar_school
             where id_child = pIdChild and cs_date between pFromDate and pThruDate and
              (os_morning_begin = '1' and os_unsubscr_morning_begin = '0' and vScheduleMorningBegin = 1)
              and
              (((os_morning_end = '0' or os_unsubscr_morning_end = '1') and vScheduleMorningEnd = 1)
               or
              ((os_afternoon_begin = '0' or os_unsubscr_afternoon_begin = '1') and vScheduleAfternoonBegin = 1) 
              or
              ((os_afternoon_end = '0' or os_unsubscr_afternoon_end = '1') and vScheduleAfternoonEnd = 1))
              and cs_date not in (
                select csu_date
                from  t_calendar_school_urgency
                where os_morning_begin = '1' and 
                      id_school = (select id_school from t_child where t_child.id_child = pIdChild) and 
                csu_date between pFromDate and pThruDate
              );
     
     
          select count(cs_date) into vQuantityMorningEnd
            from t_calendar_school
             where id_child = pIdChild and cs_date between pFromDate and pThruDate and
              (os_morning_end = '1' and os_unsubscr_morning_end = '0' and vUnitPriceMorningEnd <> -1)
              and
              (((os_morning_begin = '0' or os_unsubscr_morning_begin = '1') and vUnitPriceMorningBegin <> -1)
               or
              ((os_afternoon_begin = '0' or os_unsubscr_afternoon_begin = '1') and vUnitPriceAfternoonBegin <> -1) 
              or
              ((os_afternoon_end = '0' or os_unsubscr_afternoon_end = '1') and vUnitPriceAftenoonEnd <> -1))
              and (sm_lunch = '0' or sm_unsubscr_lunch = '1')
              and cs_date not in (
                select csu_date
                from  t_calendar_school_urgency
                where os_morning_begin = '1' and 
                      id_school = (select id_school from t_child where t_child.id_child = pIdChild) and 
                csu_date between pFromDate and pThruDate
              );
     
     
          select count(cs_date) into vQuantityAfternoonBegin
            from t_calendar_school
             where id_child = pIdChild and cs_date between pFromDate and pThruDate and
              (os_afternoon_begin = '1' and os_unsubscr_afternoon_begin = '0' and vUnitPriceAfternoonBegin <> -1)
              and
              (((os_morning_begin = '0' or os_unsubscr_morning_begin = '1') and vUnitPriceMorningBegin <> -1)
               or
              ((os_morning_end = '0' or os_unsubscr_morning_end = '1') and vUnitPriceMorningEnd <> -1)
              or
              ((os_afternoon_end = '0' or os_unsubscr_afternoon_end = '1') and vUnitPriceAftenoonEnd <> -1))
              and (sm_lunch = '0' or sm_unsubscr_lunch = '1')
              and cs_date not in (
                select csu_date
                from  t_calendar_school_urgency
                where os_morning_begin = '1' and 
                      id_school = (select id_school from t_child where t_child.id_child = pIdChild) and 
                csu_date between pFromDate and pThruDate
              );
     
     
          select count(cs_date) into vQuantityAfternoonEnd
            from t_calendar_school
             where id_child = pIdChild and cs_date between pFromDate and pThruDate and
              (os_afternoon_end = '1' and os_unsubscr_afternoon_end = '0' and vUnitPriceAftenoonEnd <> -1)
              and
              (((os_morning_begin = '0' or os_unsubscr_morning_begin = '1') and vUnitPriceMorningBegin <> -1)
               or
              ((os_morning_end = '0' or os_unsubscr_morning_end = '1') and vUnitPriceMorningEnd <> -1)
              or
              ((os_afternoon_begin = '0' or os_unsubscr_afternoon_begin = '1') and vUnitPriceAfternoonBegin <> -1))
              and cs_date not in (
                select csu_date
                from  t_calendar_school_urgency
                where os_morning_begin = '1' and 
                      id_school = (select id_school from t_child where t_child.id_child = pIdChild) and 
                csu_date between pFromDate and pThruDate
              );
     
        end if;
     
     
      end if;
     
      set vAmountMorningBegin = vQuantityMorningBegin * vUnitPriceMorningBegin;
      set vAmountMorningEnd = vQuantityMorningEnd * vUnitPriceMorningEnd;
      set vAmountAfternoonBegin = vQuantityAfternoonBegin * vUnitPriceAfternoonBegin;
      set vAmountAfternoonEnd = vQuantityAfternoonEnd * vUnitPriceAftenoonEnd;
      set vAmountAllTimes = vQuantityAllTimes * vUnitPriceAllTimes;
     
     
      set vAmount = 0;
      if ( vAmountMorningBegin is not null ) then
        set vAmount = vAmount + vAmountMorningBegin;
      end if;
      if ( vAmountMorningEnd is not null ) then
        set vAmount = vAmount + vAmountMorningEnd;
      end if;
      if ( vAmountAfternoonBegin is not null ) then
        set vAmount = vAmount + vAmountAfternoonBegin;
      end if;
      if ( vAmountAfternoonEnd is not null ) then
        set vAmount = vAmount + vAmountAfternoonEnd;
      end if;
      if ( vAmountAllTimes is not null ) then
        set vAmount = vAmount + vAmountAllTimes;
      end if;
     
     
      -- GBAR - 23/05/2011 - Répercussion de la réduction sur la facturation 
     
      call debug(concat("On rentre dans la partie de la réduction. id_child : ", pIdChild));
     
      select id_school
     
      into   vIdSchool
     
      from   t_child
     
      where  id_child = pIdChild;
     
      call debug(concat("id_school : ", vIdSchool));
     
     
     
      select familiy_quotient
     
      into vFamiliy_quotient
     
      from t_family_account, t_child
     
      where t_child.id_family_account = t_family_account.id_family_account
     
      and t_child.id_child = pIdChild; 
     
      call debug(concat("vFamiliy_quotient : ", vFamiliy_quotient));
     
     
      select count(id_school)
     
      into   vNbSchoolDiscount
     
      from   t_out_school_discount
     
      where  id_school = vIdSchool
     
      and    fq_min <= vFamiliy_quotient
     
      and    fq_max > vFamiliy_quotient;
     
      call debug(concat("vNbSchoolDiscount : ", vNbSchoolDiscount));
     
     
     
     
     
      if (vNbSchoolDiscount > 0) then
     
        insert into t_proc_stock_debug (message) values ("Il y a une réduction possible");
     
     
     
        select presence_threshold, discount_ratio, round_down
     
        into   vPresenceThreshold, vDiscountRatio, vRoundDown
     
        from   t_out_school_discount
     
        where  id_school = vIdSchool
     
        and    fq_min <= vFamiliy_quotient
     
        and    fq_max > vFamiliy_quotient;
     
        call debug(concat("vPresenceThreshold : ", vPresenceThreshold));
     
        call debug(concat("vDiscountRatio : ", vDiscountRatio));
     
        call debug(concat("vRoundDown : ", vRoundDown));
     
     
     
        set vDiscountRatio = vDiscountRatio / 100;
     
        call debug(concat("vDiscountRatio : ", vDiscountRatio));
     
     
     
        set vNbJoursInscriptions = 0;
     
        open cCompteJoursinscription;
     
        repeat
     
            fetch cCompteJoursinscription into vCsDate, vOsMorningBegin, vOsMorningEnd, vOsAfternoonBegin, vOsAfternoonEnd;
     
    	  set cpt = cpt + 1;
     
            if (vOsMorningBegin = 1 or vOsMorningEnd = 1 or
     
                vOsAfternoonBegin = 1 or vOsAfternoonEnd = 1) then
     
                set vNbJoursInscriptions = vNbJoursInscriptions +1;
     
            end if;
     
            set vNbJoursOuvres = 0;
     
            set vIsDayOff = is_day_off(vCsDate);
     
            if (vIsDayOff = false) then
     
                set vNbJoursOuvres = vNbJoursOuvres +1;
     
            end if;
     
    	  set vPourcentPresence = (vNbJoursInscriptions/vNbJoursOuvres)*100;
     
            if (vPourcentPresence >= vPresenceThreshold) then
     
                if (vRoundDown = true) then
     
                    set vMontantReduction = floor(vAmount * vDiscountRatio);
     
                else
     
                    set vMontantReduction = ceil(vAmount * vDiscountRatio);
     
                end if;
     
                set vAmount = vAmount - vMontantReduction;
     
            end if;
     
        until done end repeat;
     
        close cCompteJoursinscription;
     
        call debug(concat("vNbJoursInscriptions : ", vNbJoursInscriptions));
     
        call debug(concat("vNbJoursOuvres : ", vNbJoursOuvres));
     
        call debug(concat("vPourcentPresence : ", vPourcentPresence));
     
        call debug(concat("vMontantReduction : ", vMontantReduction));
     
        call debug(concat("cpt : ", cpt));
     
      end if;
     
      -- Fin GBAR - 23/05/2011 - Répercussion de la réduction sur la facturation
     
    	if (pRecord = true) then
     
    		if (pItemAdvance = true) then
    			set vLabelItem = 'LBL_INVOICE_ITEM_ADVANCE';
    		else
    			set vLabelItem = 'LBL_INVOICE_ITEM_PERIOD';
    		end if;
     
        if (vQuantityMorningBegin > 0) then
          set vLabelItem = 'LBL_OUT_SCHOOL_MORNING_BEGIN';	
    		call create_invoice_item(pIdInvoice, pIdChild, 'LBL_OUT_SCHOOL', pItemAdvance, 
            vQuantityMorningBegin, vUnitPriceMorningBegin, vAmountMorningBegin, vLabelItem, false);
        end if;
     
        if (vQuantityMorningEnd > 0) then
          set vLabelItem = 'LBL_OUT_SCHOOL_MORNING_END';	
          call create_invoice_item(pIdInvoice, pIdChild, 'LBL_OUT_SCHOOL', pItemAdvance, 
            vQuantityMorningEnd, vUnitPriceMorningEnd, vAmountMorningEnd, vLabelItem, false);
        end if;
     
        if (vQuantityAfternoonBegin > 0) then
          set vLabelItem = 'LBL_OUT_SCHOOL_AFTERNOON_BEGIN';	
          call create_invoice_item(pIdInvoice, pIdChild, 'LBL_OUT_SCHOOL', pItemAdvance, 
            vQuantityAfternoonBegin, vUnitPriceAfternoonBegin, vAmountAfternoonBegin, vLabelItem, false);
        end if;
     
        if (vQuantityAfternoonEnd > 0) then
          set vLabelItem = 'LBL_OUT_SCHOOL_AFTERNOON_END';	
          call create_invoice_item(pIdInvoice, pIdChild, 'LBL_OUT_SCHOOL', pItemAdvance, 
            vQuantityAfternoonEnd, vUnitPriceAftenoonEnd, vAmountAfternoonEnd, vLabelItem, false);
        end if;
     
        if (vQuantityAllTimes > 0) then
          set vLabelItem = 'LBL_OUT_SCHOOL_ALL_TIMES';	
          call create_invoice_item(pIdInvoice, pIdChild, 'LBL_OUT_SCHOOL', pItemAdvance, 
            vQuantityAllTimes, vUnitPriceAllTimes, vAmountAllTimes, vLabelItem, false);
        end if;
     
     
        -- GBAR - 23/05/2011 - Répercussion de la réduction sur la facturation
     
        if (vNbSchoolDiscount > 0) then
     
             set vLabelItem = 'LBL_OUT_SCHOOL_DISCOUNT';	
     
          call create_invoice_item(pIdInvoice, pIdChild, 'LBL_OUT_SCHOOL', pItemAdvance, 
     
            1, vMontantReduction*-1, vMontantReduction*-1, vLabelItem, false);
     
        end if;
     
        -- Fin GBAR - 23/05/2011 - Répercussion de la réduction sur la facturation
     
    	end if;
    	return vAmount;	
    end
    PS : le curseur n'existait pas avant, il a été créé par mes soins donc le problème peut venir d'ici.

  7. #7
    Membre Expert
    Avatar de ericd69
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2011
    Messages
    1 919
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2011
    Messages : 1 919
    Billets dans le blog
    1
    Par défaut
    c'est une horreur ta procédure... ...539 lignes...

    déjà je vais t'apprendre à bien utiliser un curseur...

    fetch ne garantit jamais que tu récupère des données (si ton select du curseur ne renvoie rien par exemple) donc IL FAUT TOUJOURS TESTER QUE TU AS BIEN UN RETOUR GRACE A LA VARIABLE QUI EST GEREE PAR LE HANDLER CONTINUE:
    Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    declare fini bool default 0;
    declare lit cursor for select......;
    declare continue handler for sqlstate '0200' set fini=1;
    ...
    open lit;
    repeat
    fetch lit into .......;
    if not fini then
    .... traitement en cas de résultat (éventuellement entre begin et end en cas de déclaration de variable ici)
    end if;
    until fini end repeat;
    close lit;
    il faut toujours garantir ce que tu fais car sinon les variables touchées par le fetch ne sont juste pas mise à jour et tu auras un comportement indéterminé si tu les testes

  8. #8
    Membre éclairé Avatar de magicbisous-nours
    Inscrit en
    Octobre 2005
    Messages
    277
    Détails du profil
    Informations forums :
    Inscription : Octobre 2005
    Messages : 277
    Par défaut
    d'accord merci beaucoup pour cette explication qui ne m'était pas naturelle (puisque je viens du monde Oracle dans lequel mes variables sont toujours remplies lors du parcours d'un curseur..)

    Désolé pour l'horreur mais je l'ai récupérée comme ça la procédure (en dehors des blocs délimités par les commentaires qui correspondent à mes modifications ) et j'ai dû la comprendre (ainsi que les 5 ou 6 autres du même style qui sont appelées avant elle)

  9. #9
    Membre Expert
    Avatar de ericd69
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2011
    Messages
    1 919
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2011
    Messages : 1 919
    Billets dans le blog
    1
    Par défaut
    oracle est loin d'être une bonne école car à force de compter sur le sgbd pour penser à tout un tas de détails les gens pondent souvent du code pas si propre et portable que ça... ^^
    c'est comme une variable que tu initialise pas... elle pas null par défaut... null est bien une valeur et un état...

  10. #10
    Membre éclairé Avatar de magicbisous-nours
    Inscrit en
    Octobre 2005
    Messages
    277
    Détails du profil
    Informations forums :
    Inscription : Octobre 2005
    Messages : 277
    Par défaut
    j'ai fait les modifs que tu m'as conseillé :
    Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    [...]
    declare done bool default 0;
    declare cCompteJoursinscription cursor for select cs_date, os_morning_begin, os_morning_end, os_afternoon_begin, os_afternoon_end from t_calendar_school where cs_date between pFromDate and pThruDate;
    declare continue handler for sqlstate '02000' set done = 1;
     
    [...]
     
    repeat
            fetch cCompteJoursinscription into vCsDate, vOsMorningBegin, vOsMorningEnd, vOsAfternoonBegin, vOsAfternoonEnd;
            if not done then
    	      set cpt = cpt + 1;
                if (vOsMorningBegin = 1 or vOsMorningEnd = 1 or
                    vOsAfternoonBegin = 1 or vOsAfternoonEnd = 1) then
                    set vNbJoursInscriptions = vNbJoursInscriptions +1;
                end if;
                set vNbJoursOuvres = 0;
                set vIsDayOff = is_day_off(vCsDate);
                if (vIsDayOff = false) then
                    set vNbJoursOuvres = vNbJoursOuvres +1;
                end if;
    	      set vPourcentPresence = vNbJoursInscriptions/vNbJoursOuvres)*100;
                if (vPourcentPresence >= vPresenceThreshold) then
                    if (vRoundDown = true) then
                        set vMontantReduction = floor(vAmount * vDiscountRatio);
                    else
                        set vMontantReduction = ceil(vAmount * vDiscountRatio);
                    end if;
                    set vAmount = vAmount - vMontantReduction;
                end if;
            else 
                call debug("ton curseur est naze !");
            end if;
        until done end repeat;
    mais là je n'ai plus rien du tout dans ma table de debug (elle est rempli par la procédure debug) même lorsque les appels sont fait avant ou après la boucle...

    PS : la dernière trace de debug (celle dans le else) ne t'es pas destinée mais à moi dans le sens : "t'es trop c*n t'as pas compris ce qu'il t'a dit le monsieur"

    EDIT : si je ne voyais rien c'est que ma requête était mal faite au temps pour moi.... Par contre mon compteur de passages dans la boucle est toujours à 0 et j'ai toujours la trace que mon curseur est naze....

  11. #11
    Membre Expert
    Avatar de ericd69
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2011
    Messages
    1 919
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2011
    Messages : 1 919
    Billets dans le blog
    1
    Par défaut
    question est ce qu'il y aurait pas un truc qui mettrait done à 1 avant de rentrer dans le repeat?

  12. #12
    Membre éclairé Avatar de magicbisous-nours
    Inscrit en
    Octobre 2005
    Messages
    277
    Détails du profil
    Informations forums :
    Inscription : Octobre 2005
    Messages : 277
    Par défaut
    je viens de (re-re-re-re) vérifier et en fait il se trouve que je n'ai pas de données pour cette période... Je teste sur une période où j'ai des données et je te tiens au courant.

    Désolé pour cette erreur de débutant....

  13. #13
    Membre éclairé Avatar de magicbisous-nours
    Inscrit en
    Octobre 2005
    Messages
    277
    Détails du profil
    Informations forums :
    Inscription : Octobre 2005
    Messages : 277
    Par défaut
    bon c'était pas ça non plus...
    j'ai toujours le même problème mais cette fois je suis sûr d'avoir des données
    (j'ai exécuté la requête du curseur en remplaçant les variables par les valeurs retournées lors de la précédente exécution de mon curseur et j'ai bien des données...)

    pour répondre à ta question vu que je ne sais pas ce qui pourrait faire passer done à 1 je ne sais pas...

  14. #14
    Membre Expert
    Avatar de ericd69
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2011
    Messages
    1 919
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2011
    Messages : 1 919
    Billets dans le blog
    1
    Par défaut
    recherche done dans le texte de ta procédure pour voir où il apparait

    pour vérifier ton curseur simple exécute juste la requête pour voir ce qu'elle retourne ^^

  15. #15
    Membre éclairé Avatar de magicbisous-nours
    Inscrit en
    Octobre 2005
    Messages
    277
    Détails du profil
    Informations forums :
    Inscription : Octobre 2005
    Messages : 277
    Par défaut
    Citation Envoyé par ericd69 Voir le message
    recherche done dans le texte de ta procédure pour voir où il apparait

    pour vérifier ton curseur simple exécute juste la requête pour voir ce qu'elle retourne ^^
    pour vérifier le curseur c'est ce que j'ai fait et ça m'a retourné des résultats...
    quant au handler continue done c'est moi qui l'ai déclaré et utilisé donc il n'apparaît que dans mes modifs et donc que dans le parcours du curseur (j'ai re-vérifié)...

  16. #16
    Membre Expert
    Avatar de ericd69
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2011
    Messages
    1 919
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2011
    Messages : 1 919
    Billets dans le blog
    1
    Par défaut
    tu mets bien avant le repeat:
    Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
    open cCompteJoursinscription;
    et après la boucle:
    Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
    close cCompteJoursinscription;

  17. #17
    Membre éclairé Avatar de magicbisous-nours
    Inscrit en
    Octobre 2005
    Messages
    277
    Détails du profil
    Informations forums :
    Inscription : Octobre 2005
    Messages : 277
    Par défaut
    oui
    voilà le code :
    Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    -- déclaration : 
    declare done bool default 0;
    declare cCompteJoursInscription cursor for select cs_date, os_morning_begin, os_morning_end, os_afternoon_begin, os_afternoon_end from t_calendar_school where cs_date between pFromDate and pThruDate;
    declare continue handler for NOT FOUND set done = 1;
     
    -- parcours :
    open cCompteJoursInscription;
        repeat
            fetch cCompteJoursInscription into vCsDate, vOsMorningBegin, vOsMorningEnd, vOsAfternoonBegin, vOsAfternoonEnd;
            if not done then
    	      set cpt = cpt + 1;
                if (vOsMorningBegin = 1 or vOsMorningEnd = 1 or
                    vOsAfternoonBegin = 1 or vOsAfternoonEnd = 1) then
                    set vNbJoursInscriptions = vNbJoursInscriptions +1;
                end if;
                set vNbJoursOuvres = 0;
                set vIsDayOff = is_day_off(vCsDate);
                if (vIsDayOff = false) then
                    set vNbJoursOuvres = vNbJoursOuvres +1;
                end if;
    	      set vPourcentPresence = (vNbJoursInscriptions/vNbJoursOuvres)*100;
                if (vPourcentPresence >= vPresenceThreshold) then
                    if (vRoundDown = true) then
                        set vMontantReduction = floor(vAmount * vDiscountRatio);
                    else
                        set vMontantReduction = ceil(vAmount * vDiscountRatio);
                    end if;
                    set vAmount = vAmount - vMontantReduction;
                end if;
            else 
                call debug("ton curseur est naze !");
            end if;
        until done end repeat;
        close cCompteJoursInscription;

  18. #18
    Membre Expert
    Avatar de ericd69
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2011
    Messages
    1 919
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2011
    Messages : 1 919
    Billets dans le blog
    1
    Par défaut
    mets SQLSTATE '02000' au lieu de not found dans ton gestionnaire plutot

  19. #19
    Membre éclairé Avatar de magicbisous-nours
    Inscrit en
    Octobre 2005
    Messages
    277
    Détails du profil
    Informations forums :
    Inscription : Octobre 2005
    Messages : 277
    Par défaut
    oui NOT FOUND était un essai.... si tu regardes mes bouts de code plus haut c'est SQLSTATE '02000'

  20. #20
    Membre éclairé Avatar de magicbisous-nours
    Inscrit en
    Octobre 2005
    Messages
    277
    Détails du profil
    Informations forums :
    Inscription : Octobre 2005
    Messages : 277
    Par défaut
    sinon il y a un moyen de savoir pourquoi le curseur s'arrête ? (un log, quelque chose ?)

Discussions similaires

  1. For qui sort après le premier enregistrement trouvé
    Par laurent33500 dans le forum Langage
    Réponses: 9
    Dernier message: 18/11/2014, 19h35
  2. Linux, boucle for qui s'arrête : limite mémoire ?
    Par ticad dans le forum Langage
    Réponses: 3
    Dernier message: 18/01/2012, 14h24
  3. [AC-2003] dlookup qui bloque sur le premier enregistrement
    Par chuspyto dans le forum VBA Access
    Réponses: 2
    Dernier message: 14/02/2010, 09h37
  4. boucle qui s'arrête avec firefox
    Par scavenger dans le forum Général JavaScript
    Réponses: 32
    Dernier message: 09/01/2009, 17h51
  5. Boucle avec tempo qui s'arrête a minuit
    Par thedjtony dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 02/04/2008, 23h35

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo