Class: dataSample

Attributes:
Inherits:
Implements:

Contents:

Introduction

Meta Data

Attention
Attention: There is no meta data for this class.

Constants

There are no constants defined for this class.

Properties

Methods

Also See

Attention
Attention: There are no additional references for this class.

Class Syntax

In file D:\oblib-core\php\oblib\dataList\dataSample.list.php between lines 64 and 221.

<?php
 
    
/**
     * 
     */

    
class dataSample extends dataSeries
    
{
        
        private 
$_dquQuery;
        
        private 
$_intSamplePage;
        private 
$_intSamplePages;
        private 
$_intSampleLength;
        private 
$_intResultLength;
        
        function 
__construct ($dquQuery)
        {
            if (!(
$dquQuery instanceof dataSampleQuery))
            {
                throw new 
ExceptionCore ('Query must implement dataSampleQuery: ' get_class ($dquQuery));
            }
            
            
$this->_dquQuery =& $dquQuery;
            
            
parent::__construct ($this->_dquQuery->QuerySelect_Name (), 'data');
            
            
// Main Clauses
            
$strParam '';
            
$arrParam = Array ();
            
$strClause_Field    $this->_dquQuery->QuerySelect_Field ();
            
$strClause_Table    $this->_dquQuery->QuerySelect_Table ();
            
$strClause_Where    $this->_dquQuery->QuerySelect_Where ()->___Render ($strParam$arrParam);
            
$strClause_GroupBy    $this->_dquQuery->QuerySelect_GroupBy ();
            
$strClause_OrderBy    $this->_dquQuery->QuerySelect_OrderBy ();
            
$strClause_Limit    '';
            
            
// Handle the GroupBy Clause
            
if ($strClause_GroupBy)
            {
                
$strClause_GroupBy 'GROUP BY ' $strClause_GroupBy;
            }
            
            
// Handle the OrderBy Clause
            
if ($strClause_OrderBy)
            {
                
$strClause_GroupBy 'ORDER BY ' $strClause_OrderBy;
            }
            
            
// Sample information
            
            
$strStatement  'SELECT    count(*) as `ResultLength` ';            // SELECT
            
$strStatement .= 'FROM        ' $strClause_Table ' ';                // FROM
            
$strStatement .= 'WHERE        ' $strClause_Where ' ';                // WHERE
            
$strStatement .= $strClause_GroupBy ' ';                            // GROUP BY
            
$smtStatement  $GLOBALS ['MySQL']->Prepare ($strStatement);
            
            if (!
$smtStatement)
            {
                throw new 
ExceptionMysql ($GLOBALS ['MySQL'], $strStatement);
            }
            
            if (
$arrParam)
            {
                
array_unshift ($arrParam$strParam);
                
                
call_user_func_array (
                    Array (
$smtStatement'bind_param'), 
                    
$arrParam
                
);
                
                
array_shift ($arrParam);
            }
            
            
$smtStatement->execute ();
            
$smtStatement->bind_result ($this->_intResultLength);
            
$smtStatement->fetch ();
            
$smtStatement->free_result ();
            
            if (
$this->_intSampleLength === NULL)    $this->_intSampleLength = (int) $this->_intResultLength;
            if (
$this->_intSampleLength != 0)        $this->_intSamplePages = (int) ceil ($this->_intResultLength $this->_intSampleLength);
            else                                    
$this->_intSamplePages = (int) 0;
            
            
$this->_intSamplePage    = (int) $this->_dquQuery->QuerySelect_SamplePage ();
            
$this->_intSampleLength    = (int) $this->_dquQuery->QuerySelect_SampleLength ();
            
            
$this->___setAttribute ('ResultLength',    $this->_intResultLength);
            
$this->___setAttribute ('SampleLength',    $this->_intSampleLength);
            
$this->___setAttribute ('SamplePages',    $this->_intSamplePages);
            
$this->___setAttribute ('SamplePage',    $this->_intSamplePage);
            
            
// Handle the Limit Clause
            
if ($this->_intSampleLength)
            {
                
$strClause_Limit .= 'LIMIT ' . (($this->_intSamplePage 1) * $this->_intSampleLength) . ', ' $this->_intSampleLength;
            }
            
            
// Get the Result
            
$strStatement  'SELECT    ' $strClause_Field ' ';                // SELECT
            
$strStatement .= 'FROM        ' $strClause_Table ' ';                // FROM
            
$strStatement .= 'WHERE        ' $strClause_Where ' ';                // WHERE
            
$strStatement .= $strClause_GroupBy ' ';                            // GROUP BY
            
$strStatement .= $strClause_OrderBy ' ';                            // ORDER BY
            
$strStatement .= $strClause_Limit;                                    // LIMIT
            
            
$smtStatement $GLOBALS ['MySQL']->Prepare ($strStatement);
            
            if (!
$smtStatement)
            {
                throw new 
ExceptionMysql ($GLOBALS ['MySQL'], $strStatement);
            }
            
            if (
$arrParam)
            {
                
array_unshift ($arrParam$strParam);
                
                
call_user_func_array (
                    Array (
$smtStatement'bind_param'), 
                    
$arrParam
                
);
                
                
array_shift ($arrParam);
            }
            
            
$smtStatement->execute ();
            
            
// Put the Database response into an ObLib object
            
$rmdMetaData $smtStatement->result_metadata ();
            
            
$arrData = Array ();
            
$arrReference = Array ();
            
            foreach (
$rmdMetaData->fetch_fields () as $objField)
            {
                
$arrData [$objField->name] = '';
                
$arrReference [] =& $arrData [$objField->name];
            }
            
            
call_user_func_array (
                Array (
$smtStatement'bind_result'), 
                
$arrReference
            
);
            
            
$arrQuerySelect_Return $this->_dquQuery->QuerySelect_Result ();
            
            while (
$smtStatement->Fetch ())
            {
                switch (
$arrQuerySelect_Return)
                {
                    case 
NULL:
                        
$objRow = new dataSampleResult ($this->_dquQuery$arrData);
                        break;
                        
                    default:
                        
$objRow call_user_func_array ($arrQuerySelect_Return, Array ($arrData));
                        break;
                }
                
                
$this->___Push ($objRow);
            }
            
            
$smtStatement->free_result ();
        }
    }

?>