noalyss  Version-6.7.2
Public Member Functions
Noalyss_SQL Class Reference
Inheritance diagram for Noalyss_SQL:
Anc_Key_Activity_SQL Anc_Key_Detail_SQL Anc_Key_Ledger_SQL Anc_Key_SQL Default_Menu_SQL Menu_Ref_SQL Profile_Menu_sql Profile_sql Stock_Change_Sql Stock_Goods_Sql Stock_Sql Tag_SQL

Public Member Functions

 __construct (&$p_cn, $p_id=-1)
 collect_objects ($cond='', $p_array=null)
 return an array of objects.
 count ($p_where="", $p_array=null)
 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 ()
 Insert or update : if the row already exists, update otherwise insert.
 seek ($cond='', $p_array=null)
 retrieve array of object thanks a condition
 setp ($p_string, $p_value)
 update ()
 verify ()

Detailed Description

Definition at line 72 of file class_noalyss_sql.php.


Constructor & Destructor Documentation

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

Reimplemented in Anc_Key_Detail_SQL, Anc_Key_Ledger_SQL, Profile_sql, Profile_Menu_sql, Default_Menu_SQL, and Tag_SQL.

Definition at line 75 of file class_noalyss_sql.php.

References $key, 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 */
        if ($p_id != -1 )$this->load();
    }

Member Function Documentation

Noalyss_SQL::collect_objects ( cond = '',
p_array = null 
)

return an array of objects.

Do not use this function if they are too many objects, it takes a lot of memory, and could slow down your application.

Parameters:
$condcondition, order...
$p_arrayarray to use for a condition
Note:
this function could slow down your application.

Definition at line 312 of file class_noalyss_sql.php.

References $max, $p_array, $ret, next(), Database\num_row(), and seek().

    {
        if ($p_array != null && ! is_array($p_array) )
        {
            throw new Exception(_("Erreur : exec_sql attend un array"));
        }
        $ret=$this->seek($cond, $p_array);
        $max=Database::num_row($ret);
        $a_return=array();
        for ($i=0; $i<$max; $i++)
        {
            $a_return[$i]=clone $this->next($ret, $i);
        }
        return $a_return;
    }
Noalyss_SQL::count ( p_where = "",
p_array = null 
)

Definition at line 327 of file class_noalyss_sql.php.

References $count, $p_array, and cn.

Referenced by Stock_Goods\input(), Profile_Menu\listing_profile(), and Stock_Goods\take_last_inventory().

                                                     {
        $count=$this->cn->get_value("select count(*) from $this->table".$p_where,$p_array);
        return $count;
    }

Definition at line 158 of file class_noalyss_sql.php.

References $sql, and cn.

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

Transform an array into object.

Parameters:
type$p_array
Returns:
object

Definition at line 252 of file class_noalyss_sql.php.

References $key, $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 229 of file class_noalyss_sql.php.

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

Definition at line 300 of file class_noalyss_sql.php.

References $idx, and next().

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

Definition at line 104 of file class_noalyss_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 123 of file class_noalyss_sql.php.

References $array, $idx, $key, $sep, $sql, $value, cn, name, 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 196 of file class_noalyss_sql.php.

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

Referenced by __construct().

    {
        $sql=" select ";
        $sep="";
        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." = $1";
       
        $result=$this->cn->get_array($sql,array ($this->$pk));
        if ($this->cn->count()==0)
        {
            $this->$pk=-1;
            return;
        }

        foreach ($result[0] as $key=> $value)
        {
            $this->$key=$value;
        }
    }
Noalyss_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 291 of file class_noalyss_sql.php.

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

Referenced by collect_objects(), and get_object().

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

Insert or update : if the row already exists, update otherwise insert.

Definition at line 93 of file class_noalyss_sql.php.

References $count, cn, insert(), table, and update().

    {
        $pk=$this->primary_key;
        $count=$this->cn->get_value('select count(*) from '.$this->table.' where '.$this->primary_key.'=$1',array($this->$pk));
        
        if ($count == 0)
            $this->insert();
        else
            $this->update();
    }
Noalyss_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 276 of file class_noalyss_sql.php.

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

Referenced by collect_objects().

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

Definition at line 114 of file class_noalyss_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 165 of file class_noalyss_sql.php.

References $array, $idx, $key, $sep, $sql, $value, cn, name, 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++;
        }
        $array[]=$this->$pk;
        $sql.=" where ".$this->primary_key." = $".$idx;
        $this->cn->exec_sql($sql, $array);
    }
Todo:
ajout vérification type (date, text ou numeric)
Returns:
int

Definition at line 237 of file class_noalyss_sql.php.

References $key, 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