commit-gnue
[Top][All Lists]
Advanced

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

gnue/phpforms/src database.inc gcomm.php gnue-f...


From: Jan Ischebeck
Subject: gnue/phpforms/src database.inc gcomm.php gnue-f...
Date: Thu, 11 Jul 2002 19:02:11 -0400

CVSROOT:        /cvsroot/gnue
Module name:    gnue
Changes by:     Jan Ischebeck <address@hidden>  02/07/11 19:02:11

Modified files:
        phpforms/src   : database.inc gcomm.php gnue-forms.php 

Log message:
        more work on appserver driver (sort,query,..should be feature complete)
        changes in driver interface possibly breaks postgres

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/phpforms/src/database.inc.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/phpforms/src/gcomm.php.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/phpforms/src/gnue-forms.php.diff?tr1=1.5&tr2=1.6&r1=text&r2=text

Patches:
Index: gnue/phpforms/src/database.inc
diff -c gnue/phpforms/src/database.inc:1.3 gnue/phpforms/src/database.inc:1.4
*** gnue/phpforms/src/database.inc:1.3  Mon May 27 14:21:30 2002
--- gnue/phpforms/src/database.inc      Thu Jul 11 19:02:11 2002
***************
*** 165,172 ****
          $r->setTable($table);
          return $r;
      }
!     function getResultSet($table,$query) {
          $r=$this->getEmptyResultSet($table);
          $res=$this->select($query);
          if (count($res)>0) $r->setCache($res);
          return $r;
--- 165,188 ----
          $r->setTable($table);
          return $r;
      }
!     function getResultSet($table,$query,$order_by=Null) {
          $r=$this->getEmptyResultSet($table);
+         // create sql
+         $sql = "select OID,* from ".$this->attr["TABLE"];
+         reset($this->query);
+         while (list($k,$v)=each($this->query)) {
+             if (strlen($v)>0) {
+                 $where=$where2." ".$k." LIKE '".$v."' ";
+                 $where2=$where."AND";
+                 // get field info like: defaultQuery
+                 // ignoreCaseOnquery, sloopyQuery...
+             }
+         };
+         if (isset($where))
+             $sql=$sql." WHERE ".$where;          
+         if (isset($order_by))
+             $sql=$sql." ORDER BY ".$order_by;
+ 
          $res=$this->select($query);
          if (count($res)>0) $r->setCache($res);
          return $r;
Index: gnue/phpforms/src/gcomm.php
diff -c gnue/phpforms/src/gcomm.php:1.1 gnue/phpforms/src/gcomm.php:1.2
*** gnue/phpforms/src/gcomm.php:1.1     Fri Jul  5 18:36:34 2002
--- gnue/phpforms/src/gcomm.php Thu Jul 11 19:02:11 2002
***************
*** 274,297 ****
              }
          }
      }
!     function getEmptyResultSet($table) {  
!         return $this->getResultSet($table,array("1","=","0"));
!     }
!     function getResultSet($table,$query) {
          $this->connect();
          $r=new GNURPCtoAppServerRset;
          $r->setDatabase($this);
          $r->setTable($table);
!         $r->populate($query);
          return $r;     
          
      }
      // global commit /rollback
      function commit() {
!         $this->session->execute("commit","");
      } 
      function rollback() {
!         $this->session->execute("rollback","");
      } 
      // BACKUP / RESTORE FUNCTIONS
      function getBackupData() {
--- 274,308 ----
              }
          }
      }
