noalyss  Version-6.7.2
Public Member Functions
Phpcompta_SQL Class Reference
Inheritance diagram for Phpcompta_SQL:
Default_Menu_SQL Profile_sql Stock_Change_Sql Stock_Goods_Sql Stock_Sql Tag_SQL Stock_Goods Stock

Public Member Functions

 __construct (&$p_cn, $p_id=-1)
 delete ()
 from_array ($p_array)
 Transform an array into object.
 get_info ()
 get_object ($p_ret, $idx)
 getp ($p_string)
 insert ()
 load ()
 next ($ret, $i)
 get_seek return the next object, the return of the query must have all the column of the object
 save ()
 seek ($cond='', $p_array=null)
 retrieve array of object thanks a condition
 setp ($p_string, $p_value)
 update ()
 verify ()

Detailed Description

Definition at line 73 of file class_phpcompta_sql.php.


Constructor & Destructor Documentation

Phpcompta_SQL::__construct ( &$  p_cn,
p_id = -1 
)

Reimplemented in Profile_sql, Default_Menu_SQL, and Tag_SQL.

Definition at line 76 of file class_phpcompta_sql.php.

References cn, load(), and name.

        {
                $this->cn = $p_cn;
                $pk=$this->primary_key;
                $this->$pk= $p_id;

                        /* Initialize an empty object */
                        foreach ($this->name as $key )
                        {
                                $this->$key= null;
                        }
                        $this->$pk= $p_id;
                        /* load it */
                        $this->load();
        }

Member Function Documentation

Definition at line 153 of file class_phpcompta_sql.php.

References $sql, cn, sql_string(), and table.

        {
                $pk=$this->primary_key;
                $sql = " delete from " . $this->table . " where " . $this->primary_key . "=" . sql_string($this->$pk);
                $this->cn->exec_sql($sql);
        }
Phpcompta_SQL::from_array ( p_array)

Transform an array into object.

Parameters:
type$p_array
Returns:
object

Definition at line 239 of file class_phpcompta_sql.php.

References $p_array, $value, and name.

Referenced by next().

        {
                foreach ($this->name as $key=>$value)
                {
                        if ( isset ($p_array[$value]))
                        {
                                $this->$value=$p_array[$value];
                        }
                        else
                        {
                                $this->$value=null;
                        }
                }
                return $this;
        }

Definition at line 222 of file class_phpcompta_sql.php.

        {
                return var_export($this, true);
        }
Phpcompta_SQL::get_object ( p_ret,
idx 
)
See also:
next

Definition at line 283 of file class_phpcompta_sql.php.

References $idx, and next().

    {
    return $this->next($p_ret, $idx);
   }
Phpcompta_SQL::getp ( p_string)

Definition at line 98 of file class_phpcompta_sql.php.

References $idx, and name.

        {
                if (array_key_exists( $p_string,$this->name))
                {
                        $idx = $this->name[$p_string];
                        return $this->$idx;
                }
                else
                        throw new Exception(__FILE__ . ":" . __LINE__ . $p_string . 'Erreur attribut inexistant '.$p_string);
        }

Definition at line 120 of file class_phpcompta_sql.php.

References $array, $idx, $sep, $sql, $value, cn, name, table, type, and verify().

Referenced by save().

        {
                $this->verify();
                $sql = "insert into " . $this->table . " ( ";
                $sep = "";
                $par = "";
                $idx = 1;
                $array = array();
                foreach ($this->name as $key=>$value)
                {
                        if (isset($this->default[$value]) && $this->default[$value] == "auto" && $this->$value ==null )
                                continue;
                        if ( $value==$this->primary_key && $this->$value == -1 ) continue;
                        $sql.=$sep.$value;
                        switch ($this->type[$value])
                        {
                                case "date":
                                        if ($this->date_format=="")                                             throw new Exception('Format Date invalide');
                                        $par .=$sep. 'to_date($' . $idx . ",'" . $this->date_format . "')" ;
                                        break;
                                default:
                                        $par .= $sep."$" . $idx ;
                        }

                        $array[] = $this->$value;
                        $sep = ",";
                        $idx++;
                }
                $sql.=") values (" . $par . ") returning " . $this->primary_key;
                $pk=$this->primary_key;
                $this->$pk = $this->cn->get_value($sql, $array);
        }

