/**
  * Log explain of each query in log files after truncating plan_table
  * Only if debugExplain wanted and Oracle type database used
  *
  * @access protected
  * @param  query $sql
  * @see    self::execute()
  * @link   http://www.toutenligne.com/index.php?contenu=sql_explain&menu=sql
  */
 function _logExplain($sql)
 {
     if ($this->_bDebugExplain == true && $this->isOracle()) {
         /** TRUNCATE IN ORDER TO CLEAN PLAN_TABLE
             CAN BE REMOVED IF NO_WAIT ERRORS       **/
         $sSQLExplain = "TRUNCATE TABLE PLAN_TABLE";
         sqlrcur_sendQuery($this->curs_id, $sSQLExplain);
         /** In order to identify connexion file **/
         if ($this->_sFileExplainId == '') {
             $this->_sFileExplainId = date('Y-m-d H:i:s') . '-' . (microtime() + mt_rand(0, 999));
         }
         /** In order identify request in explain **/
         $iTime = microtime() + mt_rand(0, 999);
         /** Calculate execution time of the request on the server **/
         list($usec, $sec) = explode(" ", microtime());
         $time_Start = (double) $usec + (double) $sec;
         /** EXPLAIN QUERY **/
         $query = "EXPLAIN PLAN \r\n\t\t              SET STATEMENT_ID = '" . $iTime . "' \r\n\t\t              FOR " . $sql;
         sqlrcur_prepareQuery($this->curs_id, $query);
         sqlrcur_executeQuery($this->curs_id);
         list($usec, $sec) = explode(" ", microtime());
         $time_end = (double) $usec + (double) $sec;
         $_elapsedTime += $time_end - $time_Start;
         /** GETTING BACK INFORMATIONS **/
         $sSQLExplain = "SELECT  ID, PARENT_ID, OPERATION, OPTIONS, OBJECT_NAME, OBJECT_TYPE, \r\n\t                                COST, CARDINALITY, BYTES, OPTIMIZER\r\n                            FROM    PLAN_TABLE\r\n                            WHERE   STATEMENT_ID = '" . $iTime . "'\r\n                            ORDER   BY id, parent_id";
         sqlrcur_prepareQuery($this->curs_id, $sSQLExplain);
         $iResult = sqlrcur_executeQuery($this->curs_id);
         $iNbFirstResult = sqlrcur_rowCount($this->curs_id);
         $i = 0;
         $aResult = array();
         while ($i < $iNbFirstResult) {
             $aResult[] = sqlrcur_getRowAssoc($this->curs_id, $i);
             $i++;
         }
         /** Writing in log file **/
         $filepath = BASEPATH . '/logs/SQL/Explain/' . $this->_sFileExplainId . '.log';
         if (!($fp = @fopen($filepath, "a"))) {
             return FALSE;
         }
         fwrite($fp, str_replace("\n", ' ', $sql) . ' ( ' . round($_elapsedTime, 4) . " sec )\n");
         foreach ($aResult as $aExplain) {
             $message = $aExplain['ID'] . '|' . $aExplain['PARENT_ID'] . '|' . $aExplain['OPERATION'] . '|' . $aExplain['OPTIONS'] . '|' . $aExplain['OBJECT_NAME'] . '|' . $aExplain['OBJECT_TYPE'] . '|' . $aExplain['COST'] . '|' . $aExplain['CARDINALITY'] . '|' . $aExplain['BYTES'] . '|' . $aExplain['OPTIMIZER'] . "\n";
             flock($fp, LOCK_EX);
             fwrite($fp, $message);
             flock($fp, LOCK_UN);
         }
         fclose($fp);
         @chmod($filepath, 0666);
     }
 }
function da_sql_fetch_array($result, $config)
{
    static $counter = 0;
    if ($counter < $result[count]) {
        $row = sqlrcur_getRowAssoc($result[cur], $counter);
        $counter++;
    } else {
        $counter = 0;
        return false;
    }
    if ($config[sql_debug] == 'true') {
        print "<b>DEBUG(SQL,SQLRELAY DRIVER): Query Result: <pre>";
    }
    return $row;
}
 /**
  * Result - associative array
  *
  * Returns the result set as an array
  *
  * @access	protected
  * @return	array
  */
 function _fetch_array()
 {
     $aReturn = sqlrcur_getRowAssoc($this->curs_id, $this->current_row);
     $this->current_row++;
     return $aReturn;
 }