!     function restoreResultSet($table,$data) {  
          $this->connect();
          $r=new GNURPCtoAppServerRset;
          $r->setDatabase($this);
          $r->setTable($table);
!         $r->restoreData($data);
!         return $r;
!     }
!     function getEmptyResultSet($table,$order_by) {  
!         return $this->getResultSet($table,array(array("eq",''),
!                                                 array("const",0),
!                                                 array("const",1)),
!                                    $order_by);
!     }
!     function getResultSet($table,$query,$order_by) {        
!         $this->connect();
!         $r=new GNURPCtoAppServerRset;
!         $r->setDatabase($this);
!         $r->setTable($table);        
!         $r->populate($query,$order_by);
          return $r;     
          
      }
      // global commit /rollback
      function commit() {
!         $this->session->execute("commit",None);
      } 
      function rollback() {
!         $this->session->execute("rollback",None);
      } 
      // BACKUP / RESTORE FUNCTIONS
      function getBackupData() {
***************
*** 308,313 ****
--- 319,325 ----
  class GNURPCtoAppServerRset extends Resultset {
      var $lastentry;
      var $dbcon;  // set by the database itself, or by the datasoure
+     var $instances;
      function GNURPCtoAppServerRset() {   
          $this->instances=array();
      }
***************
*** 317,323 ****
      function setTable($table) {
          $this->attr["TABLE"]=$table;
      }
!     function populate($query) {
          $this->list = 
               $this->dbcon->session->execute("createList",
                                              array($this->attr["TABLE"]));
--- 329,335 ----
      function setTable($table) {
          $this->attr["TABLE"]=$table;
      }
!     function populate($query,$order_by) {
          $this->list = 
               $this->dbcon->session->execute("createList",
                                              array($this->attr["TABLE"]));
***************
*** 327,338 ****
      
          DEBUG(5,"Using ".$fieldlist." as fieldlist");
  
!         #if hasattr(self,"order_by")
!         #    DEBUG(5,"Sorting list by fields '"+$this->order_by+"'");
!         #    $sort=string.splitfields(self.order_by,",")
!         #    $list->execute("setSort",$sort);
          
          if ($query!=None) {
              DEBUG(5,"Setting Conditions ...");
              $this->list->execute("setConditions",array($query));
          };
--- 339,368 ----
      
          DEBUG(5,"Using ".$fieldlist." as fieldlist");
  
!         if ($order_by!=None) {
!             DEBUG(5,"Sorting list by fields '"+$this->order_by+"'");
!             $sort=explode(",",$order_by);
!             if (!is_array($sort)) $sort=array($sort);
!             $this->list->execute("setSort",array($sort));
!         };
!         
          
          if ($query!=None) {
+             # check for single array ( fieldname=>value,field2=>value ...
+             if (!is_array($query)) print "WRONG FORMAT of QUERY";
+             if (!is_array(reset($query))) {
+                 while (list($k,$v)=each($query)) {
+                     if (isset($nextelm)) {
+                         $rquery[]=array("and","");
+                         $rquery=array_merge($rquery,$nextelm);
+                     };
+                     $nextelm=array(array("like",''),
+                                    array("field",$k),
+                                    array("const",$v));                    
+                 };
+                 $rquery=array_merge($rquery,$nextelm);
+                 $query=$rquery;              
+             };
              DEBUG(5,"Setting Conditions ...");
              $this->list->execute("setConditions",array($query));
          };
***************
*** 345,385 ****
              $this->instances[]=$inst;
              $inst=$this->list->execute("nextInstance",None);
          };        
      }
      // cache functions
      function isSaved() {
      }
      function markforRemoval($recordno) {
      }
      function ismarkedforRemoval ($recordno) {
      }
      function getLastRecordNumber() {
!         return count($this->instances);
      } 
      function commit($dbcon,$table) {  // write datacache
      } 
      function newEntry($pos=-1) {
      }
      function getField($fieldname,$pos) { 
          $inst=$this->instances[$pos];
!         if (is_object($inst))
!             return $inst->execute("get",$fieldname);
      }
      function setField($fieldname,$pos,$data) {
          $inst=$this->instances[$pos];
!         if (is_object($inst))
              $inst->execute("put",array($fieldname,$data));
      }
      // BACKUP / RESTORE FUNCTIONS
      function getBackupData() {
          $this->attr["LIST_HANDLE"]=$this->list->getHandle();
          return $this->attr;
      }
      function restoreData($data) {        
          $this->attr=$data;
          $this->list=new gnurpc_proxyobj($this->dbcon->link,
                                          $this->attr["LIST_HANDLE"]);
  
      }
  }
  
--- 375,481 ----
              $this->instances[]=$inst;
              $inst=$this->list->execute("nextInstance",None);
          };        
