Example #1
0
 protected function getMysqlSqlMapManager()
 {
     static $conn;
     static $sqlMapManager;
     if (Prado::getApplication() === null) {
         Prado::setApplication(new TApplication(dirname(__FILE__) . '/app'));
     }
     if ($conn === null) {
         $conn = new TDbConnection('mysql:host=localhost;dbname=prado_system_data_sqlmap', 'prado_unitest', 'prado_system_data_sqlmap_unitest');
     }
     $conn->setActive(true);
     if ($sqlMapManager === null) {
         $sqlMapManager = new TSqlMapManager($conn);
         $sqlMapManager->configureXml(dirname(__FILE__) . '/DynamicParameterTestMap.xml');
     }
     return $sqlMapManager;
 }
 /**
  * Constructor.
  * @param TDbConnection the connection associated with this transaction
  * @see TDbConnection::beginTransaction
  */
 public function __construct(TDbConnection $connection)
 {
     if ($connection instanceof ISlaveDbConnection) {
         $this->_compatible = true;
         $master = $connection->getMasterConnection();
         $master->setForceMaster(TMasterSlaveDbConnectionForceMaster::ON_TRANSACTION);
         Prado::log('contstuct, ForceMaster: ON_TRANSACTION', TLogger::DEBUG, 'System.Testing.Data.Distributed.MasterSlave.TMasterSlaveDbTransaction');
         parent::__construct($master);
     } else {
         if ($connection instanceof IMasterSlaveDbConnection) {
             $this->_compatible = true;
             $connection->setForceMaster(TMasterSlaveDbConnectionForceMaster::ON_TRANSACTION);
             Prado::log('contstuct, ForceMaster: ON_TRANSACTION', TLogger::DEBUG, 'System.TestingData.Distributed.MasterSlave.TMasterSlaveDbTransaction');
         }
         parent::__construct($connection);
     }
 }
 /**
  * Creates the DB connection.
  * @param string the module ID for TDataSourceConfig
  * @return TDbConnection the created DB connection
  * @throws TConfigurationException if module ID is invalid or empty
  */
 protected function createDbConnection()
 {
     if ($this->_connID !== '') {
         $config = $this->getApplication()->getModule($this->_connID);
         if ($config instanceof TDataSourceConfig) {
             return $config->getDbConnection();
         } else {
             throw new TConfigurationException('dbcache_connectionid_invalid', $this->_connID);
         }
     } else {
         $db = new TDbConnection();
         if ($this->_connectionString !== '') {
             $db->setConnectionString($this->_connectionString);
             if ($this->_username !== '') {
                 $db->setUsername($this->_username);
             }
             if ($this->_password !== '') {
                 $db->setPassword($this->_password);
             }
         } else {
             // default to SQLite3 database
             $dbFile = $this->getApplication()->getRuntimePath() . '/sqlite3.cache';
             $db->setConnectionString('sqlite:' . $dbFile);
         }
         return $db;
     }
 }
Example #4
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])) {
             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];
 }
Example #5
0
 /**
  * Creates the DB connection.
  * @param string the module ID for TDataSourceConfig
  * @return TDbConnection the created DB connection
  * @throws TConfigurationException if module ID is invalid or empty
  */
 protected function createDbConnection()
 {
     if ($this->_connID !== '') {
         $config = $this->getApplication()->getModule($this->_connID);
         if ($config instanceof TDataSourceConfig) {
             return $config->getDbConnection();
         } else {
             throw new TConfigurationException('dblogroute_connectionid_invalid', $this->_connID);
         }
     } else {
         $db = new TDbConnection();
         // default to SQLite3 database
         $dbFile = $this->getApplication()->getRuntimePath() . '/sqlite3.log';
         $db->setConnectionString('sqlite:' . $dbFile);
         return $db;
     }
 }
 /**
  * Constructor.
  * @param TDbConnection the database connection
  * @param string the SQL statement to be executed
  * @param TDbStatementClassification Defaults to 'UNKNOWN'
  */
 public function __construct(TDbConnection $connection, $text, $classification = TDbStatementClassification::UNKNOWN)
 {
     $connection->setActive(true);
     parent::__construct($connection, $text);
     $this->_statementClassification = $classification;
     Prado::log($classification . ', ' . $connection->getServerRole() . ': ' . preg_replace('/[\\s]+/', ' ', $text), TLogger::DEBUG, 'System.Testing.Data.Distributed.TDistributedDbCommand');
 }