diff options
Diffstat (limited to 'framework/Data/Common/Oracle')
-rw-r--r-- | framework/Data/Common/Oracle/TOracleCommandBuilder.php | 41 | ||||
-rw-r--r-- | framework/Data/Common/Oracle/TOracleMetaData.php | 43 |
2 files changed, 21 insertions, 63 deletions
diff --git a/framework/Data/Common/Oracle/TOracleCommandBuilder.php b/framework/Data/Common/Oracle/TOracleCommandBuilder.php index 8c60751a..a22c0f08 100644 --- a/framework/Data/Common/Oracle/TOracleCommandBuilder.php +++ b/framework/Data/Common/Oracle/TOracleCommandBuilder.php @@ -86,20 +86,14 @@ class TOracleCommandBuilder extends TDbCommandBuilder { $niniDoSelect = strpos($sql, 'SELECT') + 6; $nfimDoSelect = (strpos($sql, 'FROM') !== false ? strpos($sql, 'FROM') : $nfimDaSQL); - $niniDoWhere = strpos($sql, 'WHERE') + 5; - - $WhereConstraint = substr($sql, $niniDoWhere, $nfimDoWhere - $niniDoWhere); - - $WhereInSubSelect = ""; - if (trim($WhereConstraint) !== "") { - $WhereInSubSelect = "WHERE " . $WhereConstraint; - } + $WhereInSubSelect=""; + if(strpos($sql, 'WHERE')!==false) + $WhereInSubSelect = "WHERE " .substr($sql, strpos($sql, 'WHERE')+5, $nfimDoWhere - $niniDoWhere); $sORDERBY = ''; if (stripos($sql, 'ORDER') !== false) { $p = stripos($sql, 'ORDER'); - $sORDERBY = substr($sql, $p +8, 10000); - + $sORDERBY = substr($sql, $p +8); } $fields = substr($sql, 0, $nfimDoSelect); @@ -142,23 +136,18 @@ class TOracleCommandBuilder extends TDbCommandBuilder { ") WHERE {$pradoNUMLIN} >= {$offset} "; ************************* */ - $toReg = $offset + $limit -1; + $offset=(int)$offset; + $toReg = $offset + $limit ; $fullTableName = $this->getTableInfo()->getTableFullName(); - if (empty ($sORDERBY)) { - $newSql = " SELECT $fields FROM " . - "( " . - " SELECT ROW_NUMBER() OVER ( ORDER BY ROWNUM ) as {$pradoNUMLIN} {$aliasedFields} " . - " FROM {$fullTableName} {$fieldsALIAS}" . - ") nn " . - " WHERE nn.{$pradoNUMLIN} >= {$offset} AND nn.{$pradoNUMLIN} <= {$toReg} "; - } else { - $newSql = " SELECT $fields FROM " . - "( " . - " SELECT ROW_NUMBER() OVER ( ORDER BY {$sORDERBY} ) as {$pradoNUMLIN} {$aliasedFields} " . - " FROM {$fullTableName} {$fieldsALIAS} $WhereInSubSelect" . - ") nn " . - " WHERE nn.{$pradoNUMLIN} >= {$offset} AND nn.{$pradoNUMLIN} <= {$toReg} "; - } + if (empty ($sORDERBY)) + $sORDERBY="ROWNUM"; + + $newSql = " SELECT $fields FROM " . + "( " . + " SELECT ROW_NUMBER() OVER ( ORDER BY {$sORDERBY} ) -1 as {$pradoNUMLIN} {$aliasedFields} " . + " FROM {$fullTableName} {$fieldsALIAS} $WhereInSubSelect" . + ") nn " . + " WHERE nn.{$pradoNUMLIN} >= {$offset} AND nn.{$pradoNUMLIN} < {$toReg} "; //echo $newSql."\n<br>\n"; return $newSql; } diff --git a/framework/Data/Common/Oracle/TOracleMetaData.php b/framework/Data/Common/Oracle/TOracleMetaData.php index bb8e9b7b..5fdf1d5c 100644 --- a/framework/Data/Common/Oracle/TOracleMetaData.php +++ b/framework/Data/Common/Oracle/TOracleMetaData.php @@ -10,7 +10,10 @@ * @package System.Data.Common.Oracle */ - +/** + * Load the base TDbMetaData class. + */ +Prado::using('System.Data.Common.TDbMetaData'); Prado::using('System.Data.Common.Oracle.TOracleTableInfo'); Prado::using('System.Data.Common.Oracle.TOracleTableColumn'); @@ -22,28 +25,11 @@ Prado::using('System.Data.Common.Oracle.TOracleTableColumn'); * @package System.Data.Common.Oracle * @since 3.1 */ -class TOracleMetaData extends TComponent +class TOracleMetaData extends TDbMetaData { - private $_tableInfoCache=array(); - private $_connection; private $_defaultSchema = 'system'; - /** - * @param TDbConnection database connection. - */ - public function __construct($conn) - { - $this->_connection=$conn; - } - - /** - * @return TDbConnection database connection. - */ - public function getDbConnection() - { - return $this->_connection; - } - + /** * @return string TDbTableInfo class name. */ @@ -69,23 +55,6 @@ class TOracleMetaData extends TComponent } /** - * Obtains table meta data information for the current connection and given table name. - * @param string table or view name - * @return TDbTableInfo table information. - */ - public function getTableInfo($tableName=null) - { - $key = $tableName===null?$this->getDbConnection()->getConnectionString():$tableName; - if(!isset($this->_tableInfoCache[$key])) - { - $class = $this->getTableInfoClass(); - $tableInfo = $tableName===null ? new $class : $this->createTableInfo($tableName); - $this->_tableInfoCache[$key] = $tableInfo; - } - return $this->_tableInfoCache[$key]; - } - - /** * @param string table name with optional schema name prefix, uses default schema name prefix is not provided. * @return array tuple as ($schemaName,$tableName) */ |