+         if (count($this->instances)==0) {
+             $this->newEntry();
+         }
      }
      // cache functions
      function isSaved() {
      }
      function markforRemoval($recordno) {
+         $this->instances[$recordno]->marked=
+              ! $this->instances[$recordno]->marked;
      }
      function ismarkedforRemoval ($recordno) {
+         return $this->instances[$recordno]->marked;
      }
      function getLastRecordNumber() {
!         return count($this->instances)-1;
      } 
      function commit($dbcon,$table) {  // write datacache
+         $new_instlist=array();
+         while (list($k,$v)=each($this->instances)) {
+             if ($v->marked) {
+                 $v->execute("delete",None);
+             } else {
+                 $new_instlist[]=$v;
+             };
+         };
+         $this->instances=$new_instlist;
+         $this->dbcon->commit();
      } 
      function newEntry($pos=-1) {
+         $newinst=$this->list->execute("insertNewInstance",None);
+         if ($pos==-1) {
+             $this->instances[]=$newinst;
+         } else {
+             while ($newinst) {
+                 $i=$this->instances[$pos];
+                 $this->instances[$pos]=$newinst;
+                 $newinst=$i;
+                 $pos++;
+             }
+         };
      }
      function getField($fieldname,$pos) { 
          $inst=$this->instances[$pos];
!         if (is_object($inst)) {
!             if (is_array($inst->fcache)) {
!                 if (array_key_exists($fieldname,$inst->fcache)) {
!                     return $inst->fcache[$fieldname];
!                 };
!             } else {
!                 $this->instances[$pos]->fcache=array();  
!             };
!             $val=$inst->execute("get",$fieldname);
!             $this->instances[$pos]->fcache[$fieldname]=$val;
!             return $val;
!         };
      }
      function setField($fieldname,$pos,$data) {
          $inst=$this->instances[$pos];
!         if (is_object($inst)) {
!             if (is_array($inst->fcache)) {
!                 if (array_key_exists($fieldname,$inst->fcache)) {
!                     if ($inst->fcache[$fieldname]==$data) 
!                         return;
!                 };
!             };
              $inst->execute("put",array($fieldname,$data));
+         };
      }
      // BACKUP / RESTORE FUNCTIONS
      function getBackupData() {
+         # convert proxy objs into handles
+         $this->attr["INSTHANDL_LIST"]=array();
+         $this->attr["INST_DEL"]=array();
+         $this->attr["INST_FCACHE"]=array();
+         while (list($k,$v)=each($this->instances)) {
+             $insthandl[$k]=$v->getHandle();           
+             $this->attr["INST_DEL"][$k]=$v->marked;
+             $this->attr["INST_FCACHE"][$k]=$v->fcache;
+         };
+         $this->attr["INSTHANDL_LIST"]=$insthandl;
          $this->attr["LIST_HANDLE"]=$this->list->getHandle();
          return $this->attr;
      }
      function restoreData($data) {        
          $this->attr=$data;
+         # convert handles back to proxy objs
          $this->list=new gnurpc_proxyobj($this->dbcon->link,
                                          $this->attr["LIST_HANDLE"]);
  
+         $insthandl=$this->attr["INSTHANDL_LIST"];
+         if (count($insthandl)) {
+             while (list($k,$v)=each($insthandl)) {
+                 $this->instances[$k]=
+                      new gnurpc_proxyobj($this->dbcon->link,$v);
+                 $this->instances[$k]->marked=
+                      $this->attr["INST_DEL"][$k];
+                 $this->instances[$k]->fcache=
+                      $this->attr["INST_FCACHE"][$k];
+             };
+         }
      }
  }
  
Index: gnue/phpforms/src/gnue-forms.php
diff -c gnue/phpforms/src/gnue-forms.php:1.5 
gnue/phpforms/src/gnue-forms.php:1.6
*** gnue/phpforms/src/gnue-forms.php:1.5        Fri Jul  5 18:36:34 2002
--- gnue/phpforms/src/gnue-forms.php    Thu Jul 11 19:02:11 2002
***************
*** 92,105 ****
      function setAttr($attr) {
          $this->attr=$attr;
      }
!     function getEmptyResultSet($table) {  
          $r=new Resultset;
          $r->setDatabase($this);
          $r->setTable($table);
          return $r;
      }
