From bba85b544199f1a7e42920623f5c7ee74bb6c9c9 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 26 Apr 2009 20:05:09 +0000 Subject: [PATCH] - Oracle driver: fixed bug --- dibi/drivers/oracle.php | 2 +- dibi/drivers/pdo.php | 9 ++- examples/Nette/Debug.php | 142 ++++++++++++++++++++++++++------------- 3 files changed, 105 insertions(+), 48 deletions(-) diff --git a/dibi/drivers/oracle.php b/dibi/drivers/oracle.php index 68ef16e6..a03cc753 100644 --- a/dibi/drivers/oracle.php +++ b/dibi/drivers/oracle.php @@ -265,7 +265,7 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver { if ($offset > 0) { // see http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html - $sql = 'SELECT * FROM (SELECT t.*, ROWNUM AS __rnum FROM (' . $sql . ') t ' . ($limit >= 0 ? 'WHERE ROWNUM <= ' . ((int) $offset + (int) $limit) : '') . ') WHERE __rnum > '. (int) $offset; + $sql = 'SELECT * FROM (SELECT t.*, ROWNUM AS "__rnum" FROM (' . $sql . ') t ' . ($limit >= 0 ? 'WHERE ROWNUM <= ' . ((int) $offset + (int) $limit) : '') . ') WHERE "__rnum" > '. (int) $offset; } elseif ($limit >= 0) { $sql = 'SELECT * FROM (' . $sql . ') WHERE ROWNUM <= ' . (int) $limit; diff --git a/dibi/drivers/pdo.php b/dibi/drivers/pdo.php index f7e65289..fd511d89 100644 --- a/dibi/drivers/pdo.php +++ b/dibi/drivers/pdo.php @@ -320,10 +320,17 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver case 'sqlite': case 'sqlite2': - case 'oci': $sql .= ' LIMIT ' . $limit . ($offset > 0 ? ' OFFSET ' . (int) $offset : ''); break; + case 'oci': + if ($offset > 0) { + $sql = 'SELECT * FROM (SELECT t.*, ROWNUM AS "__rnum" FROM (' . $sql . ') t ' . ($limit >= 0 ? 'WHERE ROWNUM <= ' . ((int) $offset + (int) $limit) : '') . ') WHERE "__rnum" > '. (int) $offset; + } elseif ($limit >= 0) { + $sql = 'SELECT * FROM (' . $sql . ') WHERE ROWNUM <= ' . (int) $limit; + } + break; + case 'odbc': case 'mssql': if ($offset < 1) { diff --git a/examples/Nette/Debug.php b/examples/Nette/Debug.php index 16f29e62..a6e80791 100644 --- a/examples/Nette/Debug.php +++ b/examples/Nette/Debug.php @@ -17,7 +17,12 @@ * @version $Id$ */ -class +if(version_compare(PHP_VERSION,'5.2.0','<')){throw +new +Exception('Nette Framework requires PHP 5.2.0 or newer.');}@set_magic_quotes_runtime(FALSE);if(version_compare(PHP_VERSION,'5.2.2','<')){function +fixCallback(&$callback){if(is_object($callback)){$callback=array($callback,'__invoke');return;}if(is_string($callback)&&strpos($callback,':')){$callback=explode('::',$callback);}if(is_array($callback)&&is_string($callback[0])&&$a=strrpos($callback[0],'\\')){$callback[0]=substr($callback[0],$a+1);}}}else{function +fixCallback(&$callback){if(is_object($callback)){$callback=array($callback,'__invoke');}elseif(is_string($callback)&&$a=strrpos($callback,'\\')){$callback=substr($callback,$a+1);}elseif(is_array($callback)&&is_string($callback[0])&&$a=strrpos($callback[0],'\\')){$callback[0]=substr($callback[0],$a+1);}}}function +fixNamespace(&$class){if($a=strrpos($class,'\\')){$class=substr($class,$a+1);}}class ArgumentOutOfRangeException extends InvalidArgumentException{}class @@ -49,18 +54,12 @@ FatalErrorException extends Exception{public function -__construct($message,$code,$severity,$file,$line,$context){parent::__construct($message,$code);$this->file=$file;$this->line=$line;$this->context=$context;}}if(!function_exists('json_encode')){function -json_encode($val){if(is_array($val)&&(!$val||array_keys($val)===range(0,count($val)-1))){return'['.implode(',',array_map('json_encode',$val)).']';}if(is_array($val)||is_object($val)){$tmp=array();foreach($val -as$k=>$v){$tmp[]=json_encode((string)$k).':'.json_encode($v);}return'{'.implode(',',$tmp).'}';}if(is_string($val)){$val=str_replace(array("\\","\x00"),array("\\\\","\\u0000"),$val);return'"'.addcslashes($val,"\x8\x9\xA\xC\xD/\"").'"';}if(is_int($val)||is_float($val)){return -rtrim(rtrim(number_format($val,5,'.',''),'0'),'.');}if(is_bool($val)){return$val?'true':'false';}return'null';}}if(version_compare(PHP_VERSION,'5.2.2','<')){function -fixCallback(&$callback){if(is_string($callback)&&strpos($callback,':')){$callback=explode('::',$callback);}if(is_array($callback)&&is_string($callback[0])&&$a=strrpos($callback[0],'\\')){$callback[0]=substr($callback[0],$a+1);}}}else{function -fixCallback(&$callback){if(is_string($callback)&&$a=strrpos($callback,'\\')){$callback=substr($callback,$a+1);}elseif(is_array($callback)&&is_string($callback[0])&&$a=strrpos($callback[0],'\\')){$callback[0]=substr($callback[0],$a+1);}}}function -fixNamespace(&$class){if($a=strrpos($class,'\\')){$class=substr($class,$a+1);}}final +__construct($message,$code,$severity,$file,$line,$context){parent::__construct($message,$code);$this->file=$file;$this->line=$line;$this->context=$context;}}final class Framework{const NAME='Nette Framework';const VERSION='0.8';const -REVISION='223 released on 2009/03/08 06:04:31';final +REVISION='283 released on 2009/04/19 16:54:34';final public function __construct(){throw @@ -74,7 +73,10 @@ static function promo($xhtml=TRUE){echo'Powered by Nette Framework':'>'),'';}}final class -Debug{public +Debug{const +DEVELOPMENT=FALSE;const +PRODUCTION=TRUE;const +DETECT=NULL;public static$counters=array();public static$html;public static$productionMode;public @@ -98,7 +100,11 @@ static$time;const LOG='LOG';const INFO='INFO';const WARN='WARN';const -ERROR='ERROR';final +ERROR='ERROR';const +TRACE='TRACE';const +EXCEPTION='EXCEPTION';const +GROUP_START='GROUP_START';const +GROUP_END='GROUP_END';final public function __construct(){throw @@ -106,7 +112,7 @@ new LogicException("Cannot instantiate static class ".get_class($this));}public static function -init(){self::$time=microtime(TRUE);self::$consoleMode=PHP_SAPI==='cli';self::$productionMode=NULL;self::$firebugDetected=isset($_SERVER['HTTP_USER_AGENT'])&&strpos($_SERVER['HTTP_USER_AGENT'],'FirePHP/');self::$ajaxDetected=isset($_SERVER['HTTP_X_REQUESTED_WITH'])&&$_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest';}public +init(){self::$time=microtime(TRUE);self::$consoleMode=PHP_SAPI==='cli';self::$productionMode=self::DETECT;self::$firebugDetected=isset($_SERVER['HTTP_USER_AGENT'])&&strpos($_SERVER['HTTP_USER_AGENT'],'FirePHP/');self::$ajaxDetected=isset($_SERVER['HTTP_X_REQUESTED_WITH'])&&$_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest';}public static function dump($var,$return=FALSE){if(!$return&&self::$productionMode){return$var;}$output="
".self::_dump($var,0)."
\n";if(self::$consoleMode){$output=htmlspecialchars_decode(strip_tags($output),ENT_NOQUOTES);}if($return){return$output;}else{echo$output;return$var;}}private @@ -120,12 +126,12 @@ function timer($name=NULL){static$time=array();$now=microtime(TRUE);$delta=isset($time[$name])?$now-$time[$name]:0;$time[$name]=$now;return$delta;}public static function -enable($level=NULL,$logFile=NULL,$email=NULL){if(version_compare(PHP_VERSION,'5.2.1')===0){throw +enable($productionMode=NULL,$logFile=NULL,$email=NULL){if(version_compare(PHP_VERSION,'5.2.1')===0){throw new -NotSupportedException(__METHOD__.' is not supported in PHP 5.2.1');}error_reporting($level===NULL?E_ALL|E_STRICT:$level);if(self::$productionMode===NULL){if(class_exists('Environment')){self::$productionMode=Environment::isProduction();}elseif(isset($_SERVER['SERVER_ADDR'])){$oct=explode('.',$_SERVER['SERVER_ADDR']);self::$productionMode=$_SERVER['SERVER_ADDR']!=='::1'&&(count($oct)!==4||($oct[0]!=='10'&&$oct[0]!=='127'&&($oct[0]!=='172'||$oct[1]<16||$oct[1]>31)&&($oct[0]!=='169'||$oct[1]!=='254')&&($oct[0]!=='192'||$oct[1]!=='168')));}else{self::$productionMode=!self::$consoleMode;}}if(self::$productionMode&&$logFile!==FALSE){self::$logFile='php_error.log';if(class_exists('Environment')){if(is_string($logFile)){self::$logFile=Environment::expand($logFile);}else -try{self::$logFile=Environment::expand('%logDir%/php_error.log');}catch(InvalidStateException$e){}}elseif(is_string($logFile)){self::$logFile=$logFile;}ini_set('error_log',self::$logFile);}if(function_exists('ini_set')){ini_set('display_startup_errors',!self::$productionMode);ini_set('display_errors',!self::$productionMode);ini_set('html_errors',!self::$consoleMode);ini_set('log_errors',(bool)self::$logFile);}elseif(self::$productionMode){throw +NotSupportedException(__METHOD__.' is not supported in PHP 5.2.1');}error_reporting(E_ALL|E_STRICT);if(is_bool($productionMode)){self::$productionMode=$productionMode;}if(self::$productionMode===self::DETECT){if(class_exists('Environment')){self::$productionMode=Environment::isProduction();}elseif(isset($_SERVER['SERVER_ADDR'])||isset($_SERVER['LOCAL_ADDR'])){$addr=isset($_SERVER['SERVER_ADDR'])?$_SERVER['SERVER_ADDR']:$_SERVER['LOCAL_ADDR'];$oct=explode('.',$addr);self::$productionMode=$addr!=='::1'&&(count($oct)!==4||($oct[0]!=='10'&&$oct[0]!=='127'&&($oct[0]!=='172'||$oct[1]<16||$oct[1]>31)&&($oct[0]!=='169'||$oct[1]!=='254')&&($oct[0]!=='192'||$oct[1]!=='168')));}else{self::$productionMode=!self::$consoleMode;}}if(self::$productionMode&&$logFile!==FALSE){self::$logFile='log/php_error.log';if(class_exists('Environment')){if(is_string($logFile)){self::$logFile=Environment::expand($logFile);}else +try{self::$logFile=Environment::expand('%logDir%/php_error.log');}catch(InvalidStateException$e){}}elseif(is_string($logFile)){self::$logFile=$logFile;}ini_set('error_log',self::$logFile);}if(function_exists('ini_set')){ini_set('display_errors',!self::$productionMode);ini_set('html_errors',!self::$consoleMode);ini_set('log_errors',(bool)self::$logFile);}elseif(ini_get('log_errors')!=(bool)self::$logFile||(ini_get('display_errors')!=!self::$productionMode&&ini_get('display_errors')!==(self::$productionMode?'stderr':'stdout'))){throw new -NotSupportedException('Function ini_set() is not enabled.');}self::$sendEmails=$logFile&&$email;if(self::$sendEmails){if(is_string($email)){self::$emailHeaders['To']=$email;}elseif(is_array($email)){self::$emailHeaders=$email+self::$emailHeaders;}if(mt_rand()/mt_getrandmax()1,E_CORE_ERROR=>1,E_COMPILE_ERROR=>1,E_USER_ERROR=>1,E_PARSE=>1,E_RECOVERABLE_ERROR=>1);if(isset($fatals[$severity])){throw new FatalErrorException($message,0,$severity,$file,$line,$context);}elseif(($severity&error_reporting())!==$severity){return -NULL;}static$types=array(E_WARNING=>'Warning',E_USER_WARNING=>'Warning',E_NOTICE=>'Notice',E_USER_NOTICE=>'Notice',E_STRICT=>'Strict standards',E_DEPRECATED=>'Deprecated');$type=isset($types[$severity])?$types[$severity]:'Unknown error';if(self::$logFile){if(self::$sendEmails){self::sendEmail("$type: $message in $file on line $line");}return -FALSE;}elseif(!self::$productionMode&&self::$firebugDetected&&!headers_sent()){$message=strip_tags($message);self::fireLog("$type: $message in $file on line $line",'WARN');return +NULL;}static$types=array(E_WARNING=>'Warning',E_USER_WARNING=>'Warning',E_NOTICE=>'Notice',E_USER_NOTICE=>'Notice',E_STRICT=>'Strict standards',E_DEPRECATED=>'Deprecated',E_USER_DEPRECATED=>'Deprecated');$type=isset($types[$severity])?$types[$severity]:'Unknown error';if(self::$logFile){if(self::$sendEmails){self::sendEmail("$type: $message in $file on line $line");}return +FALSE;}elseif(!self::$productionMode&&self::$firebugDetected&&!headers_sent()){$message=strip_tags($message);self::fireLog("$type: $message in $file on line $line",self::ERROR);return NULL;}return FALSE;}public static function processException(Exception$exception,$outputAllowed=FALSE){if(self::$logFile){error_log("PHP Fatal error: Uncaught $exception");$file=@strftime('%d-%b-%Y %H-%M-%S ',Debug::$time).strstr(number_format(Debug::$time,4,'~',''),'~');$file=dirname(self::$logFile)."/exception $file.html";self::$logHandle=@fopen($file,'x');if(self::$logHandle){ob_start(array(__CLASS__,'writeFile'),1);self::paintBlueScreen($exception);ob_end_flush();fclose(self::$logHandle);}if(self::$sendEmails){self::sendEmail((string)$exception);}}elseif(self::$productionMode){}elseif(self::$consoleMode){if($outputAllowed){echo"$exception\n";foreach(self::$colophons as$callback){foreach((array)call_user_func($callback,'bluescreen')as$line)echo -strip_tags($line)."\n";}}}elseif(self::$firebugDetected&&self::$ajaxDetected&&!headers_sent()){self::fireLog($exception);}elseif($outputAllowed){self::paintBlueScreen($exception);}elseif(self::$firebugDetected&&!headers_sent()){self::fireLog($exception);}}public +strip_tags($line)."\n";}}}elseif(self::$firebugDetected&&self::$ajaxDetected&&!headers_sent()){self::fireLog($exception,self::EXCEPTION);}elseif($outputAllowed){self::paintBlueScreen($exception);}elseif(self::$firebugDetected&&!headers_sent()){self::fireLog($exception,self::EXCEPTION);}}public static function paintBlueScreen(Exception$exception){$internals=array();foreach(array('Object','ObjectMixin')as$class){if(class_exists($class,FALSE)){$rc=new @@ -155,8 +161,8 @@ _netteDebugPrintCode($file,$line,$count=15){if(function_exists('ini_set')){ini_s as$n=>$s){$s=str_replace(array("\r","\n"),array('',''),$s);if($n===$line){printf("Line %{$numWidth}s: %s\n%s",$n,strip_tags($s),preg_replace('#[^>]*(<[^>]+>)[^<]*#','$1',$s));}else{printf("Line %{$numWidth}s: %s\n",$n,$s);}}echo'';}function _netteOpenPanel($name,$collapsed){static$id;$id++;?>
-

+

text-align: left; } + #netteBluescreen * { + color: inherit; + background: inherit; + text-align: inherit; + } + #netteBluescreenIcon { position: absolute; right: .5em; @@ -201,6 +213,8 @@ htmlspecialchars(get_class($exception))?> z-index: 23179; color: black; text-decoration: none; + background: red; + padding: 3px; } #netteBluescreen h1 { @@ -220,6 +234,7 @@ htmlspecialchars(get_class($exception))?> } #netteBluescreen a span { + font-family: sans-serif; color: #999; } @@ -301,14 +316,14 @@ htmlspecialchars(get_class($exception))?> /* .collapsed { display: none; } '); - function toggle(link, panel) + function netteToggle(link, panelId) { var span = link.getElementsByTagName('span')[0]; - var div = document.getElementById(panel); - var collapsed = div.currentStyle ? div.currentStyle.display == 'none' : getComputedStyle(div, null).display == 'none'; + var panel = document.getElementById(panelId); + var collapsed = panel.currentStyle ? panel.currentStyle.display == 'none' : getComputedStyle(panel, null).display == 'none'; - span.innerHTML = String.fromCharCode(collapsed ? 0x25bc : 0x25b6); - div.style.display = collapsed ? 'block' : 'none'; + span.innerHTML = String.fromCharCode(collapsed ? 0x25bc : 0x25ba); + panel.style.display = collapsed ? 'block' : 'none'; return true; } @@ -320,7 +335,7 @@ htmlspecialchars(get_class($exception))?>
- +
@@ -372,12 +387,12 @@ htmlSpecialChars(basename(dirname($row['file']))),'/',htmlSpecialChars(basena <PHP inner-code> - ')">source   + ')">source   - (')">arguments ) + (')">arguments )

@@ -440,7 +455,7 @@ as$k=>$v){echo'$',htmlspecialchars($k),'';echo'',(isset($keyFil -

Constants

+

Constants

$v){echo'';echo' -

Included files (Included files ()

',htmlspecialchars($k),'
- +paintProfiler(){if(!self::$enabledProfiler||self::$productionMode){return;}self::$enabledProfiler=FALSE;if(self::$firebugDetected){self::fireLog('Nette profiler',self::GROUP_START);foreach(self::$colophons +as$callback){foreach((array)call_user_func($callback,'profiler')as$line)self::fireLog(strip_tags($line));}self::fireLog(NULL,self::GROUP_END);}if(!self::$ajaxDetected){$colophons=self::$colophons;?>