Bug : Database::fetch_all returns an array or FALSE, because

of pg_fetch_all, the version PHP7 cannot use anymore a boolean with
count().
This commit is contained in:
Dany De Bontridder 2019-08-24 12:05:49 +02:00
parent 7a41f9b301
commit 5aab6a0502
14 changed files with 41 additions and 33 deletions

View file

@ -443,7 +443,7 @@ class Acc_Ledger extends jrn_def_sql
$sql="select jrn_deb_max_line as value from jrn_def where jrn_def_id=$1"; $sql="select jrn_deb_max_line as value from jrn_def where jrn_def_id=$1";
$r=$this->db->exec_sql($sql, array($this->id)); $r=$this->db->exec_sql($sql, array($this->id));
$Res=Database::fetch_all($r); $Res=Database::fetch_all($r);
if (sizeof($Res)==0) if ($Res == FALSE || sizeof($Res)==0)
return 1; return 1;
return $Res[0]['value']; return $Res[0]['value'];
} }
@ -469,6 +469,7 @@ class Acc_Ledger extends jrn_def_sql
$array=Database::fetch_all($ret); $array=Database::fetch_all($ret);
$deb=0.0; $deb=0.0;
$cred=0.0; $cred=0.0;
if ( $array==FALSE) $array=[];
foreach ($array as $line) foreach ($array as $line)
{ {
@ -533,7 +534,7 @@ class Acc_Ledger extends jrn_def_sql
$r=$this->db->exec_sql($sql, array($this->id)); $r=$this->db->exec_sql($sql, array($this->id));
$res=Database::fetch_all($r); $res=Database::fetch_all($r);
if (empty($res)) if ($res==FALSE || empty($res))
return null; return null;
return $res[0]; return $res[0];

View file

@ -225,6 +225,9 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History
$c=0; $c=0;
// Parse data from jrnx and fill diff. field // Parse data from jrnx and fill diff. field
if ( $data_jrnx == FALSE ){
$data_jrnx=[];
}
foreach ($data_jrnx as $code) foreach ($data_jrnx as $code)
{ {
$idx_tva=0; $idx_tva=0;

View file

@ -330,7 +330,7 @@ class Acc_Operation
} }
/*!\brief retrieve data from jrnx /*!\brief retrieve data from jrnx
*\note the data are filtered by the access of the current user *\note the data are filtered by the access of the current user
* \return an array * \return an array or FALSE if nothing found
*/ */
function get_jrnx_detail() function get_jrnx_detail()
{ {

View file

@ -69,18 +69,18 @@ class Anc_Balance_Simple extends Anc_Print
$a=array(); $a=array();
$count=0; $count=0;
$array=Database::fetch_all($res); $array=Database::fetch_all($res);
foreach ($array as $row) foreach ($array as $row)
{ {
$a[$count]['po_id']=$row['po_id']; $a[$count]['po_id']=$row['po_id'];
$a[$count]['sum_deb']=$row['sum_deb']; $a[$count]['sum_deb']=$row['sum_deb'];
$a[$count]['sum_cred']=$row['sum_cred']; $a[$count]['sum_cred']=$row['sum_cred'];
$a[$count]['po_name']=$row['po_name']; $a[$count]['po_name']=$row['po_name'];
$a[$count]['ga_description']=$row['ga_description']; $a[$count]['ga_description']=$row['ga_description'];
$a[$count]['solde']=abs($row['sum_deb']-$row['sum_cred']); $a[$count]['solde']=abs($row['sum_deb']-$row['sum_cred']);
$a[$count]['debit']=($row['sum_deb']>$row['sum_cred'])?"debit":"credit"; $a[$count]['debit']=($row['sum_deb']>$row['sum_cred'])?"debit":"credit";
$count++; $count++;
} }
$this->has_data=$count; $this->has_data=$count;
return $a; return $a;

View file

@ -144,9 +144,10 @@ class Customer extends Fiche
// select the operation // select the operation
//---- //----
$Res2=$this->cn->exec_sql("select j_poste,j_montant,j_debit from jrnx where j_grpt=".$row1['j_grpt']); $Res2=$this->cn->exec_sql("select j_poste,j_montant,j_debit from jrnx where j_grpt=$1",[$row1['j_grpt']]);
$a_row=Database::fetch_all($Res2); $a_row=Database::fetch_all($Res2);
if ($a_row==FALSE) $a_row=[];
// Store the amount in the array // Store the amount in the array
//--- //---
foreach ($a_row as $e) foreach ($a_row as $e)

View file

@ -1163,7 +1163,7 @@ class Fiche
$sql="select ad_value from fiche_detail where ad_id=23 and f_id=$1"; $sql="select ad_value from fiche_detail where ad_id=23 and f_id=$1";
$Res=$this->cn->exec_sql($sql,array($this->id)); $Res=$this->cn->exec_sql($sql,array($this->id));
$r=Database::fetch_all($Res); $r=Database::fetch_all($Res);
if ( sizeof($r) == 0 ) if ( $r == FALSE || sizeof($r) == 0 )
return null; return null;
return $r[0]['ad_value']; return $r[0]['ad_value'];
} }

View file

@ -772,7 +772,7 @@ class Follow_Up
if ($a_row==false || sizeof($a_row)==0 ) if ($a_row==false || sizeof($a_row)==0 )
{ {
$r='<div style="clear:both">'; $r='<div style="clear:both">';
$r.='<hr>Aucun enregistrement trouvé'; $r.='<hr>'._("Aucun enregistrement trouvé");
$r.="</div>"; $r.="</div>";
return $r; return $r;
} }

View file

@ -68,7 +68,7 @@ class gestion_sold extends gestion_table
// $res contains all the line // $res contains all the line
$res=Database::fetch_all($ret); $res=Database::fetch_all($ret);
if ( sizeof($res)==0) return null; if ( $res == FALSE || sizeof($res)==0) return null;
$count=0; $count=0;
foreach ($res as $row) foreach ($res as $row)
@ -108,7 +108,7 @@ class gestion_sold extends gestion_table
// $res contains all the line // $res contains all the line
$res=Database::fetch_all($ret); $res=Database::fetch_all($ret);
if ( empty($res) ) return null; if ( $res==FALSE || empty($res) ) return null;
foreach ($res[0] as $idx=>$value) foreach ($res[0] as $idx=>$value)
$this->$idx=$value; $this->$idx=$value;
} }

