function test_table_info() { $conn = $this->getGateway()->getDbConnection(); $this->add_record1(); $this->add_record2(); $info = TDbMetaData::getInstance($conn)->getTableInfo('address'); $table = new TTableGateway($info, $conn); $this->assertEquals(count($table->findAll()->readAll()), 2); }
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); }
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; }
/** * 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])) { Prado::using('System.Data.Common.TDbMetaData'); $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]; }
/** * Sets up the command builder for the given table. * @param string table or view name. */ protected function setTableName($tableName) { Prado::using('System.Data.Common.TDbMetaData'); $meta = TDbMetaData::getInstance($this->getDbConnection()); $this->initCommandBuilder($meta->createCommandBuilder($tableName)); }
/** * @return TDbMetaData */ public function getDbMetaData() { if ($this->_dbMeta === null) { Prado::using('System.Data.Common.TDbMetaData'); $this->_dbMeta = TDbMetaData::getInstance($this); } return $this->_dbMeta; }