78 $pk=$this->primary_key;
82 throw new Exception (__FILE__.
" $this->table Cannot instantiate");
98 $pk=$this->primary_key;
99 $count=$this->
cn->get_value(
'select count(*) from '.$this->
table.
' where '.$this->primary_key.
'=$1',array($this->$pk));
110 public function get($p_string)
112 if (array_key_exists($p_string, $this->
type)) {
113 return $this->$p_string;
116 throw new Exception(__FILE__.
":".__LINE__.$p_string.
'Erreur attribut inexistant '.$p_string);
123 public function set($p_string, $p_value)
125 if (array_key_exists($p_string, $this->
type)) {
126 $this->
$idx=$p_value;
128 throw new Exception(__FILE__.
":".__LINE__.$p_string.
'Erreur attribut inexistant '.$p_string);
135 public function getp($p_string)
137 if (array_key_exists($p_string, $this->
name)) {
142 throw new Exception(__FILE__.
":".__LINE__.$p_string.
'Erreur attribut inexistant '.$p_string);
149 public function setp($p_string, $p_value)
151 if (array_key_exists($p_string, $this->
name)) {
153 $this->
$idx=$p_value;
155 throw new Exception(__FILE__.
":".__LINE__.$p_string.
'Erreur attribut inexistant '.$p_string);
161 $sql=
"insert into ".$this->table.
" ( ";
168 if (isset($this->
default[
$value])&&$this->
default[$value]==
"auto"&&$this->$value==null)
170 if ($value==$this->primary_key&&$this->$value==-1)
173 switch ($this->
type[$value])
176 if ($this->date_format==
"")
177 throw new Exception(
'Format Date invalide');
178 $par .=
$sep.
'to_timestamp($'.
$idx.
",'".$this->date_format.
"')";
188 $sql.=
") values (".$par.
") returning ".$this->primary_key;
189 $pk=$this->primary_key;
193 public function delete()
195 $pk=$this->primary_key;
196 $sql=
" delete from ".$this->table.
" where ".$this->primary_key.
"= $1";
197 $this->
cn->exec_sql(
$sql,array($this->$pk));
203 $pk=$this->primary_key;
204 $sql=
"update ".$this->table.
" ";
210 if (isset($this->
default[
$value])&&$this->
default[$value]==
"auto")
212 switch ($this->
type[$value])
215 $par=$value.
'=to_timestamp($'.
$idx.
",'".$this->date_format.
"')";
218 $par=$value.
"= $".
$idx;
227 $sql.=
" where ".$this->primary_key.
" = $".
$idx;
232 $pk=$this->primary_key;
237 $pk=$this->primary_key;
246 switch ($this->
type[$key])
249 $sql .=
$sep.
'to_char('.$key.
",'".$this->date_format.
"') as ".
$key;
256 $pk=$this->primary_key;
257 $sql.=
" from ".$this->table;
259 $sql.=
" where ".$this->primary_key.
" = $1";
262 if ($this->
cn->count()==0)
276 return var_export($this,
true);
286 if (
trim($this->$key)==
'')
337 $sql=
"select * from ".$this->table.
" $cond";
375 throw new Exception(_(
"Erreur : exec_sql attend un array"));
380 for ($i=0; $i<
$max; $i++)
387 $count=$this->
cn->get_value(
"select count(*) from $this->table".$p_where,
$p_array);
395 $pk=$this->primary_key;
396 $count=$this->
cn->get_value(
"select count(*) from ".$this->
table.
" where ".$this->primary_key.
"=$1",array($this->$pk));
to_array()
Turn an object (row) into an array.
save()
Insert or update : if the row already exists, update otherwise insert.
seek($cond='', $p_array=null)
retrieve array of object thanks a condition
static num_row($ret)
wrapper for the function pg_NumRows
Match a table into an object, you need to add the code for each table.
set($p_string, $p_value)
set the value thanks the colum name and not the alias (name)
__construct(&$p_cn, $p_id=-1)
from_array($p_array)
Transform an array into object.
count($p_where="", $p_array=null)
function trim(s)
remove trailing and heading space
next($ret, $i)
get_seek return the next object, the return of the query must have all the column of the object ...
collect_objects($cond='', $p_array=null)
return an array of objects.
setp($p_string, $p_value)
set the value thanks the alias name instead of the colum name
exist()
Count the number of record with the id ,.
getp($p_string)
set the value thanks the alias name instead of the colum name