From 0a228c1a01d3fc346d74f0edca9ebb78a38ab6cd Mon Sep 17 00:00:00 2001 From: sparkyx Date: Tue, 30 Oct 2007 18:52:51 +0000 Subject: [PATCH] Fix problem with sequence --- html/central.php | 4 ++-- include/central_inc.php | 8 +++++++- include/constant.php | 2 +- include/modele.inc.php | 6 ++++++ include/postgres.php | 14 +++++++++++++- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/html/central.php b/html/central.php index 457fbed0d..d93e1c803 100644 --- a/html/central.php +++ b/html/central.php @@ -61,9 +61,9 @@ if ( isset ($_POST["central"] )) { if ( $_POST["periode"] != "" ) { $ret=Centralise($cn,$_POST["periode"]); if ($ret==NOERROR) { - echo '

La période '.$_POST["periode"].' est centralisée

'; + echo '

La période '.$_POST["periode"].' est centralisée

'; } else { - echo '

La période '.$_POST["periode"].' n\' a pu être centralisée

'; + echo '

La période '.$_POST["periode"].' n\' a pu être centralisée

'; } } }// if ( isset ($_POST["central"] )) diff --git a/include/central_inc.php b/include/central_inc.php index 80be13925..3e4f17497 100644 --- a/include/central_inc.php +++ b/include/central_inc.php @@ -87,6 +87,12 @@ $sql="insert into centralized( c_j_id, $Res2=ExecSql($p_cn,$sql); $MaxLine=pg_NumRows($Res2); + $jrn_def_id=$row['jrn_def_id']; + /* if seq doesn't exist create it */ + if ( exist_sequence($p_cn,'s_jrn_'.$jr_def_id) == false ) { + create_sequence($p_cn,'s_jrn_'.$jr_def_id); + } + for ($e=0;$e < $MaxLine;$e++) { // each line is updated with a sequence $line=pg_fetch_array($Res2,$e); @@ -94,7 +100,7 @@ $sql="insert into centralized( c_j_id, $sql=sprintf ("update jrn set jr_opid = (select nextval('s_jrn_%d')) where jr_id =%d", - $row['jrn_def_id'], + $jr_def_id, $jr_id); $Ret=ExecSql($p_cn,$sql); diff --git a/include/constant.php b/include/constant.php index a1e9a1607..2f743e4b7 100644 --- a/include/constant.php +++ b/include/constant.php @@ -33,7 +33,7 @@ define ("domaine",""); define ("MAX_COMPTE",4); -define ("DEBUG","false"); +define ("DEBUG","true"); // securite correspond a la table // action diff --git a/include/modele.inc.php b/include/modele.inc.php index e64b3914c..ca42a2a0a 100644 --- a/include/modele.inc.php +++ b/include/modele.inc.php @@ -84,6 +84,12 @@ echo JS_CONFIRM; $Max=pg_NumRows($Res); for ($seq=0;$seq<$Max;$seq++) { $row=pg_fetch_array($Res,$seq); + /* if seq doesn't exist create it */ + if ( exist_sequence($cn_mod,'s_jrn_'.$row['jrn_def_id']) == false ) { + create_sequence($cn_mod,'s_jrn_'.$row['jrn_def_id']); + } + + $sql=sprintf ("select setval('s_jrn_%d',1,false)",$row['jrn_def_id']); ExecSql($cn_mod,$sql); /* diff --git a/include/postgres.php b/include/postgres.php index 1b9981c14..9dd8e7744 100644 --- a/include/postgres.php +++ b/include/postgres.php @@ -455,5 +455,17 @@ function getDbValue($p_cn,$sql) $r=pg_fetch_row($ret,0); return $r[0]; } - +/*!\brief test if a sequence exist */ +/* \return true if the seq. exist otherwise false + */ +function exist_sequence($p_cn,$p_name) { + $r=CountSql($p_cn,"select relname from pg_class where relname=lower('".$p_name."')"); + if ( $r==0) + return false; + return true; +} +function create_sequence($p_cn,$p_name) { + $sql="create sequence ".$p_name; + ExecSql($p_cn,$sql); +} ?>