93#[AllowDynamicProperties]
100 parent::__construct($p_cn,
$p_id);
107 $ret.=
"[ $name => {$this->$name} ]";
110 $ret.=
"| type ".var_export($this->
type,
true);
111 $ret.=
"| default ".var_export($this->
default,
true);
112 $ret.=
"| primary key ".$this->primary_key;
113 $ret.=
"| date_format ".$this->date_format;
114 $ret.=
"| a_virtual_col".var_export($this->a_virtual_col,
true);
122 $sql=
"insert into ".$this->table.
" ( ";
129 if (isset($this->
default[
$value])&&$this->
default[$value]==
"auto"&&$this->$value==
null)
132 if (
$value==$this->primary_key && $this->$value==-1 && isset($this->
default[$value]) )
138 if ($this->date_format==
"")
139 throw new Exception(
'Format Date invalide');
140 $par .=
$sep.
'to_timestamp($'.
$idx.
",'".$this->date_format.
"')";
153 $this->$pk=$returning;
156 public function delete()
159 $sql=
" delete from ".$this->table.
" where ".$this->primary_key.
"= $1";
160 $this->
cn->exec_sql(
$sql,array($this->$pk));
173 $sql=
"update ".$this->table.
" set {$column_expr} where {$this->primary_key} = $2";
185 $sql=
"update ".$this->table.
" ";
191 if (isset($this->
default[
$value])&&$this->
default[$value]==
"auto")
196 $par=
$value.
'=to_timestamp($'.
$idx.
",'".$this->date_format.
"')";
208 $sql.=
" where ".$this->primary_key.
" = $".
$idx;
219 if (trim($this->$pk??
"")===
"" || $this->$pk===
null) {
224 $sql.=
" where ".$this->primary_key.
" = $1";
226 if ($this->
cn->count()==0)
264 $count=$this->
cn->get_value(
"select count(*) from $this->table ".$p_where,
$p_array);
273 $count=$this->
cn->get_value(
"select count(*) from ".$this->
table.
" where ".$this->primary_key.
"=$1",array($this->$pk));
285 foreach ($this->
name as $key) {
286 switch ($this->
type[$key])
289 $sql .=
$sep.
'to_char('.$key.
",'".$this->date_format.
"') as ".$key;
300 if ( ! empty( $this->a_virtual_col)){
301 $nb_virtual_col=
count($this->a_virtual_col);
302 $a_col= array_keys($this->a_virtual_col);
303 for (
$x=0;
$x<$nb_virtual_col ;
$x++) {
305 $expr=sprintf(
"$sep %s as %s ",$this->a_virtual_col[$col], $col);
309 $sql.=
" from ".$this->table;
340 if (!isset($a_array[
$i][$p_key_col]))
342 throw new Exception(
"col not found ".$p_key_col);
344 $key=$a_array[
$i][$p_key_col];
345 if ( isset ($a_result[$key]) ){
346 throw new Exception (
"duplicate found col : $key");
348 $a_result[$key]=$a_array[
$i];
351 catch (Exception $exc)
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...
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.
$name
Database connection.
static fetch_all($ret, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_all
Interface : this wrapper is used to created easily a wrapper to a table (ORM) You must create a class...
update()
update the row but not the column with a default value
count($p_where="", $p_array=null)
return the number of count in the table corresponding to the where condition
build_query()
Build the SQL select statement for querying the object and returns it.
load()
load a row , corresponding to the primary key
seek($cond='', $p_array=null)
retrieve array of object thanks a condition
exist()
Count the number of record with the id ,.
__construct($p_cn, $p_id=-1)
get_all_to_array($p_key_col, $p_cond="", $p_array=NULL)
Get all the row and use the p_key_code are the key value of array.
column_update($column_expr, $value)
update the value of a column with an expression for $value for the current record