forked from Wavyzz/dolibarr
New: Add postgresql function to resynchronize sequences
This commit is contained in:
@@ -563,7 +563,7 @@ class DoliDBPgsql
|
|||||||
$this->lasterror = $this->error();
|
$this->lasterror = $this->error();
|
||||||
$this->lasterrno = $this->errno();
|
$this->lasterrno = $this->errno();
|
||||||
}
|
}
|
||||||
dol_syslog(get_class($this)."::query SQL error usesavepoint = ".$usesavepoint." - ".$query." ".$this->errno(), LOG_WARNING);
|
dol_syslog(get_class($this)."::query SQL error usesavepoint = ".$usesavepoint." - ".$query." - ".pg_last_error($this->db)." = ".$this->errno(), LOG_WARNING);
|
||||||
//print "\n>> ".$query."<br>\n";
|
//print "\n>> ".$query."<br>\n";
|
||||||
//print '>> '.$this->lasterrno.' - '.$this->lasterror.' - '.$this->lastqueryerror."<br>\n";
|
//print '>> '.$this->lasterrno.' - '.$this->lasterror.' - '.$this->lastqueryerror."<br>\n";
|
||||||
|
|
||||||
|
|||||||
@@ -429,22 +429,21 @@ abstract class DolibarrModules
|
|||||||
$entity = ((! empty($this->always_enabled) || ! empty($this->core_enabled)) ? 0 : $conf->entity);
|
$entity = ((! empty($this->always_enabled) || ! empty($this->core_enabled)) ? 0 : $conf->entity);
|
||||||
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
|
||||||
$sql.= " WHERE ".$this->db->decrypt('name')." = '".$this->const_name."'";
|
$sql.= " WHERE name = '".$this->db->encrypt($this->const_name)."'";
|
||||||
$sql.= " AND entity in (0, ".$entity.")";
|
$sql.= " AND entity in (0, ".$entity.")";
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::_active sql=".$sql, LOG_DEBUG);
|
dol_syslog(get_class($this)."::_active sql=".$sql, LOG_DEBUG);
|
||||||
$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
|
if (! $resql) $err++;
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible,entity) VALUES";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible,entity) VALUES";
|
||||||
$sql.= " (".$this->db->encrypt($this->const_name,1);
|
$sql.= " ('".$this->db->encrypt($this->const_name)."'";
|
||||||
$sql.= ",".$this->db->encrypt('1',1);
|
$sql.= ",".$this->db->encrypt('1',1);
|
||||||
$sql.= ",0,".$entity.")";
|
$sql.= ",0,".$entity.")";
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::_active sql=".$sql, LOG_DEBUG);
|
dol_syslog(get_class($this)."::_active sql=".$sql, LOG_DEBUG);
|
||||||
if (!$this->db->query($sql))
|
$resql=$this->db->query($sql);
|
||||||
{
|
if (! $resql) $err++;
|
||||||
$err++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $err;
|
return $err;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,3 +46,6 @@ CREATE OR REPLACE FUNCTION DAY(TIMESTAMP without TIME ZONE) RETURNS INTEGER AS $
|
|||||||
CREATE OR REPLACE FUNCTION DAY(TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$ SELECT EXTRACT(DAY FROM $1)::INTEGER; $$ LANGUAGE SQL STABLE;
|
CREATE OR REPLACE FUNCTION DAY(TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$ SELECT EXTRACT(DAY FROM $1)::INTEGER; $$ LANGUAGE SQL STABLE;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION DAY(DATE) RETURNS INTEGER AS $$ SELECT EXTRACT(DAY FROM $1)::INTEGER; $$ LANGUAGE SQL IMMUTABLE;
|
CREATE OR REPLACE FUNCTION DAY(DATE) RETURNS INTEGER AS $$ SELECT EXTRACT(DAY FROM $1)::INTEGER; $$ LANGUAGE SQL IMMUTABLE;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION rebuilt_sequences() RETURNS integer as $body$ DECLARE sequencedefs RECORD; c integer ; BEGIN FOR sequencedefs IN SELECT DISTINCT constraint_column_usage.table_name as tablename, constraint_column_usage.table_name as tablename, constraint_column_usage.column_name as columnname, replace(replace(columns.column_default,'''::regclass)',''),'nextval(''','') as sequencename from information_schema.constraint_column_usage, information_schema.columns where constraint_column_usage.table_schema ='public' AND columns.table_schema = 'public' AND columns.table_name=constraint_column_usage.table_name AND constraint_column_usage.column_name IN ('rowid','id') AND constraint_column_usage.column_name = columns.column_name AND columns.column_default is not null LOOP EXECUTE 'select max('||sequencedefs.columnname||') from ' || sequencedefs.tablename INTO c; IF c is null THEN c = 0; END IF; IF c is not null THEN c = c+ 1; END IF; EXECUTE 'alter sequence ' || sequencedefs.sequencename ||' restart with ' || c; END LOOP; RETURN 1; END; $body$ LANGUAGE PLPGSQL;
|
||||||
|
|||||||
Reference in New Issue
Block a user