noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
DatabaseCore Class Reference

This class allow you to connect to the postgresql database, execute sql, retrieve data. More...

+ Inheritance diagram for DatabaseCore:
+ Collaboration diagram for DatabaseCore:

Public Member Functions

 __construct ($p_user, $p_password, $p_dbname, $p_host, $p_port)
 !< $dbuser(string) Database user
 
 __toString ()
 
 alter_seq ($p_name, $min)
 alter the sequence value
 
 clean_orphan_lob ()
 Find all lob and remove those which are not used by any tables.
 
 clear_all_prepare ()
 clear all prepare stmt
 
 clear_prepare ($sql_name)
 clear a prepare stmt
 
 close ()
 wrapper for the function pg_close
 
 commit ()
 Commit the transaction.
 
 count ($p_ret=null)
 synomym for size()
 
 count_sql ($p_sql, $p_array=null)
 Count the number of row returned by a sql statement.
 
 create_sequence ($p_name, $min=1)
 Create a sequence.
 
 exec_sql ($p_string, $p_array=null)
 send a sql string to the database
 
 execute ($p_string, $p_array)
 wrapper for the function pg_execute
 
 execute_script ($script)
 Execute a sql script.
 
 exist_blob ($p_oid)
 check if the large object exists
 
 exist_column ($col, $table, $schema)
 Check if a column exists in a table.
 
 exist_database ($p_name)
 Count the database name in a system view.
 
 exist_schema ($p_name)
 test if a schema exists
 
 exist_sequence ($p_name)
 test if a sequence exist
 
 exist_table ($p_name, $p_schema='public')
 test if a table exist
 
 exist_view ($p_name)
 
 fetch ($p_indice, $p_mode=PGSQL_ASSOC)
 fetch the $p_indice array from the last query
 
 get_affected ()
 return the number of rows affected by the previous query
 
 get_array ($p_sql, $p_array=null, $p_mode=PGSQL_ASSOC)
 purpose return the result of a sql statment in a array
 
 get_current_seq ($p_seq)
 get the current sequence value
 
 get_db ()
 
 get_dbhost ()
 
 get_dbname ()
 
 get_dbport ()
 
 get_dbuser ()
 
 get_encoding ()
 
 get_is_open ()
 
 get_name ()
 return the name of the current database
 
 get_next_seq ($p_seq)
 get the next sequence value
 
 get_ret ()
 
 get_row ($p_sql, $p_array=NULL)
 Returns only one row from a query.
 
 get_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
 
 is_prepare ($query_name)
 Check if a prepared statement already exists or not.
 
 lo_export ($p_oid, $tmp_file)
 wrapper for the function pg_lo_export
 
 lo_import ($p_filename)
 wrapper for the function pg_lo_export
 
 lo_read ($oid)
 read a Large object with data content in a binary
 
 lo_replace ($binary_data, $oid)
 replace a Large object with data content in a binary
 
 lo_unlink ($p_oid)
 wrapper for the function pg_lo_unlink
 
 lo_write ($binary_data)
 large_object writee: create a Large object if oid is not given with data content in a binaray
 
 make_array ($p_sql, $p_null=0, $p_array=null)
 make a array with the sql.
 
 make_list ($sql, $p_array=null)
 create a string containing the value separated by comma for use in a SQL in statement
 
 prepare ($p_string, $p_sql)
 wrapper for the function pg_prepare
 
 query_to_csv ($ret, $aheader)
 with the handle of a successull query, echo each row into CSV and send it directly to output.
 
 rollback ()
 rollback the current transaction
 
 search_sql_inject ($p_sql)
 FInd if a SQL Select has a SQL stmt to inject or damage Data When a SELECT SQL string is build, this string could contain a SQL attempt to damage data, so the statement DELETE TRUNCATE ... are forbidden.
 
 set_db ($db)
 
 set_encoding ($p_charset)
 
 set_is_open ($is_open)
 
 set_ret ($ret)
 
 set_sql ($sql)
 last SQL stmt executed
 
 size ($p_ret=null)
 return the number of rows found by the last query, or the number of rows from $p_ret
 
 start ()
 : start a transaction
 
 status ()
 get the transaction status : The status can be
 
 upload ($p_name, $only_oid=false)
 Save one or several documents into the database , it just puts the file in the database and returns the corresponding OID , the mimetype , size ... of the document must be set in the calling function.
 
 verify ()
 

Static Public Member Functions

static escape_string ($p_string)
 wrapper for the function pg_escape_string
 
static fetch_all ($ret, $p_mode=PGSQL_ASSOC)
 wrapper for the function pg_fetch_all
 
