42 if (IsNumber($p_database_id) ==
false || strlen($p_database_id??
"") > 10)
43 die(
"-->Dossier invalide [$p_database_id]");
44 $noalyss_user = (defined(
"noalyss_user")) ? noalyss_user : phpcompta_user;
45 $password = (defined(
"noalyss_password")) ? noalyss_password : phpcompta_password;
46 $port = (defined(
"noalyss_psql_port")) ? noalyss_psql_port : phpcompta_psql_port;
47 $host = (!defined(
"noalyss_psql_host")) ?
'127.0.0.1' : noalyss_psql_host;
48 if (defined(
"MULTI") && MULTI ==
"0") {
52 if ($p_database_id == 0) {
53 $l_dossier = sprintf(
"%saccount_repository", strtolower(
domaine));
55 $l_dossier = sprintf(
"%sdossier%d", strtolower(
domaine), $p_database_id);
57 $l_dossier = sprintf(
"%smod%d", strtolower(
domaine), $p_database_id);
58 }
else if (
$p_type ==
'template') {
59 $l_dossier =
'template1';
61 throw new Exception(
'Connection invalide');
65 parent::__construct($noalyss_user, $password, $l_dossier, $host, $port);
68 $this->
exec_sql(
'set search_path to public,comptaproc,pg_catalog;');
70 $this->
exec_sql(
'set DateStyle to ISO, MDY;');
84 $oid = $this->
upload(
'pj');
89 $ret = $this->
exec_sql(
"select jr_pj from jrn where jr_grpt_id=$seq");
90 if (pg_num_rows(
$ret) != 0) {
91 $r = pg_fetch_array(
$ret, 0);
92 $old_oid =
$r[
'jr_pj'];
93 if (strlen($old_oid??
"") != 0)
97 $this->
exec_sql(
"update jrn set jr_pj=$1 , jr_pj_name=$2,
98 jr_pj_type=$3 where jr_grpt_id=$4",
99 array($oid, $_FILES[
'pj'][
'name'], $_FILES[
'pj'][
'type'],
$seq));
130 echo _(
'Base de donnée vide');
134 $succeed =
"<span style=\"font-size:18px;color:green\">✓</span>";
135 echo
'<ul style="list-type-style:square">';
136 for (
$i = 4;
$i <= $MaxVersion;
$i++) {
141 $this->
exec_sql(
'ALTER TABLE amortissement.amortissement_histo
142 ADD CONSTRAINT internal_fk FOREIGN KEY (jr_internal) REFERENCES jrn (jr_internal)
143 ON UPDATE CASCADE ON DELETE SET NULL');
146 echo
"<li>Patching " . $p_name .
147 " from the version " . $this->
get_version() .
" to $to ";
149 $this->
execute_script(NOALYSS_INCLUDE .
'/sql/patch/upgrade' .
$i .
'.sql');
152 if ( DEBUGNOALYSS == 0)
156 $sql =
"select jrn_def_id from jrn_def ";
161 $sql = sprintf(
"create sequence s_jrn_%d",
$row[
'jrn_def_id']);
169 $Res2 = $this->
exec_sql(
'select coalesce(max(jr_grpt_id),1) as l from jrn');
170 $Max2 = pg_num_rows($Res2);
172 $Row = pg_fetch_array($Res2, 0);
175 $this->
exec_sql(
"select setval('s_grpt',$M,true)");
180 $this->
execute_script(NOALYSS_INCLUDE .
'/sql/patch/upgrade17.sql');
181 $max = $this->
get_value(
'select last_value from s_jnt_fic_att_value');
186 if ($i == 30 && $p_name ==
"mod") {
187 $a_seq = array(
's_jrn',
's_jrn_op',
's_centralized',
188 's_stock_goods',
'c_order',
's_central');
189 foreach ($a_seq as
$seq) {
190 $sql = sprintf(
"select setval('%s',1,false)",
$seq);
193 $sql =
"select jrn_def_id from jrn_def ";
198 $sql = sprintf(
"select setval('s_jrn_%d',1,false)",
$row[
'jrn_def_id']);
204 $res = $this->
exec_sql(
"select pr_value from parameter where pr_id='MY_COUNTRY'");
205 $country = pg_fetch_result(
$res, 0, 0);
206 $this->
execute_script(NOALYSS_INCLUDE .
"/sql/patch/upgrade36." . $country .
".sql");
207 $this->
exec_sql(
'update tmp_pcmn set pcm_type=find_pcm_type(pcm_val)');
210 $res = $this->
exec_sql(
"select pr_value from parameter where pr_id='MY_COUNTRY'");
211 $country = pg_fetch_result(
$res, 0, 0);
212 if ($country ==
'BE')
213 $this->
exec_sql(
"insert into parm_code values ('SUPPLIER',440,'Poste par défaut pour les fournisseurs')");
214 if ($country ==
'FR')
215 $this->
exec_sql(
"insert into parm_code values ('SUPPLIER',400,'Poste par défaut pour les fournisseurs')");
218 $country = $this->
get_value(
"select pr_value from parameter where pr_id='MY_COUNTRY'");
219 $this->
execute_script(NOALYSS_INCLUDE .
"/sql/patch/upgrade61." . $country .
".sql");
225 $country = $this->
get_value(
"select pr_value from parameter where pr_id='MY_COUNTRY'");
226 $this->
execute_script(NOALYSS_INCLUDE .
"/sql/patch/upgrade141." . $country .
".sql");
229 if (DEBUGNOALYSS == 0 )
247 $sys_name = sprintf(
"%sdossier%d", strtolower(
domaine),
$p_id);
250 $sys_name = sprintf(
"%smod%d", strtolower(
domaine),
$p_id);
254 throw new Exception(__FILE__ .
" format_name invalid type " .
$p_type . __LINE__);
echo_error($p_log, $p_line="", $p_message="")
log error into the /tmp/noalyss_error.log it doesn't work on windows
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
This class allow you to connect to the postgresql database, execute sql, retrieve data.
alter_seq($p_name, $min)
alter the sequence value
$sql
last SQL stmt executed
get_value($p_sql, $p_array=null)
return the value of the sql, the sql will return only one value with the value
size($p_ret=null)
return the number of rows found by the last query, or the number of rows from $p_ret
exec_sql($p_string, $p_array=null)
send a sql string to the database
lo_unlink($p_oid)
wrapper for the function pg_lo_unlink
execute_script($script)
Execute a sql script.
exist_table($p_name, $p_schema='public')
test if a table exist
contains the class for connecting to Noalyss
__construct($p_database_id=0, $p_type='dos')
constructor
format_name($p_id, $p_type)
return the name of the database with the domain name
get_version()
Get version of a database, the content of the table version.
apply_patch($p_name)
loop to apply all the path to a folder or a template Upgrade check if the folder $p_name needs to be ...