Use the {@link getTableInfo} method to retrieve a table information.
Since: 3.1
Inheritance: extends Prado\TComponent
Example #1
0
 function __construct()
 {
     if (!class_exists("TActiveRecordManager", false)) {
         throw new Exception("You need to enable the ActiveRecord module in your application configuration file.");
     }
     $ar_manager = TActiveRecordManager::getInstance();
     $_conn = $ar_manager->getDbConnection();
     $_conn->Active = true;
     $this->_dbMetaData = TDbMetaData::getInstance($_conn);
 }
Example #2
0
 public function create(TSqlMapManager $manager, $connection, $statement, $parameterObject, $skip = null, $max = null)
 {
     $sqlText = $statement->getSQLText();
     $prepared = $sqlText->getPreparedStatement($parameterObject);
     $connection->setActive(true);
     $sql = $prepared->getPreparedSql();
     if ($sqlText instanceof TSimpleDynamicSql) {
         $sql = $sqlText->replaceDynamicParameter($sql, $parameterObject);
     }
     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;
 }
Example #3
0
 /**
  * Quotes a column alias for use in a query.
  * @param string $name column alias
  * @return string the properly quoted column alias
  */
 public function quoteColumnAlias($name)
 {
     return parent::quoteColumnAlias($name, '`', '`');
 }
Example #4
0
 /**
  * @return TDbMetaData
  */
 public function getDbMetaData()
 {
     if ($this->_dbMeta === null) {
         $this->_dbMeta = TDbMetaData::getInstance($this);
     }
     return $this->_dbMeta;
 }
Example #5
0
 /**
  * Sets up the command builder for the given table.
  * @param string table or view name.
  */
 protected function setTableName($tableName)
 {
     $meta = TDbMetaData::getInstance($this->getDbConnection());
     $this->initCommandBuilder($meta->createCommandBuilder($tableName));
 }
Example #6
0
 /**
  * Returns table information for table in the database connection.
  * @param TDbConnection database connection
  * @param string table name
  * @return TDbTableInfo table details.
  */
 public function getTableInfo(TDbConnection $connection, $tableName)
 {
     $connStr = $connection->getConnectionString();
     $key = $connStr . $tableName;
     if (!isset($this->_tables[$key])) {
         //call this first to ensure that unserializing the cache
         //will find the correct driver dependent classes.
         if (!isset($this->_meta[$connStr])) {
             $this->_meta[$connStr] = TDbMetaData::getInstance($connection);
         }
         $tableInfo = null;
         if (($cache = $this->getManager()->getCache()) !== null) {
             $tableInfo = $cache->get($key);
         }
         if (empty($tableInfo)) {
             $tableInfo = $this->_meta[$connStr]->getTableInfo($tableName);
             if ($cache !== null) {
                 $cache->set($key, $tableInfo);
             }
         }
         $this->_tables[$key] = $tableInfo;
     }
     return $this->_tables[$key];
 }