本文整理汇总了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!");
}
}
}