97#[\AllowDynamicProperties]
112 $ret.=
"[ $name => {$this->$name} ]";
115 $ret.=
"| type ".print_r($this->
type,
true);
116 $ret.=
"| default ".print_r($this->
default,
true);
117 $ret.=
"| primary key ".$this->primary_key;
118 $ret.=
"| date_format ".$this->date_format;
119 $ret.=
"| a_virtual_col".var_export($this->a_virtual_col,
true);
129 $this->a_virtual_col=array();
132 throw new Exception (__FILE__.
" $this->table Cannot instantiate");
137 foreach ($this->
name as $key)
139 if ( in_array($key,[
'name',
'type',
'format_date',
'cn',
'date_format',
'default'] ) ) {
140 throw new Exception (
'DATASQL-94 invalid column name'.$key,94);
147 if ( empty($this->date_format) ) $this->date_format=
"DD.MM.YYYY";
178 $this->a_virtual_col[$col_name]=$sql_expression;
184 public function get($cols)
186 if (array_key_exists($cols, $this->
type)) {
189 if (array_key_exists($cols, $this->a_virtual_col))
193 throw new \Exception (
" unknow cols [$cols] =".$this,
EXC_DATA_SQL);
200 public function set($cols, $p_value)
202 if (array_key_exists($cols, $this->
type)) {
203 $this->$cols=$p_value;
206 throw new \Exception (
" unknow cols [$cols] =".$this,
EXC_DATA_SQL);
217 if (array_key_exists($cols, $this->
name)) {
221 if (array_key_exists($cols, $this->
type)) {
224 if (array_key_exists($cols, $this->a_virtual_col))
229 throw new \Exception (
" unknow cols [$cols] =".$this,
EXC_DATA_SQL);
237 public function setp($cols, $p_value)
239 if (array_key_exists($cols, $this->
name)) {
241 $this->
$idx=$p_value;
244 if (array_key_exists($cols, $this->
type)) {
245 $this->$cols=$p_value;
249 throw new \Exception (
" unknow cols [$cols] =".$this,
EXC_DATA_SQL);
252 public function __set($cols,$p_value) {
253 if (array_key_exists($cols, $this->
type)) {
254 $this->$cols=$p_value;
257 if ( ! empty ($this->a_virtual_col) && array_key_exists($cols, $this->a_virtual_col))
259 $this->$cols=$p_value;
263 throw new \Exception (
" unknow cols [$cols] =".$this,
EXC_DATA_SQL);
266 if (array_key_exists($cols, $this->
type)) {
269 if (! empty ($this->a_virtual_col) && array_key_exists($cols, $this->a_virtual_col))
273 throw new \Exception (
" unknow cols [$cols] =".$this,
EXC_DATA_SQL);
277 abstract function delete();
323 return var_export($this,
true);
331 foreach ($this->
name as $key)
373 if ( ! empty ($this->a_virtual_col )) {
374 $a_column= array_keys($this->a_virtual_col);
375 foreach( $a_column as $column){
376 $array[$column]=$this->a_virtual_col[$column];
394 if ( ! empty ($this->a_virtual_col )) {
395 $a_column= array_keys($this->a_virtual_col);
396 foreach( $a_column as $column){
425 if ( ! empty ($this->a_virtual_col )) {
426 $a_column= array_keys($this->a_virtual_col);
427 foreach( $a_column as $column){
428 if ( isset (
$array[$column] )) {
429 $this->$column =
$array[$column];
431 $this->$column =
null;
458 throw new Exception(
_(
"Erreur : exec_sql attend un array"));
_("actif, passif,charge,...")
this an abstract class , all the SQL class, like noalyss_sql (table), Acc_Plan_SQL (based on a SQL no...
$primary_key
Array of logical and real name.
to_array($prefix="")
Turn an object (row) into an array, and the key could be prefixed with $prefix.
exist()
Count the number of record with the id ,.
__construct(DatabaseCore $p_cn, $p_id=-1)
collect_objects($cond='', $p_array=null)
return an array of objects.
count($p_where="", $p_array=null)
load()
Load the current row return false if not found.
to_row($p_array)
update the data member of current object with the value from the array.
set_virtual_col($col_name, $sql_expression)
add a virtual column (formatted column, sum of 2 col, ...)
$date_format
Type of the data.
seek($cond='', $p_array=null)
retrieve array of object thanks a condition
from_array($p_array)
Transform an array into object.
set_primary_key($primary_key)
next($ret, $i)
get_seek return the next object, the return of the query must have all the column of the object inclu...
getp($cols)
set the value thanks the alias name instead of the colum name if not found try the column name
$name
Database connection.
save()
Insert or update : if the row already exists, update otherwise insert.
$default
defaullt date format
$type
Column name of the primary key.
get_a_virtual_col()
return array of virtual cols (alias calculated, formatted cols)
setp($cols, $p_value)
set the value thanks the alias name instead of the colum name, if not found try the column name
This class allow you to connect to the postgresql database, execute sql, retrieve data.
static num_row($ret)
wrapper for the function pg_num_rows