本文整理匯總了PHP中CDbConnection::getSchema方法的典型用法代碼示例。如果您正苦於以下問題:PHP CDbConnection::getSchema方法的具體用法?PHP CDbConnection::getSchema怎麽用?PHP CDbConnection::getSchema使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CDbConnection
的用法示例。
在下文中一共展示了CDbConnection::getSchema方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: init
/**
* Initializes the command object.
* This method is invoked after a command object is created and initialized with configurations.
* You may override this method to further customize the command before it executes.
* @since 1.1.6
*/
public function init()
{
if (null === Yii::app()->db) {
throw new CException('An active "db" connection is required to run this command.');
}
$this->dbConnection = Yii::app()->db;
$this->dbSchema = $this->dbConnection->getSchema();
$this->tableNames = array_diff($this->dbSchema->tableNames, (array) $this->ignoreTableNames, (array) $this->systemTableNames);
}
示例2: testIssue1407_5
public function testIssue1407_5()
{
// :parameter3 is not used
$tableSchema = $this->db->getSchema()->getTable('users');
$builder = $this->db->getSchema()->getCommandBuilder();
$criteria = new CDbCriteria();
$criteria->select = array('t.*', ':parameter1 AS test');
$criteria->params[':parameter1'] = 'testingValue';
$criteria->order = 'IF (t.username=:parameter2,t.username,t.email) DESC';
$criteria->params[':parameter2'] = 'user2';
$criteria->params[':parameter3'] = 'parameter3Value';
$criteria->addCondition('t.email LIKE :parameter4');
$criteria->params[':parameter4'] = 'email%';
$criteria->addInCondition('t.id', array(1, 2, 3));
$this->setExpectedException('CDbException');
$builder->createCountCommand($tableSchema, $criteria)->queryScalar();
}
示例3: testMultipleInsert
public function testMultipleInsert()
{
$builder = $this->db->getSchema()->getCommandBuilder();
$tableName = 'types';
$data = array(array('int_col' => 1, 'char_col' => 'char_col_1', 'char_col2' => 'char_col_2_1', 'float_col' => 1.1, 'bool_col' => true), array('int_col' => 2, 'char_col' => 'char_col_2', 'float_col' => 2.2, 'bool_col' => false));
$command = $builder->createMultipleInsertCommand($tableName, $data);
$command->execute();
$rows = $builder->dbConnection->createCommand('SELECT * FROM ' . $builder->dbConnection->quoteTableName($tableName))->queryAll();
$this->assertEquals(count($data), count($rows), 'Records count miss matches!');
foreach ($rows as $rowIndex => $row) {
foreach ($row as $columnName => $value) {
$columnIndex = array_search($columnName, $data[$rowIndex], true);
if ($columnIndex == false) {
continue;
}
$expectedValue = $data[$rowIndex][$columnIndex];
$this->assertTrue($expectedValue == $value, "Value for column '{$columnName}' incorrect!");
}
}
}