Sql write less do more...
This commit is contained in:
parent
e915552ae1
commit
09591d75f6
@ -63,9 +63,10 @@ class UnitsTools
|
|||||||
*/
|
*/
|
||||||
static public function scaleOfUnitPow($id)
|
static public function scaleOfUnitPow($id)
|
||||||
{
|
{
|
||||||
|
global $db;
|
||||||
$base = 10;
|
$base = 10;
|
||||||
// TODO : add base col into unit dictionary table
|
// TODO : add base col into unit dictionary table
|
||||||
$unit = self::dbGetRow('SELECT scale, unit_type from '.MAIN_DB_PREFIX.'c_units WHERE rowid = '.intval($id));
|
$unit = $db->getRow('SELECT scale, unit_type from '.MAIN_DB_PREFIX.'c_units WHERE rowid = '.intval($id));
|
||||||
if($unit){
|
if($unit){
|
||||||
// TODO : if base exist in unit dictionary table remove this convertion exception and update convertion infos in database exemple time hour currently scale 3600 will become scale 2 base 60
|
// TODO : if base exist in unit dictionary table remove this convertion exception and update convertion infos in database exemple time hour currently scale 3600 will become scale 2 base 60
|
||||||
if($unit->unit_type == 'time'){
|
if($unit->unit_type == 'time'){
|
||||||
@ -77,43 +78,4 @@ class UnitsTools
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* return first result from query
|
|
||||||
* @param string $sql the sql query string
|
|
||||||
* @return bool| var
|
|
||||||
*/
|
|
||||||
static public function dbGetvalue($sql)
|
|
||||||
{
|
|
||||||
global $db;
|
|
||||||
$sql .= ' LIMIT 1;';
|
|
||||||
|
|
||||||
$res = $db->query($sql);
|
|
||||||
if ($res)
|
|
||||||
{
|
|
||||||
$Tresult = $db->fetch_row($res);
|
|
||||||
return $Tresult[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* return first result from query
|
|
||||||
* @param string $sql the sql query string
|
|
||||||
* @return bool| var
|
|
||||||
*/
|
|
||||||
static public function dbGetRow($sql)
|
|
||||||
{
|
|
||||||
global $db;
|
|
||||||
$sql .= ' LIMIT 1;';
|
|
||||||
|
|
||||||
$res = $db->query($sql);
|
|
||||||
if ($res)
|
|
||||||
{
|
|
||||||
return $db->fetch_object($res);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -297,4 +297,42 @@ abstract class DoliDB implements Database
|
|||||||
{
|
{
|
||||||
return $this->lastqueryerror;
|
return $this->lastqueryerror;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return first result value from query
|
||||||
|
* @param string $sql the sql query string
|
||||||
|
* @return bool| var
|
||||||
|
*/
|
||||||
|
public function getvalue($sql)
|
||||||
|
{
|
||||||
|
$sql .= ' LIMIT 1;';
|
||||||
|
|
||||||
|
$res = $this->query($sql);
|
||||||
|
if ($res)
|
||||||
|
{
|
||||||
|
$Tresult = $this->fetch_row($res);
|
||||||
|
return $Tresult[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return first result from query as object
|
||||||
|
* @param string $sql the sql query string
|
||||||
|
* @return bool| var
|
||||||
|
*/
|
||||||
|
public function getRow($sql)
|
||||||
|
{
|
||||||
|
$sql .= ' LIMIT 1;';
|
||||||
|
|
||||||
|
$res = $this->query($sql);
|
||||||
|
if ($res)
|
||||||
|
{
|
||||||
|
return $this->fetch_object($res);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user