[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/phpforms/src database.inc gnue-forms.php p...
From: |
Jan Ischebeck |
Subject: |
gnue/phpforms/src database.inc gnue-forms.php p... |
Date: |
Tue, 07 May 2002 17:57:06 -0400 |
CVSROOT: /cvsroot/gnue
Module name: gnue
Changes by: Jan Ischebeck <address@hidden> 02/05/07 17:57:05
Modified files:
phpforms/src : database.inc gnue-forms.php
Added files:
phpforms/src : print-gfd.inc
Log message:
new version (some bugfixes, some improvements of the SessionCacheDB
code)
still pre-alpha.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/phpforms/src/print-gfd.inc?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/phpforms/src/database.inc.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.2&tr2=1.3&r1=text&r2=text
Patches:
Index: gnue/phpforms/src/database.inc
diff -c gnue/phpforms/src/database.inc:1.1 gnue/phpforms/src/database.inc:1.2
*** gnue/phpforms/src/database.inc:1.1 Mon May 6 18:52:10 2002
--- gnue/phpforms/src/database.inc Tue May 7 17:57:05 2002
***************
*** 329,380 ****
class SessionCacheDB extends database {
! var $datastore;
! var $dataindex;
! var $lastentry;
function SessionCacheDB() {
$this->attr=array();
$this->datastore=array();
! $this->dataindex=array();
DEBUG(3,"New SessionCacheDB object");
}
function getEmptyResultSet($table) {
$r=new SessionCacheResultSet;
$r->setDatabase($this);
$r->setTable($table);
return $r;
}
function getResultSet($table,$query) {
! $r=getEmptyResultSet($table);
$r->setFilter($query);
return $r;
}
// BACKUP / RESTORE FUNCTIONS
function getBackupData() {
$this->attr["DATASTORE"]=$this->datastore;
! $this->attr["DATAINDEX"]=$this->dataindex;
return $this->attr;
}
function restoreData($data) {
$this->attr=$data;
$this->datastore=$data["DATASTORE"];
! $this->dataindex=$data["DATAINDEX"];
}
function addentry($table,$data) {
! $num=$this->dataindex[$table];
$this->datastore[$table][$num+1]=$data;
! $this->dataindex[$table]=$num+1;
}
function getentry($table,$index) {
! if ($index<$this->dataindex[$table]) {
$data=$this->datastore[$table][$index];
return $data;
} else return array();
}
function addTable($table) {
if (!isset($this->datastore[$table])) {
$this->datastore[$table]=array();
! $this->dataindex[$table]=array();
}
}
}
--- 329,400 ----
class SessionCacheDB extends database {
! var $datastore; // storage array containing one array per stored
! // table. Every table consists of a an array
! // (0=>entry,2=>entry) ..
! var $datacount; // maximal number in the storage array
! // just needed for creating (adding) entries
function SessionCacheDB() {
$this->attr=array();
$this->datastore=array();
! $this->datacount=array();
! $this->datastore["demotable"]=array(0=>array("File"=>"Hello"));
DEBUG(3,"New SessionCacheDB object");
}
function getEmptyResultSet($table) {
$r=new SessionCacheResultSet;
$r->setDatabase($this);
$r->setTable($table);
+ $this->addTable($table);
return $r;
}
function getResultSet($table,$query) {
! $r=$this->getEmptyResultSet($table);
$r->setFilter($query);
return $r;
}
// BACKUP / RESTORE FUNCTIONS
function getBackupData() {
$this->attr["DATASTORE"]=$this->datastore;
! $this->attr["DATACOUNT"]=$this->datacount;
! # var_dump($this->datastore);
return $this->attr;
}
function restoreData($data) {
$this->attr=$data;
$this->datastore=$data["DATASTORE"];
! $this->datacount=$data["DATACOUNT"];
}
function addentry($table,$data) {
! $num=$this->datacount[$table];
$this->datastore[$table][$num+1]=$data;
! $this->datacount[$table]=$num+1;
! }
! function deleteEntry($table,$index) {
! if (isset($this->datastore[$table][$index]))
! unset($this->datastore[$table][$index]);
}
function getentry($table,$index) {
! if ($index<$this->datacount[$table]) {
$data=$this->datastore[$table][$index];
return $data;
} else return array();
}
+ function getEntryIndexList($table,$filter) {
+ $dataset=$this->datastore[$table];
+ $index=0;
+ $indexList=array();
+ while (list ($key, $value) = each ($dataset)) {
+ if (isset($value))
+ $indexList[$index]=$key;
+ }
+ return $indexList;
+ }
function addTable($table) {
+ DEBUG(5,"SessionCacheDB.AddTable: Tablename='".$table."'");
if (!isset($this->datastore[$table])) {
$this->datastore[$table]=array();
! $this->datacount[$table]=2;
}
}
}
***************
*** 384,399 ****
--- 404,428 ----
// just new records appear in the result set.
function setFilter($f) {
$this->filter=$f;
+ $this->EntryIndex=
+ $this->dbcon->getEntryIndexList($this->table,$f);
+ $this->lastentry=count($this->EntryIndex)-1;
+ if ($this->lastentry==-1) // a least one entry should be in the
+ $this->newEntry();
}
// cached datasets
var $to_delete; // list of records which should be deleted
var $changed; // list of changed records
+ var $EntryIndex; // index of entrys
function SessionCacheResultset() {
DEBUG(3,"New SessionCacheResultset object");
$this->to_delete=array();
$this->changed=array();
$this->filter=array();
+ $this->EntryIndex=array();
+ $this->lastentry=-1;
+ $this->newEntry();
}
// cache functions
***************
*** 403,409 ****
return true;
}
function markforRemoval($recordno) {
! if ($recordno<=$this->lastentry) {
if ($this->to_delete[$recordno])
$this->to_delete[$recordno]=true;
else
--- 432,439 ----
return true;
}
function markforRemoval($recordno) {
! $recordno=$this->EntryIndex[$recordno];
! if (isset($recordno)) {
if ($this->to_delete[$recordno])
$this->to_delete[$recordno]=true;
else
***************
*** 411,417 ****
}
}
function ismarkedforRemoval ($recordno) {
! if ($recordno<=$this->lastentry) {
return ($this->to_delete[$recordno]==true);
}
}
--- 441,448 ----
}
}
function ismarkedforRemoval ($recordno) {
! $recordno=$this->EntryIndex[$recordno];
! if (isset($recordno)) {
return ($this->to_delete[$recordno]==true);
}
}
***************
*** 455,489 ****
}
function newEntry($pos=-1) {
if ($pos==-1) {
! $this->lastentry=count($this->datacache);
! $this->datacache[$this->lastentry]=array();
// fill in default data
- $this->datastatus[$this->lastentry]="N";
} else {
$pos++;
! $prev=array_slice($this->datacache,0,$pos);
! $prevS=array_slice($this->datastatus,0,$pos);
! $next=array_slice($this->datacache,$pos);
! $nextS=array_slice($this->datastatus,$pos);
! $prev[$pos]=array(); // new element
! $prevS[$pos]="N"; // fill in default data
while ($pos<=$this->lastentry) {
$pos++;
! $prev[$pos]=$this->datacache[$pos-1];
! $prevS[$pos]=$this->datastatus[$pos-1];
}
! $this->datacache=$prev;
! $this->datastatus=$prevS;
! $this->lastentry=count($this->datacache)-1;
! }
}
function clearCache() {
$this->datacache=array();
$this->datastatus=array();
$this->lastentry=-1;
$this->newEntry();
}
function setCache($n) {
$this->datacache=$n;
$this->datastatus=array();
$this->lastentry=count($this->datacache)-1;
--- 486,521 ----
}
function newEntry($pos=-1) {
if ($pos==-1) {
! $this->lastentry=count($this->EntryIndex);
! $this->changed["N".$this->lastentry]=array();
! $this->EntryIndex[$this->lastentry]="N".$this->lastentry;
// fill in default data
} else {
$pos++;
! $prev=array_slice($this->EntryIndex,0,$pos);
! $next=array_slice($this->EntryIndex,$pos);
! // add new element
! $prev[$pos]="N".$this->lastentry."_".$pos;
! $this->changed[$prev[$pos]]=array();
! $prev[$this->lastentry]="N".$this->lastentry;
!
while ($pos<=$this->lastentry) {
$pos++;
! $prev[$pos]=$this->EntryIndex[$pos-1];
}
! $this->EntryIndex=$prev;
! $this->lastentry=count($this->EntryIndex)-1;
! }
}
function clearCache() {
+ print "<H1>clearCache called</H1>";
$this->datacache=array();
$this->datastatus=array();
$this->lastentry=-1;
$this->newEntry();
}
function setCache($n) {
+ print "<H1>setCache called</H1>";
$this->datacache=$n;
$this->datastatus=array();
$this->lastentry=count($this->datacache)-1;
***************
*** 492,527 ****
if ($this->lastentry==-1) // a least one entry should be in the
$this->newEntry(); // Resultset
}
! function getField($fieldname,$pos) {
! $ent=$this->dbcon->getentry($this->table,$pos);
return $ent[$fieldname];
}
function setField($fieldname,$pos,$data) {
! if ($pos<=$this->lastentry) {
! $ent=$this->dbcon->getentry($this->table,$pos);
! return $ent[$fieldname];
! $d_old=$this->datacache[$pos][$fieldname];
! if ($this->datastatus[$pos]=="") {
! if ($d_old!=$data) {
! $this->datastatus[$pos]="C";
! }
! };
! $this->datacache[$pos][$fieldname]=$data;
}
}
// BACKUP / RESTORE FUNCTIONS
function getBackupData() {
// for all datasources do getBackupData
! $data= array("cache"=>$this->datacache,
! "status"=>$this->datastatus,
! "table"=>$this->table);
! return $data;
}
function restoreData($data) {
! $this->datacache=$data["cache"];
! $this->datastatus=$data["status"];
! $this->lastentry=count($this->datacache)-1;
$this->table=$data["table"];
}
}
?>
--- 524,576 ----
if ($this->lastentry==-1) // a least one entry should be in the
$this->newEntry(); // Resultset
}
! function getField($fieldname,$pos) {
! DEBUG(7,"getField($fieldname,$pos)");
! $recordno=$this->EntryIndex[$pos];
! if (isset($recordno)) {
! $ent=$this->changed[$recordno];
! if (!isset($ent)) {
! $ent=$this->dbcon->getentry($this->table,$recordno);
! }
! }
return $ent[$fieldname];
}
function setField($fieldname,$pos,$data) {
! DEBUG(7,"setField($fieldname,$pos,$data)");
! $recordno=$this->EntryIndex[$pos];
! if (isset($recordno)) {
! $ent=$this->changed[$recordno];
! if (!isset($ent)) {
! $this->changed[$recordno]=
! $this->dbcon->getentry($this->table,$recordno);
! }
! $this->changed[$recordno][$fieldname]=$data;
}
}
// BACKUP / RESTORE FUNCTIONS
function getBackupData() {
// for all datasources do getBackupData
! $data= array("filter"=>$this->filter,
! "to_delete"=>$this->to_delete,
! "changed"=>$this->changed,
! "table"=>$this->table,
! "index"=>$this->EntryIndex);
! return $data;
}
function restoreData($data) {
! $this->to_delete=$data["to_delete"];
! $this->changed=$data["changed"];
! $this->filter=$data["filter"];
! $this->EntryIndex=$data["index"];
$this->table=$data["table"];
+ $this->lastentry=count($this->EntryIndex)-1;
+ # print "<BR>CHANGED:";
+ # var_dump($this->changed);
+ # print "<BR>EntryIndex:";
+ # var_dump($this->EntryIndex);
+ ## print "<BR>CHANGED:";
+ ## var_dump($this->changed);
+ print "<BR>";
}
}
?>
Index: gnue/phpforms/src/gnue-forms.php
diff -c gnue/phpforms/src/gnue-forms.php:1.2
gnue/phpforms/src/gnue-forms.php:1.3
*** gnue/phpforms/src/gnue-forms.php:1.2 Mon May 6 19:10:58 2002
--- gnue/phpforms/src/gnue-forms.php Tue May 7 17:57:05 2002
***************
*** 44,50 ****
function DEBUG($level,$str) {
global $debuglevel;
if ($level<=$debuglevel)
! print("DEBUG:".$str."<BR>");
}
############### FILE UI.PHP ############ BEGIN ###########
--- 44,50 ----
function DEBUG($level,$str) {
global $debuglevel;
if ($level<=$debuglevel)
! print("DEBUG (".$level."):".$str."<BR>");
}
############### FILE UI.PHP ############ BEGIN ###########
***************
*** 481,487 ****
return $style;
}
function getEntryData($ename,$row) {
! $fd=$this->dtsource->getField($ename,$this->cursor+$row);
if (($fd=="")||(!isset($fd))) {
$fd=$this->entrys[$ename]["DEFAULT"];
if (!isset($fd))
--- 481,489 ----
return $style;
}
function getEntryData($ename,$row) {
!
! $fd=$this->dtsource->getField($this->entrys[$ename]["FIELD"],
! $this->cursor+$row);
if (($fd=="")||(!isset($fd))) {
$fd=$this->entrys[$ename]["DEFAULT"];
if (!isset($fd))
***************
*** 545,552 ****
$this->rowcursor++;
} else {
$this->cursor++;
! };
!
}
}
function prevRecord() {
--- 547,553 ----
$this->rowcursor++;
} else {
$this->cursor++;
! }
}
}
function prevRecord() {
***************
*** 630,636 ****
$pd=parent::getBackupData();
//echo "<BR><BR>the parent: ";
//var_dump($pd);
! // echo "cursor: ".$this->cursor."<br>";
return array_merge($data,$pd);
}
function restoreData($data) {
--- 631,637 ----
$pd=parent::getBackupData();
//echo "<BR><BR>the parent: ";
//var_dump($pd);
! DEBUG(3,"Saved cursor (value: ".$this->cursor.")");
return array_merge($data,$pd);
}
function restoreData($data) {
***************
*** 640,647 ****
$this->entrys=$data["entrys"];
$dtsname=$data["dtsource"];
$this->cursor=$data["cursor"];
! $this->rowcursor=$data["rowcursor"];
! // echo "cursor: ".$this->cursor."<br>";
$this->dtsource=&$this->_parent->datasources[$dtsname];
if (!isset($this->dtsource))
echo "SESSION RESTORE ERROR";
--- 641,648 ----
$this->entrys=$data["entrys"];
$dtsname=$data["dtsource"];
$this->cursor=$data["cursor"];
! $this->rowcursor=$data["rowcursor"];
! DEBUG(3,"Restored cursor (value: ".$this->cursor.")");
$this->dtsource=&$this->_parent->datasources[$dtsname];
if (!isset($this->dtsource))
echo "SESSION RESTORE ERROR";
***************
*** 879,887 ****
$x=$attr["X"];
$y=$attr["Y"];
$width=$attr["WIDTH"];
! if (isset($this->sel_block)) {
! $rows=$this->sel_block->getRows($attr["ROWS"]);
! $rowsp=$this->sel_block->getRowSp($attr["ROWSPACER"]);
} else {
$rows=$attr["ROWS"];
$rowsp=$attr["ROWSPACER"];
--- 880,889 ----
$x=$attr["X"];
$y=$attr["Y"];
$width=$attr["WIDTH"];
! $sel_block=$this->_parent->sel_block;
! if (isset($sel_block)) {
! $rows=$sel_block->getRows($attr["ROWS"]);
! $rowsp=$sel_block->getRowSpacer($attr["ROWSPACER"]);
} else {
$rows=$attr["ROWS"];
$rowsp=$attr["ROWSPACER"];
***************
*** 1106,1111 ****
--- 1108,1116 ----
$dbn=$attr["NAME"]."_testdb";
$attr["DATABASE"]=$dbn; // write name back to db
}
+ if (!isset($attr["TABLE"])) {
+ $attr["TABLE"]="demotable";
+ }
$this->addDatabase(array("NAME"=>$dbn,
"PROVIDER"=>"SessionCache"));
DEBUG(3,"created a new session based database with the name
'$dbn'");
***************
*** 1443,1448 ****
--- 1448,1456 ----
}
$this->pageno=$no;
$this->sel_page=&$this->pages[$no];
+ $firstblockonPage=reset($this->sel_page->entryBlock);
+ $this->sel_block=&$this->blocks[$firstblockonPage];
+ DEBUG(3,"Forms.setPageNo was called.");
}
function nextPage() {
$this->setPageNo($this->pageno+1);
***************
*** 1465,1470 ****
--- 1473,1479 ----
showblockcount($this->blocks,"forms.updatefields");
}
function nextRecord() {
+ DEBUG(3,"Forms.nextRecord was called.");
$this->sel_block->nextRecord();
}
function prevRecord() {
***************
*** 1937,1944 ****
$this->form=&$resultform;
}
if ($this->command=="showsource") {
! include("printout.php");
! prettyPrintGFDfile($this->gfdFile);
echo "<BR><CENTER><A HREF=\"".$PHP_SELF.
"\">BACK</A></CENTER>";
exit();
--- 1946,1953 ----
$this->form=&$resultform;
}
if ($this->command=="showsource") {
! include("print-gfd.inc");
! prettyPrintGFDfile($this->gfdFile,$this->gfdFileName);
echo "<BR><CENTER><A HREF=\"".$PHP_SELF.
"\">BACK</A></CENTER>";
exit();
***************
*** 2007,2013 ****
$this->form->showAbout();
} else {
$this->form->showPage();
! echo "<P ALIGN=\"RIGHT\">Used GFD file: $filename.</P>";
echo "<FONT COLOR=WHITE>";
list($usec, $sec) = explode(' ', microtime());
srand((float) $sec + ((float) $usec * 100000));
--- 2016,2024 ----
$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));
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue/phpforms/src database.inc gnue-forms.php p...,
Jan Ischebeck <=