Fixed issues with the pager code changes in DB and DISK logstream

This commit is contained in:
Andre Lorbach 2008-05-23 16:43:24 +02:00
parent b81ba95db4
commit 672e835343
3 changed files with 94 additions and 55 deletions

View File

@ -486,8 +486,8 @@ class LogStreamDisk extends LogStream {
// Helper variables
$myuid = -1;
$counter = 0;
$tmpOldDirection = $this->_readDirection;
// if ( $this->_readDirection == EnumReadDirection::Forward )
if ( $this->_sortOrder == EnumSortingOrder::Ascending )
{
// Move to the beginning of END file!
@ -496,7 +496,6 @@ class LogStreamDisk extends LogStream {
// Switch reading direction!
$this->_readDirection = EnumReadDirection::Backward;
}
// else if ( $this->_readDirection == EnumReadDirection::Backward )
else if ( $this->_sortOrder == EnumSortingOrder::Descending )
{
// Move to the beginning of the file!
@ -512,6 +511,14 @@ class LogStreamDisk extends LogStream {
// Save the current UID as LastPage UID!
$this->_lastPageUID = $myuid;
// --- Restore reading direction and file position!
$this->_readDirection = $tmpOldDirection;
if ( $this->_readDirection == EnumReadDirection::Forward )
$this->Sseek($myuid, EnumSeek::BOS, 0);
else
$this->Sseek($myuid, EnumSeek::EOS, 0);
// ---
// Return result!
return $this->_lastPageUID;
}

View File

@ -57,6 +57,7 @@ class LogStreamPDO extends LogStream {
private $_currentPageNumber = -1;
private $_SQLwhereClause = "";
private $_myDBQuery = null;
// Constructor
public function LogStreamPDO($streamConfigObj) {
@ -128,6 +129,10 @@ class LogStreamPDO extends LogStream {
// Create SQL Where Clause first!
$this->CreateSQLWhereClause();
// Only obtain rowcount if enabled and not done before
if ( $this->_logStreamConfigObj->DBEnableRowCounting && $this->_totalRecordCount == -1 )
$this->_totalRecordCount = $this->GetRowCountFromTable();
// Success, this means we init the Pagenumber to ONE!
//$this->_currentPageNumber = 1;
@ -142,9 +147,12 @@ class LogStreamPDO extends LogStream {
*/
public function Close()
{
if ( $this->_dbhandle != null )
unset($this->_dbhandle);
return SUCCESS;
// trigger closing database query!
$this->DestroyMainSQLQuery();
// TODO CLOSE DB CONN?!
return true;
}
/**
@ -208,7 +216,7 @@ class LogStreamPDO extends LogStream {
// Now read new ones
$ret = $this->ReadNextRecordsFromDB($uID);
echo "mowl2";
//echo "1mowl " . $this->_currentRecordStart . "=" . $this->_currentRecordNum;
if ( !isset($this->bufferedRecords[$this->_currentRecordNum] ) )
$ret = ERROR_NOMORERECORDS;
@ -607,74 +615,95 @@ echo "mowl2";
return SUCCESS;
}
/*
* Create the SQL QUery!
*/
private function CreateMainSQLQuery($uID)
{
global $querycount;
// create query if necessary!
if ( $this->_myDBQuery == null )
{
// Get SQL Statement
$szSql = $this->CreateSQLStatement($uID);
// Perform Database Query
$this->_myDBQuery = $this->_dbhandle->query($szSql);
if ( !$this->_myDBQuery )
{
$this->PrintDebugError("Invalid SQL: ".$szSql);
return ERROR_DB_QUERYFAILED;
}
// Increment for the Footer Stats
$querycount++;
}
// return success state if reached this point!
return SUCCESS;
}
/*
* Destroy the SQL QUery!
*/
private function DestroyMainSQLQuery()
{
// create query if necessary!
if ( $this->_myDBQuery != null )
{
// Free Query ressources
// $this->_myDBQuery->closeCursor();
$this->_myDBQuery = null;
}
// return success state if reached this point!
return SUCCESS;
}
/*
* This helper function will read the next records into the buffer.
*/
private function ReadNextRecordsFromDB($uID)
{
global $querycount;
// Get SQL Statement
$szSql = $this->CreateSQLStatement($uID);
// Append LIMIT clause
//$szSql .= " LIMIT " . $this->_currentRecordStart . ", " . $this->_logStreamConfigObj->RecordsPerQuery;
// Perform Database Query
$myquery = $this->_dbhandle->query($szSql);
if ( !$myquery )
// Create query if necessary
if ( $this->_myDBQuery == null )
{
$this->PrintDebugError("Invalid SQL: ".$szSql);
return ERROR_DB_QUERYFAILED;
// return error if there was one!
if ( ($res = $this->CreateMainSQLQuery($uID)) != SUCCESS )
return $res;
}
// Copy rows into the buffer!
$iBegin = $this->_currentRecordNum;
// $result = $myquery->setFetchMode(PDO::FETCH_ASSOC);
$iCount = 0;
while( $this->_logStreamConfigObj->RecordsPerQuery > $iCount )
{
//Obtain next record
$myRow = $myquery->fetch(PDO::FETCH_ASSOC);
// if ( $iCount >= $this->_currentRecordStart )
// {
// print_r( $iCount );
// exit;
$myRow = $this->_myDBQuery->fetch(PDO::FETCH_ASSOC);
// Check if result was successfull!
if ( $myRow === FALSE )
break;
$this->bufferedRecords[$iBegin] = $myRow;
$iBegin++;
// }
// Increment counter
$iCount++;
}
/*
foreach ($myquery as $myRow)
{
$this->bufferedRecords[$iBegin] = $myRow;
$iBegin++;
}
*/
// Free Query ressources
// $myquery->closeCursor();
$myquery = null;
// Only obtain count if enabled and not done before
if ( $this->_logStreamConfigObj->DBEnableRowCounting && $this->_totalRecordCount == -1 )
{
$this->_totalRecordCount = $this->GetRowCountFromTable();
if ( $this->_totalRecordCount <= 0 )
return ERROR_NOMORERECORDS;
// if ( $this->_totalRecordCount <= 0 )
// return ERROR_NOMORERECORDS;
}
// Increment for the Footer Stats
$querycount++;
*/
// return success state if reached this point!
return SUCCESS;
}
@ -822,7 +851,10 @@ echo "mowl2";
$myQuery->closeCursor();
}
else
{
$this->PrintDebugError("RowCount query failed: " . $szSql);
$numRows = -1;
}
// return result!
return $numRows;

View File

@ -230,9 +230,12 @@ if ( isset($content['Sources'][$currentSourceID]) ) // && $content['Sources'][$c
if ( $res == SUCCESS )
{
// TODO Implement ORDER
$stream->SetReadDirection($content['read_direction']);
// Read First and LAST UID's before start reading the stream!
$content['uid_last'] = $stream->GetLastPageUID();
$content['uid_first'] = $stream->GetFirstPageUID();
// Set current ID and init Counter
$uID = $content['uid_current'];
$counter = 0;
@ -617,10 +620,7 @@ if ( isset($content['Sources'][$currentSourceID]) ) // && $content['Sources'][$c
// ---
// --- Handle uid_last page button
// Option the last UID from the stream!
$content['uid_last'] = $stream->GetLastPageUID();
$content['uid_first'] = $stream->GetFirstPageUID();
//!!!!!!!!
// if we found a last uid, and if it is not the current one (which means we already are on the last page ;)!
if ( $content['uid_last'] != -1 && $content['uid_last'] != $content['uid_current'])
$content['main_pager_last_found'] = true;