[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 94/107: Bug : Database::fetch_all returns an
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 94/107: Bug : Database::fetch_all returns an array or FALSE, because of pg_fetch_all, the version PHP7 cannot use anymore a boolean with count(). |
Date: |
Mon, 26 Aug 2019 10:32:08 -0400 (EDT) |
sparkyx pushed a commit to branch master
in repository noalyss.
commit 5aab6a0502ca5bd2e4cc7822ca4550f2a0701947
Author: Dany De Bontridder <address@hidden>
Date: Sat Aug 24 12:05:49 2019 +0200
Bug : Database::fetch_all returns an array or FALSE, because
of pg_fetch_all, the version PHP7 cannot use anymore a boolean with
count().
---
include/class/acc_ledger.class.php | 5 +++--
include/class/acc_ledger_history_generic.class.php | 3 +++
include/class/acc_operation.class.php | 2 +-
include/class/anc_balance_simple.class.php | 24 +++++++++++-----------
include/class/customer.class.php | 5 +++--
include/class/fiche.class.php | 2 +-
include/class/follow_up.class.php | 2 +-
include/class/gestion_sold.class.php | 4 ++--
include/class/pre_op_fin.class.php | 6 +++---
include/class/pre_operation.class.php | 4 ++--
include/lib/database_core.class.php | 2 +-
include/modele.inc.php | 3 ++-
.../acc_ledger_history_purchase_extended.php | 2 +-
include/verif_bilan.inc.php | 10 +++++----
14 files changed, 41 insertions(+), 33 deletions(-)
diff --git a/include/class/acc_ledger.class.php
b/include/class/acc_ledger.class.php
index 6d38964..7487b7b 100644
--- a/include/class/acc_ledger.class.php
+++ b/include/class/acc_ledger.class.php
@@ -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";
$r=$this->db->exec_sql($sql, array($this->id));
$Res=Database::fetch_all($r);
- if (sizeof($Res)==0)
+ if ($Res == FALSE || sizeof($Res)==0)
return 1;
return $Res[0]['value'];
}
@@ -469,6 +469,7 @@ class Acc_Ledger extends jrn_def_sql
$array=Database::fetch_all($ret);
$deb=0.0;
$cred=0.0;
+ if ( $array==FALSE) $array=[];
foreach ($array as $line)
{
@@ -533,7 +534,7 @@ class Acc_Ledger extends jrn_def_sql
$r=$this->db->exec_sql($sql, array($this->id));
$res=Database::fetch_all($r);
- if (empty($res))
+ if ($res==FALSE || empty($res))
return null;
return $res[0];
diff --git a/include/class/acc_ledger_history_generic.class.php
b/include/class/acc_ledger_history_generic.class.php
index 3606193..8770f82 100644
--- a/include/class/acc_ledger_history_generic.class.php
+++ b/include/class/acc_ledger_history_generic.class.php
@@ -225,6 +225,9 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History
$c=0;
// Parse data from jrnx and fill diff. field
+ if ( $data_jrnx == FALSE ){
+ $data_jrnx=[];
+ }
foreach ($data_jrnx as $code)
{
$idx_tva=0;
diff --git a/include/class/acc_operation.class.php
b/include/class/acc_operation.class.php
index 793fb73..167325c 100644
--- a/include/class/acc_operation.class.php
+++ b/include/class/acc_operation.class.php
@@ -330,7 +330,7 @@ class Acc_Operation
}
/*!\brief retrieve data from jrnx
*\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()
{
diff --git a/include/class/anc_balance_simple.class.php
b/include/class/anc_balance_simple.class.php
index 6a9764e..8419c67 100644
--- a/include/class/anc_balance_simple.class.php
+++ b/include/class/anc_balance_simple.class.php
@@ -69,18 +69,18 @@ class Anc_Balance_Simple extends Anc_Print
$a=array();
$count=0;
$array=Database::fetch_all($res);
- foreach ($array as $row)
- {
- $a[$count]['po_id']=$row['po_id'];
- $a[$count]['sum_deb']=$row['sum_deb'];
- $a[$count]['sum_cred']=$row['sum_cred'];
- $a[$count]['po_name']=$row['po_name'];
- $a[$count]['ga_description']=$row['ga_description'];
- $a[$count]['solde']=abs($row['sum_deb']-$row['sum_cred']);
-
$a[$count]['debit']=($row['sum_deb']>$row['sum_cred'])?"debit":"credit";
- $count++;
- }
- $this->has_data=$count;
+ foreach ($array as $row)
+ {
+ $a[$count]['po_id']=$row['po_id'];
+ $a[$count]['sum_deb']=$row['sum_deb'];
+ $a[$count]['sum_cred']=$row['sum_cred'];
+ $a[$count]['po_name']=$row['po_name'];
+ $a[$count]['ga_description']=$row['ga_description'];
+ $a[$count]['solde']=abs($row['sum_deb']-$row['sum_cred']);
+
$a[$count]['debit']=($row['sum_deb']>$row['sum_cred'])?"debit":"credit";
+ $count++;
+ }
+ $this->has_data=$count;
return $a;
diff --git a/include/class/customer.class.php b/include/class/customer.class.php
index b6e8efc..59fba23 100644
--- a/include/class/customer.class.php
+++ b/include/class/customer.class.php
@@ -144,9 +144,10 @@ class Customer extends Fiche
// 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);
-
+ if ($a_row==FALSE) $a_row=[];
+
// Store the amount in the array
//---
foreach ($a_row as $e)
diff --git a/include/class/fiche.class.php b/include/class/fiche.class.php
index e5b3fa0..67db0c9 100644
--- a/include/class/fiche.class.php
+++ b/include/class/fiche.class.php
@@ -1163,7 +1163,7 @@ class Fiche
$sql="select ad_value from fiche_detail where ad_id=23 and f_id=$1";
$Res=$this->cn->exec_sql($sql,array($this->id));
$r=Database::fetch_all($Res);
- if ( sizeof($r) == 0 )
+ if ( $r == FALSE || sizeof($r) == 0 )
return null;
return $r[0]['ad_value'];
}
diff --git a/include/class/follow_up.class.php
b/include/class/follow_up.class.php
index 39d9a00..3f93271 100644
--- a/include/class/follow_up.class.php
+++ b/include/class/follow_up.class.php
@@ -772,7 +772,7 @@ class Follow_Up
if ($a_row==false || sizeof($a_row)==0 )
{
$r='<div style="clear:both">';
- $r.='<hr>Aucun enregistrement trouvé';
+ $r.='<hr>'._("Aucun enregistrement trouvé");
$r.="</div>";
return $r;
}
diff --git a/include/class/gestion_sold.class.php
b/include/class/gestion_sold.class.php
index c13492b..4aca544 100644
--- a/include/class/gestion_sold.class.php
+++ b/include/class/gestion_sold.class.php
@@ -68,7 +68,7 @@ class gestion_sold extends gestion_table
// $res contains all the line
$res=Database::fetch_all($ret);
- if ( sizeof($res)==0) return null;
+ if ( $res == FALSE || sizeof($res)==0) return null;
$count=0;
foreach ($res as $row)
@@ -108,7 +108,7 @@ class gestion_sold extends gestion_table
// $res contains all the line
$res=Database::fetch_all($ret);
- if ( empty($res) ) return null;
+ if ( $res==FALSE || empty($res) ) return null;
foreach ($res[0] as $idx=>$value)
$this->$idx=$value;
}
diff --git a/include/class/pre_op_fin.class.php
b/include/class/pre_op_fin.class.php
index 3523d42..f293eb2 100644
--- a/include/class/pre_op_fin.class.php
+++ b/include/class/pre_op_fin.class.php
@@ -118,14 +118,14 @@ class Pre_op_fin extends Pre_operation_detail
return $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()
{
$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";
- $res=$this->db->exec_sql($sql);
+ $res=$this->db->exec_sql($sql,[$this->operation->od_id]);
$array=Database::fetch_all($res);
return $array;
}
diff --git a/include/class/pre_operation.class.php
b/include/class/pre_operation.class.php
index 224d4d1..885e7a1 100644
--- a/include/class/pre_operation.class.php
+++ b/include/class/pre_operation.class.php
@@ -128,9 +128,9 @@ class Pre_operation
function load()
{
$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";
- $res=$this->db->exec_sql($sql);
+ $res=$this->db->exec_sql($sql,[$this->od_id]);
$array=Database::fetch_all($res);
foreach
(array('jrn_def_id','od_name','od_item','od_jrn_type','od_description') as
$field) {
$this->$field=$array[0][$field];
diff --git a/include/lib/database_core.class.php
b/include/lib/database_core.class.php
index dca3358..c4fb518 100644
--- a/include/lib/database_core.class.php
+++ b/include/lib/database_core.class.php
@@ -728,7 +728,7 @@ class DatabaseCore
/**\brief wrapper for the function pg_fetch_all
* \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)
diff --git a/include/modele.inc.php b/include/modele.inc.php
index 2814fc0..dab6e08 100644
--- a/include/modele.inc.php
+++ b/include/modele.inc.php
@@ -111,7 +111,8 @@ if (isset($_POST["FMOD_NAME"]))
if (Database::num_row($Res) != 0)
{
$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']);
}
$Res = $cn_mod->exec_sql("truncate table centralized");
diff --git a/include/template/acc_ledger_history_purchase_extended.php
b/include/template/acc_ledger_history_purchase_extended.php
index 5506b21..d6429db 100644
--- a/include/template/acc_ledger_history_purchase_extended.php
+++ b/include/template/acc_ledger_history_purchase_extended.php
@@ -131,7 +131,7 @@ $a_detail=Database::fetch_all($det);
<th class="num"><?=_("TVAC")?></th>
</tr>
<?php
-$nb_detail=count($a_detail);
+$nb_detail=($a_detail == FALSE)?0 : count($a_detail);
for ($j=0;$j<$nb_detail;$j++):
?>
<tr >
diff --git a/include/verif_bilan.inc.php b/include/verif_bilan.inc.php
index 73e10e6..cf0181a 100644
--- a/include/verif_bilan.inc.php
+++ b/include/verif_bilan.inc.php
@@ -66,7 +66,7 @@ order by jrn_def_name
$res=$cn->exec_sql($sql);
$jrn=Database::fetch_all($res);
-$nb_jrn= count($jrn);
+$nb_jrn= ($jrn == FALSE) ?0 :count($jrn);
if ( $jrn ===false ) {
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']));
$tmp_qcode=$cn->execute('get_qcode',array($a_fiche_id[$i]['f_id']));
$qcode=Database::fetch_all($tmp_qcode);
- if ( $qcode[0]['qcode']=="") {
+
+ if ( $qcode == FALSE || $qcode[0]['qcode']=="") {
continue;
}
?>
@@ -171,7 +172,8 @@ having count(*) > 1
</li>
<ul>
<?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>
<?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
$ret_operation=$cn->execute('get_operation',array($a_account_used[$i]['f_id']));
$a_operation=Database::fetch_all($ret_operation);
- $nb_operation=count($a_operation);
+ $nb_operation=($a_operation == FALSE) ? 0 :
count($a_operation);
?>
<table class="result">
<?php for ($x=0;$x<$nb_operation;$x++):?>
- [Noalyss-commit] [noalyss] 44/107: fixup! fixup! Code cleaning : split database into database (for noalyss) and databasecore , with the functions, (continued)
- [Noalyss-commit] [noalyss] 44/107: fixup! fixup! Code cleaning : split database into database (for noalyss) and databasecore , with the functions, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 36/107: Bug : card cannot use a attribute of the type "card", reason : the query was wrong and there were a confusion between this->name and this->id in "get_js_attr()", Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 47/107: Improve doxygen, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 51/107: Code Cleaning split sendmail between sendmail_core (not related to noalyss) and sendmail which is used by noalyss, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 54/107: Merge branch 'dev7109', Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 59/107: #0001729: Preference : ne plus recharger la page, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 85/107: Cosmetic : Icon_Trash in Todo_List, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 80/107: translation, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 82/107: DatabaseCore fix silent when not debug, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 72/107: Improve message progress bar + translation, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 94/107: Bug : Database::fetch_all returns an array or FALSE, because of pg_fetch_all, the version PHP7 cannot use anymore a boolean with count().,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 63/107: remove background color, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 66/107: Code cleaning : rename table mod_payment to payment_method, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 53/107: Select_Box new Object, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 55/107: Merge branch 'master' of gitlab.noalyss.eu:noalyss/noalyss, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 57/107: PDF_Core : code cleaning, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 71/107: Select_Box add a search, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 77/107: Security : replace direct use of $_GET, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 45/107: Replace PHPCOMPTA by NOALYSS, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 90/107: Cosmetic : add button close in history card & accounting, Dany De Bontridder, 2019/08/26
- [Noalyss-commit] [noalyss] 88/107: SQL : correct SQL script to take care of users who delete the profile no 2, Dany De Bontridder, 2019/08/26