本文整理匯總了PHP中Cake\Database\Schema\Table::truncateSql方法的典型用法代碼示例。如果您正苦於以下問題:PHP Table::truncateSql方法的具體用法?PHP Table::truncateSql怎麽用?PHP Table::truncateSql使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Cake\Database\Schema\Table
的用法示例。
在下文中一共展示了Table::truncateSql方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: truncate
/**
* {@inheritDoc}
*/
public function truncate(ConnectionInterface $db)
{
$sql = $this->_schema->truncateSql($db);
foreach ($sql as $stmt) {
$db->execute($stmt)->closeCursor();
}
return true;
}
示例2: testTruncateSql
/**
* Test truncateSql()
*
* @return void
*/
public function testTruncateSql()
{
$driver = $this->_getMockedDriver();
$connection = $this->getMockBuilder('Cake\\Database\\Connection')->disableOriginalConstructor()->getMock();
$connection->expects($this->any())->method('driver')->will($this->returnValue($driver));
$table = new Table('schema_articles');
$table->addColumn('id', 'integer')->addConstraint('primary', ['type' => 'primary', 'columns' => ['id']]);
$result = $table->truncateSql($connection);
$this->assertCount(1, $result);
$this->assertEquals('TRUNCATE "schema_articles" RESTART IDENTITY CASCADE', $result[0]);
}
示例3: testTruncateSqlNoSequences
/**
* Test truncateSql() with no sequences
*
* @return void
*/
public function testTruncateSqlNoSequences()
{
$driver = $this->_getMockedDriver();
$connection = $this->getMock('Cake\\Database\\Connection', [], [], '', false);
$connection->expects($this->any())->method('driver')->will($this->returnValue($driver));
$statement = $this->getMock('\\PDOStatement', ['execute', 'rowCount', 'closeCursor', 'fetch']);
$driver->connection()->expects($this->once())->method('prepare')->with('SELECT 1 FROM sqlite_master WHERE name = "sqlite_sequence"')->will($this->returnValue($statement));
$statement->expects($this->once())->method('fetch')->will($this->returnValue(false));
$table = new Table('articles');
$result = $table->truncateSql($connection);
$this->assertCount(1, $result);
$this->assertEquals('DELETE FROM "articles"', $result[0]);
}
示例4: testTruncateSql
/**
* Test truncateSql()
*
* @return void
*/
public function testTruncateSql()
{
$driver = $this->_getMockedDriver();
$connection = $this->getMockBuilder('Cake\\Database\\Connection')->disableOriginalConstructor()->getMock();
$connection->expects($this->any())->method('driver')->will($this->returnValue($driver));
$table = new Table('articles');
$result = $table->truncateSql($connection);
$this->assertCount(1, $result);
$this->assertEquals('TRUNCATE TABLE `articles`', $result[0]);
}
示例5: testTruncateSql
/**
* Test truncateSql()
*
* @return void
*/
public function testTruncateSql()
{
$driver = $this->_getMockedDriver();
$connection = $this->getMock('Cake\\Database\\Connection', [], [], '', false);
$connection->expects($this->any())->method('driver')->will($this->returnValue($driver));
$table = new Table('schema_articles');
$table->addColumn('id', 'integer')->addConstraint('primary', ['type' => 'primary', 'columns' => ['id']]);
$result = $table->truncateSql($connection);
$this->assertCount(2, $result);
$this->assertEquals('DELETE FROM [schema_articles]', $result[0]);
$this->assertEquals('DBCC CHECKIDENT([schema_articles], RESEED, 0)', $result[1]);
}