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)
{
global $conf;
$this->cats = array();
// Charge tableau des meres
@ -643,6 +645,7 @@ class Categorie
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_association as ca";
$sql.= " ON c.rowid=ca.fk_categorie_mere";
$sql.= " WHERE c.type = ".$type;
$sql.= " AND c.entity = ".$conf->entity;
$sql.= " ORDER BY c.label, c.rowid";
dol_syslog("Categorie::get_full_arbo get category list sql=".$sql, LOG_DEBUG);
@ -782,7 +785,10 @@ class Categorie
*/
function get_all_categories ()
{
global $conf;
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie";
$sql.= " WHERE entity = ".$conf->entity;
$res = $this->db->query($sql);
if ($res)
@ -808,8 +814,12 @@ class Categorie
*/
function get_nb_categories ()
{
global $conf;
$sql = "SELECT count(rowid)";
$sql.= " FROM ".MAIN_DB_PREFIX."categorie";
$sql.= " WHERE entity = ".$conf->entity;
$res = $this->db->query($sql);
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
{
// Suppression vieilles contraintes sans noms et en doubles
// Les contraintes indesirables ont un nom qui commence par 0_ ou se termine par ibfk_999
$listtables=array( 'llx_adherent_options',
'llx_bank_class',
'llx_c_ecotaxe',
'llx_c_methode_commande_fournisseur', // table renamed
'llx_c_input_method');
$listtables = $db->DDLListTables($conf->db->name,'');
foreach ($listtables as $val)
{
//print "x".$val."<br>";
$sql = "SHOW CREATE TABLE ".$val;
$resql = $db->query($sql);
if ($resql)
{
$values=$db->fetch_array($resql);
$i=0;
$createsql=$values[1];
while (preg_match('/CONSTRAINT `(0_[0-9a-zA-Z]+|[_0-9a-zA-Z]+_ibfk_[0-9]+)`/i',$createsql,$reg) && $i < 100)
{
$sqldrop="ALTER TABLE ".$val." DROP FOREIGN KEY ".$reg[1];
$resqldrop = $db->query($sqldrop);
if ($resqldrop)
{
print '<tr><td colspan="2">'.$sqldrop.";</td></tr>\n";
}
$createsql=preg_replace('/CONSTRAINT `'.$reg[1].'`/i','XXX',$createsql);
$i++;
}
$db->free($resql);
}
else
{
if ($db->lasterrno() != 'DB_ERROR_NOSUCHTABLE')
{
print '<tr><td colspan="2"><font class="error">'.$sql.' : '.$db->lasterror()."</font></td></tr>\n";
}
}
}
// Les contraintes indesirables ont un nom qui commence par 0_ ou se termine par ibfk_999
$listtables=array(
MAIN_DB_PREFIX.'adherent_options',
MAIN_DB_PREFIX.'bank_class',
MAIN_DB_PREFIX.'c_ecotaxe',
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)
{
// Database prefix filter
if (preg_match('/^'.MAIN_DB_PREFIX.'/', $val))
{
//print "x".$val."<br>";
$sql = "SHOW CREATE TABLE ".$val;
$resql = $db->query($sql);
if ($resql)
{
$values=$db->fetch_array($resql);
$i=0;
$createsql=$values[1];
while (preg_match('/CONSTRAINT `(0_[0-9a-zA-Z]+|[_0-9a-zA-Z]+_ibfk_[0-9]+)`/i',$createsql,$reg) && $i < 100)
{
$sqldrop="ALTER TABLE ".$val." DROP FOREIGN KEY ".$reg[1];
$resqldrop = $db->query($sqldrop);
if ($resqldrop)
{
print '<tr><td colspan="2">'.$sqldrop.";</td></tr>\n";
}
$createsql=preg_replace('/CONSTRAINT `'.$reg[1].'`/i','XXX',$createsql);
$i++;
}
$db->free($resql);
}
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)
{
if (!$name){
$name="postgres";
// use pg_connect() instead of pg_pconnect():
// 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";
//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)
else
{
$this->database_name = $name;
pg_set_error_verbosity($this->db, PGSQL_ERRORS_VERBOSE); // Set verbosity to max
}
return $this->db;
}