Definition at line 190 of file class_phpcompta_sql.php.

References $result, $sep, $sql, $value, cn, name, and type.

Referenced by __construct().

        {
                $sql = " select ";
                $sep="";$par="";

                foreach ($this->name as $key)
                {

                        switch ($this->type[$key])
                        {
                                case "date":
                                        $sql .= $sep.'to_char(' . $key . ",'" . $this->date_format . "') as ".$key ;
                                        break;
                                default:
                                        $sql.=$sep.$key ;
                        }
                        $sep = ",";
                }
                $pk=$this->primary_key;
                $sql.=" from ".$this->table;
                $sql.=" where " . $this->primary_key . " = " . $this->$pk;
                $result = $this->cn->get_array($sql);
                if ($this->cn->count() == 0 ) {
                        $this->$pk=-1;
                        return ;
                }

                foreach ($result[0] as $key=>$value) {
                        $this->$key=$value;
                }
        }
Phpcompta_SQL::next ( ret,
i 
)

get_seek return the next object, the return of the query must have all the column of the object

Parameters:
$p_retis the return value of an exec_sql
$idxis the index
See also:
seek
Returns:
object

Definition at line 276 of file class_phpcompta_sql.php.

References $array, $ret, cn, and from_array().

Referenced by get_object().

                                  {
                $array=$this->cn->fetch_array($ret,$i);
                return $this->from_array($array);
        }

Definition at line 91 of file class_phpcompta_sql.php.

References insert(), and update().

                               {
            $pk=$this->primary_key;
            if (  $this->$pk== -1 )
                  $this->insert();
                else
                        $this->update();
  }
Phpcompta_SQL::seek ( cond = '',
p_array = null 
)

retrieve array of object thanks a condition

Parameters:
$condcondition (where clause) (optional by default all the rows are fetched) you can use this parameter for the order or subselect
$p_arrayarray for the SQL stmt
See also:
Database::exec_sql get_object Database::num_row
Returns:
the return value of exec_sql

Definition at line 262 of file class_phpcompta_sql.php.

References $p_array, $ret, $sql, and cn.

        {
                $sql = "select * from ".$this->table."  $cond";
                $ret = $this->cn->exec_sql($sql, $p_array);
                return $ret;
        }
Phpcompta_SQL::setp ( p_string,
p_value 
)

Definition at line 109 of file class_phpcompta_sql.php.

References $idx, and name.

        {
                if (array_key_exists( $p_string,$this->name))
                {
                        $idx = $this->name[$p_string];
                        $this->$idx = $p_value;
                }
                else
                        throw new Exception(__FILE__ . ":" . __LINE__ . $p_string . 'Erreur attribut inexistant '.$p_string);
        }

Definition at line 160 of file class_phpcompta_sql.php.

References $array, $idx, $sep, $sql, $value, cn, name, table, type, and verify().

Referenced by save().

        {
                $this->verify();
                $pk=$this->primary_key;
                $sql = "update " . $this->table . "  ";
                $sep = "";
                $idx = 1;
                $array = array();
                $set=" set ";
                foreach ($this->name as $key=>$value)
                {
                        if (isset($this->default[$value]) && $this->default[$value] == "auto"  )
                                continue;
                        switch ($this->type[$value])
                        {
                                case "date":
                                        $par =$value. '=to_date($' . $idx . ",'" . $this->date_format . "')" ;
                                        break;
                                default:
                                        $par = $value."= $" . $idx ;
                        }
                        $sql.=$sep." $set " . $par ;
                        $array[] = $this->$value;
                        $sep = ",";$set="";$idx++;
                }
                $sql.=" where " . $this->primary_key . " =" . $this->$pk;
            $this->cn->exec_sql($sql, $array);

        }

Definition at line 227 of file class_phpcompta_sql.php.

References name, and trim().

Referenced by insert(), and update().

        {
                foreach($this->name as $key){
                        if ( trim($this->$key)=='') $this->$key=null;
                }
                return 0;
        }

The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations