Removed some code specific to databases and use instead correct abstract

method of drivers.
This commit is contained in:
Laurent Destailleur 2014-02-25 18:25:17 +01:00
parent 3c0e5b8a53
commit 1790f905c9
5 changed files with 47 additions and 71 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org> * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be> * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* *
@ -63,33 +63,17 @@ print '<tr '.$bc[0].'><td width="300"><a href="'.DOL_URL_ROOT.'/admin/system/dat
print '</table>'; print '</table>';
$base=0; $listofvars=$db->getServerParametersValues();
$sqls = array(); $listofstatus=$db->getServerStatusValues();
if ($conf->db->type == 'mysql' || $conf->db->type == 'mysqli') $arraylist=array('listofvars','listofstatus');
{
$sqls[0] = "SHOW VARIABLES"; // TODO Use function getServerParametersValues
$sqls[1] = "SHOW STATUS"; // TODO Use function getServerStatusValues
$base=1;
}
else if ($conf->db->type == 'pgsql')
{
$sqls[0] = "select name,setting from pg_settings"; // TODO function getServerParametersValues
//$sqls[1] = ""; // TODO Use function getServerStatusValues
$base=2;
}
else if ($conf->db->type == 'mssql')
{
//$sqls[0] = "";
//$base=3;
}
if (! $base) if (! count($listofvars) && ! count($listofstatus))
{ {
print $langs->trans("FeatureNotAvailableWithThisDatabaseDriver"); print $langs->trans("FeatureNotAvailableWithThisDatabaseDriver");
} }
else else
{ {
foreach($sqls as $sql) foreach($arraylist as $listname)
{ {
print '<br>'; print '<br>';
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
@ -108,33 +92,32 @@ else
); );
} }
$resql = $db->query($sql); $listtouse=array();
if ($resql) if ($listname == 'listofvars') $listtouse=$listofvars;
if ($listname == 'listofstatus') $listtouse=$listofstatus;
$var=true;
foreach($listtouse as $param => $paramval)
{ {
$var=True; $var=!$var;
while ($row = $db->fetch_row($resql)) print '<tr '.$bc[$var].'>';
print '<td>';
print $param;
print '</td>';
print '<td>';
$show=0;$text='';
foreach($arraytest as $key => $val)
{ {
$var=!$var; if ($key != $param) continue;
print '<tr '.$bc[$var].'>'; $val2=${$val['var']};
print '<td>'; $text='Should be in line with value of param <b>'.$val['var'].'</b> thas is <b>'.($val2?$val2:"'' (=".$val['valifempty'].")").'</b>';
print $row[0]; $show=1;
print '</td>';
print '<td>';
$show=0;$text='';
foreach($arraytest as $key => $val)
{
if ($key != $row[0]) continue;
$val2=${$val['var']};
$text='Should be in line with value of param <b>'.$val['var'].'</b> thas is <b>'.($val2?$val2:"'' (=".$val['valifempty'].")").'</b>';
$show=1;
}
if ($show==0) print $row[1];
if ($show==1) print $form->textwithpicto($row[1],$text);
if ($show==2) print $form->textwithpicto($row[1],$text,1,'warning');
print '</td>';
print '</tr>'."\n";
} }
$db->free($resql); if ($show==0) print $paramval;
if ($show==1) print $form->textwithpicto($paramval,$text);
if ($show==2) print $form->textwithpicto($paramval,$text,1,'warning');
print '</td>';
print '</tr>'."\n";
} }
print '</table>'."\n"; print '</table>'."\n";
} }

View File

@ -1207,12 +1207,11 @@ class DoliDBMysql extends DoliDB
$result=array(); $result=array();
$sql='SHOW VARIABLES'; $sql='SHOW VARIABLES';
if ($filter) $sql.=" LIKE '".addslashes($filter)."'"; if ($filter) $sql.=" LIKE '".$this->escape($filter)."'";
$resql=$this->query($sql); $resql=$this->query($sql);
if ($resql) if ($resql)
{ {
$obj=$this->fetch_object($resql); while ($obj=$this->fetch_object($resql)) $result[$obj->Variable_name]=$obj->Value;
$result[$obj->Variable_name]=$obj->Value;
} }
return $result; return $result;
@ -1233,8 +1232,7 @@ class DoliDBMysql extends DoliDB
$resql=$this->query($sql); $resql=$this->query($sql);
if ($resql) if ($resql)
{ {
$obj=$this->fetch_object($resql); while ($obj=$this->fetch_object($resql)) $result[$obj->Variable_name]=$obj->Value;
$result[$obj->Variable_name]=$obj->Value;
} }
return $result; return $result;

View File

