noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 24/27: Noalyss_SQL Create a function build qu


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 24/27: Noalyss_SQL Create a function build query
Date: Wed, 4 Sep 2019 15:24:58 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit d0b254366972beb94d738697f469ec700d3c1b8c
Author: Dany De Bontridder <address@hidden>
Date:   Wed Sep 4 21:11:37 2019 +0200

    Noalyss_SQL Create a function build query
---
 include/lib/noalyss_sql.class.php | 46 +++++++++++++++++++++++++--------------
 1 file changed, 30 insertions(+), 16 deletions(-)

diff --git a/include/lib/noalyss_sql.class.php 
b/include/lib/noalyss_sql.class.php
index 0e23ca8..aa40129 100644
--- a/include/lib/noalyss_sql.class.php
+++ b/include/lib/noalyss_sql.class.php
@@ -87,6 +87,7 @@ require NOALYSS_INCLUDE."/lib/data_sql.class.php";
 abstract class Noalyss_SQL extends Data_SQL
 {
 
+    var $default;
     function __construct(&$p_cn, $p_id=-1)
     {
         $this->cn=$p_cn;
@@ -104,6 +105,7 @@ abstract class Noalyss_SQL extends Data_SQL
         $this->$pk=$p_id;
         /* load it */
         if ($p_id != -1 )$this->load();
+        
     }
 /**
  * Insert or update : if the row already exists, update otherwise insert
@@ -255,23 +257,8 @@ abstract class Noalyss_SQL extends Data_SQL
 
     public function load()
     {
-        $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=",";
-        }
+        $sql=$this->build_query();
         $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)
@@ -412,6 +399,33 @@ abstract class Noalyss_SQL extends Data_SQL
         $count=$this->cn->get_value("select count(*) from ".$this->table." 
where ".$this->primary_key."=$1",array($this->$pk));
         return $count;
     }
+    
+    /**
+     * Build the SQL select statement for querying the object and returns it
+     * @return string Query of the object 
+     */
+    public function build_query()
+    {
+        $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";
+        
+        return $sql;
+    }
 }
 
 ?>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]