diff options
Diffstat (limited to 'framework/Data')
-rw-r--r-- | framework/Data/Common/Mssql/TMssqlMetaData.php | 11 | ||||
-rw-r--r-- | framework/Data/Common/Mysql/TMysqlMetaData.php | 11 | ||||
-rw-r--r-- | framework/Data/Common/Pgsql/TPgsqlMetaData.php | 11 | ||||
-rw-r--r-- | framework/Data/Common/Sqlite/TSqliteMetaData.php | 11 | ||||
-rw-r--r-- | framework/Data/Common/TDbMetaData.php | 23 | ||||
-rw-r--r-- | framework/Data/Common/TDbTableInfo.php | 2 | ||||
-rw-r--r-- | framework/Data/SqlMap/Configuration/TSqlMapStatement.php | 24 | ||||
-rw-r--r-- | framework/Data/SqlMap/Statements/TMappedStatement.php | 6 | ||||
-rw-r--r-- | framework/Data/SqlMap/Statements/TPreparedCommand.php | 12 |
9 files changed, 85 insertions, 26 deletions
diff --git a/framework/Data/Common/Mssql/TMssqlMetaData.php b/framework/Data/Common/Mssql/TMssqlMetaData.php index 72d297f7..37ce124f 100644 --- a/framework/Data/Common/Mssql/TMssqlMetaData.php +++ b/framework/Data/Common/Mssql/TMssqlMetaData.php @@ -27,6 +27,14 @@ Prado::using('System.Data.Common.Mssql.TMssqlTableInfo'); class TMssqlMetaData extends TDbMetaData
{
/**
+ * @return string TDbTableInfo class name.
+ */
+ protected function getTableInfoClass()
+ {
+ return 'TMssqlTableInfo';
+ }
+
+ /**
* Get the column definitions for given table.
* @param string table name.
* @return TMssqlTableInfo table information.
@@ -130,7 +138,8 @@ EOD; if($col['TABLE_TYPE']==='VIEW')
$info['IsView'] = true;
list($primary, $foreign) = $this->getConstraintKeys($col);
- return new TMssqlTableInfo($info,$primary,$foreign);
+ $class = $this->getTableInfoClass();
+ return new $class($info,$primary,$foreign);
}
/**
diff --git a/framework/Data/Common/Mysql/TMysqlMetaData.php b/framework/Data/Common/Mysql/TMysqlMetaData.php index 89e9e3ca..3b9a12f7 100644 --- a/framework/Data/Common/Mysql/TMysqlMetaData.php +++ b/framework/Data/Common/Mysql/TMysqlMetaData.php @@ -32,6 +32,14 @@ class TMysqlMetaData extends TDbMetaData private $_serverVersion=0;
/**
+ * @return string TDbTableInfo class name.
+ */
+ protected function getTableInfoClass()
+ {
+ return 'TMysqlTableInfo';
+ }
+
+ /**
* Get the column definitions for given table.
* @param string table name.
* @return TMysqlTableInfo table information.
@@ -185,7 +193,8 @@ class TMysqlMetaData extends TDbMetaData if($this->getIsView($schemaName,$tableName))
$info['IsView'] = true;
list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName);
- return new TMysqlTableInfo($info,$primary,$foreign);
+ $class = $this->getTableInfoClass();
+ return new $class($info,$primary,$foreign);
}
/**
diff --git a/framework/Data/Common/Pgsql/TPgsqlMetaData.php b/framework/Data/Common/Pgsql/TPgsqlMetaData.php index c68bbaa0..0b647445 100644 --- a/framework/Data/Common/Pgsql/TPgsqlMetaData.php +++ b/framework/Data/Common/Pgsql/TPgsqlMetaData.php @@ -29,6 +29,14 @@ class TPgsqlMetaData extends TDbMetaData private $_defaultSchema = 'public';
/**
+ * @return string TDbTableInfo class name.
+ */
+ protected function getTableInfoClass()
+ {
+ return 'TPgsqlTableInfo';
+ }
+
+ /**
* @param string default schema.
*/
public function setDefaultSchema($schema)
@@ -126,7 +134,8 @@ EOD; if($this->getIsView($schemaName,$tableName))
$info['IsView'] = true;
list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName);
- return new TPgsqlTableInfo($info,$primary,$foreign);
+ $class = $this->getTableInfoClass();
+ return new $class($info,$primary,$foreign);
}
/**
diff --git a/framework/Data/Common/Sqlite/TSqliteMetaData.php b/framework/Data/Common/Sqlite/TSqliteMetaData.php index 5e1c5f77..aa2ed724 100644 --- a/framework/Data/Common/Sqlite/TSqliteMetaData.php +++ b/framework/Data/Common/Sqlite/TSqliteMetaData.php @@ -27,6 +27,14 @@ Prado::using('System.Data.Common.Sqlite.TSqliteTableInfo'); class TSqliteMetaData extends TDbMetaData
{
/**
+ * @return string TDbTableInfo class name.
+ */
+ protected function getTableInfoClass()
+ {
+ return 'TSqliteTableInfo';
+ }
+
+ /**
* Get the column definitions for given table.
* @param string table name.
* @return TPgsqlTableInfo table information.
@@ -55,7 +63,8 @@ class TSqliteMetaData extends TDbMetaData $info['IsView'] = true;
if(count($columns)===0)
throw new TDbException('dbmetadata_invalid_table_view', $tableName);
- $tableInfo = new TSqliteTableInfo($info,$primary,$foreign);
+ $class = $this->getTableInfoClass();
+ $tableInfo = new $class($info,$primary,$foreign);
$tableInfo->getColumns()->copyFrom($columns);
return $tableInfo;
}
diff --git a/framework/Data/Common/TDbMetaData.php b/framework/Data/Common/TDbMetaData.php index d0963f44..e7c53618 100644 --- a/framework/Data/Common/TDbMetaData.php +++ b/framework/Data/Common/TDbMetaData.php @@ -80,11 +80,16 @@ abstract class TDbMetaData extends TComponent * @param string table or view name
* @return TDbTableInfo table information.
*/
- public function getTableInfo($tableName)
+ public function getTableInfo($tableName=null)
{
- if(!isset($this->_tableInfoCache[$tableName]))
- $this->_tableInfoCache[$tableName] = $this->createTableInfo($tableName);
- return $this->_tableInfoCache[$tableName];
+ $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];
}
/**
@@ -92,7 +97,7 @@ abstract class TDbMetaData extends TComponent * @param string table name.
* @return TDbCommandBuilder command builder instance for the given table.
*/
- public function createCommandBuilder($tableName)
+ public function createCommandBuilder($tableName=null)
{
return $this->getTableInfo($tableName)->createCommandBuilder($this->getDbConnection());
}
@@ -102,6 +107,14 @@ abstract class TDbMetaData extends TComponent * @return TDbTableInfo driver dependent create builder.
*/
abstract protected function createTableInfo($tableName);
+
+ /**
+ * @return string TDbTableInfo class name.
+ */
+ protected function getTableInfoClass()
+ {
+ return 'TDbTableInfo';
+ }
}
?>
\ No newline at end of file diff --git a/framework/Data/Common/TDbTableInfo.php b/framework/Data/Common/TDbTableInfo.php index 9689630f..ee5d2d00 100644 --- a/framework/Data/Common/TDbTableInfo.php +++ b/framework/Data/Common/TDbTableInfo.php @@ -33,7 +33,7 @@ class TDbTableInfo extends TComponent * Sets the database table meta data information.
* @param array table column information.
*/
- public function __construct($tableInfo,$primary=array(),$foreign=array())
+ public function __construct($tableInfo=array(),$primary=array(),$foreign=array())
{
$this->_info=$tableInfo;
$this->_primaryKeys=$primary;
diff --git a/framework/Data/SqlMap/Configuration/TSqlMapStatement.php b/framework/Data/SqlMap/Configuration/TSqlMapStatement.php index 5d2640e9..f5c43594 100644 --- a/framework/Data/SqlMap/Configuration/TSqlMapStatement.php +++ b/framework/Data/SqlMap/Configuration/TSqlMapStatement.php @@ -311,18 +311,6 @@ class TSqlMapSelect extends TSqlMapStatement }
/**
- * TSqlMapDelete class corresponds to the <delete> element.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- * @since 3.1
- */
-class TSqlMapDelete extends TSqlMapUpdate
-{
-}
-
-/**
* TSqlMapInsert class corresponds to the <insert> element.
*
* The <insert> element allows <selectKey> child elements that can be used
@@ -367,6 +355,18 @@ class TSqlMapUpdate extends TSqlMapStatement }
/**
+ * TSqlMapDelete class corresponds to the <delete> element.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.SqlMap.Configuration
+ * @since 3.1
+ */
+class TSqlMapDelete extends TSqlMapUpdate
+{
+}
+
+/**
* TSqlMapSelect corresponds to the <selectKey> element.
*
* @author Wei Zhuo <weizho[at]gmail[dot]com>
diff --git a/framework/Data/SqlMap/Statements/TMappedStatement.php b/framework/Data/SqlMap/Statements/TMappedStatement.php index e56e73ce..db02857f 100644 --- a/framework/Data/SqlMap/Statements/TMappedStatement.php +++ b/framework/Data/SqlMap/Statements/TMappedStatement.php @@ -203,7 +203,7 @@ class TMappedStatement extends TComponent implements IMappedStatement */
public function executeQueryForList($connection, $parameter, $result=null, $skip=-1, $max=-1, $delegate=null)
{
- $sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter);
+ $sql = $this->_command->create($this->_manager, $connection, $this->_statement, $parameter,$skip,$max);
return $this->runQueryForList($connection, $parameter, $sql, $result, $skip, $max, $delegate);
}
@@ -228,7 +228,9 @@ class TMappedStatement extends TComponent implements IMappedStatement $registry=$this->getManager()->getTypeHandlers();
$list = $result instanceof ArrayAccess ? $result :
$this->_statement->createInstanceOfListClass($registry);
- $reader = $this->executeSQLQueryLimit($connection, $sql, $max, $skip);
+ $connection->setActive(true);
+ $reader = $sql->query();
+ //$reader = $this->executeSQLQueryLimit($connection, $sql, $max, $skip);
if(!is_null($delegate))
{
foreach($reader as $row)
diff --git a/framework/Data/SqlMap/Statements/TPreparedCommand.php b/framework/Data/SqlMap/Statements/TPreparedCommand.php index 7bb68c79..ff5fd6ff 100644 --- a/framework/Data/SqlMap/Statements/TPreparedCommand.php +++ b/framework/Data/SqlMap/Statements/TPreparedCommand.php @@ -10,6 +10,8 @@ * @package System.Data.SqlMap.Statements
*/
+Prado::using('System.Data.Common.TDbMetaData');
+
/**
* TPreparedCommand class.
*
@@ -20,11 +22,17 @@ */
class TPreparedCommand
{
- public function create(TSqlMapManager $manager, $connection, $statement, $parameterObject)
+ public function create(TSqlMapManager $manager, $connection, $statement, $parameterObject,$skip=null,$max=null)
{
$prepared = $statement->getSQLText()->getPreparedStatement($parameterObject);
$connection->setActive(true);
- $command = $connection->createCommand($prepared->getPreparedSql());
+ $sql = $prepared->getPreparedSql();
+ if($max!==null || $skip!==null)
+ {
+ $builder = TDbMetaData::getInstance($connection)->createCommandBuilder();
+ $sql = $builder->applyLimitOffset($sql,$max,$skip);
+ }
+ $command = $connection->createCommand($sql);
$this->applyParameterMap($manager, $command, $prepared, $statement, $parameterObject);
return $command;
}
|