!     function getResultSet($table,$query) {
!         return $this->getEmptyResultSet($table);
      }
      // global commit /rollback
      function commit() {
--- 92,110 ----
      function setAttr($attr) {
          $this->attr=$attr;
      }
! 
!     function restoreResultSet($table,$data) {
!         $r=$this->getEmptyResultSet($table,$order_by);
!         $r->restoreData($data);
!     }
!     function getEmptyResultSet($table,$order_by) {  
          $r=new Resultset;
          $r->setDatabase($this);
          $r->setTable($table);
          return $r;
      }
!     function getResultSet($table,$query,$order_by) {
!         return $this->getEmptyResultSet($table,$order_by);
      }
      // global commit /rollback
      function commit() {
***************
*** 291,297 ****
              $this->doPreQuery($attr["PREQUERY"]);
          } else {            
              $this->Dataset=
!                  $this->dbcon->getEmptyResultSet($this->attr["TABLE"]);
          }/*
          if (isset($attr["MASTER"])) {
              $this->doPreQuery($attr["PREQUERY"]);
--- 296,303 ----
              $this->doPreQuery($attr["PREQUERY"]);
          } else {            
              $this->Dataset=
!                  $this->dbcon->getEmptyResultSet($this->attr["TABLE"],
!                                                  $this->attr["ORDER_BY"]);
          }/*
          if (isset($attr["MASTER"])) {
              $this->doPreQuery($attr["PREQUERY"]);
***************
*** 373,395 ****
          if ((strlen($this->attr["TABLE"])>0)&&($this->querymode)) {
              $this->querymode=false;        
              // create sql
!             $sql = "select OID,* from ".$this->attr["TABLE"];
              reset($this->querydata);
              while (list($k,$v)=each($this->querydata)) {
                  if (strlen($v)>0) {
!                     $where=$where2." ".$k." LIKE '".$v."' ";
!                     $where2=$where."AND";
                      // get field info like: defaultQuery
                      // ignoreCaseOnquery, sloopyQuery...
                  }
              };
!             if (isset($where))
!                 $sql=$sql." WHERE ".$where;          
!             if (isset($this->attr["ORDER_BY"]))
!                 $sql=$sql." ORDER BY ".$this->attr["ORDER_BY"];
! 
              // execute query and store results
-             $dts=$this->dbcon->getResultSet($this->attr["TABLE"],$sql);
              $this->Dataset=&$dts;        
          }
      }
--- 379,404 ----
          if ((strlen($this->attr["TABLE"])>0)&&($this->querymode)) {
              $this->querymode=false;        
              // create sql
!             $querytable= array();
              reset($this->querydata);
              while (list($k,$v)=each($this->querydata)) {
                  if (strlen($v)>0) {
!                     $querytable[$k]=$v;
                      // get field info like: defaultQuery
                      // ignoreCaseOnquery, sloopyQuery...
                  }
              };
!             if (isset($this->attr["ORDER_BY"])) {
!                 
!                 $dts=$this->dbcon->getResultSet($this->attr["TABLE"],
!                                                 $querytable,
!                                                 $this->attr["ORDER_BY"]); 
!             } else {
!                
!                 $dts=$this->dbcon->getResultSet($this->attr["TABLE"],
!                                                 $querytable);
!             };
              // execute query and store results
              $this->Dataset=&$dts;        
          }
      }
***************
*** 410,417 ****
          DEBUG(3,"Restoring DATASOURCE: database='".$dbname."'");
          $this->dbcon=&$this->_parent->dbcons[$dbname];
          $this->Dataset=
!              $this->dbcon->getEmptyResultSet($this->attr["TABLE"]);
!         $this->Dataset->restoreData($data["dataset"]);
          $this->Dataset->dbcon=&$this->_parent->dbcons[$dbname];
      }
  }
--- 419,426 ----
          DEBUG(3,"Restoring DATASOURCE: database='".$dbname."'");
          $this->dbcon=&$this->_parent->dbcons[$dbname];
          $this->Dataset=
!              $this->dbcon->restoreResultSet($this->attr["TABLE"],
!                                             $data["dataset"]);
          $this->Dataset->dbcon=&$this->_parent->dbcons[$dbname];
      }
  }
***************
*** 1852,1881 ****
  
  ############### FILE HELPER.PHP ########## END #############
  
- ############### FILE DATABASE.PHP ######## BEGIN ###########
- 
- /*if (!($fior = fopen("/usr/local/var/run/geas-server.ior", "r"))) {
-     die("could not open IOR file");
- }
- 
- while ($data = fread($fior, 4096)) {
-     echo "loading ior\n<BR>";
- };
- 
- $obj = new OrbitObject ($ior);
- 
- $obj->SetInfo ("A 2GooD object");
- 
- echo $obj->GetInfo();
- 
- $obj->value = 42;
- 
- echo $obj->value;
- 
- exit(); */
- 
- ############### FILE DATABASE.PHP ######## END #############
- 
  ############### FILE SESSION.PHP ######### BEGIN ###########
  
  class UIsession {
--- 1861,1866 ----
***************
*** 2030,2037 ****
                  $this->form->rollback();
              } 
          }        