@ -1210,12 +1210,11 @@ class DoliDBMysqli extends DoliDB
$result=array(); $result=array();
$sql='SHOW VARIABLES'; $sql='SHOW VARIABLES';
if ($filter) $sql.=" LIKE '".addslashes($filter)."'"; if ($filter) $sql.=" LIKE '".$this->escape($filter)."'";
$resql=$this->query($sql); $resql=$this->query($sql);
if ($resql) if ($resql)
{ {
$obj=$this->fetch_object($resql); while($obj=$this->fetch_object($resql)) $result[$obj->Variable_name]=$obj->Value;
$result[$obj->Variable_name]=$obj->Value;
} }
return $result; return $result;
@ -1236,8 +1235,7 @@ class DoliDBMysqli extends DoliDB
$resql=$this->query($sql); $resql=$this->query($sql);
if ($resql) if ($resql)
{ {
$obj=$this->fetch_object($resql); while($obj=$this->fetch_object($resql)) $result[$obj->Variable_name]=$obj->Value;
$result[$obj->Variable_name]=$obj->Value;
} }
return $result; return $result;

View File

@ -1137,15 +1137,15 @@ class DoliDBPgsql extends DoliDB
/** /**
* Create a user to connect to database * Create a user to connect to database
* *
* @param string $dolibarr_main_db_host Ip serveur * @param string $dolibarr_main_db_host Ip server
* @param string $dolibarr_main_db_user Nom user a creer * @param string $dolibarr_main_db_user Name of user to create
* @param string $dolibarr_main_db_pass Mot de passe user a creer * @param string $dolibarr_main_db_pass Password of user to create
* @param string $dolibarr_main_db_name Database name where user must be granted * @param string $dolibarr_main_db_name Database name where user must be granted
* @return int <0 if KO, >=0 if OK * @return int <0 if KO, >=0 if OK
*/ */
function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass,$dolibarr_main_db_name) function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass,$dolibarr_main_db_name)
{ {
$sql = "create user \"".addslashes($dolibarr_main_db_user)."\" with password '".addslashes($dolibarr_main_db_pass)."'"; $sql = "CREATE USER '".$this->escape($dolibarr_main_db_user)."' with password '".$this->escape($dolibarr_main_db_pass)."'";
dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log
$resql=$this->query($sql); $resql=$this->query($sql);
@ -1401,8 +1401,7 @@ class DoliDBPgsql extends DoliDB
$resql=$this->query($resql); $resql=$this->query($resql);
if ($resql) if ($resql)
{ {
$obj=$this->fetch_object($resql); while ($obj=$this->fetch_object($resql)) $result[$obj->name]=$obj->setting;
$result[$obj->name]=$obj->setting;
} }
return $result; return $result;

View File

@ -1185,7 +1185,7 @@ class DoliDBSqlite extends DoliDB
{ {
$sql = "INSERT INTO user "; $sql = "INSERT INTO user ";
$sql.= "(Host,User,password,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv,Lock_tables_priv)"; $sql.= "(Host,User,password,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv,Lock_tables_priv)";
$sql.= " VALUES ('".addslashes($dolibarr_main_db_host)."','".addslashes($dolibarr_main_db_user)."',password('".addslashes($dolibarr_main_db_pass)."')"; $sql.= " VALUES ('".$this->escape($dolibarr_main_db_host)."','".$this->escape($dolibarr_main_db_user)."',password('".addslashes($dolibarr_main_db_pass)."')";
$sql.= ",'Y','Y','Y','Y','Y','Y','Y','Y','Y')"; $sql.= ",'Y','Y','Y','Y','Y','Y','Y','Y','Y')";
dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log
@ -1198,7 +1198,7 @@ class DoliDBSqlite extends DoliDB
$sql = "INSERT INTO db "; $sql = "INSERT INTO db ";
$sql.= "(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv,Lock_tables_priv)"; $sql.= "(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv,Lock_tables_priv)";
$sql.= " VALUES ('".addslashes($dolibarr_main_db_host)."','".addslashes($dolibarr_main_db_name)."','".addslashes($dolibarr_main_db_user)."'"; $sql.= " VALUES ('".$this->escape($dolibarr_main_db_host)."','".$this->escape($dolibarr_main_db_name)."','".addslashes($dolibarr_main_db_user)."'";
$sql.= ",'Y','Y','Y','Y','Y','Y','Y','Y','Y')"; $sql.= ",'Y','Y','Y','Y','Y','Y','Y','Y','Y')";
dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql); dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql);
@ -1319,12 +1319,11 @@ class DoliDBSqlite extends DoliDB
$result=array(); $result=array();
$sql='SHOW VARIABLES'; $sql='SHOW VARIABLES';
if ($filter) $sql.=" LIKE '".addslashes($filter)."'"; if ($filter) $sql.=" LIKE '".$this->escape($filter)."'";
$resql=$this->query($sql); $resql=$this->query($sql);
if ($resql) if ($resql)
{ {
$obj=$this->fetch_object($resql); while ($obj=$this->fetch_object($resql)) $result[$obj->Variable_name]=$obj->Value;
$result[$obj->Variable_name]=$obj->Value;
} }
return $result; return $result;
@ -1345,8 +1344,7 @@ class DoliDBSqlite extends DoliDB
$resql=$this->query($sql); $resql=$this->query($sql);
if ($resql) if ($resql)
{ {
$obj=$this->fetch_object($resql); while ($obj=$this->fetch_object($resql)) $result[$obj->Variable_name]=$obj->Value;
$result[$obj->Variable_name]=$obj->Value;
} }
return $result; return $result;