View file

@ -118,14 +118,14 @@ class Pre_op_fin extends Pre_operation_detail
return $array; return $array;
} }
/*!\brief load the data from the database and return an array /*!\brief load the data from the database and return an array
* \return an array * \return an array or FALSE is nothing found
*/ */
function load() function load()
{ {
$sql="select opd_id,opd_poste,opd_amount,opd_comment,opd_debit". $sql="select opd_id,opd_poste,opd_amount,opd_comment,opd_debit".
" from op_predef_detail where od_id=".$this->operation->od_id. " from op_predef_detail where od_id=$1 ".
" order by opd_id"; " order by opd_id";
$res=$this->db->exec_sql($sql); $res=$this->db->exec_sql($sql,[$this->operation->od_id]);
$array=Database::fetch_all($res); $array=Database::fetch_all($res);
return $array; return $array;
} }

View file

@ -128,9 +128,9 @@ class Pre_operation
function load() function load()
{ {
$sql="select od_id,jrn_def_id,od_name,od_item,od_jrn_type,od_description". $sql="select od_id,jrn_def_id,od_name,od_item,od_jrn_type,od_description".
" from op_predef where od_id=".$this->od_id. " from op_predef where od_id=$1 ".
" order by od_name"; " order by od_name";
$res=$this->db->exec_sql($sql); $res=$this->db->exec_sql($sql,[$this->od_id]);
$array=Database::fetch_all($res); $array=Database::fetch_all($res);
foreach (array('jrn_def_id','od_name','od_item','od_jrn_type','od_description') as $field) { foreach (array('jrn_def_id','od_name','od_item','od_jrn_type','od_description') as $field) {
$this->$field=$array[0][$field]; $this->$field=$array[0][$field];

View file

@ -728,7 +728,7 @@ class DatabaseCore
/**\brief wrapper for the function pg_fetch_all /**\brief wrapper for the function pg_fetch_all
* \param $ret is the result of pg_exec (exec_sql) * \param $ret is the result of pg_exec (exec_sql)
* \return double array (row x col ) * \return double array (row x col ) or false
*/ */
static function fetch_all($ret) static function fetch_all($ret)

View file

@ -111,7 +111,8 @@ if (isset($_POST["FMOD_NAME"]))
if (Database::num_row($Res) != 0) if (Database::num_row($Res) != 0)
{ {
$a_lob = Database::fetch_all($Res); $a_lob = Database::fetch_all($Res);
for ($i = 0; $i < count($a_lob); $i++) $nb_log=($a_lob == FALSE)?0:count($a_lob);
for ($i = 0; $i < $nb_lob; $i++)
$cn_mod->lo_unlink($a_lob[$i]['jr_pj']); $cn_mod->lo_unlink($a_lob[$i]['jr_pj']);
} }
$Res = $cn_mod->exec_sql("truncate table centralized"); $Res = $cn_mod->exec_sql("truncate table centralized");

View file

@ -131,7 +131,7 @@ $a_detail=Database::fetch_all($det);
<th class="num"><?=_("TVAC")?></th> <th class="num"><?=_("TVAC")?></th>
</tr> </tr>
<?php <?php
$nb_detail=count($a_detail); $nb_detail=($a_detail == FALSE)?0 : count($a_detail);
for ($j=0;$j<$nb_detail;$j++): for ($j=0;$j<$nb_detail;$j++):
?> ?>
<tr > <tr >

View file

@ -66,7 +66,7 @@ order by jrn_def_name
$res=$cn->exec_sql($sql); $res=$cn->exec_sql($sql);
$jrn=Database::fetch_all($res); $jrn=Database::fetch_all($res);
$nb_jrn= count($jrn); $nb_jrn= ($jrn == FALSE) ?0 :count($jrn);
if ( $jrn ===false ) { if ( $jrn ===false ) {
echo $g_succeed." "._("Aucune anomalie dans les montants des journaux"); echo $g_succeed." "._("Aucune anomalie dans les montants des journaux");
} }
@ -158,7 +158,8 @@ having count(*) > 1
$poste=$cn->execute('get_poste',array($a_fiche_id[$i]['f_id'])); $poste=$cn->execute('get_poste',array($a_fiche_id[$i]['f_id']));
$tmp_qcode=$cn->execute('get_qcode',array($a_fiche_id[$i]['f_id'])); $tmp_qcode=$cn->execute('get_qcode',array($a_fiche_id[$i]['f_id']));
$qcode=Database::fetch_all($tmp_qcode); $qcode=Database::fetch_all($tmp_qcode);
if ( $qcode[0]['qcode']=="") {
if ( $qcode == FALSE || $qcode[0]['qcode']=="") {
continue; continue;
} }
?> ?>
@ -171,7 +172,8 @@ having count(*) > 1
</li> </li>
<ul> <ul>
<?php $all_dep=Database::fetch_all($poste); <?php $all_dep=Database::fetch_all($poste);
for ($e=0;$e<count($all_dep);$e++): $nb_dep = ($all_dep == FALSE ) ? 0 :count($all_dep);
for ($e=0;$e<count($nb_dep);$e++):
?> ?>
<li> <li>
<?php echo HtmlInput::history_account($all_dep[$e]['j_poste'],$all_dep[$e]['j_poste'],' display:inline ')?> <?php echo HtmlInput::history_account($all_dep[$e]['j_poste'],$all_dep[$e]['j_poste'],' display:inline ')?>
@ -229,7 +231,7 @@ $nb_account_used=count ($a_account_used);
<?php <?php
$ret_operation=$cn->execute('get_operation',array($a_account_used[$i]['f_id'])); $ret_operation=$cn->execute('get_operation',array($a_account_used[$i]['f_id']));
$a_operation=Database::fetch_all($ret_operation); $a_operation=Database::fetch_all($ret_operation);
$nb_operation=count($a_operation); $nb_operation=($a_operation == FALSE) ? 0 : count($a_operation);
?> ?>
<table class="result"> <table class="result">
<?php for ($x=0;$x<$nb_operation;$x++):?> <?php for ($x=0;$x<$nb_operation;$x++):?>