-         if (isset($this->form))
-             $this->data=$this->form->getBackupData();            
      }
      function show() {
          global $PHP_SELF;
--- 2015,2020 ----
***************
*** 2040,2073 ****
              if ($this->command=="help") {
                  $this->form->showAbout();
              } else {
                  $this->form->showPage();
                  echo "<P ALIGN=\"RIGHT\">Used GFD file: \"<A HREF=\"".
                      $PHP_SELF."?c=showsource\">".$this->gfdFileName.
                      "</A>\"</P>";
                  echo "<FONT COLOR=WHITE>";
!         list($usec, $sec) = explode(' ', microtime());
!         srand((float) $sec + ((float) $usec * 100000));
!         echo "x".rand(0,20000)."</FONT>";
! 
              }
          } else {
!             //   showQuestionPage
!             echo "<CENTER><H1>Welcome</H1>\n";
!             echo "<form enctype= \"multipart/form-data\" ".
!                 "action=\"".$PHP_SELF."\" method=\"post\">\n";
!             echo "<input type=\"hidden\" name=\"MAX_FILE_SIZE\"".
!                 " value=\"1000000\">\n";
!             echo "Try out your own GFD file:\n";
!             echo "<input name=\"userfile\" type=\"file\">\n";
!             echo "<input type=\"submit\" value=\"Try file\">";
!             echo "</form><BR>";
!           echo "Try a <A HREF=\"".$PHP_SELF."?c=demo\">simple demo</A>, ";
!         echo "<A HREF=\"".$PHP_SELF."?c=demo2\"> a database demo</A>, or<BR>";
!             echo " a <A HREF=\"".$PHP_SELF."?c=demo3\">WIZARD demo with many 
blocks and pages</A> (try PGUP,PGDN)";
!             echo "<BR><BR>Attention: IE and Konqueror are not supported at 
the moment. Just mozilla is working ok.";
!             echo "<CENTER>\n";
          }
          writeHTMLfooter();
      }
      function save() { 
          global $HTTP_SESSION_VARS;
--- 2023,2063 ----
              if ($this->command=="help") {
                  $this->form->showAbout();
              } else {
+                 // show Form
                  $this->form->showPage();
                  echo "<P ALIGN=\"RIGHT\">Used GFD file: \"<A HREF=\"".
                      $PHP_SELF."?c=showsource\">".$this->gfdFileName.
                      "</A>\"</P>";
                  echo "<FONT COLOR=WHITE>";
!                 // trick to make every page become different
!                 list($usec, $sec) = explode(' ', microtime());
!                 srand((float) $sec + ((float) $usec * 100000));
!                 echo "x".rand(0,20000)."</FONT>";
              }
          } else {
!             $this->showDemoPage();
          }
          writeHTMLfooter();
+         if (isset($this->form))
+             $this->data=$this->form->getBackupData();
+     }
+     function showDemoPage() {
+         global $PHP_SELF;
+         //   showQuestionPage
+         echo "<CENTER><H1>Welcome</H1>\n";
+         echo "<form enctype= \"multipart/form-data\" ".
+             "action=\"".$PHP_SELF."\" method=\"post\">\n";
+         echo "<input type=\"hidden\" name=\"MAX_FILE_SIZE\"".
+             " value=\"1000000\">\n";
+         echo "Try out your own GFD file:\n";
+         echo "<input name=\"userfile\" type=\"file\">\n";
+         echo "<input type=\"submit\" value=\"Try file\">";
+         echo "</form><BR>";
+           echo "Try a <A HREF=\"".$PHP_SELF."?c=demo\">simple demo</A>, ";
+         echo "<A HREF=\"".$PHP_SELF."?c=demo2\"> a database demo</A>, or<BR>";
+         echo " a <A HREF=\"".$PHP_SELF."?c=demo3\">WIZARD demo with many 
blocks and pages</A> (try PGUP,PGDN)";
+         echo "<BR><BR>Attention: IE and Konqueror are not supported at the 
moment. Just mozilla is working ok.";
+         echo "<CENTER>\n";        
      }
      function save() { 
          global $HTTP_SESSION_VARS;



reply via email to

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