Merge branch '3.1' of ssh://git@github.com/Dolibarr/dolibarr.git into 3.1

This commit is contained in:
Laurent Destailleur 2012-01-09 00:44:30 +01:00
commit 471f060647
3 changed files with 85 additions and 49 deletions

View File

@ -615,6 +615,8 @@ class Categorie
*/ */
function get_full_arbo($type,$markafterid=0) function get_full_arbo($type,$markafterid=0)
{ {
global $conf;
$this->cats = array(); $this->cats = array();
// Charge tableau des meres // Charge tableau des meres
@ -643,6 +645,7 @@ class Categorie
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_association as ca"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_association as ca";
$sql.= " ON c.rowid=ca.fk_categorie_mere"; $sql.= " ON c.rowid=ca.fk_categorie_mere";
$sql.= " WHERE c.type = ".$type; $sql.= " WHERE c.type = ".$type;
$sql.= " AND c.entity = ".$conf->entity;
$sql.= " ORDER BY c.label, c.rowid"; $sql.= " ORDER BY c.label, c.rowid";
dol_syslog("Categorie::get_full_arbo get category list sql=".$sql, LOG_DEBUG); dol_syslog("Categorie::get_full_arbo get category list sql=".$sql, LOG_DEBUG);
@ -782,7 +785,10 @@ class Categorie
*/ */
function get_all_categories () function get_all_categories ()
{ {
global $conf;
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie"; $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie";
$sql.= " WHERE entity = ".$conf->entity;
$res = $this->db->query($sql); $res = $this->db->query($sql);
if ($res) if ($res)
@ -808,8 +814,12 @@ class Categorie
*/ */
function get_nb_categories () function get_nb_categories ()
{ {
global $conf;
$sql = "SELECT count(rowid)"; $sql = "SELECT count(rowid)";
$sql.= " FROM ".MAIN_DB_PREFIX."categorie"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie";
$sql.= " WHERE entity = ".$conf->entity;
$res = $this->db->query($sql); $res = $this->db->query($sql);
if ($res) if ($res)
{ {

View File

@ -238,45 +238,51 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action')))
&& versioncompare($versioncommande,$versionarray) <= 0) // Si mysql >= 4.0 && versioncompare($versioncommande,$versionarray) <= 0) // Si mysql >= 4.0
{ {
// Suppression vieilles contraintes sans noms et en doubles // Suppression vieilles contraintes sans noms et en doubles
// Les contraintes indesirables ont un nom qui commence par 0_ ou se termine par ibfk_999 // Les contraintes indesirables ont un nom qui commence par 0_ ou se termine par ibfk_999
$listtables=array( 'llx_adherent_options', $listtables=array(
'llx_bank_class', MAIN_DB_PREFIX.'adherent_options',
'llx_c_ecotaxe', MAIN_DB_PREFIX.'bank_class',
'llx_c_methode_commande_fournisseur', // table renamed MAIN_DB_PREFIX.'c_ecotaxe',
'llx_c_input_method'); MAIN_DB_PREFIX.'c_methode_commande_fournisseur', // table renamed
MAIN_DB_PREFIX.'c_input_method'
$listtables = $db->DDLListTables($conf->db->name,''); );
foreach ($listtables as $val)
{ $listtables = $db->DDLListTables($conf->db->name,'');
//print "x".$val."<br>"; foreach ($listtables as $val)
$sql = "SHOW CREATE TABLE ".$val; {
$resql = $db->query($sql); // Database prefix filter
if ($resql) if (preg_match('/^'.MAIN_DB_PREFIX.'/', $val))
{ {
$values=$db->fetch_array($resql); //print "x".$val."<br>";
$i=0; $sql = "SHOW CREATE TABLE ".$val;
$createsql=$values[1]; $resql = $db->query($sql);
while (preg_match('/CONSTRAINT `(0_[0-9a-zA-Z]+|[_0-9a-zA-Z]+_ibfk_[0-9]+)`/i',$createsql,$reg) && $i < 100) if ($resql)
{ {
$sqldrop="ALTER TABLE ".$val." DROP FOREIGN KEY ".$reg[1]; $values=$db->fetch_array($resql);
$resqldrop = $db->query($sqldrop); $i=0;
if ($resqldrop) $createsql=$values[1];
{ while (preg_match('/CONSTRAINT `(0_[0-9a-zA-Z]+|[_0-9a-zA-Z]+_ibfk_[0-9]+)`/i',$createsql,$reg) && $i < 100)
print '<tr><td colspan="2">'.$sqldrop.";</td></tr>\n"; {
} $sqldrop="ALTER TABLE ".$val." DROP FOREIGN KEY ".$reg[1];
$createsql=preg_replace('/CONSTRAINT `'.$reg[1].'`/i','XXX',$createsql); $resqldrop = $db->query($sqldrop);
$i++; if ($resqldrop)
} {
$db->free($resql); print '<tr><td colspan="2">'.$sqldrop.";</td></tr>\n";
} }
else $createsql=preg_replace('/CONSTRAINT `'.$reg[1].'`/i','XXX',$createsql);
{ $i++;
if ($db->lasterrno() != 'DB_ERROR_NOSUCHTABLE') }
{ $db->free($resql);
print '<tr><td colspan="2"><font class="error">'.$sql.' : '.$db->lasterror()."</font></td></tr>\n"; }
} else
} {
} if ($db->lasterrno() != 'DB_ERROR_NOSUCHTABLE')
{
print '<tr><td colspan="2"><font class="error">'.$sql.' : '.$db->lasterror()."</font></td></tr>\n";
}
}
}
}
} }
} }

View File

@ -345,22 +345,42 @@ class DoliDb
*/ */
function connect($host, $login, $passwd, $name, $port=0) function connect($host, $login, $passwd, $name, $port=0)
{ {
if (!$name){ // use pg_connect() instead of pg_pconnect():
$name="postgres"; // To us persistent connection because this one cost 1ms, non persistent cost 30ms
$this->db = false;
// connections parameters must be protected (only \ and ' according to pg_connect() manual)
$host = str_replace(array("\\", "'"), array("\\\\", "\\'"), $host);
$login = str_replace(array("\\", "'"), array("\\\\", "\\'"), $login);
$passwd = str_replace(array("\\", "'"), array("\\\\", "\\'"), $passwd);
$name = str_replace(array("\\", "'"), array("\\\\", "\\'"), $name);
$port = str_replace(array("\\", "'"), array("\\\\", "\\'"), $port);
//if (! $name) $name="postgres";
// try first Unix domain socket (local)
if (! $host || $host == "" || $host == "localhost")
{
$con_string = "dbname='".$name."' user='".$login."' password='".$passwd."'";
$this->db = pg_connect($con_string);
} }
if (!$port){
$port=5432; // if local connection failed or not requested, use TCP/IP
if (! $this->db)
{
if (! $host) $host = "localhost";
if (! $port) $port = 5432;
$con_string = "host='".$host."' port='".$port."' dbname='".$name."' user='".$login."' password='".$passwd."'";
$this->db = pg_connect($con_string);
} }
$con_string = "host=$host port=$port dbname=$name user=$login password=$passwd"; else
//print 'xxx'.$con_string;
//$this->db = pg_pconnect($con_string); // To us persistent connection because this one cost 1ms, non ersisten cost 30ms
$this->db = pg_connect($con_string);
if ($this->db)
{ {
$this->database_name = $name; $this->database_name = $name;
pg_set_error_verbosity($this->db, PGSQL_ERRORS_VERBOSE); // Set verbosity to max pg_set_error_verbosity($this->db, PGSQL_ERRORS_VERBOSE); // Set verbosity to max
} }
return $this->db; return $this->db;
} }