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 // Helper variables
$myuid = -1; $myuid = -1;
$counter = 0; $counter = 0;
$tmpOldDirection = $this->_readDirection;
// if ( $this->_readDirection == EnumReadDirection::Forward )
if ( $this->_sortOrder == EnumSortingOrder::Ascending ) if ( $this->_sortOrder == EnumSortingOrder::Ascending )
{ {
// Move to the beginning of END file! // Move to the beginning of END file!
@ -496,7 +496,6 @@ class LogStreamDisk extends LogStream {
// Switch reading direction! // Switch reading direction!
$this->_readDirection = EnumReadDirection::Backward; $this->_readDirection = EnumReadDirection::Backward;
} }
// else if ( $this->_readDirection == EnumReadDirection::Backward )
else if ( $this->_sortOrder == EnumSortingOrder::Descending ) else if ( $this->_sortOrder == EnumSortingOrder::Descending )
{ {
// Move to the beginning of the file! // Move to the beginning of the file!
@ -511,6 +510,14 @@ class LogStreamDisk extends LogStream {
// Save the current UID as LastPage UID! // Save the current UID as LastPage UID!
$this->_lastPageUID = $myuid; $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 result!
return $this->_lastPageUID; return $this->_lastPageUID;

View File

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

View File

@ -230,9 +230,12 @@ if ( isset($content['Sources'][$currentSourceID]) ) // && $content['Sources'][$c
if ( $res == SUCCESS ) if ( $res == SUCCESS )
{ {
// TODO Implement ORDER // TODO Implement ORDER
$stream->SetReadDirection($content['read_direction']); $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 // Set current ID and init Counter
$uID = $content['uid_current']; $uID = $content['uid_current'];
$counter = 0; $counter = 0;
@ -245,7 +248,7 @@ if ( isset($content['Sources'][$currentSourceID]) ) // && $content['Sources'][$c
} }
else else
$ret = $stream->ReadNext($uID, $logArray); $ret = $stream->ReadNext($uID, $logArray);
// --- Check if Read was successfull! // --- Check if Read was successfull!
if ( $ret == SUCCESS ) if ( $ret == SUCCESS )
{ {
@ -617,10 +620,7 @@ if ( isset($content['Sources'][$currentSourceID]) ) // && $content['Sources'][$c
// --- // ---
// --- Handle uid_last page button // --- 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 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']) if ( $content['uid_last'] != -1 && $content['uid_last'] != $content['uid_current'])
$content['main_pager_last_found'] = true; $content['main_pager_last_found'] = true;