static fetch_array ($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
 wrapper for the function pg_fetch_array
 
static fetch_result ($ret, $p_row=0, $p_col=0)
 wrapper for the function pg_fetch_all
 
static fetch_row ($ret, $p_row)
 wrapper for the function pg_fetch_row
 
static nb_column ($p_ret)
 Returns the number of columns in a ret.
 
static num_row ($ret)
 wrapper for the function pg_num_rows
 
static test_me ()
 

Data Fields

 $array
 
 $sql
 last SQL stmt executed
 

Protected Attributes

 $db
 database connection
 
 $dbhost
 !< $dbport (int) Database port
 
 $dbname
 
 $dbport
 !< $dbname (string) Database name
 
 $dbuser
 !< $dbhost(string) Database host
 
 $is_open
 
 $ret
 return value
 

Detailed Description

This class allow you to connect to the postgresql database, execute sql, retrieve data.

Definition at line 35 of file database_core.class.php.

Constructor & Destructor Documentation

◆ __construct()

DatabaseCore::__construct ( $p_user,
$p_password,
$p_dbname,
$p_host,
$p_port )

!< $dbuser(string) Database user

Connect to a database return an connx to db or false if it fails

Parameters
string$p_userUsername
type$p_passwordUser's password
$p_dbnamename of the database to connect
type$p_hostHost of DB
type$p_portPort of DB

Definition at line 59 of file database_core.class.php.

60 {
61 $this->db = @pg_connect("dbname=$p_dbname host='$p_host' user='$p_user'
62 password='$p_password' port=$p_port");
63 if ($this->db == false) {
64 if ( DEBUGNOALYSS > 0 ) {
65
66 echo '<h2 class="error">'._('Impossible de se connecter à postgreSql').'</h2>';
67 echo '<p>';
68 echo _("Vos paramètres sont incorrectes").": <br>";
69 echo "<br>";
70 printf (_("base de donnée = %s"), $p_dbname)."<br>";
71 printf (_("Port %s"),$p_port )."<br>";
72 printf ( _("Utilisateur : %s"),$p_user )."<br>";
73 echo '</p>';
74
75 die();
76 } else {
77 echo '<h2 class="error">' . _('Erreur de connexion !') . '</h2>';
78 $this->is_open = false;
79 throw new Exception(_('Erreur Connexion'));
80 }
81 }
82 $this->dbport=$p_port;
83 $this->dbname=$p_dbname;
84 $this->dbhost=$p_host;
85 $this->dbuser=$p_user;
86 $this->is_open = TRUE;
87 $this->sql="";
88
89 }
_("actif, passif,charge,...")
$SecUser db

References _, and db.

Member Function Documentation

◆ __toString()

DatabaseCore::__toString ( )
Parameters

return

Note
See also

Reimplemented in Database.

Definition at line 1009 of file database_core.class.php.

1010 {
1011 return "database ";
1012 }

◆ alter_seq()

DatabaseCore::alter_seq ( $p_name,
$min )

alter the sequence value

Parameters
$p_namename of the sequence
$minthe start value of the sequence

Definition at line 315 of file database_core.class.php.

316 {
317 if ($min < 1)
318 $min = 1;
319 $Res = $this->exec_sql("alter sequence $p_name restart $min");
320 }
exec_sql($p_string, $p_array=null)
send a sql string to the database

References $min, $Res, and exec_sql().

Referenced by Database\apply_patch().

+ Here is the call graph for this function:

◆ clean_orphan_lob()

DatabaseCore::clean_orphan_lob ( )

Find all lob and remove those which are not used by any tables.

Definition at line 1040 of file database_core.class.php.

1041 {
1042 // find all columns of type lob
1043 $sql = "
1044 select table_schema,table_name,column_name
1045 from
1046 information_schema.columns
1047 where table_schema not in ('information_schema','pg_catalog')
1048 and data_type='oid'";
1049 $all_lob = "
1050 select oid,'N' as used from pg_largeobject_metadata
1051 ";
1052 $a_table = $this->get_array($sql);
1053 $a_lob = $this->get_array($all_lob);
1054 if ($a_table == false || $a_lob == false) return;
1055 // for each lob
1056 $nb_lob = count($a_lob);
1057 $nb_table = count($a_table);
1058 for ($i = 0; $i < $nb_lob; $i++) {
1059 $lob = $a_lob[$i]['oid'];
1060 if ($a_lob[$i]['used'] == 'Y') continue;
1061 for ($j = 0; $j < $nb_table; $j++) {
1062 if ($a_lob[$i]['used'] == 'Y') continue;
1063 $check = $this->get_value(" select count(*) from " .
1064 $a_table[$j]['table_schema'] . "." . $a_table[$j]['table_name'] .
1065 " where " .
1066 $a_table[$j]['column_name'] . "=$1", array($lob));
1067 if ($check != 0)
1068 $a_lob[$i]['used'] = 'Y';
1069
1070 }
1071 }
1072 for ($i = 0; $i < $nb_lob; $i++) {
1073 if ($a_lob[$i]['used'] == 'Y') continue;
1074 $this->lo_unlink($a_lob[$i]['oid']);
1075 }
1076 }
$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
count($p_ret=null)
synomym for size()
lo_unlink($p_oid)
wrapper for the function pg_lo_unlink
get_array($p_sql, $p_array=null, $p_mode=PGSQL_ASSOC)
purpose return the result of a sql statment in a array
$check

References $check, $i, $sql, count(), get_array(), get_value(), and lo_unlink().

+ Here is the call graph for this function:

◆ clear_all_prepare()

DatabaseCore::clear_all_prepare ( )

clear all prepare stmt

See also
DatabaseCore\is_prepare
DatabaseCore\execute
DatabaseCore\prepare

Definition at line 1171 of file database_core.class.php.

1172 {
1173 pg_exec($this->db,'DEALLOCATE ALL');
1174 }

References db.

◆ clear_prepare()

DatabaseCore::clear_prepare ( $sql_name)

clear a prepare stmt

See also
DatabaseCore\is_prepare
DatabaseCore\execute
DatabaseCore\prepare
Parameters
$sql_namename of the prepare SQL

Definition at line 1161 of file database_core.class.php.

1162 {
1163 pg_exec($this->db,sprintf('DEALLOCATE "%s"'),DatabaseCore::escape_string($sql_name));
1164 }
static escape_string($p_string)
wrapper for the function pg_escape_string

References db, and escape_string().

+ Here is the call graph for this function:

◆ close()

DatabaseCore::close ( )

wrapper for the function pg_close

Definition at line 995 of file database_core.class.php.

996 {
997 if ($this->is_open) pg_close($this->db);
998 $this->is_open = FALSE;
999 }

References db.

◆ commit()

DatabaseCore::commit ( )

Commit the transaction.

Definition at line 295 of file database_core.class.php.

296 {
297 if (!$this->is_open) return;
298 $Res = $this->exec_sql("commit");
299 }

References $Res, and exec_sql().

Referenced by lo_read(), lo_replace(), lo_write(), and upload().

+ Here is the call graph for this function:

◆ count()

DatabaseCore::count ( $p_ret = null)

synomym for size()

Definition at line 441 of file database_core.class.php.

442 {
443 return $this->size($p_ret);
444 }
$name size

References size.

Referenced by clean_orphan_lob(), Card_Property\get_attribute(), get_row(), make_list(), and query_to_csv().

◆ count_sql()

DatabaseCore::count_sql ( $p_sql,
$p_array = null )

Count the number of row returned by a sql statement.

Parameters
$p_sqlsql string
$p_arrayif not null we use the safer pg_query_params

Definition at line 255 of file database_core.class.php.

256 {
257 $r_sql = $this->exec_sql($p_sql, $p_array);
258 return pg_num_rows($r_sql);
259 }

References $p_array, and exec_sql().

Referenced by exist_schema(), exist_sequence(), exist_table(), and exist_view().

+ Here is the call graph for this function:

◆ create_sequence()

DatabaseCore::create_sequence ( $p_name,
$min = 1 )

Create a sequence.

Parameters
string$p_nameSequence Name
int$minstarting value

Definition at line 527 of file database_core.class.php.

528 {
529 if ($min < 1)
530 $min = 1;
531 $sql = "create sequence " . $p_name . " minvalue $min";
532 $this->exec_sql($sql);
533 }

References $min, $sql, and exec_sql().

+ Here is the call graph for this function:

◆ escape_string()

static DatabaseCore::escape_string ( $p_string)
static

wrapper for the function pg_escape_string

Parameters
$p_stringis the string to escape
Returns
escaped string

Definition at line 984 of file database_core.class.php.

985 {
986 static $cn=null;
987 if ( $cn==null) $cn=new Database();
988 return pg_escape_string($cn->db,$p_string);
989 }

References $cn.

Referenced by clear_prepare(), Acc_Ledger_Search\list_operation(), Anc_Acc_List\load_anc_account(), Anc_Acc_List\load_anc_card(), Anc_Acc_List\load_card(), Anc_Table\load_card(), Anc_Acc_List\load_poste(), Anc_Table\load_poste(), Follow_Up\myList(), and Noalyss_User\set_session_var().

◆ exec_sql()

DatabaseCore::exec_sql ( $p_string,
$p_array = null )

send a sql string to the database

Parameters
$p_stringsql string
$p_arrayarray for the SQL string (see pg_query_params)
Returns
the result of the query, a resource or false if an error occured

Definition at line 203 of file database_core.class.php.

204 {
205 try {
206 if (!$this->is_open) throw new Exception(' Database is closed');
207 $this->sql = $p_string;
208 $this->array = $p_array;
209
210 if ($p_array == null) {
211 if ( DEBUGNOALYSS == 0 )
212 $this->ret = pg_query($this->db, $p_string);
213 else
214 $this->ret = @pg_query($this->db, $p_string);
215 } else {
216 $a = is_array($p_array);
217 if (!is_array($p_array)) {
218 throw new Exception(_("Erreur : exec_sql attend un array"));
219 }
220 if ( DEBUGNOALYSS == 0 )
221 $this->ret =@pg_query_params($this->db, $p_string, $p_array);
222 else
223 $this->ret = pg_query_params($this->db, $p_string, $p_array);
224 }
225 if ($this->ret == false) {
226 $str_error = pg_last_error($this->db) ;
227 throw new Exception(" SQL ERROR $p_string " . $str_error, 1);
228 }
229 } catch (Exception $a) {
230 if ( DEBUGNOALYSS > 0 ) {
231 print_r($p_string);
232 print_r($p_array);
233 echo $a->getMessage();
234 echo $a->getTraceAsString();
235 echo pg_last_error($this->db);
236 }
237 record_log($a);
238 record_log($p_string);
240 $this->rollback();
241
242 throw new \Exception("exec_sql fails",242,$a);
243 }
244
245 return $this->ret;
246 }
record_log($p_message)
Record an error message into the log file of the server or in the log folder of NOALYSS Record also t...
rollback()
rollback the current transaction

References $a, $p_array, $ret, _, db, record_log(), and rollback().

Referenced by Database\__construct(), alter_seq(), Database\apply_patch(), Extension\clean(), commit(), count_sql(), create_sequence(), execute_script(), get_array(), get_next_seq(), get_value(), Sendmail\increment_mail(), make_array(), rollback(), and start().

+ Here is the call graph for this function:

◆ execute()

DatabaseCore::execute ( $p_string,
$p_array )

wrapper for the function pg_execute

Parameters
$p_stringstring name of the stmt given in pg_prepare function
$p_arraycontains the variables
Note
set this->ret to the return of pg_execute
Returns
return the result of the operation,

Definition at line 948 of file database_core.class.php.

949 {
950 $this->ret = pg_execute($this->db, $p_string, $p_array);
951 return $this->ret;
952 }

References $p_array, $ret, and db.

◆ execute_script()

DatabaseCore::execute_script ( $script)

Execute a sql script.

Parameters
$scriptscript name

Definition at line 327 of file database_core.class.php.

328 {
329
330 if ( DEBUGNOALYSS == 0 ) {
331 ob_start();
332 } else {
333 $debug = fopen("/tmp/debug_execute_script".uniqid().".log", "w+");
334 }
335 $hf = fopen($script, 'r');
336 if ($hf == false) {
337 throw new Exception ('Ne peut ouvrir ' . $script);
338 }
339 printf (" open %s <br>", $script);
340 $sql = "";
341 $flag_function = false;
342 while (!feof($hf)) {
343 $buffer = fgets($hf);
344 $buffer = str_replace('$BODY$', '$_$', $buffer);
345 print $buffer . "<br>";
346 // comment are not execute
347 if (substr($buffer, 0, 2) == "--") {
348 //echo "comment $buffer";
349 continue;
350 }
351 // Blank Lines Are Skipped
352 If (Strlen($buffer) == 0) {
353 //echo "Blank $buffer";
354 Continue;
355 }
356 if (strpos(strtolower($buffer), "create function") === 0) {
357 echo "found a function";
358 $flag_function = true;
359 $sql = $buffer;
360 continue;
361 }
362 if (strpos(strtolower($buffer), "create or replace function") === 0) {
363 echo "found a function";
364 $flag_function = true;
365 $sql = $buffer;
366 continue;
367 }
368 // No semi colon -> multiline command
369 if ($flag_function == false && strpos($buffer, ';') == false) {
370 $sql .= $buffer;
371 continue;
372 }
373 if ($flag_function) {
374 if (strpos(strtolower($buffer), "$$;") === false &&
375 strpos(strtolower($buffer), '$_$;') === false &&
376 strpos(strtolower($buffer), '$function$;') === false &&
377 strpos(strtolower($buffer), 'language plpgsql;') === false &&
378 strpos(strtolower($buffer), 'language plpgsql ;') === false
379 ) {
380 $sql .= $buffer;
381 continue;
382 }
383 } else {
384 // cut the semi colon
385 $buffer = str_replace(';', '', $buffer);
386 }
387 $sql .= $buffer;
388 if ( DEBUGNOALYSS > 0 ) fwrite($debug, $sql);
389 if ($this->exec_sql($sql) == false) {
390
391 $this->rollback();
392 if ( DEBUGNOALYSS == 0 )
393 ob_end_clean();
394 print "ERROR : $sql";
395 throw new Exception("ERROR : $sql");
396 }
397 $sql = "";
398 $flag_function = false;
399 print "<hr>";
400 } // while (feof)
401 fclose($hf);
402 if ( DEBUGNOALYSS == 0 )
403 ob_end_clean();
404 }
print
Type of printing.
$script
Definition popup.php:131

References $script, $sql, exec_sql(), print, and rollback().

Referenced by Database\apply_patch().

+ Here is the call graph for this function:

◆ exist_blob()

DatabaseCore::exist_blob ( $p_oid)

check if the large object exists

Parameters
$p_oidof the large object
Returns
return true if the large obj exist or false if not

Definition at line 596 of file database_core.class.php.

597 {
598 $r = $this->get_value('select count(*) from pg_largeobject_metadata where oid=$1'
599 , array($p_oid));
600 if ($r > 0)
601 return true;
602 else
603 return false;
604 }
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r

References $r, and get_value().

Referenced by lo_unlink().

+ Here is the call graph for this function:

◆ exist_column()

DatabaseCore::exist_column ( $col,
$table,
$schema )

Check if a column exists in a table.

Parameters
$col: column name
$table:table name
$schema:schema name, default public
Returns
true or false

Definition at line 570 of file database_core.class.php.

571 {
572 $r = $this->get_value('select count(*) from information_schema.columns where table_name=lower($1) and column_name=lower($2) and table_schema=lower($3)', array($col, $table, $schema));
573 if ($r > 0)
574 return true;
575 return false;
576 }
$table
Definition menu.inc.php:104

References $r, $table, and get_value().

+ Here is the call graph for this function:

◆ exist_database()

DatabaseCore::exist_database ( $p_name)

Count the database name in a system view.

Parameters
$p_namestring database name
Returns
number of database found (normally 0 or 1)

Definition at line 584 of file database_core.class.php.

585 {
586 $database_exist = $this->get_value('select count(*)
587 from pg_catalog.pg_database where datname = lower($1)', array($p_name));
588 return $database_exist;
589 }

References get_value().

+ Here is the call graph for this function:

◆ exist_schema()

DatabaseCore::exist_schema ( $p_name)

test if a schema exists

Returns
true if the schemas exists otherwise false

Definition at line 624 of file database_core.class.php.

625 {
626 $r = $this->count_sql("select nspname from pg_namespace where nspname=lower($1)", array($p_name));
627 if ($r == 0)
628 return false;
629 return true;
630 }
count_sql($p_sql, $p_array=null)
Count the number of row returned by a sql statement.

References $r, and count_sql().

Referenced by Database\__construct(), Database\apply_patch(), and Extension\clean().

+ Here is the call graph for this function:

◆ exist_sequence()

DatabaseCore::exist_sequence ( $p_name)

test if a sequence exist

Definition at line 540 of file database_core.class.php.

541 {
542 $r = $this->count_sql("select relname from pg_class where relname=lower($1)", array($p_name));
543 if ($r == 0)
544 return false;
545 return true;
546 }

References $r, and count_sql().

+ Here is the call graph for this function:

◆ exist_table()

DatabaseCore::exist_table ( $p_name,
$p_schema = 'public' )

test if a table exist

Parameters
$p_nametable name
$schemaname of the schema default public
Returns
true if a table exist otherwise false

Definition at line 555 of file database_core.class.php.

556 {
557 $r = $this->count_sql("select table_name from information_schema.tables where table_schema=$1 and table_name=lower($2)", array($p_schema, $p_name));
558 if ($r == 0)
559 return false;
560 return true;
561 }

References $r, and count_sql().

Referenced by Database\apply_patch().

+ Here is the call graph for this function:

◆ exist_view()

DatabaseCore::exist_view ( $p_name)

Definition at line 611 of file database_core.class.php.

612 {
613 $r = $this->count_sql("select viewname from pg_views where viewname=lower($1)", array($p_name));
614 if ($r == 0)
615 return false;
616 return true;
617 }

References $r, and count_sql().

+ Here is the call graph for this function:

◆ fetch()

DatabaseCore::fetch ( $p_indice,
$p_mode = PGSQL_ASSOC )

fetch the $p_indice array from the last query

Parameters
$p_modeis PGSQL_ASSOC, PGSQL_BOTH or PGSQL_NUM (default PGSQL_ASSOC)
$p_indiceindex

Definition at line 413 of file database_core.class.php.

414 {
415 if ($this->ret == false)
416 throw new Exception('this->ret is empty');
417 return pg_fetch_array($this->ret, $p_indice,$p_mode);
418 }

◆ fetch_all()

◆ fetch_array()

static DatabaseCore::fetch_array ( $ret,
$p_indice = 0,
$p_mode = PGSQL_ASSOC )
static

wrapper for the function pg_fetch_array

Parameters
$retis the result of a pg_exec
$p_indiceis the index
$p_modeis PGSQL_ASSOC, PGSQL_BOTH or PGSQL_NUM (default PGSQL_ASSOC)
Returns
$array of column

Definition at line 876 of file database_core.class.php.

877 {
878 return pg_fetch_array($ret, $p_indice,$p_mode);
879 }

References $ret.

Referenced by Noalyss_Parameter_Folder\__construct(), Card_Property\build_input(), Noalyss_User\Check(), Document_Modele\Delete(), Manage_Table_SQL\display_table(), Periode_Ledger_Table\display_table(), Fiche_Def\DisplayAttribut(), Print_Ledger_Detail_Item\export(), Print_Ledger_Simple\export(), Print_Ledger_Simple_Without_Vat\export(), Acc_Ledger_History_Purchase\export_csv(), Acc_Ledger_History_Sale\export_csv(), Follow_Up\export_csv_detail(), Document\export_file(), Acc_Operation\find_tiers(), Acc_Reconciliation\get(), Anc_Plan\get(), Document\get(), Fiche_Def\get(), Fiche_Def\get_all(), Acc_Reconciliation\get_amount_noautovat(), Fiche_Def\get_attr_min(), Fiche\get_bk_balance(), Customer\get_by_account(), Supplier\get_by_account(), Fiche\get_by_category(), Fiche_Def\get_by_category(), Acc_Operation\get_data(), Periode\get_date_limit(), Acc_Operation\get_internal(), Acc_Account_Ledger\get_name(), Acc_Ledger\get_name(), Acc_Report\get_row(), Fiche\get_row_result_deprecated(), Acc_Account_Ledger\get_row_sql_deprecated(), Acc_Account_Ledger\get_solde(), Acc_Account_Ledger\get_solde_detail(), Fiche\get_solde_detail(), Acc_Ledger\get_type(), html_min_page_start(), html_page_start(), isValid_deprecrated(), Acc_Ledger_Search\list_operation(), Acc_Ledger_Search\list_operation_to_reconcile(), Acc_Ledger\listing(), Acc_Bilan\load(), Acc_Ledger_Info\load(), Acc_Parm_Code\load(), Acc_Payment\load(), Anc_Group\load(), Card_Property\load(), Dossier\load(), Noalyss_User\load(), Todo_List\load(), Fiche_Def\load_attribute(), Fiche_Def\myList(), query_to_csv(), Document_Modele\Save(), Document\send(), Profile_Menu\sub_menu(), Card_Property\update(), Document_Modele\update(), Anc_Operation\update_from_jrnx(), Dossier\upgrade(), Customer\VatListing(), Acc_Bilan\verify(), and Acc_Bilan\warning().

◆ fetch_result()

static DatabaseCore::fetch_result ( $ret,
$p_row = 0,
$p_col = 0 )
static

wrapper for the function pg_fetch_all

Parameters
$retis the result of pg_exec (exec_sql)
$p_rowis the indice of the row
$p_colis the indice of the col
Returns
a string or an integer

Definition at line 901 of file database_core.class.php.

902 {
903 return pg_fetch_result($ret, $p_row, $p_col);
904 }

References $p_col, and $ret.

Referenced by Fiche\empty_attribute(), Print_Ledger_Financial\export(), Periode\find_periode(), Periode\get_exercice(), Acc_Account_Ledger\get_row(), Fiche\get_row(), Fiche\get_row_date(), Acc_Ledger_Info\insert(), Todo_List\insert(), Periode\is_centralized(), Acc_Ledger_Info\search_id_internal(), and Acc_Operation\seek_internal().

◆ fetch_row()

static DatabaseCore::fetch_row ( $ret,
$p_row )
static

wrapper for the function pg_fetch_row

Parameters
$retis the result of pg_exec (exec_sql)
$p_rowis the indice of the row
Returns
an array indexed from 0

Definition at line 912 of file database_core.class.php.

913 {
914 return pg_fetch_row($ret, $p_row);
915 }

References $ret.

Referenced by Html_Table\sql2table().

◆ get_affected()

DatabaseCore::get_affected ( )

return the number of rows affected by the previous query

Definition at line 483 of file database_core.class.php.

484 {
485 return Database::num_row($this->ret);
486 }
static num_row($ret)
wrapper for the function pg_num_rows

References num_row().

+ Here is the call graph for this function:

◆ get_array()

DatabaseCore::get_array ( $p_sql,
$p_array = null,
$p_mode = PGSQL_ASSOC )

purpose return the result of a sql statment in a array

Parameters
$p_sqlsql query
$p_arrayif not null we use ExecSqlParam
$p_modeis PGSQL_ASSOC, PGSQL_BOTH or PGSQL_NUM (default PGSQL_ASSOC)
Returns
false if nothing is found

Definition at line 497 of file database_core.class.php.

498 {
499 $r = $this->exec_sql($p_sql, $p_array,$p_mode);
500
501 if (pg_num_rows($r) == 0)
502 return array();
503 $array = pg_fetch_all($r,$p_mode);
504 return $array;
505 }

References $array, $p_array, $r, and exec_sql().

Referenced by clean_orphan_lob(), get_row(), and make_list().

+ Here is the call graph for this function:

◆ get_current_seq()

DatabaseCore::get_current_seq ( $p_seq)

get the current sequence value

Definition at line 265 of file database_core.class.php.

266 {
267 $Res = $this->get_value("select currval('$p_seq') as seq");
268 return $Res;
269 }

References $Res, and get_value().

+ Here is the call graph for this function:

◆ get_db()

DatabaseCore::get_db ( )
Returns
mixed

Definition at line 133 of file database_core.class.php.

134 {
135 return $this->db;
136 }
$db
database connection

References $db.

◆ get_dbhost()

DatabaseCore::get_dbhost ( )

Definition at line 98 of file database_core.class.php.

98 {
99 return $this->dbhost;
100 }
$dbhost
!< $dbport (int) Database port

References $dbhost.

◆ get_dbname()

DatabaseCore::get_dbname ( )

Definition at line 90 of file database_core.class.php.

90 {
91 return $this->dbname;
92 }

References $dbname.

Referenced by Database\__toString().

◆ get_dbport()

DatabaseCore::get_dbport ( )

Definition at line 94 of file database_core.class.php.

94 {
95 return $this->dbport;
96 }
$dbport
!< $dbname (string) Database name

References $dbport.

◆ get_dbuser()

DatabaseCore::get_dbuser ( )

Definition at line 102 of file database_core.class.php.

102 {
103 return $this->dbuser;
104 }
$dbuser
!< $dbhost(string) Database host

References $dbuser.

◆ get_encoding()

DatabaseCore::get_encoding ( )

Definition at line 124 of file database_core.class.php.

125 {
126 return pg_client_encoding($this->db);
127 }

References db.

◆ get_is_open()

DatabaseCore::get_is_open ( )
Returns
mixed

Definition at line 165 of file database_core.class.php.

166 {
167 return $this->is_open;
168 }

References $is_open.

◆ get_name()

DatabaseCore::get_name ( )

return the name of the current database

Returns
false|string

Definition at line 110 of file database_core.class.php.

110 {
111 return pg_dbname($this->db);
112 }

References db.

◆ get_next_seq()

DatabaseCore::get_next_seq ( $p_seq)

get the next sequence value

Definition at line 275 of file database_core.class.php.

276 {
277 $Res = $this->exec_sql("select nextval('$p_seq') as seq");
278 $seq = pg_fetch_array($Res, 0);
279 return $seq['seq'];
280 }

References $Res, $seq, and exec_sql().

+ Here is the call graph for this function:

◆ get_ret()

DatabaseCore::get_ret ( )
Returns
mixed

Definition at line 149 of file database_core.class.php.

150 {
151 return $this->ret;
152 }

References $ret.

◆ get_row()

DatabaseCore::get_row ( $p_sql,
$p_array = NULL )

Returns only one row from a query.

Parameters
string$p_sql
array$p_array
Returns
array , idx = column of the table or null if nothing is found
Exceptions
Exceptionif too many rows are found code 100

Definition at line 514 of file database_core.class.php.

515 {
516 $array = $this->get_array($p_sql, $p_array);
517 if (empty($array)) return null;
518 if (count($array) == 1) return $array[0];
519 throw new Exception(_("Database:get_row retourne trop de lignes"), 100);
520 }

References $array, $p_array, _, count(), and get_array().

+ Here is the call graph for this function:

◆ get_sql()

DatabaseCore::get_sql ( )

last SQL stmt executed

Parameters
string$sql

Definition at line 181 of file database_core.class.php.

182 {
183 return $this->sql;
184 }

References $sql.

◆ get_value()

DatabaseCore::get_value ( $p_sql,
$p_array = null )

return the value of the sql, the sql will return only one value with the value

Parameters
$p_sqlthe sql stmt example :select s_value from document_state where s_id=2
$p_arrayif array is not null we use the ExecSqlParm (safer)
See also
exec_sql
Note
print a warning if several value are found, if only the first value is needed consider using a LIMIT clause
Returns
only the first value or an empty string if nothing is found

Definition at line 460 of file database_core.class.php.

461 {
462 try {
463 $this->ret = $this->exec_sql($p_sql, $p_array);
464 $r = pg_num_rows($this->ret);
465 if ($r == 0)
466 return "";
467 if ($r > 1) {
468 $array = pg_fetch_all($this->ret);
469 throw new Exception("Attention $p_sql retourne " . pg_num_rows($this->ret) . " valeurs " .
470 var_export($p_array, true) . " values=" . var_export($array, true));
471 }
472 $r = pg_fetch_row($this->ret, 0);
473 return $r[0];
474
475 } catch (Exception $ex) {
476 throw($ex);
477 }
478 }
$ex

References $array, $ex, $p_array, $r, and exec_sql().

Referenced by Acc_Account\__construct(), Database\apply_patch(), clean_orphan_lob(), exist_blob(), exist_column(), exist_database(), Card_Property\get_attribute(), get_current_seq(), Sendmail\get_email_sent(), Sendmail\get_max_email(), Database\get_version(), and is_prepare().

+ Here is the call graph for this function:

◆ is_prepare()

DatabaseCore::is_prepare ( $query_name)

Check if a prepared statement already exists or not.

Parameters
string$query_namename of the prepared query
Returns
boolean false is not yet prepared

Definition at line 1083 of file database_core.class.php.

1084 {
1085 $nb_prepared = $this->get_value("select count(*) from pg_prepared_statements where name=$1", [$query_name]);
1086 if ($nb_prepared == 0) return FALSE;
1087 return TRUE;
1088 }

References get_value().

+ Here is the call graph for this function:

◆ lo_export()

DatabaseCore::lo_export ( $p_oid,
$tmp_file )

wrapper for the function pg_lo_export

Parameters
$p_oidis the oid of the log
$tmp_fileis the file
Returns
result of the operation

Definition at line 961 of file database_core.class.php.

962 {
963 return pg_lo_export($this->db, $p_oid, $tmp_file);
964 }

References db.

◆ lo_import()

DatabaseCore::lo_import ( $p_filename)

wrapper for the function pg_lo_export

Parameters
$p_filenameis the filename
$tmpis the file
Returns
result of the operation

Definition at line 973 of file database_core.class.php.

974 {
975 return pg_lo_import($this->db, $p_filename);
976 }

References db.

◆ lo_read()

DatabaseCore::lo_read ( $oid)

read a Large object with data content in a binary

Parameters
$oid(int8) oid of the large object
Returns
$binary_data (raw data) binary

Definition at line 811 of file database_core.class.php.

812 {
813 //var $a : 0 where in a transaction, 1 we are not in a transaction
814 $a=0;
815 if ( $this->status() !== PGSQL_TRANSACTION_INTRANS ) {
816 $a=1;
817 $this->start();
818 }
819
820 $handle=pg_lo_open($this->db,$oid,"r");
821 if ( $handle == false ) { return false ;}
822 // set position end of the LO
823 pg_lo_seek($handle, 0, PGSQL_SEEK_END);
824 // get the size
825 $size= pg_lo_tell($handle);
826 // set position to start
827 pg_lo_seek($handle, 0, PGSQL_SEEK_SET);
828 // read the comùplete LOB
829 $binary_data = pg_lo_read($handle,$size );
830 pg_lo_close($handle);
831 if ( $a==1) { $this->commit(); }
832 return $binary_data;
833 }
commit()
Commit the transaction.
start()
: start a transaction
status()
get the transaction status : The status can be
if(in_array( $type, array( 'CHA', 'ACT', 'PASINV', 'PROINV')) &&$tot_deb< $tot_cred) if(in_array($type, array('PRO', 'PAS', 'ACTINV', 'CHAINV')) && $tot_deb > $tot_cred) $size

References $a, $size, commit(), db, start(), and status().

+ Here is the call graph for this function:

◆ lo_replace()

DatabaseCore::lo_replace ( $binary_data,
$oid )

replace a Large object with data content in a binary

Parameters
$oid(int8) oid of the large object
$binary_data(raw data) binary
Returns
$oid of the LO, false if it fails

Definition at line 840 of file database_core.class.php.

840 {
841 $a = 0;
842 if ($this->status() !== PGSQL_TRANSACTION_INTRANS) {
843 $a = 1;
844 $this->start();
845 }
846 $handle = pg_lo_open($this->db, $oid, "w");
847 if ( $handle == false ) { return false ;}
848 pg_lo_truncate($handle, 0);
849 pg_lo_write($handle, $binary_data);
850 pg_lo_close($handle);
851 if ($a == 1) {
852 $this->commit();
853 }
854 return $oid;
855 }

References $a, commit(), db, start(), and status().

+ Here is the call graph for this function:

◆ lo_unlink()

DatabaseCore::lo_unlink ( $p_oid)

wrapper for the function pg_lo_unlink

Parameters
$p_oidis the of oid
Returns
return the result of the operation : false == fails

Definition at line 923 of file database_core.class.php.

924 {
925 if (!$this->exist_blob($p_oid)) return;
926 return pg_lo_unlink($this->db, $p_oid);
927 }
exist_blob($p_oid)
check if the large object exists

References db, and exist_blob().

Referenced by clean_orphan_lob().

+ Here is the call graph for this function:

◆ lo_write()

DatabaseCore::lo_write ( $binary_data)

large_object writee: create a Large object if oid is not given with data content in a binaray

Parameters
$binary_data(raw data) binary
Returns
$oid of the LO, false if it fails

Definition at line 788 of file database_core.class.php.

789 {
790 //var $a : 0 where in a transaction, 1 we are not in a transaction
791 $a=0;
792 if ( $this->status() !== PGSQL_TRANSACTION_INTRANS ) {
793 $a=1;
794 $this->start();
795 }
796
797 $oid= pg_lo_create($this->db);
798
799 if ( ($handle=pg_lo_open($this->db,$oid,"w")) == false ) { return false ;}
800 pg_lo_write($handle, $binary_data);
801 pg_lo_close($handle);
802 if ( $a==1) { $this->commit(); }
803 return $oid;
804
805 }

References $a, commit(), db, start(), and status().

+ Here is the call graph for this function:

◆ make_array()

DatabaseCore::make_array ( $p_sql,
$p_null = 0,
$p_array = null )

make a array with the sql.

Parameters
$p_sqlsql statement, only the first two column will be returned in an array. The first col. is the label and the second the value
$p_nullif the array start with a null value Yes = 1 , No=0
$p_arrayis the array with the bind value
Note
this function is used with ISelect when it is needed to have a list of options.
Returns
: a double array like
* Array
* (
* [0] => Array
* (
* [value] => 1
* [label] => Marchandise A
* )
*
* [1] => Array
* (
* [value] => 2
* [label] => Marchandise B
* )
*
* [2] => Array
* (
* [value] => 3
* [label] => Marchandise C
* )
* )
* 
See also
ISelect

Definition at line 696 of file database_core.class.php.

697 {
698 $a = $this->exec_sql($p_sql, $p_array);
699 $max = pg_num_rows($a);
700 if ($max == 0 && $p_null == 0)
701 return null;
702 for ($i = 0; $i < $max; $i++) {
703 $row = pg_fetch_row($a);
704 $r[$i]['value'] = $row[0];
705 $r[$i]['label'] = h($row[1]);
706 }
707 // add a blank item ?
708 if ($p_null == 1) {
709 for ($i = $max; $i != 0; $i--) {
710 $r[$i]['value'] = $r[$i - 1]['value'];
711 $r[$i]['label'] = $r[$i - 1]['label'];
712 }
713 $r[0]['value'] = -1;
714 $r[0]['label'] = " ";
715 } // if ( $p_null == 1 )
716
717 return $r;
718 }
h( $row[ 'oa_description'])

References $a, $i, $max, $p_array, $r, $row, exec_sql(), and h.

+ Here is the call graph for this function:

◆ make_list()

DatabaseCore::make_list ( $sql,
$p_array = null )

create a string containing the value separated by comma for use in a SQL in statement

Returns
the string or empty if nothing is found
See also
fid_card.php

Definition at line 639 of file database_core.class.php.

640 {
641 if ($p_array == null) {
642 $aArray = $this->get_array($sql);
643 } else {
644 $aArray = $this->get_array($sql, $p_array);
645 }
646 if (empty($aArray))
647 return "";
648 $aIdx = array_keys($aArray[0]);
649 $idx = $aIdx[0];
650 $ret = "";
651 $f = "";
652 for ($i = 0; $i < count($aArray); $i++) {
653 $row = $aArray[$i];
654 $ret .= $f . $aArray[$i][$idx];
655 $f = ',';
656 }
657 $ret = trim($ret, ',');
658 return $ret;
659 }

References $f, $i, $idx, $p_array, $ret, $row, $sql, count(), and get_array().

+ Here is the call graph for this function:

◆ nb_column()

static DatabaseCore::nb_column ( $p_ret)
static

Returns the number of columns in a ret.

Parameters
handler$p_rethandler to a query

Definition at line 1132 of file database_core.class.php.

1132 {
1133 return pg_num_fields($p_ret);
1134 }

◆ num_row()

static DatabaseCore::num_row ( $ret)
static

wrapper for the function pg_num_rows

Parameters
$retis the result of a exec_sql
Returns
number of line affected

Definition at line 863 of file database_core.class.php.

864 {
865 return pg_num_rows($ret);
866 }

References $ret.

Referenced by Default_Menu\__construct(), Noalyss_Parameter_Folder\__construct(), Fiche\belong_ledger(), Noalyss_User\Check(), Data_SQL\collect_objects(), Periode\display_periode_global(), Manage_Table_SQL\display_table(), Periode_Ledger_Table\display_table(), Fiche_Def\DisplayAttribut(), Acc_Account_Ledger\do_exist(), Fiche\empty_attribute(), Acc_Report\exist(), Print_Ledger_Detail_Item\export(), Print_Ledger_Simple\export(), Print_Ledger_Simple_Without_Vat\export(), Acc_Ledger_History_Purchase\export_csv(), Acc_Ledger_History_Sale\export_csv(), Follow_Up\export_csv(), Follow_Up\export_csv_detail(), Document\export_file(), Periode\find_periode(), Acc_Operation\find_tiers(), Acc_Reconciliation\get(), Anc_Plan\get(), Document\get(), Fiche_Def\get(), get_affected(), Fiche_Def\get_all(), Acc_Reconciliation\get_amount_noautovat(), Fiche_Def\get_attr_min(), Fiche\get_bk_balance(), Customer\get_by_account(), Supplier\get_by_account(), Fiche\get_by_category(), Fiche_Def\get_by_category(), Acc_Operation\get_data(), Periode\get_date_limit(), Periode\get_exercice(), Acc_Operation\get_internal(), Anc_Operation\get_jrid(), Acc_Operation\get_jrnx_detail(), Acc_Report\get_list(), Acc_Account_Ledger\get_name(), Acc_Ledger\get_name(), Acc_Account_Ledger\get_row(), Acc_Ledger_History_Generic\get_row(), Acc_Report\get_row(), Fiche\get_row(), Fiche\get_row_date(), Fiche\get_row_result_deprecated(), Acc_Account_Ledger\get_row_sql_deprecated(), Acc_Ledger_History_Generic\get_rowSimple(), Acc_Account_Ledger\get_solde(), Acc_Account_Ledger\get_solde_detail(), Fiche\get_solde_detail(), Acc_Ledger\get_type(), Stock\history(), html_min_page_start(), html_page_start(), isValid_deprecrated(), Acc_Ledger_Search\list_operation(), Acc_Ledger_Search\list_operation_to_reconcile(), Acc_Ledger\listing(), Acc_Bilan\load(), Acc_Ledger_Info\load(), Acc_Parm_Code\load(), Acc_Payment\load(), Anc_Balance_Simple\load(), Card_Property\load(), Dossier\load(), Noalyss_User\load(), Todo_List\load(), Acc_Ledger_Info\load_all(), Fiche_Def\load_attribute(), Document_Modele\myList(), Fiche_Def\myList(), query_to_csv(), Document_Modele\Save(), Acc_Ledger_Info\search_id_internal(), Acc_Operation\seek_internal(), Document\send(), Acc_Reconciliation\show_detail(), Html_Table\sql2table(), Profile_Menu\sub_menu(), Card_Property\update(), Document_Modele\update(), Anc_Operation\update_from_jrnx(), Customer\VatListing(), and Acc_Bilan\warning().

◆ prepare()

DatabaseCore::prepare ( $p_string,
$p_sql )

wrapper for the function pg_prepare

Parameters
$p_stringstring name for pg_prepare function
$p_sqlis the sql to prepare
Returns
return the result of the operation

Definition at line 935 of file database_core.class.php.

936 {
937 return pg_prepare($this->db, $p_string, $p_sql);
938 }

References db.

◆ query_to_csv()

DatabaseCore::query_to_csv ( $ret,
$aheader )

with the handle of a successull query, echo each row into CSV and send it directly to output.

To save it into a file, it is needed to send first the HEADER as CSV. If there are less column than column defined in $aheader, then the columns not included in the header are not displaid

Parameters
handle$rethandle to a query
array$aheaderdouble array, each item of the array contains (idx : title, type) a key type (num) and a key title

Definition at line 1099 of file database_core.class.php.

1100 {
1101 $csv = new Noalyss_Csv("db-query");
1102 $a_header = [];
1103 for ($i = 0; $i < count($aheader); $i++) {
1104 $a_header[] = $aheader[$i]['title'];
1105 }
1106 $csv->write_header($a_header);
1107
1108 // fetch all the rows
1110 for ($i = 0; $i < $nb; $i++) {
1112 // for each rows, for each value
1113 $e=0;
1114 foreach ($row as $row_item){
1115 if ( $e >= count($a_header)) break;
1116 switch ($aheader[$e]['type']) {
1117 case 'num':
1118 $csv->add($row_item, "number");
1119 break;
1120 default:
1121 $csv->add($row_item);
1122 }
1123 $e++;
1124 }
1125 $csv->write();
1126 }
1127 }
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array

References $csv, $e, $i, $nb, $ret, $row, count(), fetch_array(), and num_row().

+ Here is the call graph for this function:

◆ rollback()

DatabaseCore::rollback ( )

rollback the current transaction

Definition at line 304 of file database_core.class.php.

305 {
306 if (!$this->is_open) return;
307 $Res = $this->exec_sql("rollback");
308 }

References $Res, and exec_sql().

Referenced by exec_sql(), execute_script(), and upload().

+ Here is the call graph for this function:

◆ search_sql_inject()

DatabaseCore::search_sql_inject ( $p_sql)

FInd if a SQL Select has a SQL stmt to inject or damage Data When a SELECT SQL string is build, this string could contain a SQL attempt to damage data, so the statement DELETE TRUNCATE ... are forbidden.

Throw an exception EXC_INVALID

Definition at line 1141 of file database_core.class.php.

1142 {
1143 $forbid_sql=array("update","delete","truncate","insert");
1144 // protect against SQL inject
1145 foreach ($forbid_sql as $forbid_key) {
1146 if (stripos($p_sql,$forbid_key) !== false)
1147 {
1148 throw new Exception(_("Possible SQL inject"),EXC_INVALID);
1149 }
1150
1151 }
1152 }
const EXC_INVALID
Definition constant.php:358

References _, and EXC_INVALID.

◆ set_db()

DatabaseCore::set_db ( $db)
Parameters
mixed$db

Definition at line 141 of file database_core.class.php.

142 {
143 $this->db = $db;
144 }

References $db, and db.

◆ set_encoding()

DatabaseCore::set_encoding ( $p_charset)

Definition at line 119 of file database_core.class.php.

120 {
121 pg_set_client_encoding($this->db, $p_charset);
122 }

References db.

◆ set_is_open()

DatabaseCore::set_is_open ( $is_open)
Parameters
mixed$is_open

Definition at line 173 of file database_core.class.php.

174 {
175 $this->is_open = $is_open;
176 }

References $is_open.

◆ set_ret()

DatabaseCore::set_ret ( $ret)
Parameters
mixed$ret

Definition at line 157 of file database_core.class.php.

158 {
159 $this->ret = $ret;
160 }

References $ret.

◆ set_sql()

DatabaseCore::set_sql ( $sql)

last SQL stmt executed

Parameters
string$sql

Definition at line 189 of file database_core.class.php.

190 {
191 $this->sql=$sql;
192 return $this;
193 }

References $sql.

◆ size()

DatabaseCore::size ( $p_ret = null)

return the number of rows found by the last query, or the number of rows from $p_ret

Parameters
$p_retis the result of a query, the default value is null, in that case it is related to the last query
Note
synomym for count()

Definition at line 429 of file database_core.class.php.

430 {
431 if ($p_ret == null)
432 return pg_num_rows($this->ret);
433 else
434 return pg_num_rows($p_ret);
435 }

◆ start()

DatabaseCore::start ( )

: start a transaction

Definition at line 286 of file database_core.class.php.

287 {
288 $Res = $this->exec_sql("start transaction");
289 }

References $Res, and exec_sql().

Referenced by lo_read(), lo_replace(), lo_write(), and upload().

+ Here is the call graph for this function:

◆ status()

DatabaseCore::status ( )

get the transaction status : The status can be

  • PGSQL_TRANSACTION_IDLE (currently idle),
  • PGSQL_TRANSACTION_ACTIVE (a command is in progress),
  • PGSQL_TRANSACTION_INTRANS (idle, in a valid transaction block),
  • PGSQL_TRANSACTION_INERROR (idle, in a failed transaction block).
  • PGSQL_TRANSACTION_UNKNOWN is reported if the connection is bad.
  • PGSQL_TRANSACTION_ACTIVE is reported only when a query has been sent to the server and not yet completed.
Returns
PGSQL_TRANSACTION_IDLE | PGSQL_TRANSACTION_ACTIVE | PGSQL_TRANSACTION_INTRANS | PGSQL_TRANSACTION_INERROR | PGSQL_TRANSACTION_UNKNOWN | PGSQL_TRANSACTION_ACTIVE

Definition at line 1030 of file database_core.class.php.

1031 {
1032 return pg_transaction_status($this->db);
1033 }

References db.

Referenced by lo_read(), lo_replace(), lo_write(), and upload().

◆ test_me()

static DatabaseCore::test_me ( )
static

Definition at line 1014 of file database_core.class.php.

1015 {
1016
1017 }

◆ upload()

DatabaseCore::upload ( $p_name,
$only_oid = false )

Save one or several documents into the database , it just puts the file in the database and returns the corresponding OID , the mimetype , size ... of the document must be set in the calling function.

Parameters
nameof the variable in $_FILES
$only_oid(bool) (default :true) false : return filename and oid in an array , true only OID,
Returns
$oid of the lob file if success false if a error occurs or if there is no file to upload array(oid, filename) if $only_oid is true

Definition at line 733 of file database_core.class.php.

734 {
735
736 //var $a : 0 we're in a transaction, 1 we are not in a transaction
737 $a=0;
738 if ( $this->status() !== PGSQL_TRANSACTION_INTRANS ) {
739 $a=1;
740 $this->start();
741 }
742
743 /* there is no file to upload */
744 if ($_FILES[$p_name]["error"] == UPLOAD_ERR_NO_FILE) {
745 \record_log("DC759: error upload file".var_export($_FILES, true));
746 if ( $a==1) { $this->rollback(); }
747 return false;
748 }
749
750 $new_name = tempnam($_ENV['TMP'], $p_name);
751 if ($_FILES[$p_name]["error"] > 0) {
752 \record_log("DC740: error upload file".var_export($_FILES, true));
753 if ( $a==1) { $this->rollback(); }
754 return false;
755 }
756 if (strlen($_FILES[$p_name]['tmp_name']) != 0) {
757 if (move_uploaded_file($_FILES[$p_name]['tmp_name'], $new_name)) {
758 // echo "Image saved";
759 $oid = pg_lo_import($this->db, $new_name);
760 if ($oid == false) {
761 \record_log("DC747: error upload file".var_export($_FILES, true). "SQL MESSAGE". pg_last_error($this->db));
762 $this->rollback();
763 return false;
764 }
765 if ( $a == 1 ) { $this->commit(); }
766 if ($only_oid ){
767 return $oid;
768 }else {
769 return ["oid"=>$oid,'filename'=>$new_name];
770 }
771 } else {
772 \record_log("DC754: move_uploaded fails".var_export($_FILES, true));
773 $this->rollback();
774 return false;
775 }
776 }
777
778 \record_log("DC576: Files error names empty".var_export($_FILES, true));
779 if ( $a == 1) { $this->commit(); }
780 return false;
781 }
$new_name

References $a, $new_name, commit(), db, record_log(), rollback(), start(), and status().

+ Here is the call graph for this function:

◆ verify()

DatabaseCore::verify ( )

Definition at line 114 of file database_core.class.php.

115 {
116 // Verify that the elt we want to add is correct
117 }

Field Documentation

◆ $array

DatabaseCore::$array

Definition at line 44 of file database_core.class.php.

Referenced by get_array(), get_row(), and get_value().

◆ $db

DatabaseCore::$db
protected

database connection

Definition at line 38 of file database_core.class.php.

Referenced by get_db(), and set_db().

◆ $dbhost

DatabaseCore::$dbhost
protected

!< $dbport (int) Database port

Definition at line 47 of file database_core.class.php.

Referenced by get_dbhost().

◆ $dbname

DatabaseCore::$dbname
protected

Definition at line 45 of file database_core.class.php.

Referenced by get_dbname().

◆ $dbport

DatabaseCore::$dbport
protected

!< $dbname (string) Database name

Definition at line 46 of file database_core.class.php.

Referenced by get_dbport().

◆ $dbuser

DatabaseCore::$dbuser
protected

!< $dbhost(string) Database host

Definition at line 48 of file database_core.class.php.

Referenced by get_dbuser().

◆ $is_open

DatabaseCore::$is_open
protected

true is connected

Definition at line 42 of file database_core.class.php.

Referenced by get_is_open(), and set_is_open().

◆ $ret

DatabaseCore::$ret
protected

◆ $sql

DatabaseCore::$sql

last SQL stmt executed

Definition at line 43 of file database_core.class.php.

Referenced by Database\apply_patch(), clean_orphan_lob(), create_sequence(), execute_script(), get_sql(), make_list(), and set_sql().


The documentation for this class was generated from the following file: